use of jakarta.xml.soap.SOAPMessage in project openmq by eclipse-ee4j.
the class SendServiceImpl method send.
// public String authenticate (String user, String password) throws JMSException {
// return cache.authenticate(user, password);
// }
// public void authenticateUUID (String clientId) throws JMSException {
// cache.authenticateUUID (clientId);
// }
@Override
public void send(SOAPMessage sm) throws JMSException {
Client client = null;
Message message = null;
try {
/**
* String clientId = MessageUtil.getServiceClientId(sm);
*
* if (clientId == null) { user = MessageUtil.getServiceAttribute(sm, Constants.USER); pass =
* MessageUtil.getServiceAttribute(sm, Constants.PASSWORD); }
*
* client = cache.getClient(clientId, user, pass);
*/
client = cache.getClient(sm);
// Object syncObj = lock.getLock(client.getId());
Object syncObj = client.getLock();
if (UMSServiceImpl.debug) {
logger.info("*** SendServiceImpl sending message: " + sm);
}
synchronized (syncObj) {
// client = cache.getClient(clientId);
Session session = client.getSession();
String destName = MessageUtil.getServiceDestinationName(sm);
boolean isTopic = MessageUtil.isServiceTopicDomain(sm);
Destination dest = cache.getJMSDestination(destName, isTopic);
// XXX remove message header element
MessageUtil.removeMessageHeaderElement(sm);
if (UMSServiceImpl.debug) {
logger.info("*** SendServiceImpl sending message: " + sm);
}
// sm.writeTo(System.out);
message = MessageTransformer.SOAPMessageIntoJMSMessage(sm, session);
MessageProducer producer = client.getProducer();
producer.send(dest, message);
}
if (UMSServiceImpl.debug) {
logger.info("*** SendServiceImpl sent message: " + message);
}
} catch (Exception ex) {
if (ex instanceof JMSException) {
throw (JMSException) ex;
} else {
JMSException jmse = new JMSException(ex.getMessage());
jmse.setLinkedException(ex);
throw jmse;
}
} finally {
cache.returnClient(client);
}
}
use of jakarta.xml.soap.SOAPMessage in project openmq by eclipse-ee4j.
the class MessageUtil method newMessageInstance.
public static SOAPMessage newMessageInstance() throws SOAPException {
SOAPMessage soapm = null;
/**
* sync create new instance to make sure to work in ALL SAAJ impl.
*/
synchronized (syncObj) {
soapm = messageFactory.createMessage();
}
SOAPHeader sh = soapm.getSOAPHeader();
SOAPHeaderElement she = addJMSNsSOAPHeaderElement(sh, Constants.MESSAGE_HEADER);
addMessageHeaderChildElements(she);
soapm.saveChanges();
return soapm;
}
use of jakarta.xml.soap.SOAPMessage in project openmq by eclipse-ee4j.
the class UMSService method onMessage.
/**
* MQ SOAP Service implements this interafce.
*
* <p>
* The request handler chain is processed in sequence before calling the service() method.
* <p>
* The respond handler chain is processed in sequence after calling the service() method.
*/
public SOAPMessage onMessage(SOAPMessage message) {
SOAPMessage reply = null;
logger.fine("MQSOAPService received message.");
try {
UMSMessageContext context = new UMSMessageContext();
context.setRequestMessage(message);
logger.fine("created msg context: " + context);
logger.fine("*** processing request chain ...");
processHandlerChain(this.reqChain, context);
/**
* To be over ridden by subclass.
*/
service(context);
// context.setResponseMessage(reply);
logger.fine("*** processing response chain ...");
processHandlerChain(this.respChain, context);
reply = context.getResponseMessage();
} catch (MessageHandlerException mhe) {
mhe.printStackTrace(System.out);
logger.log(Level.WARNING, mhe.getMessage(), mhe);
/**
* if there is a soap fault message in the exception, use it. Otherwise, construct one and set error code and string to
* *Client* and *Client Error*.
*/
reply = mhe.getSOAPFaultMessage();
if (reply == null) {
reply = createSOAPFaultMessage(mhe, "Client", "Client Error");
}
} catch (Throwable throwe) {
logger.log(Level.WARNING, throwe.getMessage(), throwe);
/**
* For the reset of the exception, assume it is the server unable to process the message. This implies that soap header
* processing SHOULD be handled in the Message Handler. Validation of the SOAP headers SHOULD throw
* MessageHandlerException if unable to process the message.
*/
reply = createSOAPFaultMessage(throwe, "Server", "Server Error");
}
return reply;
}
use of jakarta.xml.soap.SOAPMessage in project spring-integration by spring-projects.
the class DefaultSoapHeaderMapperTests method testDoNotOverriderSoapAction.
@Test
public void testDoNotOverriderSoapAction() throws Exception {
MimeHeaders mimeHeaders = new MimeHeaders();
String testSoapAction = "fooAction";
mimeHeaders.setHeader(TransportConstants.HEADER_SOAP_ACTION, testSoapAction);
String soap = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"></soapenv:Envelope>";
SOAPMessage message = MessageFactory.newInstance().createMessage(mimeHeaders, new ByteArrayInputStream(soap.getBytes()));
SaajSoapMessage soapMessage = new SaajSoapMessage(message);
DefaultSoapHeaderMapper headerMapper = new DefaultSoapHeaderMapper();
headerMapper.fromHeadersToRequest(new MessageHeaders(null), soapMessage);
assertThat(soapMessage.getSoapAction()).isEqualTo(testSoapAction);
}
use of jakarta.xml.soap.SOAPMessage in project spring-integration by spring-projects.
the class DefaultSoapHeaderMapperTests method testRealSoapHeader.
@Test
public void testRealSoapHeader() throws Exception {
String soap = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\">" + "<soapenv:Header>" + "<auth>" + "<username>user</username>" + "<password>pass</password>" + "</auth>" + "<bar>BAR</bar>" + "<baz>BAZ</baz>" + "<qux>qux</qux>" + "</soapenv:Header>" + "<soapenv:Body>" + "<foo>foo</foo>" + "</soapenv:Body>" + "</soapenv:Envelope>";
SOAPMessage message = MessageFactory.newInstance().createMessage(new MimeHeaders(), new ByteArrayInputStream(soap.getBytes("UTF-8")));
SoapMessage soapMessage = new SaajSoapMessage(message);
DefaultSoapHeaderMapper mapper = new DefaultSoapHeaderMapper();
String authHeader = "auth";
mapper.setRequestHeaderNames(authHeader, "ba*");
Map<String, Object> headers = mapper.toHeadersFromRequest(soapMessage);
assertThat(headers.get(authHeader)).isNotNull();
assertThat(headers.get(authHeader)).isInstanceOf(SoapHeaderElement.class);
SoapHeaderElement header = (SoapHeaderElement) headers.get(authHeader);
DOMSource source = (DOMSource) header.getSource();
NodeList nodeList = source.getNode().getChildNodes();
assertThat(nodeList.item(0).getNodeName()).isEqualTo("username");
assertThat(nodeList.item(0).getFirstChild().getNodeValue()).isEqualTo("user");
assertThat(nodeList.item(1).getNodeName()).isEqualTo("password");
assertThat(nodeList.item(1).getFirstChild().getNodeValue()).isEqualTo("pass");
header = (SoapHeaderElement) headers.get("bar");
assertThat(header).isNotNull();
source = (DOMSource) header.getSource();
nodeList = source.getNode().getChildNodes();
assertThat(nodeList.item(0).getNodeValue()).isEqualTo("BAR");
header = (SoapHeaderElement) headers.get("baz");
assertThat(header).isNotNull();
source = (DOMSource) header.getSource();
nodeList = source.getNode().getChildNodes();
assertThat(nodeList.item(0).getNodeValue()).isEqualTo("BAZ");
assertThat(headers.get("qux")).isNull();
}
Aggregations