开发者

a spring bean to wrap salesforce web service calls

I am trying to figure out how to开发者_如何学Python create a stateless spring bean that wraps a group of calls to salesforce web service API. My understanding is that the process for calling salesforce is something like this:

  1. Call the login service to Log into salesforce
  2. Make a series of service calls
  3. Call the logout

To have a stateless wrapper it seems right pattern is to have each method in the bean perform all three steps above. e.g. (pseudocode)

binding.login();
binding.upsert(….);
binding.upsert(….);
binding.logout();

Is this a good practice? It seems it would be a costly way just to keep the bean stateless. Would it be preferable in this instance to make the bean request scope?


I agree with Anup, you should take a look at the sfdc wsc.

If you want go entirely stateless you will need to know the following things about a salesforce connection.

  1. every action must have an endpoint url, something like na6.salesforce.com or na7.salesforce.com
  2. every action must have a valid SID(session id) for the action to complete.

When you login to salesforce the original endpoint is login.salesforce.com and if you are sucessfull you will be returned a valid endpoint(na6.salesforce.com) and a SID.

You can then drop that endpoint/sid into a singleton and share it with as many spring beans as you want. In each bean you will need to create a new SoapBindingStub and set the endpoint and sid before you execute an insert/upsert/update/etc. action.

That sid will expire after a period of inactivity (anywhere from 30-120 minutes depending upon setting) so you should catch any exceptions and relogin using the singleton object.

Dont worry about two beans casuing the singleton relogin at the same time because salesforce will return the sames sid to both.


Have you tried SFDC WSC library? It's easy to use, and fits the use case that you are trying to accomplish.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜