All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.gwtplatform.dispatch.rest.client.gin.RestDispatchAsyncModuleBuilder Maven / Gradle / Ivy

There is a newer version: 1.6
Show newest version
/**
 * Copyright 2014 ArcBees Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */

package com.gwtplatform.dispatch.rest.client.gin;

import com.google.common.collect.LinkedHashMultimap;
import com.google.common.collect.Multimap;
import com.gwtplatform.dispatch.client.gin.AbstractDispatchAsyncModule;
import com.gwtplatform.dispatch.rest.client.DateFormat;
import com.gwtplatform.dispatch.rest.client.serialization.JsonSerialization;
import com.gwtplatform.dispatch.rest.client.serialization.Serialization;
import com.gwtplatform.dispatch.rest.shared.HttpMethod;
import com.gwtplatform.dispatch.rest.shared.RestParameter;

/**
 * A {@link RestDispatchAsyncModule} builder.
 * 

* The possible configurations are: *

    *
  • All configuration methods listed by {@link AbstractDispatchAsyncModule.Builder}
  • *
  • {@link #xsrfTokenHeaderName(String) XSRF Token Header Name}: * A {@link com.gwtplatform.dispatch.rest.client.XsrfHeaderName}. * The default value is {@link RestDispatchAsyncModule#DEFAULT_XSRF_NAME}.
  • *
  • {@link #serialization(Class) Serialization Implementation}: A {@link Serialization} implementation. * The default is {@link JsonSerialization}.
  • *
  • {@link #requestTimeout(int) Request timeout}: The number of milliseconds to wait for a request to complete. * The default value is 0 (no timeout).
  • *
*/ public class RestDispatchAsyncModuleBuilder extends AbstractDispatchAsyncModule.Builder { private String xsrfTokenHeaderName = RestDispatchAsyncModule.DEFAULT_XSRF_NAME; private Class serializationClass = JsonSerialization.class; private int requestTimeoutMs; private String defaultDateFormat = DateFormat.DEFAULT; private Multimap globalHeaderParams = LinkedHashMultimap.create(); private Multimap globalQueryParams = LinkedHashMultimap.create(); @Override public RestDispatchAsyncModule build() { return new RestDispatchAsyncModule(this); } /** * Specify the XSRF token header name. * * @deprecated See {@link #xsrfTokenHeaderName(String)} */ @Deprecated public RestDispatchAsyncModuleBuilder xcsrfTokenHeaderName(String xsrfTokenHeaderName) { this.xsrfTokenHeaderName = xsrfTokenHeaderName; return this; } /** * Specify the XSRF token header name. * * @param xsrfTokenHeaderName The XSRF token header name. * @return this {@link RestDispatchAsyncModuleBuilder builder} object. */ public RestDispatchAsyncModuleBuilder xsrfTokenHeaderName(String xsrfTokenHeaderName) { this.xsrfTokenHeaderName = xsrfTokenHeaderName; return this; } /** * Specify the serialization implementation to use. * Default is {@link JsonSerialization}. * * @param serializationClass The {@link Serialization} implementation to use. * @return this {@link RestDispatchAsyncModuleBuilder builder} object. */ public RestDispatchAsyncModuleBuilder serialization(Class serializationClass) { this.serializationClass = serializationClass; return this; } /** * Specify the number of milliseconds to wait for a request to complete. If the timeout is reached, * {@link com.google.gwt.user.client.rpc.AsyncCallback#onFailure(Throwable) AsyncCallback#onFailure(Throwable)} * will be called. * Default is 0: no timeout. * * @param timeoutMs The maximum time to wait, in milliseconds, or {@code 0} for no timeout. * @return this {@link RestDispatchAsyncModuleBuilder builder} object. */ public RestDispatchAsyncModuleBuilder requestTimeout(int timeoutMs) { this.requestTimeoutMs = timeoutMs; return this; } /** * Specify the pattern to use to format dates before they are sent to the end-point. The pattern must follow the * rules defined by {@link com.google.gwt.i18n.shared.DateTimeFormat DateTimeFormat}. *

* Default is {@link DateFormat#DEFAULT}. * * @param defaultDateFormat The pattern used to format dates. * @return this {@link RestDispatchAsyncModuleBuilder builder} object. */ public RestDispatchAsyncModuleBuilder defaultDateFormat(String defaultDateFormat) { this.defaultDateFormat = defaultDateFormat; return this; } /** * Initiate the creation of a global header parameter that will be attached to all requests. * * @param key The key used for this parameter * @return the parameter builder instance */ public RestParameterBuilder addGlobalHeaderParam(String key) { return new RestParameterBuilder(this, globalHeaderParams, key); } /** * Initiate the creation of a global query parameter that will be attached to all requests. * * @param key The key used for this parameter * @return the parameter builder instance */ public RestParameterBuilder addGlobalQueryParam(String key) { return new RestParameterBuilder(this, globalQueryParams, key); } public String getXsrfTokenHeaderName() { return xsrfTokenHeaderName; } public Class getSerializationClass() { return serializationClass; } public int getRequestTimeoutMs() { return requestTimeoutMs; } public String getDefaultDateFormat() { return defaultDateFormat; } public Multimap getGlobalHeaderParams() { return globalHeaderParams; } public Multimap getGlobalQueryParams() { return globalQueryParams; } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy