Search in sources :

Example 11 with SOAPElement

use of jakarta.xml.soap.SOAPElement in project openmq by eclipse-ee4j.

the class UMSService method createSOAPFaultMessage.

/**
 * Create a soap fault message and set its error code and error string as specified in the parameter.
 */
public static SOAPMessage createSOAPFaultMessage(Throwable t, String faultCode, String faultString) {
    SOAPMessage soapFault = null;
    try {
        MessageFactory mf = MessageFactory.newInstance();
        soapFault = mf.createMessage();
        SOAPEnvelope env = soapFault.getSOAPPart().getEnvelope();
        SOAPBody body = env.getBody();
        SOAPFault faultElement = body.addFault();
        String soapNs = env.getElementName().getPrefix();
        String fcode = soapNs + ":" + faultCode;
        faultElement.setFaultCode(fcode);
        faultElement.setFaultString(faultString);
        Detail detail = faultElement.getDetail();
        if (detail == null) {
            detail = faultElement.addDetail();
        }
        Name stname = MessageUtil.createJMSName("StackTrace");
        SOAPElement entryEle = detail.addDetailEntry(stname);
        // get stack trace
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        PrintStream ps = new PrintStream(baos);
        t.printStackTrace(ps);
        ps.close();
        String trace = baos.toString("utf8");
        entryEle.setValue(trace);
        soapFault.saveChanges();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return soapFault;
}
Also used : PrintStream(java.io.PrintStream) SOAPBody(jakarta.xml.soap.SOAPBody) MessageFactory(jakarta.xml.soap.MessageFactory) SOAPElement(jakarta.xml.soap.SOAPElement) SOAPFault(jakarta.xml.soap.SOAPFault) SOAPEnvelope(jakarta.xml.soap.SOAPEnvelope) ByteArrayOutputStream(java.io.ByteArrayOutputStream) SOAPMessage(jakarta.xml.soap.SOAPMessage) Detail(jakarta.xml.soap.Detail) SOAPException(jakarta.xml.soap.SOAPException) Name(jakarta.xml.soap.Name)

Example 12 with SOAPElement

use of jakarta.xml.soap.SOAPElement in project openmq by eclipse-ee4j.

the class MessageUtil method createAcknowledgeMessage.

/**
 * Create ack message from the specified soap message.
 *
 * @param soapm the message to be acknowledged.
 * @return the created acknowledge message.
 */
public static SOAPMessage createAcknowledgeMessage(SOAPMessage soapm) throws SOAPException {
    // create message
    SOAPMessage ackm = newMessageInstance();
    // add acknowledge element
    SOAPHeaderElement ackele = addJMSNsSOAPHeaderElement(ackm.getSOAPHeader(), InternalConstants.ACKNOWLEDGMENT);
    // message to be acked
    SOAPHeaderElement messageHeader = getMessageHeaderElement(soapm);
    String mid = getJMSChildElementValue(messageHeader, Constants.MESSAGE_ID);
    SOAPHeaderElement ackMsgHdr = getMessageHeaderElement(ackm);
    SOAPElement se = getJMSChildElement(ackMsgHdr, Constants.REF_TO_MESSAGE_ID);
    se.setValue(mid);
    // add RefToMessageID element
    SOAPElement refEle = addJMSChildElement(ackele, Constants.REF_TO_MESSAGE_ID);
    refEle.setValue(mid);
    ackm.saveChanges();
    return ackm;
}
Also used : SOAPHeaderElement(jakarta.xml.soap.SOAPHeaderElement) SOAPElement(jakarta.xml.soap.SOAPElement) SOAPMessage(jakarta.xml.soap.SOAPMessage)

Example 13 with SOAPElement

use of jakarta.xml.soap.SOAPElement in project openmq by eclipse-ee4j.

the class MessageUtil method setJMSProperty.

public static SOAPElement setJMSProperty(SOAPHeaderElement jmsPropertyRoot, String pname, Object pvalue) throws SOAPException {
    // prop element to be added to JMSProperty element
    String eleName = null;
    if (pvalue instanceof String) {
        eleName = InternalConstants.STRING_PROPERTY;
    // System.out.println ("Message util setting String prop ... " +
    // pvalue );
    } else if (pvalue instanceof Integer) {
        eleName = InternalConstants.INT_PROPERTY;
    // System.out.println ("Message util setting Int prop ... " + pvalue
    // );
    } else if (pvalue instanceof Long) {
        eleName = InternalConstants.LONG_PROPERTY;
    // System.out.println ("Message util setting Long prop ... " +
    // pvalue );
    } else if (pvalue instanceof Boolean) {
        eleName = InternalConstants.BOOLEAN_PROPERTY;
    // System.out.println ("Message util setting Boolean prop... " +
    // pvalue );
    } else if (pvalue instanceof Short) {
        eleName = InternalConstants.SHORT_PROPERTY;
    // System.out.println ("Message util setting SHORT prop... " +
    // pvalue );
    } else if (pvalue instanceof Byte) {
        eleName = InternalConstants.BYTE_PROPERTY;
    // System.out.println ("Message util setting Byte prop ... " +
    // pvalue );
    } else {
        throw new SOAPException("Invalid property value." + pvalue);
    }
    // SOAPElement propEle = jmsPropertyRoot.addChildElement(eleName);
    SOAPElement propEle = MessageUtil.addJMSChildElement(jmsPropertyRoot, eleName);
    // pname attr
    Name propNameAttr = createJMSName(InternalConstants.PNAME);
    // pvalue attr
    Name propValueAttr = createJMSName(InternalConstants.PVALUE);
    // add pname attr
    propEle.addAttribute(propNameAttr, pname);
    // add pvalue attr.
    propEle.addAttribute(propValueAttr, pvalue.toString());
    return propEle;
}
Also used : SOAPException(jakarta.xml.soap.SOAPException) SOAPElement(jakarta.xml.soap.SOAPElement) Name(jakarta.xml.soap.Name)

Example 14 with SOAPElement

use of jakarta.xml.soap.SOAPElement in project openmq by eclipse-ee4j.

the class MessageUtil method setServiceAttribute.

public static void setServiceAttribute(SOAPMessage soapm, String localName, String value) throws SOAPException {
    SOAPHeaderElement mh = getMessageHeaderElement(soapm);
    SOAPElement serviceElement = getJMSChildElement(mh, Constants.SERVICE);
    Name n = createJMSName(localName);
    serviceElement.addAttribute(n, value);
    soapm.saveChanges();
}
Also used : SOAPHeaderElement(jakarta.xml.soap.SOAPHeaderElement) SOAPElement(jakarta.xml.soap.SOAPElement) Name(jakarta.xml.soap.Name)

Example 15 with SOAPElement

use of jakarta.xml.soap.SOAPElement in project openmq by eclipse-ee4j.

the class MessageUtil method setObjectProperty.

public static SOAPElement setObjectProperty(SOAPMessage soapm, String pname, Object pvalue) throws SOAPException {
    SOAPHeader sheader = soapm.getSOAPHeader();
    SOAPHeaderElement jmsPropertyRoot = getJMSPropertyElement(sheader);
    if (jmsPropertyRoot == null) {
        jmsPropertyRoot = addJMSPropertyElement(sheader);
    }
    SOAPElement propEle = setJMSProperty(jmsPropertyRoot, pname, pvalue);
    return propEle;
}
Also used : SOAPHeaderElement(jakarta.xml.soap.SOAPHeaderElement) SOAPElement(jakarta.xml.soap.SOAPElement) SOAPHeader(jakarta.xml.soap.SOAPHeader)

Aggregations

SOAPElement (jakarta.xml.soap.SOAPElement)24 SOAPMessage (jakarta.xml.soap.SOAPMessage)12 SOAPException (jakarta.xml.soap.SOAPException)10 SOAPBody (jakarta.xml.soap.SOAPBody)9 Name (jakarta.xml.soap.Name)7 SOAPHeaderElement (jakarta.xml.soap.SOAPHeaderElement)6 MessageFactory (jakarta.xml.soap.MessageFactory)5 QName (javax.xml.namespace.QName)5 Detail (jakarta.xml.soap.Detail)3 SOAPEnvelope (jakarta.xml.soap.SOAPEnvelope)3 SOAPFault (jakarta.xml.soap.SOAPFault)3 Iterator (java.util.Iterator)3 SAAJFactory (com.sun.xml.ws.api.message.saaj.SAAJFactory)2 StreamMessage (com.sun.xml.ws.message.stream.StreamMessage)2 SOAPFactory (jakarta.xml.soap.SOAPFactory)2 SOAPPart (jakarta.xml.soap.SOAPPart)2 ProtocolException (jakarta.xml.ws.ProtocolException)2 WebServiceException (jakarta.xml.ws.WebServiceException)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 StringReader (java.io.StringReader)2