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;
}
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;
}
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;
}
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();
}
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;
}
Aggregations