use of javax.xml.soap.SOAPBody in project tomee by apache.
the class Increment method handleMessage.
public boolean handleMessage(SOAPMessageContext mc) {
try {
final SOAPMessage message = mc.getMessage();
final SOAPBody body = message.getSOAPBody();
final String localName = body.getFirstChild().getLocalName();
if ("sumResponse".equals(localName) || "multiplyResponse".equals(localName)) {
final Node responseNode = body.getFirstChild();
final Node returnNode = responseNode.getFirstChild();
final Node intNode = returnNode.getFirstChild();
final int value = new Integer(intNode.getNodeValue());
intNode.setNodeValue(Integer.toString(value + 1));
}
return true;
} catch (SOAPException e) {
return false;
}
}
use of javax.xml.soap.SOAPBody in project webservices-axiom by apache.
the class TestAddChildElementReification method runTest.
@Override
protected void runTest() throws Throwable {
MessageFactory mf = spec.getAdapter(FactorySelector.class).newMessageFactory(saajImplementation, false);
SOAPBody body = mf.createMessage().getSOAPBody();
SOAPElement child = body.addChildElement((SOAPElement) body.getOwnerDocument().createElementNS("urn:test", "p:test"));
assertThat(child).isInstanceOf(SOAPBodyElement.class);
}
use of javax.xml.soap.SOAPBody in project camel by apache.
the class Client method invoke.
public String invoke() throws Exception {
// Service Qname as defined in the WSDL.
QName serviceName = new QName("http://apache.org/hello_world_soap_http", "SOAPService");
// Port QName as defined in the WSDL.
QName portName = new QName("http://apache.org/hello_world_soap_http", "SoapOverHttpRouter");
// Create a dynamic Service instance
Service service = Service.create(serviceName);
// Add a port to the Service
service.addPort(portName, SOAPBinding.SOAP11HTTP_BINDING, endpointAddress);
// Create a dispatch instance
Dispatch<SOAPMessage> dispatch = service.createDispatch(portName, SOAPMessage.class, Service.Mode.MESSAGE);
// Use Dispatch as BindingProvider
BindingProvider bp = dispatch;
MessageFactory factory = ((SOAPBinding) bp.getBinding()).getMessageFactory();
// Create SOAPMessage Request
SOAPMessage request = factory.createMessage();
// Request Body
SOAPBody body = request.getSOAPBody();
// Compose the soap:Body payload
QName payloadName = new QName("http://apache.org/hello_world_soap_http/types", "greetMe", "ns1");
SOAPBodyElement payload = body.addBodyElement(payloadName);
SOAPElement message = payload.addChildElement("requestType");
message.addTextNode("Hello Camel!!");
System.out.println("Send out the request: Hello Camel!!");
// Invoke the endpoint synchronously
// Invoke endpoint operation and read response
SOAPMessage reply = dispatch.invoke(request);
// process the reply
body = reply.getSOAPBody();
QName responseName = new QName("http://apache.org/hello_world_soap_http/types", "greetMeResponse");
SOAPElement bodyElement = (SOAPElement) body.getChildElements(responseName).next();
String responseMessageText = bodyElement.getTextContent();
System.out.println("Get the response: " + responseMessageText);
return responseMessageText;
}
use of javax.xml.soap.SOAPBody in project tomcat by apache.
the class SignCode method downloadSignedFiles.
private void downloadSignedFiles(List<File> filesToSign, String id) throws SOAPException, IOException {
log("Downloading signed files. The signing set ID is: " + id);
SOAPMessage message = SOAP_MSG_FACTORY.createMessage();
SOAPBody body = populateEnvelope(message, NS);
SOAPElement getSigningSetDetails = body.addChildElement("getSigningSetDetails", NS);
SOAPElement getSigningSetDetailsRequest = getSigningSetDetails.addChildElement("getSigningSetDetailsRequest", NS);
addCredentials(getSigningSetDetailsRequest, this.userName, this.password, this.partnerCode);
SOAPElement signingSetID = getSigningSetDetailsRequest.addChildElement("signingSetID", NS);
signingSetID.addTextNode(id);
SOAPElement returnApplication = getSigningSetDetailsRequest.addChildElement("returnApplication", NS);
returnApplication.addTextNode("true");
// Send the message
SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
SOAPConnection connection = soapConnectionFactory.createConnection();
log("Requesting signed files from server and waiting for response");
SOAPMessage response = connection.call(message, SIGNING_SERVICE_URL);
log("Processing response");
SOAPElement responseBody = response.getSOAPBody();
// Check for success
// Extract the signed file(s) from the ZIP
NodeList bodyNodes = responseBody.getChildNodes();
NodeList getSigningSetDetailsResponseNodes = bodyNodes.item(0).getChildNodes();
NodeList returnNodes = getSigningSetDetailsResponseNodes.item(0).getChildNodes();
String result = null;
String data = null;
for (int i = 0; i < returnNodes.getLength(); i++) {
Node returnNode = returnNodes.item(i);
if (returnNode.getLocalName().equals("result")) {
result = returnNode.getChildNodes().item(0).getTextContent();
} else if (returnNode.getLocalName().equals("signingSet")) {
data = returnNode.getChildNodes().item(1).getTextContent();
}
}
if (!"0".equals(result)) {
throw new BuildException("Download failed. Result code was: " + result);
}
extractFilesFromApplicationString(data, filesToSign);
}
use of javax.xml.soap.SOAPBody in project tomcat by apache.
the class SignCode method makeSigningRequest.
private String makeSigningRequest(List<File> filesToSign) throws SOAPException, IOException {
log("Constructing the code signing request");
SOAPMessage message = SOAP_MSG_FACTORY.createMessage();
SOAPBody body = populateEnvelope(message, NS);
SOAPElement requestSigning = body.addChildElement("requestSigning", NS);
SOAPElement requestSigningRequest = requestSigning.addChildElement("requestSigningRequest", NS);
addCredentials(requestSigningRequest, this.userName, this.password, this.partnerCode);
SOAPElement applicationName = requestSigningRequest.addChildElement("applicationName", NS);
applicationName.addTextNode(this.applicationName);
SOAPElement applicationVersion = requestSigningRequest.addChildElement("applicationVersion", NS);
applicationVersion.addTextNode(this.applicationVersion);
SOAPElement signingServiceName = requestSigningRequest.addChildElement("signingServiceName", NS);
signingServiceName.addTextNode(this.signingService);
List<String> fileNames = getFileNames(filesToSign);
SOAPElement commaDelimitedFileNames = requestSigningRequest.addChildElement("commaDelimitedFileNames", NS);
commaDelimitedFileNames.addTextNode(listToString(fileNames));
SOAPElement application = requestSigningRequest.addChildElement("application", NS);
application.addTextNode(getApplicationString(fileNames, filesToSign));
// Send the message
SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
SOAPConnection connection = soapConnectionFactory.createConnection();
log("Sending singing request to server and waiting for response");
SOAPMessage response = connection.call(message, SIGNING_SERVICE_URL);
log("Processing response");
SOAPElement responseBody = response.getSOAPBody();
// Should come back signed
NodeList bodyNodes = responseBody.getChildNodes();
NodeList requestSigningResponseNodes = bodyNodes.item(0).getChildNodes();
NodeList returnNodes = requestSigningResponseNodes.item(0).getChildNodes();
String signingSetID = null;
String signingSetStatus = null;
for (int i = 0; i < returnNodes.getLength(); i++) {
Node returnNode = returnNodes.item(i);
if (returnNode.getLocalName().equals("signingSetID")) {
signingSetID = returnNode.getTextContent();
} else if (returnNode.getLocalName().equals("signingSetStatus")) {
signingSetStatus = returnNode.getTextContent();
}
}
if (!signingService.contains("TEST") && !"SIGNED".equals(signingSetStatus) || signingService.contains("TEST") && !"INITIALIZED".equals(signingSetStatus)) {
throw new BuildException("Signing failed. Status was: " + signingSetStatus);
}
return signingSetID;
}
Aggregations