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
orikkerorikker 

ConnectionException

Ok. I give up... What am I doing wrong? 

 

 

package comEJMSandbox;


	import com.sforce.soap.enterprise.EnterpriseConnection;
	import com.sforce.soap.enterprise.GetUserInfoResult;
	import com.sforce.ws.*;

	public class testLogin {
		
	  
	  

	  public static void main(String[] args) {
		
		  ConnectorConfig config = new ConnectorConfig();
	      config.setUsername("admin@salesforce.com");
	      config.setPassword("password");
	      
	      config.setAuthEndpoint("https://login.salesforce.com/services/Soap/c/20.0");
	      EnterpriseConnection connection;
	      try {
	    	  connection = new EnterpriseConnection(config);
	          GetUserInfoResult userInfo = connection.getUserInfo();
	          System.out.println("\nLogging in ...\n");
	          System.out.println("UserID: " + userInfo.getUserId());
	          System.out.println("User Full Name: " + 
	              userInfo.getUserFullName());
	          System.out.println("User Email: " + 
	              userInfo.getUserEmail());
	          System.out.println();
	          System.out.println("SessionID: " + 
	              config.getSessionId());
	          System.out.println("Auth End Point: " + 
	              config.getAuthEndpoint());
	          System.out.println("Service End Point: " + 
	              config.getServiceEndpoint());
	          System.out.println();
	         
	        } catch (ConnectionException ce) {
	        	ce.printStackTrace();
	        }
		
		
		  
	    
	  }	  
	  
}

 

I get this error

 

 

com.sforce.ws.ConnectionException: Unexpected element. Parser was expecting element 'urn:enterprise.soap.sforce.com:orgAttachmentFileSizeLimit' but found 'urn:enterprise.soap.sforce.com:orgDefaultCurrencyIsoCode'
	at com.sforce.ws.bind.TypeMapper.verifyTag(TypeMapper.java:386)
	at com.sforce.ws.bind.TypeMapper.verifyElement(TypeMapper.java:415)
	at com.sforce.soap.enterprise.GetUserInfoResult.loadFields(GetUserInfoResult.java:1)
	at com.sforce.soap.enterprise.GetUserInfoResult.load(GetUserInfoResult.java:1)
	at com.sforce.ws.bind.TypeMapper.readSingle(TypeMapper.java:628)
	at com.sforce.ws.bind.TypeMapper.readObject(TypeMapper.java:504)
	at com.sforce.soap.enterprise.LoginResult.loadFields(LoginResult.java:1)
	at com.sforce.soap.enterprise.LoginResult.load(LoginResult.java:1)
	at com.sforce.ws.bind.TypeMapper.readSingle(TypeMapper.java:628)
	at com.sforce.ws.bind.TypeMapper.readObject(TypeMapper.java:504)
	at com.sforce.soap.enterprise.LoginResponse_element.loadFields(LoginResponse_element.java:1)
	at com.sforce.soap.enterprise.LoginResponse_element.load(LoginResponse_element.java:1)
	at com.sforce.ws.bind.TypeMapper.readSingle(TypeMapper.java:628)
	at com.sforce.ws.bind.TypeMapper.readObject(TypeMapper.java:504)
	at com.sforce.ws.transport.SoapConnection.bind(SoapConnection.java:170)
	at com.sforce.ws.transport.SoapConnection.receive(SoapConnection.java:144)
	at com.sforce.ws.transport.SoapConnection.send(SoapConnection.java:98)
	at com.sforce.soap.enterprise.EnterpriseConnection.login(EnterpriseConnection.java:1)
	at com.sforce.soap.enterprise.EnterpriseConnection.<init>(EnterpriseConnection.java:1)
	at comEJMSandbox.testLogin.main(testLogin.java:22)

 

 

 

Best Answer chosen by Admin (Salesforce Developers) 
SuperfellSuperfell

You can use any version of WSC, whats important is that the endpoint you connect to is the same version as the version of the WSDL you used to generate your client code.

All Answers

SuperfellSuperfell

You are using one version of the WSDL, but sending your request to a different version, make sure you're setting the correct authEndpoint URL for the version of the WSDL you're using.

orikkerorikker

That is what I thought, but not sure if it's the case. WSDL is from EE sandbox and the end point is for sandbox... both end point and wsdl are for enterprise connection... Does version matter? the only WSC on wiki is version 20, but WSDL is generated for v 21... Does this matter? if it does, how can I get the WSC-21.jar?  

SuperfellSuperfell

Yes version matters.

orikkerorikker

Is there a way to genereate my own WSC-21.jar then? I only see  wsc-20.jar on google code site...

SuperfellSuperfell

You can use any version of WSC, whats important is that the endpoint you connect to is the same version as the version of the WSDL you used to generate your client code.

This was selected as the best answer
orikkerorikker

right on! it worked.

 

Thank you.

Force.comForce.com

 

Hello,
This is my code for calling salesforce from java. I am also getting an exception which is very similar to the one you were getting.
The sample code is:
import com.sforce.soap.enterprise.EnterpriseConnection;
import com.sforce.ws.ConnectorConfig;
import com.sforce.soap.enterprise.GetUserInfoResult;
import com.sforce.ws.ConnectionException;

public class TestClient {
 public static void main(String[] args) {
 String userName = "test.com.tbs";
 String pwd = "testing"+securityToken;
 EnterpriseConnection connection;
 ConnectorConfig config = new ConnectorConfig();
 config.setUsername(userName);
 config.setPassword(pwd);
 config.setAuthEndpoint("https://cs1-api.salesforce.com/services/Soap/c/21.0");
//config.setServiceEndpoint("https://cs6-api.salesforce.com/services/Soap/c/20.0");
//config.setServiceEndpoint("http://soap.sforce.com/schemas/class/Billing_Integration");
 try {
  connection = new EnterpriseConnection(config);
  GetUserInfoResult userInfo = connection.getUserInfo();
  System.out.println("UserID: " + userInfo.getUserId());
  System.out.println();
  config.setTraceMessage(true);
  //SoapConnection connection = Connector.newConnection(config);
  System.out.println("SessionHeader: " + config.getSessionid());
  System.out.println("Auth End Point: " + config.getAuthEndpoint());
  System.out.println("Service End Point: " + config.getServiceEndpoint());
     } 
    catch (ConnectionException ce) {
    	 ce.printStackTrace();
       System.out.println("exception is" + ce);
    }
  }
}

 

Few lines of  Enterprise Wsdl is:
<?xml version="1.0" encoding="UTF-8"?>


<!--
Salesforce.com Enterprise Web Services API Version 21.0
Generated on 2011-03-07 04:40:19 +0000.

Package Versions:
Salesforce for Google AdWords (Version: 166.1, Namespace: sfga)

Copyright 1999-2011 salesforce.com, inc.
All Rights Reserved
-->

<definitions targetNamespace="urn:enterprise.soap.sforce.com"
             xmlns="http://schemas.xmlsoap.org/wsdl/"
             xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
             xmlns:xsd="http://www.w3.org/2001/XMLSchema"
             xmlns:tns="urn:enterprise.soap.sforce.com"
             xmlns:fns="urn:fault.enterprise.soap.sforce.com"
             xmlns:ens="urn:sobject.enterprise.soap.sforce.com">
    <types>

        <schema elementFormDefault="qualified" xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="urn:sobject.enterprise.soap.sforce.com">

            <import namespace="urn:enterprise.soap.sforce.com"/>

 

I tried with both versions : "20" and "21" by setting them in "authEndPoint" string in the java code. Still I am getting the following exception:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/axis/AxisFault
 at java.lang.ClassLoader.defineClass1(Native Method)
 at java.lang.ClassLoader.defineClass(Unknown Source)
 at java.security.SecureClassLoader.defineClass(Unknown Source)
 at java.net.URLClassLoader.defineClass(Unknown Source)
 at java.net.URLClassLoader.access$000(Unknown Source)
 at java.net.URLClassLoader$1.run(Unknown Source)
 at java.security.AccessController.doPrivileged(Native Method)
 at java.net.URLClassLoader.findClass(Unknown Source)
 at java.lang.ClassLoader.loadClass(Unknown Source)
 at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
 at java.lang.ClassLoader.loadClass(Unknown Source)
 at java.lang.ClassLoader.loadClassInternal(Unknown Source)
 at java.lang.ClassLoader.defineClass1(Native Method)
 at java.lang.ClassLoader.defineClass(Unknown Source)
 at java.security.SecureClassLoader.defineClass(Unknown Source)
 at java.net.URLClassLoader.defineClass(Unknown Source)
 at java.net.URLClassLoader.access$000(Unknown Source)
 at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at com.sforce.ws.bind.TypeMapper.load(TypeMapper.java:688)
at com.sforce.ws.bind.TypeMapper.getJavaType(TypeMapper.java:668)
at com.sforce.ws.bind.TypeMapper.readSingle(TypeMapper.java:579)
at com.sforce.ws.bind.TypeMapper.readObject(TypeMapper.java:504)
at com.sforce.ws.transport.SoapConnection.parseDetail(SoapConnection.java:226)
at com.sforce.ws.transport.SoapConnection.createException(SoapConnection.java:200)
at com.sforce.ws.transport.SoapConnection.receive(SoapConnection.java:146)
at com.sforce.ws.transport.SoapConnection.send(SoapConnection.java:98)
at com.sforce.soap.enterprise.EnterpriseConnection.login(EnterpriseConnection.java:1)
at com.sforce.soap.enterprise.EnterpriseConnection.<init>(EnterpriseConnection.java:1)
at TestClient.doLogin(TestClient.java:35)
at TestClient.main(TestClient.java:18)
I dnt understand why this exception is coming. Any Ideas?
Plz help
Thanks

 

orikkerorikker

I don't think your code even gets through login portion of it. Can you see login attempts in SFDC when you run code?

Force.comForce.com

I have tried calling the webservice again with new security token and getting the following error now:

 

 

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/axis/encoding/Serializer
	at java.lang.Class.getDeclaredConstructors0(Native Method)
	at java.lang.Class.privateGetDeclaredConstructors(Unknown Source)
	at java.lang.Class.getConstructor0(Unknown Source)
	at java.lang.Class.newInstance0(Unknown Source)
	at java.lang.Class.newInstance(Unknown Source)
	at com.sforce.ws.bind.TypeMapper.readSingle(TypeMapper.java:627)
	at com.sforce.ws.bind.TypeMapper.readObject(TypeMapper.java:504)
	at com.sforce.soap.enterprise.LoginResponse_element.loadFields(LoginResponse_element.java:1)
	at com.sforce.soap.enterprise.LoginResponse_element.load(LoginResponse_element.java:1)
	at com.sforce.ws.bind.TypeMapper.readSingle(TypeMapper.java:628)
	at com.sforce.ws.bind.TypeMapper.readObject(TypeMapper.java:504)
	at com.sforce.ws.transport.SoapConnection.bind(SoapConnection.java:170)
	at com.sforce.ws.transport.SoapConnection.receive(SoapConnection.java:144)
	at com.sforce.ws.transport.SoapConnection.send(SoapConnection.java:98)
	at com.sforce.soap.enterprise.EnterpriseConnection.login(EnterpriseConnection.java:1)
	at com.sforce.soap.enterprise.EnterpriseConnection.<init>(EnterpriseConnection.java:1)
	at TestClient.doLogin(TestClient.java:35)
	at TestClient.main(TestClient.java:18)

 

 

SuperfellSuperfell

java.lang.NoClassDefFoundError  - you are missing one or more jars from your runtime classpath.

Force.comForce.com

I have generated the jar files again and this time the code worked. 

 

Thanks for your great help.

Force.comForce.com

I got the seesion id and thus connection is established. The code I used for setting connection is:

 

 

connection = new EnterpriseConnection(config);

 

 

I have webservice named "Integration" in salesforce. In the Integration class, there is a method called "import" which will do all the processing, so I need to call the "import" method. I have generated the jar files for "Integration" wsdl.

 

How should I call the import method through java code and run the webservice?

Plz help.