if (!(invocation instanceof ActionInvocation))
{
throw new IllegalArgumentException("ActionHandler can only handle ActionInvocations!");
}
ActionInvocation actionInvocation = (ActionInvocation)invocation;
PortletContext portletContext = requestPrecursor.getPortletContext();
log.debug("Consumer about to attempt action on portlet '" + portletContext.getPortletHandle() + "'");
// access mode
InstanceContext instanceContext = invocation.getInstanceContext();
ParameterValidation.throwIllegalArgExceptionIfNull(instanceContext, "instance context");
AccessMode accessMode = instanceContext.getAccessMode();
ParameterValidation.throwIllegalArgExceptionIfNull(accessMode, "access mode");
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();
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);
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())