Skip to content
Permalink
Browse files
CXF-4866, CXF-352: Fixes to restructured WS-RM code from problems
found with unit tests, and corrected unit tests to work with the
restructured code.

git-svn-id: https://svn.apache.org/repos/asf/cxf/trunk@1566556 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
Dennis M. Sosnoski committed Feb 10, 2014
1 parent b54206b commit ac9ced7fed677f3802b16ebc68d6ab11be2be420
Show file tree
Hide file tree
Showing 14 changed files with 314 additions and 872 deletions.
@@ -24,7 +24,6 @@
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.namespace.QName;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
@@ -129,7 +128,25 @@ public boolean insertHeaders(RMProperties rmps, Document doc) throws JAXBExcepti
return false;
}

// get the SOAP:Header element
// add WSRM namespace declaration to header, instead of repeating in each individual child node
Element header = getSoapHeader(doc);
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 true;
}

/**
* Get the SOAP Header element from a message document.
*
* @param doc
* @return header
* @throws JAXBException if not found
*/
protected Element getSoapHeader(Document doc) throws JAXBException {
NodeList nodes = doc.getDocumentElement().getChildNodes();
Element header = null;
for (int i = 0; i < nodes.getLength(); i++) {
@@ -142,15 +159,22 @@ public boolean insertHeaders(RMProperties rmps, Document doc) throws JAXBExcepti
if (header == null) {
throw new JAXBException("No SOAP:Header element in message");
}

// add WSRM namespace declaration to header, instead of repeating in each individual child node
return header;
}

/**
* Inserts a Header element containing a WS-RM Fault into a SOAP message.
*
* @param sf
* @param qname constructed element name
* @param doc
*/
public void insertHeaderFault(SequenceFault sf, Document doc) throws JAXBException {
Element header = getSoapHeader(doc);
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 true;
buildHeaderFault(sf, header, marshaller);
}

/**
@@ -166,16 +190,17 @@ public boolean insertHeaders(RMProperties rmps, Document doc) throws JAXBExcepti
*/
protected abstract void buildHeaders(SequenceType seq, Collection<SequenceAcknowledgement> acks,
Collection<AckRequestedType> reqs, boolean last, Element header, Marshaller marshaller) throws JAXBException;

/**
* 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.
* Build a header fault, using the correct protocol variation.
*
* @param sf
* @param qname constructed element name
* @return element
* @param header
* @param marshaller
* @throws JAXBException
*/
public abstract Element buildHeaderFault(SequenceFault sf, QName qname) throws JAXBException;
protected abstract void buildHeaderFault(SequenceFault sf, Element header, Marshaller marshaller)
throws JAXBException;

/**
* Marshals a SequenceAcknowledgement to the appropriate external form.
@@ -29,7 +29,6 @@
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;
import javax.xml.namespace.QName;

import org.w3c.dom.Attr;
import org.w3c.dom.Document;
@@ -141,40 +140,30 @@ protected void buildHeaders(SequenceType seq, Collection<SequenceAcknowledgement
}
}

public Element buildHeaderFault(SequenceFault sf, QName qname) throws JAXBException {

Document doc = DOMUtils.createDocument();
Element header = doc.createElementNS(qname.getNamespaceURI(), qname.getLocalPart());
// add WSRM namespace declaration to header, instead of
// repeating in each individual child node

Attr attr = doc.createAttributeNS("http://www.w3.org/2000/xmlns/",
"xmlns:" + RMConstants.NAMESPACE_PREFIX);
attr.setValue(RM10Constants.NAMESPACE_URI);
header.setAttributeNodeNS(attr);

Marshaller marshaller = getContext().createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
QName fqname = RM10Constants.SEQUENCE_FAULT_QNAME;
public void buildHeaderFault(SequenceFault sf, Element header, Marshaller marshaller) throws JAXBException {
org.apache.cxf.ws.rm.v200502wsa15.SequenceFaultType flt =
new org.apache.cxf.ws.rm.v200502wsa15.SequenceFaultType();
flt.setFaultCode(sf.getFaultCode());
Object detail = sf.getDetail();
Document doc = DOMUtils.createDocument();
if (detail instanceof Element) {
flt.getAny().add(detail);
} else if (detail instanceof Identifier) {
marshaller.marshal(VersionTransformer.convert200502wsa15((Identifier)detail), doc);
} else if (detail instanceof SequenceAcknowledgement) {
marshaller.marshal(VersionTransformer.convert200502wsa15((SequenceAcknowledgement)detail),
doc);
marshaller.marshal(VersionTransformer.convert200502wsa15((SequenceAcknowledgement)detail), doc);
}
Element data = doc.getDocumentElement();
if (data != null) {
flt.getAny().add(data);
}
marshaller.marshal(new JAXBElement<org.apache.cxf.ws.rm.v200502wsa15.SequenceFaultType>(fqname,
data = sf.getExtraDetail();
if (data != null) {
flt.getAny().add(data);
}
marshaller.marshal(new JAXBElement<org.apache.cxf.ws.rm.v200502wsa15.SequenceFaultType>(
RM10Constants.SEQUENCE_FAULT_QNAME,
org.apache.cxf.ws.rm.v200502wsa15.SequenceFaultType.class, flt), header);
return header;
}

public Element encodeSequenceAcknowledgement(SequenceAcknowledgement ack) throws JAXBException {
@@ -29,7 +29,6 @@
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;
import javax.xml.namespace.QName;

import org.w3c.dom.Attr;
import org.w3c.dom.Document;
@@ -140,25 +139,11 @@ protected void buildHeaders(SequenceType seq, Collection<SequenceAcknowledgement
}
}

public Element buildHeaderFault(SequenceFault sf, QName qname) throws JAXBException {

Document doc = DOMUtils.createDocument();
Element header = doc.createElementNS(qname.getNamespaceURI(), qname.getLocalPart());
// add WSRM namespace declaration to header, instead of
// repeating in each individual child node

Attr attr = doc.createAttributeNS("http://www.w3.org/2000/xmlns/",
"xmlns:" + RMConstants.NAMESPACE_PREFIX);
attr.setValue(RM10Constants.NAMESPACE_URI);
header.setAttributeNodeNS(attr);

Marshaller marshaller = getContext().createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
QName fqname = RM10Constants.SEQUENCE_FAULT_QNAME;
org.apache.cxf.ws.rm.v200502.SequenceFaultType flt =
new org.apache.cxf.ws.rm.v200502.SequenceFaultType();
public void buildHeaderFault(SequenceFault sf, Element header, Marshaller marshaller) throws JAXBException {
org.apache.cxf.ws.rm.v200502.SequenceFaultType flt = new org.apache.cxf.ws.rm.v200502.SequenceFaultType();
flt.setFaultCode(sf.getFaultCode());
Object detail = sf.getDetail();
Document doc = DOMUtils.createDocument();
if (detail instanceof Element) {
flt.getAny().add(detail);
} else if (detail instanceof Identifier) {
@@ -170,9 +155,13 @@ public Element buildHeaderFault(SequenceFault sf, QName qname) throws JAXBExcept
if (data != null) {
flt.getAny().add(data);
}
marshaller.marshal(new JAXBElement<org.apache.cxf.ws.rm.v200502.SequenceFaultType>(fqname,
data = sf.getExtraDetail();
if (data != null) {
flt.getAny().add(data);
}
marshaller.marshal(new JAXBElement<org.apache.cxf.ws.rm.v200502.SequenceFaultType>(
RM10Constants.SEQUENCE_FAULT_QNAME,
org.apache.cxf.ws.rm.v200502.SequenceFaultType.class, flt), header);
return header;
}

public Element encodeSequenceAcknowledgement(SequenceAcknowledgement ack) throws JAXBException {
@@ -29,7 +29,6 @@
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;
import javax.xml.namespace.QName;

import org.w3c.dom.Attr;
import org.w3c.dom.Document;
@@ -137,20 +136,11 @@ protected void addNamespaceDecl(Element element) {
element.setAttributeNodeNS(attr);
}

public Element buildHeaderFault(SequenceFault sf, QName qname) throws JAXBException {

Document doc = DOMUtils.createDocument();
Element header = doc.createElementNS(qname.getNamespaceURI(), qname.getLocalPart());

// add WSRM namespace declaration to header, instead of repeating in each individual child node
addNamespaceDecl(header);

Marshaller marshaller = getContext().createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
QName fqname = RM11Constants.SEQUENCE_FAULT_QNAME;
public void buildHeaderFault(SequenceFault sf, Element header, Marshaller marshaller) throws JAXBException {
SequenceFaultType flt = new SequenceFaultType();
flt.setFaultCode(sf.getFaultCode());
Object detail = sf.getDetail();
Document doc = DOMUtils.createDocument();
if (detail instanceof Element) {
flt.getAny().add(detail);
} else if (detail instanceof Identifier) {
@@ -166,8 +156,8 @@ public Element buildHeaderFault(SequenceFault sf, QName qname) throws JAXBExcept
if (data != null) {
flt.getDetail().getAny().add(data);
}
marshaller.marshal(new JAXBElement<SequenceFaultType>(fqname, SequenceFaultType.class, flt), header);
return header;
marshaller.marshal(new JAXBElement<SequenceFaultType>(RM11Constants.SEQUENCE_FAULT_QNAME,
SequenceFaultType.class, flt), header);
}

public Element encodeSequenceAcknowledgement(SequenceAcknowledgement ack) throws JAXBException {
@@ -155,7 +155,7 @@ public class RMTxStore implements RMStore {
private static final String SELECT_MESSAGES_STMT_STR =
"SELECT MSG_NO, SEND_TO, CONTENT FROM {0} WHERE SEQ_ID = ?";
private static final String SELECT_ATTACHMENTS_STMT_STR =
"SELECT ATTACHMENT_NO, DATA FROM {0} WHERE SEQ_ID = ?, MSG_ID = ?";
"SELECT ATTACHMENT_NO, DATA FROM {0} WHERE SEQ_ID = ? AND MSG_NO = ?";
private static final String ALTER_TABLE_STMT_STR =
"ALTER TABLE {0} ADD {1} {2}";
private static final String CREATE_INBOUND_MESSAGE_STMT_STR =
@@ -1104,8 +1104,7 @@ protected void releaseResources(PreparedStatement stmt, ResultSet rs) {
}


protected void cacheStatement(Connection con, String sql)
throws SQLException {
protected void cacheStatement(Connection con, String sql) throws SQLException {
PreparedStatement stmt = con.prepareStatement(sql);
cachedStatements.put(sql, stmt);
statementLocks.put(stmt, new ReentrantLock());
@@ -1137,6 +1136,12 @@ protected void cacheStatements() throws SQLException {
cacheStatement(connection, DELETE_OUTBOUND_MESSAGE_STMT_STR);
cacheStatement(connection, SELECT_INBOUND_MESSAGES_STMT_STR);
cacheStatement(connection, SELECT_OUTBOUND_MESSAGES_STMT_STR);
cacheStatement(connection, CREATE_INBOUND_ATTACHMENT_STMT_STR);
cacheStatement(connection, CREATE_OUTBOUND_ATTACHMENT_STMT_STR);
cacheStatement(connection, DELETE_INBOUND_ATTACHMENTS_STMT_STR);
cacheStatement(connection, DELETE_OUTBOUND_ATTACHMENTS_STMT_STR);
cacheStatement(connection, SELECT_INBOUND_ATTACHMENTS_STMT_STR);
cacheStatement(connection, SELECT_OUTBOUND_ATTACHMENTS_STMT_STR);
}

public synchronized void init() {
@@ -21,7 +21,6 @@

import java.net.HttpURLConnection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -32,16 +31,10 @@
import javax.xml.soap.SOAPException;
import javax.xml.soap.SOAPMessage;

import org.w3c.dom.Attr;
import org.w3c.dom.Element;
import org.w3c.dom.Node;

import org.apache.cxf.binding.soap.Soap11;
import org.apache.cxf.binding.soap.SoapFault;
import org.apache.cxf.binding.soap.SoapMessage;
import org.apache.cxf.binding.soap.interceptor.AbstractSoapInterceptor;
import org.apache.cxf.common.logging.LogUtils;
import org.apache.cxf.headers.Header;
import org.apache.cxf.interceptor.Fault;
import org.apache.cxf.message.Message;
import org.apache.cxf.message.MessageUtils;
@@ -50,7 +43,6 @@
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.RMOutInterceptor;
import org.apache.cxf.ws.rm.RMProperties;
@@ -144,16 +136,9 @@ public static void encode(SoapMessage message, RMProperties rmps) {
if (added) {
try {
content.saveChanges();
// ByteArrayOutputStream bos = new ByteArrayOutputStream();
// content.writeTo(bos);
// bos.close();
// LOG.info("Message after headers added: " + bos.toString("UTF-8"));
} catch (SOAPException e) {
// TODO Auto-generated catch block
e.printStackTrace();
// } catch (IOException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
}

}
@@ -172,22 +157,13 @@ public static void encode(SoapMessage message, RMProperties rmps) {
public static void encodeFault(SoapMessage message, SequenceFault sf) {
LOG.log(Level.FINE, "Encoding SequenceFault in SOAP header");
try {
List<Header> headers = message.getHeaders();
Message inmsg = message.getExchange().getInMessage();
RMProperties rmps = RMContextUtils.retrieveRMProperties(inmsg, false);
AddressingProperties maps = RMContextUtils.retrieveMAPs(inmsg, false, false);
ProtocolVariation protocol = ProtocolVariation.findVariant(rmps.getNamespaceURI(),
maps.getNamespaceURI());
Element header = protocol.getCodec().buildHeaderFault(sf, Soap11.getInstance().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);
}

headers.add(new Header(new QName(node.getNamespaceURI(), node.getLocalName()), node));
SOAPMessage content = message.getContent(SOAPMessage.class);
protocol.getCodec().insertHeaderFault(sf, content.getSOAPPart());
} catch (JAXBException je) {
LOG.log(Level.WARNING, "SOAP_HEADER_ENCODE_FAILURE_MSG", je);
}
@@ -19,7 +19,6 @@

package org.apache.cxf.ws.rm;

import java.io.IOException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collection;
@@ -37,7 +36,6 @@
import org.apache.cxf.endpoint.Client;
import org.apache.cxf.endpoint.Endpoint;
import org.apache.cxf.endpoint.Server;
import org.apache.cxf.io.CachedOutputStream;
import org.apache.cxf.message.Exchange;
import org.apache.cxf.message.Message;
import org.apache.cxf.service.Service;
@@ -645,14 +643,6 @@ void setUpRecoverReliableEndpoint(Endpoint endpoint,
if (null == conduit) {
EasyMock.expect(m.getTo()).andReturn("toAddress");
}
byte[] content = new byte[] {'x', '9'};
CachedOutputStream cos = new CachedOutputStream();
try {
cos.write(content);
} catch (IOException e) {
// ignore
}
EasyMock.expect(m.getCachedOutputStream()).andReturn(cos);

if (mc != null) {
queue.addUnacknowledged(EasyMock.capture(mc));

0 comments on commit ac9ced7

Please sign in to comment.