ParameterValidation.throwIllegalArgExceptionIfNull(accessMode, "access mode");
if (debug)
{
log.debug("Portlet is requesting " + accessMode + " access mode");
}
InteractionParams interactionParams = WSRPTypeFactory.createInteractionParams(WSRPUtils.getStateChangeFromAccessMode(accessMode));
// interaction state
StateString interactionState = actionInvocation.getInteractionState();
if (interactionState != null)
{
String state = interactionState.getStringValue();
if (!StateString.JBPNS_PREFIX.equals(state)) // fix-me: see JBPORTAL-900
{
interactionParams.setInteractionState(state);
}
}
// check for multi-part
RequestContextWrapper requestContext = new RequestContextWrapper(actionInvocation.getRequestContext());
try
{
if (FileUpload.isMultipartContent(requestContext))
{
// content is multipart, we need to parse it (that includes form parameters)
FileUpload upload = new FileUpload();
FileItemIterator iter = upload.getItemIterator(requestContext);
List<UploadContext> uploadContexts = new ArrayList<UploadContext>(7);
List<NamedString> formParameters = new ArrayList<NamedString>(7);
while (iter.hasNext())
{
FileItemStream item = iter.next();
InputStream stream = item.openStream();
if (!item.isFormField())
{
String contentType = item.getContentType();
if (debug)
{
log.debug("File field " + item.getFieldName() + " with file name " + item.getName() + " and content type "
+ contentType + " detected.");
}
BufferedInputStream bufIn = new BufferedInputStream(stream);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
BufferedOutputStream bos = new BufferedOutputStream(baos);
int c = bufIn.read();
while (c != -1)
{
bos.write(c);
c = bufIn.read();
}
bos.flush();
baos.flush();
bufIn.close();
bos.close();
UploadContext uploadContext = WSRPTypeFactory.createUploadContext(contentType, baos.toByteArray());
List<NamedString> mimeAttributes = new ArrayList<NamedString>(2);
String value = FileUpload.FORM_DATA + ";"
+ " name=\"" + item.getFieldName() + "\";"
+ " filename=\"" + item.getName() + "\"";
NamedString mimeAttribute = WSRPTypeFactory.createNamedString(FileUpload.CONTENT_DISPOSITION, value);
mimeAttributes.add(mimeAttribute);
mimeAttribute = WSRPTypeFactory.createNamedString(FileUpload.CONTENT_TYPE, item.getContentType());
mimeAttributes.add(mimeAttribute);
uploadContext.getMimeAttributes().addAll(mimeAttributes);
uploadContexts.add(uploadContext);
}
else
{
NamedString formParameter = WSRPTypeFactory.createNamedString(item.getFieldName(), 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;
for (String value : values)
{
formParameter = WSRPTypeFactory.createNamedString(name, value);
formParameters.add(formParameter);
}
}
interactionParams.getFormParameters().addAll(formParameters);
}
}
}
catch (Exception e)
{