• Kevin Wright
  • NEWBIE
  • 25 Points
  • Member since 2010

  • Chatter
    Feed
  • 1
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 4
    Replies

I feel I'm almost there :)

 

The code below connects to the Salesforce server but ultimately fails with a 'no endpoint' exception.

 

I think I'm just not passing on the protocol credentials such as service and url endpoint to the object making the call,  but

I'm only guessing.

 

Also are there any pieces of sample code that make a WebService call from Java as I've not been able to find any?

 

Can anyone help me please?

 

 

 

import com.sforce.soap.schemas._class.MyWebService.*;
import java.net.*;
import com.sforce.soap.enterprise.*;
import com.sforce.soap.enterprise.fault.LoginFault;
import com.sforce.soap.enterprise.fault.ExceptionCode;

 

public class TestCall{

 

 public static void main(String[] args){

                LoginResult loginResult;

  System.out.println("start of program");
  try{

  SoapBindingStub bind=  (SoapBindingStub) new SforceServiceLocator().getSoap();
                System.out.println("after call to getSoap()");
  bind.setTimeout(60000);

   
  loginResult = bind.login("myadminuser", "mypassword");
  System.out.println("straight after login call");
  bind._setProperty(SoapBindingStub.ENDPOINT_ADDRESS_PROPERTY, loginResult.getServerUrl());

    com.sforce.soap.enterprise.SessionHeader sh = new com.sforce.soap.enterprise.SessionHeader();
          sh.setSessionId(loginResult.getSessionId());
      
   
         bind.setHeader(new SforceServiceLocator().getServiceName().getNamespaceURI(),
                          "SessionHeader", sh);
       
              

   MyWebServiceBindingStub stub = new MyWebServiceBindingStub();

   

   System.out.println("about to make call");
   stub.myMethod();
  }
    catch (LoginFault ex) {
            // The LoginFault derives from AxisFault

            ExceptionCode exCode = ex.getExceptionCode();
            System.out.println("######" + exCode);
            if (exCode == ExceptionCode.FUNCTIONALITY_NOT_ENABLED ||
                exCode == ExceptionCode.INVALID_CLIENT ||
                exCode == ExceptionCode.INVALID_LOGIN ||
                exCode == ExceptionCode.LOGIN_DURING_RESTRICTED_DOMAIN ||
                exCode == ExceptionCode.LOGIN_DURING_RESTRICTED_TIME ||
                exCode == ExceptionCode.ORG_LOCKED ||
                exCode == ExceptionCode.PASSWORD_LOCKOUT ||
                exCode == ExceptionCode.SERVER_UNAVAILABLE ||
                exCode == ExceptionCode.TRIAL_EXPIRED ||
                exCode == ExceptionCode.UNSUPPORTED_CLIENT) {
                System.out.println("Please be sure that you have a valid username " +
                     "and password.");
            } else {
                // Write the fault code to the console

                System.out.println(ex.getExceptionCode());
                // Write the fault message to the console

                System.out.println("An unexpected error has occurred." + ex.getMessage());
            }
  

  }
   catch(Exception e){
   System.out.println("error" + e.getMessage());
  }

 }

 


}

 

 

Hi Guys,

I am attempting to call a simple web service that I have written in Apex from a Java Program.

The steps I have taken so far.

1. Create a webservice method inside a global class. (compiles ok).
2. Generate wsdl files for both my WebService and the org.
3. Install Apache Axis
4. Use Axis to generate proxy stubs (runs ok - and generates Java source files.)
5. Compile All Java sources generated (all compile first time without changes).
6. Construct Client code (as shown below).

import com.sforce.soap.schemas._class.MyWebService.*;
import java.net.*;


public class TestCall{

 

 public static void main(String[] args){

  System.out.println("start of program");
  try{

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

   MyWebServiceBindingStub stub =
                              new MyWebServiceBindingStub
                               (new URL("https://na1-api.salesforce.com/services/Soap/class/MyWebService"),null);
   //com.sforce.soap.schemas._class.MyWebService.MyWebServicePortType pt =
                                //  stub.getMyWebService();
   System.out.println("about to make call");
   stub.myMethod();
  }
  catch(Exception e){
   System.out.println("exception thrown");
   System.out.println(e.getMessage());
  }
 }

 


}


7. The code above compiles fine.
8. On running I get:

INVALID_SESSION_ID: Invalid Session ID found in SessionHeader: Illegal Session.

Can you please tell me where I am going wrong. (While I still have some hair left to pull out please :)  )

Thank you , in advance.


Kevin Wright.

I feel I'm almost there :)

 

The code below connects to the Salesforce server but ultimately fails with a 'no endpoint' exception.

 

I think I'm just not passing on the protocol credentials such as service and url endpoint to the object making the call,  but

I'm only guessing.

 

Also are there any pieces of sample code that make a WebService call from Java as I've not been able to find any?

 

Can anyone help me please?

 

 

 

import com.sforce.soap.schemas._class.MyWebService.*;
import java.net.*;
import com.sforce.soap.enterprise.*;
import com.sforce.soap.enterprise.fault.LoginFault;
import com.sforce.soap.enterprise.fault.ExceptionCode;

 

public class TestCall{

 

 public static void main(String[] args){

                LoginResult loginResult;

  System.out.println("start of program");
  try{

  SoapBindingStub bind=  (SoapBindingStub) new SforceServiceLocator().getSoap();
                System.out.println("after call to getSoap()");
  bind.setTimeout(60000);

   
  loginResult = bind.login("myadminuser", "mypassword");
  System.out.println("straight after login call");
  bind._setProperty(SoapBindingStub.ENDPOINT_ADDRESS_PROPERTY, loginResult.getServerUrl());

    com.sforce.soap.enterprise.SessionHeader sh = new com.sforce.soap.enterprise.SessionHeader();
          sh.setSessionId(loginResult.getSessionId());
      
   
         bind.setHeader(new SforceServiceLocator().getServiceName().getNamespaceURI(),
                          "SessionHeader", sh);
       
              

   MyWebServiceBindingStub stub = new MyWebServiceBindingStub();

   

   System.out.println("about to make call");
   stub.myMethod();
  }
    catch (LoginFault ex) {
            // The LoginFault derives from AxisFault

            ExceptionCode exCode = ex.getExceptionCode();
            System.out.println("######" + exCode);
            if (exCode == ExceptionCode.FUNCTIONALITY_NOT_ENABLED ||
                exCode == ExceptionCode.INVALID_CLIENT ||
                exCode == ExceptionCode.INVALID_LOGIN ||
                exCode == ExceptionCode.LOGIN_DURING_RESTRICTED_DOMAIN ||
                exCode == ExceptionCode.LOGIN_DURING_RESTRICTED_TIME ||
                exCode == ExceptionCode.ORG_LOCKED ||
                exCode == ExceptionCode.PASSWORD_LOCKOUT ||
                exCode == ExceptionCode.SERVER_UNAVAILABLE ||
                exCode == ExceptionCode.TRIAL_EXPIRED ||
                exCode == ExceptionCode.UNSUPPORTED_CLIENT) {
                System.out.println("Please be sure that you have a valid username " +
                     "and password.");
            } else {
                // Write the fault code to the console

                System.out.println(ex.getExceptionCode());
                // Write the fault message to the console

                System.out.println("An unexpected error has occurred." + ex.getMessage());
            }
  

  }
   catch(Exception e){
   System.out.println("error" + e.getMessage());
  }

 }

 


}

 

 

I feel I'm almost there :)

 

The code below connects to the Salesforce server but ultimately fails with a 'no endpoint' exception.

 

I think I'm just not passing on the protocol credentials such as service and url endpoint to the object making the call,  but

I'm only guessing.

 

Also are there any pieces of sample code that make a WebService call from Java as I've not been able to find any?

 

Can anyone help me please?

 

 

 

import com.sforce.soap.schemas._class.MyWebService.*;
import java.net.*;
import com.sforce.soap.enterprise.*;
import com.sforce.soap.enterprise.fault.LoginFault;
import com.sforce.soap.enterprise.fault.ExceptionCode;

 

public class TestCall{

 

 public static void main(String[] args){

                LoginResult loginResult;

  System.out.println("start of program");
  try{

  SoapBindingStub bind=  (SoapBindingStub) new SforceServiceLocator().getSoap();
                System.out.println("after call to getSoap()");
  bind.setTimeout(60000);

   
  loginResult = bind.login("myadminuser", "mypassword");
  System.out.println("straight after login call");
  bind._setProperty(SoapBindingStub.ENDPOINT_ADDRESS_PROPERTY, loginResult.getServerUrl());

    com.sforce.soap.enterprise.SessionHeader sh = new com.sforce.soap.enterprise.SessionHeader();
          sh.setSessionId(loginResult.getSessionId());
      
   
         bind.setHeader(new SforceServiceLocator().getServiceName().getNamespaceURI(),
                          "SessionHeader", sh);
       
              

   MyWebServiceBindingStub stub = new MyWebServiceBindingStub();

   

   System.out.println("about to make call");
   stub.myMethod();
  }
    catch (LoginFault ex) {
            // The LoginFault derives from AxisFault

            ExceptionCode exCode = ex.getExceptionCode();
            System.out.println("######" + exCode);
            if (exCode == ExceptionCode.FUNCTIONALITY_NOT_ENABLED ||
                exCode == ExceptionCode.INVALID_CLIENT ||
                exCode == ExceptionCode.INVALID_LOGIN ||
                exCode == ExceptionCode.LOGIN_DURING_RESTRICTED_DOMAIN ||
                exCode == ExceptionCode.LOGIN_DURING_RESTRICTED_TIME ||
                exCode == ExceptionCode.ORG_LOCKED ||
                exCode == ExceptionCode.PASSWORD_LOCKOUT ||
                exCode == ExceptionCode.SERVER_UNAVAILABLE ||
                exCode == ExceptionCode.TRIAL_EXPIRED ||
                exCode == ExceptionCode.UNSUPPORTED_CLIENT) {
                System.out.println("Please be sure that you have a valid username " +
                     "and password.");
            } else {
                // Write the fault code to the console

                System.out.println(ex.getExceptionCode());
                // Write the fault message to the console

                System.out.println("An unexpected error has occurred." + ex.getMessage());
            }
  

  }
   catch(Exception e){
   System.out.println("error" + e.getMessage());
  }

 }

 


}

 

 

Hi Guys,

I am attempting to call a simple web service that I have written in Apex from a Java Program.

The steps I have taken so far.

1. Create a webservice method inside a global class. (compiles ok).
2. Generate wsdl files for both my WebService and the org.
3. Install Apache Axis
4. Use Axis to generate proxy stubs (runs ok - and generates Java source files.)
5. Compile All Java sources generated (all compile first time without changes).
6. Construct Client code (as shown below).

import com.sforce.soap.schemas._class.MyWebService.*;
import java.net.*;


public class TestCall{

 

 public static void main(String[] args){

  System.out.println("start of program");
  try{

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

   MyWebServiceBindingStub stub =
                              new MyWebServiceBindingStub
                               (new URL("https://na1-api.salesforce.com/services/Soap/class/MyWebService"),null);
   //com.sforce.soap.schemas._class.MyWebService.MyWebServicePortType pt =
                                //  stub.getMyWebService();
   System.out.println("about to make call");
   stub.myMethod();
  }
  catch(Exception e){
   System.out.println("exception thrown");
   System.out.println(e.getMessage());
  }
 }

 


}


7. The code above compiles fine.
8. On running I get:

INVALID_SESSION_ID: Invalid Session ID found in SessionHeader: Illegal Session.

Can you please tell me where I am going wrong. (While I still have some hair left to pull out please :)  )

Thank you , in advance.


Kevin Wright.

I downloaded the enterprise.wsdl and using axis tools managed to get the wsdl2java tool working and built the java stubs for the wsdl.  I'm trying to do a simple login into SalesForce and grab some data from the contact object, an extremely simple app.  I cannot find the SoapBindingStub and I am completely stuck and its making me so mad.  Below is a list of the java classes that were created as a result of using axis tools.

 

InvalidFieldFault.java

InvalidIdFault.java

InvalidNewPasswordFault.java

InvalidQueryLocatorFault.java

InvalidSObjectFault.java

LoginFault.java

MalformedQueryFault.java

MalformedSearchFault.java

SforceServiceCallbackHandler.java

SforceServiceStub.java

UnexpectedErrorFault.java

 

I read somewhere that SoapBindingStuf is found is SforceServiceStub.java but I cannot find it anywhere.  I am really stuck here and any help that anybody could give, I would really appreciate it.  I am kinda new to java as I'm mainly a .NET guy and this is bothering me.

 

Ralph