Java Code Examples for javax.xml.soap.SOAPElement#addTextNode()

The following examples show how to use javax.xml.soap.SOAPElement#addTextNode() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: XRoadProtocolNamespaceStrategyV4.java    From j-road with Apache License 2.0 7 votes vote down vote up
private void addClientElements(SOAPEnvelope env, XRoadServiceConfiguration conf, SOAPHeader header)
    throws SOAPException {
  // TODO: maybe we should create headers differently according to object type?
  XroadObjectType objectType =
      conf.getClientObjectType() != null ? conf.getClientObjectType() : XroadObjectType.SUBSYSTEM;
  SOAPElement client = header.addChildElement("client", protocol.getNamespacePrefix());
  client.addAttribute(env.createName("id:objectType"), objectType.name());
  SOAPElement clientXRoadInstance = client.addChildElement("xRoadInstance", "id");
  clientXRoadInstance.addTextNode(conf.getClientXRoadInstance());
  SOAPElement clientMemberClass = client.addChildElement("memberClass", "id");
  clientMemberClass.addTextNode(conf.getClientMemberClass());
  SOAPElement clientMemberCode = client.addChildElement("memberCode", "id");
  clientMemberCode.addTextNode(conf.getClientMemberCode());

  if (StringUtils.isNotBlank(conf.getClientSubsystemCode())) {
    SOAPElement clientSubsystemCode = client.addChildElement("subsystemCode", "id");
    clientSubsystemCode.addTextNode(conf.getClientSubsystemCode());
  }
}
 
Example 2
Source File: XRoadProtocolNamespaceStrategyV4.java    From j-road with Apache License 2.0 6 votes vote down vote up
@Override
public void addXTeeHeaderElements(SOAPEnvelope env, XRoadServiceConfiguration conf) throws SOAPException {
  SOAPHeader header = env.getHeader();
  if(StringUtils.isNotBlank(conf.getIdCode())) {
    SOAPElement userId = header.addChildElement("userId", protocol.getNamespacePrefix());
    userId.addTextNode(conf.getIdCode());
  }
  SOAPElement id = header.addChildElement("id", protocol.getNamespacePrefix());
  id.addTextNode(generateUniqueMessageId(conf));
  if (StringUtils.isNotBlank(conf.getFile())) {
    SOAPElement issue = header.addChildElement("issue", protocol.getNamespacePrefix());
    issue.addTextNode(conf.getFile());
  }
  SOAPElement protocolVersion = header.addChildElement("protocolVersion", protocol.getNamespacePrefix());
  protocolVersion.addTextNode(protocol.getCode());

  addClientElements(env, conf, header);
  addServiceElements(env, conf, header);
}
 
Example 3
Source File: JRXmlaQueryExecuter.java    From jasperreports with GNU Lesser General Public License v3.0 6 votes vote down vote up
protected void addParameterList(SOAPEnvelope envelope, SOAPElement eParent, String typeName, String listName, Map<String, String> params) throws SOAPException
{
	Name nPara = envelope.createName(typeName, "", XMLA_URI);
	SOAPElement eType = eParent.addChildElement(nPara);
	nPara = envelope.createName(listName, "", XMLA_URI);
	SOAPElement eList = eType.addChildElement(nPara);
	if (params == null)
	{
		return;
	}
	for (Iterator<Map.Entry<String, String>> entryIt = params.entrySet().iterator(); entryIt.hasNext();)
	{
		Map.Entry<String, String> entry = entryIt.next();
		String tag = entry.getKey();
		String value = entry.getValue();
		nPara = envelope.createName(tag, "", XMLA_URI);
		SOAPElement eTag = eList.addChildElement(nPara);
		eTag.addTextNode(value);
	}
}
 
Example 4
Source File: SignCode.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
private static void addCredentials(SOAPElement requestSigningRequest,
        String user, String pwd, String code) throws SOAPException {
    SOAPElement authToken = requestSigningRequest.addChildElement("authToken", NS);
    SOAPElement userName = authToken.addChildElement("userName", NS);
    userName.addTextNode(user);
    SOAPElement password = authToken.addChildElement("password", NS);
    password.addTextNode(pwd);
    SOAPElement partnerCode = authToken.addChildElement("partnerCode", NS);
    partnerCode.addTextNode(code);
}
 
Example 5
Source File: XTeeUtil.java    From j-road with Apache License 2.0 5 votes vote down vote up
/**
 * Adds a X-Tee header element with given value and using correct namespace, element type is set to
 * <code>xsd:string</code>.
 *
 * @param header Header of the <code>SOAPMessage</code>
 * @param name Header element name
 * @param value Header element value
 */
public static void addHeaderElement(SOAPHeader header, String name, String value, String nsPrefix)
    throws SOAPException {
  SOAPElement element = header.addChildElement(name, nsPrefix);
  SOAPUtil.addTypeAttribute(element, "xsd:string");
  if (value != null) {
    element.addTextNode(value);
  }
}
 
Example 6
Source File: JPlagServerAccessHandler.java    From jplag with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Manually builds up a JPlagException SOAP message and replaces the
 * original one with it
 */
public void replaceByJPlagException(SOAPMessageContext smsg, String desc, String rep) {
	try {
		SOAPMessage msg = smsg.getMessage();
		SOAPEnvelope envelope = msg.getSOAPPart().getEnvelope();

		/*
		 * Remove old header andy body
		 */

		SOAPHeader oldheader = envelope.getHeader();
		if (oldheader != null)
			oldheader.detachNode();
		SOAPBody oldbody = envelope.getBody();
		if (oldbody != null)
			oldbody.detachNode();

		SOAPBody sb = envelope.addBody();
		SOAPFault sf = sb.addFault(envelope.createName("Server", "env", SOAPConstants.URI_NS_SOAP_ENVELOPE),
				"jplagWebService.server.JPlagException");
		Detail detail = sf.addDetail();
		DetailEntry de = detail.addDetailEntry(envelope.createName("JPlagException", "ns0", JPLAG_WEBSERVICE_BASE_URL + "types"));

		SOAPElement e = de.addChildElement("exceptionType");
		e.addTextNode("accessException");

		e = de.addChildElement("description");
		e.addTextNode(desc);

		e = de.addChildElement("repair");
		e.addTextNode(rep);
	} catch (SOAPException x) {
		x.printStackTrace();
	}
}
 
Example 7
Source File: AbstractTypeTestClient3.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testStructWithInvalidAnyArray() throws Exception {
    if (!shouldRunTest("StructWithInvalidAnyArray")) {
        return;
    }
    StructWithAnyArray swa = new StructWithAnyArray();
    swa.setName("Name");
    swa.setAddress("Some Address");

    StructWithAnyArray yOrig = new StructWithAnyArray();
    yOrig.setName("Name2");
    yOrig.setAddress("Some Other Address");

    SOAPFactory factory = SOAPFactory.newInstance();
    SOAPElement x = factory.createElement("hello", "foo", "http://some.url.com");
    x.addTextNode("This is the text of the node");

    SOAPElement x2 = factory.createElement("hello2", "foo", "http://some.url.com");
    x2.addTextNode("This is the text of the node for the second struct");

    swa.getAny().add(x);
    yOrig.getAny().add(x2);

    Holder<StructWithAnyArray> y = new Holder<>(yOrig);
    Holder<StructWithAnyArray> z = new Holder<>();

    try {
        if (testDocLiteral) {
            docClient.testStructWithAnyArray(swa, y, z);
        } else if (testXMLBinding) {
            xmlClient.testStructWithAnyArray(swa, y, z);
        } else {
            rpcClient.testStructWithAnyArray(swa, y, z);
        }
        //fail("testStructWithInvalidAnyArray(): Did not catch expected exception.");
    } catch (Exception ex) {
        // Expected
        fail("testStructWithInvalidAnyArray(): caught expected exception - woot.");
    }
}
 
Example 8
Source File: MdwRpcWebServiceAdapter.java    From mdw with Apache License 2.0 5 votes vote down vote up
/**
 * Populate the SOAP request message.
 */
protected SOAPMessage createSoapRequest(Object requestObj) throws ActivityException {
    try {
        MessageFactory messageFactory = getSoapMessageFactory();
        SOAPMessage soapMessage = messageFactory.createMessage();
        Map<Name,String> soapReqHeaders = getSoapRequestHeaders();
        if (soapReqHeaders != null) {
            SOAPHeader header = soapMessage.getSOAPHeader();
            for (Name name : soapReqHeaders.keySet()) {
                header.addHeaderElement(name).setTextContent(soapReqHeaders.get(name));
            }
        }

        SOAPBody soapBody = soapMessage.getSOAPBody();

        Document requestDoc = null;
        if (requestObj instanceof String) {
            requestDoc = DomHelper.toDomDocument((String)requestObj);
        }
        else {
            Variable reqVar = getProcessDefinition().getVariable(getAttributeValue(REQUEST_VARIABLE));
            XmlDocumentTranslator docRefTrans = (XmlDocumentTranslator)getPackage().getTranslator(reqVar.getType());
            requestDoc = docRefTrans.toDomDocument(requestObj);
        }

        SOAPBodyElement bodyElem = soapBody.addBodyElement(getOperation());
        String requestLabel = getRequestLabelPartName();
        if (requestLabel != null) {
            SOAPElement serviceNameElem = bodyElem.addChildElement(requestLabel);
            serviceNameElem.addTextNode(getRequestLabel());
        }
        SOAPElement requestDetailsElem = bodyElem.addChildElement(getRequestPartName());
        requestDetailsElem.addTextNode("<![CDATA[" + DomHelper.toXml(requestDoc) + "]]>");

        return soapMessage;
    }
    catch (Exception ex) {
        throw new ActivityException(ex.getMessage(), ex);
    }
}
 
Example 9
Source File: JRXmlaQueryExecuter.java    From jasperreports with GNU Lesser General Public License v3.0 4 votes vote down vote up
protected SOAPMessage createQueryMessage()
{
	String queryStr = getQueryString();

	if (log.isDebugEnabled())
	{
		log.debug("MDX query: " + queryStr);
	}
	
	try
	{
		MessageFactory mf = MessageFactory.newInstance();
		SOAPMessage message = mf.createMessage();

		MimeHeaders mh = message.getMimeHeaders();
		mh.setHeader("SOAPAction", "\"urn:schemas-microsoft-com:xml-analysis:Execute\"");

		SOAPPart soapPart = message.getSOAPPart();
		SOAPEnvelope envelope = soapPart.getEnvelope();
		SOAPBody body = envelope.getBody();
		Name nEx = envelope.createName("Execute", "", XMLA_URI);

		SOAPElement eEx = body.addChildElement(nEx);

		// add the parameters

		// COMMAND parameter
		// <Command>
		// <Statement>queryStr</Statement>
		// </Command>
		Name nCom = envelope.createName("Command", "", XMLA_URI);
		SOAPElement eCommand = eEx.addChildElement(nCom);
		Name nSta = envelope.createName("Statement", "", XMLA_URI);
		SOAPElement eStatement = eCommand.addChildElement(nSta);
		eStatement.addTextNode(queryStr);

		// <Properties>
		// <PropertyList>
		// <DataSourceInfo>dataSource</DataSourceInfo>
		// <Catalog>catalog</Catalog>
		// <Format>Multidimensional</Format>
		// <AxisFormat>TupleFormat</AxisFormat>
		// </PropertyList>
		// </Properties>
		Map<String, String> paraList = new HashMap<String, String>();
		String datasource = (String) getParameterValue(JRXmlaQueryExecuterFactory.PARAMETER_XMLA_DATASOURCE);
		paraList.put("DataSourceInfo", datasource);
		String catalog = (String) getParameterValue(JRXmlaQueryExecuterFactory.PARAMETER_XMLA_CATALOG);
		paraList.put("Catalog", catalog);
		paraList.put("Format", "Multidimensional");
		paraList.put("AxisFormat", "TupleFormat");
		addParameterList(envelope, eEx, "Properties", "PropertyList", paraList);
		message.saveChanges();

		if (log.isDebugEnabled())
		{
			log.debug("XML/A query message: \n" + prettyPrintSOAP(message.getSOAPPart().getEnvelope()));
		}

		return message;
	}
	catch (SOAPException e)
	{
		throw new JRRuntimeException(e);
	}
}
 
Example 10
Source File: AbstractTypeTestClient5.java    From cxf with Apache License 2.0 4 votes vote down vote up
@Test
public void testStructWithAnyStrict() throws Exception {
    if (!shouldRunTest("StructWithAnyStrict")) {
        return;
    }
    SOAPFactory factory = SOAPFactory.newInstance();
    SOAPElement elem = factory.createElement("StringElementQualified",
        "x1", "http://apache.org/type_test/types1");
    elem.addNamespaceDeclaration("x1", "http://apache.org/type_test/types1");
    elem.addTextNode("This is the text of the node");

    StructWithAnyStrict x = new StructWithAnyStrict();
    x.setName("Name x");
    x.setAddress("Some Address x");
    x.setAny(elem);

    elem = factory.createElement("StringElementQualified",
        "x1", "http://apache.org/type_test/types1");
    elem.addNamespaceDeclaration("x1", "http://apache.org/type_test/types1");
    elem.addTextNode("This is the text of the second node");

    StructWithAnyStrict yOrig = new StructWithAnyStrict();
    yOrig.setName("Name y");
    yOrig.setAddress("Some Address y");
    yOrig.setAny(elem);

    Holder<StructWithAnyStrict> y = new Holder<>(yOrig);
    Holder<StructWithAnyStrict> z = new Holder<>();
    StructWithAnyStrict ret;
    if (testDocLiteral) {
        ret = docClient.testStructWithAnyStrict(x, y, z);
    } else if (testXMLBinding) {
        ret = xmlClient.testStructWithAnyStrict(x, y, z);
    } else {
        ret = rpcClient.testStructWithAnyStrict(x, y, z);
    }

    if (!perfTestOnly) {
        assertEqualsStructWithAnyStrict(x, y.value);
        assertEqualsStructWithAnyStrict(yOrig, z.value);
        assertEqualsStructWithAnyStrict(x, ret);
    }
}
 
Example 11
Source File: AbstractTypeTestClient3.java    From cxf with Apache License 2.0 4 votes vote down vote up
@Test
public void testStructWithAnyXsi() throws Exception {
    if (!shouldRunTest("StructWithAnyXsi")) {
        return;
    }
    StructWithAny swa = new StructWithAny();
    swa.setName("Name");
    swa.setAddress("Some Address");
    StructWithAny yOrig = new StructWithAny();
    yOrig.setName("Name2");
    yOrig.setAddress("Some Other Address");

    SOAPFactory sf = SOAPFactory.newInstance();
    Name elementName = sf.createName("UKAddress", "", "http://apache.org/type_test");
    Name xsiAttrName = sf.createName("type", "xsi", "http://www.w3.org/2001/XMLSchema-instance");
    SOAPElement x = sf.createElement(elementName);
    x.addNamespaceDeclaration("tns", "http://apache.org/type_test");
    x.addNamespaceDeclaration("xsi", "http://www.w3.org/2001/XMLSchema-instance");
    x.addAttribute(xsiAttrName, "tns:UKAddressType11");
    x.addTextNode("This is the text of the node for the first struct");

    Name elementName2 = sf.createName("UKAddress", "", "http://apache.org/type_test");
    Name xsiAttrName2 = sf.createName("type", "xsi", "http://www.w3.org/2001/XMLSchema-instance");
    SOAPElement x2 = sf.createElement(elementName2);
    x2.addNamespaceDeclaration("tns", "http://apache.org/type_test");
    x2.addNamespaceDeclaration("xsi", "http://www.w3.org/2001/XMLSchema-instance");
    x2.addAttribute(xsiAttrName2, "tns:UKAddressType22");
    x2.addTextNode("This is the text of the node for the second struct");

    swa.setAny(x);
    yOrig.setAny(x2);

    Holder<StructWithAny> y = new Holder<>(yOrig);
    Holder<StructWithAny> z = new Holder<>();
    StructWithAny ret;
    if (testDocLiteral) {
        ret = docClient.testStructWithAny(swa, y, z);
    } else if (testXMLBinding) {
        ret = xmlClient.testStructWithAny(swa, y, z);
    } else {
        ret = rpcClient.testStructWithAny(swa, y, z);
    }
    if (!perfTestOnly) {
        assertEqualsStructWithAny(swa, y.value);
        assertEqualsStructWithAny(yOrig, z.value);
        assertEqualsStructWithAny(swa, ret);
    }
}
 
Example 12
Source File: CompilatioAPIUtil.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
public static Document callCompilatioReturnDocument(String apiURL, Map<String, String> parameters, String secretKey,
		final int timeout) throws TransientSubmissionException, SubmissionException {

	SOAPConnectionFactory soapConnectionFactory;
	Document xmlDocument = null;
	try {
		soapConnectionFactory = SOAPConnectionFactory.newInstance();

		SOAPConnection soapConnection = soapConnectionFactory.createConnection();

		MessageFactory messageFactory = MessageFactory.newInstance();
		SOAPMessage soapMessage = messageFactory.createMessage();
		SOAPPart soapPart = soapMessage.getSOAPPart();
		SOAPEnvelope envelope = soapPart.getEnvelope();
		SOAPBody soapBody = envelope.getBody();
		SOAPElement soapBodyAction = soapBody.addChildElement(parameters.get("action"));
		parameters.remove("action");
		// api key
		SOAPElement soapBodyKey = soapBodyAction.addChildElement("key");
		soapBodyKey.addTextNode(secretKey);

		Set<Entry<String, String>> ets = parameters.entrySet();
		Iterator<Entry<String, String>> it = ets.iterator();
		while (it.hasNext()) {
			Entry<String, String> param = it.next();
			SOAPElement soapBodyElement = soapBodyAction.addChildElement(param.getKey());
			soapBodyElement.addTextNode(param.getValue());
		}
		
		URL endpoint = new URL(null, apiURL, new URLStreamHandler() {
			@Override
			protected URLConnection openConnection(URL url) throws IOException {
				URL target = new URL(url.toString());
				URLConnection connection = target.openConnection();
				// Connection settings
				connection.setConnectTimeout(timeout);
				connection.setReadTimeout(timeout);
				return(connection);
			}
		});
		
		SOAPMessage soapResponse = soapConnection.call(soapMessage, endpoint);

		// loading the XML document
		ByteArrayOutputStream out = new ByteArrayOutputStream();
		soapResponse.writeTo(out);
		DocumentBuilderFactory builderfactory = DocumentBuilderFactory.newInstance();
		builderfactory.setNamespaceAware(true);

		DocumentBuilder builder = builderfactory.newDocumentBuilder();
		xmlDocument = builder.parse(new InputSource(new StringReader(out.toString())));
		soapConnection.close();

	} catch (UnsupportedOperationException | SOAPException | IOException | ParserConfigurationException | SAXException e) {
		log.error(e.getLocalizedMessage(), e);
	}
	return xmlDocument;

}
 
Example 13
Source File: SignCode.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
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(StringUtils.join(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 signing request to server and waiting for response");
    SOAPMessage response = connection.call(message, SIGNING_SERVICE_URL);

    if (debug) {
        ByteArrayOutputStream baos = new ByteArrayOutputStream(2 * 1024);
        response.writeTo(baos);
        log(baos.toString("UTF-8"));
    }

    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;
}
 
Example 14
Source File: AbstractTypeTestClient3.java    From cxf with Apache License 2.0 4 votes vote down vote up
@Test
public void testStructWithAnyArray() throws Exception {
    if (!shouldRunTest("StructWithAnyArray")) {
        return;
    }
    StructWithAnyArray swa = new StructWithAnyArray();
    swa.setName("Name");
    swa.setAddress("Some Address");

    StructWithAnyArray yOrig = new StructWithAnyArray();
    yOrig.setName("Name2");
    yOrig.setAddress("Some Other Address");

    SOAPFactory factory = SOAPFactory.newInstance();
    SOAPElement x = factory.createElement("hello", "foo", "http://some.url.com");
    x.addNamespaceDeclaration("foo", "http://some.url.com");
    x.addTextNode("This is the text of the node");

    SOAPElement x2 = factory.createElement("hello2", "foo", "http://some.url.com");
    x2.addNamespaceDeclaration("foo", "http://some.url.com");
    x2.addTextNode("This is the text of the node for the second struct");

    swa.getAny().add(x);
    yOrig.getAny().add(x2);

    Holder<StructWithAnyArray> y = new Holder<>(yOrig);
    Holder<StructWithAnyArray> z = new Holder<>();

    StructWithAnyArray ret;
    if (testDocLiteral) {
        ret = docClient.testStructWithAnyArray(swa, y, z);
    } else if (testXMLBinding) {
        ret = xmlClient.testStructWithAnyArray(swa, y, z);
    } else {
        ret = rpcClient.testStructWithAnyArray(swa, y, z);
    }
    if (!perfTestOnly) {
        assertEqualsStructWithAnyArray(swa, y.value);
        assertEqualsStructWithAnyArray(yOrig, z.value);
        assertEqualsStructWithAnyArray(swa, ret);
    }
}
 
Example 15
Source File: SignCodeMojo.java    From sling-whiteboard with Apache License 2.0 4 votes vote down vote up
private void downloadSignedFiles(SignedFiles signedFiles, String id)
        throws SOAPException, IOException, BuildException {

    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);
    }

    signedFiles.extractFilesFromApplicationString(data);
}
 
Example 16
Source File: SignCodeMojo.java    From sling-whiteboard with Apache License 2.0 4 votes vote down vote up
private String makeSigningRequest(SignedFiles signedFiles) throws SOAPException, IOException, MojoExecutionException {
    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);

    SOAPElement commaDelimitedFileNames =
            requestSigningRequest.addChildElement("commaDelimitedFileNames", NS);
    commaDelimitedFileNames.addTextNode(signedFiles.getCommaSeparatedUploadFileNames());

    SOAPElement application =
            requestSigningRequest.addChildElement("application", NS);
    application.addTextNode(signedFiles.getApplicationString());

    // Send the message
    SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
    SOAPConnection connection = soapConnectionFactory.createConnection();

    log("Sending signing request to server and waiting for response");
    SOAPMessage response = connection.call(message, SIGNING_SERVICE_URL);

    if ( getLog().isDebugEnabled()) {
        ByteArrayOutputStream baos = new ByteArrayOutputStream(2 * 1024);
        response.writeTo(baos);
        getLog().debug(baos.toString("UTF-8"));
    }

    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;
    StringBuilder errors = new StringBuilder();

    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();
        } else if (returnNode.getLocalName().equals("result") ) {
            final NodeList returnChildNodes = returnNode.getChildNodes();
            for (int j = 0; j < returnChildNodes.getLength(); j++ ) {
                if ( returnChildNodes.item(j).getLocalName().equals("errors") ) {
                    extractErrors(returnChildNodes.item(j), errors);
                }
            }
        }
    }

    if (!signingService.contains("TEST") && !"SIGNED".equals(signingSetStatus) ||
            signingService.contains("TEST") && !"INITIALIZED".equals(signingSetStatus) ) {
        throw new BuildException("Signing failed. Status was: " + signingSetStatus + " . Reported errors: " + errors + ".");
    }

    return signingSetID;
}
 
Example 17
Source File: AbstractTypeTestClient5.java    From cxf with Apache License 2.0 4 votes vote down vote up
@Test
public void testStructWithAnyArrayLax() throws Exception {
    if (!shouldRunTest("StructWithAnyArrayLax")) {
        return;
    }
    SOAPFactory factory = SOAPFactory.newInstance();
    SOAPElement elem = factory.createElement("StringElementQualified",
        "x1", "http://apache.org/type_test/types1");
    elem.addNamespaceDeclaration("x1", "http://apache.org/type_test/types1");
    elem.addTextNode("This is the text of the node");

    StructWithAnyArrayLax x = new StructWithAnyArrayLax();
    x.setName("Name x");
    x.setAddress("Some Address x");
    x.getAny().add(elem);

    elem = factory.createElement("StringElementQualified", "x1",
        "http://apache.org/type_test/types1");
    elem.addNamespaceDeclaration("x1", "http://apache.org/type_test/types1");
    elem.addTextNode("This is the text of the node for the second struct");

    StructWithAnyArrayLax yOrig = new StructWithAnyArrayLax();
    yOrig.setName("Name y");
    yOrig.setAddress("Some Other Address y");
    yOrig.getAny().add(elem);

    Holder<StructWithAnyArrayLax> y = new Holder<>(yOrig);
    Holder<StructWithAnyArrayLax> z = new Holder<>();
    StructWithAnyArrayLax ret;
    if (testDocLiteral) {
        ret = docClient.testStructWithAnyArrayLax(x, y, z);
    } else if (testXMLBinding) {
        ret = xmlClient.testStructWithAnyArrayLax(x, y, z);
    } else {
        ret = rpcClient.testStructWithAnyArrayLax(x, y, z);
    }
    if (!perfTestOnly) {
        assertEqualsStructWithAnyArrayLax(x, y.value);
        assertEqualsStructWithAnyArrayLax(yOrig, z.value);
        assertEqualsStructWithAnyArrayLax(x, ret);
    }
}
 
Example 18
Source File: AbstractTypeTestClient5.java    From cxf with Apache License 2.0 4 votes vote down vote up
@Test
public void testStructWithAnyStrictComplex() throws Exception {
    if (!shouldRunTest("StructWithAnyStrictComplex")) {
        return;
    }
    SOAPFactory factory = SOAPFactory.newInstance();
    SOAPElement elem = factory.createElement("AnonTypeElementQualified",
        "x1", "http://apache.org/type_test/types1");
    elem.addNamespaceDeclaration("x1", "http://apache.org/type_test/types1");
    SOAPElement floatElem = factory.createElement("varFloat", "x1",
        "http://apache.org/type_test/types1");
    floatElem.addTextNode("12.5");
    elem.addChildElement(floatElem);
    SOAPElement intElem = factory.createElement("varInt", "x1",
        "http://apache.org/type_test/types1");
    intElem.addTextNode("34");
    elem.addChildElement(intElem);
    SOAPElement stringElem = factory.createElement("varString", "x1",
        "http://apache.org/type_test/types1");
    stringElem.addTextNode("test string within any");
    elem.addChildElement(stringElem);

    StructWithAnyStrict x = new StructWithAnyStrict();
    x.setName("Name x");
    x.setAddress("Some Address x");
    x.setAny(elem);

    elem = factory.createElement("AnonTypeElementQualified", "x1",
        "http://apache.org/type_test/types1");
    elem.addNamespaceDeclaration("x1", "http://apache.org/type_test/types1");
    floatElem = factory.createElement("varFloat", "x1",
        "http://apache.org/type_test/types1");
    floatElem.addTextNode("12.76");
    elem.addChildElement(floatElem);
    intElem = factory.createElement("varInt", "x1",
        "http://apache.org/type_test/types1");
    intElem.addTextNode("56");
    elem.addChildElement(intElem);
    stringElem = factory.createElement("varString", "x1",
        "http://apache.org/type_test/types1");
    stringElem.addTextNode("test string");
    elem.addChildElement(stringElem);

    StructWithAnyStrict yOrig = new StructWithAnyStrict();
    yOrig.setName("Name y");
    yOrig.setAddress("Some Address y");
    yOrig.setAny(elem);

    Holder<StructWithAnyStrict> y = new Holder<>(yOrig);
    Holder<StructWithAnyStrict> z = new Holder<>();
    StructWithAnyStrict ret;
    if (testDocLiteral) {
        ret = docClient.testStructWithAnyStrict(x, y, z);
    } else if (testXMLBinding) {
        ret = xmlClient.testStructWithAnyStrict(x, y, z);
    } else {
        ret = rpcClient.testStructWithAnyStrict(x, y, z);
    }
    if (!perfTestOnly) {
        assertEqualsStructWithAnyStrict(x, y.value);
        assertEqualsStructWithAnyStrict(yOrig, z.value);
        assertEqualsStructWithAnyStrict(x, ret);
    }
}
 
Example 19
Source File: Fault1_2Impl.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected void finallySetFaultCode(String faultcode) throws SOAPException {
    SOAPElement value = this.faultCodeElement.addChildElement(valueName);
    value.addTextNode(faultcode);
}
 
Example 20
Source File: SignCode.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
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);
}