use of jakarta.xml.soap.SOAPBody in project openmq by eclipse-ee4j.
the class SOAPtoJMSServlet method generateResponseMessage.
/**
* Add a MessageStatus element with the value of "published" to
* the soapMessage.
*/
public SOAPMessage generateResponseMessage(SOAPMessage soapMessage) {
try {
SOAPPart soapPart = soapMessage.getSOAPPart();
SOAPEnvelope envelope = soapPart.getEnvelope();
SOAPBody soapBody = envelope.getBody();
soapBody.addChildElement("MessageStatus").addTextNode("published");
soapMessage.saveChanges();
} catch (SOAPException soape) {
soape.printStackTrace();
}
return soapMessage;
}
use of jakarta.xml.soap.SOAPBody 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.SOAPBody in project metro-jax-ws by eclipse-ee4j.
the class SOAPActionTest method testUnquotedSOAPAction1.
public void testUnquotedSOAPAction1() throws Exception {
TestEndpoint port = new TestEndpointService().getTestEndpointPort1();
String address = (String) ((BindingProvider) port).getRequestContext().get(BindingProvider.ENDPOINT_ADDRESS_PROPERTY);
HTTPResponseInfo rInfo = ClientServerTestUtil.sendPOSTRequest(address, s11_request, "text/xml", "http://example.com/action/echo");
String resp = rInfo.getResponseBody();
SOAPMessage respMesg = getSOAPMessage(makeStreamSource(resp));
SOAPBody body = respMesg.getSOAPPart().getEnvelope().getBody();
Element e = (Element) body.getElementsByTagName("return").item(0);
// make sure it is dispatched to echo() using SoapAction
assertEquals("Hello Duke", e.getTextContent());
}
use of jakarta.xml.soap.SOAPBody in project metro-jax-ws by eclipse-ee4j.
the class Client method testMultipleBodies.
public void testMultipleBodies() throws SOAPException {
if (ClientServerTestUtil.useLocal()) {
System.out.println("Runs only in HTTP!");
return;
}
Service service = Service.create(new QName("urn:test", "Endpoint"));
service.addPort(new QName("urn:test", "EndpointPort"), SOAPBinding.SOAP11HTTP_BINDING, "http://localhost:8080/jaxrpc-provider_tests_multiple_body/endpoint");
Dispatch<SOAPMessage> disp = service.createDispatch(new QName("urn:test", "EndpointPort"), SOAPMessage.class, Service.Mode.MESSAGE);
SOAPMessage sm = SOAPVersion.SOAP_11.saajMessageFactory.createMessage();
SOAPBody sb = sm.getSOAPBody();
sb.addBodyElement(new QName("http://first.body", "first"));
sb.addBodyElement(new QName("http://second.body", "second"));
SOAPMessage resp = disp.invoke(sm);
SOAPBody body = resp.getSOAPBody();
NodeList nl = body.getChildNodes();
assertTrue(nl.getLength() == 2);
Node n = nl.item(0);
assertTrue(n.getLocalName().equals("first") && n.getNamespaceURI().equals("http://first.body"));
n = nl.item(1);
assertTrue(n.getLocalName().equals("second") && n.getNamespaceURI().equals("http://second.body"));
}
use of jakarta.xml.soap.SOAPBody in project metro-jax-ws by eclipse-ee4j.
the class SOAPTestHandler method handleMessage.
public boolean handleMessage(SOAPMessageContext smc) {
try {
SOAPMessage message = smc.getMessage();
SOAPBody body = message.getSOAPBody();
SOAPElement paramElement = (SOAPElement) body.getFirstChild().getFirstChild();
int number = Integer.parseInt(paramElement.getValue());
if (number == THROW_RUNTIME_EXCEPTION) {
throw new RuntimeException("EXPECTED EXCEPTION");
} else if (number == THROW_PROTOCOL_EXCEPTION) {
throw new ProtocolException("EXPECTED EXCEPTION");
} else if (number == THROW_SOAPFAULT_EXCEPTION) {
// todo
}
paramElement.setValue(String.valueOf(++number));
} catch (SOAPException e) {
e.printStackTrace();
throw new RuntimeException(e);
}
return true;
}
Aggregations