UploadContext uploadContext = WSRPTypeFactory.createUploadContext(contentType, baos.toByteArray());
List<NamedString> mimeAttributes = new ArrayList<NamedString>(2);
NamedString mimeAttribute = new NamedString();
mimeAttribute.setName(FileUpload.CONTENT_DISPOSITION);
mimeAttribute.setValue(FileUpload.FORM_DATA + ";"
+ " name=\"" + item.getFieldName() + "\";"
+ " filename=\"" + item.getName() + "\"");
mimeAttributes.add(mimeAttribute);
mimeAttribute = new NamedString();
mimeAttribute.setName(FileUpload.CONTENT_TYPE);
mimeAttribute.setValue(item.getContentType());
mimeAttributes.add(mimeAttribute);
uploadContext.getMimeAttributes().addAll(mimeAttributes);
uploadContexts.add(uploadContext);
}
else
{
NamedString formParameter = new NamedString();
formParameter.setName(item.getFieldName());
formParameter.setValue(Streams.asString(stream));
formParameters.add(formParameter);
}
}
interactionParams.getUploadContexts().addAll(uploadContexts);
interactionParams.getFormParameters().addAll(formParameters);
}
else
{
// if the content is not multipart, then check for form parameters
Map<String, String[]> params = actionInvocation.getForm();
if (params != null && !params.isEmpty())
{
int capacity = params.size();
List<NamedString> formParameters = new ArrayList<NamedString>(capacity);
for (Map.Entry param : params.entrySet())
{
String name = (String)param.getKey();
String[] values = (String[])param.getValue();
NamedString formParameter = new NamedString();
for (String value : values)
{
formParameter.setName(name);
formParameter.setValue(value);
formParameters.add(formParameter);
}
}
interactionParams.getFormParameters().addAll(formParameters);
}