Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 6EDEC200C8E for ; Thu, 8 Jun 2017 19:02:52 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 6D6D1160BC3; Thu, 8 Jun 2017 17:02:52 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 9593C160BE5 for ; Thu, 8 Jun 2017 19:02:50 +0200 (CEST) Received: (qmail 57319 invoked by uid 500); 8 Jun 2017 17:02:49 -0000 Mailing-List: contact commits-help@cxf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cxf.apache.org Delivered-To: mailing list commits@cxf.apache.org Received: (qmail 57297 invoked by uid 99); 8 Jun 2017 17:02:49 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 08 Jun 2017 17:02:49 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id F0DB4E0210; Thu, 8 Jun 2017 17:02:48 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: dkulp@apache.org To: commits@cxf.apache.org Date: Thu, 08 Jun 2017 17:02:50 -0000 Message-Id: In-Reply-To: <7de07574cd464d048f4d6031a8b91cd2@git.apache.org> References: <7de07574cd464d048f4d6031a8b91cd2@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [3/6] cxf git commit: Optimizations to keep RM Objects as objects instead of converting to DOM archived-at: Thu, 08 Jun 2017 17:02:52 -0000 Optimizations to keep RM Objects as objects instead of converting to DOM Project: http://git-wip-us.apache.org/repos/asf/cxf/repo Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/2555920e Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/2555920e Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/2555920e Branch: refs/heads/3.1.x-fixes Commit: 2555920e2d61a28423117d32e5411475132b9802 Parents: ae27ee6 Author: Daniel Kulp Authored: Thu Jun 8 11:27:58 2017 -0400 Committer: Daniel Kulp Committed: Thu Jun 8 11:48:59 2017 -0400 ---------------------------------------------------------------------- .../org/apache/cxf/binding/soap/SoapHeader.java | 15 +- rt/ws/rm/pom.xml | 12 ++ .../org/apache/cxf/ws/rm/EncoderDecoder.java | 172 +++++++++---------- .../apache/cxf/ws/rm/EncoderDecoder10AImpl.java | 42 +++-- .../apache/cxf/ws/rm/EncoderDecoder10Impl.java | 41 +++-- .../apache/cxf/ws/rm/EncoderDecoder11Impl.java | 38 ++-- .../cxf/ws/rm/soap/RMSoapOutInterceptor.java | 37 +--- .../apache/cxf/ws/rm/v200502/package-info.java | 25 +++ .../cxf/ws/rm/v200502wsa15/package-info.java | 25 +++ .../apache/cxf/ws/rm/v200702/package-info.java | 25 +++ .../ws/rm/soap/RMSoapOutInterceptorTest.java | 38 ++-- 11 files changed, 278 insertions(+), 192 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cxf/blob/2555920e/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/SoapHeader.java ---------------------------------------------------------------------- diff --git a/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/SoapHeader.java b/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/SoapHeader.java index 39ff6bc..356d0f9 100644 --- a/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/SoapHeader.java +++ b/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/SoapHeader.java @@ -33,20 +33,29 @@ public class SoapHeader extends Header { public SoapHeader(QName q, Object o, DataBinding b) { super(q, o, b); } - + public SoapHeader(QName q, Object o, DataBinding b, boolean mustUnderstand, String actor) { + super(q, o, b); + this.mustUnderstand = mustUnderstand; + this.actor = actor; + } + public SoapHeader(QName q, Object o, DataBinding b, boolean mustUnderstand) { + super(q, o, b); + this.mustUnderstand = mustUnderstand; + } + public String getActor() { return actor; } public void setActor(String actor) { this.actor = actor; } - + public boolean isMustUnderstand() { return mustUnderstand; } public void setMustUnderstand(boolean mustUnderstand) { this.mustUnderstand = mustUnderstand; } - + } http://git-wip-us.apache.org/repos/asf/cxf/blob/2555920e/rt/ws/rm/pom.xml ---------------------------------------------------------------------- diff --git a/rt/ws/rm/pom.xml b/rt/ws/rm/pom.xml index cc44ec3..d1751d9 100644 --- a/rt/ws/rm/pom.xml +++ b/rt/ws/rm/pom.xml @@ -162,6 +162,9 @@ ${basedir}/target/generated/src/main/java/org/apache/cxf/ws/addressing + + -npa + ${basedir}/src/main/resources/schemas/wsdl/wsrm-1.0-wsa15.xsd @@ -170,6 +173,9 @@ ${basedir}/target/generated/src/main/java/org/apache/cxf/ws/addressing + + -npa + ${basedir}/src/main/resources/schemas/wsdl/wsrm-1.1.xsd @@ -178,6 +184,9 @@ ${basedir}/target/generated/src/main/java/org/apache/cxf/ws/addressing + + -npa + ${basedir}/src/main/resources/schemas/wsdl/wsmc-1.1.xsd @@ -186,6 +195,9 @@ ${basedir}/target/generated/src/main/java/org/apache/cxf/ws/addressing + + -npa + ${basedir}/src/main/resources/schemas/configuration/wsrm-manager-types.xsd http://git-wip-us.apache.org/repos/asf/cxf/blob/2555920e/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/EncoderDecoder.java ---------------------------------------------------------------------- diff --git a/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/EncoderDecoder.java b/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/EncoderDecoder.java index 5515a79..3717a18 100644 --- a/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/EncoderDecoder.java +++ b/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/EncoderDecoder.java @@ -20,17 +20,18 @@ package org.apache.cxf.ws.rm; import java.util.Collection; +import java.util.List; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; import javax.xml.bind.Marshaller; import javax.xml.namespace.QName; -import org.w3c.dom.Attr; -import org.w3c.dom.Document; import org.w3c.dom.Element; -import org.apache.cxf.helpers.DOMUtils; +import org.apache.cxf.databinding.DataBinding; +import org.apache.cxf.headers.Header; +import org.apache.cxf.jaxb.JAXBDataBinding; import org.apache.cxf.ws.rm.v200702.AckRequestedType; import org.apache.cxf.ws.rm.v200702.CloseSequenceType; import org.apache.cxf.ws.rm.v200702.CreateSequenceResponseType; @@ -45,131 +46,129 @@ import org.apache.cxf.ws.rm.v200702.TerminateSequenceType; * encoding and decoding. */ public abstract class EncoderDecoder { - + protected volatile DataBinding databinding; + /** * Get context for JAXB marshalling/unmarshalling. - * + * * @return context * @throws JAXBException */ protected abstract JAXBContext getContext() throws JAXBException; - + + /** * Get the WS-ReliableMessaging namespace used by this encoder/decoder. - * + * * @return URI */ public abstract String getWSRMNamespace(); - + /** * Get the WS-Addressing namespace used by this encoder/decoder. - * + * * @return URI */ public abstract String getWSANamespace(); - + /** * Get the WS-ReliableMessaging constants used by this encoder/decoder. - * + * * @return */ public abstract RMConstants getConstants(); - + /** * Get the class used for the CreateSequenceType. - * + * * @return class */ public abstract Class getCreateSequenceType(); - + /** * Get the class used for the CreateSequenceResponseType. - * + * * @return class */ public abstract Class getCreateSequenceResponseType(); - + /** * Get the class used for the TerminateSequenceType. - * + * * @return class */ public abstract Class getTerminateSequenceType(); - + /** * Get the class used for the TerminateSequenceResponseType. - * + * * @return class */ public abstract Class getTerminateSequenceResponseType(); + + + /** + * Get the databinding used for the header objects + * @return databinding + */ + protected DataBinding getDataBinding() throws JAXBException { + DataBinding result = databinding; + if (result == null) { + synchronized (this) { + result = databinding; + if (result == null) { + result = new JAXBDataBinding(getContext()); + databinding = result; + } + } + } + return result; + } + /** * Builds an element containing WS-RM headers. This adds the appropriate WS-RM namespace declaration to the element, * and then adds any WS-RM headers set in the supplied properties as child elements. - * + * * @param rmps * @param qname constructed element name * @return element (null if none) */ - public Element buildHeaders(RMProperties rmps, QName qname) throws JAXBException { - + public void buildHeaders(RMProperties rmps, List
headers) throws JAXBException { + // check if there's anything to insert SequenceType seq = rmps.getSequence(); Collection acks = rmps.getAcks(); Collection reqs = rmps.getAcksRequested(); if (seq == null && acks == null && reqs == null) { - return null; + return; } - - // create element with namespace declaration included - Document doc = DOMUtils.createDocument(); - Element header = doc.createElementNS(qname.getNamespaceURI(), qname.getLocalPart()); - addNamespaceDecl(header); - + // build individual headers Marshaller marshaller = getContext().createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE); - buildHeaders(seq, acks, reqs, rmps.isLastMessage(), header, marshaller); - return header; - } - - /** - * Add WS-RM namespace declaration to element. - * - * @param element - */ - protected void addNamespaceDecl(Element element) { - Attr attr = element.getOwnerDocument().createAttributeNS("http://www.w3.org/2000/xmlns/", - "xmlns:" + RMConstants.NAMESPACE_PREFIX); - attr.setValue(getWSRMNamespace()); - element.setAttributeNodeNS(attr); + buildHeaders(seq, acks, reqs, rmps.isLastMessage(), headers); } - + /** * Builds an element containing a WS-RM Fault. This adds the appropriate WS-RM namespace declaration to * the element, and then adds the Fault as a child element. - * + * * @param sf * @param qname constructed element name * @return element */ - public Element buildHeaderFault(SequenceFault sf, QName qname) throws JAXBException { + public Header buildHeaderFault(SequenceFault sf) throws JAXBException { + Object o = buildHeaderFaultObject(sf); - // create element with namespace declaration included - Document doc = DOMUtils.createDocument(); - Element header = doc.createElementNS(qname.getNamespaceURI(), qname.getLocalPart()); - addNamespaceDecl(header); - - // insert the actual fault - Marshaller marshaller = getContext().createMarshaller(); - marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE); - buildHeaderFault(sf, header, marshaller); - return header; + return new Header(new QName(getConstants().getWSRMNamespace(), + RMConstants.SEQUENCE_FAULT_NAME), + o, getDataBinding()); } /** * Build all required headers, using the correct protocol variation. - * + * * @param seq * @param acks * @param reqs @@ -179,116 +178,113 @@ public abstract class EncoderDecoder { * @throws JAXBException */ protected abstract void buildHeaders(SequenceType seq, Collection acks, - Collection reqs, boolean last, Element header, Marshaller marshaller) throws JAXBException; + Collection reqs, boolean last, List
headers) throws JAXBException; /** * Build a header fault, using the correct protocol variation. - * + * * @param sf - * @param header - * @param marshaller - * @throws JAXBException + * @return the object marshallable with the JAXContext */ - protected abstract void buildHeaderFault(SequenceFault sf, Element header, Marshaller marshaller) - throws JAXBException; - + protected abstract Object buildHeaderFaultObject(SequenceFault sf); + /** * Marshals a SequenceAcknowledgement to the appropriate external form. - * + * * @param ack * @return element * @throws JAXBException */ public abstract Element encodeSequenceAcknowledgement(SequenceAcknowledgement ack) throws JAXBException; - + /** * Marshals an Identifier to the appropriate external form. - * + * * @param id * @return element * @throws JAXBException */ public abstract Element encodeIdentifier(Identifier id) throws JAXBException; - + /** * Unmarshals a SequenceType, converting it if necessary to the internal form. - * + * * @param elem * @return * @throws JAXBException */ public abstract SequenceType decodeSequenceType(Element elem) throws JAXBException; - + /** * Generates a CloseSequenceType if a SequenceType represents a last message state. - * + * * @param elem * @return CloseSequenceType if last message state, else null * @throws JAXBException */ public abstract CloseSequenceType decodeSequenceTypeCloseSequence(Element elem) throws JAXBException; - + /** * Unmarshals a SequenceAcknowledgement, converting it if necessary to the internal form. - * + * * @param elem * @return * @throws JAXBException */ public abstract SequenceAcknowledgement decodeSequenceAcknowledgement(Element elem) throws JAXBException; - + /** * Unmarshals a AckRequestedType, converting it if necessary to the internal form. - * + * * @param elem * @return * @throws JAXBException */ public abstract AckRequestedType decodeAckRequestedType(Element elem) throws JAXBException; - + /** * Convert a CreateSequence message to the correct format for transmission. - * + * * @param create * @return converted */ public abstract Object convertToSend(CreateSequenceType create); - + /** * Convert a CreateSequenceResponse message to the correct format for transmission. - * + * * @param create * @return converted */ public abstract Object convertToSend(CreateSequenceResponseType create); - + /** * Convert a TerminateSequence message to the correct format for transmission. - * + * * @param term * @return converted */ public abstract Object convertToSend(TerminateSequenceType term); - + /** * Convert a received TerminateSequence message to internal form. - * + * * @param term * @return converted */ public abstract TerminateSequenceType convertReceivedTerminateSequence(Object term); - + /** * Convert a received CreateSequence message to internal form. - * + * * @param create * @return converted */ public abstract CreateSequenceType convertReceivedCreateSequence(Object create); - + /** * Convert a received CreateSequenceResponse message to internal form. - * + * * @param create * @return converted */ http://git-wip-us.apache.org/repos/asf/cxf/blob/2555920e/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/EncoderDecoder10AImpl.java ---------------------------------------------------------------------- diff --git a/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/EncoderDecoder10AImpl.java b/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/EncoderDecoder10AImpl.java index 630dec5..16ff41b 100644 --- a/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/EncoderDecoder10AImpl.java +++ b/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/EncoderDecoder10AImpl.java @@ -20,6 +20,7 @@ package org.apache.cxf.ws.rm; import java.util.Collection; +import java.util.List; import java.util.concurrent.atomic.AtomicReference; import java.util.logging.Level; import java.util.logging.Logger; @@ -29,12 +30,15 @@ import javax.xml.bind.JAXBElement; import javax.xml.bind.JAXBException; import javax.xml.bind.Marshaller; import javax.xml.bind.Unmarshaller; +import javax.xml.namespace.QName; import org.w3c.dom.Document; import org.w3c.dom.Element; +import org.apache.cxf.binding.soap.SoapHeader; import org.apache.cxf.common.logging.LogUtils; import org.apache.cxf.common.util.PackageUtils; +import org.apache.cxf.headers.Header; import org.apache.cxf.helpers.DOMUtils; import org.apache.cxf.ws.addressing.Names; import org.apache.cxf.ws.rm.v200702.AckRequestedType; @@ -51,16 +55,16 @@ import org.apache.cxf.ws.rm.v200702.TerminateSequenceType; * 1.0 representation using the WS-Addressing recommendation 200508 namespace. */ public final class EncoderDecoder10AImpl extends EncoderDecoder { - + public static final EncoderDecoder10AImpl INSTANCE = new EncoderDecoder10AImpl(); private static AtomicReference jaxbContextReference = new AtomicReference(); private static final Logger LOG = LogUtils.getL7dLogger(EncoderDecoder10AImpl.class); - + private EncoderDecoder10AImpl() { } - + public String getWSRMNamespace() { return RM10Constants.NAMESPACE_URI; } @@ -105,34 +109,42 @@ public final class EncoderDecoder10AImpl extends EncoderDecoder { return jaxbContext; } + @Override protected void buildHeaders(SequenceType seq, Collection acks, - Collection reqs, boolean last, Element header, Marshaller marshaller) throws JAXBException { + Collection reqs, boolean last, List
headers) throws JAXBException { + if (null != seq) { LOG.log(Level.FINE, "encoding sequence into RM header"); org.apache.cxf.ws.rm.v200502wsa15.SequenceType toseq = VersionTransformer.convert200502wsa15(seq); if (last) { toseq.setLastMessage(new org.apache.cxf.ws.rm.v200502wsa15.SequenceType.LastMessage()); } - JAXBElement element + JAXBElement element = RMUtils.getWSRM200502WSA200508Factory().createSequence(toseq); - marshaller.marshal(element, header); - } + headers.add(new SoapHeader(element.getName(), element, getDataBinding(), true)); + } if (null != acks) { LOG.log(Level.FINE, "encoding sequence acknowledgement(s) into RM header"); for (SequenceAcknowledgement ack : acks) { - marshaller.marshal(VersionTransformer.convert200502wsa15(ack), header); + headers.add(new SoapHeader(new QName(getConstants().getWSRMNamespace(), + RMConstants.SEQUENCE_ACK_NAME), + VersionTransformer.convert200502wsa15(ack), getDataBinding())); } } if (null != reqs) { LOG.log(Level.FINE, "encoding acknowledgement request(s) into RM header"); for (AckRequestedType req : reqs) { - marshaller.marshal(RMUtils.getWSRM200502WSA200508Factory() - .createAckRequested(VersionTransformer.convert200502wsa15(req)), header); + headers.add(new SoapHeader(new QName(getConstants().getWSRMNamespace(), + RMConstants.ACK_REQUESTED_NAME), + RMUtils.getWSRM200502WSA200508Factory() + .createAckRequested(VersionTransformer.convert200502wsa15(req)), + getDataBinding())); } } } - public void buildHeaderFault(SequenceFault sf, Element header, Marshaller marshaller) throws JAXBException { + @Override + protected Object buildHeaderFaultObject(SequenceFault sf) { org.apache.cxf.ws.rm.v200502wsa15.SequenceFaultType flt = new org.apache.cxf.ws.rm.v200502wsa15.SequenceFaultType(); flt.setFaultCode(sf.getFaultCode()); @@ -148,9 +160,7 @@ public final class EncoderDecoder10AImpl extends EncoderDecoder { if (data != null) { flt.getAny().add(data); } - marshaller.marshal(new JAXBElement( - RM10Constants.SEQUENCE_FAULT_QNAME, - org.apache.cxf.ws.rm.v200502wsa15.SequenceFaultType.class, flt), header); + return flt; } public Element encodeSequenceAcknowledgement(SequenceAcknowledgement ack) throws JAXBException { @@ -173,7 +183,7 @@ public final class EncoderDecoder10AImpl extends EncoderDecoder { = unmarshaller.unmarshal(elem, org.apache.cxf.ws.rm.v200502wsa15.SequenceType.class); return VersionTransformer.convert(jaxbElement.getValue()); } - + public CloseSequenceType decodeSequenceTypeCloseSequence(Element elem) throws JAXBException { Unmarshaller unmarshaller = getContext().createUnmarshaller(); JAXBElement jaxbElement @@ -206,7 +216,7 @@ public final class EncoderDecoder10AImpl extends EncoderDecoder { public Object convertToSend(CreateSequenceType create) { return VersionTransformer.convert200502wsa15(create); } - + public Object convertToSend(TerminateSequenceType term) { return VersionTransformer.convert200502wsa15(term); } http://git-wip-us.apache.org/repos/asf/cxf/blob/2555920e/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/EncoderDecoder10Impl.java ---------------------------------------------------------------------- diff --git a/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/EncoderDecoder10Impl.java b/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/EncoderDecoder10Impl.java index 1d3e8d2..55658a1 100644 --- a/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/EncoderDecoder10Impl.java +++ b/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/EncoderDecoder10Impl.java @@ -20,6 +20,7 @@ package org.apache.cxf.ws.rm; import java.util.Collection; +import java.util.List; import java.util.concurrent.atomic.AtomicReference; import java.util.logging.Level; import java.util.logging.Logger; @@ -29,12 +30,15 @@ import javax.xml.bind.JAXBElement; import javax.xml.bind.JAXBException; import javax.xml.bind.Marshaller; import javax.xml.bind.Unmarshaller; +import javax.xml.namespace.QName; import org.w3c.dom.Document; import org.w3c.dom.Element; +import org.apache.cxf.binding.soap.SoapHeader; import org.apache.cxf.common.logging.LogUtils; import org.apache.cxf.common.util.PackageUtils; +import org.apache.cxf.headers.Header; import org.apache.cxf.helpers.DOMUtils; import org.apache.cxf.ws.addressing.VersionTransformer.Names200408; import org.apache.cxf.ws.rm.v200702.AckRequestedType; @@ -51,16 +55,16 @@ import org.apache.cxf.ws.rm.v200702.TerminateSequenceType; * 1.0 representation using the WS-Addressing 200408 namespace specified in the WS-RM 1.0 recommendation. */ public final class EncoderDecoder10Impl extends EncoderDecoder { - + public static final EncoderDecoder10Impl INSTANCE = new EncoderDecoder10Impl(); private static AtomicReference jaxbContextReference = new AtomicReference(); private static final Logger LOG = LogUtils.getL7dLogger(EncoderDecoder10Impl.class); - + private EncoderDecoder10Impl() { } - + public String getWSRMNamespace() { return RM10Constants.NAMESPACE_URI; } @@ -105,8 +109,9 @@ public final class EncoderDecoder10Impl extends EncoderDecoder { return jaxbContext; } + @Override protected void buildHeaders(SequenceType seq, Collection acks, - Collection reqs, boolean last, Element header, Marshaller marshaller) throws JAXBException { + Collection reqs, boolean last, List
headers) throws JAXBException { if (null != seq) { LOG.log(Level.FINE, "encoding sequence into RM header"); org.apache.cxf.ws.rm.v200502.SequenceType toseq = VersionTransformer.convert200502(seq); @@ -114,24 +119,32 @@ public final class EncoderDecoder10Impl extends EncoderDecoder { toseq.setLastMessage(new org.apache.cxf.ws.rm.v200502.SequenceType.LastMessage()); } JAXBElement element = RMUtils.getWSRM200502Factory().createSequence(toseq); - marshaller.marshal(element, header); - } + headers.add(new SoapHeader(element.getName(), element, getDataBinding(), true)); + } if (null != acks) { LOG.log(Level.FINE, "encoding sequence acknowledgement(s) into RM header"); for (SequenceAcknowledgement ack : acks) { - marshaller.marshal(VersionTransformer.convert200502(ack), header); + headers.add(new SoapHeader(new QName(getConstants().getWSRMNamespace(), + RMConstants.SEQUENCE_ACK_NAME), + VersionTransformer.convert200502(ack), + getDataBinding())); } } if (null != reqs) { LOG.log(Level.FINE, "encoding acknowledgement request(s) into RM header"); for (AckRequestedType req : reqs) { - marshaller.marshal(RMUtils.getWSRM200502Factory() - .createAckRequested(VersionTransformer.convert200502(req)), header); + headers.add(new SoapHeader(new QName(getConstants().getWSRMNamespace(), + RMConstants.ACK_REQUESTED_NAME), + RMUtils.getWSRM200502Factory() + .createAckRequested(VersionTransformer.convert200502(req)), + getDataBinding())); } } + } - public void buildHeaderFault(SequenceFault sf, Element header, Marshaller marshaller) throws JAXBException { + @Override + protected Object buildHeaderFaultObject(SequenceFault sf) { org.apache.cxf.ws.rm.v200502.SequenceFaultType flt = new org.apache.cxf.ws.rm.v200502.SequenceFaultType(); flt.setFaultCode(sf.getFaultCode()); Object detail = sf.getDetail(); @@ -146,9 +159,7 @@ public final class EncoderDecoder10Impl extends EncoderDecoder { if (data != null) { flt.getAny().add(data); } - marshaller.marshal(new JAXBElement( - RM10Constants.SEQUENCE_FAULT_QNAME, - org.apache.cxf.ws.rm.v200502.SequenceFaultType.class, flt), header); + return flt; } public Element encodeSequenceAcknowledgement(SequenceAcknowledgement ack) throws JAXBException { @@ -171,7 +182,7 @@ public final class EncoderDecoder10Impl extends EncoderDecoder { = unmarshaller.unmarshal(elem, org.apache.cxf.ws.rm.v200502.SequenceType.class); return VersionTransformer.convert(jaxbElement.getValue()); } - + public CloseSequenceType decodeSequenceTypeCloseSequence(Element elem) throws JAXBException { Unmarshaller unmarshaller = getContext().createUnmarshaller(); JAXBElement jaxbElement @@ -208,7 +219,7 @@ public final class EncoderDecoder10Impl extends EncoderDecoder { public Object convertToSend(CreateSequenceResponseType create) { return VersionTransformer.convert200502(create); } - + public Object convertToSend(TerminateSequenceType term) { return VersionTransformer.convert200502(term); } http://git-wip-us.apache.org/repos/asf/cxf/blob/2555920e/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/EncoderDecoder11Impl.java ---------------------------------------------------------------------- diff --git a/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/EncoderDecoder11Impl.java b/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/EncoderDecoder11Impl.java index 7e868cc..b896272 100644 --- a/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/EncoderDecoder11Impl.java +++ b/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/EncoderDecoder11Impl.java @@ -20,6 +20,7 @@ package org.apache.cxf.ws.rm; import java.util.Collection; +import java.util.List; import java.util.concurrent.atomic.AtomicReference; import java.util.logging.Level; import java.util.logging.Logger; @@ -29,12 +30,15 @@ import javax.xml.bind.JAXBElement; import javax.xml.bind.JAXBException; import javax.xml.bind.Marshaller; import javax.xml.bind.Unmarshaller; +import javax.xml.namespace.QName; import org.w3c.dom.Document; import org.w3c.dom.Element; +import org.apache.cxf.binding.soap.SoapHeader; import org.apache.cxf.common.logging.LogUtils; import org.apache.cxf.common.util.PackageUtils; +import org.apache.cxf.headers.Header; import org.apache.cxf.helpers.DOMUtils; import org.apache.cxf.ws.addressing.Names; import org.apache.cxf.ws.rm.v200702.AckRequestedType; @@ -53,16 +57,16 @@ import org.apache.cxf.ws.rm.v200702.TerminateSequenceType; * WS-RM data structures. */ public final class EncoderDecoder11Impl extends EncoderDecoder { - + public static final EncoderDecoder11Impl INSTANCE = new EncoderDecoder11Impl(); private static AtomicReference jaxbContextReference = new AtomicReference(); private static final Logger LOG = LogUtils.getL7dLogger(EncoderDecoder11Impl.class); - + private EncoderDecoder11Impl() { } - + public String getWSRMNamespace() { return RM11Constants.NAMESPACE_URI; } @@ -107,29 +111,36 @@ public final class EncoderDecoder11Impl extends EncoderDecoder { return jaxbContext; } + @Override protected void buildHeaders(SequenceType seq, Collection acks, - Collection reqs, boolean last, Element header, Marshaller marshaller) throws JAXBException { - + Collection reqs, boolean last, List
headers) throws JAXBException { + if (null != seq) { LOG.log(Level.FINE, "encoding sequence into RM header"); JAXBElement element = RMUtils.getWSRMFactory().createSequence(seq); - marshaller.marshal(element, header); - } + headers.add(new SoapHeader(element.getName(), element, getDataBinding(), true)); + } if (null != acks) { LOG.log(Level.FINE, "encoding sequence acknowledgement(s) into RM header"); for (SequenceAcknowledgement ack : acks) { - marshaller.marshal(ack, header); + headers.add(new SoapHeader(new QName(getConstants().getWSRMNamespace(), + RMConstants.SEQUENCE_ACK_NAME), + ack, getDataBinding())); } } if (null != reqs) { LOG.log(Level.FINE, "encoding acknowledgement request(s) into RM header"); for (AckRequestedType req : reqs) { - marshaller.marshal(RMUtils.getWSRMFactory().createAckRequested(req), header); + headers.add(new SoapHeader(new QName(getConstants().getWSRMNamespace(), + RMConstants.ACK_REQUESTED_NAME), + RMUtils.getWSRMFactory().createAckRequested(req), + getDataBinding())); } } } - public void buildHeaderFault(SequenceFault sf, Element header, Marshaller marshaller) throws JAXBException { + @Override + protected Object buildHeaderFaultObject(SequenceFault sf) { SequenceFaultType flt = new SequenceFaultType(); flt.setFaultCode(sf.getFaultCode()); Object detail = sf.getDetail(); @@ -138,8 +149,7 @@ public final class EncoderDecoder11Impl extends EncoderDecoder { if (data != null) { addDetail(flt, data); } - marshaller.marshal(new JAXBElement(RM11Constants.SEQUENCE_FAULT_QNAME, - SequenceFaultType.class, flt), header); + return flt; } private static void addDetail(SequenceFaultType sft, Element data) { @@ -168,7 +178,7 @@ public final class EncoderDecoder11Impl extends EncoderDecoder { JAXBElement jaxbElement = unmarshaller.unmarshal(elem, SequenceType.class); return jaxbElement.getValue(); } - + public CloseSequenceType decodeSequenceTypeCloseSequence(Element elem) throws JAXBException { return null; } @@ -191,7 +201,7 @@ public final class EncoderDecoder11Impl extends EncoderDecoder { public Object convertToSend(CreateSequenceResponseType create) { return create; } - + public Object convertToSend(TerminateSequenceType term) { return term; } http://git-wip-us.apache.org/repos/asf/cxf/blob/2555920e/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/soap/RMSoapOutInterceptor.java ---------------------------------------------------------------------- diff --git a/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/soap/RMSoapOutInterceptor.java b/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/soap/RMSoapOutInterceptor.java index 26342d4..cb070ad 100644 --- a/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/soap/RMSoapOutInterceptor.java +++ b/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/soap/RMSoapOutInterceptor.java @@ -30,12 +30,8 @@ import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; import javax.xml.namespace.QName; -import org.w3c.dom.Attr; -import org.w3c.dom.Element; -import org.w3c.dom.Node; import org.apache.cxf.binding.soap.SoapFault; -import org.apache.cxf.binding.soap.SoapHeader; import org.apache.cxf.binding.soap.SoapMessage; import org.apache.cxf.binding.soap.interceptor.AbstractSoapInterceptor; import org.apache.cxf.common.logging.LogUtils; @@ -49,7 +45,6 @@ import org.apache.cxf.ws.addressing.soap.MAPCodec; import org.apache.cxf.ws.rm.ProtocolVariation; import org.apache.cxf.ws.rm.RM10Constants; import org.apache.cxf.ws.rm.RM11Constants; -import org.apache.cxf.ws.rm.RMConstants; import org.apache.cxf.ws.rm.RMContextUtils; import org.apache.cxf.ws.rm.RMProperties; import org.apache.cxf.ws.rm.SequenceFault; @@ -132,26 +127,13 @@ public class RMSoapOutInterceptor extends AbstractSoapInterceptor { AddressingProperties maps = RMContextUtils.retrieveMAPs(message, false, true); ProtocolVariation protocol = ProtocolVariation.findVariant(rmps.getNamespaceURI(), maps.getNamespaceURI()); - Element header = protocol.getCodec().buildHeaders(rmps, message.getVersion().getHeader()); - if (header != null) { - Node node = header.getFirstChild(); - if (node != null && MessageUtils.isPartialResponse(message)) { + List
headers = message.getHeaders(); + int startSize = headers.size(); + protocol.getCodec().buildHeaders(rmps, headers); + if (startSize != headers.size() && MessageUtils.isPartialResponse(message)) { // make sure the response is returned as HTTP 200 and not 202 message.put(Message.RESPONSE_CODE, HttpURLConnection.HTTP_OK); } - while (node != null) { - Header holder = null; - if (node.getLocalName().equals("Sequence")) { - holder = new SoapHeader(new QName(node.getNamespaceURI(), node.getLocalName()), node); - ((SoapHeader)holder).setMustUnderstand(true); - } else { - holder = new Header(new QName(node.getNamespaceURI(), node.getLocalName()), node); - } - message.getHeaders().add(holder); - node = node.getNextSibling(); - } - } - } catch (JAXBException je) { LOG.log(Level.WARNING, "SOAP_HEADER_ENCODE_FAILURE_MSG", je); } @@ -171,16 +153,9 @@ public class RMSoapOutInterceptor extends AbstractSoapInterceptor { AddressingProperties maps = RMContextUtils.retrieveMAPs(inmsg, false, false); ProtocolVariation protocol = ProtocolVariation.findVariant(rmps.getNamespaceURI(), maps.getNamespaceURI()); - Element header = protocol.getCodec().buildHeaderFault(sf, message.getVersion().getHeader()); - Node node = header.getFirstChild(); - if (node instanceof Element) { - Attr attr = header.getOwnerDocument().createAttributeNS("http://www.w3.org/2000/xmlns/", - "xmlns:" + RMConstants.NAMESPACE_PREFIX); - attr.setValue(rmps.getNamespaceURI()); - ((Element)node).setAttributeNodeNS(attr); - } + Header header = protocol.getCodec().buildHeaderFault(sf); List
headers = message.getHeaders(); - headers.add(new Header(new QName(node.getNamespaceURI(), node.getLocalName()), node)); + headers.add(header); } catch (JAXBException je) { LOG.log(Level.WARNING, "SOAP_HEADER_ENCODE_FAILURE_MSG", je); } http://git-wip-us.apache.org/repos/asf/cxf/blob/2555920e/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/v200502/package-info.java ---------------------------------------------------------------------- diff --git a/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/v200502/package-info.java b/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/v200502/package-info.java new file mode 100644 index 0000000..b891c8e --- /dev/null +++ b/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/v200502/package-info.java @@ -0,0 +1,25 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ +@javax.xml.bind.annotation.XmlSchema( + namespace = "http://schemas.xmlsoap.org/ws/2005/02/rm", + elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED, + xmlns = { @javax.xml.bind.annotation.XmlNs(namespaceURI = "http://schemas.xmlsoap.org/ws/2005/02/rm", + prefix = "wsrm") }) +package org.apache.cxf.ws.rm.v200502; + http://git-wip-us.apache.org/repos/asf/cxf/blob/2555920e/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/v200502wsa15/package-info.java ---------------------------------------------------------------------- diff --git a/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/v200502wsa15/package-info.java b/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/v200502wsa15/package-info.java new file mode 100644 index 0000000..b115768 --- /dev/null +++ b/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/v200502wsa15/package-info.java @@ -0,0 +1,25 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ +@javax.xml.bind.annotation.XmlSchema( + namespace = "http://schemas.xmlsoap.org/ws/2005/02/rm", + elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED, + xmlns = { @javax.xml.bind.annotation.XmlNs(namespaceURI = "http://schemas.xmlsoap.org/ws/2005/02/rm", + prefix = "wsrm") }) +package org.apache.cxf.ws.rm.v200502wsa15; + http://git-wip-us.apache.org/repos/asf/cxf/blob/2555920e/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/v200702/package-info.java ---------------------------------------------------------------------- diff --git a/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/v200702/package-info.java b/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/v200702/package-info.java new file mode 100644 index 0000000..1862fbf --- /dev/null +++ b/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/v200702/package-info.java @@ -0,0 +1,25 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ +@javax.xml.bind.annotation.XmlSchema( + namespace = "http://docs.oasis-open.org/ws-rx/wsrm/200702", + elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED, + xmlns = { @javax.xml.bind.annotation.XmlNs(namespaceURI = "http://docs.oasis-open.org/ws-rx/wsrm/200702", + prefix = "wsrm") }) +package org.apache.cxf.ws.rm.v200702; + http://git-wip-us.apache.org/repos/asf/cxf/blob/2555920e/rt/ws/rm/src/test/java/org/apache/cxf/ws/rm/soap/RMSoapOutInterceptorTest.java ---------------------------------------------------------------------- diff --git a/rt/ws/rm/src/test/java/org/apache/cxf/ws/rm/soap/RMSoapOutInterceptorTest.java b/rt/ws/rm/src/test/java/org/apache/cxf/ws/rm/soap/RMSoapOutInterceptorTest.java index 3d10125..0056673 100644 --- a/rt/ws/rm/src/test/java/org/apache/cxf/ws/rm/soap/RMSoapOutInterceptorTest.java +++ b/rt/ws/rm/src/test/java/org/apache/cxf/ws/rm/soap/RMSoapOutInterceptorTest.java @@ -257,53 +257,41 @@ public class RMSoapOutInterceptorTest extends Assert { } private void verifyHeaders(SoapMessage message, String... names) { - List
header = message.getHeaders(); + List
headers = new ArrayList
(message.getHeaders()); // check all expected headers are present for (String name : names) { boolean found = false; - Iterator
iter = header.iterator(); + Iterator
iter = headers.iterator(); while (iter.hasNext()) { - Object obj = iter.next().getObject(); + Header header = iter.next(); + Object obj = header.getObject(); + String namespace = header.getName().getNamespaceURI(); + String localName = header.getName().getLocalPart(); if (obj instanceof Element) { Element elem = (Element) obj; - String namespace = elem.getNamespaceURI(); - String localName = elem.getLocalName(); + namespace = elem.getNamespaceURI(); + localName = elem.getLocalName(); + } if (RM10Constants.NAMESPACE_URI.equals(namespace) && localName.equals(name)) { found = true; + iter.remove(); break; } else if (Names.WSA_NAMESPACE_NAME.equals(namespace) && localName.equals(name)) { found = true; + iter.remove(); break; } } - } assertTrue("Could not find header element " + name, found); } // no other headers should be present - - Iterator
iter1 = header.iterator(); - while (iter1.hasNext()) { - Object obj = iter1.next().getObject(); - if (obj instanceof Element) { - Element elem = (Element) obj; - String namespace = elem.getNamespaceURI(); - String localName = elem.getLocalName(); - assertTrue(RM10Constants.NAMESPACE_URI.equals(namespace) - || Names.WSA_NAMESPACE_NAME.equals(namespace)); - boolean found = false; - for (String name : names) { - if (localName.equals(name)) { - found = true; - break; - } - } - assertTrue("Unexpected header element " + localName, found); - } + if (!headers.isEmpty()) { + assertTrue("Unexpected header element " + headers.get(0).getName(), false); } } }