001 /**
002 * Copyright (C) 2009-2011 the original author or authors.
003 * See the notice.md file distributed with this work for additional
004 * information regarding copyright ownership.
005 *
006 * Licensed under the Apache License, Version 2.0 (the "License");
007 * you may not use this file except in compliance with the License.
008 * You may obtain a copy of the License at
009 *
010 * http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018
019 package org.fusesource.restygwt.client.dispatcher;
020
021 import org.fusesource.restygwt.client.Dispatcher;
022 import org.fusesource.restygwt.client.Method;
023
024 import com.google.gwt.core.client.GWT;
025 import com.google.gwt.http.client.Request;
026 import com.google.gwt.http.client.RequestBuilder;
027 import com.google.gwt.http.client.RequestException;
028
029 /**
030 * Some valuable ideas came from:
031 * http://turbomanage.wordpress.com/2010/07/12/caching
032 * -batching-dispatcher-for-gwt-dispatch/
033 * <p/>
034 * Thanks David!
035 * <p/>
036 * Especially: - Waiting if a particular request is already on the way
037 * (otherwise you end up having many requests on the same source.
038 *
039 * @author <a href="mailto:mail@raphaelbauer.com">rEyez</<a>
040 * @author <a href="http://hiramchirino.com">Hiram Chirino</a>
041 */
042 public class DefaultDispatcher implements Dispatcher {
043
044 public static final DefaultDispatcher INSTANCE = new DefaultDispatcher();
045
046 public Request send(Method method, RequestBuilder builder) throws RequestException {
047 GWT.log("Sending http request: " + builder.getHTTPMethod() + " "
048 + builder.getUrl() + " ,timeout:"
049 + builder.getTimeoutMillis(), null);
050
051 String content = builder.getRequestData();
052 if (content != null && content.length() > 0) {
053 GWT.log(content, null);
054 }
055 return builder.send();
056 }
057
058
059 }