Search in sources :

Example 1 with SOAPMessage

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);
    }
}
Also used : Destination(jakarta.jms.Destination) Message(jakarta.jms.Message) SimpleMessage(com.sun.messaging.ums.simple.SimpleMessage) SOAPMessage(jakarta.xml.soap.SOAPMessage) JMSException(jakarta.jms.JMSException) MessageProducer(jakarta.jms.MessageProducer) JMSException(jakarta.jms.JMSException) SOAPException(jakarta.xml.soap.SOAPException) Session(jakarta.jms.Session)

Example 2 with SOAPMessage

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;
}
Also used : SOAPHeaderElement(jakarta.xml.soap.SOAPHeaderElement) SOAPMessage(jakarta.xml.soap.SOAPMessage) SOAPHeader(jakarta.xml.soap.SOAPHeader)

Example 3 with SOAPMessage

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;
}
Also used : SOAPMessage(jakarta.xml.soap.SOAPMessage)

Example 4 with SOAPMessage

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);
}
Also used : MimeHeaders(jakarta.xml.soap.MimeHeaders) SaajSoapMessage(org.springframework.ws.soap.saaj.SaajSoapMessage) ByteArrayInputStream(java.io.ByteArrayInputStream) MessageHeaders(org.springframework.messaging.MessageHeaders) SOAPMessage(jakarta.xml.soap.SOAPMessage) Test(org.junit.Test)

Example 5 with SOAPMessage

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();
}
Also used : MimeHeaders(jakarta.xml.soap.MimeHeaders) SaajSoapMessage(org.springframework.ws.soap.saaj.SaajSoapMessage) DOMSource(javax.xml.transform.dom.DOMSource) SoapHeaderElement(org.springframework.ws.soap.SoapHeaderElement) ByteArrayInputStream(java.io.ByteArrayInputStream) NodeList(org.w3c.dom.NodeList) SOAPMessage(jakarta.xml.soap.SOAPMessage) SoapMessage(org.springframework.ws.soap.SoapMessage) SaajSoapMessage(org.springframework.ws.soap.saaj.SaajSoapMessage) Test(org.junit.Test)

Aggregations

SOAPMessage (jakarta.xml.soap.SOAPMessage)181 MessageFactory (jakarta.xml.soap.MessageFactory)66 ByteArrayInputStream (java.io.ByteArrayInputStream)51 SOAPBody (jakarta.xml.soap.SOAPBody)37 SOAPException (jakarta.xml.soap.SOAPException)36 QName (javax.xml.namespace.QName)31 MimeHeaders (jakarta.xml.soap.MimeHeaders)27 Source (javax.xml.transform.Source)25 StreamSource (javax.xml.transform.stream.StreamSource)25 WebServiceException (jakarta.xml.ws.WebServiceException)24 ByteArrayOutputStream (java.io.ByteArrayOutputStream)21 SAAJMessage (com.sun.xml.ws.message.saaj.SAAJMessage)19 Element (org.w3c.dom.Element)18 Node (org.w3c.dom.Node)18 Packet (com.sun.xml.ws.api.message.Packet)17 Message (com.sun.xml.ws.api.message.Message)16 Iterator (java.util.Iterator)14 SOAPElement (jakarta.xml.soap.SOAPElement)12 AttachmentPart (jakarta.xml.soap.AttachmentPart)11 Dispatch (jakarta.xml.ws.Dispatch)10