Guice + Servlet Example

109 Aufrufe
Direkt zur ersten ungelesenen Nachricht

Budband

ungelesen,
29.10.2009, 13:48:0129.10.09
an 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

Budband

ungelesen,
29.10.2009, 16:00:2329.10.09
an google-guice
Any other examples of Guice + GWT RPC would be great.

Alen Vrečko

ungelesen,
29.10.2009, 18:15:4129.10.09
an google-guice
Maybe this will give you some ideas: http://stuffthathappens.com/blog/2009/09/14/guice-with-gwt/

Cheers
Alen

Jamie Gennis

ungelesen,
06.11.2009, 10:43:0206.11.09
an google...@googlegroups.com
I recently started a project aimed at making GWT + Guice development easier.  It currently only works with GWT 2.0 + Guice 2.0 and has a run-time dependency on gwt-dev (for parsing .gwt.xml files), so it may not be suitable for some folks right now.

http://codehttp://code.google.com/p/ggdi/.google.com/p/ggdi/

The Guice-based GWT RPC dispatch code lives in these files:

For the old-style GWT RPC transport:

For the new GWT deRPC transport (which may or may not make it into the GWT 2.0 release):

Jamie

On Thu, Oct 29, 2009 at 2:15 PM, Alen Vrečko <alen_...@yahoo.com> wrote:

Maybe this will give you some ideas: http://stuffthathappens.chttp://code.google.com/p/ggdi/om/blog/2009/09/14/guice-with-gwt/
Allen antworten
Antwort an Autor
Weiterleiten
0 neue Nachrichten