Budband
unread,Oct 29, 2009, 1:48:01 PM10/29/09Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to google-guice
I am new to Guice and wanted to use it on the Serverside. I am using
GWT plugin with Eclipse, which nicely creates a GWT project i.e. with
greeting service. Can anybody provide the changes I need to do to
make that a GUICE enabled project? I know that I need to inject the
GuiceModule to this code later !
What is wrong on the following changes: [The code cann't reach the
welcome html page]
_______
web.xml
___________________________________________________________
<web-app>
<!-- Servlets -->
<servlet>
<servlet-name>greetServlet</servlet-name>
<servlet-class>com.mycompany.server.MyDispatcher</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>greetServlet</servlet-name>
<url-pattern>greet</url-pattern>
</servlet-mapping>
<!-- Default page to serve -->
<welcome-file-list>
<welcome-file>GuiceWeb.html</welcome-file>
</welcome-file-list>
</web-app>
_________________
MyDispatcher.java
__________________________________________________________________________
public class MyDispathcer extends RemoteServiceServlet {
@Override
public String processCall(String payload) throws
SerializationException {
RPCRequest request = RPC.decodeRequest(payload);
java.lang.reflect.Method method = request.getMethod(); //
request.getMethod();
System.out.println(method.getName());
// Object targetInjectedInstance = injector.getInstance(method
// .getDeclaringClass());
Object targetInjectedInstance = new GreetingServiceImpl();
return RPC.invokeAndEncodeResponse(targetInjectedInstance, method,
request.getParameters());
}
}
_______________
GreetingService - [no changes here:]
_____________________________________________________________________
@RemoteServiceRelativePath("greet")
public interface GreetingService extends RemoteService {
String greetServer(String name);
}
_________________
GreetingServiceImpl [no changes here:]
______________________________
public class GreetingServiceImpl extends RemoteServiceServlet
implements
GreetingService {
public String greetServer(String input) {
String serverInfo = getServletContext().getServerInfo();
String userAgent = getThreadLocalRequest().getHeader("User-Agent");
return "Hello, " + input + "!<br><br>I am running " + serverInfo
+ ".<br><br>It looks like you are using:<br>" + userAgent;
}
}
Thanks