Package edu.uiuc.ncsa.security.servlet
Class ServiceClient
- java.lang.Object
-
- edu.uiuc.ncsa.security.servlet.ServiceClient
-
- Direct Known Subclasses:
Client
public class ServiceClient extends Object
This class is a client that talks to a server. It manages a client pool and does a get based on pairs of strings, which are assumed to be of the form {{key1,value1},{key2,value2},...}Created by Jeff Gaynor
on 5/21/12 at 1:43 PM
-
-
Field Summary
Fields Modifier and Type Field Description protected Pool<org.apache.http.client.HttpClient>
clientPool
static boolean
ECHO_REQUEST
static boolean
ECHO_RESPONSE
static String
ENCODING
static String
HEADER_KEY
-
Constructor Summary
Constructors Constructor Description ServiceClient(URI address)
Basic default service client that uses the java keystore only.ServiceClient(URI address, SSLConfiguration sslConfiguration)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected Map
addHeaders(org.apache.http.client.methods.HttpRequestBase httpRequestBase, Map<String,String> headers)
Adds the headers from an existing header map.protected Map
addHeadersFromParameters(org.apache.http.client.methods.HttpRequestBase httpRequestBase, Map parameters)
Peels off the headers (if any) from the parameter map and adds them to the request.static String
convertToStringRequest(String host, String[][] args)
static String
convertToStringRequest(String host, Map m)
static String
decode(String x)
protected String
doBearerRequest(org.apache.http.client.methods.HttpRequestBase httpRequestBase, String token)
Process the request, but use a bearer token (the access token which should eb suitably encoded)protected String
doBearerRequest(org.apache.http.client.methods.HttpRequestBase httpRequestBase, String token, boolean base64Encode)
If the token is not already base 64 or 32 encoded, option flag to do so.String
doGet(String requestString, Map<String,String> headers)
String
doGet(String requestString, Map<String,String> headers, String id, String secret)
Do a GET with a specifically constructed request stringString
doGet(Map m)
String
doGet(Map m, String id, String secret)
String
doPost(Map m)
Does a POST using only the map.String
doPost(Map<String,Object> parameters, String bearerToken)
Do post using a bearer tokenString
doPost(Map<String,Object> parameters, String id, String secret)
Do an HTTP POST to the endpoint sending along basic authorization and any parameters.protected String
doRequest(org.apache.http.client.methods.HttpRequestBase httpRequestBase)
Do the request.protected String
doRequest(org.apache.http.client.methods.HttpRequestBase httpRequestBase, String id, String secret)
This will set the basic authorization in the headers for the request.static String
encode(String x)
protected Map
getHeaders(Map parameters)
Removes the headers from the parameter request for the map.URI
host(URI... x)
boolean
isVerbose()
void
setVerbose(boolean verbose)
-
-
-
Field Detail
-
clientPool
protected Pool<org.apache.http.client.HttpClient> clientPool
-
ENCODING
public static String ENCODING
-
ECHO_REQUEST
public static boolean ECHO_REQUEST
-
ECHO_RESPONSE
public static boolean ECHO_RESPONSE
-
HEADER_KEY
public static final String HEADER_KEY
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
ServiceClient
public ServiceClient(URI address, SSLConfiguration sslConfiguration)
-
ServiceClient
public ServiceClient(URI address)
Basic default service client that uses the java keystore only.- Parameters:
address
-
-
-
Method Detail
-
isVerbose
public boolean isVerbose()
-
setVerbose
public void setVerbose(boolean verbose)
-
encode
public static String encode(String x) throws UnsupportedEncodingException
- Throws:
UnsupportedEncodingException
-
decode
public static String decode(String x) throws UnsupportedEncodingException
- Throws:
UnsupportedEncodingException
-
doPost
public String doPost(Map m)
Does a POST using only the map. This is useful if there are other authentication methods used that are encoded as parameters (e.g. RFC 7523).- Parameters:
m
-- Returns:
-
doPost
public String doPost(Map<String,Object> parameters, String id, String secret)
Do an HTTP POST to the endpoint sending along basic authorization and any parameters. This returns a string, so do process the result.- Parameters:
parameters
-id
-secret
-- Returns:
-
getHeaders
protected Map getHeaders(Map parameters)
Removes the headers from the parameter request for the map. This is destructive in the sense that the headers are no longer in the parameter map, so it is a one-time use call.- Parameters:
parameters
-- Returns:
-
addHeadersFromParameters
protected Map addHeadersFromParameters(org.apache.http.client.methods.HttpRequestBase httpRequestBase, Map parameters)
Peels off the headers (if any) from the parameter map and adds them to the request. This returns the header map. The parameter map will not contain the headers once this call completes.- Parameters:
httpRequestBase
-parameters
-- Returns:
-
addHeaders
protected Map addHeaders(org.apache.http.client.methods.HttpRequestBase httpRequestBase, Map<String,String> headers)
Adds the headers from an existing header map.- Parameters:
httpRequestBase
-headers
-- Returns:
-
doPost
public String doPost(Map<String,Object> parameters, String bearerToken)
Do post using a bearer token- Parameters:
bearerToken
-- Returns:
-
doRequest
protected String doRequest(org.apache.http.client.methods.HttpRequestBase httpRequestBase, String id, String secret)
This will set the basic authorization in the headers for the request.- Parameters:
httpRequestBase
-id
-secret
-- Returns:
-
doBearerRequest
protected String doBearerRequest(org.apache.http.client.methods.HttpRequestBase httpRequestBase, String token, boolean base64Encode)
If the token is not already base 64 or 32 encoded, option flag to do so.- Parameters:
httpRequestBase
-token
- -- the bearer tokenbase64Encode
-- Returns:
-
doBearerRequest
protected String doBearerRequest(org.apache.http.client.methods.HttpRequestBase httpRequestBase, String token)
Process the request, but use a bearer token (the access token which should eb suitably encoded)- Parameters:
httpRequestBase
-token
-- Returns:
-
doRequest
protected String doRequest(org.apache.http.client.methods.HttpRequestBase httpRequestBase)
Do the request. The response will be the response of the server if there was a success. Otherwise, the response will be (a) constructed if not JSON or (b) the JSON if the server response is a JSON payload. It is becoming de facto standard to return JSON as part of the error, so we should just send that along.- Parameters:
httpRequestBase
-- Returns:
-
doGet
public String doGet(String requestString, Map<String,String> headers, String id, String secret)
Do a GET with a specifically constructed request string- Parameters:
requestString
-headers
-id
-secret
-- Returns:
-
-