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
Ryan Avent 14Ryan Avent 14 

login partner via PartnerConnection parser error (Java)

Im having some issues attempting to login using PartnerConnection via a simple Java project, my SF org has the below URL structure:

https://[myorg].lightning.force.com/services/Soap/u/34.0/[orgid]

(tried with multiple api versions)

when ever i run the project im seeing the below error that appreas to be triggerd during the  setting of PartnerConnection to a new connection.

Does anyone have any ideas what could be the issue here?

INFO: Error - Unexpected element. Parser was expecting element 'http://schemas.xmlsoap.org/soap/envelope/:Envelope' but found ':html'
My code:
package com.example.integration.testing;

import com.sforce.soap.partner.*;
import com.sforce.soap.partner.Error;
import com.sforce.soap.partner.fault.ApiFault;
import com.sforce.soap.partner.fault.ExceptionCode;
import com.sforce.soap.partner.fault.UnexpectedErrorFault;
import com.sforce.soap.partner.sobject.SObject;
import com.sforce.ws.ConnectionException;
import com.sforce.ws.ConnectorConfig;
import java.util.Optional;
import java.util.logging.Logger;


public class Testing {

    private static final Logger logger = Logger.getLogger(Testing.class.getName());

    public static void main(String[] args) {        
        String username = "[myUser]";
        String password = "[myUser]";
        String securityToken ="[myToken]";
        String url = "https://[my org]/services/Soap/u/42.0";
        
        //I have tried with the url ser to https://[my org]/services/Soap/u/42.0 and https://[my org]/services/Soap/u/42.0/[org id]

        PartnerConnection con = login(username, password, securityToken, url);
    }
    
    public static PartnerConnection login(String username, String password, String securityToken, String url) {
    String v_message = null;
    PartnerConnection connection = null;

    try {

      ConnectorConfig config = new ConnectorConfig();
      config.setUsername(username);
      
      if (securityToken.isBlank()) {
        password = password + securityToken;
      }
      logger.info("Setting password");

      config.setPassword(password);
	  
      logger.info("Setting setAuthEndpoint");
      String setAuthEndpoint = url;
      logger.info("Connecting to setAuthEndpoint - " + setAuthEndpoint);
      config.setAuthEndpoint(setAuthEndpoint);
   
   
      logger.info("Setting setServiceEndpoint");   
      String setServiceEndpoint = url;
      logger.info("Connecting to setServiceEndpoint - " + setServiceEndpoint);
      config.setServiceEndpoint(setServiceEndpoint);

      logger.info("Logging in as " + username);
      logger.info("Setting calling new connection");
      try{
        connection = Connector.newConnection(config);
        connection.setQueryOptions(2000);
        
         logger.info("Auth EndPoint: "+config.getAuthEndpoint());
         logger.info("Service EndPoint: "+config.getServiceEndpoint());
         logger.info("Username: "+config.getUsername());
         logger.info("SessionId: "+config.getSessionId());

      }catch(ConnectionException e){
       logger.info("Error - "+ e.getMessage());
      }
    }catch(Exception e){
        logger.info("Error during connection " + e.getMessage());
        
    }
        return connection;
    }
}

 

Dependencies:

<!-- I have tried with multiple api versions from 34 - 50 -->
        <dependencies>
            <dependency>
                <groupId>com.force.api</groupId>
                <artifactId>force-wsc</artifactId>
                <version>34.0.0</version>
            </dependency>
                <dependency>
                        <groupId>com.force.api</groupId>
                        <artifactId>force-partner-api</artifactId>
                        <version>34.0.0</version>
                        <type>jar</type>
                </dependency>
        </dependencies>
Ryan Avent 14Ryan Avent 14
I was using the wrong URL structure, the url used should have been https://[org].my.salesforce.com/services/Soap/u/[api version]/
SubratSubrat (Salesforce Developers) 
Hello Ryan ,

The error message you're encountering suggests that the response received from Salesforce is not in the expected SOAP envelope format but rather in HTML format. This can happen if there is an issue with the URL or authentication settings you're using to connect to the Salesforce org.

So for this ,verify the URL you're using to connect to Salesforce. Ensure that it is correct and includes the appropriate API version. The format should be something like:
https://<instance>.salesforce.com/services/Soap/u/<API_version>. Replace <instance> with your Salesforce instance, and <API_version> with the desired API version.

Hope this helps too .
Thank you.