Search in sources :

Example 1 with ServiceException

use of javax.xml.rpc.ServiceException in project tdi-studio-se by Talend.

the class SObjectsToSchema method login.

boolean login(String userName, String password) throws ServiceException {
    /**
         * Next, the sample client application initializes the binding stub. This is our main interface to the API
         * through which all calls are made. The getSoap method takes an optional parameter, (a java.net.URL) which is
         * the endpoint. For the login call, the parameter always starts with http(s)://login.salesforce.com. After
         * logging in, the sample client application changes the endpoint to the one specified in the returned
         * loginResult object.
         */
    binding = (SoapBindingStub) new SforceServiceLocator().getSoap();
    // Time out after a minute
    binding.setTimeout(60000);
    // Test operation
    LoginResult loginResult;
    try {
        System.out.println("LOGGING IN NOW....");
        loginResult = binding.login(userName, password);
    } catch (LoginFault ex) {
        // The LoginFault derives from AxisFault
        ExceptionCode exCode = ex.getExceptionCode();
        if (exCode == ExceptionCode.FUNCTIONALITY_NOT_ENABLED || exCode == ExceptionCode.INVALID_CLIENT || exCode == ExceptionCode.INVALID_LOGIN || exCode == ExceptionCode.LOGIN_DURING_RESTRICTED_DOMAIN || exCode == ExceptionCode.LOGIN_DURING_RESTRICTED_TIME || exCode == ExceptionCode.ORG_LOCKED || exCode == ExceptionCode.PASSWORD_LOCKOUT || exCode == ExceptionCode.SERVER_UNAVAILABLE || exCode == ExceptionCode.TRIAL_EXPIRED || exCode == ExceptionCode.UNSUPPORTED_CLIENT) {
            System.out.println("Please be sure that you have a valid username " + "and password.");
        } else {
            // Write the fault code to the console
            System.out.println(ex.getExceptionCode());
            // Write the fault message to the console
            System.out.println("An unexpected error has occurred." + ex.getMessage());
        }
        return false;
    } catch (Exception ex) {
        System.out.println("An unexpected error has occurred: " + ex.getMessage());
        ex.printStackTrace();
        return false;
    }
    if (loginResult.isPasswordExpired()) {
        System.out.println("An error has occurred. Your password has expired.");
        return false;
    }
    /**
         * Once the client application has logged in successfully, it will use the results of the login call to reset
         * the endpoint of the service to the virtual server instance that is servicing your organization. To do this,
         * the client application sets the ENDPOINT_ADDRESS_PROPERTY of the binding object using the URL returned from
         * the LoginResult.
         */
    binding._setProperty(SoapBindingStub.ENDPOINT_ADDRESS_PROPERTY, loginResult.getServerUrl());
    /**
         * The sample client application now has an instance of the SoapBindingStub that is pointing to the correct
         * endpoint. Next, the sample client application sets a persistent SOAP header (to be included on all subsequent
         * calls that are made with the SoapBindingStub) that contains the valid sessionId for our login credentials. To
         * do this, the sample client application creates a new SessionHeader object and set its sessionId property to
         * the sessionId property from the LoginResult object.
         */
    // Create a new session header object and add the session id
    // from the login return object
    SessionHeader sh = new SessionHeader();
    sh.setSessionId(loginResult.getSessionId());
    /**
         * Next, the sample client application calls the setHeader method of the SoapBindingStub to add the header to
         * all subsequent method calls. This header will persist until the SoapBindingStub is destroyed until the header
         * is explicitly removed. The "SessionHeader" parameter is the name of the header to be added.
         */
    // set the session header for subsequent call authentication
    binding.setHeader(new SforceServiceLocator().getServiceName().getNamespaceURI(), "SessionHeader", sh);
    return true;
}
Also used : SforceServiceLocator(com.salesforce.soap.partner.SforceServiceLocator) SessionHeader(com.salesforce.soap.partner.SessionHeader) LoginResult(com.salesforce.soap.partner.LoginResult) LoginFault(com.salesforce.soap.partner.fault.LoginFault) ExceptionCode(com.salesforce.soap.partner.fault.ExceptionCode) IOException(java.io.IOException) ServiceException(javax.xml.rpc.ServiceException) RemoteException(java.rmi.RemoteException)

Example 2 with ServiceException

use of javax.xml.rpc.ServiceException in project tdi-studio-se by Talend.

the class PartnerSamples method login.

/*
     * login sample Prompts for username and password, set class variable binding resets the url for the binding and
     * adds the session header to the binding class variable
     */
private boolean login() {
    un = getUserInput("Enter user name: ");
    if (un.length() == 0) {
        return false;
    }
    pw = getUserInput("Enter password: ");
    if (pw.length() == 0) {
        return false;
    }
    // Provide feed back while we create the web service binding
    System.out.println("Creating the binding to the web service...");
    /*
         * There are 2 ways to get the binding, one by passing a url to the getSoap() method of the
         * SforceServiceLocator, the other by not passing a url. In the second case the binding will use the url
         * contained in the wsdl file when the proxy was generated.
         */
    try {
        binding = (SoapBindingStub) new SforceServiceLocator().getSoap();
    } catch (ServiceException ex) {
        System.out.println("ERROR: createing binding to soap service, error was: \n" + ex.getMessage());
        System.out.print("Hit return to continue...");
        return false;
    }
    // Time out after a minute
    binding.setTimeout(60000);
    // binding._setProperty(Stub.ENDPOINT_ADDRESS_PROPERTY, "http://localhost:8080/services/Soap/u/8.0");
    // Attempt the login giving the user feedback
    System.out.println("LOGGING IN NOW....");
    try {
        loginResult = binding.login(un, pw);
    } catch (LoginFault lf) {
        System.out.println(lf.getExceptionMessage());
        // lf.printStackTrace();
        getUserInput("\nHit return to continue...");
        return false;
    } catch (ApiFault af) {
        System.out.println(af.getExceptionMessage());
        getUserInput("\nHit return to continue...");
    } catch (RemoteException re) {
        System.out.println(re.getMessage());
        re.printStackTrace();
        getUserInput("\nHit return to continue...");
        return false;
    }
    System.out.println("\nThe session id is: " + loginResult.getSessionId());
    System.out.println("\nThe new server url is: " + loginResult.getServerUrl());
    binding._setProperty(SoapBindingStub.ENDPOINT_ADDRESS_PROPERTY, loginResult.getServerUrl());
    // binding._setProperty(Stub.ENDPOINT_ADDRESS_PROPERTY, "http://localhost:8080/services/Soap/u/8.0");
    // Create a new session header object and set the session id to that
    // returned by the login
    SessionHeader sh = new SessionHeader();
    sh.setSessionId(loginResult.getSessionId());
    binding.setHeader(new SforceServiceLocator().getServiceName().getNamespaceURI(), "SessionHeader", sh);
    loggedIn = true;
    // call the getServerTimestamp method
    getServerTimestampSample();
    // call the getUserInfo method
    getUserInfoSample();
    return true;
}
Also used : ApiFault(com.salesforce.soap.partner.fault.ApiFault) ServiceException(javax.xml.rpc.ServiceException) SforceServiceLocator(com.salesforce.soap.partner.SforceServiceLocator) SessionHeader(com.salesforce.soap.partner.SessionHeader) LoginFault(com.salesforce.soap.partner.fault.LoginFault) RemoteException(java.rmi.RemoteException)

Example 3 with ServiceException

use of javax.xml.rpc.ServiceException in project opennms by OpenNMS.

the class OtrsTicketerPluginTest method createTicketAndArticle.

// This is just to bootstrap a saved ticket so that we can get it back later
private TicketIDAndNumber createTicketAndArticle(String ticketSubject, String articleBody) throws InterruptedException {
    TicketIDAndNumber idAndNumber = null;
    m_configDao = new DefaultOtrsConfigDao();
    TicketCore otrsTicket = new TicketCore();
    Credentials creds = new Credentials(m_configDao.getUserName(), m_configDao.getPassword());
    otrsTicket.setLock(m_configDao.getLock());
    otrsTicket.setQueue(m_configDao.getQueue());
    otrsTicket.setPriority(m_configDao.getPriority());
    otrsTicket.setState(m_configDao.getState());
    otrsTicket.setOwnerID(m_configDao.getOwnerID());
    otrsTicket.setUser(defaultUser);
    otrsTicket.setTitle(ticketSubject);
    Integer articleId = null;
    TicketServiceLocator service = new TicketServiceLocator();
    service.setTicketServicePortEndpointAddress(m_configDao.getEndpoint());
    TicketServicePort_PortType port = null;
    try {
        port = service.getTicketServicePort();
    } catch (ServiceException e1) {
        e1.printStackTrace();
    }
    try {
        idAndNumber = port.ticketCreate(otrsTicket, creds);
    } catch (RemoteException e) {
        e.printStackTrace();
    }
    ArticleCore otrsArticle = new ArticleCore();
    otrsArticle.setArticleType(m_configDao.getArticleType());
    otrsArticle.setSenderType(m_configDao.getArticleSenderType());
    otrsArticle.setContentType(m_configDao.getArticleContentType());
    otrsArticle.setHistoryType(m_configDao.getArticleHistoryType());
    otrsArticle.setHistoryComment(m_configDao.getArticleHistoryComment());
    otrsArticle.setSenderType(m_configDao.getArticleSenderType());
    otrsArticle.setSubject(defaultArticleSubject);
    otrsArticle.setFrom(m_configDao.getArticleFrom());
    otrsArticle.setBody(defaultArticleBody);
    otrsArticle.setUser(defaultUser);
    otrsArticle.setTicketID(idAndNumber.getTicketID());
    otrsArticle.setBody(articleBody);
    try {
        articleId = port.articleCreate(otrsArticle, creds);
        assertNotNull(articleId);
    } catch (RemoteException e) {
        e.printStackTrace();
    }
    return idAndNumber;
}
Also used : ArticleCore(org.opennms.integration.otrs.ticketservice.ArticleCore) ServiceException(javax.xml.rpc.ServiceException) DefaultOtrsConfigDao(org.opennms.netmgt.ticketer.otrs.common.DefaultOtrsConfigDao) TicketServicePort_PortType(org.opennms.integration.otrs.ticketservice.TicketServicePort_PortType) RemoteException(java.rmi.RemoteException) TicketCore(org.opennms.integration.otrs.ticketservice.TicketCore) TicketServiceLocator(org.opennms.integration.otrs.ticketservice.TicketServiceLocator) Credentials(org.opennms.integration.otrs.ticketservice.Credentials) TicketIDAndNumber(org.opennms.integration.otrs.ticketservice.TicketIDAndNumber)

Example 4 with ServiceException

use of javax.xml.rpc.ServiceException in project opennms by OpenNMS.

the class OtrsTicketerPlugin method getTicketServicePort.

/**
 * Convenience method for initialising the ticketServicePort and correctly setting the endpoint.
 *
 * @return TicketServicePort to connect to the remote service.
 */
private TicketServicePort_PortType getTicketServicePort(String endpoint) throws PluginException {
    TicketServiceLocator service = new TicketServiceLocator();
    service.setTicketServicePortEndpointAddress(endpoint);
    TicketServicePort_PortType port = null;
    try {
        port = service.getTicketServicePort();
    } catch (ServiceException e) {
        LOG.error("Failed initialzing OTRS TicketServicePort", e);
        throw new PluginException("Failed initialzing OTRS TicketServicePort");
    }
    return port;
}
Also used : ServiceException(javax.xml.rpc.ServiceException) TicketServicePort_PortType(org.opennms.integration.otrs.ticketservice.TicketServicePort_PortType) TicketServiceLocator(org.opennms.integration.otrs.ticketservice.TicketServiceLocator)

Example 5 with ServiceException

use of javax.xml.rpc.ServiceException in project opennms by OpenNMS.

the class RemedyTicketerPlugin method getTicketServicePort.

/**
 * Convenience method for initializing the ticketServicePort and correctly setting the endpoint.
 *
 * @return TicketServicePort to connect to the remote service.
 */
private HPD_IncidentInterface_WSPortTypePortType getTicketServicePort(String portname, String endpoint) throws PluginException {
    HPD_IncidentInterface_WSServiceLocator service = new HPD_IncidentInterface_WSServiceLocator();
    HPD_IncidentInterface_WSPortTypePortType port = null;
    try {
        service.setEndpointAddress(portname, endpoint);
        port = service.getHPD_IncidentInterface_WSPortTypeSoap();
    } catch (ServiceException e) {
        LOG.error("Failed initialzing Remedy TicketServicePort", e);
        throw new PluginException("Failed initialzing Remedy TicketServicePort", e);
    }
    return port;
}
Also used : ServiceException(javax.xml.rpc.ServiceException) HPD_IncidentInterface_WSPortTypePortType(org.opennms.integration.remedy.ticketservice.HPD_IncidentInterface_WSPortTypePortType) HPD_IncidentInterface_WSServiceLocator(org.opennms.integration.remedy.ticketservice.HPD_IncidentInterface_WSServiceLocator)

Aggregations

ServiceException (javax.xml.rpc.ServiceException)18 RemoteException (java.rmi.RemoteException)7 Remote (java.rmi.Remote)3 AddInteractiveRequest (com.AddressDoctor.validator2.addInteractive.Interactive.AddInteractiveRequest)2 AddInteractiveResponse (com.AddressDoctor.validator2.addInteractive.Interactive.AddInteractiveResponse)2 Authentication (com.AddressDoctor.validator2.addInteractive.Interactive.Authentication)2 InteractiveSoap (com.AddressDoctor.validator2.addInteractive.Interactive.InteractiveSoap)2 Parameters (com.AddressDoctor.validator2.addInteractive.Interactive.Parameters)2 SessionHeader (com.salesforce.soap.partner.SessionHeader)2 SforceServiceLocator (com.salesforce.soap.partner.SforceServiceLocator)2 LoginFault (com.salesforce.soap.partner.fault.LoginFault)2 QName (javax.xml.namespace.QName)2 TicketServiceLocator (org.opennms.integration.otrs.ticketservice.TicketServiceLocator)2 TicketServicePort_PortType (org.opennms.integration.otrs.ticketservice.TicketServicePort_PortType)2 Address (com.AddressDoctor.validator2.addInteractive.Interactive.Address)1 Result (com.AddressDoctor.validator2.addInteractive.Interactive.Result)1 LoginResult (com.salesforce.soap.partner.LoginResult)1 ApiFault (com.salesforce.soap.partner.fault.ApiFault)1 ExceptionCode (com.salesforce.soap.partner.fault.ExceptionCode)1 IOException (java.io.IOException)1