You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by sc...@apache.org on 2006/11/10 16:47:54 UTC
svn commit: r473375 - in /webservices/axis2/trunk/java/modules/jaxws:
src/org/apache/axis2/jaxws/message/attachments/
src/org/apache/axis2/jaxws/message/impl/
src/org/apache/axis2/jaxws/message/util/
src/org/apache/axis2/jaxws/server/dispatcher/ test/o...
Author: scheu
Date: Fri Nov 10 07:47:53 2006
New Revision: 473375
URL: http://svn.apache.org/viewvc?view=rev&rev=473375
Log:
AXIS2-1671
Contributor:Rich Scheuerle
Support for Attachments in Dispatch<SOAPMessage> and Provider<SOAPMessage>. Support for SWA attachments in JAXWS
Modified:
webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/attachments/AttachmentUtils.java
webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/attachments/JAXBAttachmentMarshaller.java
webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/impl/AttachmentImpl.java
webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/impl/MessageImpl.java
webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/util/MessageUtils.java
webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/dispatcher/ProviderDispatcher.java
webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/provider/SoapMessageProviderTests.java
webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/provider/soapmsg/SoapMessageProvider.java
Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/attachments/AttachmentUtils.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/attachments/AttachmentUtils.java?view=diff&rev=473375&r1=473374&r2=473375
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/attachments/AttachmentUtils.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/attachments/AttachmentUtils.java Fri Nov 10 07:47:53 2006
@@ -57,6 +57,9 @@
*/
private static void findXopElements(OMElement root, ArrayList<OMElement> xops) {
+ // Forces a parse. This seems to be necessary due to bugs in OMNavigator
+ root.getNextOMSibling();
+
// Navigator does a traversal that mimics the structure of an xml document.
// Each non-element object is processed once.
// Each element object is visited prior to its children and after its children.
@@ -77,7 +80,7 @@
while (nav.isNavigable()) {
OMNode curr = nav.next();
-
+
// Inspect elements that have been visited.
// It is probably safer to inspect the node when it is visited, because this guarantees that its
// children have been processed/expanded.
@@ -132,6 +135,8 @@
*/
private static void findBinaryElements(OMNode node, ArrayList<OMText> attachments) {
+ // Forces a parse. This seems to be necessary due to bugs in OMNavigator
+ node.getNextOMSibling();
// Navigator does a traversal that mimics the structure of an xml document.
// Each non-element object is processed once.
@@ -150,7 +155,7 @@
// is A B D D' e B' C F F' g C' A'
// The ' indicates that this is the second time the node is visited (i.e. nav.isVisited() returns true)
OMNavigator nav = new OMNavigator(node);
-
+
while (nav.isNavigable()) {
OMNode curr = nav.next();
if (curr instanceof OMText) {
Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/attachments/JAXBAttachmentMarshaller.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/attachments/JAXBAttachmentMarshaller.java?view=diff&rev=473375&r1=473374&r2=473375
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/attachments/JAXBAttachmentMarshaller.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/attachments/JAXBAttachmentMarshaller.java Fri Nov 10 07:47:53 2006
@@ -71,8 +71,14 @@
}
@Override
- public String addSwaRefAttachment(DataHandler arg0) {
- throw new UnsupportedOperationException("SwaRef attachments are not supported.");
+ public String addSwaRefAttachment(DataHandler data) {
+ if (log.isDebugEnabled())
+ log.debug("Adding SWARef attachment");
+
+ String cid = UUIDGenerator.getUUID();
+ Attachment a = message.createAttachment(data, cid);
+ message.addAttachment(a);
+ return cid;
}
}
Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/impl/AttachmentImpl.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/impl/AttachmentImpl.java?view=diff&rev=473375&r1=473374&r2=473375
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/impl/AttachmentImpl.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/impl/AttachmentImpl.java Fri Nov 10 07:47:53 2006
@@ -29,6 +29,11 @@
private DataHandler dh;
private MimeHeaders mimeHeaders = new MimeHeaders();
+ /**
+ * Constructor
+ * @param dh DataHandler
+ * @param id Content ID
+ */
AttachmentImpl(DataHandler dh, String id) {
setDataHandler(dh);
setContentID(id);
Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/impl/MessageImpl.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/impl/MessageImpl.java?view=diff&rev=473375&r1=473374&r2=473375
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/impl/MessageImpl.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/impl/MessageImpl.java Fri Nov 10 07:47:53 2006
@@ -25,6 +25,7 @@
import javax.activation.DataHandler;
import javax.jws.soap.SOAPBinding.Style;
import javax.xml.namespace.QName;
+import javax.xml.soap.AttachmentPart;
import javax.xml.soap.MessageFactory;
import javax.xml.soap.MimeHeaders;
import javax.xml.soap.SOAPEnvelope;
@@ -47,6 +48,7 @@
import org.apache.axis2.jaxws.message.factory.BlockFactory;
import org.apache.axis2.jaxws.message.factory.SAAJConverterFactory;
import org.apache.axis2.jaxws.message.factory.XMLPartFactory;
+import org.apache.axis2.jaxws.message.util.MessageUtils;
import org.apache.axis2.jaxws.message.util.SAAJConverter;
import org.apache.axis2.jaxws.registry.FactoryRegistry;
@@ -192,6 +194,13 @@
// At this point the XMLPart is still an OMElement. We need to change it to the new SOAPEnvelope.
createXMLPart(soapMessage.getSOAPPart().getEnvelope());
+
+ // Now add the attachments to the SOAPMessage
+ Iterator it = getAttachments().iterator();
+ while (it.hasNext()) {
+ AttachmentPart ap = MessageUtils.createAttachmentPart((Attachment)it.next(), soapMessage);
+ soapMessage.addAttachmentPart(ap);
+ }
return soapMessage;
} catch (Exception e) {
Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/util/MessageUtils.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/util/MessageUtils.java?view=diff&rev=473375&r1=473374&r2=473375
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/util/MessageUtils.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/util/MessageUtils.java Fri Nov 10 07:47:53 2006
@@ -148,6 +148,10 @@
* @return Message
*/
public static Message getMessageFromMessageContext(MessageContext msgContext) throws MessageException {
+ if (log.isDebugEnabled()) {
+ log.debug("Start getMessageFromMessageContext");
+ }
+
Message message = null;
// If the Axis2 MessageContext that was passed in has a SOAPEnvelope
// set on it, grab that and create a JAX-WS Message out of it.
@@ -166,11 +170,21 @@
//the inbound message has more than just the normal XML payload
Attachments as = (Attachments) msgContext.getProperty(MTOMConstants.ATTACHMENTS);
if (as != null) {
- message.setMTOMEnabled(true);
+ if (log.isDebugEnabled()) {
+ log.debug("Found Axis MTOM Attachments");
+ }
//Walk the tree and find all of the optimized binary nodes.
ArrayList<OMText> binaryNodes = AttachmentUtils.findBinaryNodes((SOAPEnvelope) message.getAsOMElement());
- if (binaryNodes != null) {
+ if (binaryNodes != null && binaryNodes.size() > 0) {
+
+ if (log.isDebugEnabled()) {
+ log.debug("Found " + binaryNodes.size() +"MTOM Binary Nodes");
+ }
+
+ // Mark the JAX-WS Message as MTOM enabled
+ message.setMTOMEnabled(true);
+
//Replace each of the nodes with it's corresponding <xop:include>
//element, so JAXB can process it correctly.
Iterator<OMText> itr = binaryNodes.iterator();
@@ -182,24 +196,32 @@
//We have to add the individual attachments in their raw
//binary form, so we can access them later.
+ if (log.isDebugEnabled()) {
+ log.debug("Create MTOM Message Attachment for " + node.getContentID());
+ }
Attachment a = message.createAttachment(
(DataHandler) node.getDataHandler(),
node.getContentID());
message.addAttachment(a);
}
}
- } else {
- // Add non-mtom attachments
- Attachments attachments = msgContext.getAttachmentMap();
- if (attachments != null) {
- String[] ids = attachments.getAllContentIDs();
- if (ids != null) {
- for (int i = 0; i<ids.length; i++) {
+ }
+
+ // Get SWA Attachments from the Axis2 MessageContext
+ Attachments attachments = msgContext.getAttachmentMap();
+ if (attachments != null) {
+ String[] ids = attachments.getAllContentIDs();
+ if (ids != null) {
+ // Axis2 stores the SOAP Part as one of the Attachments.
+ // For now we will assume that the SOAPPart is the first attachment, and skip it.
+ for (int i = 1; i<ids.length; i++) {
+ // The Attachment may already be added as an MTOM attachment (by the processing above)
+ if (message.getAttachment(ids[i]) == null) {
DataHandler dh = attachments.getDataHandler(ids[i]);
Attachment a = message.createAttachment(dh, ids[i]);
message.addAttachment(a);
if (log.isDebugEnabled()) {
- log.debug("Create Attachment for:" + a.getContentID() + " " + a.getContentType());
+ log.debug("Create JAXWS Attachment for SWA Attachment:" + a.getContentID() + " " + a.getContentType());
}
}
}
@@ -222,23 +244,37 @@
// Enable MTOM Attachments
if (message.isMTOMEnabled()) {
- Options opts = msgContext.getOptions();
- opts.setProperty(Configuration.ENABLE_MTOM, "true");
+ if (log.isDebugEnabled()) {
+ log.debug("MTOM is enabled on the JAX-WS Message...look for XOP Includes");
+ }
// If we have MTOM attachments, we need to replace the <xop:include>
// elements with OMText binary nodes.
// First find all of the <xop:include> elements
ArrayList<OMElement> xops = AttachmentUtils.findXopElements(envelope);
- if (xops != null) {
+ if (xops != null && xops.size() > 0) {
+ if (log.isDebugEnabled()) {
+ log.debug("Found XOP:Include Elements");
+ }
+ // Enable MTOM on the Axis2 MessageContext
+ Options opts = msgContext.getOptions();
+ opts.setProperty(Configuration.ENABLE_MTOM, "true");
+
QName href = new QName("","href");
Iterator<OMElement> itr = xops.iterator();
+
+
while (itr.hasNext()) {
OMElement xop = itr.next();
String cid = xop.getAttributeValue(href);
- // Then find their corresponding Attachment object
- Attachment a = message.getAttachment(cid);
+ // Find and remove the Attachment from the JAX-WS Message
+ // (It is removed so that it is not considered a SWA Attachment ...see below)
+ Attachment a = message.removeAttachment(cid);
+ if (log.isDebugEnabled()) {
+ log.debug("Create Binary OMNode for attachment:" + cid);
+ }
// Convert the <xop:include> OMElement into an OMText
// binary node and replace it in the tree.
@@ -250,14 +286,18 @@
}
- // Add the remaining attachments
+ // Any remaining attachments must be SWA attachments
List attachments = message.getAttachments();
if (attachments != null && attachments.size() > 0) {
+ // Indicate SWA Attachments are present
+ Options opts = msgContext.getOptions();
+ opts.setProperty(Configuration.ENABLE_SWA, "true");
+
for (int i=0; i<attachments.size(); i++) {
Attachment a = (Attachment) attachments.get(i);
msgContext.addAttachment(a.getContentID(), a.getDataHandler());
if (log.isDebugEnabled()) {
- log.debug("Attachment for:" + a.getContentID() + " " + a.getContentType());
+ log.debug("Add SWA Attachment for:" + a.getContentID() + " " + a.getContentType());
}
}
}
Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/dispatcher/ProviderDispatcher.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/dispatcher/ProviderDispatcher.java?view=diff&rev=473375&r1=473374&r2=473375
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/dispatcher/ProviderDispatcher.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/dispatcher/ProviderDispatcher.java Fri Nov 10 07:47:53 2006
@@ -29,6 +29,7 @@
import javax.xml.transform.Source;
import javax.xml.ws.Provider;
import javax.xml.ws.Service;
+import javax.xml.ws.soap.SOAPBinding;
import org.apache.axiom.om.OMElement;
import org.apache.axis2.description.AxisOperation;
@@ -97,6 +98,9 @@
// to be invoking against
providerType = getProviderType();
+ // REVIEW: This assumes there is only one endpoint description on the service. Is that always the case?
+ EndpointDescription endpointDesc = mc.getServiceDescription().getEndpointDescriptions()[0];
+
// Now that we know what kind of Provider we have, we can create the
// right type of Block for the request parameter data
Object requestParamValue = null;
@@ -107,8 +111,7 @@
// Determine what type blocks we want to create (String, Source, etc) based on Provider Type
BlockFactory factory = createBlockFactory(providerType);
- // REVIEW: This assumes there is only one endpoint description on the service. Is that always the case?
- EndpointDescription endpointDesc = mc.getServiceDescription().getEndpointDescriptions()[0];
+
providerServiceMode = endpointDesc.getServiceMode();
if (providerServiceMode != null && providerServiceMode == Service.Mode.MESSAGE) {
@@ -116,6 +119,10 @@
// This is based on logic in org.apache.axis2.jaxws.client.XMLDispatch.getValueFromMessage()
if (providerType.equals(SOAPMessage.class)) {
// We can get the SOAPMessage directly from the message itself
+ if (log.isDebugEnabled()) {
+ log.debug("Provider Type is SOAPMessage.");
+ log.debug("Number Message attachments=" + message.getAttachments().size());
+ }
requestParamValue = message.getAsSOAPMessage();
}
else {
@@ -167,6 +174,16 @@
MessageContext responseMsgCtx = null;
if (!isOneWay(mc.getAxisMessageContext())) {
Message responseMsg = createMessageFromValue(responseParamValue);
+
+ // Enable MTOM if indicated by the binding
+ String bindingType = endpointDesc.getBindingType();
+ if (bindingType != null) {
+ if (bindingType.equals(SOAPBinding.SOAP11HTTP_MTOM_BINDING) ||
+ bindingType.equals(SOAPBinding.SOAP12HTTP_MTOM_BINDING)) {
+ responseMsg.setMTOMEnabled(true);
+ }
+ }
+
responseMsgCtx = MessageContextUtils.
createMessageMessageContext(mc);
@@ -330,8 +347,10 @@
clazz == Source.class ||
clazz == DataSource.class;
- if (log.isDebugEnabled()) {
- log.debug("Class " + clazz.getName() + " is not a valid Provider<T> type");
+ if (!valid) {
+ if (log.isDebugEnabled()) {
+ log.debug("Class " + clazz.getName() + " is not a valid Provider<T> type");
+ }
}
return valid;
Modified: webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/provider/SoapMessageProviderTests.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/provider/SoapMessageProviderTests.java?view=diff&rev=473375&r1=473374&r2=473375
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/provider/SoapMessageProviderTests.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/provider/SoapMessageProviderTests.java Fri Nov 10 07:47:53 2006
@@ -27,8 +27,10 @@
import javax.xml.soap.SOAPBody;
import javax.xml.soap.SOAPElement;
import javax.xml.soap.SOAPMessage;
+import javax.xml.ws.Binding;
import javax.xml.ws.Dispatch;
import javax.xml.ws.Service;
+import javax.xml.ws.soap.SOAPBinding;
import org.apache.axis2.jaxws.provider.soapmsg.SoapMessageProvider;
@@ -43,11 +45,29 @@
private QName serviceName = new QName("http://ws.apache.org/axis2", "SoapMessageProviderService");
private String reqMsgStart = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
- "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"><soap:Body>" +
- "<ns2:invoke xmlns:ns2=\"http://org.test.soapmessage\"><invoke_str>";
+ "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"><soap:Body>";
+ ;
- private String reqMsgEnd = "</invoke_str></ns2:invoke></soap:Body></soap:Envelope>";
+ private String reqMsgEnd = "</soap:Body></soap:Envelope>";
+ private String XML_INVOKE = "<ns2:invoke xmlns:ns2=\"http://org.test.soapmessage\"><invoke_str>" +
+ SoapMessageProvider.XML_REQUEST +
+ "</invoke_str></ns2:invoke>";
+ private String ATTACHMENT_INVOKE = "<ns2:invoke xmlns:ns2=\"http://org.test.soapmessage\"><invoke_str>" +
+ SoapMessageProvider.XML_ATTACHMENT_REQUEST +
+ "</invoke_str></ns2:invoke>";
+ private String MTOM_INVOKE = "<ns2:invoke xmlns:ns2=\"http://org.test.soapmessage\"><invoke_str>" +
+ SoapMessageProvider.XML_MTOM_REQUEST +
+ "</invoke_str>" +
+ SoapMessageProvider.MTOM_REF +
+ "</ns2:invoke>";
+ private String SWAREF_INVOKE = "<ns2:invoke xmlns:ns2=\"http://org.test.soapmessage\"><invoke_str>" +
+ SoapMessageProvider.XML_SWAREF_REQUEST +
+ "</invoke_str>" +
+ SoapMessageProvider.SWAREF_REF +
+ "</ns2:invoke>";
+
+
protected void setUp() throws Exception {
super.setUp();
}
@@ -64,13 +84,13 @@
* Sends an SOAPMessage containing only xml data to the web service.
* Receives a response containing just xml data.
*/
- public void testProviderSource1(){
+ public void testProviderSourceXMLOnly(){
try{
// Create the dispatch
Dispatch<SOAPMessage> dispatch = createDispatch();
// Create the SOAPMessage
- String msg = reqMsgStart + SoapMessageProvider.XML_REQUEST + reqMsgEnd;
+ String msg = reqMsgStart + XML_INVOKE + reqMsgEnd;
MessageFactory factory = MessageFactory.newInstance();
SOAPMessage request = factory.createMessage(null,
new ByteArrayInputStream(msg.getBytes()));
@@ -99,14 +119,18 @@
* Sends an SOAPMessage containing xml data and raw attachments to the web service.
* Receives a response containing xml data and the same raw attachments.
*/
- /** TODO Disable while I implement the code
- public void testProviderSource2(){
+
+ public void testProviderSourceRawAttachment(){
+ // Raw Attachments are attachments that are not referenced in the xml with MTOM or SWARef.
+ // Currently there is no support in Axis 2 for these kinds of attachments.
+ // The belief is that most customers will use MTOM. Some legacy customers will use SWARef.
+ // Raw Attachments may be so old that no customers need this behavior.
try{
// Create the dispatch
Dispatch<SOAPMessage> dispatch = createDispatch();
// Create the SOAPMessage
- String msg = reqMsgStart + SoapMessageProvider.XML_ATTACHMENT_REQUEST + reqMsgEnd;
+ String msg = reqMsgStart + ATTACHMENT_INVOKE + reqMsgEnd;
MessageFactory factory = MessageFactory.newInstance();
SOAPMessage request = factory.createMessage(null,
new ByteArrayInputStream(msg.getBytes()));
@@ -145,8 +169,112 @@
}
}
- */
+ /**
+ * Sends an SOAPMessage containing xml data and mtom attachment.
+ * Receives a response containing xml data and the mtom attachment.
+ */
+ public void testProviderSourceMTOM(){
+ try{
+ // Create the dispatch
+ Dispatch<SOAPMessage> dispatch = createDispatch();
+
+ // Must indicated that this is a JAX-WS MTOM Dispatch
+ Binding binding = dispatch.getBinding();
+ SOAPBinding soapBinding = (SOAPBinding) binding;
+ soapBinding.setMTOMEnabled(true);
+
+
+ // Create the SOAPMessage
+ String msg = reqMsgStart + MTOM_INVOKE + reqMsgEnd;
+ MessageFactory factory = MessageFactory.newInstance();
+ SOAPMessage request = factory.createMessage(null,
+ new ByteArrayInputStream(msg.getBytes()));
+
+ // Add the Attachment
+ AttachmentPart ap = request.createAttachmentPart(SoapMessageProvider.TEXT_XML_ATTACHMENT, "text/xml");
+ ap.setContentId(SoapMessageProvider.ID);
+ request.addAttachmentPart(ap);
+
+ System.out.println("Request Message:");
+ request.writeTo(System.out);
+
+ // Dispatch
+ System.out.println(">> Invoking SourceMessageProviderDispatch");
+ SOAPMessage response = dispatch.invoke(request);
+
+ // Check assertions and get the data element
+ SOAPElement dataElement = assertResponseXML(response, SoapMessageProvider.XML_MTOM_RESPONSE);
+ assertTrue(countAttachments(response) == 1);
+
+ // Get the Attachment
+ AttachmentPart attachmentPart = (AttachmentPart) response.getAttachments().next();
+
+ // Check the attachment
+ String content = (String) attachmentPart.getContent();
+ assertTrue(content != null);
+ assertTrue(SoapMessageProvider.TEXT_XML_ATTACHMENT.equals(content));
+
+ // Print out the response
+ System.out.println(">> Response [" + response.toString() + "]");
+ response.writeTo(System.out);
+
+ }catch(Exception e){
+ e.printStackTrace();
+ fail("Caught exception " + e);
+ }
+
+ }
+
+ /**
+ * Sends an SOAPMessage containing xml data and a swaref attachment to the web service.
+ * Receives a response containing xml data and the swaref attachment attachment.
+ */
+ public void testProviderSourceSWARef(){
+ try{
+ // Create the dispatch
+ Dispatch<SOAPMessage> dispatch = createDispatch();
+
+ // Create the SOAPMessage
+ String msg = reqMsgStart + SWAREF_INVOKE + reqMsgEnd;
+ MessageFactory factory = MessageFactory.newInstance();
+ SOAPMessage request = factory.createMessage(null,
+ new ByteArrayInputStream(msg.getBytes()));
+
+ // Add the Attachment
+ AttachmentPart ap = request.createAttachmentPart(SoapMessageProvider.TEXT_XML_ATTACHMENT, "text/xml");
+ ap.setContentId(SoapMessageProvider.ID);
+ request.addAttachmentPart(ap);
+
+ System.out.println("Request Message:");
+ request.writeTo(System.out);
+
+ // Dispatch
+ System.out.println(">> Invoking SourceMessageProviderDispatch");
+ SOAPMessage response = dispatch.invoke(request);
+
+ // Check assertions and get the data element
+ SOAPElement dataElement = assertResponseXML(response, SoapMessageProvider.XML_SWAREF_RESPONSE);
+ assertTrue(countAttachments(response) == 1);
+
+ // Get the Attachment
+ AttachmentPart attachmentPart = (AttachmentPart) response.getAttachments().next();
+
+ // Check the attachment
+ String content = (String) attachmentPart.getContent();
+ assertTrue(content != null);
+ assertTrue(SoapMessageProvider.TEXT_XML_ATTACHMENT.equals(content));
+
+ // Print out the response
+ System.out.println(">> Response [" + response.toString() + "]");
+ response.writeTo(System.out);
+
+ }catch(Exception e){
+ e.printStackTrace();
+ fail("Caught exception " + e);
+ }
+
+ }
/**
* @return
* @throws Exception
Modified: webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/provider/soapmsg/SoapMessageProvider.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/provider/soapmsg/SoapMessageProvider.java?view=diff&rev=473375&r1=473374&r2=473375
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/provider/soapmsg/SoapMessageProvider.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/provider/soapmsg/SoapMessageProvider.java Fri Nov 10 07:47:53 2006
@@ -19,10 +19,12 @@
import java.io.ByteArrayInputStream;
import java.util.Iterator;
+import javax.xml.ws.BindingType;
import javax.xml.ws.Provider;
import javax.xml.ws.Service;
import javax.xml.ws.ServiceMode;
import javax.xml.ws.WebServiceProvider;
+import javax.xml.ws.soap.SOAPBinding;
import javax.xml.soap.AttachmentPart;
import javax.xml.soap.MessageFactory;
import javax.xml.soap.Node;
@@ -32,10 +34,11 @@
@WebServiceProvider()
@ServiceMode(value=Service.Mode.MESSAGE)
+@BindingType(SOAPBinding.SOAP11HTTP_MTOM_BINDING)
public class SoapMessageProvider implements Provider<SOAPMessage> {
- String responseMsgStart = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"><soapenv:Header/><soapenv:Body><ns2:ReturnType xmlns:ns2=\"http://test\"><return_str>";
- String responseMsgEnd = "</return_str></ns2:ReturnType></soapenv:Body></soapenv:Envelope>";
+ String responseMsgStart = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"><soapenv:Header/><soapenv:Body>";
+ String responseMsgEnd = "</soapenv:Body></soapenv:Envelope>";
// Requests and Response values of invoke_str and return_str
// These constants are referenced by the SoapMessageProviderTest and SoapMessageProvider
@@ -48,40 +51,75 @@
public static String XML_RESPONSE = "xml response";
public static String XML_ATTACHMENT_REQUEST = "xml and attachment request";
public static String XML_ATTACHMENT_RESPONSE = "xml and attachment response";
+ public static String XML_MTOM_REQUEST = "xml and mtom request";
+ public static String XML_MTOM_RESPONSE = "xml and mtom response";
+ public static String XML_SWAREF_REQUEST = "xml and swaref request";
+ public static String XML_SWAREF_RESPONSE = "xml and swaref response";
+
+ private String XML_RETURN = "<ns2:ReturnType xmlns:ns2=\"http://test\"><return_str>" +
+ SoapMessageProvider.XML_RESPONSE +
+ "</return_str></ns2:ReturnType>";
+ private String ATTACHMENT_RETURN = "<ns2:ReturnType xmlns:ns2=\"http://test\"><return_str>" +
+ SoapMessageProvider.XML_ATTACHMENT_RESPONSE +
+ "</return_str></ns2:ReturnType>";
+ private String MTOM_RETURN = "<ns2:ReturnType xmlns:ns2=\"http://test\"><return_str>" +
+ SoapMessageProvider.XML_MTOM_RESPONSE +
+ "</return_str>" +
+ SoapMessageProvider.MTOM_REF +
+ "</ns2:ReturnType>";
+ private String SWAREF_RETURN = "<ns2:ReturnType xmlns:ns2=\"http://test\"><return_str>" +
+ SoapMessageProvider.XML_SWAREF_RESPONSE +
+ "</return_str>" +
+ SoapMessageProvider.SWAREF_REF +
+ "</ns2:ReturnType>";
public static String TEXT_XML_ATTACHMENT = "<myAttachment>Hello World</myAttachment>";
- public static String ID = "cid123";
+ public static String ID = "helloWorld123";
+
+ public static String MTOM_REF = "<data>" +
+ "<xop:Include href='" + ID + "' xmlns:xop='http://www.w3.org/2004/08/xop/include' />" +
+ "</data>";
+ public static String SWAREF_REF = "<data>" +
+ "cid:" + ID +
+ "</data>";
+
+
public SOAPMessage invoke(SOAPMessage soapMessage) {
System.out.println(">> SoapMessageProvider: Request received.");
try{
// Look at the incoming request message
- System.out.println(">> Request on Server:");
- soapMessage.writeTo(System.out);
- System.out.println("\n");
+ //System.out.println(">> Request on Server:");
+ //soapMessage.writeTo(System.out);
+ //System.out.println("\n");
- // Get the data element. This performs basic assertions on the received message
- SOAPElement dataElement = assertRequestXML(soapMessage);
+ // Get the discrimination element. This performs basic assertions on the received message
+ SOAPElement discElement = assertRequestXML(soapMessage);
// Use the data element text to determine the type of response to send
SOAPMessage response = null;
// TODO AXIS2 SAAJ should (but does not) support the getTextContent();
// String text = dataElement.getTextContent();
- String text = dataElement.getValue();
+ String text = discElement.getValue();
if (XML_REQUEST.equals(text)) {
- response = getXMLResponse(soapMessage, dataElement);
+ response = getXMLResponse(soapMessage, discElement);
} else if (XML_ATTACHMENT_REQUEST.equals(text)) {
- response = getXMLAttachmentResponse(soapMessage, dataElement);
+ response = getXMLAttachmentResponse(soapMessage, discElement);
+ } else if (XML_MTOM_REQUEST.equals(text)) {
+ response = getXMLMTOMResponse(soapMessage, discElement);
+ } else if (XML_SWAREF_REQUEST.equals(text)) {
+ response = getXMLSWARefResponse(soapMessage, discElement);
} else {
// We should not get here
+ System.out.println("Unknown Type of Message");
assert(false);
}
// Write out the Message
System.out.println(">> Response being sent by Server:");
- response.writeTo(System.out);
- System.out.println("\n");
+ //response.writeTo(System.out);
+ //System.out.println("\n");
return response;
}catch(Exception e){
System.out.println("***ERROR: In SoapMessageProvider.invoke: Caught exception " + e);
@@ -104,15 +142,16 @@
assert(invokeElement instanceof SOAPElement);
assert(SoapMessageProvider.RESPONSE_NAME.equals(invokeElement.getLocalName()));
- Node dataElement = (Node) invokeElement.getFirstChild();
- assert(dataElement instanceof SOAPElement);
- assert(SoapMessageProvider.RESPONSE_DATA_NAME.equals(dataElement.getLocalName()));
+ Node discElement = (Node) invokeElement.getFirstChild();
+ assert(discElement instanceof SOAPElement);
+ assert(SoapMessageProvider.RESPONSE_DATA_NAME.equals(discElement.getLocalName()));
- String text = dataElement.getValue();
+ String text = discElement.getValue();
assert(text != null);
assert(text.length() > 0);
+ System.out.println("Request Message Type is:" + text);
- return (SOAPElement) dataElement;
+ return (SOAPElement) discElement;
}
/**
@@ -129,7 +168,7 @@
// Build the Response
MessageFactory factory = MessageFactory.newInstance();
- String responseXML = responseMsgStart + XML_RESPONSE + responseMsgEnd;
+ String responseXML = responseMsgStart + XML_RETURN + responseMsgEnd;
response = factory.createMessage(null, new ByteArrayInputStream(responseXML.getBytes()));
return response;
@@ -152,7 +191,67 @@
// Build the Response
MessageFactory factory = MessageFactory.newInstance();
- String responseXML = responseMsgStart + XML_ATTACHMENT_RESPONSE + responseMsgEnd;
+ String responseXML = responseMsgStart + ATTACHMENT_RETURN + responseMsgEnd;
+ response = factory.createMessage(null, new ByteArrayInputStream(responseXML.getBytes()));
+
+ // Create and attach the attachment
+ AttachmentPart ap = response.createAttachmentPart(SoapMessageProvider.TEXT_XML_ATTACHMENT, "text/xml");
+ ap.setContentId(ID);
+ response.addAttachmentPart(ap);
+
+ return response;
+ }
+
+ /**
+ * Get the response for an XML and an MTOM Attachment request
+ * @param request
+ * @param dataElement
+ * @return SOAPMessage
+ */
+ private SOAPMessage getXMLMTOMResponse(SOAPMessage request, SOAPElement dataElement) throws Exception {
+ SOAPMessage response;
+
+ System.out.println("Received MTOM Message");
+ // Additional assertion checks
+ assert(countAttachments(request) == 1);
+ AttachmentPart requestAP = (AttachmentPart) request.getAttachments().next();
+ String content = (String) requestAP.getContent();
+ assert(SoapMessageProvider.TEXT_XML_ATTACHMENT.equals(content));
+
+ System.out.println("The MTOM Request Message appears correct.");
+
+ // Build the Response
+ MessageFactory factory = MessageFactory.newInstance();
+ String responseXML = responseMsgStart + MTOM_RETURN + responseMsgEnd;
+ response = factory.createMessage(null, new ByteArrayInputStream(responseXML.getBytes()));
+
+ // Create and attach the attachment
+ AttachmentPart ap = response.createAttachmentPart(SoapMessageProvider.TEXT_XML_ATTACHMENT, "text/xml");
+ ap.setContentId(ID);
+ response.addAttachmentPart(ap);
+
+ System.out.println("Returning the Response Message");
+ return response;
+ }
+
+ /**
+ * Get the response for an XML and an MTOM Attachment request
+ * @param request
+ * @param dataElement
+ * @return SOAPMessage
+ */
+ private SOAPMessage getXMLSWARefResponse(SOAPMessage request, SOAPElement dataElement) throws Exception {
+ SOAPMessage response;
+
+ // Additional assertion checks
+ assert(countAttachments(request) == 1);
+ AttachmentPart requestAP = (AttachmentPart) request.getAttachments().next();
+ String content = (String) requestAP.getContent();
+ assert(SoapMessageProvider.TEXT_XML_ATTACHMENT.equals(content));
+
+ // Build the Response
+ MessageFactory factory = MessageFactory.newInstance();
+ String responseXML = responseMsgStart + SWAREF_RETURN + responseMsgEnd;
response = factory.createMessage(null, new ByteArrayInputStream(responseXML.getBytes()));
// Create and attach the attachment
---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org