use of javax.xml.soap.SOAPElement in project ddf by codice.
the class GuestInterceptor method createAddressing.
private void createAddressing(SoapMessage message, SOAPMessage soapMessage) {
SOAPFactory soapFactory;
try {
soapFactory = SOAPFactory.newInstance();
} catch (SOAPException e) {
LOGGER.debug("Could not create a SOAPFactory.", e);
// can't add anything if we can't create it
return;
}
String addressingProperty = org.apache.cxf.ws.addressing.JAXWSAConstants.CLIENT_ADDRESSING_PROPERTIES_INBOUND;
AddressingProperties addressingProperties = new AddressingProperties();
try {
SOAPElement action = soapFactory.createElement(org.apache.cxf.ws.addressing.Names.WSA_ACTION_NAME, org.apache.cxf.ws.addressing.JAXWSAConstants.WSA_PREFIX, org.apache.cxf.ws.security.wss4j.DefaultCryptoCoverageChecker.WSA_NS);
action.addTextNode((String) message.get(org.apache.cxf.message.Message.REQUEST_URL));
AttributedURIType attributedString = new AttributedURIType();
String actionValue = StringUtils.defaultIfEmpty((String) message.get(SoapBindingConstants.SOAP_ACTION), "");
attributedString.setValue(actionValue);
addressingProperties.setAction(attributedString);
soapMessage.getSOAPHeader().addChildElement(action);
} catch (SOAPException e) {
LOGGER.debug("Unable to add addressing action.", e);
}
try {
SOAPElement messageId = soapFactory.createElement(org.apache.cxf.ws.addressing.Names.WSA_MESSAGEID_NAME, org.apache.cxf.ws.addressing.JAXWSAConstants.WSA_PREFIX, org.apache.cxf.ws.security.wss4j.DefaultCryptoCoverageChecker.WSA_NS);
String uuid = "urn:uuid:" + UUID.randomUUID().toString();
messageId.addTextNode(uuid);
AttributedURIType attributedString = new AttributedURIType();
attributedString.setValue(uuid);
addressingProperties.setMessageID(attributedString);
soapMessage.getSOAPHeader().addChildElement(messageId);
} catch (SOAPException e) {
LOGGER.debug("Unable to add addressing messageId.", e);
}
try {
SOAPElement to = soapFactory.createElement(org.apache.cxf.ws.addressing.Names.WSA_TO_NAME, org.apache.cxf.ws.addressing.JAXWSAConstants.WSA_PREFIX, org.apache.cxf.ws.security.wss4j.DefaultCryptoCoverageChecker.WSA_NS);
to.addTextNode((String) message.get(org.apache.cxf.message.Message.REQUEST_URL));
EndpointReferenceType endpointReferenceType = new EndpointReferenceType();
AttributedURIType attributedString = new AttributedURIType();
attributedString.setValue((String) message.get(org.apache.cxf.message.Message.REQUEST_URL));
endpointReferenceType.setAddress(attributedString);
addressingProperties.setTo(endpointReferenceType);
soapMessage.getSOAPHeader().addChildElement(to);
} catch (SOAPException e) {
LOGGER.debug("Unable to add addressing to.", e);
}
try {
SOAPElement replyTo = soapFactory.createElement(org.apache.cxf.ws.addressing.Names.WSA_REPLYTO_NAME, org.apache.cxf.ws.addressing.JAXWSAConstants.WSA_PREFIX, org.apache.cxf.ws.security.wss4j.DefaultCryptoCoverageChecker.WSA_NS);
SOAPElement address = soapFactory.createElement(org.apache.cxf.ws.addressing.Names.WSA_ADDRESS_NAME, org.apache.cxf.ws.addressing.JAXWSAConstants.WSA_PREFIX, org.apache.cxf.ws.security.wss4j.DefaultCryptoCoverageChecker.WSA_NS);
address.addTextNode(org.apache.cxf.ws.addressing.Names.WSA_ANONYMOUS_ADDRESS);
replyTo.addChildElement(address);
soapMessage.getSOAPHeader().addChildElement(replyTo);
} catch (SOAPException e) {
LOGGER.debug("Unable to add addressing replyTo.", e);
}
message.put(addressingProperty, addressingProperties);
}
use of javax.xml.soap.SOAPElement 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.SOAPElement 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.SOAPElement 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;
}
use of javax.xml.soap.SOAPElement in project OpenAM by OpenRock.
the class SAMLSOAPReceiver method onMessage.
/**
* Retrieves the SAML <code>Request</code> from the
* <code>SOAPMessage</code>, calls internal methods to parse the
* <code>Request</code> generate SAML <code>Response</code> and send it
* back to the requestor again using SOAP binding over HTTP.
*/
private SOAPMessage onMessage(HttpServletRequest req, HttpServletResponse servletResp, SOAPMessage message, Set partnerSourceID) {
// first check if there was any soap error during verifyHost()
try {
if (SAMLUtils.debug.messageEnabled()) {
SAMLUtils.debug.message("OnMessage called in receiving " + "servlet");
}
// check the SOAP message for any SOAP
// related errros before passing control to SAML processor
ByteArrayOutputStream bop = new ByteArrayOutputStream();
message.writeTo(bop);
ByteArrayInputStream bin = new ByteArrayInputStream(bop.toByteArray());
Document doc = XMLUtils.toDOMDocument(bin, SAMLUtils.debug);
Element root = doc.getDocumentElement();
String rootName = doc.getDocumentElement().getLocalName();
if ((rootName == null) || (rootName.length() == 0)) {
SAMLUtils.debug.error("Local name of the SOAPElement in the" + " SOAPMessage passed seems to be missing");
return FormSOAPError(servletResp, "Client", "nullInput", "LocalNameMissing");
}
if (!(rootName.equals("Envelope")) || (!(root.getNamespaceURI().equals(sc.SOAP_URI)))) {
SAMLUtils.debug.error("SOAPReceiver: Could not parse " + "SOAPMessage, either root element is not Envelope" + " or invalid name space or prefix");
return FormSOAPError(servletResp, "Client", "invalidElement", "envelopeInvalid");
}
NodeList nl = doc.getChildNodes();
int length = nl.getLength();
if (length <= 0) {
SAMLUtils.debug.error("SOAPReceiver: Message does not have " + "body");
return FormSOAPError(servletResp, "Client", "missingBody", null);
}
Node child = null;
for (int i = 0; i < length; i++) {
child = (Node) nl.item(i);
if (child.getNodeType() != Node.ELEMENT_NODE) {
continue;
}
String childName = child.getLocalName();
if (childName.equals("Body")) {
// found the message body
break;
}
}
Element body = (Element) child;
Response resp = extractProcessRequest(req, body, partnerSourceID);
if (((Boolean) SAMLServiceManager.getAttribute(SAMLConstants.SIGN_RESPONSE)).booleanValue()) {
resp.signXML();
}
return FormMessageResponse(servletResp, resp);
} catch (Exception e) {
SAMLUtils.debug.error("Error in processing Request", e);
return FormSOAPError(servletResp, "Server", "cannotProcessRequest", null);
}
}
Aggregations