You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by ch...@apache.org on 2006/02/22 00:40:29 UTC
svn commit: r379627 [20/34] - in /incubator/servicemix/trunk: ./ etc/
sandbox/servicemix-wsn-1.2/src/sa/META-INF/
sandbox/servicemix-wsn-1.2/src/su/META-INF/ servicemix-assembly/
servicemix-assembly/src/main/assembly/ servicemix-assembly/src/main/relea...
Modified: incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/handlers/AbstractHandler.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/handlers/AbstractHandler.java?rev=379627&r1=379626&r2=379627&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/handlers/AbstractHandler.java (original)
+++ incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/handlers/AbstractHandler.java Tue Feb 21 15:40:05 2006
@@ -1,35 +1,35 @@
-/*
- * Copyright 2005-2006 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.servicemix.soap.handlers;
-
-import org.apache.servicemix.soap.Context;
-import org.apache.servicemix.soap.Handler;
-
-/**
- *
- * @author Guillaume Nodet
- * @version $Revision: 1.5 $
- * @since 3.0
- */
-public abstract class AbstractHandler implements Handler {
-
- public void onComplete(Context context) {
- }
-
- public void onException(Context context, Exception e) {
- }
-
-}
+/*
+ * Copyright 2005-2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicemix.soap.handlers;
+
+import org.apache.servicemix.soap.Context;
+import org.apache.servicemix.soap.Handler;
+
+/**
+ *
+ * @author Guillaume Nodet
+ * @version $Revision: 1.5 $
+ * @since 3.0
+ */
+public abstract class AbstractHandler implements Handler {
+
+ public void onComplete(Context context) {
+ }
+
+ public void onException(Context context, Exception e) {
+ }
+
+}
Propchange: incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/handlers/AbstractHandler.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/handlers/AddressingInHandler.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/handlers/AddressingInHandler.java?rev=379627&r1=379626&r2=379627&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/handlers/AddressingInHandler.java (original)
+++ incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/handlers/AddressingInHandler.java Tue Feb 21 15:40:05 2006
@@ -1,107 +1,107 @@
-/*
- * Copyright 2005-2006 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.servicemix.soap.handlers;
-
-import java.util.Iterator;
-import java.util.Map;
-
-import javax.xml.namespace.QName;
-
-import org.apache.servicemix.jbi.util.DOMUtil;
-import org.apache.servicemix.soap.Context;
-import org.apache.servicemix.soap.SoapFault;
-import org.apache.servicemix.soap.marshalers.SoapMessage;
-import org.w3c.dom.DocumentFragment;
-import org.w3c.dom.Element;
-
-/**
- *
- * @author Guillaume Nodet
- * @version $Revision: 1.5 $
- * @since 3.0
- */
-public class AddressingInHandler extends AbstractHandler {
-
- public static final String WSA_NAMESPACE_200303 = "http://schemas.xmlsoap.org/ws/2003/03/addressing";
- public static final String WSA_NAMESPACE_200408 = "http://schemas.xmlsoap.org/ws/2004/08/addressing";
- public static final String WSA_NAMESPACE_200508 = "http://www.w3.org/2005/08/addressing";
-
- public static final String EL_ACTION = "Action";
- public static final String EL_ADDRESS = "Address";
- public static final String EL_FAULT_TO = "FaultTo";
- public static final String EL_FROM = "From";
- public static final String EL_MESSAGE_ID = "MessageID";
- public static final String EL_METADATA = "Metadata";
- public static final String EL_REFERENCE_PARAMETERS = "ReferenceParameters";
- public static final String EL_RELATES_TO = "RelatesTo";
- public static final String EL_REPLY_TO = "ReplyTo";
- public static final String EL_TO = "To";
-
- public void process(Context context) throws Exception {
- SoapMessage message = (SoapMessage) context.getProperty(Context.SOAP_MESSAGE);
- String action = null;
- String to = null;
- String nsUri = null;
- Map headers = message.getHeaders();
- if (headers != null) {
- for (Iterator it = headers.keySet().iterator(); it.hasNext();) {
- QName qname = (QName) it.next();
- Object value = headers.get(qname);
- if (WSA_NAMESPACE_200303.equals(qname.getNamespaceURI()) ||
- WSA_NAMESPACE_200408.equals(qname.getNamespaceURI()) ||
- WSA_NAMESPACE_200508.equals(qname.getNamespaceURI())) {
- if (nsUri == null) {
- nsUri = qname.getNamespaceURI();
- } else if (!nsUri.equals(qname.getNamespaceURI())) {
- throw new SoapFault(SoapFault.SENDER, "Inconsistent use of wsa namespaces");
- }
- if (qname.getLocalPart().equals(AddressingInHandler.EL_ACTION)) {
- Element el = (Element) ((DocumentFragment) value).getFirstChild();
- action = DOMUtil.getElementText(el);
- String[] parts = split(action);
- context.setProperty(Context.INTERFACE, new QName(parts[0], parts[1]));
- context.setProperty(Context.OPERATION, new QName(parts[0], parts[2]));
- } else if (qname.getLocalPart().equals(AddressingInHandler.EL_TO)) {
- Element el = (Element) ((DocumentFragment) value).getFirstChild();
- to = DOMUtil.getElementText(el);
- String[] parts = split(to);
- context.setProperty(Context.SERVICE, new QName(parts[0], parts[1]));
- context.setProperty(Context.ENDPOINT, parts[2]);
- } else {
- // TODO: what ?
- }
- }
- }
- }
- }
-
- protected String[] split(String uri) {
- char sep;
- uri = uri.trim();
- if (uri.indexOf('/') > 0) {
- sep = '/';
- } else {
- sep = ':';
- }
- int idx1 = uri.lastIndexOf(sep);
- int idx2 = uri.lastIndexOf(sep, idx1 - 1);
- String epName = uri.substring(idx1 + 1);
- String svcName = uri.substring(idx2 + 1, idx1);
- String nsUri = uri.substring(0, idx2);
- return new String[] { nsUri, svcName, epName };
- }
-
-}
+/*
+ * Copyright 2005-2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicemix.soap.handlers;
+
+import java.util.Iterator;
+import java.util.Map;
+
+import javax.xml.namespace.QName;
+
+import org.apache.servicemix.jbi.util.DOMUtil;
+import org.apache.servicemix.soap.Context;
+import org.apache.servicemix.soap.SoapFault;
+import org.apache.servicemix.soap.marshalers.SoapMessage;
+import org.w3c.dom.DocumentFragment;
+import org.w3c.dom.Element;
+
+/**
+ *
+ * @author Guillaume Nodet
+ * @version $Revision: 1.5 $
+ * @since 3.0
+ */
+public class AddressingInHandler extends AbstractHandler {
+
+ public static final String WSA_NAMESPACE_200303 = "http://schemas.xmlsoap.org/ws/2003/03/addressing";
+ public static final String WSA_NAMESPACE_200408 = "http://schemas.xmlsoap.org/ws/2004/08/addressing";
+ public static final String WSA_NAMESPACE_200508 = "http://www.w3.org/2005/08/addressing";
+
+ public static final String EL_ACTION = "Action";
+ public static final String EL_ADDRESS = "Address";
+ public static final String EL_FAULT_TO = "FaultTo";
+ public static final String EL_FROM = "From";
+ public static final String EL_MESSAGE_ID = "MessageID";
+ public static final String EL_METADATA = "Metadata";
+ public static final String EL_REFERENCE_PARAMETERS = "ReferenceParameters";
+ public static final String EL_RELATES_TO = "RelatesTo";
+ public static final String EL_REPLY_TO = "ReplyTo";
+ public static final String EL_TO = "To";
+
+ public void process(Context context) throws Exception {
+ SoapMessage message = (SoapMessage) context.getProperty(Context.SOAP_MESSAGE);
+ String action = null;
+ String to = null;
+ String nsUri = null;
+ Map headers = message.getHeaders();
+ if (headers != null) {
+ for (Iterator it = headers.keySet().iterator(); it.hasNext();) {
+ QName qname = (QName) it.next();
+ Object value = headers.get(qname);
+ if (WSA_NAMESPACE_200303.equals(qname.getNamespaceURI()) ||
+ WSA_NAMESPACE_200408.equals(qname.getNamespaceURI()) ||
+ WSA_NAMESPACE_200508.equals(qname.getNamespaceURI())) {
+ if (nsUri == null) {
+ nsUri = qname.getNamespaceURI();
+ } else if (!nsUri.equals(qname.getNamespaceURI())) {
+ throw new SoapFault(SoapFault.SENDER, "Inconsistent use of wsa namespaces");
+ }
+ if (qname.getLocalPart().equals(AddressingInHandler.EL_ACTION)) {
+ Element el = (Element) ((DocumentFragment) value).getFirstChild();
+ action = DOMUtil.getElementText(el);
+ String[] parts = split(action);
+ context.setProperty(Context.INTERFACE, new QName(parts[0], parts[1]));
+ context.setProperty(Context.OPERATION, new QName(parts[0], parts[2]));
+ } else if (qname.getLocalPart().equals(AddressingInHandler.EL_TO)) {
+ Element el = (Element) ((DocumentFragment) value).getFirstChild();
+ to = DOMUtil.getElementText(el);
+ String[] parts = split(to);
+ context.setProperty(Context.SERVICE, new QName(parts[0], parts[1]));
+ context.setProperty(Context.ENDPOINT, parts[2]);
+ } else {
+ // TODO: what ?
+ }
+ }
+ }
+ }
+ }
+
+ protected String[] split(String uri) {
+ char sep;
+ uri = uri.trim();
+ if (uri.indexOf('/') > 0) {
+ sep = '/';
+ } else {
+ sep = ':';
+ }
+ int idx1 = uri.lastIndexOf(sep);
+ int idx2 = uri.lastIndexOf(sep, idx1 - 1);
+ String epName = uri.substring(idx1 + 1);
+ String svcName = uri.substring(idx2 + 1, idx1);
+ String nsUri = uri.substring(0, idx2);
+ return new String[] { nsUri, svcName, epName };
+ }
+
+}
Propchange: incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/handlers/AddressingInHandler.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/marshalers/JBIMarshaler.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/marshalers/JBIMarshaler.java?rev=379627&r1=379626&r2=379627&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/marshalers/JBIMarshaler.java (original)
+++ incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/marshalers/JBIMarshaler.java Tue Feb 21 15:40:05 2006
@@ -1,69 +1,69 @@
-/*
- * Copyright 2005-2006 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.servicemix.soap.marshalers;
-
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Set;
-
-import javax.activation.DataHandler;
-import javax.jbi.messaging.NormalizedMessage;
-import javax.xml.namespace.QName;
-
-import org.apache.servicemix.JbiConstants;
-import org.w3c.dom.DocumentFragment;
-
-/**
- *
- * @author Guillaume Nodet
- * @version $Revision: 1.5 $
- * @since 3.0
- */
-public class JBIMarshaler {
-
- public void toNMS(NormalizedMessage normalizedMessage, SoapMessage soapMessage) throws Exception {
- if (soapMessage.hasHeaders()) {
- normalizedMessage.setProperty(JbiConstants.SOAP_HEADERS, soapMessage.getHeaders());
- }
- if (soapMessage.hasAttachments()) {
- Map attachments = soapMessage.getAttachments();
- for (Iterator it = attachments.entrySet().iterator(); it.hasNext();) {
- Map.Entry entry = (Map.Entry) it.next();
- normalizedMessage.addAttachment((String) entry.getKey(),
- (DataHandler) entry.getValue());
- }
- }
- normalizedMessage.setContent(soapMessage.getSource());
- }
-
- public void fromNMS(SoapMessage soapMessage, NormalizedMessage normalizedMessage) {
- if (normalizedMessage.getProperty(JbiConstants.SOAP_HEADERS) != null) {
- Map headers = (Map) normalizedMessage.getProperty(JbiConstants.SOAP_HEADERS);
- for (Iterator it = headers.entrySet().iterator(); it.hasNext();) {
- Map.Entry entry = (Map.Entry) it.next();
- soapMessage.addHeader((QName) entry.getKey(), (DocumentFragment) entry.getValue());
- }
- }
- Set attachmentNames = normalizedMessage.getAttachmentNames();
- for (Iterator it = attachmentNames.iterator(); it.hasNext();) {
- String id = (String) it.next();
- DataHandler handler = normalizedMessage.getAttachment(id);
- soapMessage.addAttachment(id, handler);
- }
- soapMessage.setSource(normalizedMessage.getContent());
- }
-
-}
+/*
+ * Copyright 2005-2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicemix.soap.marshalers;
+
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
+import javax.activation.DataHandler;
+import javax.jbi.messaging.NormalizedMessage;
+import javax.xml.namespace.QName;
+
+import org.apache.servicemix.JbiConstants;
+import org.w3c.dom.DocumentFragment;
+
+/**
+ *
+ * @author Guillaume Nodet
+ * @version $Revision: 1.5 $
+ * @since 3.0
+ */
+public class JBIMarshaler {
+
+ public void toNMS(NormalizedMessage normalizedMessage, SoapMessage soapMessage) throws Exception {
+ if (soapMessage.hasHeaders()) {
+ normalizedMessage.setProperty(JbiConstants.SOAP_HEADERS, soapMessage.getHeaders());
+ }
+ if (soapMessage.hasAttachments()) {
+ Map attachments = soapMessage.getAttachments();
+ for (Iterator it = attachments.entrySet().iterator(); it.hasNext();) {
+ Map.Entry entry = (Map.Entry) it.next();
+ normalizedMessage.addAttachment((String) entry.getKey(),
+ (DataHandler) entry.getValue());
+ }
+ }
+ normalizedMessage.setContent(soapMessage.getSource());
+ }
+
+ public void fromNMS(SoapMessage soapMessage, NormalizedMessage normalizedMessage) {
+ if (normalizedMessage.getProperty(JbiConstants.SOAP_HEADERS) != null) {
+ Map headers = (Map) normalizedMessage.getProperty(JbiConstants.SOAP_HEADERS);
+ for (Iterator it = headers.entrySet().iterator(); it.hasNext();) {
+ Map.Entry entry = (Map.Entry) it.next();
+ soapMessage.addHeader((QName) entry.getKey(), (DocumentFragment) entry.getValue());
+ }
+ }
+ Set attachmentNames = normalizedMessage.getAttachmentNames();
+ for (Iterator it = attachmentNames.iterator(); it.hasNext();) {
+ String id = (String) it.next();
+ DataHandler handler = normalizedMessage.getAttachment(id);
+ soapMessage.addAttachment(id, handler);
+ }
+ soapMessage.setSource(normalizedMessage.getContent());
+ }
+
+}
Propchange: incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/marshalers/JBIMarshaler.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/marshalers/SoapMarshaler.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/marshalers/SoapMarshaler.java?rev=379627&r1=379626&r2=379627&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/marshalers/SoapMarshaler.java (original)
+++ incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/marshalers/SoapMarshaler.java Tue Feb 21 15:40:05 2006
@@ -1,121 +1,121 @@
-/*
- * Copyright 2005-2006 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.servicemix.soap.marshalers;
-
-import javax.xml.stream.XMLInputFactory;
-import javax.xml.stream.XMLOutputFactory;
-
-import org.apache.servicemix.jbi.jaxp.StAXSourceTransformer;
-
-/**
- *
- * @author Guillaume Nodet
- * @version $Revision: 359186 $
- * @since 3.0
- */
-public class SoapMarshaler {
-
- public static final String MULTIPART_CONTENT = "multipart/related";
- public static final String SOAP_PART_ID = "soap-request";
- public static final String SOAP_11_URI = "http://schemas.xmlsoap.org/soap/envelope/";
- public static final String SOAP_12_URI = "http://www.w3.org/2003/05/soap-envelope";
- public static final String SOAP_PREFIX = "env";
- public static final String ENVELOPE = "Envelope";
- public static final String HEADER = "Header";
- public static final String BODY = "Body";
- public static final String FAULT = "Fault";
-
- protected XMLInputFactory inputFactory;
- protected XMLOutputFactory outputFactory;
- protected StAXSourceTransformer sourceTransformer;
- protected boolean repairingNamespace;
- protected String prefix = SOAP_PREFIX;
- protected boolean soap = true;
- protected String soapUri = SOAP_12_URI;
-
- public SoapMarshaler() {
- }
-
- public SoapMarshaler(boolean soap) {
- this.soap = soap;
- }
-
- public XMLInputFactory getInputFactory() {
- if (inputFactory == null) {
- inputFactory = XMLInputFactory.newInstance();
- inputFactory.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, Boolean.TRUE);
- }
- return inputFactory;
- }
-
- public XMLOutputFactory getOutputFactory() {
- if (outputFactory == null) {
- outputFactory = XMLOutputFactory.newInstance();
- if (isRepairingNamespace()) {
- outputFactory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES,
- Boolean.valueOf(isRepairingNamespace()));
- }
- }
- return outputFactory;
- }
-
- public StAXSourceTransformer getSourceTransformer() {
- if (sourceTransformer == null) {
- sourceTransformer = new StAXSourceTransformer();
- }
- return sourceTransformer;
- }
-
- public boolean isRepairingNamespace() {
- return repairingNamespace;
- }
-
- public void setRepairingNamespace(boolean repairingNamespace) {
- this.repairingNamespace = repairingNamespace;
- }
-
- public boolean isSoap() {
- return soap;
- }
-
- public void setSoap(boolean soap) {
- this.soap = soap;
- }
-
- public String getPrefix() {
- return prefix;
- }
-
- public void setPrefix(String prefix) {
- this.prefix = prefix;
- }
-
- public String getSoapUri() {
- return soapUri;
- }
-
- public void setSoapUri(String soapUri) {
- this.soapUri = soapUri;
- }
-
- public SoapReader createReader() {
- return new SoapReader(this);
- }
-
- public SoapWriter createWriter(SoapMessage message) {
- return new SoapWriter(this, message);
- }
-}
+/*
+ * Copyright 2005-2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicemix.soap.marshalers;
+
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLOutputFactory;
+
+import org.apache.servicemix.jbi.jaxp.StAXSourceTransformer;
+
+/**
+ *
+ * @author Guillaume Nodet
+ * @version $Revision: 359186 $
+ * @since 3.0
+ */
+public class SoapMarshaler {
+
+ public static final String MULTIPART_CONTENT = "multipart/related";
+ public static final String SOAP_PART_ID = "soap-request";
+ public static final String SOAP_11_URI = "http://schemas.xmlsoap.org/soap/envelope/";
+ public static final String SOAP_12_URI = "http://www.w3.org/2003/05/soap-envelope";
+ public static final String SOAP_PREFIX = "env";
+ public static final String ENVELOPE = "Envelope";
+ public static final String HEADER = "Header";
+ public static final String BODY = "Body";
+ public static final String FAULT = "Fault";
+
+ protected XMLInputFactory inputFactory;
+ protected XMLOutputFactory outputFactory;
+ protected StAXSourceTransformer sourceTransformer;
+ protected boolean repairingNamespace;
+ protected String prefix = SOAP_PREFIX;
+ protected boolean soap = true;
+ protected String soapUri = SOAP_12_URI;
+
+ public SoapMarshaler() {
+ }
+
+ public SoapMarshaler(boolean soap) {
+ this.soap = soap;
+ }
+
+ public XMLInputFactory getInputFactory() {
+ if (inputFactory == null) {
+ inputFactory = XMLInputFactory.newInstance();
+ inputFactory.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, Boolean.TRUE);
+ }
+ return inputFactory;
+ }
+
+ public XMLOutputFactory getOutputFactory() {
+ if (outputFactory == null) {
+ outputFactory = XMLOutputFactory.newInstance();
+ if (isRepairingNamespace()) {
+ outputFactory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES,
+ Boolean.valueOf(isRepairingNamespace()));
+ }
+ }
+ return outputFactory;
+ }
+
+ public StAXSourceTransformer getSourceTransformer() {
+ if (sourceTransformer == null) {
+ sourceTransformer = new StAXSourceTransformer();
+ }
+ return sourceTransformer;
+ }
+
+ public boolean isRepairingNamespace() {
+ return repairingNamespace;
+ }
+
+ public void setRepairingNamespace(boolean repairingNamespace) {
+ this.repairingNamespace = repairingNamespace;
+ }
+
+ public boolean isSoap() {
+ return soap;
+ }
+
+ public void setSoap(boolean soap) {
+ this.soap = soap;
+ }
+
+ public String getPrefix() {
+ return prefix;
+ }
+
+ public void setPrefix(String prefix) {
+ this.prefix = prefix;
+ }
+
+ public String getSoapUri() {
+ return soapUri;
+ }
+
+ public void setSoapUri(String soapUri) {
+ this.soapUri = soapUri;
+ }
+
+ public SoapReader createReader() {
+ return new SoapReader(this);
+ }
+
+ public SoapWriter createWriter(SoapMessage message) {
+ return new SoapWriter(this, message);
+ }
+}
Propchange: incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/marshalers/SoapMarshaler.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/marshalers/SoapMessage.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/marshalers/SoapMessage.java?rev=379627&r1=379626&r2=379627&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/marshalers/SoapMessage.java (original)
+++ incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/marshalers/SoapMessage.java Tue Feb 21 15:40:05 2006
@@ -1,103 +1,103 @@
-/*
- * Copyright 2005-2006 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.servicemix.soap.marshalers;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import javax.activation.DataHandler;
-import javax.xml.namespace.QName;
-import javax.xml.transform.Source;
-
-import org.apache.servicemix.soap.SoapFault;
-import org.w3c.dom.DocumentFragment;
-
-/**
- * Simple DTO to hold attachments, soap headers and main xml source.
- *
- * @author Guillaume Nodet
- * @version $Revision: 359186 $
- * @since 3.0
- */
-public class SoapMessage {
-
- private QName envelopeName;
- private QName bodyName;
- private Source source;
- private Map attachments;
- private Map headers;
- private SoapFault fault;
-
- public Map getAttachments() {
- return attachments;
- }
- public void setAttachments(Map attachments) {
- this.attachments = attachments;
- }
- public void addAttachment(String name, DataHandler handler) {
- if (this.attachments == null) {
- this.attachments = new HashMap();
- }
- this.attachments.put(name, handler);
- }
- public boolean hasAttachments() {
- return attachments != null && attachments.size() > 0;
- }
-
- public Map getHeaders() {
- return headers;
- }
- public void setHeaders(Map headers) {
- this.headers = headers;
- }
- public void addHeader(QName name, DocumentFragment header) {
- if (this.headers == null) {
- this.headers = new HashMap();
- }
- this.headers.put(name, header);
- }
- public boolean hasHeaders() {
- return headers != null && headers.size() > 0;
- }
-
- public Source getSource() {
- return source;
- }
- public void setSource(Source source) {
- this.source = source;
- }
-
- public QName getEnvelopeName() {
- return envelopeName;
- }
- public void setEnvelopeName(QName envelopeName) {
- this.envelopeName = envelopeName;
- }
- public QName getBodyName() {
- return bodyName;
- }
- public void setBodyName(QName bodyName) {
- this.bodyName = bodyName;
- }
-
- public SoapFault getFault() {
- return fault;
- }
- public void setFault(SoapFault fault) {
- this.fault = fault;
- }
-
-}
+/*
+ * Copyright 2005-2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicemix.soap.marshalers;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.activation.DataHandler;
+import javax.xml.namespace.QName;
+import javax.xml.transform.Source;
+
+import org.apache.servicemix.soap.SoapFault;
+import org.w3c.dom.DocumentFragment;
+
+/**
+ * Simple DTO to hold attachments, soap headers and main xml source.
+ *
+ * @author Guillaume Nodet
+ * @version $Revision: 359186 $
+ * @since 3.0
+ */
+public class SoapMessage {
+
+ private QName envelopeName;
+ private QName bodyName;
+ private Source source;
+ private Map attachments;
+ private Map headers;
+ private SoapFault fault;
+
+ public Map getAttachments() {
+ return attachments;
+ }
+ public void setAttachments(Map attachments) {
+ this.attachments = attachments;
+ }
+ public void addAttachment(String name, DataHandler handler) {
+ if (this.attachments == null) {
+ this.attachments = new HashMap();
+ }
+ this.attachments.put(name, handler);
+ }
+ public boolean hasAttachments() {
+ return attachments != null && attachments.size() > 0;
+ }
+
+ public Map getHeaders() {
+ return headers;
+ }
+ public void setHeaders(Map headers) {
+ this.headers = headers;
+ }
+ public void addHeader(QName name, DocumentFragment header) {
+ if (this.headers == null) {
+ this.headers = new HashMap();
+ }
+ this.headers.put(name, header);
+ }
+ public boolean hasHeaders() {
+ return headers != null && headers.size() > 0;
+ }
+
+ public Source getSource() {
+ return source;
+ }
+ public void setSource(Source source) {
+ this.source = source;
+ }
+
+ public QName getEnvelopeName() {
+ return envelopeName;
+ }
+ public void setEnvelopeName(QName envelopeName) {
+ this.envelopeName = envelopeName;
+ }
+ public QName getBodyName() {
+ return bodyName;
+ }
+ public void setBodyName(QName bodyName) {
+ this.bodyName = bodyName;
+ }
+
+ public SoapFault getFault() {
+ return fault;
+ }
+ public void setFault(SoapFault fault) {
+ this.fault = fault;
+ }
+
+}
Propchange: incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/marshalers/SoapMessage.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/marshalers/SoapReader.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/marshalers/SoapReader.java?rev=379627&r1=379626&r2=379627&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/marshalers/SoapReader.java (original)
+++ incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/marshalers/SoapReader.java Tue Feb 21 15:40:05 2006
@@ -1,162 +1,162 @@
-/*
- * Copyright 2005-2006 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.servicemix.soap.marshalers;
-
-import java.io.InputStream;
-import java.util.Properties;
-
-import javax.mail.Session;
-import javax.mail.internet.ContentType;
-import javax.mail.internet.MimeBodyPart;
-import javax.mail.internet.MimeMessage;
-import javax.mail.internet.MimeMultipart;
-import javax.xml.namespace.QName;
-import javax.xml.stream.XMLStreamConstants;
-import javax.xml.stream.XMLStreamReader;
-import javax.xml.transform.stream.StreamSource;
-
-import org.apache.servicemix.jbi.jaxp.ExtendedXMLStreamReader;
-import org.apache.servicemix.jbi.jaxp.FragmentStreamReader;
-import org.apache.servicemix.jbi.jaxp.StaxSource;
-import org.apache.servicemix.soap.SoapFault;
-import org.w3c.dom.Document;
-import org.w3c.dom.DocumentFragment;
-
-/**
- *
- * @author Guillaume Nodet
- * @version $Revision: 1.5 $
- * @since 3.0
- */
-public class SoapReader {
-
- private SoapMarshaler marshaler;
-
- public SoapReader(SoapMarshaler marshaler) {
- this.marshaler = marshaler;
- }
-
- public SoapMessage read(InputStream is, String contentType)
- throws Exception {
- if (contentType != null && contentType.toLowerCase().indexOf(SoapMarshaler.MULTIPART_CONTENT) != -1) {
- Session session = Session.getDefaultInstance(new Properties());
- MimeMessage mime = new MimeMessage(session, is);
- mime.setHeader("Content-Type", contentType);
- return read(mime);
- } else {
- return read(is);
- }
- }
-
- public SoapMessage read(InputStream is) throws Exception {
- if (marshaler.isSoap()) {
- return readSoap(is);
- } else {
- SoapMessage message = new SoapMessage();
- message.setSource(new StreamSource(is));
- return message;
- }
- }
-
- private SoapMessage readSoap(InputStream is) throws Exception {
- SoapMessage message = new SoapMessage();
- XMLStreamReader reader = marshaler.getInputFactory().createXMLStreamReader(is);
- reader = new ExtendedXMLStreamReader(reader);
- reader.nextTag();
- // Check Envelope tag
- if (!reader.getLocalName().equals(SoapMarshaler.ENVELOPE)) {
- throw new SoapFault(SoapFault.SENDER, "Unrecognized element: "
- + reader.getName() + " at ["
- + reader.getLocation().getLineNumber() + ","
- + reader.getLocation().getColumnNumber()
- + "]. Expecting 'Envelope'.");
- }
- message.setEnvelopeName(reader.getName());
- // Check soap 1.1 or 1.2
- String soapUri = reader.getNamespaceURI();
- if (!SoapMarshaler.SOAP_11_URI.equals(soapUri) && !SoapMarshaler.SOAP_12_URI.equals(soapUri)) {
- throw new SoapFault(SoapFault.SENDER, "Unrecognized namespace: " + soapUri
- + " for element 'Envelope' at ["
- + reader.getLocation().getLineNumber() + ","
- + reader.getLocation().getColumnNumber()
- + "]. Expecting 'Envelope'.");
- }
- // Check Headers
- reader.nextTag();
- if (reader.getName().equals(new QName(soapUri, SoapMarshaler.HEADER))) {
- parseHeaders(message, reader);
- reader.nextTag();
- }
- // Check Body
- if (!reader.getName().equals(new QName(soapUri, SoapMarshaler.BODY))) {
- throw new SoapFault(SoapFault.SENDER, "Unrecognized element: "
- + reader.getName() + " at ["
- + reader.getLocation().getLineNumber() + ","
- + reader.getLocation().getColumnNumber()
- + "]. Expecting 'Body'.");
- }
- // Create Source for content
- if (reader.nextTag() != XMLStreamConstants.END_ELEMENT) {
- message.setBodyName(reader.getName());
- message.setSource(new StaxSource(new FragmentStreamReader(reader)));
- }
- return message;
- }
-
- private void parseHeaders(SoapMessage message, XMLStreamReader reader)
- throws Exception {
- while (reader.nextTag() != XMLStreamConstants.END_ELEMENT) {
- QName hn = reader.getName();
- FragmentStreamReader rh = new FragmentStreamReader(reader);
- Document doc = (Document) marshaler.getSourceTransformer().toDOMNode(
- new StaxSource(rh));
- DocumentFragment df = doc.createDocumentFragment();
- df.appendChild(doc.getDocumentElement());
- message.addHeader(hn, df);
- }
- }
-
- public SoapMessage read(MimeMessage mime) throws Exception {
- final Object content = mime.getContent();
- if (content instanceof MimeMultipart) {
- MimeMultipart multipart = (MimeMultipart) content;
- ContentType type = new ContentType(mime.getContentType());
- String contentId = type.getParameter("start");
- if (contentId == null) {
- contentId = ((MimeBodyPart) multipart.getBodyPart(0))
- .getContentID();
- }
- // Get request
- MimeBodyPart part = (MimeBodyPart) multipart.getBodyPart(contentId);
- SoapMessage message = read(part.getInputStream());
- for (int i = 0; i < multipart.getCount(); i++) {
- part = (MimeBodyPart) multipart.getBodyPart(i);
- String id = part.getContentID();
- if (id != null && !id.equals(contentId)) {
- if (id.startsWith("<")) {
- id = id.substring(1, id.length() - 1);
- }
- message.addAttachment(id, part.getDataHandler());
- }
- }
- return message;
- } else {
- throw new UnsupportedOperationException(
- "Expected a javax.mail.internet.MimeMultipart object");
- }
- }
-
-}
+/*
+ * Copyright 2005-2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicemix.soap.marshalers;
+
+import java.io.InputStream;
+import java.util.Properties;
+
+import javax.mail.Session;
+import javax.mail.internet.ContentType;
+import javax.mail.internet.MimeBodyPart;
+import javax.mail.internet.MimeMessage;
+import javax.mail.internet.MimeMultipart;
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.transform.stream.StreamSource;
+
+import org.apache.servicemix.jbi.jaxp.ExtendedXMLStreamReader;
+import org.apache.servicemix.jbi.jaxp.FragmentStreamReader;
+import org.apache.servicemix.jbi.jaxp.StaxSource;
+import org.apache.servicemix.soap.SoapFault;
+import org.w3c.dom.Document;
+import org.w3c.dom.DocumentFragment;
+
+/**
+ *
+ * @author Guillaume Nodet
+ * @version $Revision: 1.5 $
+ * @since 3.0
+ */
+public class SoapReader {
+
+ private SoapMarshaler marshaler;
+
+ public SoapReader(SoapMarshaler marshaler) {
+ this.marshaler = marshaler;
+ }
+
+ public SoapMessage read(InputStream is, String contentType)
+ throws Exception {
+ if (contentType != null && contentType.toLowerCase().indexOf(SoapMarshaler.MULTIPART_CONTENT) != -1) {
+ Session session = Session.getDefaultInstance(new Properties());
+ MimeMessage mime = new MimeMessage(session, is);
+ mime.setHeader("Content-Type", contentType);
+ return read(mime);
+ } else {
+ return read(is);
+ }
+ }
+
+ public SoapMessage read(InputStream is) throws Exception {
+ if (marshaler.isSoap()) {
+ return readSoap(is);
+ } else {
+ SoapMessage message = new SoapMessage();
+ message.setSource(new StreamSource(is));
+ return message;
+ }
+ }
+
+ private SoapMessage readSoap(InputStream is) throws Exception {
+ SoapMessage message = new SoapMessage();
+ XMLStreamReader reader = marshaler.getInputFactory().createXMLStreamReader(is);
+ reader = new ExtendedXMLStreamReader(reader);
+ reader.nextTag();
+ // Check Envelope tag
+ if (!reader.getLocalName().equals(SoapMarshaler.ENVELOPE)) {
+ throw new SoapFault(SoapFault.SENDER, "Unrecognized element: "
+ + reader.getName() + " at ["
+ + reader.getLocation().getLineNumber() + ","
+ + reader.getLocation().getColumnNumber()
+ + "]. Expecting 'Envelope'.");
+ }
+ message.setEnvelopeName(reader.getName());
+ // Check soap 1.1 or 1.2
+ String soapUri = reader.getNamespaceURI();
+ if (!SoapMarshaler.SOAP_11_URI.equals(soapUri) && !SoapMarshaler.SOAP_12_URI.equals(soapUri)) {
+ throw new SoapFault(SoapFault.SENDER, "Unrecognized namespace: " + soapUri
+ + " for element 'Envelope' at ["
+ + reader.getLocation().getLineNumber() + ","
+ + reader.getLocation().getColumnNumber()
+ + "]. Expecting 'Envelope'.");
+ }
+ // Check Headers
+ reader.nextTag();
+ if (reader.getName().equals(new QName(soapUri, SoapMarshaler.HEADER))) {
+ parseHeaders(message, reader);
+ reader.nextTag();
+ }
+ // Check Body
+ if (!reader.getName().equals(new QName(soapUri, SoapMarshaler.BODY))) {
+ throw new SoapFault(SoapFault.SENDER, "Unrecognized element: "
+ + reader.getName() + " at ["
+ + reader.getLocation().getLineNumber() + ","
+ + reader.getLocation().getColumnNumber()
+ + "]. Expecting 'Body'.");
+ }
+ // Create Source for content
+ if (reader.nextTag() != XMLStreamConstants.END_ELEMENT) {
+ message.setBodyName(reader.getName());
+ message.setSource(new StaxSource(new FragmentStreamReader(reader)));
+ }
+ return message;
+ }
+
+ private void parseHeaders(SoapMessage message, XMLStreamReader reader)
+ throws Exception {
+ while (reader.nextTag() != XMLStreamConstants.END_ELEMENT) {
+ QName hn = reader.getName();
+ FragmentStreamReader rh = new FragmentStreamReader(reader);
+ Document doc = (Document) marshaler.getSourceTransformer().toDOMNode(
+ new StaxSource(rh));
+ DocumentFragment df = doc.createDocumentFragment();
+ df.appendChild(doc.getDocumentElement());
+ message.addHeader(hn, df);
+ }
+ }
+
+ public SoapMessage read(MimeMessage mime) throws Exception {
+ final Object content = mime.getContent();
+ if (content instanceof MimeMultipart) {
+ MimeMultipart multipart = (MimeMultipart) content;
+ ContentType type = new ContentType(mime.getContentType());
+ String contentId = type.getParameter("start");
+ if (contentId == null) {
+ contentId = ((MimeBodyPart) multipart.getBodyPart(0))
+ .getContentID();
+ }
+ // Get request
+ MimeBodyPart part = (MimeBodyPart) multipart.getBodyPart(contentId);
+ SoapMessage message = read(part.getInputStream());
+ for (int i = 0; i < multipart.getCount(); i++) {
+ part = (MimeBodyPart) multipart.getBodyPart(i);
+ String id = part.getContentID();
+ if (id != null && !id.equals(contentId)) {
+ if (id.startsWith("<")) {
+ id = id.substring(1, id.length() - 1);
+ }
+ message.addAttachment(id, part.getDataHandler());
+ }
+ }
+ return message;
+ } else {
+ throw new UnsupportedOperationException(
+ "Expected a javax.mail.internet.MimeMultipart object");
+ }
+ }
+
+}
Propchange: incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/marshalers/SoapReader.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/marshalers/SoapWriter.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/marshalers/SoapWriter.java?rev=379627&r1=379626&r2=379627&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/marshalers/SoapWriter.java (original)
+++ incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/marshalers/SoapWriter.java Tue Feb 21 15:40:05 2006
@@ -1,258 +1,258 @@
-/*
- * Copyright 2005-2006 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.servicemix.soap.marshalers;
-
-import java.io.ByteArrayOutputStream;
-import java.io.OutputStream;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Properties;
-
-import javax.activation.DataHandler;
-import javax.mail.Session;
-import javax.mail.internet.MimeBodyPart;
-import javax.mail.internet.MimeMessage;
-import javax.mail.internet.MimeMultipart;
-import javax.xml.XMLConstants;
-import javax.xml.namespace.QName;
-import javax.xml.stream.XMLStreamReader;
-import javax.xml.stream.XMLStreamWriter;
-import javax.xml.transform.Source;
-
-import org.apache.servicemix.jbi.jaxp.W3CDOMStreamReader;
-import org.apache.servicemix.jbi.jaxp.XMLStreamHelper;
-import org.apache.servicemix.jbi.util.ByteArrayDataSource;
-import org.apache.servicemix.soap.SoapFault;
-import org.w3c.dom.DocumentFragment;
-import org.w3c.dom.Element;
-
-/**
- *
- * @author Guillaume Nodet
- * @version $Revision: 1.5 $
- * @since 3.0
- */
-public class SoapWriter {
-
- public static final String SOAP_PART_ID = "soap-request";
-
- private SoapMessage message;
-
- private String contentType;
-
- private SoapMarshaler marshaler;
-
- private MimeMultipart parts;
-
- public SoapWriter(SoapMarshaler marshaler, SoapMessage message) {
- this.marshaler = marshaler;
- this.message = message;
- this.contentType = prepare();
- }
-
- public String getContentType() {
- return contentType;
- }
-
- public void write(OutputStream out) throws Exception {
- if (message.hasAttachments()) {
- writeMultipartMessage(out);
- } else {
- writeSimpleMessage(out);
- }
- }
-
- private String prepare() {
- if (message.hasAttachments()) {
- parts = new MimeMultipart("related; type=\"text/xml\"; start=\"<" + SOAP_PART_ID + ">\"");
- return parts.getContentType();
- } else {
- return "text/xml";
- }
- }
-
- private void writeSimpleMessage(OutputStream out) throws Exception {
- XMLStreamWriter writer = marshaler.getOutputFactory().createXMLStreamWriter(out);
- writer.writeStartDocument();
- if (marshaler.isSoap()) {
- writeSoapEnvelope(writer);
- } else {
- if (message.hasHeaders()) {
- throw new IllegalStateException("SOAP headers found on non-soap message");
- }
- if (message.getFault() != null) {
- if (message.getFault().getDetails() != null) {
- XMLStreamReader reader = marshaler.getSourceTransformer().toXMLStreamReader(
- message.getFault().getDetails());
- XMLStreamHelper.copy(reader, writer, marshaler.isRepairingNamespace());
- } else {
- throw new IllegalStateException("Cannot write non xml faults for non soap messages");
- }
- } else if (message.getSource() != null) {
- writeContents(writer);
- }
- }
- writer.writeEndDocument();
- writer.flush();
- }
-
- private void writeMultipartMessage(OutputStream out) throws Exception {
- Session session = Session.getDefaultInstance(new Properties(), null);
- MimeMessage mime = new MimeMessage(session);
- // Add soap part
- MimeBodyPart soapPart = new MimeBodyPart();
- soapPart.setContentID("<" + SOAP_PART_ID + ">");
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- writeSimpleMessage(baos);
- soapPart.setDataHandler(new DataHandler(new ByteArrayDataSource(baos.toByteArray(), "text/xml")));
- parts.addBodyPart(soapPart);
- // Add attachments
- for (Iterator itr = message.getAttachments().entrySet().iterator(); itr.hasNext();) {
- Map.Entry entry = (Map.Entry) itr.next();
- String id = (String) entry.getKey();
- DataHandler dh = (DataHandler) entry.getValue();
- MimeBodyPart part = new MimeBodyPart();
- part.setDataHandler(dh);
- part.setContentID("<" + id + ">");
- parts.addBodyPart(part);
- }
- mime.setContent(parts);
- mime.writeTo(out);
- }
-
- private void writeSoapEnvelope(XMLStreamWriter writer) throws Exception {
- QName envelope = getEnvelopeName();
- String soapUri = envelope.getNamespaceURI();
- String soapPrefix = envelope.getPrefix();
- writer.setPrefix(soapPrefix, soapUri);
- writer.writeStartElement(soapPrefix, SoapMarshaler.ENVELOPE, soapUri);
- if (!marshaler.isRepairingNamespace()) {
- writer.writeNamespace(soapPrefix, soapUri);
- // XMLStreamHelper.writeNamespacesExcludingPrefixAndNamespace(out, in, soapPrefix, soapUri);
- }
- // Write Header
- if (message.getHeaders() != null && message.getHeaders().size() > 0) {
- writer.writeStartElement(soapPrefix, SoapMarshaler.HEADER, soapUri);
- for (Iterator it = message.getHeaders().values().iterator(); it.hasNext();) {
- DocumentFragment df = (DocumentFragment) it.next();
- Element e = (Element) df.getFirstChild();
- XMLStreamHelper.copy(new W3CDOMStreamReader(e), writer, marshaler.isRepairingNamespace());
- }
- writer.writeEndElement();
- }
- // Write Body
- writer.writeStartElement(soapPrefix, SoapMarshaler.BODY, soapUri);
- if (message.getFault() != null) {
- writeFault(writer);
- } else if (message.getSource() != null) {
- writeContents(writer);
- }
- writer.writeEndElement();
- writer.writeEndElement();
- }
-
- private void writeContents(XMLStreamWriter writer) throws Exception {
- XMLStreamReader reader = marshaler.getSourceTransformer().toXMLStreamReader(message.getSource());
- XMLStreamHelper.copy(reader, writer, marshaler.isRepairingNamespace());
- }
-
- private void writeFault(XMLStreamWriter writer) throws Exception {
- QName envelope = getEnvelopeName();
- String soapUri = envelope.getNamespaceURI();
- if (SoapMarshaler.SOAP_11_URI.equals(soapUri)) {
- writeSoap11Fault(writer);
- } else {
- writeSoap12Fault(writer);
- }
- }
-
- private void writeSoap11Fault(XMLStreamWriter writer) throws Exception {
- // TODO
- writeSoap12Fault(writer);
- }
-
- private void writeSoap12Fault(XMLStreamWriter writer) throws Exception {
- QName envelope = getEnvelopeName();
- String soapUri = envelope.getNamespaceURI();
- String soapPrefix = envelope.getPrefix();
- writer.setPrefix(soapPrefix, soapUri);
- SoapFault fault = message.getFault();
-
- writer.writeStartElement(soapPrefix, "Fault", soapUri);
- String code = fault.getCode();
- if (code != null) {
- writer.writeStartElement(soapPrefix, "Code", soapUri);
- writer.writeStartElement(soapPrefix, "Value", soapUri);
- writer.writeCharacters(soapPrefix + ":" + code);
- writer.writeEndElement();
- String subcode = fault.getSubcode();
- if (subcode != null) {
- writer.writeStartElement(soapPrefix, "Subcode", soapUri);
- writer.writeStartElement(soapPrefix, "Value", soapUri);
- writer.writeCharacters(subcode);
- writer.writeEndElement();
- writer.writeEndElement();
- }
- writer.writeEndElement();
- }
- String reason = fault.getReason();
- if (reason == null && fault.getCause() != null) {
- reason = fault.getCause().toString();
- }
- if (reason != null) {
- writer.writeStartElement(soapPrefix, "Reason", soapUri);
- writer.writeStartElement(soapPrefix, "Text", soapUri);
- writer.writeAttribute(XMLConstants.XML_NS_PREFIX, XMLConstants.XML_NS_URI, "lang", "en-US");
- writer.writeCharacters(reason);
- writer.writeEndElement();
- writer.writeEndElement();
- }
- String node = fault.getNode();
- if (node != null) {
- writer.writeStartElement(soapPrefix, "Node", soapUri);
- writer.writeCharacters(node);
- writer.writeEndElement();
- }
-
- String role = fault.getRole();
- if (role != null) {
- writer.writeStartElement(soapPrefix, "Role", soapUri);
- writer.writeCharacters(role);
- writer.writeEndElement();
- }
-
- Source details = fault.getDetails();
- if (details != null) {
- writer.writeStartElement(soapPrefix, "Details", soapUri);
- XMLStreamReader reader = marshaler.getSourceTransformer().toXMLStreamReader(details);
- XMLStreamHelper.copy(reader, writer, marshaler.isRepairingNamespace());
- writer.writeEndElement();
- }
-
- writer.writeEndElement();
- }
-
- protected QName getEnvelopeName() {
- QName name = message.getEnvelopeName();
- if (name == null) {
- name = new QName(marshaler.soapUri, SoapMarshaler.ENVELOPE, marshaler.prefix);
- } else if (name.getPrefix() == null) {
- name = new QName(name.getNamespaceURI(), name.getLocalPart(), marshaler.prefix);
- }
- return name;
- }
-
-}
+/*
+ * Copyright 2005-2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicemix.soap.marshalers;
+
+import java.io.ByteArrayOutputStream;
+import java.io.OutputStream;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Properties;
+
+import javax.activation.DataHandler;
+import javax.mail.Session;
+import javax.mail.internet.MimeBodyPart;
+import javax.mail.internet.MimeMessage;
+import javax.mail.internet.MimeMultipart;
+import javax.xml.XMLConstants;
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+import javax.xml.transform.Source;
+
+import org.apache.servicemix.jbi.jaxp.W3CDOMStreamReader;
+import org.apache.servicemix.jbi.jaxp.XMLStreamHelper;
+import org.apache.servicemix.jbi.util.ByteArrayDataSource;
+import org.apache.servicemix.soap.SoapFault;
+import org.w3c.dom.DocumentFragment;
+import org.w3c.dom.Element;
+
+/**
+ *
+ * @author Guillaume Nodet
+ * @version $Revision: 1.5 $
+ * @since 3.0
+ */
+public class SoapWriter {
+
+ public static final String SOAP_PART_ID = "soap-request";
+
+ private SoapMessage message;
+
+ private String contentType;
+
+ private SoapMarshaler marshaler;
+
+ private MimeMultipart parts;
+
+ public SoapWriter(SoapMarshaler marshaler, SoapMessage message) {
+ this.marshaler = marshaler;
+ this.message = message;
+ this.contentType = prepare();
+ }
+
+ public String getContentType() {
+ return contentType;
+ }
+
+ public void write(OutputStream out) throws Exception {
+ if (message.hasAttachments()) {
+ writeMultipartMessage(out);
+ } else {
+ writeSimpleMessage(out);
+ }
+ }
+
+ private String prepare() {
+ if (message.hasAttachments()) {
+ parts = new MimeMultipart("related; type=\"text/xml\"; start=\"<" + SOAP_PART_ID + ">\"");
+ return parts.getContentType();
+ } else {
+ return "text/xml";
+ }
+ }
+
+ private void writeSimpleMessage(OutputStream out) throws Exception {
+ XMLStreamWriter writer = marshaler.getOutputFactory().createXMLStreamWriter(out);
+ writer.writeStartDocument();
+ if (marshaler.isSoap()) {
+ writeSoapEnvelope(writer);
+ } else {
+ if (message.hasHeaders()) {
+ throw new IllegalStateException("SOAP headers found on non-soap message");
+ }
+ if (message.getFault() != null) {
+ if (message.getFault().getDetails() != null) {
+ XMLStreamReader reader = marshaler.getSourceTransformer().toXMLStreamReader(
+ message.getFault().getDetails());
+ XMLStreamHelper.copy(reader, writer, marshaler.isRepairingNamespace());
+ } else {
+ throw new IllegalStateException("Cannot write non xml faults for non soap messages");
+ }
+ } else if (message.getSource() != null) {
+ writeContents(writer);
+ }
+ }
+ writer.writeEndDocument();
+ writer.flush();
+ }
+
+ private void writeMultipartMessage(OutputStream out) throws Exception {
+ Session session = Session.getDefaultInstance(new Properties(), null);
+ MimeMessage mime = new MimeMessage(session);
+ // Add soap part
+ MimeBodyPart soapPart = new MimeBodyPart();
+ soapPart.setContentID("<" + SOAP_PART_ID + ">");
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ writeSimpleMessage(baos);
+ soapPart.setDataHandler(new DataHandler(new ByteArrayDataSource(baos.toByteArray(), "text/xml")));
+ parts.addBodyPart(soapPart);
+ // Add attachments
+ for (Iterator itr = message.getAttachments().entrySet().iterator(); itr.hasNext();) {
+ Map.Entry entry = (Map.Entry) itr.next();
+ String id = (String) entry.getKey();
+ DataHandler dh = (DataHandler) entry.getValue();
+ MimeBodyPart part = new MimeBodyPart();
+ part.setDataHandler(dh);
+ part.setContentID("<" + id + ">");
+ parts.addBodyPart(part);
+ }
+ mime.setContent(parts);
+ mime.writeTo(out);
+ }
+
+ private void writeSoapEnvelope(XMLStreamWriter writer) throws Exception {
+ QName envelope = getEnvelopeName();
+ String soapUri = envelope.getNamespaceURI();
+ String soapPrefix = envelope.getPrefix();
+ writer.setPrefix(soapPrefix, soapUri);
+ writer.writeStartElement(soapPrefix, SoapMarshaler.ENVELOPE, soapUri);
+ if (!marshaler.isRepairingNamespace()) {
+ writer.writeNamespace(soapPrefix, soapUri);
+ // XMLStreamHelper.writeNamespacesExcludingPrefixAndNamespace(out, in, soapPrefix, soapUri);
+ }
+ // Write Header
+ if (message.getHeaders() != null && message.getHeaders().size() > 0) {
+ writer.writeStartElement(soapPrefix, SoapMarshaler.HEADER, soapUri);
+ for (Iterator it = message.getHeaders().values().iterator(); it.hasNext();) {
+ DocumentFragment df = (DocumentFragment) it.next();
+ Element e = (Element) df.getFirstChild();
+ XMLStreamHelper.copy(new W3CDOMStreamReader(e), writer, marshaler.isRepairingNamespace());
+ }
+ writer.writeEndElement();
+ }
+ // Write Body
+ writer.writeStartElement(soapPrefix, SoapMarshaler.BODY, soapUri);
+ if (message.getFault() != null) {
+ writeFault(writer);
+ } else if (message.getSource() != null) {
+ writeContents(writer);
+ }
+ writer.writeEndElement();
+ writer.writeEndElement();
+ }
+
+ private void writeContents(XMLStreamWriter writer) throws Exception {
+ XMLStreamReader reader = marshaler.getSourceTransformer().toXMLStreamReader(message.getSource());
+ XMLStreamHelper.copy(reader, writer, marshaler.isRepairingNamespace());
+ }
+
+ private void writeFault(XMLStreamWriter writer) throws Exception {
+ QName envelope = getEnvelopeName();
+ String soapUri = envelope.getNamespaceURI();
+ if (SoapMarshaler.SOAP_11_URI.equals(soapUri)) {
+ writeSoap11Fault(writer);
+ } else {
+ writeSoap12Fault(writer);
+ }
+ }
+
+ private void writeSoap11Fault(XMLStreamWriter writer) throws Exception {
+ // TODO
+ writeSoap12Fault(writer);
+ }
+
+ private void writeSoap12Fault(XMLStreamWriter writer) throws Exception {
+ QName envelope = getEnvelopeName();
+ String soapUri = envelope.getNamespaceURI();
+ String soapPrefix = envelope.getPrefix();
+ writer.setPrefix(soapPrefix, soapUri);
+ SoapFault fault = message.getFault();
+
+ writer.writeStartElement(soapPrefix, "Fault", soapUri);
+ String code = fault.getCode();
+ if (code != null) {
+ writer.writeStartElement(soapPrefix, "Code", soapUri);
+ writer.writeStartElement(soapPrefix, "Value", soapUri);
+ writer.writeCharacters(soapPrefix + ":" + code);
+ writer.writeEndElement();
+ String subcode = fault.getSubcode();
+ if (subcode != null) {
+ writer.writeStartElement(soapPrefix, "Subcode", soapUri);
+ writer.writeStartElement(soapPrefix, "Value", soapUri);
+ writer.writeCharacters(subcode);
+ writer.writeEndElement();
+ writer.writeEndElement();
+ }
+ writer.writeEndElement();
+ }
+ String reason = fault.getReason();
+ if (reason == null && fault.getCause() != null) {
+ reason = fault.getCause().toString();
+ }
+ if (reason != null) {
+ writer.writeStartElement(soapPrefix, "Reason", soapUri);
+ writer.writeStartElement(soapPrefix, "Text", soapUri);
+ writer.writeAttribute(XMLConstants.XML_NS_PREFIX, XMLConstants.XML_NS_URI, "lang", "en-US");
+ writer.writeCharacters(reason);
+ writer.writeEndElement();
+ writer.writeEndElement();
+ }
+ String node = fault.getNode();
+ if (node != null) {
+ writer.writeStartElement(soapPrefix, "Node", soapUri);
+ writer.writeCharacters(node);
+ writer.writeEndElement();
+ }
+
+ String role = fault.getRole();
+ if (role != null) {
+ writer.writeStartElement(soapPrefix, "Role", soapUri);
+ writer.writeCharacters(role);
+ writer.writeEndElement();
+ }
+
+ Source details = fault.getDetails();
+ if (details != null) {
+ writer.writeStartElement(soapPrefix, "Details", soapUri);
+ XMLStreamReader reader = marshaler.getSourceTransformer().toXMLStreamReader(details);
+ XMLStreamHelper.copy(reader, writer, marshaler.isRepairingNamespace());
+ writer.writeEndElement();
+ }
+
+ writer.writeEndElement();
+ }
+
+ protected QName getEnvelopeName() {
+ QName name = message.getEnvelopeName();
+ if (name == null) {
+ name = new QName(marshaler.soapUri, SoapMarshaler.ENVELOPE, marshaler.prefix);
+ } else if (name.getPrefix() == null) {
+ name = new QName(name.getNamespaceURI(), name.getLocalPart(), marshaler.prefix);
+ }
+ return name;
+ }
+
+}
Propchange: incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/marshalers/SoapWriter.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/package.html
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/package.html?rev=379627&r1=379626&r2=379627&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/package.html (original)
+++ incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/package.html Tue Feb 21 15:40:05 2006
@@ -1,9 +1,9 @@
-<html>
-<head>
-</head>
-<body>
-
-The core API and classes for the SOAP stack
-
-</body>
-</html>
+<html>
+<head>
+</head>
+<body>
+
+The core API and classes for the SOAP stack
+
+</body>
+</html>
Propchange: incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/package.html
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/servicemix/trunk/servicemix-soap/src/main/resources/META-INF/DISCLAIMER.txt
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-soap/src/main/resources/META-INF/DISCLAIMER.txt?rev=379627&r1=379626&r2=379627&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-soap/src/main/resources/META-INF/DISCLAIMER.txt (original)
+++ incubator/servicemix/trunk/servicemix-soap/src/main/resources/META-INF/DISCLAIMER.txt Tue Feb 21 15:40:05 2006
@@ -1,7 +1,7 @@
-ActiveMQ is an effort undergoing incubation at the Apache Software Foundation
-(ASF), sponsored by the Geronimo PMC. Incubation is required of all newly
-accepted projects until a further review indicates that the infrastructure,
-communications, and decision making process have stabilized in a manner
-consistent with other successful ASF projects. While incubation status is not
-necessarily a reflection of the completeness or stability of the code, it does
+ActiveMQ is an effort undergoing incubation at the Apache Software Foundation
+(ASF), sponsored by the Geronimo PMC. Incubation is required of all newly
+accepted projects until a further review indicates that the infrastructure,
+communications, and decision making process have stabilized in a manner
+consistent with other successful ASF projects. While incubation status is not
+necessarily a reflection of the completeness or stability of the code, it does
indicate that the project has yet to be fully endorsed by the ASF.
Propchange: incubator/servicemix/trunk/servicemix-soap/src/main/resources/META-INF/DISCLAIMER.txt
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/servicemix/trunk/servicemix-soap/src/main/resources/META-INF/LICENSE.txt
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/servicemix/trunk/servicemix-soap/src/test/java/org/apache/servicemix/soap/marshalers/SoapMessageMarshalerTest.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-soap/src/test/java/org/apache/servicemix/soap/marshalers/SoapMessageMarshalerTest.java?rev=379627&r1=379626&r2=379627&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-soap/src/test/java/org/apache/servicemix/soap/marshalers/SoapMessageMarshalerTest.java (original)
+++ incubator/servicemix/trunk/servicemix-soap/src/test/java/org/apache/servicemix/soap/marshalers/SoapMessageMarshalerTest.java Tue Feb 21 15:40:05 2006
@@ -1,200 +1,200 @@
-/*
- * Copyright 2005-2006 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.servicemix.soap.marshalers;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.net.URI;
-import java.util.Iterator;
-
-import javax.activation.DataHandler;
-import javax.activation.FileDataSource;
-import javax.xml.namespace.QName;
-import javax.xml.transform.dom.DOMSource;
-import javax.xml.transform.stream.StreamSource;
-
-import junit.framework.TestCase;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.servicemix.jbi.jaxp.BytesSource;
-import org.apache.servicemix.jbi.jaxp.SourceTransformer;
-import org.apache.servicemix.jbi.util.DOMUtil;
-import org.apache.servicemix.soap.marshalers.SoapMarshaler;
-import org.apache.servicemix.soap.marshalers.SoapMessage;
-import org.apache.xpath.CachedXPathAPI;
-import org.w3c.dom.DocumentFragment;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-import org.w3c.dom.traversal.NodeIterator;
-
-/**
- *
- * @author Guillaume Nodet
- * @version $Revision: 1.5 $
- */
-public class SoapMessageMarshalerTest extends TestCase {
-
- private static final Log log = LogFactory.getLog(SoapMessageMarshalerTest.class);
-
- private SourceTransformer sourceTransformer = new SourceTransformer();
-
- public void testReadNonSoapMessage() throws Exception {
- SoapMarshaler marshaler = new SoapMarshaler(false);
- SoapMessage msg = marshaler.createReader().read(getClass().getResourceAsStream("soap.xml"));
- assertNotNull(msg);
- assertFalse(msg.hasAttachments());
- assertFalse(msg.hasHeaders());
- assertNotNull(msg.getSource());
- Node node = sourceTransformer.toDOMNode(msg.getSource());
- checkServiceNameNamespace(node);
- checkUserIdNamespace(node);
- }
-
- public void testWriteAndReadNonSoapMessage() throws Exception {
- SoapMarshaler marshaler = new SoapMarshaler(false);
- SoapMessage msg = new SoapMessage();
- msg.setSource(new StreamSource(getClass().getResourceAsStream("soap.xml")));
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- marshaler.createWriter(msg).write(baos);
- log.info(baos.toString());
-
- SoapMessage msg2 = marshaler.createReader().read(new ByteArrayInputStream(baos.toByteArray()));
- assertNotNull(msg2);
- assertFalse(msg2.hasAttachments());
- assertFalse(msg2.hasHeaders());
- assertNotNull(msg2.getSource());
- Node node = sourceTransformer.toDOMNode(msg2.getSource());
- checkServiceNameNamespace(node);
- checkUserIdNamespace(node);
- }
-
- public void testWriteAndReadNonSoapMessageWithAttachments() throws Exception {
- SoapMarshaler marshaler = new SoapMarshaler(false);
- SoapMessage msg = new SoapMessage();
- msg.setSource(new StreamSource(getClass().getResourceAsStream("soap.xml")));
- msg.addAttachment("servicemix.jpg", new DataHandler(new FileDataSource(new File(new URI(getClass().getResource("servicemix.jpg").toString())))));
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- SoapWriter writer = marshaler.createWriter(msg);
- writer.write(baos);
- log.info(baos.toString());
-
- SoapMessage msg2 = marshaler.createReader().read(new ByteArrayInputStream(baos.toByteArray()), writer.getContentType());
- assertNotNull(msg2);
- assertTrue(msg2.hasAttachments());
- assertEquals(1, msg2.getAttachments().size());
- DataHandler handler = (DataHandler) msg2.getAttachments().get(msg2.getAttachments().keySet().iterator().next());
- assertNotNull(handler);
- assertFalse(msg2.hasHeaders());
- assertNotNull(msg2.getSource());
- Node node = sourceTransformer.toDOMNode(msg2.getSource());
- checkServiceNameNamespace(node);
- checkUserIdNamespace(node);
- }
-
- public void testWriteNonSoapMessageWithHeaders() throws Exception {
- SoapMarshaler marshaler = new SoapMarshaler(false);
- SoapMessage msg = new SoapMessage();
- msg.addHeader(new QName("test"), null);
- msg.setSource(null);
- try {
- marshaler.createWriter(msg).write(new ByteArrayOutputStream());
- fail("Exception should have been thrown");
- } catch (Exception e) {
- // ok
- }
- }
-
- public void testSoapMessage() throws Exception {
- SoapMarshaler marshaler = new SoapMarshaler(true);
-
- SoapMessage msg = marshaler.createReader().read(getClass().getResourceAsStream("soap.xml"));
- assertNotNull(msg);
- assertFalse(msg.hasAttachments());
- assertTrue(msg.hasHeaders());
- assertNotNull(msg.getSource());
-
- Iterator headers = msg.getHeaders().values().iterator();
- assertTrue(headers.hasNext());
- assertNotNull(headers.next());
- assertTrue(headers.hasNext());
- checkServiceNameNamespace((DocumentFragment) headers.next());
- assertFalse(headers.hasNext());
-
- Node node2 = sourceTransformer.toDOMNode(msg.getSource());
- checkUserIdNamespace(node2);
-
- msg.setSource(new DOMSource(node2));
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- marshaler.createWriter(msg).write(baos);
- Node node = sourceTransformer.toDOMNode(new BytesSource(baos.toByteArray()));
- checkUserIdNamespace(node);
- }
-
- public void testSoapMessage2() throws Exception {
- SoapMarshaler marshaler = new SoapMarshaler(true);
- SoapMessage msg = marshaler.createReader().read(getClass().getResourceAsStream("soap2.xml"));
- assertNotNull(msg);
- }
-
- public void testWriteAndReadSoapMessageWithAttachments() throws Exception {
- SoapMarshaler marshaler = new SoapMarshaler(true);
- SoapMessage msg = marshaler.createReader().read(getClass().getResourceAsStream("soap.xml"));
- msg.addAttachment("servicemix.jpg", new DataHandler(new FileDataSource(new File(new URI(getClass().getResource("servicemix.jpg").toString())))));
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- SoapWriter writer = marshaler.createWriter(msg);
- writer.write(baos);
- log.info(baos.toString());
-
- SoapMessage msg2 = marshaler.createReader().read(new ByteArrayInputStream(baos.toByteArray()), writer.getContentType());
- assertNotNull(msg2);
- assertTrue(msg2.hasAttachments());
- assertEquals(1, msg2.getAttachments().size());
- DataHandler handler = (DataHandler) msg2.getAttachments().get(msg2.getAttachments().keySet().iterator().next());
- assertNotNull(handler);
- assertNotNull(msg2.getSource());
- checkUserIdNamespace(sourceTransformer.toDOMNode(msg2.getSource()));
- assertTrue(msg2.hasHeaders());
- Iterator headers = msg2.getHeaders().values().iterator();
- assertTrue(headers.hasNext());
- assertNotNull(headers.next());
- assertTrue(headers.hasNext());
- checkServiceNameNamespace((DocumentFragment) headers.next());
- assertFalse(headers.hasNext());
- }
-
- protected void checkUserIdNamespace(Node node) throws Exception {
- CachedXPathAPI cachedXPathAPI = new CachedXPathAPI();
- NodeIterator iterator = cachedXPathAPI.selectNodeIterator(node, "//*[local-name() = 'userId']");
- Element root = (Element) iterator.nextNode();
- QName qname = DOMUtil.createQName(root, root.getAttributeNS("http://www.w3.org/2001/XMLSchema-instance", "type"));
- assertEquals("http://www.w3.org/2001/XMLSchema", qname.getNamespaceURI());
- assertEquals("string", qname.getLocalPart());
- }
-
- protected void checkServiceNameNamespace(Node node) throws Exception {
- CachedXPathAPI cachedXPathAPI = new CachedXPathAPI();
- NodeIterator iterator = cachedXPathAPI.selectNodeIterator(node, "//*[local-name() = 'ServiceName']");
- Element root = (Element) iterator.nextNode();
- assertEquals(new QName("http://schemas.xmlsoap.org/ws/2003/03/addressing", "ServiceName"),
- new QName(root.getNamespaceURI(), root.getLocalName()));
- QName qname = DOMUtil.createQName(root, DOMUtil.getElementText(root));
- assertEquals(new QName("uri:test", "MyConsumerService"), qname);
- }
-
-
-}
+/*
+ * Copyright 2005-2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicemix.soap.marshalers;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.net.URI;
+import java.util.Iterator;
+
+import javax.activation.DataHandler;
+import javax.activation.FileDataSource;
+import javax.xml.namespace.QName;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamSource;
+
+import junit.framework.TestCase;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.servicemix.jbi.jaxp.BytesSource;
+import org.apache.servicemix.jbi.jaxp.SourceTransformer;
+import org.apache.servicemix.jbi.util.DOMUtil;
+import org.apache.servicemix.soap.marshalers.SoapMarshaler;
+import org.apache.servicemix.soap.marshalers.SoapMessage;
+import org.apache.xpath.CachedXPathAPI;
+import org.w3c.dom.DocumentFragment;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.traversal.NodeIterator;
+
+/**
+ *
+ * @author Guillaume Nodet
+ * @version $Revision: 1.5 $
+ */
+public class SoapMessageMarshalerTest extends TestCase {
+
+ private static final Log log = LogFactory.getLog(SoapMessageMarshalerTest.class);
+
+ private SourceTransformer sourceTransformer = new SourceTransformer();
+
+ public void testReadNonSoapMessage() throws Exception {
+ SoapMarshaler marshaler = new SoapMarshaler(false);
+ SoapMessage msg = marshaler.createReader().read(getClass().getResourceAsStream("soap.xml"));
+ assertNotNull(msg);
+ assertFalse(msg.hasAttachments());
+ assertFalse(msg.hasHeaders());
+ assertNotNull(msg.getSource());
+ Node node = sourceTransformer.toDOMNode(msg.getSource());
+ checkServiceNameNamespace(node);
+ checkUserIdNamespace(node);
+ }
+
+ public void testWriteAndReadNonSoapMessage() throws Exception {
+ SoapMarshaler marshaler = new SoapMarshaler(false);
+ SoapMessage msg = new SoapMessage();
+ msg.setSource(new StreamSource(getClass().getResourceAsStream("soap.xml")));
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ marshaler.createWriter(msg).write(baos);
+ log.info(baos.toString());
+
+ SoapMessage msg2 = marshaler.createReader().read(new ByteArrayInputStream(baos.toByteArray()));
+ assertNotNull(msg2);
+ assertFalse(msg2.hasAttachments());
+ assertFalse(msg2.hasHeaders());
+ assertNotNull(msg2.getSource());
+ Node node = sourceTransformer.toDOMNode(msg2.getSource());
+ checkServiceNameNamespace(node);
+ checkUserIdNamespace(node);
+ }
+
+ public void testWriteAndReadNonSoapMessageWithAttachments() throws Exception {
+ SoapMarshaler marshaler = new SoapMarshaler(false);
+ SoapMessage msg = new SoapMessage();
+ msg.setSource(new StreamSource(getClass().getResourceAsStream("soap.xml")));
+ msg.addAttachment("servicemix.jpg", new DataHandler(new FileDataSource(new File(new URI(getClass().getResource("servicemix.jpg").toString())))));
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ SoapWriter writer = marshaler.createWriter(msg);
+ writer.write(baos);
+ log.info(baos.toString());
+
+ SoapMessage msg2 = marshaler.createReader().read(new ByteArrayInputStream(baos.toByteArray()), writer.getContentType());
+ assertNotNull(msg2);
+ assertTrue(msg2.hasAttachments());
+ assertEquals(1, msg2.getAttachments().size());
+ DataHandler handler = (DataHandler) msg2.getAttachments().get(msg2.getAttachments().keySet().iterator().next());
+ assertNotNull(handler);
+ assertFalse(msg2.hasHeaders());
+ assertNotNull(msg2.getSource());
+ Node node = sourceTransformer.toDOMNode(msg2.getSource());
+ checkServiceNameNamespace(node);
+ checkUserIdNamespace(node);
+ }
+
+ public void testWriteNonSoapMessageWithHeaders() throws Exception {
+ SoapMarshaler marshaler = new SoapMarshaler(false);
+ SoapMessage msg = new SoapMessage();
+ msg.addHeader(new QName("test"), null);
+ msg.setSource(null);
+ try {
+ marshaler.createWriter(msg).write(new ByteArrayOutputStream());
+ fail("Exception should have been thrown");
+ } catch (Exception e) {
+ // ok
+ }
+ }
+
+ public void testSoapMessage() throws Exception {
+ SoapMarshaler marshaler = new SoapMarshaler(true);
+
+ SoapMessage msg = marshaler.createReader().read(getClass().getResourceAsStream("soap.xml"));
+ assertNotNull(msg);
+ assertFalse(msg.hasAttachments());
+ assertTrue(msg.hasHeaders());
+ assertNotNull(msg.getSource());
+
+ Iterator headers = msg.getHeaders().values().iterator();
+ assertTrue(headers.hasNext());
+ assertNotNull(headers.next());
+ assertTrue(headers.hasNext());
+ checkServiceNameNamespace((DocumentFragment) headers.next());
+ assertFalse(headers.hasNext());
+
+ Node node2 = sourceTransformer.toDOMNode(msg.getSource());
+ checkUserIdNamespace(node2);
+
+ msg.setSource(new DOMSource(node2));
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ marshaler.createWriter(msg).write(baos);
+ Node node = sourceTransformer.toDOMNode(new BytesSource(baos.toByteArray()));
+ checkUserIdNamespace(node);
+ }
+
+ public void testSoapMessage2() throws Exception {
+ SoapMarshaler marshaler = new SoapMarshaler(true);
+ SoapMessage msg = marshaler.createReader().read(getClass().getResourceAsStream("soap2.xml"));
+ assertNotNull(msg);
+ }
+
+ public void testWriteAndReadSoapMessageWithAttachments() throws Exception {
+ SoapMarshaler marshaler = new SoapMarshaler(true);
+ SoapMessage msg = marshaler.createReader().read(getClass().getResourceAsStream("soap.xml"));
+ msg.addAttachment("servicemix.jpg", new DataHandler(new FileDataSource(new File(new URI(getClass().getResource("servicemix.jpg").toString())))));
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ SoapWriter writer = marshaler.createWriter(msg);
+ writer.write(baos);
+ log.info(baos.toString());
+
+ SoapMessage msg2 = marshaler.createReader().read(new ByteArrayInputStream(baos.toByteArray()), writer.getContentType());
+ assertNotNull(msg2);
+ assertTrue(msg2.hasAttachments());
+ assertEquals(1, msg2.getAttachments().size());
+ DataHandler handler = (DataHandler) msg2.getAttachments().get(msg2.getAttachments().keySet().iterator().next());
+ assertNotNull(handler);
+ assertNotNull(msg2.getSource());
+ checkUserIdNamespace(sourceTransformer.toDOMNode(msg2.getSource()));
+ assertTrue(msg2.hasHeaders());
+ Iterator headers = msg2.getHeaders().values().iterator();
+ assertTrue(headers.hasNext());
+ assertNotNull(headers.next());
+ assertTrue(headers.hasNext());
+ checkServiceNameNamespace((DocumentFragment) headers.next());
+ assertFalse(headers.hasNext());
+ }
+
+ protected void checkUserIdNamespace(Node node) throws Exception {
+ CachedXPathAPI cachedXPathAPI = new CachedXPathAPI();
+ NodeIterator iterator = cachedXPathAPI.selectNodeIterator(node, "//*[local-name() = 'userId']");
+ Element root = (Element) iterator.nextNode();
+ QName qname = DOMUtil.createQName(root, root.getAttributeNS("http://www.w3.org/2001/XMLSchema-instance", "type"));
+ assertEquals("http://www.w3.org/2001/XMLSchema", qname.getNamespaceURI());
+ assertEquals("string", qname.getLocalPart());
+ }
+
+ protected void checkServiceNameNamespace(Node node) throws Exception {
+ CachedXPathAPI cachedXPathAPI = new CachedXPathAPI();
+ NodeIterator iterator = cachedXPathAPI.selectNodeIterator(node, "//*[local-name() = 'ServiceName']");
+ Element root = (Element) iterator.nextNode();
+ assertEquals(new QName("http://schemas.xmlsoap.org/ws/2003/03/addressing", "ServiceName"),
+ new QName(root.getNamespaceURI(), root.getLocalName()));
+ QName qname = DOMUtil.createQName(root, DOMUtil.getElementText(root));
+ assertEquals(new QName("uri:test", "MyConsumerService"), qname);
+ }
+
+
+}
Propchange: incubator/servicemix/trunk/servicemix-soap/src/test/java/org/apache/servicemix/soap/marshalers/SoapMessageMarshalerTest.java
------------------------------------------------------------------------------
svn:eol-style = native