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/13 21:10:18 UTC
svn commit: r1730266 - in /axis/axis2/java/core/trunk/modules:
jaxws-integration/test/org/apache/axis2/jaxws/sample/ jaxws/
jaxws/src/org/apache/axis2/datasource/jaxb/
jaxws/src/org/apache/axis2/jaxws/marshaller/impl/alt/
jaxws/test/org/apache/axis2/da...
Author: veithen
Date: Sat Feb 13 20:10:18 2016
New Revision: 1730266
URL: http://svn.apache.org/viewvc?rev=1730266&view=rev
Log:
Adapt to latest changes in Axiom's CustomBuilder API.
Modified:
axis/axis2/java/core/trunk/modules/jaxws-integration/test/org/apache/axis2/jaxws/sample/WrapTests.java
axis/axis2/java/core/trunk/modules/jaxws/pom.xml
axis/axis2/java/core/trunk/modules/jaxws/src/org/apache/axis2/datasource/jaxb/JAXBCustomBuilder.java
axis/axis2/java/core/trunk/modules/jaxws/src/org/apache/axis2/jaxws/marshaller/impl/alt/UnmarshalMessageContextListener.java
axis/axis2/java/core/trunk/modules/jaxws/test/org/apache/axis2/datasource/jaxb/JAXBCustomBuilderDisableStreamingTests.java
axis/axis2/java/core/trunk/modules/jaxws/test/org/apache/axis2/jaxws/message/JAXBCustomBuilderTests.java
axis/axis2/java/core/trunk/modules/jaxws/test/org/apache/axis2/jaxws/message/MessageTests.java
Modified: axis/axis2/java/core/trunk/modules/jaxws-integration/test/org/apache/axis2/jaxws/sample/WrapTests.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/jaxws-integration/test/org/apache/axis2/jaxws/sample/WrapTests.java?rev=1730266&r1=1730265&r2=1730266&view=diff
==============================================================================
--- axis/axis2/java/core/trunk/modules/jaxws-integration/test/org/apache/axis2/jaxws/sample/WrapTests.java (original)
+++ axis/axis2/java/core/trunk/modules/jaxws-integration/test/org/apache/axis2/jaxws/sample/WrapTests.java Sat Feb 13 20:10:18 2016
@@ -510,9 +510,6 @@ public class WrapTests extends AbstractT
assertTrue(totalBuilders >= 1);
int totalCreates = JAXBCustomBuilderMonitor.getTotalCreates();
assertTrue(totalCreates == 0);
- int totalFailedCreates =
- JAXBCustomBuilderMonitor.getTotalFailedCreates();
- assertTrue(totalFailedCreates >= 1);
}
TestLogger.logger.debug("------------------------------");
Modified: axis/axis2/java/core/trunk/modules/jaxws/pom.xml
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/jaxws/pom.xml?rev=1730266&r1=1730265&r2=1730266&view=diff
==============================================================================
--- axis/axis2/java/core/trunk/modules/jaxws/pom.xml (original)
+++ axis/axis2/java/core/trunk/modules/jaxws/pom.xml Sat Feb 13 20:10:18 2016
@@ -124,6 +124,12 @@
<artifactId>log4j</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ <version>1.10.19</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<url>http://axis.apache.org/axis2/java/core/</url>
<scm>
Modified: axis/axis2/java/core/trunk/modules/jaxws/src/org/apache/axis2/datasource/jaxb/JAXBCustomBuilder.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/jaxws/src/org/apache/axis2/datasource/jaxb/JAXBCustomBuilder.java?rev=1730266&r1=1730265&r2=1730266&view=diff
==============================================================================
--- axis/axis2/java/core/trunk/modules/jaxws/src/org/apache/axis2/datasource/jaxb/JAXBCustomBuilder.java (original)
+++ axis/axis2/java/core/trunk/modules/jaxws/src/org/apache/axis2/datasource/jaxb/JAXBCustomBuilder.java Sat Feb 13 20:10:18 2016
@@ -19,22 +19,24 @@
package org.apache.axis2.datasource.jaxb;
+import org.apache.axiom.om.OMContainer;
import org.apache.axiom.om.OMDataSource;
+import org.apache.axiom.om.OMDocument;
import org.apache.axiom.om.OMException;
-import org.apache.axiom.om.impl.builder.CustomBuilder;
+import org.apache.axiom.om.ds.custombuilder.CustomBuilder;
+import org.apache.axiom.soap.SOAPBody;
import org.apache.axis2.jaxws.handler.HandlerUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import javax.xml.bind.JAXBException;
-import javax.xml.soap.SOAPConstants;
import javax.xml.stream.XMLStreamReader;
/**
* JAXBCustomBuilder creates an OMSourcedElement backed by a JAXBDataSource
* for the specified namespace and localPart.
*/
-public class JAXBCustomBuilder implements CustomBuilder {
+public class JAXBCustomBuilder implements CustomBuilder, CustomBuilder.Selector {
private static final Log log = LogFactory.getLog(JAXBCustomBuilder.class);
@@ -52,24 +54,12 @@ public class JAXBCustomBuilder implement
public OMDataSource create(XMLStreamReader reader) throws OMException {
- String namespace = reader.getNamespaceURI();
- if (namespace == null) {
- namespace = "";
- }
- String localPart = reader.getLocalName();
-
if (log.isDebugEnabled()) {
- log.debug("create namespace = " + namespace);
- log.debug(" localPart = " + localPart);
+ log.debug("create namespace = " + reader.getNamespaceURI());
+ log.debug(" localPart = " + reader.getLocalName());
log.debug(" reader = " + reader.getClass());
}
- // There are some situations where we want to use normal
- // unmarshalling, so return null
- if (!shouldUnmarshal(namespace, localPart)) {
- JAXBCustomBuilderMonitor.updateTotalFailedCreates();
- return null;
- }
try {
// Create an OMSourcedElement backed by an unmarshalled JAXB object
@@ -90,37 +80,23 @@ public class JAXBCustomBuilder implement
}
}
- /**
- * @param namespace
- * @param localPart
- * @return true if this ns and local part is acceptable for unmarshalling
- */
- private boolean shouldUnmarshal(String namespace, String localPart) {
- boolean isHighFidelity = HandlerUtils.isHighFidelity(jdsContext.getMessageContext());
-
- if (isHighFidelity) {
- if (log.isDebugEnabled()) {
+ @Override
+ public boolean accepts(OMContainer parent, int depth, String namespaceURI, String localName) {
+ if (parent instanceof OMDocument || parent instanceof SOAPBody) {
+ boolean shouldUnmarshal;
+ if (HandlerUtils.isHighFidelity(jdsContext.getMessageContext())) {
log.debug("JAXB payload streaming disabled because high fidelity messages are requested.");
+ shouldUnmarshal = false;
+ } else {
+ // Don't unmarshal if this looks like encrypted data
+ shouldUnmarshal = !localName.equals("EncryptedData");
}
- return false;
-
- }
-
- // Don't unmarshall SOAPFaults or anything else in the SOAP
- // namespace.
- // Don't unmarshall elements that are unqualified
- if (localPart == null || namespace == null || namespace.length() == 0 ||
- SOAPConstants.URI_NS_SOAP_1_1_ENVELOPE.equals(namespace) ||
- SOAPConstants.URI_NS_SOAP_1_2_ENVELOPE.equals(namespace)) {
- return false;
- }
-
- // Don't unmarshal if this looks like encrypted data
- if (localPart.equals("EncryptedData")) {
+ if (!shouldUnmarshal) {
+ JAXBCustomBuilderMonitor.updateTotalFailedCreates();
+ }
+ return shouldUnmarshal;
+ } else {
return false;
}
-
- return true;
-
}
}
Modified: axis/axis2/java/core/trunk/modules/jaxws/src/org/apache/axis2/jaxws/marshaller/impl/alt/UnmarshalMessageContextListener.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/jaxws/src/org/apache/axis2/jaxws/marshaller/impl/alt/UnmarshalMessageContextListener.java?rev=1730266&r1=1730265&r2=1730266&view=diff
==============================================================================
--- axis/axis2/java/core/trunk/modules/jaxws/src/org/apache/axis2/jaxws/marshaller/impl/alt/UnmarshalMessageContextListener.java (original)
+++ axis/axis2/java/core/trunk/modules/jaxws/src/org/apache/axis2/jaxws/marshaller/impl/alt/UnmarshalMessageContextListener.java Sat Feb 13 20:10:18 2016
@@ -19,7 +19,7 @@
package org.apache.axis2.jaxws.marshaller.impl.alt;
-import org.apache.axiom.om.impl.builder.CustomBuilderSupport;
+import org.apache.axiom.om.ds.custombuilder.CustomBuilderSupport;
import org.apache.axiom.soap.SOAPEnvelope;
import org.apache.axis2.context.MessageContext;
import org.apache.axis2.context.ServiceContext;
@@ -114,7 +114,7 @@ public class UnmarshalMessageContextList
JAXBDSContext jaxbDSC = new JAXBDSContext(info.getPackages(), info.getPackagesKey());
jaxbDSC.setMessageContext(mc);
JAXBCustomBuilder jcb = new JAXBCustomBuilder(jaxbDSC);
- ((CustomBuilderSupport) envelope.getBuilder()).registerCustomBuilderForPayload(jcb);
+ ((CustomBuilderSupport) envelope.getBuilder()).registerCustomBuilder(jcb, jcb);
if (log.isDebugEnabled()) {
log.debug("Registering JAXBCustomBuilder: " + jcb + " for AxisOperation: " + axisOp.getName());
}
Modified: axis/axis2/java/core/trunk/modules/jaxws/test/org/apache/axis2/datasource/jaxb/JAXBCustomBuilderDisableStreamingTests.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/jaxws/test/org/apache/axis2/datasource/jaxb/JAXBCustomBuilderDisableStreamingTests.java?rev=1730266&r1=1730265&r2=1730266&view=diff
==============================================================================
--- axis/axis2/java/core/trunk/modules/jaxws/test/org/apache/axis2/datasource/jaxb/JAXBCustomBuilderDisableStreamingTests.java (original)
+++ axis/axis2/java/core/trunk/modules/jaxws/test/org/apache/axis2/datasource/jaxb/JAXBCustomBuilderDisableStreamingTests.java Sat Feb 13 20:10:18 2016
@@ -18,15 +18,14 @@
*/
package org.apache.axis2.datasource.jaxb;
+import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.Mockito.mock;
+
+import org.apache.axiom.soap.SOAPBody;
import org.apache.axis2.context.MessageContext;
import org.apache.axis2.description.AxisService;
import org.apache.axis2.jaxws.Constants;
-import javax.xml.namespace.NamespaceContext;
-import javax.xml.namespace.QName;
-import javax.xml.stream.Location;
-import javax.xml.stream.XMLStreamException;
-
import junit.framework.TestCase;
/**
@@ -42,13 +41,7 @@ public class JAXBCustomBuilderDisableStr
// Disable the JAXB Payload streaming
msgCtx.setProperty(Constants.JAXWS_ENABLE_JAXB_PAYLOAD_STREAMING, new Boolean(false));
jaxbDSC.setMessageContext(msgCtx);
- try {
- assertNull(jaxbCB.create(new MockXMLStreamReader("ns", "lp")));
- } catch (Exception e) {
- // Since we didn't set up the JAXBDSContext fully, if the disabling of it didn't
- // work, then we'll get some sort of exception.
- fail("JAXB Payload streaming was not disabled");
- }
+ assertThat(jaxbCB.accepts(mock(SOAPBody.class), 3, "ns", "lp")).isFalse();
}
public void testDisableJAXBPayloadStreamingWithHighFidelity() {
@@ -59,13 +52,7 @@ public class JAXBCustomBuilderDisableStr
// Disable the JAXB Payload streaming
msgCtx.setProperty(Constants.JAXWS_PAYLOAD_HIGH_FIDELITY, new Boolean(true));
jaxbDSC.setMessageContext(msgCtx);
- try {
- assertNull(jaxbCB.create(new MockXMLStreamReader("ns", "lp")));
- } catch (Exception e) {
- // Since we didn't set up the JAXBDSContext fully, if the disabling of it didn't
- // work, then we'll get some sort of exception.
- fail("JAXB Payload streaming was not disabled");
- }
+ assertThat(jaxbCB.accepts(mock(SOAPBody.class), 3, "ns", "lp")).isFalse();
}
public void testDisableJAXBPayloadStreamingWithHighFidelityParameter() throws Exception {
@@ -78,13 +65,7 @@ public class JAXBCustomBuilderDisableStr
service.addParameter(Constants.JAXWS_PAYLOAD_HIGH_FIDELITY, "true");
jaxbDSC.setMessageContext(msgCtx);
- try {
- assertNull(jaxbCB.create(new MockXMLStreamReader("ns", "lp")));
- } catch (Exception e) {
- // Since we didn't set up the JAXBDSContext fully, if the disabling of it didn't
- // work, then we'll get some sort of exception.
- fail("JAXB Payload streaming was not disabled");
- }
+ assertThat(jaxbCB.accepts(mock(SOAPBody.class), 3, "ns", "lp")).isFalse();
}
public void testDefaultJAXBPayloadStreaming() {
@@ -95,204 +76,6 @@ public class JAXBCustomBuilderDisableStr
// Do NOT Disable the JAXB Payload streaming; the default should be ON
// msgCtx.setProperty(Constants.JAXWS_ENABLE_JAXB_PAYLOAD_STREAMING, new Boolean(false));
jaxbDSC.setMessageContext(msgCtx);
- try {
- jaxbCB.create(new MockXMLStreamReader("ns", "lp"));
- fail("JAXB Payload streaming default was not enabled");
- } catch (Exception e) {
- // Expected code path
- // Since we didn't set up the JAXBDSContext fully, if the disabling of it didn't
- // work, then we'll get some sort of exception.
- }
- }
-
-
- class MockXMLStreamReader implements javax.xml.stream.XMLStreamReader {
- private final String namespaceURI;
- private final String localName;
-
- MockXMLStreamReader(String namespaceURI, String localName) {
- this.namespaceURI = namespaceURI;
- this.localName = localName;
- }
-
- public void close() throws XMLStreamException {
- }
-
- public int getAttributeCount() {
- return 0;
- }
-
- public String getAttributeLocalName(int i) {
- return null;
- }
-
- public QName getAttributeName(int i) {
- return null;
- }
-
- public String getAttributeNamespace(int i) {
- return null;
- }
-
- public String getAttributePrefix(int i) {
- return null;
- }
-
- public String getAttributeType(int i) {
- return null;
- }
-
- public String getAttributeValue(int i) {
- return null;
- }
-
- public String getAttributeValue(String s, String s1) {
- return null;
- }
-
- public String getCharacterEncodingScheme() {
- return null;
- }
-
- public String getElementText() throws XMLStreamException {
- return null;
- }
-
- public String getEncoding() {
- return null;
- }
-
- public int getEventType() {
- return 0;
- }
-
- public String getLocalName() {
- return localName;
- }
-
- public Location getLocation() {
- return null;
- }
-
- public QName getName() {
- return null;
- }
-
- public NamespaceContext getNamespaceContext() {
- return null;
- }
-
- public int getNamespaceCount() {
- return 0;
- }
-
- public String getNamespacePrefix(int i) {
- return null;
- }
-
- public String getNamespaceURI() {
- return namespaceURI;
- }
-
- public String getNamespaceURI(int i) {
- return null;
- }
-
- public String getNamespaceURI(String s) {
- return null;
- }
-
- public String getPIData() {
- return null;
- }
-
- public String getPITarget() {
- return null;
- }
-
- public String getPrefix() {
- return null;
- }
-
- public Object getProperty(String s) throws IllegalArgumentException {
- return null;
- }
-
- public String getText() {
- return null;
- }
-
- public char[] getTextCharacters() {
- return null;
- }
-
- public int getTextCharacters(int i, char[] ac, int j, int k) throws XMLStreamException {
- return 0;
- }
-
- public int getTextLength() {
- return 0;
- }
-
- public int getTextStart() {
- return 0;
- }
-
- public String getVersion() {
- return null;
- }
-
- public boolean hasName() {
- return false;
- }
-
- public boolean hasNext() throws XMLStreamException {
- return false;
- }
-
- public boolean hasText() {
- return false;
- }
-
- public boolean isAttributeSpecified(int i) {
- return false;
- }
-
- public boolean isCharacters() {
- return false;
- }
-
- public boolean isEndElement() {
- return false;
- }
-
- public boolean isStandalone() {
- return false;
- }
-
- public boolean isStartElement() {
- return false;
- }
-
- public boolean isWhiteSpace() {
- return false;
- }
-
- public int next() throws XMLStreamException {
- return 0;
- }
-
- public int nextTag() throws XMLStreamException {
- return 0;
- }
-
- public void require(int i, String s, String s1) throws XMLStreamException {
-
- }
-
- public boolean standaloneSet() {
- return false;
- }
-
+ assertThat(jaxbCB.accepts(mock(SOAPBody.class), 3, "ns", "lp")).isTrue();
}
}
Modified: axis/axis2/java/core/trunk/modules/jaxws/test/org/apache/axis2/jaxws/message/JAXBCustomBuilderTests.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/jaxws/test/org/apache/axis2/jaxws/message/JAXBCustomBuilderTests.java?rev=1730266&r1=1730265&r2=1730266&view=diff
==============================================================================
--- axis/axis2/java/core/trunk/modules/jaxws/test/org/apache/axis2/jaxws/message/JAXBCustomBuilderTests.java (original)
+++ axis/axis2/java/core/trunk/modules/jaxws/test/org/apache/axis2/jaxws/message/JAXBCustomBuilderTests.java Sat Feb 13 20:10:18 2016
@@ -26,7 +26,7 @@ import org.apache.axiom.om.OMNamespace;
import org.apache.axiom.om.OMSourcedElement;
import org.apache.axiom.om.OMXMLBuilderFactory;
import org.apache.axiom.om.OMXMLParserWrapper;
-import org.apache.axiom.om.impl.builder.CustomBuilderSupport;
+import org.apache.axiom.om.ds.custombuilder.CustomBuilderSupport;
import org.apache.axis2.datasource.jaxb.JAXBCustomBuilder;
import org.apache.axis2.datasource.jaxb.JAXBDSContext;
import org.apache.axis2.datasource.jaxb.JAXBDataSource;
@@ -103,7 +103,7 @@ public class JAXBCustomBuilderTests exte
// Register the JAXBCustomBuilder...this will intercept the payload
// and build a jaxb element
- ((CustomBuilderSupport)builder).registerCustomBuilderForPayload(jcb);
+ ((CustomBuilderSupport)builder).registerCustomBuilder(jcb, jcb);
// Get the OM element
OMElement om = builder.getDocumentElement();
Modified: axis/axis2/java/core/trunk/modules/jaxws/test/org/apache/axis2/jaxws/message/MessageTests.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/jaxws/test/org/apache/axis2/jaxws/message/MessageTests.java?rev=1730266&r1=1730265&r2=1730266&view=diff
==============================================================================
--- axis/axis2/java/core/trunk/modules/jaxws/test/org/apache/axis2/jaxws/message/MessageTests.java (original)
+++ axis/axis2/java/core/trunk/modules/jaxws/test/org/apache/axis2/jaxws/message/MessageTests.java Sat Feb 13 20:10:18 2016
@@ -24,7 +24,7 @@ import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMOutputFormat;
import org.apache.axiom.om.OMSourcedElement;
import org.apache.axiom.om.OMXMLBuilderFactory;
-import org.apache.axiom.om.impl.builder.CustomBuilderSupport;
+import org.apache.axiom.om.ds.custombuilder.CustomBuilderSupport;
import org.apache.axiom.om.impl.llom.OMSourcedElementImpl;
import org.apache.axiom.soap.SOAPModelBuilder;
import org.apache.axis2.datasource.jaxb.JAXBCustomBuilder;
@@ -910,7 +910,7 @@ public class MessageTests extends TestCa
if (installJAXBCustomBuilder) {
jds = new JAXBDSContext(EchoStringResponse.class.getPackage().getName());
JAXBCustomBuilder jcb = new JAXBCustomBuilder(jds);
- ((CustomBuilderSupport)builder).registerCustomBuilderForPayload(jcb);
+ ((CustomBuilderSupport)builder).registerCustomBuilder(jcb, jcb);
}
// Create a SOAP 1.1 Message from the sample incoming XML