Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2013 Jeanfrancois Arcand
   *
   * 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 org.atmosphere.wasync;
 
 import java.util.List;
 import java.util.Map;
Base class for building Request

Author(s):
jeanfrancois Arcand
 
 public abstract class RequestBuilder<T extends RequestBuilder<T>> {
 
     protected final List<Request.TRANSPORTtransports = new ArrayList<Request.TRANSPORT>();
     protected Request.METHOD method = ..;
     protected String uri = "http://localhost:8080";
     protected final List<Encoder<?, ?>> encoders = new CopyOnWriteArrayList<Encoder<?, ?>>();
     protected final List<Decoder<?, ?>> decoders = new CopyOnWriteArrayList<Decoder<?, ?>>();
     protected final Map<StringCollection<String>> headers = new HashMap<StringCollection<String>>();
     protected final Map<StringList<String>> queryString = new HashMap<StringList<String>>();
     protected final Class<T> derived;
 
     protected RequestBuilder(Class<T> derived) {
         this. = derived;
     }

    
The Request.TRANSPORT to use. This method can be invoked several time and the library will loop over the list until one Request.TRANSPORT succeed. The first added is always the first used.

Parameters:
t
Returns:
this
 
     public T transport(Request.TRANSPORT t) {
         .add(t);
         return .cast(this);
     }

    
The method to use for connecting tho the remote server. It is recommended to always use Request.METHOD.GET

Parameters:
method
Returns:
this
 
     public T method(Request.METHOD method) {
         this. = method;
         return .cast(this);
     }

    
The URI to connect to.

Parameters:
uri a uri to connect to
Returns:
this
 
     public T uri(String uri) {
         this. = uri;
         return .cast(this);
     }

    
Add an Encoder. Several Encoder can be added and will be invoked the order they were added. This method doesn't allow duplicate.

Parameters:
e an Encoder
Returns:
this
 
     public T encoder(Encoder e) {
         if (!.contains(e)) {
             .add(e);
         }
         return .cast(this);
     }

    
Add a Decoder. Several Decoder can be added and will be invoked the order they were added. This method doesn't allow duplicate.

Parameters:
d a Decoder
Returns:
this
 
     public T decoder(Decoder d) {
         if (!.contains(d)) {
             .add(d);
         }
        return .cast(this);
    }

    
Add a header.

Parameters:
name header name
value header value
Returns:
this
    public T header(String nameString value) {
        Collection<Stringl = .get(name);
        if (l == null) {
            l = new ArrayList<String>();
        }
        l.add(value);
        .put(namel);
        return .cast(this);
    }

    
Add a query param.

Parameters:
name header name
value header value
Returns:
this
    public T queryString(String nameString value) {
        List<Stringl = .get(name);
        if (l == null) {
            l = new ArrayList<String>();
        }
        l.add(value);
        .put(namel);
        return .cast(this);
    }

    
Add a FunctionResolver

Parameters:
resolver a FunctionResolver
Returns:
this
    public T resolver(FunctionResolver resolver) {
        this. = resolver;
        return .cast(this);
    }

    
Build a Request. IMPORTANT: if you are using stateful Decoder, you must NOT call this method more than once to prevent response corruption.

Returns:
a Request
    public abstract Request build();

    
Return the current list of Request.TRANSPORT

Returns:
the current list of Request.TRANSPORT
    public List<Request.TRANSPORTtransports() {
        return ;
    }

    
Return the HTTP method

Returns:
the HTTP method
    public Request.METHOD method() {
        return ;
    }

    
Return the current tMap of headers

Returns:
the current tMap of headers
    public Map<StringCollection<String>> headers() {
        return ;
    }

    
Return the current query string/form param

Returns:
the current query string/form param
    public Map<StringList<String>> queryString() {
        return ;
    }

    
Return the current list of Encoder

Returns:
the current list of Encoder
    public List<Encoder<?, ?>> encoders() {
        return ;
    }

    
Return the current list of Decoder

Returns:
the current list of Decoder
    public List<Decoder<?, ?>> decoders() {
        return ;
    }

    
Return the uri

Returns:
the uri
    public String uri() {
        return ;
    }

    
Return the current FunctionResolver

Returns:
the current FunctionResolver
    public FunctionResolver resolver() {
        return ;
    }
New to GrepCode? Check out our FAQ X