简体   繁体   中英

HTTP Request in GWT

i have to understand the whole RPC mechanism because i need it for my own project and especially for an upcoming exam.

@RemoteServiceRelativePath("message")
public interface MessageService extends RemoteService {
   Message getMessage(String input);
}

The "RemoteServiceRelativePath..." part is always confusing me. I don't understand how it works together with the HTTP URL and how the HTTP request works in general. I'm a beginner and it would be really cool if someone here could explain that to me :) Thanks in advance!

For me the most confusing part was how to use @RemoteServiceRelativePath("message") and what I have to put in the web.xml.

  <servlet-mapping>
    <servlet-name>greetServlet</servlet-name>
    <url-pattern>/sample/greet</url-pattern>
  </servlet-mapping>

So the url /sample/greet is made up of two strings in this case: the sample comes from your module name, you find that in your *.gwt.xml file.

<module rename-to='sample'>
    ...
</module>

and the greet part in it comes from @RemoteServiceRelativePath("greet")

@RemoteServiceRelativePath("greet")
public interface GreetingService extends RemoteService {
    String greetServer(String name) throws IllegalArgumentException;
}

this is not answering all you questions but maybe it helps you anyway

1) In Eclipse Configure GWT Plugins

2) Create the Google Web Application Project

2.1) Name the Project

2.2) Give Package structure (optional)

2.3) Uncheck App Engine Checkbox

2.4) Click Finish

3) GWT project is created with the standard package structure

client (UI)

server (Servlets)

shared (shared between client and server, ideal place to put models)

4) This sample project will be having GreetingService created by Default

I will explain you the RPC mechanism in detail

To communicate from Client (browser) to Server (web server) we need a servlet and in web application we map our servlets in web.xml

In our Sample project, we have Greeting Servlet which we need to map in the web.xml

Snippet from web.xml
 <servlet>
    <servlet-name>greetServlet</servlet-name>
    <servlet-class>com.server.GreetingServiceImpl</servlet-class>
  </servlet>

  <servlet-mapping>
    <servlet-name>greetServlet</servlet-name>
    <url-pattern>/sample/greet</url-pattern>
  </servlet-mapping>

In the server package we have the servlet GreetingServiceImpl, which extends RemoteServiceServlet whose super class is HttpServlet

public class GreetingServiceImpl extends RemoteServiceServlet implements
        GreetingService {

    public String greetServer(String input) throws IllegalArgumentException {

In the client package

we do have two interfaces GreetingService and GreetingServiceAsync

@RemoteServiceRelativePath("greet")
public interface GreetingService extends RemoteService {
    String greetServer(String name) throws IllegalArgumentException;
}

Note that the path to the servlet is given in @RemoteServiceRelativePath

public interface GreetingServiceAsync {
    void greetServer(String input, AsyncCallback<String> callback)
            throws IllegalArgumentException;
}

callback is the parameter in which we will get the response

References

http://h2g2java.blessedgeek.com/2010/02/tutorial-gwt-rpc-stub-modified-with.html

http://www.gwtproject.org/doc/latest/tutorial/RPC.html

Hope this helps!!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM