RPC - can't get to remote server

514 views
Skip to first unread message

Blake McBride

unread,
Apr 14, 2012, 11:43:50 AM4/14/12
to Google Web Toolkit
Greetings,

I have a pre-existing Java / NetBeans / tomcat server app that I am trying to interface to an eclipse / GWT front-end.  I can't seem to get to the backend at all.  I think the problem may be the backend URL but I'm not sure.  This is what I have on the backend:

package com.xxx.servlets.gwt;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;

public class GWTServlet extends RemoteServiceServlet {
public String getValue(String arg) {
return "ABC " + arg + " DEF";
}
}

------------

web.xml:

<servlet>
<servlet-name>GWTServlet</servlet-name>
<servlet-class>com.xxx.servlets.gwt.GWTServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>GWTServlet</servlet-name>
<url-pattern>/GWTServlet</url-pattern>
</servlet-mapping>

---------------

Front-end:

package com.arahant.client;


import com.google.gwt.user.client.rpc.RemoteService;

import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;


@RemoteServiceRelativePath("GWTServlet")

public interface ArahantService extends RemoteService {

String getValue(String arg);

}



---------

package com.arahant.client;

import com.google.gwt.user.client.rpc.AsyncCallback;


public interface ArahantServiceAsync {

void getValue(String arg, AsyncCallback<String> callback);

}


------------

private ArahantServiceAsync arahantSvc = GWT.create(ArahantService.class);

......

public void onClick(ClickEvent event) {

Window.alert("Hello, GWT World!");

ServiceDefTarget serviceDefTarget = (ServiceDefTarget) arahantSvc;

Window.alert(serviceDefTarget.getServiceEntryPoint());

serviceDefTarget.setServiceEntryPoint("http://127.0.0.1:8084/MyApp/GWTServlet");


AsyncCallback<String> callback = new AsyncCallback<String>() {


@Override

public void onFailure(Throwable caught) {

caught.printStackTrace();

}


@Override

public void onSuccess(String result) {

// TODO Auto-generated method stub

Window.alert("Result = " + result);

}

};

arahantSvc.getValue("ggg", callback);


--------

The given URL should be correct but I tried a number of variations.  The app works at http://127.0.0.1:8084/MyApp/index.html

When I run I get:

com.google.gwt.user.client.rpc.StatusCodeException: 0 

at com.google.gwt.user.client.rpc.impl.RequestCallbackAdapter.onResponseReceived(RequestCallbackAdapter.java:209)

at com.google.gwt.http.client.Request.fireOnResponseReceived(Request.java:287)

at com.google.gwt.http.client.RequestBuilder$1.onReadyStateChange(RequestBuilder.java:395)

at sun.reflect.GeneratedMethodAccessor26.invoke(Unknown Source)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

at java.lang.reflect.Method.invoke(Method.java:597)

at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)

at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)

at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)

at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessagesWhileWaitingForReturn(BrowserChannelServer.java:337)

at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:218)

at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:136)

at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:561)

at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:269)

at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:91)

at com.google.gwt.core.client.impl.Impl.apply(Impl.java)

at com.google.gwt.core.client.impl.Impl.entry0(Impl.java:213)

at sun.reflect.GeneratedMethodAccessor24.invoke(Unknown Source)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

at java.lang.reflect.Method.invoke(Method.java:597)

at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)

at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)

at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)

at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessages(BrowserChannelServer.java:292)

at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:546)

at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:363)

at java.lang.Thread.run(Thread.java:680)



I would really appreciate some hemp.


Thanks.


Blake McBride


Jens

unread,
Apr 14, 2012, 12:35:53 PM4/14/12
to google-we...@googlegroups.com
You start your GWT app and your Netbeans server app independently of each other? If so, you have run into the Same-Origin-Policy implemented by web browsers (http://en.wikipedia.org/wiki/Same_origin_policy). This means that your GWT application that is running on http://127.0.0.1:8888 can only make JavaScript Ajax requests to locations also available on http://127.0.0.1:8888. It can not access locations on a different protocol://host:port combination.

You can solve this using one of the following ways:
1.) Run your GWT frontend on the same protocol://host:port as your Netbeans server project (= deploy your GWT app to your Tomcat server and use GWT DevMode with the -noserver option).
2.) Let your GWT frontend have its own server part that communicates with your Netbeans server project on your Tomcat server.
3.) Use a reverse proxy that transparently maps http://127.0.0.1:8888/<your GWT App Name>/GWTServlet to http://127.0.0.1:8084/MyApp/GWTServlet

And maybe:
4.) Use GWT's JsonpRequestBuilder along with JSON services on your server instead of GWT-RPC (http://en.wikipedia.org/wiki/JSONP).


Btw: Your server implementation of GWTServlet should implement the ArahantService interface.

-- J.

Blake McBride

unread,
Apr 14, 2012, 1:03:20 PM4/14/12
to google-we...@googlegroups.com
Wow.  I was trying to use RPC to get past SOP.  I can't deploy them together because I need the development environment to develop and that means separate environments.  Having two backends communicate adds an undesired additional layer.

I had JSONP working just fine but couldn't get two way communications when getting past SOP.  I could only pass data in one direction.

Most of my backend uses web services.  Is there anyway to get to that?

Thanks for the help.

Blake


-- J.

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-web-toolkit/-/eGN2WL84QU0J.
To post to this group, send email to google-we...@googlegroups.com.
To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.

Jesse Hutton

unread,
Apr 16, 2012, 1:23:38 PM4/16/12
to google-we...@googlegroups.com
Are you missing "implements ArahantService" in your RPC servlet?

Jesse

> --
> You received this message because you are subscribed to the Google Groups
> "Google Web Toolkit" group.

Reply all
Reply to author
Forward
0 new messages