johvargas / sfdc-wsc

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

Get INVALID_SESSION_ID: Invalid Session ID found in SessionHeader: Illegal Session when trying to access metadata #4

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Create a ConnectorConfig object setting username and password
2. Use this to create a MetadataConnection
3. Invoke a method on the connection such as listMetadata

What is the expected output? What do you see instead?

The expected output is the retrieved metadata. Instead an exception is
raised with message "INVALID_SESSION_ID: Invalid Session ID found in
SessionHeader: Illegal Session"

What version of the product are you using? On what operating system?

I've compiled my own version of the stubs (after fixing the source for
Encoding.java).  I've also tried this with both the standard and gae
specific wsc libraries (wsc-16_0 and wsc-gae-16_0)

Please provide any additional information below.

Looking at the generated stubs I noticed that the MetadataConnection cstr:

public MetadataConnection(ConnectorConfig config)
            throws ConnectionException {
        this.__config = config;
        this.__typeMapper.setPackagePrefix(null);
        this.__typeMapper.setConfig(config);
        __SessionHeader = new SessionHeader_element();
        __SessionHeader.setSessionId(config.getSessionId());
    }

gets the session id from the given config -- but this will always be null
when the config is built from a username and pwd.  This null value is what
is sent to the SOAP endpoint and causes the exception.

Sample standalone program is included.

If help is needed to address this issue, I would also be interested in
contributing.

Original issue reported on code.google.com by turntwo...@gmail.com on 16 Jun 2009 at 5:01

Attachments:

GoogleCodeExporter commented 8 years ago
After some more investigation I've found a work-around to this issue.  Since the
metadata API doesn't have its own login operation, I first login to the partner
service, and use the session id obtained from that call to invoke metadata 
operations.

I'm not sure if this approach is optimal, but it would be nice if the generated
metadata stubs could be enhanced to do this (or similar behavior).

Sample code is attached...

Original comment by turntwo...@gmail.com on 16 Jun 2009 at 7:14

Attachments:

GoogleCodeExporter commented 8 years ago
Thanks for the sample. You are doing the right thing. There is no login call on
metadata wsdl. You need to login using partner wsdl to get the session id.

Original comment by manoj.ch...@gmail.com on 19 Jun 2009 at 10:44

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
The sample can be simplified a bit without hacking the URL.  Set the Session Id 
at for a new connector config and pass that to the metadata connection.

        ConnectorConfig partnerConfig = new ConnectorConfig();
        partnerConfig.setUsername("un");
        partnerConfig.setPassword("pw");
        partnerConfig.setTraceMessage(true);

        PartnerConnection partnerConn = com.sforce.soap.partner.Connector.newConnection(partnerConfig);
        System.out.println("Partner Session Id: " + partnerConn.getSessionHeader().getSessionId());
        System.out.println("Partner Endpoint: " + partnerConn.getConfig().getServiceEndpoint());

        ConnectorConfig metaConfig = new ConnectorConfig();
        metaConfig.setSessionId(partnerConn.getSessionHeader().getSessionId());

        MetadataConnection metaConn = Connector.newConnection(metaConfig);
        System.out.println("Metadata Session Id: " + metaConn.getSessionHeader().getSessionId());
        System.out.println("Endpoint: " + metaConn.getConfig().getServiceEndpoint());

Original comment by naamanne...@gmail.com on 8 Jul 2010 at 6:34

GoogleCodeExporter commented 8 years ago
Rather creating metadata URL, I guess simpler solution can be to use 
metadataServerUrl from Partner Login result. Sample code shown below

ConnectorConfig partnerConfig = new ConnectorConfig();
// IMPORTANT : This will not let PartnerConnection do the login
partnerConfig.setManualLogin(true);

PartnerConnection partnerConnection = 
com.sforce.soap.partner.Connector.newConnection(partnerConfig);
LoginResult lr = partnerConnection.login(USERNAME, PASSWORD);

ConnectorConfig metadataConfig = new ConnectorConfig();
metadataConfig.setSessionId(lr.getSessionId());
metadataConfig.setServiceEndpoint(lr.getMetadataServerUrl());
MetadataConnection metadataConnection = 
com.sforce.soap.metadata.Connector.newConnection(metadataConfig);
DescribeMetadataResult describeMetadata = 
metadataConnection.describeMetadata(API_VERSION);
System.out.println(describeMetadata);

Original comment by abhinavgupta697 on 27 Jul 2010 at 9:31

GoogleCodeExporter commented 8 years ago
@naamannewbold I tried your code it didn't worked and failed for invalid 
session Id. So I tried digging the stuff and found the solution I suggested in 
previous comment.

Original comment by abhinavgupta697 on 27 Jul 2010 at 9:35