Author: richard.opalka(a)jboss.com
Date: 2011-01-31 06:33:23 -0500 (Mon, 31 Jan 2011)
New Revision: 13649
Modified:
stack/native/branches/jbossws-native-3.1.2/modules/core/src/main/java/org/jboss/ws/core/CommonSOAPBinding.java
stack/native/branches/jbossws-native-3.1.2/modules/core/src/main/java/org/jboss/ws/core/server/ServiceEndpointInvoker.java
stack/native/branches/jbossws-native-3.1.2/modules/core/src/main/java/org/jboss/wsf/stack/jbws/RequestHandlerImpl.java
Log:
[JBPAPP-4564][JBWS-3155] back porting anonymous attachments fix
Modified:
stack/native/branches/jbossws-native-3.1.2/modules/core/src/main/java/org/jboss/ws/core/CommonSOAPBinding.java
===================================================================
---
stack/native/branches/jbossws-native-3.1.2/modules/core/src/main/java/org/jboss/ws/core/CommonSOAPBinding.java 2011-01-31
11:07:19 UTC (rev 13648)
+++
stack/native/branches/jbossws-native-3.1.2/modules/core/src/main/java/org/jboss/ws/core/CommonSOAPBinding.java 2011-01-31
11:33:23 UTC (rev 13649)
@@ -23,6 +23,8 @@
import java.util.HashMap;
import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -328,14 +330,6 @@
{
AttachmentPart part = getAttachmentFromMessage(paramMetaData,
reqMessage);
epInv.setRequestParamValue(xmlName, part);
-
- // Add the attachment to the standard property
- if (part.getDataHandler() != null && msgContext instanceof
MessageContextJAXWS)
- {
- DataHandler dataHandler = part.getDataHandler();
- Map<String, DataHandler> attachments = (Map<String,
DataHandler>)msgContext.get(MessageContext.INBOUND_MESSAGE_ATTACHMENTS);
- attachments.put(part.getContentId(), dataHandler);
- }
}
else
{
@@ -374,6 +368,9 @@
}
}
+ // Add all attachments to the standard property
+ this.propagateAttachmentsToJAXWSMessageContext(reqMessage, msgContext);
+
return epInv;
}
catch (Exception e)
@@ -439,6 +436,8 @@
}
}
+ this.propagateAttachmentsFromJAXWSMessageContext(resMessage, msgContext);
+
// Add the return to the message
ParameterMetaData retMetaData = opMetaData.getReturnParameter();
if (retMetaData != null)
@@ -503,7 +502,7 @@
}
}
}
-
+
return resMessage;
}
catch (Exception e)
@@ -512,7 +511,32 @@
return null;
}
}
+
+ /**
+ * Propagates attachments from JAXWS message context to soap message.
+ *
+ * @param message soap message to bind attachments to
+ * @param msgContext message context to read attachments from
+ */
+ private void propagateAttachmentsFromJAXWSMessageContext(final SOAPMessage message,
final CommonMessageContext msgContext)
+ {
+ if (msgContext instanceof MessageContextJAXWS)
+ {
+ @SuppressWarnings("unchecked")
+ final Map<String, DataHandler> attachments = (Map<String,
DataHandler>)msgContext.get(MessageContext.OUTBOUND_MESSAGE_ATTACHMENTS);
+ final Iterator<?> attachmentsIterator = attachments.keySet().iterator();
+ AttachmentPart part = null;
+ while (attachmentsIterator.hasNext())
+ {
+ final String contentId = (String)attachmentsIterator.next();
+ final DataHandler handler = attachments.get(contentId);
+ part = this.createAttachmentPart(contentId, handler);
+ ((SOAPMessageImpl)message).addAttachmentPart(part);
+ }
+ }
+ }
+
/** On the client side, extract the OUT parameters from the payload and return them to
the client. */
public void unbindResponseMessage(OperationMetaData opMetaData, MessageAbstraction
payload, EndpointInvocation epInv, Map<QName, UnboundHeader> unboundHeaders)
throws BindingException
@@ -599,14 +623,6 @@
{
AttachmentPart part = getAttachmentFromMessage(retMetaData, resMessage);
epInv.setReturnValue(part);
-
- // Add the attachment to the standard property
- if (part.getDataHandler() != null && msgContext instanceof
MessageContextJAXWS)
- {
- DataHandler dataHandler = part.getDataHandler();
- Map<String, DataHandler> attachments = (Map<String,
DataHandler>)msgContext.get(MessageContext.INBOUND_MESSAGE_ATTACHMENTS);
- attachments.put(part.getContentId(), dataHandler);
- }
}
else
{
@@ -622,14 +638,6 @@
{
AttachmentPart part = getAttachmentFromMessage(paramMetaData,
resMessage);
epInv.setResponseParamValue(xmlName, part);
-
- // Add the attachment to the standard property
- if (part.getDataHandler() != null && msgContext instanceof
MessageContextJAXWS)
- {
- DataHandler dataHandler = part.getDataHandler();
- Map<String, DataHandler> attachments = (Map<String,
DataHandler>)msgContext.get(MessageContext.INBOUND_MESSAGE_ATTACHMENTS);
- attachments.put(part.getContentId(), dataHandler);
- }
}
else
{
@@ -638,13 +646,40 @@
epInv.setResponseParamValue(xmlName, value);
}
}
+
+ // Add all attachments to the standard property
+ this.propagateAttachmentsToJAXWSMessageContext(resMessage, msgContext);
}
catch (Exception e)
{
handleException(e);
}
}
+
+ /**
+ * Propagates all the attachments from SOAPMessage to JAXWS Message context standard
property.
+ *
+ * @param message soap message to read attachments from
+ * @param msgContext to propagate attachments to
+ * @throws SOAPException if something went wrong
+ */
+ private void propagateAttachmentsToJAXWSMessageContext(final SOAPMessage message,
final CommonMessageContext msgContext) throws SOAPException
+ {
+ if (msgContext instanceof MessageContextJAXWS)
+ {
+ final SOAPMessageImpl implMessage = (SOAPMessageImpl)message;
+ final Iterator<?> attachmentsIterator = implMessage.getAttachments();
+ final Map<String, DataHandler> attachments = (Map<String,
DataHandler>)msgContext.get(MessageContext.INBOUND_MESSAGE_ATTACHMENTS);
+ AttachmentPart part = null;
+ while (attachmentsIterator.hasNext())
+ {
+ part = (AttachmentPart)attachmentsIterator.next();
+ attachments.put(part.getContentId(), part.getDataHandler()); // TODO: test on
getDataHandler() == null?
+ }
+ }
+ }
+
public MessageAbstraction bindFaultMessage(Exception ex)
{
SOAPMessageImpl faultMessage =
(SOAPMessageImpl)createFaultMessageFromException(ex);
@@ -724,6 +759,15 @@
return part;
}
+ private AttachmentPart createAttachmentPart(final String contentId, final DataHandler
value)
+ {
+ AttachmentPart part = new AttachmentPartImpl();
+ part.setContentId(contentId);
+ part.setDataHandler(value);
+
+ return part;
+ }
+
private AttachmentPart getAttachmentFromMessage(ParameterMetaData paramMetaData,
SOAPMessage message) throws SOAPException, BindingException
{
QName xmlName = paramMetaData.getXmlName();
Modified:
stack/native/branches/jbossws-native-3.1.2/modules/core/src/main/java/org/jboss/ws/core/server/ServiceEndpointInvoker.java
===================================================================
---
stack/native/branches/jbossws-native-3.1.2/modules/core/src/main/java/org/jboss/ws/core/server/ServiceEndpointInvoker.java 2011-01-31
11:07:19 UTC (rev 13648)
+++
stack/native/branches/jbossws-native-3.1.2/modules/core/src/main/java/org/jboss/ws/core/server/ServiceEndpointInvoker.java 2011-01-31
11:33:23 UTC (rev 13649)
@@ -25,6 +25,7 @@
import java.lang.reflect.Method;
import java.lang.reflect.UndeclaredThrowableException;
import java.util.HashMap;
+import java.util.Map;
import javax.activation.DataHandler;
import javax.xml.namespace.QName;
@@ -423,8 +424,19 @@
CommonMessageContext msgContext = MessageContextAssociation.peekMessageContext();
if (msgContext instanceof MessageContextJAXWS)
{
+ Map<String, DataHandler> outboundAttachments = (Map<String,
DataHandler>)msgContext.get(MessageContextJAXWS.OUTBOUND_MESSAGE_ATTACHMENTS);
+ Map<String, DataHandler> newAttachments = new HashMap<String,
DataHandler>(); // to protect against attacks from endpoint
+
// Map of attachments to a message for the outbound message, key is the MIME
Content-ID, value is a DataHandler
- msgContext.put(MessageContextJAXWS.OUTBOUND_MESSAGE_ATTACHMENTS, new
HashMap<String, DataHandler>());
+ msgContext.put(MessageContextJAXWS.OUTBOUND_MESSAGE_ATTACHMENTS,
newAttachments);
+
+ if (outboundAttachments != null)
+ {
+ for (final String key : outboundAttachments.keySet())
+ {
+ newAttachments.put(key, outboundAttachments.get(key));
+ }
+ }
}
}
Modified:
stack/native/branches/jbossws-native-3.1.2/modules/core/src/main/java/org/jboss/wsf/stack/jbws/RequestHandlerImpl.java
===================================================================
---
stack/native/branches/jbossws-native-3.1.2/modules/core/src/main/java/org/jboss/wsf/stack/jbws/RequestHandlerImpl.java 2011-01-31
11:07:19 UTC (rev 13648)
+++
stack/native/branches/jbossws-native-3.1.2/modules/core/src/main/java/org/jboss/wsf/stack/jbws/RequestHandlerImpl.java 2011-01-31
11:33:23 UTC (rev 13649)
@@ -251,6 +251,7 @@
msgContext = new SOAPMessageContextJAXWS();
msgContext.put(MessageContextJAXWS.MESSAGE_OUTBOUND_PROPERTY,
Boolean.valueOf(false));
msgContext.put(MessageContextJAXWS.INBOUND_MESSAGE_ATTACHMENTS, new
HashMap<String, DataHandler>());
+ msgContext.put(MessageContextJAXWS.OUTBOUND_MESSAGE_ATTACHMENTS, new
HashMap<String, DataHandler>());
invContext.addAttachment(javax.xml.ws.handler.MessageContext.class,
msgContext);
}