else
throw new RequestException("No method name was set");
}
instance.setMethodName(methodName);
BrokerContext context = Broker.getInstance().getBrokerContext();
Discovery disc = context.getDiscovery();
String[] paramNames = disc.listParams(methodName);
boolean postUsed = false;
for ( int i = 0; paramNames != null && i < paramNames.length; i++ ) {
boolean array = disc.isParamArray(methodName, i);
String[] vals = request.getValues(paramNames[i]);
if ( vals != null ) {
if ( array )
instance.setParameter(i, vals);
else
instance.setParameter(i, vals[0]);
}
else if ( !postUsed && request.hasContent() ) {
// If there is POST data, and this parameter is a String, Document,
// or byte array, then let us assume that the POST data is intended
// for this one.
try {
InputStream is = request.getInputStream();
ByteArrayOutputStream bos = new ByteArrayOutputStream(BUFFER_SIZE);
byte[] buffer = new byte[BUFFER_SIZE];
int size;
do {
size = is.read(buffer);
if ( size > 0 )
bos.write(buffer, 0, size);
}
while ( size != -1 );
instance.setParameter(i, bos.toByteArray());
postUsed = true;
}
catch ( IOException e ) {
/** @todo Hmmm */
}
}
else
instance.setParameter(i, null);
}
// Initially set the MIME type in case we get an HTTP 403 Exception
ID id = context.getId();
String contentType = getMimeType(id);
if ( contentType != null )
response.setHeader(HTTP.HEADER_CONTENT_TYPE, contentType);
Object o = instance.invoke();
Object type = context.getProperty(CONTENT_TYPE);
if ( type == null )
type = instance.getProperty(CONTENT_TYPE+'_'+methodName);
if ( type instanceof String ) {
contentType = (String)type;