Search in sources :

Example 1 with SessionResponse

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

the class NetSuiteClientServiceImpl 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.v2016_2.platform.core.Status) NsStatus(org.talend.components.netsuite.client.NsStatus) InvalidCredentialsFault(com.netsuite.webservices.v2016_2.platform.InvalidCredentialsFault) LoginResponse(com.netsuite.webservices.v2016_2.platform.messages.LoginResponse) NetSuiteException(org.talend.components.netsuite.client.NetSuiteException) UnexpectedErrorFault(com.netsuite.webservices.v2016_2.platform.UnexpectedErrorFault) LoginRequest(com.netsuite.webservices.v2016_2.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) WebServiceException(javax.xml.ws.WebServiceException) NetSuitePortType(com.netsuite.webservices.v2016_2.platform.NetSuitePortType) NetSuiteErrorCode(org.talend.components.netsuite.NetSuiteErrorCode) Passport(com.netsuite.webservices.v2016_2.platform.core.Passport) SessionResponse(com.netsuite.webservices.v2016_2.platform.messages.SessionResponse)

Example 2 with SessionResponse

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

the class NetSuiteClientServiceTest method testConnectAndLogin.

/**
 */
@Test
public void testConnectAndLogin() throws Exception {
    final NetSuiteCredentials credentials = webServiceMockTestFixture.getCredentials();
    final NetSuitePortType port = webServiceMockTestFixture.getPortMock();
    SessionResponse sessionResponse = new SessionResponse();
    sessionResponse.setStatus(createSuccessStatus());
    LoginResponse response = new LoginResponse();
    response.setSessionResponse(sessionResponse);
    when(port.login(argThat(new AssertMatcher<LoginRequest>() {

        @Override
        protected void doAssert(LoginRequest target) throws Exception {
            assertEquals(credentials.getEmail(), target.getPassport().getEmail());
            assertEquals(credentials.getPassword(), target.getPassport().getPassword());
            assertEquals(credentials.getRoleId(), target.getPassport().getRole().getInternalId());
            assertEquals(credentials.getAccount(), target.getPassport().getAccount());
            MessageContext messageContext = MessageContextHolder.get();
            assertNotNull(messageContext);
            List<Header> headers = (List<Header>) messageContext.get(Header.HEADER_LIST);
            assertNotNull(headers);
            Header appInfoHeader = NetSuiteWebServiceMockTestFixture.getHeader(headers, new QName(NetSuiteClientServiceImpl.NS_URI_PLATFORM_MESSAGES, "applicationInfo"));
            assertNotNull(appInfoHeader);
        }
    }))).thenReturn(response);
    NetSuiteClientService<?> clientService = webServiceMockTestFixture.getClientService();
    clientService.login();
    verify(port, times(1)).login(any(LoginRequest.class));
}
Also used : NetSuitePortType(com.netsuite.webservices.v2016_2.platform.NetSuitePortType) NetSuiteCredentials(org.talend.components.netsuite.client.NetSuiteCredentials) LoginResponse(com.netsuite.webservices.v2016_2.platform.messages.LoginResponse) Header(org.apache.cxf.headers.Header) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) List(java.util.List) LoginRequest(com.netsuite.webservices.v2016_2.platform.messages.LoginRequest) MessageContext(javax.xml.ws.handler.MessageContext) SessionResponse(com.netsuite.webservices.v2016_2.platform.messages.SessionResponse) AssertMatcher(org.talend.components.netsuite.test.AssertMatcher) Test(org.junit.Test)

Example 3 with SessionResponse

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

the class NetSuiteClientServiceTest method testConnectAndLogin.

/**
 * TODO Verify headers (applicationInfo etc.)
 */
@Test
public void testConnectAndLogin() throws Exception {
    final NetSuiteCredentials credentials = webServiceMockTestFixture.getCredentials();
    final NetSuitePortType port = webServiceMockTestFixture.getPortMock();
    SessionResponse sessionResponse = new SessionResponse();
    sessionResponse.setStatus(createSuccessStatus());
    LoginResponse response = new LoginResponse();
    response.setSessionResponse(sessionResponse);
    when(port.login(argThat(new AssertMatcher<LoginRequest>() {

        @Override
        protected void doAssert(LoginRequest target) throws Exception {
            assertEquals(credentials.getEmail(), target.getPassport().getEmail());
            assertEquals(credentials.getPassword(), target.getPassport().getPassword());
            assertEquals(credentials.getRoleId(), target.getPassport().getRole().getInternalId());
            assertEquals(credentials.getAccount(), target.getPassport().getAccount());
            MessageContext messageContext = MessageContextHolder.get();
            assertNotNull(messageContext);
            List<Header> headers = (List<Header>) messageContext.get(Header.HEADER_LIST);
            assertNotNull(headers);
            Header appInfoHeader = NetSuiteWebServiceMockTestFixture.getHeader(headers, new QName(NetSuiteClientServiceImpl.NS_URI_PLATFORM_MESSAGES, "applicationInfo"));
            assertNotNull(appInfoHeader);
        }
    }))).thenReturn(response);
    NetSuiteClientService<?> clientService = webServiceMockTestFixture.getClientService();
    clientService.login();
    verify(port, times(1)).login(any(LoginRequest.class));
}
Also used : NetSuitePortType(com.netsuite.webservices.v2014_2.platform.NetSuitePortType) NetSuiteCredentials(org.talend.components.netsuite.client.NetSuiteCredentials) LoginResponse(com.netsuite.webservices.v2014_2.platform.messages.LoginResponse) Header(org.apache.cxf.headers.Header) QName(javax.xml.namespace.QName) List(java.util.List) LoginRequest(com.netsuite.webservices.v2014_2.platform.messages.LoginRequest) MessageContext(javax.xml.ws.handler.MessageContext) SessionResponse(com.netsuite.webservices.v2014_2.platform.messages.SessionResponse) AssertMatcher(org.talend.components.netsuite.test.AssertMatcher) Test(org.junit.Test)

Example 4 with SessionResponse

use of com.netsuite.webservices.v2016_2.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();
    Status status = new Status();
    status.setIsSuccess(true);
    sessionResponse.setStatus(status);
    LoginResponse response = new LoginResponse();
    response.setSessionResponse(sessionResponse);
    when(port.login(any(LoginRequest.class))).thenReturn(response);
}
Also used : Status(com.netsuite.webservices.v2016_2.platform.core.Status) LoginResponse(com.netsuite.webservices.v2016_2.platform.messages.LoginResponse) LoginRequest(com.netsuite.webservices.v2016_2.platform.messages.LoginRequest) SessionResponse(com.netsuite.webservices.v2016_2.platform.messages.SessionResponse)

Example 5 with SessionResponse

use of com.netsuite.webservices.v2016_2.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();
    Status status = new Status();
    status.setIsSuccess(true);
    sessionResponse.setStatus(status);
    LoginResponse response = new LoginResponse();
    response.setSessionResponse(sessionResponse);
    when(port.login(any(LoginRequest.class))).thenReturn(response);
}
Also used : Status(com.netsuite.webservices.v2014_2.platform.core.Status) LoginResponse(com.netsuite.webservices.v2014_2.platform.messages.LoginResponse) LoginRequest(com.netsuite.webservices.v2014_2.platform.messages.LoginRequest) SessionResponse(com.netsuite.webservices.v2014_2.platform.messages.SessionResponse)

Aggregations

LoginRequest (com.netsuite.webservices.v2014_2.platform.messages.LoginRequest)3 LoginResponse (com.netsuite.webservices.v2014_2.platform.messages.LoginResponse)3 SessionResponse (com.netsuite.webservices.v2014_2.platform.messages.SessionResponse)3 LoginRequest (com.netsuite.webservices.v2016_2.platform.messages.LoginRequest)3 LoginResponse (com.netsuite.webservices.v2016_2.platform.messages.LoginResponse)3 SessionResponse (com.netsuite.webservices.v2016_2.platform.messages.SessionResponse)3 NetSuitePortType (com.netsuite.webservices.v2014_2.platform.NetSuitePortType)2 Status (com.netsuite.webservices.v2014_2.platform.core.Status)2 NetSuitePortType (com.netsuite.webservices.v2016_2.platform.NetSuitePortType)2 Status (com.netsuite.webservices.v2016_2.platform.core.Status)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 MalformedURLException (java.net.MalformedURLException)2 SocketException (java.net.SocketException)2 RemoteException (java.rmi.RemoteException)2 List (java.util.List)2 QName (javax.xml.namespace.QName)2 WebServiceException (javax.xml.ws.WebServiceException)2 MessageContext (javax.xml.ws.handler.MessageContext)2 SOAPFaultException (javax.xml.ws.soap.SOAPFaultException)2 Header (org.apache.cxf.headers.Header)2