use of jakarta.xml.soap.SOAPMessage 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 jakarta.xml.soap.SOAPMessage in project metro-jax-ws by eclipse-ee4j.
the class SAAJMessageTest method testWhiteSpaceCharacters.
public void testWhiteSpaceCharacters() throws Exception {
MessageFactory messageFactory = MessageFactory.newInstance();
SOAPMessage message = messageFactory.createMessage();
SOAPBody body = message.getSOAPBody();
QName name = new QName("testString1");
SOAPBodyElement bodyElement = body.addBodyElement(name);
bodyElement.addTextNode("Hello World, ---\003\007\024---");
name = new QName("testString2");
bodyElement = body.addBodyElement(name);
bodyElement.addTextNode("Hello \t\n\r World");
SAAJMessage saajMsg = new SAAJMessage(message);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
XMLStreamWriter writer = XMLStreamWriterFactory.create(baos);
saajMsg.writeTo(writer);
writer.close();
Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new InputSource(new StringReader(baos.toString())));
NodeList nodeList = doc.getElementsByTagName("testString1");
assertEquals(nodeList.item(0).getFirstChild().getNodeValue(), "Hello World, ------");
nodeList = doc.getElementsByTagName("testString2");
assertEquals(nodeList.item(0).getFirstChild().getNodeValue(), "Hello \t\n\r World");
}
use of jakarta.xml.soap.SOAPMessage 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 jakarta.xml.soap.SOAPMessage in project metro-jax-ws by eclipse-ee4j.
the class SAAJMessageTest method testMtomAttachmentCid.
public void testMtomAttachmentCid() throws Exception {
String testMtomMessageReload_01 = "multipart/related;type=\"application/xop+xml\";boundary=\"----=_Part_0_1145105632.1353005695468\";start=\"<cbe648b3-2055-413e-b8ed-877cdf0f2477>\";start-info=\"text/xml\"";
MessageContext m1 = mcf.createContext(getResource("testMtomMessageReload_01.msg"), testMtomMessageReload_01);
Packet packet = (Packet) m1;
Message riMsg = packet.getInternalMessage();
// This will cause all the attachments to be created ...
// Iterator<Attachment> as = packet.getInternalMessage().getAttachments().iterator();
// SAAJFactory:
SOAPVersion soapVersion = packet.getMessage().getSOAPVersion();
SOAPMessage saajMsg = soapVersion.getMessageFactory().createMessage();
SaajStaxWriterEx writer = new SaajStaxWriterEx(saajMsg, soapVersion.nsUri);
try {
riMsg.writeTo(writer);
} catch (XMLStreamException e) {
throw (e.getCause() instanceof SOAPException) ? (SOAPException) e.getCause() : new SOAPException(e);
}
saajMsg = writer.getSOAPMessage();
int counter = 0;
String hredCid = null;
for (Attachment a : riMsg.getAttachments()) {
hredCid = ((StreamingDataHandler) a.asDataHandler()).getHrefCid();
counter++;
}
assertTrue(writer.ma.size() == counter);
AttachmentPart ap = null;
// for (Iterator<AttachmentPart> itr = saajMsg.getAttachments(); itr.hasNext(); ) {
// System.out.println("\r\n itr.next().getContentId() " + itr.next().getContentId() );
// }
StreamingDataHandler sdh = (StreamingDataHandler) writer.ma.get(0);
assertEquals(hredCid, sdh.getHrefCid());
}
use of jakarta.xml.soap.SOAPMessage in project metro-jax-ws by eclipse-ee4j.
the class SAAJMessageTest method testMtomAttachment.
public void testMtomAttachment() throws Exception {
String testMtomMessageReload_01 = "multipart/related;type=\"application/xop+xml\";boundary=\"----=_Part_0_1145105632.1353005695468\";start=\"<cbe648b3-2055-413e-b8ed-877cdf0f2477>\";start-info=\"text/xml\"";
MessageContext m1 = mcf.createContext(getResource("testMtomMessageReload_01.msg"), testMtomMessageReload_01);
Packet packet = (Packet) m1;
Message message = packet.getInternalMessage();
Iterator<Attachment> as = packet.getInternalMessage().getAttachments().iterator();
Attachment att = null;
int counter = 0;
String cid1 = null;
while (as.hasNext()) {
att = as.next();
cid1 = att.getContentId();
counter++;
}
assertTrue(counter == 1);
// SAAJFactory:
SOAPVersion soapVersion = packet.getMessage().getSOAPVersion();
SOAPMessage msg = soapVersion.getMessageFactory().createMessage();
SaajStaxWriterEx writer = new SaajStaxWriterEx(msg, soapVersion.nsUri);
try {
message.writeTo(writer);
} catch (XMLStreamException e) {
throw (e.getCause() instanceof SOAPException) ? (SOAPException) e.getCause() : new SOAPException(e);
}
msg = writer.getSOAPMessage();
counter = 0;
String cid2 = null;
for (Attachment a : message.getAttachments()) {
counter++;
cid2 = a.getContentId();
}
assertTrue(writer.ma.size() == counter);
StreamingDataHandler sdh = (StreamingDataHandler) writer.ma.get(0);
assertEquals(cid1, sdh.getHrefCid());
assertEquals(cid2, sdh.getHrefCid());
}
Aggregations