use of jakarta.xml.soap.SOAPMessage 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.SOAPMessage 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.SOAPMessage in project metro-jax-ws by eclipse-ee4j.
the class PacketTest method testEncodeDecodedPacketMtom.
/**
* Tests that a server response Packet with MTOM feature, but
* decoded from an InputStream with a user specified non-MTOM
* content type, does NOT use MTOM when re-encoded
*/
public void testEncodeDecodedPacketMtom() throws Exception {
String msg = "<?xml version='1.0' encoding='UTF-8'?>" + "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\">" + "<soapenv:Body><soapenv:Fault>" + "<faultcode>soapenv:Server</faultcode>" + "<faultstring>ABC-380001:Internal Server Error</faultstring>" + "<detail><con:fault xmlns:con=\"http://www.bea.com/wli/sb/context\">" + "<con:errorCode>ABC-380001</con:errorCode>" + "<con:reason>Internal Server Error</con:reason>" + "<con:location><con:node>RouteNode1</con:node><con:path>response-pipeline</con:path></con:location>" + "</con:fault></detail>" + "</soapenv:Fault></soapenv:Body></soapenv:Envelope>";
WebServiceFeature[] features = { new MTOMFeature(true, 0) };
MessageContextFactory mcf = new MessageContextFactory(features);
Packet fakeRequest = (Packet) mcf.createContext();
Packet p = (Packet) mcf.createContext(new ByteArrayInputStream(msg.getBytes()), "text/xml");
fakeRequest.relateServerResponse(p, null, null, BindingImpl.create(BindingID.SOAP11_HTTP, features));
ByteArrayOutputStream bos = new ByteArrayOutputStream();
p.writeTo(bos);
String writtenMsg = new String(bos.toByteArray());
System.out.println(writtenMsg);
assertEquals("text/xml", p.getContentType().getContentType());
// try reading the message as a soap message with text/xml - this should succeed
// in parsing the message
Packet reReadPacket = (Packet) mcf.createContext(new ByteArrayInputStream(writtenMsg.getBytes()), "text/xml");
SOAPMessage soap = reReadPacket.getAsSOAPMessage();
Node bodyChild = soap.getSOAPBody().getFirstChild();
assertEquals("Fault", bodyChild.getLocalName());
}
use of jakarta.xml.soap.SOAPMessage 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.SOAPMessage in project metro-jax-ws by eclipse-ee4j.
the class SAAJFactory method readAsSOAPMessageSax2Dom.
public SOAPMessage readAsSOAPMessageSax2Dom(final SOAPVersion soapVersion, final Message message) throws SOAPException {
SOAPMessage msg = soapVersion.getMessageFactory().createMessage();
SAX2DOMEx s2d = new SAX2DOMEx(msg.getSOAPPart());
try {
message.writeTo(s2d, XmlUtil.DRACONIAN_ERROR_HANDLER);
} catch (SAXException e) {
throw new SOAPException(e);
}
addAttachmentsToSOAPMessage(msg, message);
if (msg.saveRequired())
msg.saveChanges();
return msg;
}
Aggregations