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
-
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 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)
String
doGet(String requestString, String id, String secret)
String
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)
URI
host(URI... x)
boolean
isVerbose()
void
setVerbose(boolean verbose)
-
-
-
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:
-
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:
-
-