Steps to create a simple RPC in hosted mode

15 views
Skip to first unread message

pierrot

unread,
Jun 8, 2006, 10:11:31 AM6/8/06
to Google Web Toolkit
Hi I've created a simple RPC application like this:

1) >projectCreator -eclipse MyProject
2) >applicationCreator -eclipse MyProject
com.MyCompany.client.MyProject
3) Then I imported MyProject into Eclipse.
4) Then I created the following java files:

DateService.java

package com.MyCompany.client;
import com.google.gwt.user.client.rpc.RemoteService;
public interface DateService extends RemoteService {
public String getDate(String prefix);
}

DateServiceAsync.java

package com.MyCompany.client;
import com.google.gwt.user.client.rpc.AsyncCallback;
public interface DateServiceAsync {
public void getDate(String prefix, AsyncCallback callback);
}

DateServiceImpl.java

package com.MyCompany.server;
import java.util.Date;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import com.MyCompany.client.DateService;
public class DateServiceImpl extends RemoteServiceServlet
implements DateService {
public String getDate(String prefix) {
Date d = new Date();
return d.toString();
}
}

MyProject.java

package com.MyCompany.client;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.rpc.ServiceDefTarget;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.Widget;
public class RPCTomcat implements EntryPoint {
private Button button = new Button("Click Me");
private Label label = new Label("Invoke DateService");
public void onModuleLoad() {
class btnClkListener implements ClickListener{
public void onClick(Widget sender) {
DateServiceAsync dateService = (DateServiceAsync)
GWT.create(DateService.class);
ServiceDefTarget endpoint = (ServiceDefTarget)
dateService;
endpoint.setServiceEntryPoint("/date");
AsyncCallback callback = new AsyncCallback() {
public void onSuccess(Object result) {
label.setText(result.toString());
}
public void onFailure(Throwable caught) {
label.setText("DateService Failed");
}
};
dateService.getDate("prefix", callback);
}
}
button.addClickListener(new btnClkListener());
RootPanel.get().add(button);
RootPanel.get().add(label);
}
}

5) I then modified MyProject.gwt.xml like this:

<module>
<!-- Inherit the core Web Toolkit stuff. -->
<inherits name='com.google.gwt.user.User'/>

<!-- Specify the app entry point class. -->
<entry-point class='com.MyCompany.client.MyProject'/>
<servlet path="/date" class="com.MyCompany.server.DateServiceImpl"/>
</module>

6) With MyProject-shell.cmd my RPC works very well.
7) It is also possible to access it from any browser with the following
URL:

http://mycomputer:8888/com.MyCompany.MyProject/MyProject.html

Of course the GWT development shell has to be active.

Now the big question is this: I've been trying to deploy MyProject into
my Tomcat server for a few days now. I need help on how to package
MyProject into a WAR file. I tried some suggestions already on this
site but it didn't work.

Cheerio.

tim.i...@gmail.com

unread,
Jun 8, 2006, 12:02:22 PM6/8/06
to Google Web Toolkit
Try this tutorial for deploying to Tomcat.
www.adp-gmbh.ch/blog/2004/october/13.html

ednardo

unread,
Jun 9, 2006, 12:37:19 PM6/9/06
to Google Web Toolkit
I need to access a external library in servlet.
Somebody can help me?

Ednardo

d...@yorkemail.org

unread,
Jun 9, 2006, 3:27:59 PM6/9/06
to Google Web Toolkit
The main thing is to make sure the external library is in your
classpath. If you're deploying it on Tomcat (or some other engine) put
the correct jars in WEB-INF/lib. If you're using hosted mode, edit the
shell script to add the jars into the classpath there (the path after
-cp).

ednardo

unread,
Jun 9, 2006, 4:47:38 PM6/9/06
to Google Web Toolkit
Thanks,

I already had attemped almost all its suggestions, less to edit script,
and now it's working!

Ednardo

anudeep...@gmail.com

unread,
Jun 17, 2006, 9:22:00 AM6/17/06
to Google Web Toolkit
i get the following throwable while making a rpc call when servlet is
deployed on weblogic.

Click Me
DateService Failed 1com.google.gwt.user.client.rpc.InvocationException:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Draft//EN">
<HTML>
<HEAD>
<TITLE>Error 404--Not Found</TITLE>
<META NAME="GENERATOR" CONTENT="WebLogic Server">
</HEAD>
<BODY bgcolor="white">
<FONT FACE=Helvetica><BR CLEAR=all>
<TABLE border=0 cellspacing=5><TR><TD><BR CLEAR=all>
<FONT FACE="Helvetica" COLOR="black" SIZE="3"><H2>Error 404--Not
Found</H2>
</FONT></TD></TR>
</TABLE>
<TABLE border=0 width=100% cellpadding=10><TR><TD VALIGN=top WIDTH=100%
BGCOLOR=white><FONT FACE="Courier New"><FONT FACE="Helvetica"
SIZE="3"><H3>From RFC 2068 <i>Hypertext Transfer Protocol --
HTTP/1.1</i>:</H3>
</FONT><FONT FACE="Helvetica" SIZE="3"><H4>10.4.5 404 Not Found</H4>
</FONT><P><FONT FACE="Courier New">The server has not found anything
matching the Request-URI. No indication is given of whether the
condition is temporary or permanent.</p><p>If the server does not wish
to make this information available to the client, the status code 403
(Forbidden) can be used instead. The 410 (Gone) status code SHOULD be
used if the server knows, through some internally configurable
mechanism, that an old resource is permanently unavailable and has no
forwarding address.</FONT></P>
</FONT></TD></TR>
</TABLE>


</BODY>
</HTML>

it works fine with shell..please guide me what to do next.

anudeep...@gmail.com

unread,
Jun 17, 2006, 11:21:43 AM6/17/06
to Google Web Toolkit
i made it work on Tomcat.

Mike Pastor

unread,
Jun 25, 2006, 12:48:20 AM6/25/06
to Google Web Toolkit
Have you been able to get this example working on Tomcat? I've tried
several 'simple' examples, but cannot the callbacks and RPC calls
working in Tomcat 5.5. They work fine in the Google development
shell, but cannot be exported to an external Tomcat server.

Does anyone have a working Tomcat example? Is GWT stable enough for a
production system at this time in history?

Thanks & Cheers,
Mike Pastor

mcoruh

unread,
Jun 27, 2006, 6:41:46 AM6/27/06
to Google Web Toolkit
Yes, I have same problem with Tomcat 5.5...

I realized that dynamic table sample application is well and its
compiled outputs works well in many webserver(sun One, Tomcat 5.5)
Hovever when I tried to build dynamic table by shell batch in the
sample directory I have taken error messages....

Thanks....

pierrot

unread,
Jun 28, 2006, 8:38:40 AM6/28/06
to Google Web Toolkit
In the <endpoint.setServiceEntryPoint("/date");> statement the
<"/date"> has to be changed to something like this:
<"http://localhost:8080/MyContext/MyServlet">.

I also presume that you have successfully implemented the MyServlet in
Tomcat 5.5.

Cheerio.

Mel

unread,
Jul 16, 2006, 1:42:55 PM7/16/06
to Google Web Toolkit

Quick question, I am trying to run the sample code above but I cannot
get the CLICK ME button to produce either response. I inserted the
code into an established GWT project where I toying with other widgets
and wondered if anyone had time to tell me what I'm doing wrong(?). I
am running on Eclipse 3.2 and running in hosted mode I get my page but
when I click the button I get NOTHING. No error or either of the
button's response. Here is my code:

public class MyApplication implements EntryPoint {


private Button button = new Button("Click Me");
private Label label = new Label("Invoke DateService");

/**
* This is the entry point method.
*/
public void onModuleLoad() {

final FlexTable ft = new FlexTable();

final Trees tree = new Trees();

final TabPanel tabs = new TabPanel();
// Create tabs.
tabs.add(new HTML("First Tab"), "One");
tabs.add(new HTML("Second Tab"), "Two");
tabs.add(new HTML("Third Tab"), "Three");
tabs.add(tree, "Details"); // Add the TREES widget inside the
TabPanel widget.

// Show the 'bar' tab.
tabs.selectTab(0);
ft.setWidget(0, 0, tabs);

final AutoCompleteTextBox box = new AutoCompleteTextBox();

// Show an autocomplete textbox.
box.setCompletionItems(new SimpleAutoCompletionItems(
new String[]{ "apple", "ape", "anything", "else"}));
// This getCompletionItems is based on RPC.
// box.getCompletionItems();
ft.setWidget(1, 0, box);

// RPC code


class btnClkListener implements ClickListener{
public void onClick(Widget sender) {
DateServiceAsync dateService =
(DateServiceAsync)GWT.create(DateService.class);
ServiceDefTarget endpoint = (ServiceDefTarget)dateService;
endpoint.setServiceEntryPoint("/date");
AsyncCallback callback = new AsyncCallback() {
public void onSuccess(Object result) {
label.setText(result.toString());
}
public void onFailure(Throwable caught) {
label.setText("DateService Failed");
}
};
dateService.getDate("prefix", callback);
}
}
button.addClickListener(new btnClkListener());

ft.setWidget(2, 0, button);

VerticalPanel vp = new VerticalPanel();
vp.add(ft);
RootPanel.get("slot1").add(vp);
}
}

Any insight or direction would be appreciated. Thank you!!

Reply all
Reply to author
Forward
0 new messages