use of javax.xml.soap.SOAPHeader in project OpenAM by OpenRock.
the class MessageProcessor method addCorrelationHeader.
/**
* Adds the correlation header.
* @param msg SOAP Message that needs to be added with Correlation header.
* @param req Message Request, if present adds the correlation header
* reference.
* @return SOAPHeader SOAP Header with Correlation header.
* @throws SOAPBindingException if there is an error.
*/
private SOAPHeader addCorrelationHeader(SOAPMessage msg, Message req) throws SOAPBindingException {
try {
SOAPHeader header = msg.getSOAPPart().getEnvelope().getHeader();
if (header == null) {
header = msg.getSOAPPart().getEnvelope().addHeader();
}
CorrelationHeader cHeader = new CorrelationHeader();
correlationId = cHeader.getId();
if (req != null) {
cHeader.setRefToMessageID(req.getCorrelationHeader().getMessageID());
}
cHeader.addToParent(header);
return header;
} catch (Exception ex) {
Utils.debug.error("MessageProcessor.addCorrealtionHeader: " + "Could not add correlation header", ex);
throw new SOAPBindingException(Utils.bundle.getString("cannotAddCorrelationHeader"));
}
}
use of javax.xml.soap.SOAPHeader in project tdi-studio-se by Talend.
the class SOAPUtil method invokeSOAP.
public void invokeSOAP(String version, String destination, String soapAction, String soapMessage) throws SOAPException, TransformerException, ParserConfigurationException, FileNotFoundException, UnsupportedEncodingException {
MessageFactory messageFactory = null;
if (version.equals(SOAP12)) {
messageFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
} else {
messageFactory = MessageFactory.newInstance();
}
SOAPMessage message = messageFactory.createMessage();
MimeHeaders mimeHeaders = message.getMimeHeaders();
mimeHeaders.setHeader("SOAPAction", soapAction);
if (basicAuth) {
addBasicAuthHeader(mimeHeaders, username, password);
}
// Create objects for the message parts
SOAPPart soapPart = message.getSOAPPart();
String encoding = getEncoding(soapMessage);
ByteArrayInputStream stream = new ByteArrayInputStream(soapMessage.getBytes(encoding));
StreamSource preppedMsgSrc = new StreamSource(stream);
soapPart.setContent(preppedMsgSrc);
// InputStream stream = new FileInputStream(new File("d://soap.txt"));
// StreamSource preppedMsgSrc = new StreamSource(stream);
// soapPart.setContent(preppedMsgSrc);
message.saveChanges();
// Send the message
SOAPMessage reply = connection.call(message, destination);
SOAPPart reSoapPart = reply.getSOAPPart();
if (reSoapPart != null && reSoapPart instanceof SOAPPartImpl) {
((SOAPPartImpl) reSoapPart).setSourceCharsetEncoding(encoding);
}
SOAPEnvelope reEnvelope = reSoapPart.getEnvelope();
SOAPHeader reHeader = reEnvelope.getHeader();
if (reHeader != null) {
setReHeaderMessage(Doc2StringWithoutDeclare(extractContentAsDocument(reHeader)));
}
SOAPBody reBody = reEnvelope.getBody();
if (reBody.getFault() != null) {
hasFault = true;
setReFaultMessage(Doc2StringWithoutDeclare(extractContentAsDocument(reBody)));
setReBodyMessage(null);
} else {
hasFault = false;
if (reBody.getChildNodes().getLength() < 1) {
setReBodyMessage(null);
} else if (reBody.getChildNodes().getLength() == 1 && reBody.getChildNodes().item(0) instanceof javax.xml.soap.Text) {
setReBodyMessage(null);
} else {
setReBodyMessage(Doc2StringWithoutDeclare(extractContentAsDocument(reBody)));
}
setReFaultMessage(null);
}
}
use of javax.xml.soap.SOAPHeader in project narayana by jbosstm.
the class InstanceIdentifierHandler 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 {
ArjunaContext arjunaContext = ArjunaContext.getCurrentContext(context);
if (arjunaContext != null) {
InstanceIdentifier instanceIdentifier = arjunaContext.getInstanceIdentifier();
// insert a header into the current message containing the instance identifier as a text element
final SOAPMessage soapMessage = context.getMessage();
final SOAPEnvelope soapEnvelope = soapMessage.getSOAPPart().getEnvelope();
SOAPHeader soapHeader = soapEnvelope.getHeader();
if (soapHeader == null) {
soapHeader = soapEnvelope.addHeader();
}
final SOAPHeaderElement headerElement = soapHeader.addHeaderElement(ArjunaConstants.WSARJ_ELEMENT_INSTANCE_IDENTIFIER_QNAME);
headerElement.setValue(instanceIdentifier.getInstanceIdentifier());
headerElement.setMustUnderstand(true);
}
} catch (Exception se) {
throw new ProtocolException(se);
}
return true;
}
use of javax.xml.soap.SOAPHeader in project narayana by jbosstm.
the class JaxBaseHeaderContextProcessor method handleOutboundMessage.
/**
* Handle the request.
*
* @param soapMessage The current message context.
* @param mustUnderstand Value of MustUnderstand attribute.
* @return whether the message was handled
*/
public boolean handleOutboundMessage(final SOAPMessage soapMessage, boolean mustUnderstand) {
if (soapMessage == null) {
return true;
}
try {
/*
* There should either be an Atomic Transaction *or* a Business Activity
* associated with the thread.
*/
final TransactionManager transactionManager = TransactionManagerFactory.transactionManager();
final com.arjuna.mw.wst11.BusinessActivityManager businessActivityManager = BusinessActivityManagerFactory.businessActivityManager();
final Context atContext;
if (transactionManager != null) {
final TxContextImple txContext = (TxContextImple) transactionManager.currentTransaction();
atContext = (txContext == null ? null : txContext.context());
} else {
atContext = null;
}
final Context baContext;
if (businessActivityManager != null) {
final com.arjuna.mwlabs.wst11.ba.context.TxContextImple txContext = (com.arjuna.mwlabs.wst11.ba.context.TxContextImple) businessActivityManager.currentTransaction();
baContext = (txContext == null ? null : txContext.context());
} else {
baContext = null;
}
final CoordinationContextType coordinationContext;
if (baContext != null) {
coordinationContext = baContext.getCoordinationContext();
} else if (atContext != null) {
coordinationContext = atContext.getCoordinationContext();
} else {
coordinationContext = null;
}
if (coordinationContext != null) {
final SOAPEnvelope env = soapMessage.getSOAPPart().getEnvelope();
SOAPHeader header = env.getHeader();
if (header == null) {
header = env.addHeader();
}
final Name name = env.createName(CoordinationConstants.WSCOOR_ELEMENT_COORDINATION_CONTEXT, CoordinationConstants.WSCOOR_PREFIX, CoordinationConstants.WSCOOR_NAMESPACE);
final SOAPHeaderElement headerElement = header.addHeaderElement(name);
headerElement.addNamespaceDeclaration(CoordinationConstants.WSCOOR_PREFIX, CoordinationConstants.WSCOOR_NAMESPACE);
headerElement.setMustUnderstand(mustUnderstand);
CoordinationContextHelper.serialise(coordinationContext, headerElement);
}
} catch (final Throwable th) {
wstxLogger.i18NLogger.warn_mw_wst11_client_JaxHC11P_1("com.arjuna.mw.wst11.client.JaxBaseHeaderContextProcessor.handleRequest()", th);
}
return true;
}
use of javax.xml.soap.SOAPHeader in project narayana by jbosstm.
the class AbstractJTAOverWSATHandler method getHeaderElement.
/**
* Extracts and returns SOAP header element from the SOAP message context based on <code>uri</code> and <code>name</code>.
*
* @param soapMessageContext
* @param uri
* @param name
* @return SOAP header element if such element existed and <code>null</code> if not.
*/
private SOAPHeaderElement getHeaderElement(final SOAPMessageContext soapMessageContext, final String uri, final String name) {
SOAPHeaderElement soapHeaderElement = null;
try {
final SOAPMessage soapMessage = soapMessageContext.getMessage();
final SOAPEnvelope soapEnvelope = soapMessage.getSOAPPart().getEnvelope();
final SOAPHeader soapHeader = soapEnvelope.getHeader();
if (soapHeader != null) {
soapHeaderElement = getHeaderElement(soapHeader, uri, name);
}
} catch (SOAPException e) {
}
return soapHeaderElement;
}
Aggregations