johvargas / sfdc-wsc

Automatically exported from code.google.com/p/sfdc-wsc
0 stars 0 forks source link

API does not appear to expose LoginResponse.Result.metadataServerUrl - cannot reset endpoint. #37

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
If partner (or enterprise) objects are generated from a given WSDL, then the 
service endpoint (URL to use *after* logging in) is baked into the generated 
class files.  For normal API calls, the ConnectorConfig object exposes the 
serviceEndpoint property via setters/getters, so that it can be reset after 
login.  In fact, the WSC code appears to already do this for you.

The problem is when you want to use WSC for metadata API calls.  Again, the 
endpoints will be baked into the code upon code-generating from meta.wsdl, 
however the ConnectorConfig object does not expose 
LoginResponse.Result.metadataServerUrl - so there is no getter.  

The issue manifests when you build with a partner.wsdl/meta.wsdl from one org 
and try run on another org with a different instance host.

The code should look like this:

        ConnectorConfig partnerConfig = new ConnectorConfig();
        ConnectorConfig metadataConfig = new ConnectorConfig();
        partnerConfig.setUsername(USERNAME);
        partnerConfig.setPassword(PASSWORD);
        PartnerConnection partnerConnection =        
           com.sforce.soap.partner.Connector.newConnection(partnerConfig);
        metadataConfig.setSessionId(
            partnerConnection.getSessionHeader().getSessionId());
        metadataConfig.setServiceEndpoint(partnerConnection.getMetadataEndpoint());  <== no such API - we need it!!

So here's my work-around:

        String metaurl = partnerConfig.getServiceEndpoint();
        metaurl = metaurl.replace("Soap/u", "Soap/m");
        metadataConfig.setServiceEndpoint(metaurl);

Original issue reported on code.google.com by cw10...@gmail.com on 21 Mar 2011 at 6:07

GoogleCodeExporter commented 8 years ago
You can set partnerConfig.setManualLogin(true) and do the login call your self. 
This will return the LoginResult object from which you can get the metadata URL.

HTHs,
manoj

Original comment by manoj.ch...@gmail.com on 21 Mar 2011 at 6:40

GoogleCodeExporter commented 8 years ago
I see - I didn't see that in the Wiki docs - thanks.  In any case, I tried
manual login and I'm still having an "INVALID SESSION" issue.  So is the 
auto-login doing other stuff besides resetting end points?

Here's my code that doesn't work.  (my original hack, above, continues to work)

        ConnectorConfig partnerConfig = new ConnectorConfig();
        ConnectorConfig metadataConfig = new ConnectorConfig();

        /*partnerConfig.setUsername(USERNAME);
        partnerConfig.setPassword(PASSWORD);
        */
        partnerConfig.setManualLogin(true);
        PartnerConnection partnerConnection = 
            com.sforce.soap.partner.Connector.newConnection(partnerConfig);
        LoginResult result = partnerConnection.login(USERNAME, PASSWORD);
        partnerConfig.setServiceEndpoint(result.getServerUrl());
        metadataConfig.setServiceEndpoint(result.getMetadataServerUrl());
        metadataConfig.setSessionId(
            partnerConnection.getSessionHeader().getSessionId());

        MetadataConnection conn = Connector.newConnection(metadataConfig);
        ListMetadataQuery query = new ListMetadataQuery();
        query.setType("CustomObject");

        double asOfVersion = 21.0;
        ListMetadataQuery [] queries = { query };
        FileProperties[] lmr = conn.listMetadata(queries, asOfVersion);

Original comment by cw10...@gmail.com on 21 Mar 2011 at 8:22

GoogleCodeExporter commented 8 years ago
yes, auto login will reset the endpoint as well as the session id. 

Original comment by manoj.ch...@gmail.com on 21 Mar 2011 at 8:30

GoogleCodeExporter commented 8 years ago
Ok, but the manual login code doesn't work.  As you can see from the above 
listed code, I'm manually resetting the endpoints and session, but it fails 
with INVALID_SESSION_ID.  I have to continue to use auto-login and the hack I 
show in the initial issue entry here...

Original comment by cw10...@gmail.com on 21 Mar 2011 at 8:44