use of org.talend.components.netsuite.NetSuiteErrorCode 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);
}
use of org.talend.components.netsuite.NetSuiteErrorCode 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);
}
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/2014.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 | UnexpectedErrorFault | ExceededRequestSizeFault e) {
throw new NetSuiteException(new NetSuiteErrorCode(NetSuiteErrorCode.CLIENT_ERROR), NetSuiteRuntimeI18n.MESSAGES.getMessage("error.failedToInitClient", e.getLocalizedMessage()), e);
}
}
use of org.talend.components.netsuite.NetSuiteErrorCode in project components by Talend.
the class NetSuiteClientService method checkLoginError.
/**
* Check 'log-in' operation status and throw {@link NetSuiteException} if status indicates that
* an error occurred or exception message is present.
*
* @param status status object to be checked, if present
* @param exceptionMessage exception message, if present
*/
protected void checkLoginError(NsStatus status, String exceptionMessage) {
if (status == null || !status.isSuccess()) {
StringBuilder sb = new StringBuilder();
if (status != null && status.getDetails().size() > 0) {
NsStatus.Detail detail = status.getDetails().get(0);
sb.append(detail.getCode()).append(" ").append(detail.getMessage());
} else if (exceptionMessage != null) {
sb.append(exceptionMessage);
}
throw new NetSuiteException(new NetSuiteErrorCode(NetSuiteErrorCode.CLIENT_ERROR), NetSuiteRuntimeI18n.MESSAGES.getMessage("error.failedToLogin", sb));
}
}
use of org.talend.components.netsuite.NetSuiteErrorCode in project components by Talend.
the class NetSuiteClientService method setPreferences.
/**
* Set preferences for given port.
*
* @param port port which to set preferences for
* @param nsPreferences general preferences
* @param nsSearchPreferences search preferences
* @throws NetSuiteException if an error occurs during performing of operation
*/
protected void setPreferences(PortT port, NsPreferences nsPreferences, NsSearchPreferences nsSearchPreferences) throws NetSuiteException {
Object searchPreferences = createNativeSearchPreferences(nsSearchPreferences);
Object preferences = createNativePreferences(nsPreferences);
try {
Header searchPreferencesHeader = new Header(new QName(getPlatformMessageNamespaceUri(), "searchPreferences"), searchPreferences, new JAXBDataBinding(searchPreferences.getClass()));
Header preferencesHeader = new Header(new QName(getPlatformMessageNamespaceUri(), "preferences"), preferences, new JAXBDataBinding(preferences.getClass()));
setHeader(port, preferencesHeader);
setHeader(port, searchPreferencesHeader);
} catch (JAXBException e) {
throw new NetSuiteException(new NetSuiteErrorCode(NetSuiteErrorCode.INTERNAL_ERROR), "XML binding error", e);
}
}
Aggregations