net.craftforge.essential.client
Class NetworkClient

java.lang.Object
  extended by net.craftforge.essential.client.NetworkClient
All Implemented Interfaces:
Client

public class NetworkClient
extends Object
implements Client

A network client performs client requests remotely via HTTP.

Since:
06.07.11
Author:
Christian Bick

Constructor Summary
NetworkClient(String urlBasePart)
          Creates an HTTP client that uses the given URL base part for its requests.
 
Method Summary
protected  ClientResponse getClientResponse(org.apache.http.HttpResponse httpResponse)
          Gets the client response from the provided HTTP response.
protected  org.apache.http.client.methods.HttpRequestBase getHttpRequest(ClientRequest request)
          Gets an HTTP request from the provided client request.
protected  org.apache.http.Header[] getRequestHeaders(Map<String,String[]> headers)
          Gets the HTTP headers from the provided header map.
protected  org.apache.http.params.HttpParams getRequestParameters(Map<String,String[]> parameters)
          Gets the HTTP parameters from the provided parameter map.
protected  Map<String,String[]> getResponseHeaders(org.apache.http.Header[] headers)
          Gets the response header map from the given HTTP headers.
 ClientResponse performRequest(ClientRequest clientRequest)
          Performs an HTTP request from the data provided by the given client request and retrieves an HTTP response that as provided as client response.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NetworkClient

public NetworkClient(String urlBasePart)

Creates an HTTP client that uses the given URL base part for its requests. The URL base part looks like follows.

schema: protocol://host:port/context

example: http://api.craftforge.net:8080/core

The URL base part is prefixed to every URL info part of a request. Together with an optional URL query part the complete request URL is assembled from these three parts.

Parameters:
urlBasePart - The URL base part
Method Detail

performRequest

public ClientResponse performRequest(ClientRequest clientRequest)
Performs an HTTP request from the data provided by the given client request and retrieves an HTTP response that as provided as client response.

Specified by:
performRequest in interface Client
Parameters:
clientRequest - The client request
Returns:
The client response

getHttpRequest

protected org.apache.http.client.methods.HttpRequestBase getHttpRequest(ClientRequest request)
                                                                 throws URISyntaxException
Gets an HTTP request from the provided client request.

Parameters:
request - The client request
Returns:
The HTTP request
Throws:
URISyntaxException - if the request or base URI is not valid

getRequestParameters

protected org.apache.http.params.HttpParams getRequestParameters(Map<String,String[]> parameters)
Gets the HTTP parameters from the provided parameter map.

Parameters:
parameters - The parameter map
Returns:
The HTTP parameters

getRequestHeaders

protected org.apache.http.Header[] getRequestHeaders(Map<String,String[]> headers)
Gets the HTTP headers from the provided header map.

Parameters:
headers - The header map
Returns:
The HTTP headers

getClientResponse

protected ClientResponse getClientResponse(org.apache.http.HttpResponse httpResponse)
                                    throws IOException
Gets the client response from the provided HTTP response.

Parameters:
httpResponse - The http response
Returns:
The client response
Throws:
IOException - if the response reading failed

getResponseHeaders

protected Map<String,String[]> getResponseHeaders(org.apache.http.Header[] headers)
Gets the response header map from the given HTTP headers.

Parameters:
headers - The response HTTP headers
Returns:
The response header map


Copyright © 2011. All Rights Reserved.