You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-commits@axis.apache.org by ve...@apache.org on 2016/02/25 09:04:07 UTC
svn commit: r1732255 - in /axis/axis2/java/core/trunk: ./
modules/kernel/src/org/apache/axis2/transport/http/ modules/transport/http/
modules/transport/http/test/org/apache/axis2/transport/http/
Author: veithen
Date: Thu Feb 25 08:04:07 2016
New Revision: 1732255
URL: http://svn.apache.org/viewvc?rev=1732255&view=rev
Log:
Adapt to changes in Axiom 1.3.
Modified:
axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/transport/http/SOAPMessageFormatter.java
axis/axis2/java/core/trunk/modules/transport/http/pom.xml
axis/axis2/java/core/trunk/modules/transport/http/test/org/apache/axis2/transport/http/CommonsHTTPTransportSenderClientSideTest.java
axis/axis2/java/core/trunk/modules/transport/http/test/org/apache/axis2/transport/http/CommonsHTTPTransportSenderTest.java
axis/axis2/java/core/trunk/modules/transport/http/test/org/apache/axis2/transport/http/HTTPClient4SenderTest.java
axis/axis2/java/core/trunk/modules/transport/http/test/org/apache/axis2/transport/http/HTTPSenderTest.java
axis/axis2/java/core/trunk/pom.xml
Modified: axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/transport/http/SOAPMessageFormatter.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/transport/http/SOAPMessageFormatter.java?rev=1732255&r1=1732254&r2=1732255&view=diff
==============================================================================
--- axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/transport/http/SOAPMessageFormatter.java (original)
+++ axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/transport/http/SOAPMessageFormatter.java Thu Feb 25 08:04:07 2016
@@ -20,9 +20,13 @@
package org.apache.axis2.transport.http;
import org.apache.axiom.attachments.Attachments;
+import org.apache.axiom.om.OMContainer;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMOutputFormat;
import org.apache.axiom.om.impl.OMMultipartWriter;
+import org.apache.axiom.soap.SOAPEnvelope;
+import org.apache.axiom.soap.SOAPFactory;
+import org.apache.axiom.soap.SOAPMessage;
import org.apache.axiom.util.UIDGenerator;
import org.apache.axis2.AxisFault;
import org.apache.axis2.Constants;
@@ -67,11 +71,23 @@ public class SOAPMessageFormatter implem
if (!(format.isOptimized()) && format.isDoingSWA()) {
writeSwAMessage(msgCtxt, out, format, preserve);
} else {
- OMElement element = msgCtxt.getEnvelope();
+ SOAPEnvelope envelope = msgCtxt.getEnvelope();
+ // Always use a SOAPMessage for serialization so that we produce an XML declaration.
+ // Note that an XML declaration shouldn't be necessary except for weird cases such as
+ // the UDP transport. This is for compatibility with Axis2 1.7.0 and Axiom 1.2.x;
+ // Axiom 1.3.x no longer produces an XML declaration when serializing a SOAPEnvelope.
+ SOAPMessage message;
+ OMContainer parent = envelope.getParent();
+ if (parent instanceof SOAPMessage) {
+ message = (SOAPMessage)parent;
+ } else {
+ message = ((SOAPFactory)envelope.getOMFactory()).createSOAPMessage();
+ message.setSOAPEnvelope(envelope);
+ }
if (preserve) {
- element.serialize(out, format);
+ message.serialize(out, format);
} else {
- element.serializeAndConsume(out, format);
+ message.serializeAndConsume(out, format);
}
}
} catch (XMLStreamException e) {
@@ -85,34 +101,9 @@ public class SOAPMessageFormatter implem
public byte[] getBytes(MessageContext msgCtxt, OMOutputFormat format)
throws AxisFault {
- if (log.isDebugEnabled()) {
- log.debug("start getBytes()");
- log.debug(" isOptimized=" + format.isOptimized());
- log.debug(" isDoingSWA=" + format.isDoingSWA());
- }
- OMElement element = msgCtxt.getEnvelope();
- try {
- ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
- if (!format.isOptimized()) {
- if (format.isDoingSWA()) {
- writeSwAMessage(msgCtxt, bytesOut, format, false);
- } else {
- element.serializeAndConsume(bytesOut, format);
- }
- return bytesOut.toByteArray();
- } else {
- element.serializeAndConsume(bytesOut, format);
- return bytesOut.toByteArray();
- }
- } catch (XMLStreamException e) {
- throw AxisFault.makeFault(e);
- } catch (FactoryConfigurationError e) {
- throw AxisFault.makeFault(e);
- } finally {
- if (log.isDebugEnabled()) {
- log.debug("end getBytes()");
- }
- }
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ writeTo(msgCtxt, format, out, true);
+ return out.toByteArray();
}
public String getContentType(MessageContext msgCtxt, OMOutputFormat format,
Modified: axis/axis2/java/core/trunk/modules/transport/http/pom.xml
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/transport/http/pom.xml?rev=1732255&r1=1732254&r2=1732255&view=diff
==============================================================================
--- axis/axis2/java/core/trunk/modules/transport/http/pom.xml (original)
+++ axis/axis2/java/core/trunk/modules/transport/http/pom.xml Thu Feb 25 08:04:07 2016
@@ -113,5 +113,10 @@
<version>${project.version}</version>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.apache.ws.commons.axiom</groupId>
+ <artifactId>axiom-truth</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
</project>
Modified: axis/axis2/java/core/trunk/modules/transport/http/test/org/apache/axis2/transport/http/CommonsHTTPTransportSenderClientSideTest.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/transport/http/test/org/apache/axis2/transport/http/CommonsHTTPTransportSenderClientSideTest.java?rev=1732255&r1=1732254&r2=1732255&view=diff
==============================================================================
--- axis/axis2/java/core/trunk/modules/transport/http/test/org/apache/axis2/transport/http/CommonsHTTPTransportSenderClientSideTest.java (original)
+++ axis/axis2/java/core/trunk/modules/transport/http/test/org/apache/axis2/transport/http/CommonsHTTPTransportSenderClientSideTest.java Thu Feb 25 08:04:07 2016
@@ -1,5 +1,8 @@
package org.apache.axis2.transport.http;
+import static com.google.common.truth.Truth.assertAbout;
+import static org.apache.axiom.truth.xml.XMLTruth.xml;
+
import javax.xml.namespace.QName;
import org.apache.axiom.om.OMAbstractFactory;
@@ -41,8 +44,7 @@ public class CommonsHTTPTransportSenderC
getHeaders().get("Content-Type"));
assertEquals("Not the expected Header value", "custom-value",
getHeaders().get("Custom-header"));
- assertEquals("Not the expected body content", getEnvelope().toString()
- .replace("utf", "UTF"), getStringContent());
+ assertAbout(xml()).that(getStringContent()).hasSameContentAs(getEnvelope().toString());
}
/*
Modified: axis/axis2/java/core/trunk/modules/transport/http/test/org/apache/axis2/transport/http/CommonsHTTPTransportSenderTest.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/transport/http/test/org/apache/axis2/transport/http/CommonsHTTPTransportSenderTest.java?rev=1732255&r1=1732254&r2=1732255&view=diff
==============================================================================
--- axis/axis2/java/core/trunk/modules/transport/http/test/org/apache/axis2/transport/http/CommonsHTTPTransportSenderTest.java (original)
+++ axis/axis2/java/core/trunk/modules/transport/http/test/org/apache/axis2/transport/http/CommonsHTTPTransportSenderTest.java Thu Feb 25 08:04:07 2016
@@ -18,6 +18,9 @@
*/
package org.apache.axis2.transport.http;
+import static com.google.common.truth.Truth.assertAbout;
+import static org.apache.axiom.truth.xml.XMLTruth.xml;
+
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
@@ -69,8 +72,9 @@ public abstract class CommonsHTTPTranspo
.get("Content-Type"));
assertEquals("Not the expected Header value", "custom-value", httpResponse.getHeaders()
.get("Custom-header"));
- assertEquals("Not the expected body content", envelope.toString().replace("utf", "UTF"),
- new String(httpResponse.getByteArrayOutputStream().toByteArray()));
+ assertAbout(xml())
+ .that(new String(httpResponse.getByteArrayOutputStream().toByteArray()))
+ .hasSameContentAs(envelope.toString());
}
public void testInvokeWithAxisHttpResponseImpl() throws Exception {
@@ -84,8 +88,9 @@ public abstract class CommonsHTTPTranspo
.get("Content-Type"));
assertEquals("Not the expected Header value", "custom-value", httpResponse.getHeaders()
.get("Custom-header"));
- assertEquals("Not the expected body content", envelope.toString().replace("utf", "UTF"),
- new String(httpResponse.getByteArrayOutputStream().toByteArray()));
+ assertAbout(xml())
+ .that(new String(httpResponse.getByteArrayOutputStream().toByteArray()))
+ .hasSameContentAs(envelope.toString());
}
public void testCleanup() throws AxisFault {
Modified: axis/axis2/java/core/trunk/modules/transport/http/test/org/apache/axis2/transport/http/HTTPClient4SenderTest.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/transport/http/test/org/apache/axis2/transport/http/HTTPClient4SenderTest.java?rev=1732255&r1=1732254&r2=1732255&view=diff
==============================================================================
--- axis/axis2/java/core/trunk/modules/transport/http/test/org/apache/axis2/transport/http/HTTPClient4SenderTest.java (original)
+++ axis/axis2/java/core/trunk/modules/transport/http/test/org/apache/axis2/transport/http/HTTPClient4SenderTest.java Thu Feb 25 08:04:07 2016
@@ -22,6 +22,9 @@ package org.apache.axis2.transport.http;
import org.apache.axis2.Constants;
import org.apache.axis2.transport.http.impl.httpclient4.HTTPSenderImpl;
+import static com.google.common.truth.Truth.assertAbout;
+import static org.apache.axiom.truth.xml.XMLTruth.xml;
+
import javax.ws.rs.core.HttpHeaders;
public class HTTPClient4SenderTest extends HTTPSenderTest {
@@ -73,7 +76,7 @@ public class HTTPClient4SenderTest exten
"http://localhost:" + port + "/postService", false);
assertEquals("Not the expected HTTP Method", Constants.Configuration.HTTP_METHOD_POST,
getHTTPMethod());
- assertEquals("Not the expected content", getEnvelope().toString(), getStringContent());
+ assertAbout(xml()).that(getStringContent()).hasSameContentAs(getEnvelope().toString());
assertEquals("Not the expected HTTP Header value", "urn:postService",
getHeaders().get("SOAPAction").replace("\"", ""));
assertEquals("Not the expected HTTP Header value", "text/xml",
@@ -107,7 +110,7 @@ public class HTTPClient4SenderTest exten
+ port + "/putService", false);
assertEquals("Not the expected HTTP Method", Constants.Configuration.HTTP_METHOD_PUT,
getHTTPMethod());
- assertEquals("Not the expected content", getEnvelope().toString(), getStringContent());
+ assertAbout(xml()).that(getStringContent()).hasSameContentAs(getEnvelope().toString());
assertEquals("Not the expected HTTP Header value", "urn:putService",
getHeaders().get("SOAPAction").replace("\"", ""));
assertEquals("Not the expected HTTP Header value", "text/xml",
Modified: axis/axis2/java/core/trunk/modules/transport/http/test/org/apache/axis2/transport/http/HTTPSenderTest.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/transport/http/test/org/apache/axis2/transport/http/HTTPSenderTest.java?rev=1732255&r1=1732254&r2=1732255&view=diff
==============================================================================
--- axis/axis2/java/core/trunk/modules/transport/http/test/org/apache/axis2/transport/http/HTTPSenderTest.java (original)
+++ axis/axis2/java/core/trunk/modules/transport/http/test/org/apache/axis2/transport/http/HTTPSenderTest.java Thu Feb 25 08:04:07 2016
@@ -29,6 +29,10 @@ import org.apache.axis2.transport.http.m
import javax.mail.MessagingException;
import javax.ws.rs.core.HttpHeaders;
+
+import static com.google.common.truth.Truth.assertAbout;
+import static org.apache.axiom.truth.xml.XMLTruth.xml;
+
import java.io.IOException;
import java.net.URL;
@@ -127,7 +131,7 @@ public abstract class HTTPSenderTest ext
"http://localhost:" + port + "/postService", false);
assertEquals("Not the expected HTTP Method", Constants.Configuration.HTTP_METHOD_POST,
getHTTPMethod());
- assertEquals("Not the expected content", getEnvelope().toString(), getStringContent());
+ assertAbout(xml()).that(getStringContent()).hasSameContentAs(getEnvelope().toString());
assertEquals("Not the expected HTTP Header value", "urn:postService",
getHeaders().get("SOAPAction").replace("\"", ""));
assertEquals("Not the expected HTTP Header value", "text/xml",
@@ -169,7 +173,7 @@ public abstract class HTTPSenderTest ext
+ port + "/putService", false);
assertEquals("Not the expected HTTP Method", Constants.Configuration.HTTP_METHOD_PUT,
getHTTPMethod());
- assertEquals("Not the expected content", getEnvelope().toString(), getStringContent());
+ assertAbout(xml()).that(getStringContent()).hasSameContentAs(getEnvelope().toString());
assertEquals("Not the expected HTTP Header value", "urn:putService",
getHeaders().get("SOAPAction").replace("\"", ""));
assertEquals("Not the expected HTTP Header value", "text/xml",
@@ -252,7 +256,7 @@ public abstract class HTTPSenderTest ext
getHeaders().get(HttpHeaders.USER_AGENT));
sendViaHTTP(null, "urn:noService", "http://localhost:" + port + "/noService", false);
- assertEquals("Not the expected content", getEnvelope().toString(), getStringContent());
+ assertAbout(xml()).that(getStringContent()).hasSameContentAs(getEnvelope().toString());
assertEquals("Not the expected HTTP Header value", "urn:noService",
getHeaders().get("SOAPAction").replace("\"", ""));
assertEquals("Not the expected HTTP Header value", "text/xml",
Modified: axis/axis2/java/core/trunk/pom.xml
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/pom.xml?rev=1732255&r1=1732254&r2=1732255&view=diff
==============================================================================
--- axis/axis2/java/core/trunk/pom.xml (original)
+++ axis/axis2/java/core/trunk/pom.xml Thu Feb 25 08:04:07 2016
@@ -731,6 +731,11 @@
<version>${axiom.version}</version>
</dependency>
<dependency>
+ <groupId>org.apache.ws.commons.axiom</groupId>
+ <artifactId>axiom-truth</artifactId>
+ <version>${axiom.version}</version>
+ </dependency>
+ <dependency>
<groupId>org.apache.ws.xmlschema</groupId>
<artifactId>xmlschema-core</artifactId>
<version>${xmlschema.version}</version>