use of com.microsoft.schemas.xrm._2011.contracts.DiscoveryServiceStub in project tdi-studio-se by Talend.
the class MSCRMClient method doGetOnlineConnection.
/**
* URL for the Discovery Service For North America Microsoft account, discovery service url is
* https://dev.crm.dynamics.com/XRMServices/2011/Discovery.svc Microsoft office 365, discovery service url is
* https://disco.crm.dynamics.com/XRMServices/2011/Discovery.svc To use appropriate discovery service url for other
* environments refer http://technet.microsoft.com/en-us/library/gg309401.aspx
*
* @throws Exception
*/
public OrganizationServiceStub doGetOnlineConnection(String discoveryServiceURL) throws Exception {
try {
// Retrieve the authentication policy for the discovery service.
OnlineAuthenticationPolicy discoveryPolicy = new OnlineAuthenticationPolicy(discoveryServiceURL + FlatWSDLSuffix);
WsdlTokenManager discoeryTokenManager = new WsdlTokenManager();
// Authenticate the user using the discovery authentication policy.
SecurityData discoverySecurityData = discoeryTokenManager.authenticate(discoveryServiceURL, username, password, discoveryPolicy.getAppliesTo(), discoveryPolicy.getPolicy(), discoveryPolicy.getIssuerUri());
// Retrieve discovery stub using organization URL with the security data.
DiscoveryServiceStub discoveryServiceStub = createDiscoveryServiceStub(discoveryServiceURL, discoverySecurityData);
// Retrieve organization service url using discovery stub.
String orgUrl = discoverOrganizationUrl(discoveryServiceStub, orgName);
// The discovery service stub cannot be reused against the organization service
// as the Issuer and AppliesTo may differ between the discovery and organization services.
// Retrieve the authentication policy for the organization service.
OnlineAuthenticationPolicy organizationPolicy = new OnlineAuthenticationPolicy(orgUrl + FlatWSDLSuffix);
WsdlTokenManager orgTokenManager = new WsdlTokenManager();
// Authenticate the user using the organization authentication policy.
SecurityData securityData = orgTokenManager.authenticate(orgUrl, username, password, organizationPolicy.getAppliesTo(), organizationPolicy.getPolicy(), organizationPolicy.getIssuerUri());
// Retrieve organization stub using organization URL with the security data.
serviceStub = createOrganizationServiceStub(orgUrl, securityData);
Options options = serviceStub._getServiceClient().getOptions();
if (reuseHttpClient != null) {
options.setProperty(org.apache.axis2.transport.http.HTTPConstants.REUSE_HTTP_CLIENT, reuseHttpClient);
}
if (timeout != null) {
options.setTimeOutInMilliSeconds(Long.valueOf(timeout));
options.setProperty(org.apache.axis2.transport.http.HTTPConstants.SO_TIMEOUT, timeout);
options.setProperty(org.apache.axis2.transport.http.HTTPConstants.CONNECTION_TIMEOUT, timeout);
}
} catch (IDiscoveryService_Execute_DiscoveryServiceFaultFault_FaultMessage e) {
throw new Exception(e.getFaultMessage().getDiscoveryServiceFault().getMessage());
}
return serviceStub;
}
use of com.microsoft.schemas.xrm._2011.contracts.DiscoveryServiceStub in project tdi-studio-se by Talend.
the class MSCRMClient method createDiscoveryServiceStub.
private static DiscoveryServiceStub createDiscoveryServiceStub(String discoveryServiceURL, SecurityData securityData) throws RemoteException, XMLStreamException {
try {
DiscoveryServiceStub stub = new DiscoveryServiceStub(getConfigurationContext(), discoveryServiceURL);
setServiceClientOptions(stub._getServiceClient(), securityData);
return stub;
} catch (RemoteException e) {
logger.error(e.getMessage());
throw e;
}
}
use of com.microsoft.schemas.xrm._2011.contracts.DiscoveryServiceStub in project tdi-studio-se by Talend.
the class MSCRMClient method discoverOrganizationUrl.
private static String discoverOrganizationUrl(DiscoveryServiceStub serviceStub, String organizationUniqueName) throws RemoteException, IDiscoveryService_Execute_DiscoveryServiceFaultFault_FaultMessage {
try {
RetrieveOrganizationRequest request = RetrieveOrganizationRequest.Factory.newInstance();
request.setUniqueName(organizationUniqueName);
Execute exe = Execute.Factory.newInstance();
exe.setRequest(request);
ExecuteDocument exeDoc = ExecuteDocument.Factory.newInstance();
exeDoc.setExecute(exe);
ExecuteResponseDocument executeRespDoc = serviceStub.execute(exeDoc);
ExecuteResponse executeResp = executeRespDoc.getExecuteResponse();
RetrieveOrganizationResponse result = (RetrieveOrganizationResponse) executeResp.getExecuteResult();
OrganizationDetail orgDetail = result.getDetail();
KeyValuePairOfEndpointTypestringztYlk6OT[] keyValuePairs = orgDetail.getEndpoints().getKeyValuePairOfEndpointTypestringztYlk6OTArray();
for (KeyValuePairOfEndpointTypestringztYlk6OT keyValuePair : keyValuePairs) {
if (keyValuePair.getKey() == EndpointType.ORGANIZATION_SERVICE) {
return keyValuePair.getValue();
}
}
} catch (RemoteException e) {
logger.error(e.getMessage());
throw e;
} catch (IDiscoveryService_Execute_DiscoveryServiceFaultFault_FaultMessage e) {
logger.error(e.getMessage());
throw e;
}
return null;
}
Aggregations