Search in sources :

Example 6 with NetSuiteErrorCode

use of org.talend.components.netsuite.NetSuiteErrorCode in project components by Talend.

the class NetSuiteClientService method setLoginHeaders.

/**
 * Set log-in specific SOAP headers for given port.
 *
 * @param port port
 * @throws NetSuiteException if an error occurs during performing of operation
 */
protected void setLoginHeaders(PortT port) throws NetSuiteException {
    if (!StringUtils.isEmpty(credentials.getApplicationId())) {
        Object applicationInfo = createNativeApplicationInfo(credentials);
        try {
            if (applicationInfo != null) {
                Header appInfoHeader = new Header(new QName(getPlatformMessageNamespaceUri(), "applicationInfo"), applicationInfo, new JAXBDataBinding(applicationInfo.getClass()));
                setHeader(port, appInfoHeader);
            }
        } catch (JAXBException e) {
            throw new NetSuiteException(new NetSuiteErrorCode(NetSuiteErrorCode.INTERNAL_ERROR), "XML binding error", e);
        }
    }
}
Also used : NetSuiteErrorCode(org.talend.components.netsuite.NetSuiteErrorCode) Header(org.apache.cxf.headers.Header) QName(javax.xml.namespace.QName) JAXBException(javax.xml.bind.JAXBException) JAXBDataBinding(org.apache.cxf.jaxb.JAXBDataBinding)

Example 7 with NetSuiteErrorCode

use of org.talend.components.netsuite.NetSuiteErrorCode in project components by Talend.

the class NetSuiteWriteOperation method createWriter.

@Override
public Writer<Result> createWriter(RuntimeContainer adaptor) {
    NetSuiteClientService clientService = sink.getClientService();
    OutputAction action = properties.module.action.getValue();
    Schema schema = properties.module.main.schema.getValue();
    MetaDataSource originalMetaDataSource = clientService.getMetaDataSource();
    MetaDataSource metaDataSource = clientService.createDefaultMetaDataSource();
    metaDataSource.setCustomizationEnabled(originalMetaDataSource.isCustomizationEnabled());
    SchemaCustomMetaDataSource schemaCustomMetaDataSource = new SchemaCustomMetaDataSource(clientService.getBasicMetaData(), originalMetaDataSource.getCustomMetaDataSource(), schema);
    metaDataSource.setCustomMetaDataSource(schemaCustomMetaDataSource);
    NetSuiteOutputWriter<?, ?> writer;
    switch(action) {
        case ADD:
            writer = new NetSuiteAddWriter<>(this, adaptor, metaDataSource);
            break;
        case UPDATE:
            writer = new NetSuiteUpsertWriter<>(this, adaptor, metaDataSource);
            break;
        case UPSERT:
            writer = new NetSuiteUpsertWriter<>(this, adaptor, metaDataSource);
            Boolean useNativeUpsert = properties.module.useNativeUpsert.getValue();
            if (useNativeUpsert != null) {
                ((NetSuiteUpsertWriter) writer).setUseNativeUpsert(useNativeUpsert);
            }
            break;
        case DELETE:
            writer = new NetSuiteDeleteWriter<>(this, adaptor, metaDataSource);
            break;
        default:
            throw new NetSuiteException(new NetSuiteErrorCode(NetSuiteErrorCode.INTERNAL_ERROR), NetSuiteRuntimeI18n.MESSAGES.getMessage("error.outputOperationNotImplemented", action));
    }
    Integer batchSize = properties.batchSize.getValue();
    if (batchSize != null) {
        writer.setBatchSize(batchSize);
    }
    Boolean dieOnError = properties.dieOnError.getValue();
    if (dieOnError != null) {
        writer.setExceptionForErrors(dieOnError);
    }
    return writer;
}
Also used : Schema(org.apache.avro.Schema) SchemaCustomMetaDataSource(org.talend.components.netsuite.SchemaCustomMetaDataSource) NetSuiteClientService(org.talend.components.netsuite.client.NetSuiteClientService) NetSuiteException(org.talend.components.netsuite.client.NetSuiteException) NetSuiteErrorCode(org.talend.components.netsuite.NetSuiteErrorCode) MetaDataSource(org.talend.components.netsuite.client.MetaDataSource) SchemaCustomMetaDataSource(org.talend.components.netsuite.SchemaCustomMetaDataSource)

Example 8 with NetSuiteErrorCode

use of org.talend.components.netsuite.NetSuiteErrorCode in project components by Talend.

the class SearchDateFieldAdapter method convertDateTime.

protected XMLGregorianCalendar convertDateTime(String input) {
    String valueToParse = input;
    String dateTimeFormatPattern = dateFormatPattern + " " + timeFormatPattern;
    if (input.length() == dateFormatPattern.length()) {
        dateTimeFormatPattern = dateFormatPattern;
    } else if (input.length() == timeFormatPattern.length()) {
        DateTime dateTime = new DateTime();
        DateTimeFormatter dateFormatter = DateTimeFormat.forPattern(dateFormatPattern);
        valueToParse = dateFormatter.print(dateTime) + " " + input;
    }
    DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern(dateTimeFormatPattern);
    DateTime dateTime;
    try {
        dateTime = dateTimeFormatter.parseDateTime(valueToParse);
    } catch (IllegalArgumentException e) {
        throw new NetSuiteException(new NetSuiteErrorCode(NetSuiteErrorCode.CLIENT_ERROR), NetSuiteRuntimeI18n.MESSAGES.getMessage("error.searchDateField.invalidDateTimeFormat", valueToParse));
    }
    XMLGregorianCalendar xts = datatypeFactory.newXMLGregorianCalendar();
    xts.setYear(dateTime.getYear());
    xts.setMonth(dateTime.getMonthOfYear());
    xts.setDay(dateTime.getDayOfMonth());
    xts.setHour(dateTime.getHourOfDay());
    xts.setMinute(dateTime.getMinuteOfHour());
    xts.setSecond(dateTime.getSecondOfMinute());
    xts.setMillisecond(dateTime.getMillisOfSecond());
    xts.setTimezone(dateTime.getZone().toTimeZone().getOffset(dateTime.getMillis()) / 60000);
    return xts;
}
Also used : NetSuiteErrorCode(org.talend.components.netsuite.NetSuiteErrorCode) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) NetSuiteException(org.talend.components.netsuite.client.NetSuiteException) DateTimeFormatter(org.joda.time.format.DateTimeFormatter) DateTime(org.joda.time.DateTime)

Example 9 with NetSuiteErrorCode

use of org.talend.components.netsuite.NetSuiteErrorCode in project components by Talend.

the class NetSuiteClientServiceImpl method getNetSuitePort.

protected NetSuitePortType getNetSuitePort(String defaultEndpointUrl, String account) throws NetSuiteException {
    try {
        URL wsdlLocationUrl = this.getClass().getResource("/wsdl/2016.2/netsuite.wsdl");
        NetSuiteService service = new NetSuiteService(wsdlLocationUrl, NetSuiteService.SERVICE);
        List<WebServiceFeature> features = new ArrayList<>(2);
        if (isMessageLoggingEnabled()) {
            features.add(new LoggingFeature());
        }
        NetSuitePortType port = service.getNetSuitePort(features.toArray(new WebServiceFeature[features.size()]));
        BindingProvider provider = (BindingProvider) port;
        Map<String, Object> requestContext = provider.getRequestContext();
        requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, defaultEndpointUrl);
        GetDataCenterUrlsRequest dataCenterRequest = new GetDataCenterUrlsRequest();
        dataCenterRequest.setAccount(account);
        DataCenterUrls urls = null;
        GetDataCenterUrlsResponse response = port.getDataCenterUrls(dataCenterRequest);
        if (response != null && response.getGetDataCenterUrlsResult() != null) {
            urls = response.getGetDataCenterUrlsResult().getDataCenterUrls();
        }
        if (urls == null) {
            throw new NetSuiteException(new NetSuiteErrorCode(NetSuiteErrorCode.CLIENT_ERROR), NetSuiteRuntimeI18n.MESSAGES.getMessage("error.couldNotGetWebServiceDomain", defaultEndpointUrl));
        }
        String wsDomain = urls.getWebservicesDomain();
        String endpointUrl = wsDomain.concat(new URL(defaultEndpointUrl).getPath());
        requestContext.put(BindingProvider.SESSION_MAINTAIN_PROPERTY, true);
        requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpointUrl);
        return port;
    } catch (WebServiceException | MalformedURLException | InsufficientPermissionFault | InvalidCredentialsFault | InvalidSessionFault | UnexpectedErrorFault | ExceededRequestSizeFault e) {
        throw new NetSuiteException(new NetSuiteErrorCode(NetSuiteErrorCode.CLIENT_ERROR), NetSuiteRuntimeI18n.MESSAGES.getMessage("error.failedToInitClient", e.getLocalizedMessage()), e);
    }
}
Also used : InsufficientPermissionFault(com.netsuite.webservices.v2016_2.platform.InsufficientPermissionFault) InvalidCredentialsFault(com.netsuite.webservices.v2016_2.platform.InvalidCredentialsFault) MalformedURLException(java.net.MalformedURLException) WebServiceException(javax.xml.ws.WebServiceException) GetDataCenterUrlsResponse(com.netsuite.webservices.v2016_2.platform.messages.GetDataCenterUrlsResponse) ArrayList(java.util.ArrayList) DataCenterUrls(com.netsuite.webservices.v2016_2.platform.core.DataCenterUrls) NetSuiteException(org.talend.components.netsuite.client.NetSuiteException) UnexpectedErrorFault(com.netsuite.webservices.v2016_2.platform.UnexpectedErrorFault) BindingProvider(javax.xml.ws.BindingProvider) InvalidSessionFault(com.netsuite.webservices.v2016_2.platform.InvalidSessionFault) URL(java.net.URL) NetSuitePortType(com.netsuite.webservices.v2016_2.platform.NetSuitePortType) NetSuiteErrorCode(org.talend.components.netsuite.NetSuiteErrorCode) NetSuiteService(com.netsuite.webservices.v2016_2.platform.NetSuiteService) LoggingFeature(org.apache.cxf.feature.LoggingFeature) WebServiceFeature(javax.xml.ws.WebServiceFeature) GetDataCenterUrlsRequest(com.netsuite.webservices.v2016_2.platform.messages.GetDataCenterUrlsRequest) ExceededRequestSizeFault(com.netsuite.webservices.v2016_2.platform.ExceededRequestSizeFault)

Example 10 with NetSuiteErrorCode

use of org.talend.components.netsuite.NetSuiteErrorCode in project components by Talend.

the class NetSuiteClientServiceImpl method doLogin.

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.v2014_2.platform.core.Status) NsStatus(org.talend.components.netsuite.client.NsStatus) InvalidCredentialsFault(com.netsuite.webservices.v2014_2.platform.InvalidCredentialsFault) LoginResponse(com.netsuite.webservices.v2014_2.platform.messages.LoginResponse) NetSuiteException(org.talend.components.netsuite.client.NetSuiteException) UnexpectedErrorFault(com.netsuite.webservices.v2014_2.platform.UnexpectedErrorFault) LoginRequest(com.netsuite.webservices.v2014_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.v2014_2.platform.NetSuitePortType) NetSuiteErrorCode(org.talend.components.netsuite.NetSuiteErrorCode) Passport(com.netsuite.webservices.v2014_2.platform.core.Passport) SessionResponse(com.netsuite.webservices.v2014_2.platform.messages.SessionResponse)

Aggregations

NetSuiteErrorCode (org.talend.components.netsuite.NetSuiteErrorCode)10 NetSuiteException (org.talend.components.netsuite.client.NetSuiteException)7 MalformedURLException (java.net.MalformedURLException)5 WebServiceException (javax.xml.ws.WebServiceException)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 SocketException (java.net.SocketException)3 RemoteException (java.rmi.RemoteException)3 SOAPFaultException (javax.xml.ws.soap.SOAPFaultException)3 NetSuitePortType (com.netsuite.webservices.v2014_2.platform.NetSuitePortType)2 UnexpectedErrorFault (com.netsuite.webservices.v2014_2.platform.UnexpectedErrorFault)2 InvalidCredentialsFault (com.netsuite.webservices.v2016_2.platform.InvalidCredentialsFault)2 NetSuitePortType (com.netsuite.webservices.v2016_2.platform.NetSuitePortType)2 UnexpectedErrorFault (com.netsuite.webservices.v2016_2.platform.UnexpectedErrorFault)2 URL (java.net.URL)2 ArrayList (java.util.ArrayList)2 JAXBException (javax.xml.bind.JAXBException)2 QName (javax.xml.namespace.QName)2 BindingProvider (javax.xml.ws.BindingProvider)2 WebServiceFeature (javax.xml.ws.WebServiceFeature)2 LoggingFeature (org.apache.cxf.feature.LoggingFeature)2