The address is formatted like this:. The scheme specifies the protocol or type of server. The example. If a username is required, it is inserted before the server name:. You can connect to different types of servers. Some servers are public, and allow anybody to connect. Other servers require you to log in with a username and password. You may not have permissions to perform certain actions on files on a server.
For example, on public FTP sites, you will probably not be able to delete files. The URL you enter depends on the protocol that the server uses to export its file shares. If you have a secure shell account on a server, you can connect using this method. Many web hosts provide SSH accounts to members so they can securely upload files. SSH servers always require you to log in.
FTP is a popular way to exchange files on the Internet. Some servers, however, still allow or require you to use FTP to upload or download files.
FTP sites with logins will usually allow you to delete and upload files. Sites that allow you to download files will sometimes provide public or anonymous FTP access.
If these types are changed, or new serializable types are added to your RPC calls, the GWT compiler will generate a new. You will need to replace the old file deployed on your web server with the newly generated file.
There are many options you can pass to the development mode process to control how you want to start up the development mode browser. These options can differ slightly from version to version, but will generally include the options shown in the command-line help text below:.
Any time you want to look up the development mode options available for your version of GWT, you can simply invoke the DevMode class from command-line as shown above and it will list out the options available along with their descriptions. Run the command from the directory containing gwt-dev. Early adopters may wish to try out an alternative to Development Mode. See Introducing Super Dev Mode.
After you have your application working well in development mode, you will want to try out your application in your target web browsers; that is, you want to run it in production mode. Running your application in production mode allows you to test your application as it is deployed. If you have a servlet component specified in your web. You can also take a different browser or a browser running on another machine and point it at the same URL substitute the hostname or IP address of your workstation for localhost in the URL.
The GWT compiler supports the vast majority of the Java language. The GWT runtime library emulates a relevant subset of the Java runtime library. If a JRE class or method is not supported, the compiler will emit an error.
You can run the compiler with the name of the module you want to compile in one of the following manners:. Once compilation completes successfully, directories will be created containing the JavaScript implementation of your project. The compiler will create one directory for each module it compiles.
You may have noticed in the compilation target in the build. See this war directory FAQ for more details. The other thing you may have noticed is that there are a number of other files generated along with the GWT compiler output.
Of these there are a few that are key to deploying your application. The only difference is where these files are now generated, and the fact that the host HTML page and CSS files are not in the same directory as the rest of the. These are the key applications files to deploy you GWT application on your web server.
The host HTML page is the first page your clients should visit when they browse to your application and is also where the rest of your application files are loaded from.
You could also load the script from anywhere else in a website, but the default start page is typically the entry point that developers use to load their GWT applications.
The host page from the Hello starter sample application mentioned above is shown below. You may have noticed that one of the generated files is named after your module, followed by a. This is the GWT bootstrap file. This file is responsible for choosing the correct version of your application to load for your client based on their browser and locale, or any other custom selection rule see Deferred Binding.
The host HTML page references this file so that clients visiting your page first download the bootstrap, and the bootstrap script in turn figures out which browser environment it is running in and determines the appropriate version of your application to load. See the documentation on the bootstrap process for more details. They represent one version of your application tailored to a specific browser or locale. All public resources, such as image files, stylesheets or XML files, can be placed anywhere under the war directory or any subdirectory therein during development.
As long as references to these resources in your GWT application code hold when deployed, you can expect your application to work properly in production. In GWT 1. The above example is a good way to test your application from client to server, but may not be the best production setup. Also, you may already have a web infrastructure setup for serving static content that you would like to leverage.
The following example will show you how to split the web engine deployment from the static content. To setup your Tomcat server, just deploy the entire war, including both kinds of content. The reason for including static content is that servlets may need to use ServletContext. In this case, there is going to be a problem. Specific directions for configuring Apache and Tomcat for such a proxy setup are at the Apache website. That way Apache will serve all the static content, and your Tomcat server will only be used for service calls.
For this example, assume that:. If you get something different hitting the second URL, you may have a configuration issue. It should be mentioned that these are just two examples of deployment scenarios.
There are many ways to configure your application for deployment:. Tip: You can also use a real production server while debugging in development mode. This can be useful if you are adding GWT to an existing application, or if your server-side requirements have become more than the embedded web server can handle. See this article on how to use an external server in development mode.
Making HTTP requests in GWT works much like it does in any language or framework, but there are a couple of important differences you should be aware of. When sending an HTTP request, the client code must register a callback method that will handle the response or the error, if the call fails.
For more information about the exclusion of synchronous server connections, you may want to check out this FAQ article. SOP prevents client-side JavaScript code from interacting with untrusted and potentially harmful resources loaded from other websites. Once you have a RequestBuilder object, you can use its methods to set the username , password , and timeout interval.
You can also set any number of headers in the HTTP request. The RequestCallback argument you pass will handle the response or the error that results. When a request completes normally, your onResponseReceived Request, Response method is invoked. Details of the response for example, status code , HTTP headers , and response text can be retrieved from the Response argument. If the call does not complete normally, the onError Request, Throwable method gets called, with the second parameter describing the type error that occurred.
You can use the Request object that is returned from sendRequest String, RequestCallback to monitor the status of the call, and cancel it if necessary. Once you receive the response from the server using Response. Using the AsyncCallback interface is new to many developers.
Code is not necessarily executed sequentially, and it forces developers to handle situations where a server call is in progress but has not completed. Despite these seeming drawbacks, the designers of GWT felt it was an essential part of creating usable interfaces in AJAX for several reasons:. Browser mechanics aside, asynchronous RPC gives your application the ability to achieve true parallelism in your application, even without multi-threading. For example, suppose your application displays a large table containing many widgets.
Constructing and laying out all those widgets can be time consuming. At the same time, you need to fetch data from the server to display inside the table.
This is a perfect reason to use asynchronous calls. Initiate an asynchronous call to request the data immediately before you begin constructing your table and its widgets.
While the server is fetching the required data, the browser is executing your user interface code. When the client finally receives the data from the server, the table has been constructed and laid out, and the data is ready to be displayed. To give you an idea of how effective this technique can be, suppose that building the table takes one second and fetching the data takes one second.
If you make the server call synchronously, the whole process will require at least two seconds. Tip: Most browsers restrict the number of outgoing network connections to two at a time, restricting the amount of parallelism you can expect from multiple simultaneous RPCs. The hardest thing to get used to about asynchronous calls is that the calls are non-blocking, however, Java inner classes go a long way toward making this manageable.
Consider the following implementation of an asynchronous call adapted from the Dynamic Table sample application. It uses a slightly different syntax to define the required interface for the AsyncCallback object that is the last parameter to the getPeople RPC call:. The important issue to understand is that that the code that follows the RPC call invocation will be executed while the actual round trip to the server is still in progress.
Although the code inside the onSuccess method is defined inline with the call, it will not be executed until both the calling code returns back to the JavaScript main loop, and the result message from the server returns. This feature did not work out as planned, and the GWT team strongly discourages its use. Try the Request Factory feature when you have non-trivial server-domain objects.
Server Communication At some point, most GWT applications will need to interact with a backend server. Server-side Code Everything that happens within your web server is referred to as server-side processing.
Define a class to implement the server-side code that extends RemoteServiceServlet and implements the interface you created above. Define an asynchronous interface to your service to be called from the client-side code. Synchronous Interface To begin developing a new service interface, create a client-side Java interface that extends the RemoteService tag interface.
RemoteServiceServlet; import com. Asynchronous Interfaces Before you can actually attempt to make a remote call from the client, you must create another client interface, an asynchronous one, based on your original service interface.
Continuing with the example above, create a new interface in the client subpackage: package com. Naming Standards Note the use of the suffix Async and argument referencing the AsyncCallback class in the examples above.
A service interface must have a corresponding asynchronous interface with the same package and name with the Async suffix appended.
For example, if a service interface is named com. SpellingService , then the asynchronous interface must be called com. Each method in the synchronous service interface must have a corresponding method in the asynchronous service interface with an extra AsyncCallback parameter as the last argument.
Implementing Services Every service ultimately needs to perform some processing to order to respond to client requests. Testing Services During Development GWT development mode includes an embedded version of Jetty which acts as a development-time servlet container for testing. Common Pitfalls Here are some commonly seen errors trying to get RPC running: When you start development mode, you see a ClassNotFoundException exception on the console, and the embedded server returns an error.
Be sure to compile your server classes into this location. If you are using an Ant build. This most likely means you forgot to copy gwt-servlet. This error means that you did not specify a RemoteServiceRelativePath in your service interface, and you also did not manually set target path by calling ServiceDefTarget.
Create an asynchronous callback object to be notified when the RPC has completed. Make the call. A type is serializable and can be used in a service interface if one of the following is true: The type is primitive, such as char , byte , short , int , long , boolean , float , or double. The type is an enumeration. Enumeration constants are serialized as a name only; none of the field values are serialized.
The type is an array of serializable types including other serializable arrays. The type is a serializable user-defined class. The type has at least one serializable subclass. The type has a Custom Field Serializer The class java. Serializable User-defined Classes A user-defined class is serializable if all of the following apply: It is assignable to IsSerializable or Serializable , either because it directly implements one of these interfaces or because it derives from a superclass that does All non- final , non- transient instance fields are themselves serializable, and As of GWT 1.
Raw Types Collection classes such as java. The class is annotated with a JPA javax. Entity annotation.
0コメント