// This value identifies Teiid as a SF certified solution.
// It was provided by SF and should not be changed.
co.setClient("RedHat/MetaMatrix/"); //$NON-NLS-1$
if(url == null) {
throw new ResourceException("SalesForce URL is not specified, please provide a valid URL"); //$NON-NLS-1$
}
Bus bus = BusFactory.getThreadDefaultBus();
BusFactory.setThreadDefaultBus(mcf.getBus());
try {
sfService = new SforceService();
sfSoap = sfService.getSoap();
((BindingProvider)sfSoap).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, url.toExternalForm());
loginResult = sfSoap.login(username, password);
} catch (LoginFault e) {
throw new ResourceException(e);
} catch (InvalidIdFault e) {
throw new ResourceException(e);
} catch (com.sforce.soap.partner.UnexpectedErrorFault e) {
throw new ResourceException(e);
} finally {
BusFactory.setThreadDefaultBus(bus);
}
LogManager.logTrace(LogConstants.CTX_CONNECTOR, "Login was successful for username " + username); //$NON-NLS-1$
sh = new SessionHeader();
sh.setSessionId(loginResult.getSessionId());
// Reset the SOAP endpoint to the returned server URL
((BindingProvider)sfSoap).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,loginResult.getServerUrl());
// or maybe org.apache.cxf.message.Message.ENDPOINT_ADDRESS
((BindingProvider)sfSoap).getRequestContext().put(BindingProvider.SESSION_MAINTAIN_PROPERTY,Boolean.TRUE);
// Set the timeout.
//((BindingProvider)sfSoap).getRequestContext().put(JAXWSProperties.CONNECT_TIMEOUT, timeout);
// Test the connection.
try {
sfSoap.getUserInfo(sh);
} catch (com.sforce.soap.partner.UnexpectedErrorFault e) {
throw new ResourceException(e);
}
}
}