Example usage for javax.xml.soap SOAPConnectionFactory newInstance

List of usage examples for javax.xml.soap SOAPConnectionFactory newInstance

Introduction

In this page you can find the example usage for javax.xml.soap SOAPConnectionFactory newInstance.

Prototype

public static SOAPConnectionFactory newInstance() throws SOAPException, UnsupportedOperationException 

Source Link

Document

Creates an instance of the default SOAPConnectionFactory object.

Usage

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

/**
 * Method to create SOAP connection/*from w ww . j av a  2s.  c o m*/
 */
public static String invokeSOAP(InweboUser user, String operation) throws IdentityProvisioningException {
    String provisionedId = null;
    SOAPConnectionFactory soapConnectionFactory = null;
    SOAPConnection soapConnection = null;
    try {
        Properties inweboProperties = new Properties();
        String resourceName = InweboConnectorConstants.PROPERTIES_FILE;
        ClassLoader loader = Thread.currentThread().getContextClassLoader();
        InputStream resourceStream = loader.getResourceAsStream(resourceName);
        try {
            inweboProperties.load(resourceStream);
        } catch (IOException e) {
            throw new IdentityProvisioningException("Unable to load the properties file", e);
        }

        SOAPMessage soapMessage = null;
        soapConnectionFactory = SOAPConnectionFactory.newInstance();
        soapConnection = soapConnectionFactory.createConnection();
        String url = inweboProperties.getProperty(InweboConnectorConstants.INWEBO_URL);
        if (operation.equals(InweboConnectorConstants.INWEBO_OPERATION_POST)) {
            soapMessage = createUserSOAPMessage(inweboProperties, user);
        } else if (operation.equals(InweboConnectorConstants.INWEBO_OPERATION_PUT)) {
            soapMessage = updateUserSOAPMessage(inweboProperties, user);
        } else if (operation.equals(InweboConnectorConstants.INWEBO_OPERATION_DELETE)) {
            soapMessage = deleteUserSOAPMessage(inweboProperties, user.getLoginId(), user.getUserId(),
                    user.getServiceId());
        }
        SOAPMessage soapResponse = soapConnection.call(soapMessage, url);
        if (operation.equals(InweboConnectorConstants.INWEBO_OPERATION_POST)) {
            if (soapResponse.getSOAPBody().getElementsByTagName("id").getLength() != 0) {
                provisionedId = soapResponse.getSOAPBody().getElementsByTagName("id").item(0).getTextContent()
                        .toString();
                if (StringUtils.isEmpty(provisionedId) || "0".equals(provisionedId)) {
                    String error = soapResponse.getSOAPBody().getElementsByTagName("loginCreateReturn").item(0)
                            .getTextContent().toString();
                    throw new IdentityProvisioningException(
                            "Error occurred while creating the user in InWebo:" + error);
                }
            } else {
                throw new IdentityProvisioningException("Unable to find the provisioning ID");
            }
        } else if (operation.equals(InweboConnectorConstants.INWEBO_OPERATION_PUT)) {
            if (soapResponse.getSOAPBody().getElementsByTagName("loginUpdateReturn").getLength() != 0) {
                String updationStatus = soapResponse.getSOAPBody().getElementsByTagName("loginUpdateReturn")
                        .item(0).getTextContent().toString();
                boolean processStatus = StringUtils.equals("OK", updationStatus);
                if (!processStatus) {
                    String error = soapResponse.getSOAPBody().getElementsByTagName("loginUpdateReturn").item(0)
                            .getTextContent().toString();
                    throw new IdentityProvisioningException(
                            "Error occurred while updating the user in InWebo:" + error);
                }
            } else {
                throw new IdentityProvisioningException("Unable to get the updation status");
            }
        } else if (operation.equals(InweboConnectorConstants.INWEBO_OPERATION_DELETE)) {
            if (soapResponse.getSOAPBody().getElementsByTagName("loginDeleteReturn").getLength() != 0) {
                String deletionStatus = soapResponse.getSOAPBody().getElementsByTagName("loginDeleteReturn")
                        .item(0).getTextContent().toString();
                boolean processStatus = StringUtils.equals("OK", deletionStatus);
                if (!processStatus) {
                    String error = soapResponse.getSOAPBody().getElementsByTagName("loginDeleteReturn").item(0)
                            .getTextContent().toString();
                    throw new IdentityProvisioningException(
                            "Error occurred while deleting the user from InWebo:" + error);
                }
            } else {
                throw new IdentityProvisioningException("Unable to get the operation status");
            }
        }
    } catch (SOAPException e) {
        throw new IdentityProvisioningException("Error occurred while sending SOAP Request to Server", e);
    } finally {
        try {
            if (soapConnection != null) {
                soapConnection.close();
            }
        } catch (SOAPException e) {
            log.error("Error while closing the SOAP connection", e);
        }
    }
    return provisionedId;
}

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

/**
 * Method for create SOAP connection/* ww w  .  ja  v a 2 s.  co m*/
 */
public static String invokeSOAP(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 IdentityProvisioningException {
    String provisionedId = null;
    try {
        SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
        SOAPConnection soapConnection = soapConnectionFactory.createConnection();
        String url = InweboConnectorConstants.INWEBO_URL;
        SOAPMessage soapResponse = soapConnection.call(createUser(userId, serviceId, login, firstName, name,
                mail, phone, status, role, access, codeType, language, extraFields), url);
        provisionedId = soapResponse.getSOAPBody().getElementsByTagName("id").item(0).getTextContent()
                .toString();
        soapConnection.close();
        if (StringUtils.isEmpty(provisionedId) || provisionedId.equals("0")) {
            String error = soapResponse.getSOAPBody().getElementsByTagName("loginCreateReturn").item(0)
                    .getTextContent().toString();
            throw new IdentityProvisioningException(
                    "Error occurred while creating the user in InWebo:" + error);
        }
    } catch (SOAPException e) {
        throw new IdentityProvisioningException("Error occurred while sending SOAP Request to Server", e);
    } catch (IdentityProvisioningException e) {
        throw new IdentityProvisioningException("Error occurred while sending SOAP Request to Server", e);
    }
    return provisionedId;
}

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

public boolean deleteUser(String loginId, String userId, String serviceId)
        throws IdentityProvisioningException {
    try {/*  w  ww  .j a v a2 s . com*/
        SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
        SOAPConnection soapConnection = soapConnectionFactory.createConnection();
        String url = InweboConnectorConstants.INWEBO_URL;
        SOAPMessage soapResponse = soapConnection.call(deleteUsers(loginId, userId, serviceId), url);
        String deletionStatus = soapResponse.getSOAPBody().getElementsByTagName("loginDeleteReturn").item(0)
                .getTextContent().toString();
        soapConnection.close();
        boolean processStatus = StringUtils.equals("OK", deletionStatus);
        if (!processStatus) {
            String error = soapResponse.getSOAPBody().getElementsByTagName("loginDeleteReturn").item(0)
                    .getTextContent().toString();
            throw new IdentityProvisioningException(
                    "Error occurred while deleting the user from InWebo:" + error);
        }
        return processStatus;
    } catch (SOAPException e) {
        throw new IdentityProvisioningException("Error occurred while sending SOAP Request to Server", e);
    } catch (IdentityProvisioningException e) {
        throw new IdentityProvisioningException("Error occurred while sending SOAP Request to Server", e);
    }
}

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

/**
 * Method for create SOAP connection/*w w  w .  jav  a  2s  . c  o m*/
 */
public static boolean invokeSOAP(String userId, String serviceId, String loginId, String login,
        String firstName, String name, String mail, String phone, String status, String role,
        String extraFields) throws IdentityProvisioningException {
    try {
        SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
        SOAPConnection soapConnection = soapConnectionFactory.createConnection();
        String url = InweboConnectorConstants.INWEBO_URL;
        SOAPMessage soapResponse = soapConnection.call(createUserObject(userId, serviceId, loginId, login,
                firstName, name, mail, phone, status, role, extraFields), url);
        String updationStatus = soapResponse.getSOAPBody().getElementsByTagName("loginUpdateReturn").item(0)
                .getTextContent().toString();
        soapConnection.close();
        boolean processStatus = StringUtils.equals("OK", updationStatus);
        if (!processStatus) {
            String error = soapResponse.getSOAPBody().getElementsByTagName("loginUpdateReturn").item(0)
                    .getTextContent().toString();
            throw new IdentityProvisioningException(
                    "Error occurred while updating the user in InWebo:" + error);
        }
        return processStatus;
    } catch (SOAPException e) {
        throw new IdentityProvisioningException("Error occurred while sending SOAP Request to Server", e);
    } catch (IdentityProvisioningException e) {
        throw new IdentityProvisioningException("Error occurred while sending SOAP Request to Server", e);
    }
}

From source file:test.functional.TestJAXMSamples.java

public void testJWSFault() throws Exception {
    try {//w  w  w  . j av a2s. co  m
        SOAPConnectionFactory scFactory = SOAPConnectionFactory.newInstance();
        SOAPConnection con = scFactory.createConnection();

        MessageFactory factory = MessageFactory.newInstance();
        SOAPMessage message = factory.createMessage();

        SOAPEnvelope envelope = message.getSOAPPart().getEnvelope();
        SOAPBody body = envelope.getBody();

        Name bodyName = envelope.createName("echo");
        SOAPBodyElement bodyElement = body.addBodyElement(bodyName);

        Name name = envelope.createName("arg0");
        SOAPElement symbol = bodyElement.addChildElement(name);
        symbol.addTextNode("Hello");

        URLEndpoint endpoint = new URLEndpoint("http://localhost:8080/jws/FaultTest.jws");
        SOAPMessage response = con.call(message, endpoint);
        SOAPBody respBody = response.getSOAPPart().getEnvelope().getBody();
        assertTrue(respBody.hasFault());
    } catch (javax.xml.soap.SOAPException e) {
        Throwable t = e.getCause();
        if (t != null) {
            t.printStackTrace();
            if (t instanceof AxisFault) {
                AxisFault af = (AxisFault) t;
                if ((af.detail instanceof SocketException)
                        || (af.getFaultCode().getLocalPart().equals("HTTP"))) {
                    System.out.println("Connect failure caused testJWSFault to be skipped.");
                    return;
                }
            }
            throw new Exception("Fault returned from test: " + t);
        } else {
            e.printStackTrace();
            throw new Exception("Exception returned from test: " + e);
        }
    } catch (Throwable t) {
        t.printStackTrace();
        throw new Exception("Fault returned from test: " + t);
    }
}