use of com.sun.xml.ws.message.StringHeader in project metro-jax-ws by eclipse-ee4j.
the class SAAJMessageHeadersTest method testMustUnderstand.
public void testMustUnderstand() throws Exception {
SOAPMessage sm = makeSOAPMessage(MESSAGE);
// SAAJMessage saajMsg = new SAAJMessage(sm);
MessageHeaders hdrs = new SAAJMessageHeaders(sm, SOAPVersion.SOAP_11);
// new must understand header
Header newHdr = new StringHeader(new QName("myNs", "stringHeader1"), "stringHeaderValue1", SOAPVersion.SOAP_11, true);
hdrs.add(newHdr);
Set<QName> notUnderstoods = hdrs.getNotUnderstoodHeaders(null, null, null);
assertNotNull(notUnderstoods);
assertEquals(1, notUnderstoods.size());
// verify the understood headers list
Set<QName> understoods = hdrs.getUnderstoodHeaders();
// none of the headers is marked understood
assertNull(understoods);
// assertEquals(1, understoods.size());
// the new header should not be understood yet
assertFalse(hdrs.isUnderstood(newHdr));
// now "understand" the header
hdrs.understood(newHdr);
// the new header should be understood now
assertTrue(hdrs.isUnderstood(newHdr));
notUnderstoods = hdrs.getNotUnderstoodHeaders(null, null, null);
assertNotNull(notUnderstoods);
assertEquals(0, notUnderstoods.size());
// make sure the newly understood header now shows up in the understoodHeaders
understoods = hdrs.getUnderstoodHeaders();
assertNotNull(understoods);
assertEquals(1, understoods.size());
}
use of com.sun.xml.ws.message.StringHeader in project metro-jax-ws by eclipse-ee4j.
the class SAAJMessageTest method test1.
public void test1() throws Exception {
MessageFactory factory = MessageFactory.newInstance();
SOAPMessage message = factory.createMessage();
Source src = new StreamSource(new ByteArrayInputStream(MESSAGE.getBytes()));
message.getSOAPPart().setContent(src);
SAAJMessage saajMsg = new SAAJMessage(message);
assertEquals("addNumbers", saajMsg.getPayloadLocalPart());
assertEquals("http://example.com/addNumbers", AddressingUtils.getAction(saajMsg.getHeaders(), AddressingVersion.W3C, SOAPVersion.SOAP_11));
Header header = new StringHeader(new QName("urn:foo", "header1"), "test header ");
saajMsg.getHeaders().add(header);
SOAPMessage newMsg = saajMsg.readAsSOAPMessage();
newMsg.writeTo(System.out);
SAAJMessage saajMsg2 = new SAAJMessage(newMsg);
assertEquals(2, saajMsg2.getHeaders().asList().size());
Message saajMsg3 = saajMsg2.copy();
assertEquals("addNumbers", saajMsg3.getPayloadLocalPart());
assertEquals("http://example.com/addNumbers", AddressingUtils.getAction(saajMsg3.getHeaders(), AddressingVersion.W3C, SOAPVersion.SOAP_11));
assertEquals(2, saajMsg2.getHeaders().asList().size());
XMLStreamWriter writer = XMLStreamWriterFactory.create(System.out);
saajMsg3.writeTo(writer);
writer.close();
}
use of com.sun.xml.ws.message.StringHeader in project metro-jax-ws by eclipse-ee4j.
the class Message method getID.
/**
* Retuns a unique id for the message.
* <p><p>
* @see #getID(com.sun.xml.ws.api.WSBinding) for detailed description.
* @param av WS-Addressing version
* @param sv SOAP version
* @return unique id for the message
* @deprecated
*/
@Deprecated
@NotNull
public String getID(AddressingVersion av, SOAPVersion sv) {
String uuid = null;
if (av != null) {
uuid = AddressingUtils.getMessageID(getHeaders(), av, sv);
}
if (uuid == null) {
uuid = generateMessageID();
getHeaders().add(new StringHeader(av.messageIDTag, uuid));
}
return uuid;
}
use of com.sun.xml.ws.message.StringHeader in project metro-jax-ws by eclipse-ee4j.
the class AddressingUtils method fillCommonAddressingHeaders.
/**
* Creates wsa:To, wsa:Action and wsa:MessageID header on the client
*
* @param packet request packet
* @param av WS-Addressing version
* @param sv SOAP version
* @param action Action Message Addressing Property value
* @throws IllegalArgumentException if any of the parameters is null.
*/
private static void fillCommonAddressingHeaders(MessageHeaders headers, Packet packet, @NotNull AddressingVersion av, @NotNull SOAPVersion sv, @NotNull String action, boolean mustUnderstand) {
if (packet == null) {
throw new IllegalArgumentException(AddressingMessages.NULL_PACKET());
}
if (av == null) {
throw new IllegalArgumentException(AddressingMessages.NULL_ADDRESSING_VERSION());
}
if (sv == null) {
throw new IllegalArgumentException(AddressingMessages.NULL_SOAP_VERSION());
}
if (action == null && !sv.httpBindingId.equals(SOAPBinding.SOAP12HTTP_BINDING)) {
throw new IllegalArgumentException(AddressingMessages.NULL_ACTION());
}
// wsa:To
if (headers.get(av.toTag, false) == null) {
StringHeader h = new StringHeader(av.toTag, packet.endpointAddress.toString());
headers.add(h);
}
// wsa:Action
if (action != null) {
packet.soapAction = action;
if (headers.get(av.actionTag, false) == null) {
// As per WS-I BP 1.2/2.0, if one of the WSA headers is MU, then all WSA headers should be treated as MU.,
// so just set MU on action header
StringHeader h = new StringHeader(av.actionTag, action, sv, mustUnderstand);
headers.add(h);
}
}
}
use of com.sun.xml.ws.message.StringHeader in project metro-jax-ws by eclipse-ee4j.
the class AddressingUtils method fillRequestAddressingHeaders.
public static void fillRequestAddressingHeaders(MessageHeaders headers, Packet packet, AddressingVersion av, SOAPVersion sv, boolean oneway, String action, boolean mustUnderstand) {
fillCommonAddressingHeaders(headers, packet, av, sv, action, mustUnderstand);
// null or "true" is equivalent to request/response MEP
if (!oneway) {
WSEndpointReference epr = av.anonymousEpr;
if (headers.get(av.replyToTag, false) == null) {
headers.add(epr.createHeader(av.replyToTag));
}
// wsa:FaultTo
if (headers.get(av.faultToTag, false) == null) {
headers.add(epr.createHeader(av.faultToTag));
}
// wsa:MessageID
if (packet.getMessage().getHeaders().get(av.messageIDTag, false) == null) {
if (headers.get(av.messageIDTag, false) == null) {
Header h = new StringHeader(av.messageIDTag, Message.generateMessageID());
headers.add(h);
}
}
}
}
Aggregations