[Yanel-commits] rev 32469 -
public/yanel/contributions/ajax-components/src/core/java/org/wyona/yanel/gwt/client
michi at wyona.com
michi at wyona.com
Mon Feb 25 21:58:25 CET 2008
Author: michi
Date: 2008-02-25 21:58:25 +0100 (Mon, 25 Feb 2008)
New Revision: 32469
Modified:
public/yanel/contributions/ajax-components/src/core/java/org/wyona/yanel/gwt/client/AsynchronousAgent.java
Log:
formatting and some alerts added
Modified: public/yanel/contributions/ajax-components/src/core/java/org/wyona/yanel/gwt/client/AsynchronousAgent.java
===================================================================
--- public/yanel/contributions/ajax-components/src/core/java/org/wyona/yanel/gwt/client/AsynchronousAgent.java 2008-02-25 20:45:22 UTC (rev 32468)
+++ public/yanel/contributions/ajax-components/src/core/java/org/wyona/yanel/gwt/client/AsynchronousAgent.java 2008-02-25 20:58:25 UTC (rev 32469)
@@ -9,32 +9,41 @@
import com.google.gwt.http.client.RequestBuilder;
import com.google.gwt.http.client.RequestCallback;
import com.google.gwt.http.client.RequestException;
+import com.google.gwt.user.client.Window;
/**
* Asynchronous agents are calling some URL in an asynchronous way.
- * */
+ * See http://code.google.com/p/bunsenandbeaker/wiki/DevGuideHttpRequests
+ */
public abstract class AsynchronousAgent implements RequestCallback{
- private RequestBuilder requestBuilder = null;
+ private RequestBuilder requestBuilder = null;
+ private String url = null;
+ private Map/*<String, String>*/ parameters = new HashMap/*<String, String>*/();
- private String url = null;
- private Map/*<String, String>*/ parameters = new HashMap/*<String, String>*/();
+ /**
+ * Default request using GET method and application/x-www-form-urlencoded content type within header
+ */
+ public AsynchronousAgent(String url){
+ this.url = url;
+ requestBuilder = new RequestBuilder(RequestBuilder.GET, url);
+ initializeHeaders();
+ }
- public AsynchronousAgent(String url){
- requestBuilder = new RequestBuilder(RequestBuilder.GET, url);
- initializeHeaders();
- }
+ /**
+ *
+ */
+ public AsynchronousAgent(String url, RequestBuilder.Method method){
+ this.url = url;
+ requestBuilder = new RequestBuilder(method, url);
+ initializeHeaders();
+ }
- public AsynchronousAgent(String url, RequestBuilder.Method method){
- requestBuilder = new RequestBuilder(method, url);
- initializeHeaders();
- }
-
- /**
- * If no request headers have been set, the header "Content-Type" will be used with a value of "text/plain; charset=utf-8"
- * */
- protected void initializeHeaders(){
- requestBuilder.setHeader("Content-Type", "application/x-www-form-urlencoded");
- }
+ /**
+ * If no request headers have been set, the header "Content-Type" will be used with a value of "text/plain; charset=utf-8"
+ */
+ protected void initializeHeaders(){
+ requestBuilder.setHeader("Content-Type", "application/x-www-form-urlencoded");
+ }
/**
* Sending the parameter depends on a content type and the receiving party
@@ -55,18 +64,26 @@
return data;
}
+
+ /**
+ * Send request
+ */
+ public final Request execute() throws RequestException{
+ Window.alert("Send request: " + url);
+ return requestBuilder.sendRequest(buildRequestData(), this);
+ }
- public final Request execute() throws RequestException{
- return requestBuilder.sendRequest(buildRequestData(), this);
- }
-
public void addParameter(String name, String value){
parameters.put(name, value);
}
-
- public void onError(Request request, Throwable exception) {
- if(!GWT.isScript()){
- exception.printStackTrace();
- }
+
+ /**
+ *
+ */
+ public void onError(Request request, Throwable exception) {
+ Window.alert("Exception: " + exception.getMessage());
+ if(!GWT.isScript()){
+ exception.printStackTrace();
+ }
}
}
More information about the Yanel-commits
mailing list