none
Dynamices CRM http connect failed with java: org.apache.axis2.AxisFault: Transport error: 401 Error: Unauthorized RRS feed

  • 问题

  • hi:

    I tried to create account with below java code, but get error 401 Error: Unauthorized. Is there any advise? thanks!

    public static void main(String[] args) throws Exception {
    private static final String UserName = "****";
    private static final String UserPassword = "*****";
    private static final String OrganizationServiceURL = "https://****:443/CRMORG/XRMServices/2011/Organization.svc/web";

    OrganizationServiceStub stub=new OrganizationServiceStub(OrganizationServiceURL);
    org.apache.axis2.client.Options opt = stub._getServiceClient().getOptions();
           EndpointReference epr = new EndpointReference(OrganizationServiceURL);
           opt.setTo(epr); 
           opt.setProperty(HTTPConstants.SO_TIMEOUT, new Integer(300000));
           HttpTransportProperties.Authenticator authenticator = new HttpTransportProperties.Authenticator();
           List<String> auth = new ArrayList<String>();
           auth.add(Authenticator.BASIC);
           authenticator.setAuthSchemes(auth);
           authenticator.setUsername(UserName);
           authenticator.setPassword(UserPassword);
           authenticator.setHost("16.16.95.248");
           authenticator.setPort(80);
           authenticator.setPreemptiveAuthentication(true);
           opt.setProperty(HTTPConstants.AUTHENTICATE, authenticator);
           stub._getServiceClient().setOptions(opt);

           
    Create create=new Create();
    Entity param=new Entity();
    param.setLogicalName("account");
    EntityState entityState=new EntityState("",true);
    param.setEntityState(entityState);
    Guid guid=new Guid();
    guid.setGuid("00000000-0000-0000-0000-000000000000");
    param.setId(guid);
    AttributeCollection attributeCollection=new AttributeCollection();
    KeyValuePairOfstringanyType[] keyValuePairTypes=new KeyValuePairOfstringanyType[1];
    keyValuePairTypes[0]=new KeyValuePairOfstringanyType();
    keyValuePairTypes[0].setKey("name");
    keyValuePairTypes[0].setValue("account1");
    attributeCollection.setKeyValuePairOfstringanyType(keyValuePairTypes);
    param.setAttributes(attributeCollection);
    create.setEntity(param);
    stub.create(create);

    }

    the error details:

    org.apache.axis2.AxisFault: Transport error: 401 Error: Unauthorized
    at org.apache.axis2.transport.http.HTTPSender.handleResponse(HTTPSender.java:310)
    at org.apache.axis2.transport.http.HTTPSender.sendViaPost(HTTPSender.java:194)
    at org.apache.axis2.transport.http.HTTPSender.send(HTTPSender.java:75)
    at org.apache.axis2.transport.http.CommonsHTTPTransportSender.writeMessageWithCommons(CommonsHTTPTransportSender.java:404)
    at org.apache.axis2.transport.http.CommonsHTTPTransportSender.invoke(CommonsHTTPTransportSender.java:231)
    at org.apache.axis2.engine.AxisEngine.send(AxisEngine.java:443)
    at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:406)
    at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:229)
    at org.apache.axis2.client.OperationClient.execute(OperationClient.java:165)
    at java2crmpack.OrganizationServiceStub.create(OrganizationServiceStub.java:337)
    at java2crmpack.test.main(test.java:113)

    2013年9月4日 7:49

全部回复

  • Java Connection Dynamics CRM 2011 Webservices with Axis2

    Same trouble to me

    你是如何解决该问题的?能否给我一份调试通过的源码?

    How do you handle with this problem?

    Give a copy code to me(project best)

    3Q~

    Thanks~

    Email: 745356640@qq.com
    • 已编辑 Percy0601 2014年4月3日 7:46 补充邮箱
    2014年4月3日 7:45