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
ashokashok 

Calling SalesForce API through a proxy.

Issue # 1

The XML-RPC java Library provided by SalesForce.com does not support a common method of

calling applications thru a proxy. The standard java code snippet normally allows

applications to converse outside our proxy. This code fragment works with our proxy.

The code is:

System.getProperties().put( "proxySet", "true" );

System.getProperties().put( "proxyHost", "gateway.xyz.net" ); //This is the proxy entry in the Browser.

System.getProperties().put( "proxyPort", "80" );

String password = "userid:password";

BASE64Encoder enc = new sun.misc.BASE64Encoder();

String encoded = enc.encode(password.getBytes());

connection.setRequestProperty( "Proxy-Authorization", "Basic " + encoded );

 

Issue #2

The XMLRPC library provided by SalesForce.com has modifications that are not in the

public domain apache.org XMLRPC jar file. The Apache Library Standard does not have:

setSessionId(). This prevents us from making changes to the public XMLRPC

source (.java) to handle Proxies as mentioned above.

 

DevAngelDevAngel

ashok,

You are correct in your analysis.
 
We have no specific plans to change this.  We don't support use of that XML-RPC client, nor do we warrant that it will have any specific features or compatibility.  It is example code only.
ashokashok

How does one then go about making calls to salesforce.com using the API if all our outbound traffic on 80/443 requires and logon/password to a proxy. We are a very secure financial services company.

 

Thanks

 

EnderEnder

From a jguru post: http://www.jguru.com/faq/view.jsp?EID=13186 

I am not sure if the Apache XML-RPC implementation has this, but if it doesn't you need to recompile the package.  Remember to set the cookie for the sid. 

"

If your proxy server requires user name/password authentication you need to insert this login information into the HTTP header by invoking the setRequestProperty() method of the URLConnection. The HTTP protocol requires that the user name/password combination be Base64 encoded. This is not encryption - it is simply a way of representing ASCII characters using a reduced character set for portability.

The Java 2 platform does not include classes to perform the Base64 encoding, so you will have to write your own or use one of the many publicly-available ones. In the following example I use one written by Chuck McManis, which you can get from http://www.mcmanis.com/~cmcmanis/java/encoders/index.html

URL url = new URL("www.jGuru.com");
URLConnection connection = url.openConnection();
String login = "username:password";
String encodedLogin = new BASE64Encoder().encodeBuffer(login.getBytes());
connection.setRequestProperty("Proxy-Authorization", "Basic " + encodedLogin);

This should establish the URL connection, which you can then use however you like.


 

EnderEnder

Another way to do this would be to install an Authenticator.  When the authentication in necessary, the Authenticator.getPasswordAuthentication() would be called.  Check out sun's site or javaworld for info on how to use the Authenticator class.

 

 

ashokashok

The XMLRPC implementation of Salesforce is supplied in a Jar file. (xmlrpc.jar).

The code fragment to connect to Salesforce.com is given below. This compiles clean.

Facts:?
XMLRPC.jar is a SalesForce.com supplied jar file.

Questions:
1. Where would one stick in PROXY code  (proxy-username, proxy-password).
2. Where can I get source for this xlmrpc.jar file to add my proxy code ?

 

/*********************** SFConnectTest.java ******************/
import java.io.*;
import java.util.*;
import helma.xmlrpc.*;

public class SFConnectTest {

public static void main(String[] args) throws java.io.IOException, helma.xmlrpc.XmlRpcException {

        String propsFilename = "SFConnectTest.prop";
        Properties props = new Properties();
        props.load(new FileInputStream(propsFilename));

        String username = props.getProperty("username");
        String pwd      = props.getProperty("password");

        String server    = props.getProperty("server");

        String version  = props.getProperty("version");
        String clientId = props.getProperty("client");
        String types    = props.getProperty("type");

        XmlRpcClient xmlrpc_login = new XmlRpcClient(server);


        if (clientId != null) {
            xmlrpc_login.setUserAgent(clientId);
        }

        Hashtable htLoginParms = new Hashtable();
        htLoginParms.put("username", username);  //SalesForce.com Login
        htLoginParms.put("password", pwd);            //Slaseforce.com Password

        if (clientId != null) {
            htLoginParms.put("client",   clientId);
        }

        htLoginParms.put("version",  "1.7");

        Vector loginParms = new Vector();
        loginParms.add(htLoginParms);          


        Hashtable result =  (Hashtable) xmlrpc_login.execute("sfdc.login",  loginParms);

        String mySessionID = (String)result.get("session_id");
        System.out.println("Login call successful, session_id: " +  mySessionID);
  
        String myServer = (String)result.get("server_url");
        System.out.println("Server URL: " + myServer);

        XmlRpcClient xmlrpc = new XmlRpcClient(myServer);

        xmlrpc.setSessionId(mySessionID);

        Hashtable htDescParms = new Hashtable();
        htDescParms.put("version", "1.7");
        //.....
  //...next call to add/update etc.
  }
}

AWilkinsonAWilkinson

when I tried to compile the code, there were 2 errors, on in this line

        xmlrpc_login.setUserAgent(clientId);

and the other in this line

 xmlrpc.setSessionId(mySessionID); (cannont resolve symbol)

also if you havent downloaded the xmlrpc.jar file, I found it at

http://cvs.mandrakesoft.com/cgi-bin/cvsweb.cgi/koinettivity/dist/Attic/xmlrpc.jar?hideattic=0

ashokashok

I forgot to add:

Compile the code with the following:


set CLASSPATH=.;jars/xmlrpc.jar
javac SFConnectTest.java

 

ashokashok

Please The xmlrpc.jar file of SalesForce.com is not the same xmlrpc.jar from xmlrpc.org.

I think the SalesForce.com xmlrpc.jar has some salesforce.com information. This prevents me from adding proxy code.

 

aditya singh 68aditya singh 68
we can study online tutorial http://www.welookups.com/