use of org.apache.cxf.headers.Header in project cxf by apache.
the class RMSoapOutInterceptorTest method verifyHeaders.
private void verifyHeaders(SoapMessage message, String... names) {
List<Header> headers = new ArrayList<Header>(message.getHeaders());
for (String name : names) {
boolean found = false;
Iterator<Header> iter = headers.iterator();
while (iter.hasNext()) {
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;
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
if (!headers.isEmpty()) {
assertTrue("Unexpected header element " + headers.get(0).getName(), false);
}
}
use of org.apache.cxf.headers.Header in project cxf by apache.
the class RMSoapInInterceptor method decodeHeaders.
public void decodeHeaders(SoapMessage message, List<Header> headers, RMProperties rmps) {
try {
Collection<SequenceAcknowledgement> acks = new ArrayList<>();
Collection<AckRequestedType> requested = new ArrayList<>();
String rmUri = null;
EncoderDecoder codec = null;
Iterator<Header> iter = headers.iterator();
while (iter.hasNext()) {
Object node = iter.next().getObject();
if (node instanceof Element) {
Element elem = (Element) node;
if (Node.ELEMENT_NODE != elem.getNodeType()) {
continue;
}
String ns = elem.getNamespaceURI();
if (rmUri == null && (RM10Constants.NAMESPACE_URI.equals(ns) || RM11Constants.NAMESPACE_URI.equals(ns))) {
LOG.log(Level.FINE, "set RM namespace {0}", ns);
rmUri = ns;
rmps.exposeAs(rmUri);
}
if (rmUri != null && rmUri.equals(ns)) {
if (codec == null) {
String wsauri = null;
AddressingProperties maps = ContextUtils.retrieveMAPs(message, false, false, false);
if (maps == null) {
RMConfiguration config = getManager(message).getEffectiveConfiguration(message);
wsauri = config.getAddressingNamespace();
} else {
wsauri = maps.getNamespaceURI();
}
ProtocolVariation protocol = ProtocolVariation.findVariant(rmUri, wsauri);
if (protocol == null) {
LOG.log(Level.WARNING, "NAMESPACE_ERROR_MSG", wsauri);
break;
}
codec = protocol.getCodec();
}
String localName = elem.getLocalName();
LOG.log(Level.FINE, "decoding RM header {0}", localName);
if (RMConstants.SEQUENCE_NAME.equals(localName)) {
rmps.setSequence(codec.decodeSequenceType(elem));
rmps.setCloseSequence(codec.decodeSequenceTypeCloseSequence(elem));
} else if (RMConstants.SEQUENCE_ACK_NAME.equals(localName)) {
acks.add(codec.decodeSequenceAcknowledgement(elem));
} else if (RMConstants.ACK_REQUESTED_NAME.equals(localName)) {
requested.add(codec.decodeAckRequestedType(elem));
}
}
}
}
if (!acks.isEmpty()) {
rmps.setAcks(acks);
}
if (!requested.isEmpty()) {
rmps.setAcksRequested(requested);
}
} catch (JAXBException ex) {
LOG.log(Level.WARNING, "SOAP_HEADER_DECODE_FAILURE_MSG", ex);
}
}
use of org.apache.cxf.headers.Header in project cxf by apache.
the class DecoupledFaultHandler method handleFault.
// Ideally, this code will instead be executed as part of the Fault chain
// but at the moment PhaseInterceptorChain needs to be tricked that this is
// a two way request for a fault chain be invoked
public void handleFault(SoapMessage message) {
if (!ContextUtils.isRequestor(message)) {
Exchange exchange = message.getExchange();
Message inMessage = exchange.getInMessage();
final AddressingProperties maps = ContextUtils.retrieveMAPs(inMessage, false, false, true);
if (maps != null && !ContextUtils.isGenericAddress(maps.getFaultTo())) {
// Just keep the wsa headers to remove the not understand headers
if (exchange.getOutMessage() != null) {
message = (SoapMessage) exchange.getOutMessage();
}
Iterator<Header> iterator = message.getHeaders().iterator();
while (iterator.hasNext()) {
Header header = iterator.next();
if (!isWSAHeader(header)) {
iterator.remove();
}
}
exchange.setOneWay(false);
exchange.setOutMessage(message);
// manually set the action
message.put(ContextUtils.ACTION, WSA_ACTION);
Destination destination = createDecoupledDestination(exchange, maps.getFaultTo());
exchange.setDestination(destination);
}
}
}
use of org.apache.cxf.headers.Header in project cxf by apache.
the class MAPCodec method encode.
/**
* Encode the current MAPs in protocol-specific headers.
*
* @param message the messsage message
* @param maps the MAPs to encode
*/
private void encode(SoapMessage message, AddressingProperties maps) {
if (maps != null) {
cacheExchange(message, maps);
LOG.log(Level.FINE, "Outbound WS-Addressing headers");
try {
List<Header> header = message.getHeaders();
discardMAPs(header, maps);
JAXBContext jaxbContext = org.apache.cxf.ws.addressing.VersionTransformer.getExposedJAXBContext(maps.getNamespaceURI());
QName duplicate = maps.getDuplicate();
encodeAsExposed(maps, message, maps.getAction(), Names.WSA_ACTION_QNAME, AttributedURIType.class, jaxbContext);
if (Names.WSA_ACTION_QNAME.equals(duplicate)) {
encodeAsExposed(maps, message, maps.getAction(), Names.WSA_ACTION_QNAME, AttributedURIType.class, jaxbContext);
}
encodeAsExposed(maps, message, maps.getMessageID(), Names.WSA_MESSAGEID_QNAME, AttributedURIType.class, jaxbContext);
if (Names.WSA_MESSAGEID_QNAME.equals(duplicate)) {
encodeAsExposed(maps, message, maps.getMessageID(), Names.WSA_MESSAGEID_QNAME, AttributedURIType.class, jaxbContext);
}
encodeAsExposed(maps, message, maps.getTo(), Names.WSA_TO_QNAME, AttributedURIType.class, jaxbContext);
if (Names.WSA_TO_QNAME.equals(duplicate)) {
encodeAsExposed(maps, message, maps.getTo(), Names.WSA_TO_QNAME, AttributedURIType.class, jaxbContext);
}
if (needsReplyTo(maps, message)) {
encodeAsExposed(maps, message, maps.getReplyTo(), Names.WSA_REPLYTO_QNAME, EndpointReferenceType.class, jaxbContext);
if (Names.WSA_REPLYTO_QNAME.equals(duplicate)) {
encodeAsExposed(maps, message, maps.getReplyTo(), Names.WSA_REPLYTO_QNAME, EndpointReferenceType.class, jaxbContext);
}
}
encodeAsExposed(maps, message, maps.getRelatesTo(), Names.WSA_RELATESTO_QNAME, RelatesToType.class, jaxbContext);
if (Names.WSA_RELATESTO_QNAME.equals(duplicate)) {
encodeAsExposed(maps, message, maps.getRelatesTo(), Names.WSA_RELATESTO_QNAME, RelatesToType.class, jaxbContext);
}
encodeAsExposed(maps, message, maps.getFrom(), Names.WSA_FROM_QNAME, EndpointReferenceType.class, jaxbContext);
if (Names.WSA_FROM_QNAME.equals(duplicate)) {
encodeAsExposed(maps, message, maps.getFrom(), Names.WSA_FROM_QNAME, EndpointReferenceType.class, jaxbContext);
}
if (needsFaultTo(maps)) {
encodeAsExposed(maps, message, maps.getFaultTo(), Names.WSA_FAULTTO_QNAME, EndpointReferenceType.class, jaxbContext);
if (Names.WSA_FAULTTO_QNAME.equals(duplicate)) {
encodeAsExposed(maps, message, maps.getFaultTo(), Names.WSA_FAULTTO_QNAME, EndpointReferenceType.class, jaxbContext);
}
}
encodeReferenceParameters(maps, message, jaxbContext);
maps.setDuplicate(null);
propogateAction(maps.getAction(), message);
applyMAPValidation(message);
} catch (JAXBException je) {
LOG.log(Level.WARNING, "SOAP_HEADER_ENCODE_FAILURE_MSG", je);
}
}
}
use of org.apache.cxf.headers.Header in project cxf by apache.
the class MAPCodecTest method setUpMessage.
private SoapMessage setUpMessage(boolean requestor, boolean outbound, boolean invalidMAP, boolean preExistingSOAPAction, Boolean generateRelatesTo, String exposeAs) throws Exception {
SoapMessage message = new SoapMessage(new MessageImpl());
setUpOutbound(message, outbound);
expectRelatesTo = generateRelatesTo != null ? generateRelatesTo : (requestor && !outbound) || (!requestor && outbound);
message.put(REQUESTOR_ROLE, Boolean.valueOf(requestor));
String mapProperty = getMAPProperty(requestor, outbound);
AddressingProperties maps = getMAPs(requestor, outbound, exposeAs);
final Element header = control.createMock(Element.class);
codec.setHeaderFactory(new MAPCodec.HeaderFactory() {
public Element getHeader(SoapVersion version) {
return header;
}
});
List<Header> headers = message.getHeaders();
JAXBContext jaxbContext = control.createMock(JAXBContext.class);
ContextUtils.setJAXBContext(jaxbContext);
Names200408.setJAXBContext(jaxbContext);
Names200403.setJAXBContext(jaxbContext);
if (outbound) {
setUpEncode(requestor, message, header, maps, mapProperty, invalidMAP, preExistingSOAPAction);
} else {
setUpDecode(message, headers, maps, mapProperty, requestor);
}
control.replay();
return message;
}
Aggregations