/** * 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<B> addGlobalQueryParam(String key) { return new RestParameterBuilder<>(self(), Type.QUERY, globalQueryParams, key); }
/** * Creates this module using the default values as specified by {@link RestDispatchAsyncModuleBuilder}. */ public RestDispatchAsyncModule() { this(new RestDispatchAsyncModuleBuilder()); }
/** * Specify the XSRF token header name. * * @param xsrfTokenHeaderName The XSRF token header name. * * @return this {@link com.gwtplatform.dispatch.rest.client.gin.BaseRestDispatchModuleBuilder builder} object. */ public B xsrfTokenHeaderName(String xsrfTokenHeaderName) { this.xsrfTokenHeaderName = xsrfTokenHeaderName; return self(); }
@Override protected void configureDispatch() { // Common install(new CommonGinModule()); install(new SerializationModule()); install(builder.getCoreModule()); bind(RestFilterRegistry.class).to(builder.getFilterRegistry()).in(Singleton.class); // Constants / Configurations // It's not possible to bind non-native type constants, so we must encode them at compile-time and decode them // at runtime (ie: Global Parameters) String globalHeaderParams = bindingsSerializer.serialize(builder.getGlobalHeaderParams()); String globalQueryParams = bindingsSerializer.serialize(builder.getGlobalQueryParams()); bindConstant().annotatedWith(XsrfHeaderName.class).to(builder.getXsrfTokenHeaderName()); bindConstant().annotatedWith(RequestTimeout.class).to(builder.getRequestTimeoutMs()); bindConstant().annotatedWith(DefaultDateFormat.class).to(builder.getDefaultDateFormat()); bindConstant().annotatedWith(GlobalHeaderParams.class).to(globalHeaderParams); bindConstant().annotatedWith(GlobalQueryParams.class).to(globalQueryParams); }
@Override protected void configure() { install(new RestDispatchAsyncModule.Builder().xsrfTokenHeaderName(ResourcePaths.XSRF_HEADER) .build()); bindConstant().annotatedWith(SecurityCookie.class).to(ResourcePaths.XSRF_COOKIE); }
/** * Used to serialize the bindings at compilation. Usage of GWT code is <b>not</b> allowed. */ public String serialize(RestParameterBindings parameterBindings) { StringBuilder result = new StringBuilder("{"); for (Entry<HttpMethod, Set<HttpParameter>> entry : parameterBindings.entrySet()) { serializeValues(result, entry.getKey(), entry.getValue()); } if (!parameterBindings.isEmpty()) { result.deleteCharAt(result.length() - 1); } result.append("}"); return result.toString(); }
@Override protected void configure() { install(new RestDispatchAsyncModule.Builder().build()); }
@Override public RestDispatchAsyncModule build() { return new RestDispatchAsyncModule(this); }
private void addGlobalHeaders(RestAction<?> action, List<HttpParameter> headerParams) { headerParams.addAll(globalParams.get(action.getHttpMethod())); }
@Provides @Singleton @GlobalQueryParams RestParameterBindings getGlobalQueryParams(@GlobalQueryParams String encodedParams) { return bindingsSerializer.deserialize(encodedParams); } }
@Override public String encodePathSegment(String decodedPathSegment) { return encodeQueryString(decodedPathSegment); }
@Override public CoreModule getCoreModule() { return core().getCoreModule(); } }
/** * Define the value of this parameter. * * @param value The value for this parameter. * * @return The module builder instance. */ public B withValue(String value) { HttpParameter parameter = new ClientHttpParameter(type, key, value, null); for (HttpMethod httpMethod : httpMethods) { target.put(httpMethod, parameter); } return moduleBuilder; } }
@Override protected void configure() { install(new RestDispatchAsyncModule.Builder().xsrfTokenHeaderName(ResourcePaths.XSRF_HEADER) .build()); bindConstant().annotatedWith(SecurityCookie.class).to(ResourcePaths.XSRF_COOKIE); }
/** * 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<B> addGlobalHeaderParam(String key) { return new RestParameterBuilder<>(self(), Type.HEADER, globalHeaderParams, key); }
/** * Specify an alternate REST filter registry. * * @param filterRegistry A {@link com.gwtplatform.dispatch.rest.client.filter.RestFilterRegistry} class. * * @return this {@link com.gwtplatform.dispatch.rest.client.gin.BaseRestDispatchModuleBuilder builder} object. */ public B filterRegistry(Class<? extends RestFilterRegistry> filterRegistry) { this.filterRegistry = filterRegistry; return self(); }
private List<HttpParameter> getParameters(RestAction<?> action, Type type) { List<HttpParameter> queryParams = new ArrayList<>(); queryParams.addAll(globalQueryParams.get(action.getHttpMethod())); queryParams.addAll(action.getParameters(type)); return queryParams; }
@Provides @Singleton @GlobalHeaderParams RestParameterBindings getGlobalHeaderParams(@GlobalHeaderParams String encodedParams) { return bindingsSerializer.deserialize(encodedParams); }
/** * 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 <code>0</code>: no timeout. * * @param timeoutMs The maximum time to wait, in milliseconds, or {@code 0} for no timeout. * * @return this {@link com.gwtplatform.dispatch.rest.client.gin.BaseRestDispatchModuleBuilder builder} object. */ public B requestTimeout(int timeoutMs) { this.requestTimeoutMs = timeoutMs; return self(); }
/** * 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}. * <p/> * Default is {@link com.gwtplatform.dispatch.rest.shared.DateFormat#DEFAULT}. * * @param defaultDateFormat The pattern used to format dates. * * @return this {@link com.gwtplatform.dispatch.rest.client.gin.BaseRestDispatchModuleBuilder builder} object. */ public B defaultDateFormat(String defaultDateFormat) { this.defaultDateFormat = defaultDateFormat; return self(); }