0

I have developed application using SmartGWT. Now I need to call webservice using json to another application which is deployed in another server for submitting username and password. When I make a request with url and POST method, getting the response status code as 0 and response text as blank.

Here is my code,

public void sendRequest() throws Exception {

    // Get login json data to be sent to server.
    String strData = createLoginReqPacket();
    String url = "some url";
    RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, url);
    builder.setHeader("Content-Type", "application/json");
    builder.setHeader("Content-Length", strData.length() + "");

    Request response = builder.sendRequest(strData, new RequestCallback() {

        @Override
        public void onResponseReceived(Request request, Response response) {

            int statusCode = response.getStatusCode();
            System.out.println("Response code ----"+response.getStatusCode()+"");

            if (statusCode == Response.SC_OK) {
                String responseBody = response.getText();
                System.out.println("Respose :" + responseBody);
                // do something with the response
            } else {
                GWT.log("Response error at server side ----",null);
                // do in case of server error
            }

        }// end of method.

        @Override
        public void onError(Request request, Throwable exception) {
            GWT.log("**** Error in service call ******",null);
        }// end of method.
    });

    builder.send();
}// end of send request.

Please anybody knows the solution?


as i am new to GWT/SmartGwt i don't no much about it.

@ModeEngage There is no reason to use GWT class(RequestBuilder), But i don't have any idea to use Data source. Can u give reference or stuffs to do this??

And when i run this in chrome browser i get the following in error console.

XMLHttpRequest cannot load http:// "requested Url" . Origin http:// "localhost:8888" is not allowed by Access-Control-Allow-Origin.

Any solutions???

Jean-Michel Garcia
  • 2,359
  • 2
  • 23
  • 44
Girish
  • 1
  • 1

1 Answers1

0

I believe this is caused by Firewall. I've run some test, and this is the most likely explanation.

Jean-Michel Garcia
  • 2,359
  • 2
  • 23
  • 44
  • as far as I know, no there isn't. In your description, you also have to describe what are you trying to achieve. For a quick description of a datasource : http://www.smartclient.com/smartgwt/javadoc/com/smartgwt/client/data/DataSource.html – Jean-Michel Garcia Jun 14 '12 at 12:07