+ Start a Discussion
Arup SarkarArup Sarkar 

Integrating custom APEX WebService

Hi:

 

  1. I created a simple APEX web service class.
  2. Generated WSDL from the custom class.
  3. Created a Web Service client, in eclipse which generated stub, port and service locator class.

I already have enterprise.jar in my build path. When I am running it I am getting an error. Can someone please let me know where I am going wrong, My connection is working fine. Checked it.

 

package com.nb.sfdc.client;

import java.net.MalformedURLException;
import java.net.URL;
import java.rmi.RemoteException;

import javax.xml.rpc.ServiceException;

import org.apache.axis.AxisFault;

import com.sforce.soap.enterprise.Connector;
import com.sforce.soap.enterprise.EnterpriseConnection;
import com.sforce.soap.enterprise.LoginResult;
import com.sforce.soap.enterprise.fault.LoginFault;
import com.sforce.soap.schemas._class.AccountWebService.AccountWebServiceBindingStub;
import com.sforce.soap.schemas._class.AccountWebService.AccountWebServiceServiceLocator;
import com.sforce.ws.ConnectionException;
import com.sforce.ws.ConnectorConfig;

public class TestAccountWebService {

	/**
	 * @param args
	 */
	
	static ConnectorConfig config = new ConnectorConfig();
	static EnterpriseConnection connection;		
	
	public static void main(String[] args) {
		//Create a salesforce service
		LoginResult loginResult;
		System.out.println("start of program");
		try{
			
			
			config.setNtlmDomain("xxxxxx.com");
			config.setProxy("xxxxxxx.xx.com", 80);
			config.setProxyUsername("xxxxxxxxx");
			config.setProxyPassword("xxxxxxxxx");
			config.setAuthEndpoint("https://login.salesforce.com/services/Soap/c/23.0");
			config.setUsername("xxxxxxxxxxxxxxxxxx");
			config.setPassword("xxxxxxxxxxxxxxxxxx");

			connection = Connector.newConnection(config);
			System.out.println("Connected to salesforce successfully.");
			System.out.println("Authorized End Point: " + config.getAuthEndpoint());
			System.out.println("Session Id : " + config.getSessionId());

			
			//Integrate Web Service
			AccountWebServiceServiceLocator service = new AccountWebServiceServiceLocator();
			try {
				service.getAccountWebService(new URL("https://login.salesforce.com/services/Soap/c/23.0"));
			} catch (ServiceException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			AccountWebServiceBindingStub stub = new AccountWebServiceBindingStub(new URL("https://login.salesforce.com/services/Soap/c/23.0"), service);
			stub.makeAccount("Testing web account");
			

            System.out.println("after call to getSoap()");			
			
		}catch(LoginFault ex){
			ex.printStackTrace();
		}catch(ConnectionException e){
			e.printStackTrace();
		}catch(AxisFault e){
			e.printStackTrace();
		}catch(RemoteException e){
			e.printStackTrace();
		}catch(MalformedURLException e){
			e.printStackTrace();
		}
		

	}

}

 I am getting the following error.

 

AxisFault
 faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Server.userException
 faultSubcode: 
 faultString: java.net.NoRouteToHostException: No route to host: connect
 faultActor: 
 faultNode: 
 faultDetail:

 

 

@dsmith_vr@dsmith_vr

Not clear from the exception you've included where the exception is thrown on the Java side.  You should use the System Log and see if your code getAccountWebService is actually throwing an exception and see what made it over from the Java side? 

Arup SarkarArup Sarkar

I do not think it is going that far, I believe the java web service client is not able to connect to salesforce at all.