Example usage for javax.xml.soap MessageFactory createMessage

List of usage examples for javax.xml.soap MessageFactory createMessage

Introduction

In this page you can find the example usage for javax.xml.soap MessageFactory createMessage.

Prototype

public abstract SOAPMessage createMessage() throws SOAPException;

Source Link

Document

Creates a new SOAPMessage object with the default SOAPPart , SOAPEnvelope , SOAPBody , and SOAPHeader objects.

Usage

From source file:org.sakaiproject.contentreview.compilatio.util.CompilatioAPIUtil.java

public static Document callCompilatioReturnDocument(String apiURL, Map<String, String> parameters,
        String secretKey, final int timeout, Proxy proxy, boolean isMultipart)
        throws TransientSubmissionException, SubmissionException {

    SOAPConnectionFactory soapConnectionFactory;
    Document xmlDocument = null;/*from   www  . j  av a 2s. co m*/
    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);
    }
    return xmlDocument;

}

From source file:org.springframework.ws.server.endpoint.mapping.PayloadRootAnnotationMethodEndpointMappingTest.java

@Test
public void invoke() throws Exception {

    MessageFactory messageFactory = MessageFactory.newInstance();
    SOAPMessage request = messageFactory.createMessage();
    request.getSOAPBody().addBodyElement(QName.valueOf("{http://springframework.org/spring-ws}Request"));
    MessageContext messageContext = new DefaultMessageContext(new SaajSoapMessage(request),
            new SaajSoapMessageFactory(messageFactory));
    DefaultMethodEndpointAdapter adapter = new DefaultMethodEndpointAdapter();
    adapter.afterPropertiesSet();//from   w ww. j  a v  a2s . c o m

    MessageDispatcher messageDispatcher = new SoapMessageDispatcher();
    messageDispatcher.setApplicationContext(applicationContext);
    messageDispatcher.setEndpointMappings(Collections.<EndpointMapping>singletonList(mapping));
    messageDispatcher.setEndpointAdapters(Collections.<EndpointAdapter>singletonList(adapter));

    messageDispatcher.receive(messageContext);

    MyEndpoint endpoint = applicationContext.getBean("endpoint", MyEndpoint.class);
    assertTrue("doIt() not invoked on endpoint", endpoint.isDoItInvoked());

    LogAspect aspect = (LogAspect) applicationContext.getBean("logAspect");
    assertTrue("log() not invoked on aspect", aspect.isLogInvoked());
}

From source file:org.springframework.ws.soap.saaj.support.SaajUtils.java

/**
 * Checks whether we can find a SAAJ 1.2 implementation, being aware of the broken WebLogic 9 SAAJ implementation.
 * <p/>//from   ww w.  ja va 2s  .  co m
 * WebLogic 9 does implement SAAJ 1.2, but throws UnsupportedOperationExceptions when a SAAJ 1.2 method is called.
 */
private static boolean isSaaj12() {
    if (Element.class.isAssignableFrom(SOAPElement.class)) {
        // see if we are dealing with WebLogic 9
        try {
            MessageFactory messageFactory = MessageFactory.newInstance();
            SOAPMessage message = messageFactory.createMessage();
            try {
                message.getSOAPBody();
                return true;
            } catch (UnsupportedOperationException ex) {
                return false;
            }
        } catch (SOAPException e) {
            return false;
        }
    } else {
        return false;
    }
}

From source file:org.springframework.ws.transport.http.CommonsHttpMessageSenderIntegrationTest.java

@Test
public void testContextClose() throws Exception {
    MessageFactory messageFactory = MessageFactory.newInstance();
    int port = FreePortScanner.getFreePort();
    Server jettyServer = new Server(port);
    Context jettyContext = new Context(jettyServer, "/");
    jettyContext.addServlet(new ServletHolder(new EchoServlet()), "/");
    jettyServer.start();//from  w  w  w.j ava 2  s .c o  m
    WebServiceConnection connection = null;
    try {

        StaticApplicationContext appContext = new StaticApplicationContext();
        appContext.registerSingleton("messageSender", CommonsHttpMessageSender.class);
        appContext.refresh();

        CommonsHttpMessageSender messageSender = appContext.getBean("messageSender",
                CommonsHttpMessageSender.class);
        connection = messageSender.createConnection(new URI("http://localhost:" + port));

        appContext.close();

        connection.send(new SaajSoapMessage(messageFactory.createMessage()));
        connection.receive(new SaajSoapMessageFactory(messageFactory));
    } finally {
        if (connection != null) {
            try {
                connection.close();
            } catch (IOException ex) {
                // ignore
            }
        }
        if (jettyServer.isRunning()) {
            jettyServer.stop();
        }
    }

}

From source file:org.wso2.carbon.identity.provisioning.connector.InweboUserManager.java

private static SOAPMessage createUserSOAPMessage(Properties inweboProperties, InweboUser user)
        throws SOAPException {
    MessageFactory messageFactory = MessageFactory.newInstance();
    SOAPMessage soapMessage = messageFactory.createMessage();
    SOAPPart soapPart = soapMessage.getSOAPPart();
    String serverURI = inweboProperties.getProperty(InweboConnectorConstants.INWEBO_URI);
    SOAPEnvelope envelope = soapPart.getEnvelope();
    String namespacePrefix = InweboConnectorConstants.SOAPMessage.SOAP_NAMESPACE_PREFIX;
    envelope.addNamespaceDeclaration(namespacePrefix, serverURI);
    SOAPBody soapBody = envelope.getBody();
    SOAPElement soapBodyElem = soapBody
            .addChildElement(InweboConnectorConstants.SOAPMessage.SOAP_ACTION_LOGIN_CREATE, namespacePrefix);
    SOAPElement soapBodyElem1 = soapBodyElem.addChildElement(InweboConnectorConstants.SOAPMessage.SOAP_USER_ID,
            namespacePrefix);//from   w w w .  j  a  va2s . c  o  m
    soapBodyElem1.addTextNode(user.getUserId());
    SOAPElement soapBodyElem2 = soapBodyElem
            .addChildElement(InweboConnectorConstants.SOAPMessage.SOAP_SERVICE_ID, namespacePrefix);
    soapBodyElem2.addTextNode(user.getServiceId());
    SOAPElement soapBodyElem3 = soapBodyElem.addChildElement(InweboConnectorConstants.SOAPMessage.SOAP_LOGIN,
            namespacePrefix);
    soapBodyElem3.addTextNode(user.getLogin());
    SOAPElement soapBodyElem4 = soapBodyElem
            .addChildElement(InweboConnectorConstants.SOAPMessage.SOAP_FIRST_NAME, namespacePrefix);
    soapBodyElem4.addTextNode(user.getFirstName());
    SOAPElement soapBodyElem5 = soapBodyElem.addChildElement(InweboConnectorConstants.SOAPMessage.SOAP_NAME,
            namespacePrefix);
    soapBodyElem5.addTextNode(user.getLastName());
    SOAPElement soapBodyElem6 = soapBodyElem.addChildElement(InweboConnectorConstants.SOAPMessage.SOAP_MAIL,
            namespacePrefix);
    soapBodyElem6.addTextNode(user.getMail());
    SOAPElement soapBodyElem7 = soapBodyElem.addChildElement(InweboConnectorConstants.SOAPMessage.SOAP_PHONE,
            namespacePrefix);
    soapBodyElem7.addTextNode(user.getPhone());
    SOAPElement soapBodyElem8 = soapBodyElem.addChildElement(InweboConnectorConstants.SOAPMessage.SOAP_STATUS,
            namespacePrefix);
    soapBodyElem8.addTextNode(user.getStatus());
    SOAPElement soapBodyElem9 = soapBodyElem.addChildElement(InweboConnectorConstants.SOAPMessage.SOAP_ROLE,
            namespacePrefix);
    soapBodyElem9.addTextNode(user.getRole());
    SOAPElement soapBodyElem10 = soapBodyElem.addChildElement(InweboConnectorConstants.SOAPMessage.SOAP_ACCESS,
            namespacePrefix);
    soapBodyElem10.addTextNode(user.getAccess());
    SOAPElement soapBodyElem11 = soapBodyElem
            .addChildElement(InweboConnectorConstants.SOAPMessage.SOAP_CONTENT_TYPE, namespacePrefix);
    soapBodyElem11.addTextNode(user.getCodeType());
    SOAPElement soapBodyElem12 = soapBodyElem.addChildElement(InweboConnectorConstants.SOAPMessage.SOAP_LANG,
            namespacePrefix);
    soapBodyElem12.addTextNode(user.getLanguage());
    SOAPElement soapBodyElem13 = soapBodyElem
            .addChildElement(InweboConnectorConstants.SOAPMessage.SOAP_EXTRA_FIELDS, namespacePrefix);
    soapBodyElem13.addTextNode(user.getExtraFields());
    MimeHeaders headers = soapMessage.getMimeHeaders();
    headers.addHeader(InweboConnectorConstants.SOAPMessage.SOAP_ACTION,
            serverURI + InweboConnectorConstants.SOAPMessage.SOAP_ACTION_HEADER);
    soapMessage.saveChanges();
    return soapMessage;
}

From source file:org.wso2.carbon.identity.provisioning.connector.InweboUserManager.java

private static SOAPMessage updateUserSOAPMessage(Properties inweboProperties, InweboUser user)
        throws SOAPException {
    MessageFactory messageFactory = MessageFactory.newInstance();
    SOAPMessage soapMessage = messageFactory.createMessage();
    SOAPPart soapPart = soapMessage.getSOAPPart();
    String serverURI = inweboProperties.getProperty(InweboConnectorConstants.INWEBO_URI);
    SOAPEnvelope envelope = soapPart.getEnvelope();
    String namespacePrefix = InweboConnectorConstants.SOAPMessage.SOAP_NAMESPACE_PREFIX;
    envelope.addNamespaceDeclaration(namespacePrefix, serverURI);
    SOAPBody soapBody = envelope.getBody();
    SOAPElement soapBodyElem = soapBody
            .addChildElement(InweboConnectorConstants.SOAPMessage.SOAP_ACTION_LOGIN_UPDATE, namespacePrefix);
    SOAPElement soapBodyElem1 = soapBodyElem.addChildElement(InweboConnectorConstants.SOAPMessage.SOAP_USER_ID,
            namespacePrefix);//from ww  w.j a v  a2s. co m
    soapBodyElem1.addTextNode(user.getUserId());
    SOAPElement soapBodyElem2 = soapBodyElem
            .addChildElement(InweboConnectorConstants.SOAPMessage.SOAP_SERVICE_ID, namespacePrefix);
    soapBodyElem2.addTextNode(user.getServiceId());
    SOAPElement soapBodyElem3 = soapBodyElem.addChildElement(InweboConnectorConstants.SOAPMessage.SOAP_LOGIN_ID,
            namespacePrefix);
    soapBodyElem3.addTextNode(user.getLoginId());
    SOAPElement soapBodyElem4 = soapBodyElem.addChildElement(InweboConnectorConstants.SOAPMessage.SOAP_LOGIN,
            namespacePrefix);
    soapBodyElem4.addTextNode(user.getLogin());
    SOAPElement soapBodyElem5 = soapBodyElem
            .addChildElement(InweboConnectorConstants.SOAPMessage.SOAP_FIRST_NAME, namespacePrefix);
    soapBodyElem5.addTextNode(user.getFirstName());
    SOAPElement soapBodyElem6 = soapBodyElem.addChildElement(InweboConnectorConstants.SOAPMessage.SOAP_NAME,
            namespacePrefix);
    soapBodyElem6.addTextNode(user.getLastName());
    SOAPElement soapBodyElem7 = soapBodyElem.addChildElement(InweboConnectorConstants.SOAPMessage.SOAP_MAIL,
            namespacePrefix);
    soapBodyElem7.addTextNode(user.getMail());
    SOAPElement soapBodyElem8 = soapBodyElem.addChildElement(InweboConnectorConstants.SOAPMessage.SOAP_PHONE,
            namespacePrefix);
    soapBodyElem8.addTextNode(user.getPhone());
    SOAPElement soapBodyElem9 = soapBodyElem.addChildElement(InweboConnectorConstants.SOAPMessage.SOAP_STATUS,
            namespacePrefix);
    soapBodyElem9.addTextNode(user.getStatus());
    SOAPElement soapBodyElem10 = soapBodyElem.addChildElement(InweboConnectorConstants.SOAPMessage.SOAP_ROLE,
            namespacePrefix);
    soapBodyElem10.addTextNode(user.getRole());
    SOAPElement soapBodyElem11 = soapBodyElem
            .addChildElement(InweboConnectorConstants.SOAPMessage.SOAP_EXTRA_FIELDS, namespacePrefix);
    soapBodyElem11.addTextNode(user.getExtraFields());
    MimeHeaders headers = soapMessage.getMimeHeaders();
    headers.addHeader(InweboConnectorConstants.SOAPMessage.SOAP_ACTION,
            serverURI + InweboConnectorConstants.SOAPMessage.SOAP_ACTION_HEADER);
    soapMessage.saveChanges();
    return soapMessage;
}

From source file:org.wso2.carbon.identity.provisioning.connector.InweboUserManager.java

private static SOAPMessage deleteUserSOAPMessage(Properties inweboProperties, String loginId, String userId,
        String serviceId) throws SOAPException {

    MessageFactory messageFactory = MessageFactory.newInstance();
    SOAPMessage soapMessage = messageFactory.createMessage();
    SOAPPart soapPart = soapMessage.getSOAPPart();
    String serverURI = inweboProperties.getProperty(InweboConnectorConstants.INWEBO_URI);
    SOAPEnvelope envelope = soapPart.getEnvelope();
    String namespacePrefix = InweboConnectorConstants.SOAPMessage.SOAP_NAMESPACE_PREFIX;
    envelope.addNamespaceDeclaration(namespacePrefix, serverURI);
    SOAPBody soapBody = envelope.getBody();
    SOAPElement soapBodyElem = soapBody
            .addChildElement(InweboConnectorConstants.SOAPMessage.SOAP_ACTION_LOGIN_DELETE, namespacePrefix);
    SOAPElement soapBodyElem1 = soapBodyElem.addChildElement(InweboConnectorConstants.SOAPMessage.SOAP_USER_ID,
            namespacePrefix);//from  w ww. ja v  a 2  s  .c  o  m
    soapBodyElem1.addTextNode(userId);
    SOAPElement soapBodyElem2 = soapBodyElem
            .addChildElement(InweboConnectorConstants.SOAPMessage.SOAP_SERVICE_ID, namespacePrefix);
    soapBodyElem2.addTextNode(serviceId);
    SOAPElement soapBodyElem3 = soapBodyElem.addChildElement(InweboConnectorConstants.SOAPMessage.SOAP_LOGIN_ID,
            namespacePrefix);
    soapBodyElem3.addTextNode(loginId);
    MimeHeaders headers = soapMessage.getMimeHeaders();
    headers.addHeader(InweboConnectorConstants.SOAPMessage.SOAP_ACTION,
            serverURI + InweboConnectorConstants.SOAPMessage.SOAP_ACTION_HEADER);
    soapMessage.saveChanges();
    return soapMessage;
}

From source file:org.wso2.carbon.identity.provisioning.connector.UserCreation.java

private static SOAPMessage createUser(String userId, String serviceId, String login, String firstName,
        String name, String mail, String phone, String status, String role, String access, String codetype,
        String language, String extrafields) throws SOAPException, IdentityProvisioningException {
    MessageFactory messageFactory = MessageFactory.newInstance();
    SOAPMessage soapMessage = messageFactory.createMessage();
    SOAPPart soapPart = soapMessage.getSOAPPart();
    String serverURI = InweboConnectorConstants.INWEBO_URI;
    SOAPEnvelope envelope = soapPart.getEnvelope();
    envelope.addNamespaceDeclaration("con", serverURI);
    SOAPBody soapBody = envelope.getBody();
    SOAPElement soapBodyElem = soapBody.addChildElement("loginCreate", "con");
    SOAPElement soapBodyElem1 = soapBodyElem.addChildElement("userid", "con");
    soapBodyElem1.addTextNode(userId);/*w w w. java2 s  .com*/
    SOAPElement soapBodyElem2 = soapBodyElem.addChildElement("serviceid", "con");
    soapBodyElem2.addTextNode(serviceId);
    SOAPElement soapBodyElem3 = soapBodyElem.addChildElement("login", "con");
    soapBodyElem3.addTextNode(login);
    SOAPElement soapBodyElem4 = soapBodyElem.addChildElement("firstname", "con");
    soapBodyElem4.addTextNode(firstName);
    SOAPElement soapBodyElem5 = soapBodyElem.addChildElement("name", "con");
    soapBodyElem5.addTextNode(name);
    SOAPElement soapBodyElem6 = soapBodyElem.addChildElement("mail", "con");
    soapBodyElem6.addTextNode(mail);
    SOAPElement soapBodyElem7 = soapBodyElem.addChildElement("phone", "con");
    soapBodyElem7.addTextNode(phone);
    SOAPElement soapBodyElem8 = soapBodyElem.addChildElement("status", "con");
    soapBodyElem8.addTextNode(status);
    SOAPElement soapBodyElem9 = soapBodyElem.addChildElement("role", "con");
    soapBodyElem9.addTextNode(role);
    SOAPElement soapBodyElem10 = soapBodyElem.addChildElement("access", "con");
    soapBodyElem10.addTextNode(access);
    SOAPElement soapBodyElem11 = soapBodyElem.addChildElement("codetype", "con");
    soapBodyElem11.addTextNode(codetype);
    SOAPElement soapBodyElem12 = soapBodyElem.addChildElement("lang", "con");
    soapBodyElem12.addTextNode(language);
    SOAPElement soapBodyElem13 = soapBodyElem.addChildElement("extrafields", "con");
    soapBodyElem13.addTextNode(extrafields);
    MimeHeaders headers = soapMessage.getMimeHeaders();
    headers.addHeader("SOAPAction", serverURI + "/services/ConsoleAdmin");
    soapMessage.saveChanges();

    return soapMessage;
}

From source file:org.wso2.carbon.identity.provisioning.connector.UserDeletion.java

private static SOAPMessage deleteUsers(String loginId, String userId, String serviceId)
        throws SOAPException, IdentityProvisioningException {

    MessageFactory messageFactory = MessageFactory.newInstance();
    SOAPMessage soapMessage = messageFactory.createMessage();
    try {/*w  ww  .  j  a  v  a 2  s .  co m*/
        SOAPPart soapPart = soapMessage.getSOAPPart();
        String serverURI = InweboConnectorConstants.INWEBO_URI;
        SOAPEnvelope envelope = soapPart.getEnvelope();
        envelope.addNamespaceDeclaration("con", serverURI);
        SOAPBody soapBody = envelope.getBody();
        SOAPElement soapBodyElem = soapBody.addChildElement("loginDelete", "con");
        SOAPElement soapBodyElem1 = soapBodyElem.addChildElement("userid", "con");
        soapBodyElem1.addTextNode(userId);
        SOAPElement soapBodyElem2 = soapBodyElem.addChildElement("serviceid", "con");
        soapBodyElem2.addTextNode(serviceId);
        SOAPElement soapBodyElem3 = soapBodyElem.addChildElement("loginid", "con");
        soapBodyElem3.addTextNode(loginId);
        MimeHeaders headers = soapMessage.getMimeHeaders();
        headers.addHeader("SOAPAction", serverURI + "/services/ConsoleAdmin");
        soapMessage.saveChanges();
    } catch (SOAPException e) {
        throw new IdentityProvisioningException("Error while delete the user", e);
    }
    return soapMessage;
}

From source file:org.wso2.carbon.identity.provisioning.connector.UserUpdation.java

private static SOAPMessage createUserObject(String userId, String serviceId, String loginId, String login,
        String firstName, String name, String mail, String phone, String status, String role,
        String extraFields) throws SOAPException, IdentityProvisioningException {
    MessageFactory messageFactory = MessageFactory.newInstance();
    SOAPMessage soapMessage = messageFactory.createMessage();
    SOAPPart soapPart = soapMessage.getSOAPPart();
    String serverURI = InweboConnectorConstants.INWEBO_URI;
    SOAPEnvelope envelope = soapPart.getEnvelope();
    envelope.addNamespaceDeclaration("con", serverURI);
    SOAPBody soapBody = envelope.getBody();
    SOAPElement soapBodyElem = soapBody.addChildElement("loginUpdate", "con");
    SOAPElement soapBodyElem1 = soapBodyElem.addChildElement("userid", "con");
    soapBodyElem1.addTextNode(userId);/*  ww  w. ja v a2 s  .  c  o m*/
    SOAPElement soapBodyElem2 = soapBodyElem.addChildElement("serviceid", "con");
    soapBodyElem2.addTextNode(serviceId);
    SOAPElement soapBodyElem3 = soapBodyElem.addChildElement("loginid", "con");
    soapBodyElem3.addTextNode(loginId);
    SOAPElement soapBodyElem4 = soapBodyElem.addChildElement("login", "con");
    soapBodyElem4.addTextNode(login);
    SOAPElement soapBodyElem5 = soapBodyElem.addChildElement("firstname", "con");
    soapBodyElem5.addTextNode(firstName);
    SOAPElement soapBodyElem6 = soapBodyElem.addChildElement("name", "con");
    soapBodyElem6.addTextNode(name);
    SOAPElement soapBodyElem7 = soapBodyElem.addChildElement("mail", "con");
    soapBodyElem7.addTextNode(mail);
    SOAPElement soapBodyElem8 = soapBodyElem.addChildElement("phone", "con");
    soapBodyElem8.addTextNode(phone);
    SOAPElement soapBodyElem9 = soapBodyElem.addChildElement("status", "con");
    soapBodyElem9.addTextNode(status);
    SOAPElement soapBodyElem10 = soapBodyElem.addChildElement("role", "con");
    soapBodyElem10.addTextNode(role);
    SOAPElement soapBodyElem11 = soapBodyElem.addChildElement("extrafields", "con");
    soapBodyElem11.addTextNode(extraFields);
    MimeHeaders headers = soapMessage.getMimeHeaders();
    headers.addHeader("SOAPAction", serverURI + "/services/ConsoleAdmin");
    soapMessage.saveChanges();
    return soapMessage;
}