use of com.sun.xml.ws.message.saaj.SAAJMessage in project metro-jax-ws by eclipse-ee4j.
the class SaajMessageTest method testBodyAttr.
/**
* Test for body attribute after SAAJMessage.copy()
*
* @throws Exception - error
*/
public void testBodyAttr() throws Exception {
MessageFactory factory = MessageFactory.newInstance();
SOAPMessage soapMessage = factory.createMessage();
Source src = new StreamSource(new ByteArrayInputStream(MESSAGE.getBytes()));
soapMessage.getSOAPPart().setContent(src);
SAAJMessage saajMsg = new SAAJMessage(soapMessage);
// breaks the underlying SOAPMessage
saajMsg.hasHeaders();
saajMsg = (SAAJMessage) saajMsg.copy();
SOAPBody soapBody = saajMsg.readAsSOAPMessage().getSOAPBody();
assertEquals("value", soapBody.getAttribute("attr"));
}
use of com.sun.xml.ws.message.saaj.SAAJMessage in project metro-jax-ws by eclipse-ee4j.
the class SAAJFactory method readAsSAAJ.
/**
* Reads the message within the Packet to a SAAJMessage. After this call message is consumed.
* @param packet Packet
* @return Created SAAJPMessage
* @throws SOAPException if SAAJ processing fails
*/
public SAAJMessage readAsSAAJ(Packet packet) throws SOAPException {
SOAPVersion v = packet.getMessage().getSOAPVersion();
SOAPMessage msg = readAsSOAPMessage(v, packet.getMessage());
return new SAAJMessage(msg);
}
use of com.sun.xml.ws.message.saaj.SAAJMessage in project metro-jax-ws by eclipse-ee4j.
the class HeaderListTest method testUnderstoodBehavior.
public void testUnderstoodBehavior() throws Exception {
// a fairly complex SOAPMessage with 2 mustUnderstand=true headers,
// one mustUnderstand=false and one with no mustUnderstand specified
String soapMsgStr = "<env:Envelope xmlns:env=\"http://schemas.xmlsoap.org/soap/envelope/\">" + "<env:Header>" + "<wsa:Action xmlns:wsa=\"http://www.w3.org/2005/08/addressing\" env:mustUnderstand=\"true\"></wsa:Action>" + "<wsa:MessageID xmlns:wsa=\"http://www.w3.org/2005/08/addressing\">uuid:40a19d86-071d-4d3f-8b1b-8c8b5245b1de</wsa:MessageID>" + "<wsa:RelatesTo xmlns:wsa=\"http://www.w3.org/2005/08/addressing\" env:mustUnderstand=\"false\">uuid:bd2cf21b-d2ad-4dc6-b0ec-2928736b5ae2</wsa:RelatesTo>" + "<wsa:To xmlns:wsa=\"http://www.w3.org/2005/08/addressing\" env:mustUnderstand=\"true\">http://www.w3.org/2005/08/addressing/anonymous</wsa:To>" + "</env:Header>" + "<env:Body xmlns:wsrm11=\"http://docs.oasis-open.org/ws-rx/wsrm/200702\">" + "<wsrm11:CreateSequenceResponse>" + "<wsrm11:Identifier>35599b13-3672-462a-a51a-31e1820ef236</wsrm11:Identifier>" + "<wsrm11:Expires>P1D</wsrm11:Expires>" + "<wsrm11:IncompleteSequenceBehavior>NoDiscard</wsrm11:IncompleteSequenceBehavior>" + "</wsrm11:CreateSequenceResponse>" + "</env:Body></env:Envelope>";
SAAJMessage msg = new SAAJMessage(makeSOAPMessage(soapMsgStr));
HeaderList hdrs = (HeaderList) msg.getHeaders();
String addrNs = "http://www.w3.org/2005/08/addressing";
String msgId = "MessageID";
String action = "Action";
String relatesTo = "RelatesTo";
String toHdrName = "To";
QName msgIdQName = new QName(addrNs, msgId);
QName actionQName = new QName(addrNs, action);
QName relatesToQName = new QName(addrNs, relatesTo);
QName toQName = new QName(addrNs, toHdrName);
// check understood headers
Set<QName> understood = hdrs.getUnderstoodHeaders();
assertTrue(understood == null || understood.size() == 0);
// check getNotUnderstoodHeaders
Set<QName> notUnderstood = hdrs.getNotUnderstoodHeaders(null, null, null);
assertNotNull(notUnderstood);
assertEquals(2, notUnderstood.size());
// notUnderstoodHeaders should not contain non-mustUnderstand headers
assertFalse(notUnderstood.contains(msgIdQName));
assertFalse(notUnderstood.contains(relatesToQName));
// notUnderstoodHeaders MUST contain mustUnderstand headers
assertTrue(notUnderstood.contains(actionQName));
assertTrue(notUnderstood.contains(toQName));
// messageid is _not_ a mustUnderstandHeader - isUnderstood should still be false
assertFalse(hdrs.isUnderstood(addrNs, msgId));
hdrs.understood(addrNs, msgId);
// after marking it must be listed as understood
assertTrue(hdrs.isUnderstood(addrNs, msgId));
// notUnderstood must continue to not contain it
notUnderstood = hdrs.getNotUnderstoodHeaders(null, null, null);
assertNotNull(notUnderstood);
assertEquals(2, notUnderstood.size());
assertFalse(notUnderstood.contains(msgIdQName));
// check understood headers - must contain message id
understood = hdrs.getUnderstoodHeaders();
assertNotNull(understood);
assertTrue(understood.size() == 1);
assertTrue(understood.contains(msgIdQName));
// check the mustUnderstand=true header Action
assertFalse(hdrs.isUnderstood(addrNs, action));
hdrs.understood(addrNs, action);
assertTrue(hdrs.isUnderstood(addrNs, action));
notUnderstood = hdrs.getNotUnderstoodHeaders(null, null, null);
// Action must no longer be in notUnderstood
assertNotNull(notUnderstood);
assertEquals(1, notUnderstood.size());
assertFalse(notUnderstood.contains(actionQName));
understood = hdrs.getUnderstoodHeaders();
assertNotNull(understood);
assertEquals(2, understood.size());
assertTrue(understood.contains(actionQName));
assertTrue(understood.contains(msgIdQName));
}
use of com.sun.xml.ws.message.saaj.SAAJMessage in project metro-jax-ws by eclipse-ee4j.
the class ReplaceAddressingHeaderTest method testReplaceBehavior.
public void testReplaceBehavior() throws Exception {
String reqMsgStr = "<env:Envelope xmlns:env=\"http://www.w3.org/2003/05/soap-envelope\">" + "<env:Header>" + "<r:AckRequested xmlns:s=\"http://www.w3.org/2003/05/soap-envelope\" xmlns:r=\"http://docs.oasis-open.org/ws-rx/wsrm/200702\" xmlns:a=\"http://www.w3.org/2005/08/addressing\">" + "<r:Identifier>uuid:WLS2:store:WseeJaxwsFileStore:dece97a1d44772e7:-3fbed9f:13b4b7da0a6:-7fb6</r:Identifier>" + "</r:AckRequested>" + "<a:Action xmlns:s=\"http://www.w3.org/2003/05/soap-envelope\" xmlns:r=\"http://docs.oasis-open.org/ws-rx/wsrm/200702\" " + "xmlns:a=\"http://www.w3.org/2005/08/addressing\" s:mustUnderstand=\"1\">http://docs.oasis-open.org/ws-rx/wsrm/200702/AckRequested</a:Action>" + "<a:To xmlns:s=\"http://www.w3.org/2003/05/soap-envelop\" " + "xmlns:r=\"http://docs.oasis-open.org/ws-rx/wsrm/200702\" xmlns:a=\"http://www.w3.org/2005/08/addressing\" " + "s:mustUnderstand=\"1\">http://10.245.29.191:9902/ReliableMessaging_Service_WSAddressing10_Indigo/OneWay.svc/Reliable_Addressable_Soap12_WSAddressing10_RM11</a:To>" + "</env:Header>" + "<env:Body/>" + "</env:Envelope>";
String respMsgStr = "<env:Envelope xmlns:env=\"http://www.w3.org/2003/05/soap-envelope\">" + "<env:Header>" + "<Action xmlns=\"http://www.w3.org/2005/08/addressing\">http://docs.oasis-open.org/ws-rx/wsrm/200702/SequenceAcknowledgement</Action>" + "<wsrm11:SequenceAcknowledgement xmlns:wsrm11=\"http://docs.oasis-open.org/ws-rx/wsrm/200702\">" + "<wsrm11:Identifier>uuid:WLS2:store:WseeJaxwsFileStore:dece97a1d44772e7:-3fbed9f:13b4b7da0a6:-7fb6</wsrm11:Identifier>" + "<wsrm11:AcknowledgementRange Lower=\"1\" Upper=\"3\"/>" + "</wsrm11:SequenceAcknowledgement>" + "<To xmlns=\"http://www.w3.org/2005/08/addressing\">" + "http://10.244.13.245:8000/bcabf5e4-d888-403c-a93e-99ed5e7f4a40/fe5c31e3-a8af-40ed-8066-e41c3ba9f742</To>" + "<ns0:ReplyTo xmlns:ns0=\"http://www.w3.org/2005/08/addressing\">" + "<ns0:Address>" + "http://10.245.29.191:9902/ReliableMessaging_Service_WSAddressing10_Indigo/OneWay.svc/Reliable_Addressable_Soap12_WSAddressing10_RM11" + "</ns0:Address>" + "<ns0:Metadata xmlns:ns1=\"http://www.w3.org/ns/wsdl-instance\" " + "ns1:wsdlLocation=\"http://tempuri.org/http://10.245.29.191:9902/ReliableMessaging_Service_WSAddressing10_Indigo/OneWay.svc/Reliable_Addressable_Soap12_WSAddressing10_RM11?wsdl\">" + "<wsam:InterfaceName xmlns:wsam=\"http://www.w3.org/2007/05/addressing/metadata\" xmlns:wsns=\"http://tempuri.org/\">" + "wsns:IPing</wsam:InterfaceName>" + "<wsam:ServiceName xmlns:wsam=\"http://www.w3.org/2007/05/addressing/metadata\" xmlns:wsns=\"http://tempuri.org/\" EndpointName=\"CustomBinding_IPing10\">" + "wsns:PingService</wsam:ServiceName>" + "</ns0:Metadata>" + "</ns0:ReplyTo>" + "</env:Header>" + "<env:Body/></env:Envelope>";
AddressingVersion av = AddressingVersion.W3C;
SOAPVersion sv = SOAPVersion.SOAP_12;
String action = "http://docs.oasis-open.org/ws-rx/wsrm/200702/SequenceAcknowledgement";
SAAJMessage reqMsg = new SAAJMessage(makeSOAPMessage(reqMsgStr));
SAAJMessage respMsg = new SAAJMessage(makeSOAPMessage(respMsgStr));
HeaderList hdrs = (HeaderList) respMsg.getHeaders();
String originToHeader = hdrs.getTo(av, sv);
Packet responsePacket = null;
try {
responsePacket = new Packet(reqMsg).createServerResponse(respMsg, av, sv, action);
} catch (Exception e) {
e.printStackTrace();
}
// check toHeader
String toHeaderAfterProcessed = AddressingUtils.getTo(responsePacket.getHeaderList(), av, sv);
assertTrue(toHeaderAfterProcessed.equals(originToHeader));
}
use of com.sun.xml.ws.message.saaj.SAAJMessage in project metro-jax-ws by eclipse-ee4j.
the class SOAPFaultBuilder1Test method testFault2.
public void testFault2() throws Throwable {
SOAPMessage msg = SOAPVersion.SOAP_12.getMessageFactory().createMessage(null, new ByteArrayInputStream(fault2.trim().getBytes()));
SOAPFaultBuilder sfb = SOAPFaultBuilder.create(new SAAJMessage(msg));
Throwable t = sfb.createException(null);
assertTrue(t instanceof SOAPFaultException);
SOAPFaultException sfe = (SOAPFaultException) t;
Detail detail = sfe.getFault().getDetail();
assertTrue(detail != null);
Iterator iter = detail.getDetailEntries();
// there should be two detail entries
assertTrue(iter.hasNext());
DetailEntry de = (DetailEntry) iter.next();
assertTrue(de.getElementQName().equals(new QName("http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd", "FaultDetail")));
Node n = de.getFirstChild();
assertTrue(n.getNodeValue().equals("http://schemas.dmtf.org/wbem/wsman/1/wsman/faultDetail/InvalidValues"));
assertTrue(iter.hasNext());
de = (DetailEntry) iter.next();
assertTrue(de.getElementQName().equals(new QName("http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd", "FaultDetail2")));
n = de.getFirstChild();
assertTrue(n.getNodeValue().equals("http://schemas.dmtf.org/wbem/wsman/1/wsman/faultDetail/InvalidValues1"));
}
Aggregations