use of jakarta.xml.soap.MessageFactory in project metro-jax-ws by eclipse-ee4j.
the class AddNumbersClient method invokeAsyncPollAddNumbers.
private void invokeAsyncPollAddNumbers(String msgString) throws RemoteException {
SOAPMessage message = null;
try {
MessageFactory factory = MessageFactory.newInstance();
message = factory.createMessage();
message.getSOAPPart().setContent((Source) new StreamSource(new StringReader(msgString)));
message.saveChanges();
} catch (SOAPException e) {
e.printStackTrace();
}
Dispatch<SOAPMessage> smDispatch = null;
smDispatch = service.createDispatch(portQName, SOAPMessage.class, Service.Mode.MESSAGE);
System.out.println("\nInvoking async poll message: " + msgString);
Response<SOAPMessage> response = smDispatch.invokeAsync(message);
while (!response.isDone()) {
// go do some work
}
String xmlString = null;
try {
SOAPMessage result = response.get();
Source sourceResult = (Source) result.getSOAPPart().getContent();
xmlString = sourceToXMLString(sourceResult);
} catch (SOAPException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
System.out.println("Received response: " + xmlString);
}
use of jakarta.xml.soap.MessageFactory in project metro-jax-ws by eclipse-ee4j.
the class AddNumbersClient method invokeAsyncCallbackAddNumbers.
private void invokeAsyncCallbackAddNumbers(String msgString) throws RemoteException {
SOAPMessage message = null;
try {
MessageFactory factory = MessageFactory.newInstance();
message = factory.createMessage();
message.getSOAPPart().setContent((Source) new StreamSource(new StringReader(msgString)));
message.saveChanges();
} catch (SOAPException e) {
e.printStackTrace();
}
Dispatch smDispatch = null;
smDispatch = service.createDispatch(portQName, SOAPMessage.class, Service.Mode.MESSAGE);
System.out.println("\nInvoking async callback message: " + msgString);
DispatchAsyncHandler handler = new DispatchAsyncHandler();
Future<?> response = smDispatch.invokeAsync(message, handler);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
if (response.isDone()) {
if (handler.isFailure()) {
Throwable failure = handler.getFailure();
System.out.println("Failure in DispatchAsyncHandler " + failure.getMessage());
} else
System.out.println("Success processing result!");
}
}
use of jakarta.xml.soap.MessageFactory in project metro-jax-ws by eclipse-ee4j.
the class ReplaceAddressingHeaderTest method makeSOAPMessage.
private SOAPMessage makeSOAPMessage(String msg) throws Exception {
MessageFactory factory = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
SOAPMessage message = factory.createMessage();
Source src = new StreamSource(new ByteArrayInputStream(msg.getBytes()));
message.getSOAPPart().setContent(src);
return message;
}
use of jakarta.xml.soap.MessageFactory 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.MessageFactory 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();
}
Aggregations