Search in sources :

Example 1 with SessionResponse

use of com.netsuite.webservices.test.platform.messages.SessionResponse in project components by Talend.

the class TestNetSuiteClientService method doLogin.

@Override
protected void doLogin() throws NetSuiteException {
    port = getNetSuitePort(endpointUrl, credentials.getAccount());
    setHttpClientPolicy(port);
    setLoginHeaders(port);
    PortOperation<SessionResponse, NetSuitePortType> loginOp;
    if (!credentials.isUseSsoLogin()) {
        final Passport passport = createNativePassport(credentials);
        loginOp = new PortOperation<SessionResponse, NetSuitePortType>() {

            @Override
            public SessionResponse execute(NetSuitePortType port) throws Exception {
                LoginRequest request = new LoginRequest();
                request.setPassport(passport);
                LoginResponse response = port.login(request);
                return response.getSessionResponse();
            }
        };
    } else {
        throw new NetSuiteException(new NetSuiteErrorCode(NetSuiteErrorCode.CLIENT_ERROR), NetSuiteRuntimeI18n.MESSAGES.getMessage("error.ssoLoginNotSupported"));
    }
    Status status = null;
    SessionResponse sessionResponse;
    String exceptionMessage = null;
    for (int i = 0; i < getRetryCount(); i++) {
        try {
            sessionResponse = loginOp.execute(port);
            status = sessionResponse.getStatus();
        } catch (InvalidCredentialsFault f) {
            throw new NetSuiteException(new NetSuiteErrorCode(NetSuiteErrorCode.CLIENT_ERROR), f.getFaultInfo().getMessage());
        } catch (UnexpectedErrorFault f) {
            exceptionMessage = f.getFaultInfo().getMessage();
        } catch (Exception e) {
            exceptionMessage = e.getMessage();
        }
        if (status != null) {
            break;
        }
        if (i != getRetryCount() - 1) {
            waitForRetryInterval();
        }
    }
    checkLoginError(toNsStatus(status), exceptionMessage);
    removeLoginHeaders(port);
}
Also used : Status(com.netsuite.webservices.test.platform.core.Status) NsStatus(org.talend.components.netsuite.client.NsStatus) InvalidCredentialsFault(com.netsuite.webservices.test.platform.InvalidCredentialsFault) LoginResponse(com.netsuite.webservices.test.platform.messages.LoginResponse) NetSuiteException(org.talend.components.netsuite.client.NetSuiteException) UnexpectedErrorFault(com.netsuite.webservices.test.platform.UnexpectedErrorFault) LoginRequest(com.netsuite.webservices.test.platform.messages.LoginRequest) NetSuiteException(org.talend.components.netsuite.client.NetSuiteException) InvocationTargetException(java.lang.reflect.InvocationTargetException) RemoteException(java.rmi.RemoteException) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) SocketException(java.net.SocketException) MalformedURLException(java.net.MalformedURLException) NetSuitePortType(com.netsuite.webservices.test.platform.NetSuitePortType) NetSuiteErrorCode(org.talend.components.netsuite.NetSuiteErrorCode) Passport(com.netsuite.webservices.test.platform.core.Passport) SessionResponse(com.netsuite.webservices.test.platform.messages.SessionResponse)

Example 2 with SessionResponse

use of com.netsuite.webservices.test.platform.messages.SessionResponse in project components by Talend.

the class NetSuiteClientServiceTest method testLoginInvalidCredentials.

@Test(expected = NetSuiteException.class)
public void testLoginInvalidCredentials() throws Exception {
    SessionResponse sessionResponse = new SessionResponse();
    sessionResponse.setStatus(NetSuitePortTypeMockAdapterImpl.createErrorStatus(StatusDetailCodeType.INVALID_LOGIN_CREDENTIALS, "Invalid credentials"));
    LoginResponse response = new LoginResponse();
    response.setSessionResponse(sessionResponse);
    when(port.login(any(LoginRequest.class))).thenReturn(response);
    clientService.login();
}
Also used : LoginResponse(com.netsuite.webservices.test.platform.messages.LoginResponse) LoginRequest(com.netsuite.webservices.test.platform.messages.LoginRequest) SessionResponse(com.netsuite.webservices.test.platform.messages.SessionResponse) Test(org.junit.Test)

Example 3 with SessionResponse

use of com.netsuite.webservices.test.platform.messages.SessionResponse in project components by Talend.

the class NetSuiteComponentMockTestFixture method mockLoginResponse.

@Override
protected void mockLoginResponse(NetSuitePortType port) throws Exception {
    SessionResponse sessionResponse = new SessionResponse();
    sessionResponse.setStatus(NetSuitePortTypeMockAdapterImpl.createSuccessStatus());
    LoginResponse response = new LoginResponse();
    response.setSessionResponse(sessionResponse);
    when(port.login(any(LoginRequest.class))).thenReturn(response);
}
Also used : LoginResponse(com.netsuite.webservices.test.platform.messages.LoginResponse) LoginRequest(com.netsuite.webservices.test.platform.messages.LoginRequest) SessionResponse(com.netsuite.webservices.test.platform.messages.SessionResponse)

Example 4 with SessionResponse

use of com.netsuite.webservices.test.platform.messages.SessionResponse in project components by Talend.

the class NetSuiteMockTestBase method mockLoginResponse.

protected void mockLoginResponse(NetSuitePortType port) throws Exception {
    SessionResponse sessionResponse = new SessionResponse();
    sessionResponse.setStatus(NetSuitePortTypeMockAdapterImpl.createSuccessStatus());
    LoginResponse response = new LoginResponse();
    response.setSessionResponse(sessionResponse);
    when(port.login(any(LoginRequest.class))).thenReturn(response);
}
Also used : LoginResponse(com.netsuite.webservices.test.platform.messages.LoginResponse) LoginRequest(com.netsuite.webservices.test.platform.messages.LoginRequest) SessionResponse(com.netsuite.webservices.test.platform.messages.SessionResponse)

Aggregations

LoginRequest (com.netsuite.webservices.test.platform.messages.LoginRequest)4 LoginResponse (com.netsuite.webservices.test.platform.messages.LoginResponse)4 SessionResponse (com.netsuite.webservices.test.platform.messages.SessionResponse)4 InvalidCredentialsFault (com.netsuite.webservices.test.platform.InvalidCredentialsFault)1 NetSuitePortType (com.netsuite.webservices.test.platform.NetSuitePortType)1 UnexpectedErrorFault (com.netsuite.webservices.test.platform.UnexpectedErrorFault)1 Passport (com.netsuite.webservices.test.platform.core.Passport)1 Status (com.netsuite.webservices.test.platform.core.Status)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 MalformedURLException (java.net.MalformedURLException)1 SocketException (java.net.SocketException)1 RemoteException (java.rmi.RemoteException)1 SOAPFaultException (javax.xml.ws.soap.SOAPFaultException)1 Test (org.junit.Test)1 NetSuiteErrorCode (org.talend.components.netsuite.NetSuiteErrorCode)1 NetSuiteException (org.talend.components.netsuite.client.NetSuiteException)1 NsStatus (org.talend.components.netsuite.client.NsStatus)1