Example usage for javax.xml.soap SOAPElement addChildElement

List of usage examples for javax.xml.soap SOAPElement addChildElement

Introduction

In this page you can find the example usage for javax.xml.soap SOAPElement addChildElement.

Prototype

public SOAPElement addChildElement(SOAPElement element) throws SOAPException;

Source Link

Document

Add a SOAPElement as a child of this SOAPElement instance.

Usage

From source file:com.hiperium.commons.client.soap.AthenticationDispatcherTest.java

/**
 * //from   ww  w  .  j ava2s .  c o m
 * @return
 */
public static SOAPMessage createSelectHomeSOAPMessage(HomeSelectionDTO dto) {
    SOAPMessage soapMessage = null;
    try {
        soapMessage = MessageFactory.newInstance().createMessage();
        SOAPPart soapPart = soapMessage.getSOAPPart();
        SOAPEnvelope soapEnvelope = soapPart.getEnvelope();

        // Add message body parameters
        SOAPBody soapBody = soapEnvelope.getBody();
        SOAPElement method = soapBody.addChildElement("selectHome", "ns2",
                "https://sei.authentication.soap.web.hiperium.com/");
        SOAPElement argument = method.addChildElement("arg0");
        argument.addChildElement("homeId").addTextNode(dto.getHomeId().toString());
        argument.addChildElement("profileId").addTextNode(dto.getProfileId().toString());

        // Check the input
        System.out.println("REQUEST:");
        soapMessage.writeTo(System.out);
        System.out.println();

    } catch (SOAPException e) {
        LOGGER.error(e.getMessage(), e);
    } catch (IOException e) {
        LOGGER.error(e.getMessage(), e);
    }
    return soapMessage;
}

From source file:com.hiperium.commons.client.soap.AthenticationDispatcherTest.java

/**
 * /*from  w w  w  .j a  v a2 s.c  o m*/
 * @return
 */
public static SOAPMessage createAuthSOAPMessage(UserCredentialDTO dto) {
    SOAPMessage soapMessage = null;
    try {
        soapMessage = MessageFactory.newInstance().createMessage();
        SOAPPart soapPart = soapMessage.getSOAPPart();
        SOAPEnvelope soapEnvelope = soapPart.getEnvelope();

        // Add message body parameters
        SOAPBody soapBody = soapEnvelope.getBody();
        SOAPElement method = soapBody.addChildElement("userAuthentication", "ns2",
                "https://sei.authentication.soap.web.hiperium.com/");
        SOAPElement argument = method.addChildElement("arg0");
        argument.addChildElement("email").addTextNode(dto.getEmail());
        argument.addChildElement("password").addTextNode(dto.getPassword());

        // Check the input
        System.out.println("REQUEST:");
        soapMessage.writeTo(System.out);
        System.out.println();

    } catch (SOAPException e) {
        LOGGER.error(e.getMessage(), e);
    } catch (IOException e) {
        LOGGER.error(e.getMessage(), e);
    }
    return soapMessage;
}

From source file:org.jasig.portlet.blackboardvcportlet.service.util.SASWebServiceTemplate.java

@Override
public Object marshalSendAndReceiveToSAS(final String soapAction, final Object requestPayload) {
    return marshalSendAndReceive(requestPayload, new WebServiceMessageCallback() {

        @Override// ww w . j ava2  s . c  o m
        public void doWithMessage(WebServiceMessage webServiceMessage)
                throws IOException, TransformerException {
            if (webServiceMessage instanceof SaajSoapMessage) {
                final SaajSoapMessage casted = (SaajSoapMessage) webServiceMessage;
                casted.setSoapAction(soapAction);

                QName qName = new QName(elluminateMarshller.getContextPath(), "BasicAuth", "sas");
                try {
                    SOAPElement baHeader = casted.getSaajMessage().getSOAPHeader().addChildElement(qName);
                    baHeader.addChildElement(new QName("sas", "Name")).addTextNode(username);
                    baHeader.addChildElement(new QName("sas", "Password")).addTextNode(password);
                } catch (Exception e) {
                    logger.error("Error creating SOAPHeader: ", e);
                }
            }
        }
    });
}

From source file:net.bpelunit.framework.control.deploy.activebpel.BPRDeployRequestEntity.java

@Override
protected void populateMessage(SOAPMessage message) throws SOAPException, IOException {
    SOAPElement xmlDeployBpr = addRootElement(message, new QName(ACTIVEBPEL_ELEMENT_DEPLOYBPR));

    // Add filename
    SOAPElement xmlBprFilename = xmlDeployBpr.addChildElement(ACTIVEBPEL_ELEMENT_ABPRFILENAME);
    xmlBprFilename.addAttribute(new QName(ActiveBPELRequestEntityBase.NS_XMLSCHEMA_INSTANCE, "type"),
            XSD_STRING);//from  ww  w . j  a v  a  2  s  . c om
    xmlBprFilename.setTextContent(FilenameUtils.getName(file.toString()));

    // Add data
    SOAPElement xmlBase64File = xmlDeployBpr.addChildElement(ACTIVEBPEL_ELEMENT_ABASE64FILE);
    xmlBase64File.addAttribute(new QName(ActiveBPELRequestEntityBase.NS_XMLSCHEMA_INSTANCE, "type"),
            XSD_STRING);

    StringBuilder content = new StringBuilder();
    byte[] arr = FileUtils.readFileToByteArray(file);
    byte[] encoded = Base64.encodeBase64Chunked(arr);
    for (int i = 0; i < encoded.length; i++) {
        content.append((char) encoded[i]);
    }
    xmlBase64File.setTextContent(content.toString());
}

From source file:net.bpelunit.framework.control.deploy.ode.ODERequestEntityFactory.java

private void prepareUndeploySOAP(String packageId) throws SOAPException, IOException {
    MessageFactory mFactory = MessageFactory.newInstance();
    SOAPMessage message = mFactory.createMessage();
    SOAPBody body = message.getSOAPBody();

    SOAPElement xmlUndeploy = body.addChildElement(ODE_ELEMENT_UNDEPLOY);
    SOAPElement xmlPackageName = xmlUndeploy.addChildElement(ODE_ELEMENT_PACKAGENAME);
    xmlPackageName.setTextContent(packageId);

    ByteArrayOutputStream b = new ByteArrayOutputStream();
    message.writeTo(b);//from   w w w.j  a va  2s. c  o m
    fContent = b.toString();
}

From source file:net.bpelunit.framework.control.deploy.ode.ODERequestEntityFactory.java

private void prepareDeploySOAP(File file) throws IOException, SOAPException {
    MessageFactory mFactory = MessageFactory.newInstance();
    SOAPMessage message = mFactory.createMessage();
    SOAPBody body = message.getSOAPBody();

    SOAPElement xmlDeploy = body.addChildElement(ODE_ELEMENT_DEPLOY);
    SOAPElement xmlZipFilename = xmlDeploy.addChildElement(ODE_ELEMENT_ZIPNAME);
    xmlZipFilename.setTextContent(FilenameUtils.getName(file.toString()).split("\\.")[0]);

    SOAPElement xmlZipContent = xmlDeploy.addChildElement(ODE_ELEMENT_PACKAGE);
    SOAPElement xmlBase64ZipFile = xmlZipContent.addChildElement(ODE_ELEMENT_ZIP, "dep", NS_DEPLOY_SERVICE);

    xmlBase64ZipFile.addAttribute(new QName(NS_XML_MIME, CONTENT_TYPE_STRING), ZIP_CONTENT_TYPE);

    StringBuilder content = new StringBuilder();
    byte[] arr = FileUtils.readFileToByteArray(file);
    byte[] encoded = Base64.encodeBase64Chunked(arr);
    for (int i = 0; i < encoded.length; i++) {
        content.append((char) encoded[i]);
    }/*w w w.  j av  a 2 s. c  o m*/

    xmlBase64ZipFile.setTextContent(content.toString());

    ByteArrayOutputStream b = new ByteArrayOutputStream();
    message.writeTo(b);
    fContent = b.toString();
}

From source file:whitelabel.cloud.wsclient.WebServiceAuthenticator.java

public void authenticateInClear(final SOAPMessage request, final String username, final String password)
        throws WsAuthenticationException {

    if (request == null) {
        LOG.error(" SoapMessage request not defined");
        throw new WsAuthenticationException("SOAP_REQUEST_NOT_DEFINED");
    }/*w  ww. ja va  2  s  .  c o  m*/
    if (username == null || password == null || username.trim().length() == 0
            || password.trim().length() == 0) {
        LOG.error("Username: " + username + " password: " + password + " - invalid parameters");
        throw new WsAuthenticationException("INVALID_PARAMETERS");
    }

    String nonceValue = generateNonceBase64(16);
    String createdValue = dfe.print(new Date());
    String userValue = username;
    String pwdValue = password;
    String pwdType = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText";

    QName securityQName = new QName(
            "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", "Security",
            "wsse");
    QName usernameTokenQName = new QName(
            "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd",
            "UsernameToken", "wsse");
    QName usernameQName = new QName(
            "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", "Username",
            "wsse");
    QName PasswordQName = new QName(
            "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", "Password",
            "wsse");
    QName PasswordTypeQName = new QName("Type");
    QName nonceQName = new QName(
            "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", "Nonce",
            "wsse");
    QName createdQName = new QName(
            "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd", "Created",
            "wsu");

    try {
        SOAPElement securitySoap = request.getSOAPHeader().addChildElement(securityQName);
        SOAPElement usernameTokenSoap = securitySoap.addChildElement(usernameTokenQName);
        SOAPElement usernameSoap = usernameTokenSoap.addChildElement(usernameQName);
        usernameSoap.addTextNode(userValue);
        SOAPElement passwordSoap = usernameTokenSoap.addChildElement(PasswordQName);
        passwordSoap.addTextNode(pwdValue);
        passwordSoap.addAttribute(PasswordTypeQName, pwdType);
        SOAPElement nonceSoap = usernameTokenSoap.addChildElement(nonceQName);
        nonceSoap.addTextNode(nonceValue);
        SOAPElement creadedSoap = usernameTokenSoap.addChildElement(createdQName);
        creadedSoap.addTextNode(createdValue);
    } catch (SOAPException se) {
        LOG.error(se);
        throw new WsAuthenticationException("SOAPHEADER_CREATION", se);
    }
}

From source file:whitelabel.cloud.wsclient.WebServiceAuthenticator.java

public void authenticateWithDigest(final SOAPMessage request, final String username, final String password)
        throws WsAuthenticationException {

    if (request == null) {
        LOG.error(" SoapMessage request not defined");
        throw new WsAuthenticationException("SOAP_REQUEST_NOT_DEFINED");
    }/*w  w  w. j a  v a 2  s.  c om*/
    if (username == null || password == null || username.trim().length() == 0
            || password.trim().length() == 0) {
        LOG.error("Username: " + username + " password: " + password + " - invalid parameters");
        throw new WsAuthenticationException("INVALID_PARAMETERS");
    }

    String nonceValue = generateNonceBase64(16);
    String createdValue = dfe.print(new Date());
    String userValue = username;
    String pwdValue = crypthPassword(nonceValue, createdValue, password);

    String pwdType = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest";

    QName securityQName = new QName(
            "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", "Security",
            "wsse");
    QName usernameTokenQName = new QName(
            "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd",
            "UsernameToken", "wsse");
    QName usernameQName = new QName(
            "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", "Username",
            "wsse");
    QName PasswordQName = new QName(
            "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", "Password",
            "wsse");
    QName PasswordTypeQName = new QName("Type");
    QName nonceQName = new QName(
            "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", "Nonce",
            "wsse");
    QName createdQName = new QName(
            "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd", "Created",
            "wsu");

    SOAPElement securitySoap;
    try {
        securitySoap = request.getSOAPHeader().addChildElement(securityQName);
        SOAPElement usernameTokenSoap = securitySoap.addChildElement(usernameTokenQName);
        SOAPElement usernameSoap = usernameTokenSoap.addChildElement(usernameQName);
        usernameSoap.addTextNode(userValue);
        SOAPElement passwordSoap = usernameTokenSoap.addChildElement(PasswordQName);
        passwordSoap.addTextNode(pwdValue);
        passwordSoap.addAttribute(PasswordTypeQName, pwdType);
        SOAPElement nonceSoap = usernameTokenSoap.addChildElement(nonceQName);
        nonceSoap.addTextNode(nonceValue);
        SOAPElement creadedSoap = usernameTokenSoap.addChildElement(createdQName);
        creadedSoap.addTextNode(createdValue);
    } catch (SOAPException se) {
        LOG.error(se);
        throw new WsAuthenticationException("SOAPHEADER_CREATION", se);
    }
}

From source file:backend.Weather.java

private SOAPMessage createSOAPRequest() throws Exception {
    MessageFactory messageFactory = MessageFactory.newInstance();
    SOAPMessage soapMessage = messageFactory.createMessage();
    SOAPPart soapPart = soapMessage.getSOAPPart();
    String serverURI = "http://ws.cdyne.com/";
    SOAPEnvelope envelope = soapPart.getEnvelope();

    SOAPBody soapBody = envelope.getBody();
    SOAPElement soapBodyElem = soapBody.addChildElement("GetCityWeatherByZIP");
    QName attributeName = new QName("xmlns");
    soapBodyElem.addAttribute(attributeName, "http://ws.cdyne.com/WeatherWS/");
    SOAPElement soapBodyElem1 = soapBodyElem.addChildElement("ZIP");
    soapBodyElem1.addTextNode("02215");
    soapMessage.saveChanges();/*from   w  ww  . j a  v  a2 s.c  om*/
    return soapMessage;

}

From source file:com.fortify.bugtracker.tgt.archer.connection.ArcherAuthenticatingRestConnection.java

public Long addValueToValuesList(Long valueListId, String value) {
    LOG.info("[Archer] Adding value '" + value + "' to value list id " + valueListId);
    // Adding items to value lists is not supported via REST API, so we need to revert to SOAP API
    // TODO Simplify this method?
    // TODO Make this method more fail-safe (like checking for the correct response element)?
    Long result = null;/*from  w  w  w  .  j  av a2 s.  c om*/
    try {
        MessageFactory messageFactory = MessageFactory.newInstance();
        SOAPMessage message = messageFactory.createMessage();
        SOAPPart soapPart = message.getSOAPPart();
        SOAPEnvelope envelope = soapPart.getEnvelope();
        SOAPBody body = envelope.getBody();
        SOAPElement bodyElement = body.addChildElement(
                envelope.createName("CreateValuesListValue", "", "http://archer-tech.com/webservices/"));
        bodyElement.addChildElement("sessionToken").addTextNode(tokenProviderRest.getToken());
        bodyElement.addChildElement("valuesListId").addTextNode(valueListId + "");
        bodyElement.addChildElement("valuesListValueName").addTextNode(value);
        message.saveChanges();

        SOAPMessage response = executeRequest(HttpMethod.POST,
                getBaseResource().path("/ws/field.asmx").request()
                        .header("SOAPAction", "\"http://archer-tech.com/webservices/CreateValuesListValue\"")
                        .accept("text/xml"),
                Entity.entity(message, "text/xml"), SOAPMessage.class);
        @SuppressWarnings("unchecked")
        Iterator<Object> it = response.getSOAPBody().getChildElements();
        while (it.hasNext()) {
            Object o = it.next();
            if (o instanceof SOAPElement) {
                result = new Long(((SOAPElement) o).getTextContent());
            }
        }
        System.out.println(response);
    } catch (SOAPException e) {
        throw new RuntimeException("Error executing SOAP request", e);
    }
    return result;
}