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
FluffyFluffy 

Cant execute queries with axis 2

Hello, I am using axis 2 and having a problem executing queries from my Java code. I have generated the SforceServiceStub.java from the wsdl file, and I am able to connect to the salesforce service successfully (i.e. I can get the server URL, and a session ID). Moreover, the describeGlobal()
function runs great, and returns all the object types. However, when trying to execute a basic
query, I'm getting this error:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
java.lang.RuntimeException: Unsupported type urn:sobject.enterprise.soap.sforce.com Contact
at com.sforce.soap.enterprise.SforceServiceStub$ExtensionMapper.getTypeObject(SforceServiceStub.java:25165)
at com.sforce.soap.enterprise.SforceServiceStub$SObject$Factory.parse(SforceServiceStub.java:16678)
at com.sforce.soap.enterprise.SforceServiceStub$QueryResult$Factory.parse(SforceServiceStub.java:21263) at  com.sforce.soap.enterprise.SforceServiceStub$QueryResponse$Factory.parse(SforceServiceStub.java:40935)
at com.sforce.soap.enterprise.SforceServiceStub.fromOM(SforceServiceStub.java:25016)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

my code is as follows:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
public class SampleLogin {    
   
    public static void main(String args[])  {      
     
            SforceServiceStub stub = new SforceServiceStub();
            Options options = stub._getServiceClient().getOptions();
            options.setProperty(HTTPConstants.MC_ACCEPT_GZIP, Boolean.TRUE);
            options.setProperty(HTTPConstants.MC_GZIP_REQUEST, Boolean.TRUE);

            Login lg = new Login();
            lg.setPassword("********");
            lg.setUsername("*******");
            LoginScopeHeader lsh = null;         
            LoginResponse response = stub.login(lg, lsh);
            LoginResult lr  = response.getResult();
                    
            SessionHeader sh = new SessionHeader();
            sh.setSessionId(lr.getSessionId());          
            stub = new SforceServiceStub(lr.getServerUrl());
            options = stub._getServiceClient().getOptions();
            options.setProperty(HTTPConstants.MC_ACCEPT_GZIP, Boolean.TRUE);
            options.setProperty(HTTPConstants.MC_GZIP_REQUEST, Boolean.TRUE);
          
           QueryOptions qOptions = new QueryOptions();
            qOptions.setBatchSize(200);          
            Query q = new Query();
            q.setQueryString("select AccountId from Contact");
            QueryResponse qResponse = stub.query(q, sh, qOptions, null);          
            QueryResult qr = qResponse.getResult();
 }
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Can anyone please suggest what  I may be doing wrong, and point in the right direction ?

Thanks a bunch ahead,
:0)
--Fluffy 

SuperfellSuperfell
I wrote up some details of the issues with axis2 a while back see http://www.pocketsoap.com/weblog/2006/05/1623.html
FluffyFluffy

Hi Simon,

thanks alot for your reply.

I saw your code snippet, but it is impossible for me to simply re-use it, because for

some reason the classes which got generated from my wsdl are somewhat different.

For example, there is no such thing as  QueryDocument in my class space.

Am I SUPPOSED to have a QueryDocument ?

 

Moreover, as you can see in my code, I DO create a new session

header before I call the query, and the query function DOES get

the new copy of the session header. The only difference is that

I don't have any QueryDocument, but - obviously I can't have it

because it doesn't exist amongst the classes generated by the wsdl.

 

So can you please be more specific regarding what I may be doing wrong

here ? Do you think that I SHOULD have had a QueryDocument class , so

does that mean that my wsdl wasn't generated correctly or something ?

(Although I'm pretty sure that wsdl generated everything correctly because

otherwise I probably wouldn't be able to login).

?? (??????? ???? ?????? ?)

 

Thanks alot for any clarifications,

regards,

fluffy

SuperfellSuperfell
You need to re-import the WSDL using XMLBeans, as the blog post says

"the default ADB databinding will not work with the sforce enterprise WSDL, because it can't handle complex types extensions, unfortunately it won't tell you this at WSDL2Java time, you get a rather more cryptic error at runtime, use the XMLBeans option instead (this is unfortunate because the xmlbeans model is even more verbose to use than ADB)"
FluffyFluffy
Simon,

I used the xmlbeans option, like you suggested and it worked this time. Thanks so much for your help !

regards,
--Fluffy
mbiffimbiffi
Hi,
did someone succeed in generating and using the partner wsdl with axis2?
I have some code which uses the get_any method and this seems not to be supported by xmlbeans options.
Regards
Massi
SuperfellSuperfell
I haven't tried recently, i did get it working with the xmlbeans option, but its very painful programming model to work with. Why do you want to use axis2 ?
mbiffimbiffi
Hi Simon, we are using axis2 for our service bus and would like to have to query sforce using the partner wsdl with axis2 in order to be consistent. I generated the sources but I can't find the get_any method in Sobject. How did you manage this issue (if managed)? Thanks and regards Massimiliano
SuperfellSuperfell
You have to use the XMLBeans option, and then you have to use the XMLBeans methods for dealing with the wildcard elements, there's no simple get_any method.
mbiffimbiffi
Hi Simon maybe you could help me, I'm trying to do an update using xmlbeans-axis2 generated API,and I can't figure out how to add specific field to add to update an Opportunity Here's the code: UpdateDocument updateDocument = UpdateDocument.Factory.newInstance(); Update update = Update.Factory.newInstance(); SObject updateOpportunity = SObject.Factory.newInstance(); updateOpportunity.setType(TYPE); updateOpportunity.setId(this.getOpportunityId()); update.setSObjectsArray(new SObject[] { updateOpportunity }); updateDocument.setUpdate(update); SaveResult[] saveResults = binding.update(updateDocument, this.sessionHeaderDocument, null, null, null, null) .getUpdateResponse().getResultArray(); what I would like to do is to add a fieldname+fieldValue to the Opportunity object but I can't find how. Using xml,but how? Thank you and regards Massimiliano
Alon SchreibmanAlon Schreibman
Hi,

I use Axis2 to integrate with Salesforce web-service API and run queries.

see http://rabout.com/?q=salesforce_api_axis2

I hope you'll find it useful,
Alon