function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
rohits83rohits83 

Problem while connecting to Enterprise API using java (Axis)

I'm trying to connect the salesforce API by creating a web service client in java (Axis).

 

I'm behind proxy and I have set the property that is required for connecting a web service for proxy

The code that I'm using is 

 

            binding = (SoapBindingStub) new SforceServiceLocator().getSoap();

            binding._setProperty("http.proxySet", "true");
            binding._setProperty("http.proxyHost", <proxy-host>);
            binding._setProperty("http.proxyPort", <proxy-port>);

 

 

 I'm calling the login function given below

 

            Login login = new Login();
            login.setUsername(<username>);
            login.setPassword(<password>);
            LoginResult lr = binding.login(username, password);
 

 

I have added the following jars in my classpath :

 

jaxrpc.jar
axis.jar
commons-discovery-0.2.jar
commons-logging.jar
wsdl4j-1.5.1.jar
commons-httpclient-3.0-rc4.jar

I'm getting the following error while calling the login function 

 


AxisFault
 faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Server.userException
 faultSubcode:
 faultString: java.net.UnknownHostException: test.salesforce.com
 faultActor:
 faultNode:
 faultDetail:
    {http://xml.apache.org/axis/}stackTrace:java.net.UnknownHostException: test.salesforce.com
    at java.net.PlainSocketImpl.connect(Unknown Source)
    at java.net.SocksSocketImpl.connect(Unknown Source)
    at java.net.Socket.connect(Unknown Source)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.apache.axis.components.net.DefaultSocketFactory.create(DefaultSocketFactory.java:153)
    at org.apache.axis.components.net.DefaultSocketFactory.create(DefaultSocketFactory.java:120)
    at org.apache.axis.transport.http.HTTPSender.getSocket(HTTPSender.java:191)

 

Can someone please help me how can I resolve the problem...

 

Thanks!!!

Best Answer chosen by Admin (Salesforce Developers) 
rohits83rohits83

I'm able to connect to the salesforce.com ...

 

The problem was rectified by adding the ip address of salesforce.com to the HOST file.

 

 

Thanks for your Help!!!

All Answers

LosintikfosLosintikfos

Your exception is pretty obvious:

 

 

faultString: java.net.UnknownHostException: test.salesforce.com

You are definitely trying to connect to an unknown host which in this case is the salesforce sandbox/production, which ever enviroment you're trying to connect to.

 

I think sandbox should be:

https://cs2.salesforce.com/services/Soap/c/17.0/0DF20000000Tqps

 

and production should b:

https://www.salesforce.com/services/Soap/c/17.0/0DF20000000Tqps.

 


 

 

To correct this:

Open the SforceServiceStub and replace all http/https connection to above.

 

 

Message Edited by Losintikfos on 11-12-2009 03:16 AM
rohits83rohits83

No the URL that I'm trying to connect is correct i.e. test.salesforce.com. I'm trying to connect to sandbox.

 

Same URL is in WSDL, I also tried with the URL that you mentioned with the same problem

 

Can someone suggest what may be the problem

LosintikfosLosintikfos

I can see what you're saying - because the URL is the WSDL you're refusing to debug hence listening to advice. The exception you posted says:

 

{http://xml.apache.org/axis/}stackTrace:java.net.UnknownHostException: test.salesforce.com

 Do you know what it means? it means the SOAP request document contains the wrong URL hence the one in the WSDL, which in your case is test.salesforce.com. You either try do what i said ealier or i am out.

 

 

Message Edited by Losintikfos on 11-12-2009 04:33 AM
rohits83rohits83

First of all thanks for your help!

I forgot to mentioned in my previous post that I had modified the end point URL to the sandbox URL mentioned by you but got the same error message

 

 The error message was

faultString: java.net.UnknownHostException: cs2.salesforce.com

 

I had created the web service client in eclipse and the soap address was modified in SforceServiceLocator class to the URL you had mentioned.

Please advice.

LosintikfosLosintikfos

Best way to findout the URL is if you login to salesforce sandbox - click on Setup -> Develop ->API ->enterprise wsdl. Scroll to the bottom of the WSDL and you should see correct URL. If this is different from what you have currently, then i suggest you regenerate your stubs, and then try invoke the service again.

rohits83rohits83

The URL in WSDL is - https://test.salesforce.com/services/Soap/c/17.0 

 

and the enterprise WSDL was retrieved from the location you have mentioned in the post before generating the web service client.

LosintikfosLosintikfos

Good!

 

Now we can limit it down to the proxy. If you hit the URL you've just supplied in your browser address line, what message do you get?

SuperfellSuperfell
It would appear that your request are not using the proxy, hence the error, you should double check that the property names are correct (you might need to set the system level settings, rather than just on the stub, IIRC, this differs between the regular axis http client and the commons-http based client)
SuperfellSuperfell
oh, and test.salesforce.com is the correct host for sandbox logins.
rohits83rohits83

I'm able to connect to the salesforce.com ...

 

The problem was rectified by adding the ip address of salesforce.com to the HOST file.

 

 

Thanks for your Help!!!

This was selected as the best answer