Search in sources :

Example 1 with IDiscoveryService_Execute_DiscoveryServiceFaultFault_FaultMessage

use of com.microsoft.schemas.xrm._2011.contracts.IDiscoveryService_Execute_DiscoveryServiceFaultFault_FaultMessage 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;
}
Also used : DiscoveryServiceStub(com.microsoft.schemas.xrm._2011.contracts.DiscoveryServiceStub) Options(org.apache.axis2.client.Options) OnlineAuthenticationPolicy(org.talend.ms.crm.sdk.OnlineAuthenticationPolicy) SecurityData(org.talend.ms.crm.sdk.SecurityData) IDiscoveryService_Execute_DiscoveryServiceFaultFault_FaultMessage(com.microsoft.schemas.xrm._2011.contracts.IDiscoveryService_Execute_DiscoveryServiceFaultFault_FaultMessage) WsdlTokenManager(org.talend.ms.crm.sdk.WsdlTokenManager) XMLStreamException(javax.xml.stream.XMLStreamException) RemoteException(java.rmi.RemoteException)

Example 2 with IDiscoveryService_Execute_DiscoveryServiceFaultFault_FaultMessage

use of com.microsoft.schemas.xrm._2011.contracts.IDiscoveryService_Execute_DiscoveryServiceFaultFault_FaultMessage 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;
}
Also used : KeyValuePairOfEndpointTypestringztYlk6OT(org.datacontract.schemas._2004._07.system_collections_generic.KeyValuePairOfEndpointTypestringztYlk6OT) ExecuteDocument(com.microsoft.schemas.xrm._2011.contracts.discovery.ExecuteDocument) Execute(com.microsoft.schemas.xrm._2011.contracts.discovery.ExecuteDocument.Execute) ExecuteResponseDocument(com.microsoft.schemas.xrm._2011.contracts.discovery.ExecuteResponseDocument) ExecuteResponse(com.microsoft.schemas.xrm._2011.contracts.discovery.ExecuteResponseDocument.ExecuteResponse) OrganizationDetail(com.microsoft.schemas.xrm._2011.contracts.discovery.OrganizationDetail) RetrieveOrganizationRequest(com.microsoft.schemas.xrm._2011.contracts.discovery.RetrieveOrganizationRequest) RemoteException(java.rmi.RemoteException) IDiscoveryService_Execute_DiscoveryServiceFaultFault_FaultMessage(com.microsoft.schemas.xrm._2011.contracts.IDiscoveryService_Execute_DiscoveryServiceFaultFault_FaultMessage) RetrieveOrganizationResponse(com.microsoft.schemas.xrm._2011.contracts.discovery.RetrieveOrganizationResponse)

Aggregations

IDiscoveryService_Execute_DiscoveryServiceFaultFault_FaultMessage (com.microsoft.schemas.xrm._2011.contracts.IDiscoveryService_Execute_DiscoveryServiceFaultFault_FaultMessage)2 RemoteException (java.rmi.RemoteException)2 DiscoveryServiceStub (com.microsoft.schemas.xrm._2011.contracts.DiscoveryServiceStub)1 ExecuteDocument (com.microsoft.schemas.xrm._2011.contracts.discovery.ExecuteDocument)1 Execute (com.microsoft.schemas.xrm._2011.contracts.discovery.ExecuteDocument.Execute)1 ExecuteResponseDocument (com.microsoft.schemas.xrm._2011.contracts.discovery.ExecuteResponseDocument)1 ExecuteResponse (com.microsoft.schemas.xrm._2011.contracts.discovery.ExecuteResponseDocument.ExecuteResponse)1 OrganizationDetail (com.microsoft.schemas.xrm._2011.contracts.discovery.OrganizationDetail)1 RetrieveOrganizationRequest (com.microsoft.schemas.xrm._2011.contracts.discovery.RetrieveOrganizationRequest)1 RetrieveOrganizationResponse (com.microsoft.schemas.xrm._2011.contracts.discovery.RetrieveOrganizationResponse)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 Options (org.apache.axis2.client.Options)1 KeyValuePairOfEndpointTypestringztYlk6OT (org.datacontract.schemas._2004._07.system_collections_generic.KeyValuePairOfEndpointTypestringztYlk6OT)1 OnlineAuthenticationPolicy (org.talend.ms.crm.sdk.OnlineAuthenticationPolicy)1 SecurityData (org.talend.ms.crm.sdk.SecurityData)1 WsdlTokenManager (org.talend.ms.crm.sdk.WsdlTokenManager)1