use of javax.xml.soap.SOAPEnvelope 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.SOAPEnvelope 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.SOAPEnvelope 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.SOAPEnvelope 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.SOAPEnvelope in project scout.rt by eclipse.
the class WsseUsernameTokenAuthenticationHandler method handleMessage.
@Override
public final boolean handleMessage(final SOAPMessageContext messageContext) {
if (MessageContexts.isInboundMessage(messageContext)) {
return true;
}
SOAPEnvelope envelope;
SOAPHeader header;
try {
envelope = messageContext.getMessage().getSOAPPart().getEnvelope();
header = envelope.getHeader();
if (header == null) {
header = envelope.addHeader();
}
final SOAPElement security = header.addChildElement(WS_SEC, WSSE, NAME_SPACE_URI);
final SOAPElement userToken = security.addChildElement(USERNAME_TOKEN, WSSE);
userToken.addChildElement(USERNAME, WSSE).addTextNode(StringUtility.valueOf(messageContext.get(InvocationContext.PROP_USERNAME)));
userToken.addChildElement(PASSWORD, WSSE).addTextNode(StringUtility.valueOf(messageContext.get(InvocationContext.PROP_PASSWORD)));
return true;
} catch (final SOAPException e) {
throw new WebServiceException("Failed to set SOAP header for WsseUsernameTokenAuthentication", e);
}
}
Aggregations