use of javax.xml.soap.SOAPHeaderElement in project narayana by jbosstm.
the class InstanceIdentifierHandler method handlemessageInbound.
/**
* check for an arjuna instance identifier element embedded in the soap message headesr and, if found, use it to
* label an arjuna context attached to the message context
* @param context
* @return
* @throws ProtocolException
*/
private boolean handlemessageInbound(SOAPMessageContext context) throws ProtocolException {
try {
final SOAPMessage soapMessage = context.getMessage();
final SOAPEnvelope soapEnvelope = soapMessage.getSOAPPart().getEnvelope();
Iterator<SOAPHeaderElement> iterator = soapEnvelope.getHeader().examineAllHeaderElements();
while (iterator.hasNext()) {
final SOAPHeaderElement headerElement = iterator.next();
if (ArjunaConstants.WSARJ_ELEMENT_INSTANCE_IDENTIFIER_QNAME.equals(headerElement.getElementQName())) {
// found it - clear the must understand flag, retrieve the value and store an arjuna
// context in the message context
headerElement.setMustUnderstand(false);
String identifierString = headerElement.getValue();
if (identifierString != null) {
ArjunaContext arjunaContext = ArjunaContext.getContext(context);
arjunaContext.setInstanceIdentifier(new InstanceIdentifier(identifierString));
break;
}
}
}
} catch (Exception se) {
throw new ProtocolException(se);
}
return true;
}
use of javax.xml.soap.SOAPHeaderElement in project narayana by jbosstm.
the class JaxBaseHeaderContextProcessor method getHeaderElement.
/**
* Retrieve the first header matching the uri and name.
* @param soapEnvelope The soap envelope containing the header.
* @param uri The uri of the header element.
* @param name The name of the header element.
* @return The header element or null if not found.
*/
private SOAPHeaderElement getHeaderElement(final SOAPEnvelope soapEnvelope, final String uri, final String name) throws SOAPException {
final SOAPHeader soapHeader = soapEnvelope.getHeader();
if (soapHeader != null) {
final Iterator headerIter = SOAPUtil.getChildElements(soapHeader);
while (headerIter.hasNext()) {
final SOAPHeaderElement current = (SOAPHeaderElement) headerIter.next();
final Name currentName = current.getElementName();
if ((currentName != null) && match(name, currentName.getLocalName()) && match(uri, currentName.getURI())) {
return current;
}
}
}
return null;
}
use of javax.xml.soap.SOAPHeaderElement in project narayana by jbosstm.
the class CoordinationContextHandler method handleMessageOutbound.
/**
* check for an arjuna context attached to the message context and, if found, install its identifier as the value
* of a soap message header element
* @param context
* @return
* @throws ProtocolException
*/
protected boolean handleMessageOutbound(SOAPMessageContext context) throws ProtocolException {
try {
CoordinationContextType coordinationContext = CoordinationContextManager.getThreadContext();
if (coordinationContext != null) {
final JAXBContext jaxbCtx = getJaxbContext();
// insert a header into the current message containing the coordination context
final SOAPMessage soapMessage = context.getMessage();
final SOAPEnvelope soapEnvelope = soapMessage.getSOAPPart().getEnvelope();
SOAPHeader soapHeader = soapEnvelope.getHeader();
if (soapHeader == null) {
soapHeader = soapEnvelope.addHeader();
}
/*
* this does not work but it is what we want!!
*
* The problem here is that the marshaller creates plain old elements and inserts them top
* down as it goes along. but the soap header add child method checks its argument and
* replaces plain elements with soap header elements before inserting them. it copies the
* inserted element substructure into the rpelacement but since it does not exist at
* copy time the chiuldren get lost
Marshaller marshaller = jaxbCtx.createMarshaller();
marshaller.marshal(coordinationContext, soapHeader);
*/
/*
* ok, here's the workaround -- marshall the object as a child of a dummy header, detach it and
* then insert it as a header element.
*/
SOAPHeaderElement headerElement = soapHeader.addHeaderElement(getDummyQName());
Marshaller marshaller = jaxbCtx.createMarshaller();
marshaller.marshal(coordinationContext, headerElement);
soapHeader.replaceChild(headerElement.getChildNodes().item(0), headerElement);
// ok, now we need to locate the inserted node and set the mustunderstand attribute
Iterator<SOAPHeaderElement> iterator = soapHeader.examineAllHeaderElements();
while (iterator.hasNext()) {
headerElement = iterator.next();
if (CoordinationConstants.WSCOOR_ELEMENT_COORDINATION_CONTEXT_QNAME.equals(headerElement.getElementQName())) {
headerElement.setMustUnderstand(true);
break;
}
}
}
} catch (Exception se) {
throw new ProtocolException(se);
}
return true;
}
use of javax.xml.soap.SOAPHeaderElement in project narayana by jbosstm.
the class CoordinationContextHandler method handlemessageInbound.
/**
* check for an arjuna instance identifier element embedded in the soap message headesr and, if found, use it to
* label an arjuna context attached to the message context
* @param context
* @return
* @throws ProtocolException
*/
private boolean handlemessageInbound(SOAPMessageContext context) throws ProtocolException {
try {
final SOAPMessage soapMessage = context.getMessage();
final SOAPEnvelope soapEnvelope = soapMessage.getSOAPPart().getEnvelope();
Iterator<SOAPHeaderElement> iterator = soapEnvelope.getHeader().examineAllHeaderElements();
while (iterator.hasNext()) {
final SOAPHeaderElement headerElement = iterator.next();
if (CoordinationConstants.WSCOOR_ELEMENT_COORDINATION_CONTEXT_QNAME.equals(headerElement.getElementQName())) {
// found it - clear the must understand flag, retrieve the value and store an arjuna
// context in the message context
headerElement.setMustUnderstand(false);
final JAXBContext jaxbCtx = getJaxbContext();
final JAXBElement<CoordinationContextType> elt = jaxbCtx.createUnmarshaller().unmarshal(headerElement, CoordinationContextType.class);
final CoordinationContextType coordinationContext = elt.getValue();
CoordinationContextManager.setContext(context, coordinationContext);
}
}
} catch (Exception se) {
throw new ProtocolException(se);
}
return true;
}
use of javax.xml.soap.SOAPHeaderElement in project jbossws-cxf by jbossws.
the class RoutingHandler method handleOutbound.
@Override
protected boolean handleOutbound(SOAPMessageContext msgContext) {
log.info("handleOutbound");
try {
SOAPMessage soapMessage = msgContext.getMessage();
SOAPHeader soapHeader = soapMessage.getSOAPHeader();
SOAPBody soapBody = soapMessage.getSOAPBody();
SOAPFactory soapFactory = SOAPFactory.newInstance();
Name headerName = soapFactory.createName("RoutingHandlerOutbound", "ns1", "http://somens");
SOAPHeaderElement she = soapHeader.addHeaderElement(headerName);
she.setValue("true");
SOAPBodyElement soapBodyElement = (SOAPBodyElement) soapBody.getChildElements().next();
SOAPElement soapElement = (SOAPElement) soapBodyElement.getChildElements().next();
String value = soapElement.getValue();
soapElement.setValue(value + "|RoutOut");
} catch (SOAPException e) {
throw new WebServiceException(e);
}
return true;
}
Aggregations