Go Back   SmartClient Forums > Smart GWT Technical Q&A
Wiki Register Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 9th Aug 2011, 03:25
mrpavankumar mrpavankumar is offline
Registered Developer
 
Join Date: Aug 2011
Posts: 10
Default Problem with the webservices - smartgwt

Hi

I am trying to invoke webservices from smartgwt api,
Code:
package com.example.myproject.client;

import java.util.LinkedHashMap;
import java.util.Map;

import com.google.gwt.core.client.EntryPoint;
import com.smartgwt.client.data.WSDLLoadCallback;
import com.smartgwt.client.data.WebService;
import com.smartgwt.client.data.WebServiceCallback;
import com.smartgwt.client.data.XMLTools;
import com.smartgwt.client.util.Page;
import com.smartgwt.client.util.SC;
import com.smartgwt.client.widgets.form.DynamicForm;
import com.smartgwt.client.widgets.form.fields.ButtonItem;
import com.smartgwt.client.widgets.form.fields.TextItem;
import com.smartgwt.client.widgets.form.fields.events.ClickEvent;
import com.smartgwt.client.widgets.form.fields.events.ClickHandler;
import com.smartgwt.client.widgets.layout.HLayout;
import com.google.gwt.core.client.JavaScriptObject;
import com.smartgwt.client.rpc.RPCManager;
import com.smartgwt.client.rpc.RPCResponse;

public class SmartGWTWebservices implements EntryPoint {
      private WebService myservice;
      public void onModuleLoad(){

            HLayout hl = new HLayout();
            MyForm mi=new MyForm();
            hl.addMember(mi);
            final MyForm form=new MyForm();
            ButtonItem bi = new ButtonItem("ClickMe");
            bi.addClickHandler(new ClickHandler() {
                  public void onClick(ClickEvent event) {
                    SC.say("Clicked the button....");
                    form.callService();
                  }
                });
            form.setItems(bi);
      hl.addMember(form);
      //RPCManager.setUseHttpProxy(true);

            XMLTools.loadWSDL("https://somehost/HelloService/remoting/helloService?wsdl", new WSDLLoadCallback() {
                  public void execute(WebService webService) {
                    myservice = webService;
                  }
                });
            hl.setWidth(Page.getWidth());
hl.draw();
            
            
      }
      
      class MyForm extends DynamicForm{
            
            
            public void callService(){
                  if(myservice==null){
                        SC.say("Still Processing Try again......");
                  }else{
                        Map inputData = new LinkedHashMap();
                        inputData.put("Name", "Pavan");
                        //RPCManager.setUseHttpProxy(true);
                        myservice.callOperation("sayHello",inputData,null, new WebServiceCallback() {

                            public void execute(Object[] data, JavaScriptObject xmlDoc, RPCResponse rpcResponse,
                                JavaScriptObject wsRequest) {
                                
                                
                              SC.say("Hi, " + ((JavaScriptObject)data[0]));
                              SC.say("Hello " + new TextItem((JavaScriptObject)data[0]).getValueAsString());
                              
                            }
                          });
                  }
                  
            }
            
            
      }
      
      
      
}
This is the code i was written to invoke a method named sayHello, I have supposed to get a message "Hello <some name>" but it is always getting null printed

can you please help me where i am doing the mistake

Thanks
Pavan
Reply With Quote
  #2  
Old 9th Aug 2011, 08:28
mrpavankumar mrpavankumar is offline
Registered Developer
 
Join Date: Aug 2011
Posts: 10
Default

I am getting the JavaScriptObject, i am conveting it to a map with the help of JSOHelper and getting the value of the key which is a tag in soap xml response. Please direct me if i am doing in wrong way

Thanks
Pavan
Reply With Quote
  #3  
Old 21st Sep 2011, 06:44
bvamos bvamos is offline
Registered Developer
 
Join Date: Sep 2010
Posts: 57
Default

What about:

XMLTools.selectString(data, "//xpath/tagname")

instead of

((JavaScriptObject)data[0])

Change //xpath/tagname to something that exist in you reply.
Reply With Quote
  #4  
Old 20th Nov 2011, 11:03
Osa Osa is offline
Registered Developer
 
Join Date: Nov 2011
Posts: 10
Default

Guys,


I need to send a nested data to my webservice. The typical Webservice example using the LinkedMap for the outgoing request is great for a service that takes one single input or multiple (below). In this case USZip. Does anyone have an example of how to fill in a linkedMap for a complex type.

The example is simple but I want an example on a more complex soap body with numerous required input data and maybe a complex types or two.
data.put("USZip", getValueAsString("ZipCode"));


ZipForm extends DynamicForm {
public void callService() {
if (zipCodeService == null) {
SC.say("Please try again in a moment - still loading web service descriptor");
} else {
setValue("City", "Loading...");
Map data = new LinkedHashMap();
data.put("USZip", getValueAsString("ZipCode"));
zipCodeService.callOperation("GetInfoByZIP", data, "//CITY", new WebServiceCallback() {

public void execute(Object[] data, JavaScriptObject xmlDoc, RPCResponse rpcResponse,
JavaScriptObject wsRequest) {
ZipForm.this.setValue("City", (String) data[0]);
}
});
}
}
}
Reply With Quote
  #5  
Old 20th Nov 2011, 13:35
Isomorphic Isomorphic is offline
Administrator
 
Join Date: May 2006
Posts: 38,342
Default

The best single discussion is the doc for useFlatFields.

If you're filling out a complex set of elements you can either arrange a set of nested Maps and Lists that corresponds the XML structure if the data were serialized by DataSource.xmlSerialize(), or, with useFlatFields:true, you can provide the data "flattened" and have SmartGWT automatically fill in same-named elements, generating intervening XML structure as needed. This latter approach is more robust across possible changes to your WSDL message format.
Reply With Quote
  #6  
Old 20th Nov 2011, 14:18
Osa Osa is offline
Registered Developer
 
Join Date: Nov 2011
Posts: 10
Default

Thanks for the quick response.
I actually tried that yesterday but for some reason, its not working. I feel like I am not setting it it at the right place.

I tried to set it using the asRequest. I guess my question is how does the following code correlate with the actual request.
XmlNamespaces aXmlNamespaces = new XmlNamespaces();
aXmlNamespaces.addNamespace("ws", "http://dude.host.com/testService");
WSRequest aWSRequest = new WSRequest();
aWSRequest.setXmlNamespaces(aXmlNamespaces);
aWSRequest.setUseFlatFields(true);

Here the SOAP code. I am trying to set SystemID below.


<soapenv:Body>
<dev:GetZipCode>
<ZipCode>dafadf</ZipCode>
<!--Optional:-->
<serviceContext>
<!--Optional:-->
<dat:SystemID>?</dat:SystemID>
<!--Optional:-->
<dat:TouchID>?</dat:TouchID>
<!--Optional:-->
</serviceContext>
</dev:GetZipCode>
</soapenv:Body>

Quote:
Originally Posted by Isomorphic
The best single discussion is the doc for useFlatFields.

If you're filling out a complex set of elements you can either arrange a set of nested Maps and Lists that corresponds the XML structure if the data were serialized by DataSource.xmlSerialize(), or, with useFlatFields:true, you can provide the data "flattened" and have SmartGWT automatically fill in same-named elements, generating intervening XML structure as needed. This latter approach is more robust across possible changes to your WSDL message format.
Reply With Quote
  #7  
Old 20th Nov 2011, 14:20
Isomorphic Isomorphic is offline
Administrator
 
Join Date: May 2006
Posts: 38,342
Default

Not clear on your question about how the code correlates with the request, but, if you were trying to set SystemID with useFlatFields:true, you'd just use map.put("SystemID", value) and provide that map as the wsRequest's data.
Reply With Quote
  #8  
Old 20th Nov 2011, 14:45
Osa Osa is offline
Registered Developer
 
Join Date: Nov 2011
Posts: 10
Default

It appears the forum did not keep the formatting.

It works when I am setting ZipCode only but once I try sending two values, it 's not sending the second.

So I can do
Map data = new LinkedHashMap();
data.put("USZip", getValueAsString("ZipCode"))


but when I do
Map data = new LinkedHashMap();
data.put("USZip", getValueAsString("ZipCode"))
data.put("SystemID", getValueAsString("USSystemID"))

It sends out only SystemID and does not send ZipCode. SO I thought the issue was the useFlatFields but apparently not.


map.

<soapenv:Body>
<dev:GetZipCode>
<ZipCode>dafadf</ZipCode>
<!--Optional:-->
<serviceContext>
<dat:SystemID>?</dat:SystemID>
<dat:TouchID>?</dat:TouchID>
<!--Optional:-->
</serviceContext>
</dev:GetZipCode>
</soapenv:Body>

Quote:
Originally Posted by Isomorphic
Not clear on your question about how the code correlates with the request, but, if you were trying to set SystemID with useFlatFields:true, you'd just use map.put("SystemID", value) and provide that map as the wsRequest's data.

Last edited by Osa; 20th Nov 2011 at 14:49..
Reply With Quote
  #9  
Old 20th Nov 2011, 14:47
Isomorphic Isomorphic is offline
Administrator
 
Join Date: May 2006
Posts: 38,342
Default

The tag is SystemID not USSystemID.
Reply With Quote
  #10  
Old 20th Nov 2011, 14:51
Osa Osa is offline
Registered Developer
 
Join Date: Nov 2011
Posts: 10
Default

Yes, that was a result of me trying to translate the code without using my actual code. I still have the same issue. Basically, you are saying that even with the complex xml structure that I have, it should find the systemID and send that value. I must be doing something wrong in my code somewhere else. I spend some time to re-write and let you know what I find out. T
Quote:
Originally Posted by Isomorphic
The tag is SystemID not USSystemID.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads
Thread Thread Starter Forum Replies Last Post
GWT Designer plugin and SmartGWT 2.4 problem lof Smart GWT Technical Q&A 1 13th Apr 2011 01:44
Smartgwt 2.1 basic setup problem kedaar Smart GWT Technical Q&A 5 21st Jun 2010 05:16
Development Mode problem with ListGridFieldType.IMAGE in SmartGWT 2.1 TreeGrid. AW Smart GWT Technical Q&A 2 29th Apr 2010 03:36
GWT-Ext to SmartGWT for rendering problem bbhangale Smart GWT Technical Q&A 0 3rd Jun 2009 23:04

© 2010,2011 Isomorphic Software. All Rights Reserved