agave-apps/clients/AbstractService.java
/**
	 * @param endpoint URL to which to post the form.
	 * @param token AuthenticationToken used for the request
	 * @param nvps List of form variables.
	 * @return
	 * @throws APIClientException
	 */
@param endpoint URL to which to post the form.
@param token AuthenticationToken used for the request
@param nvps List of form variables.
@param endpoint URL to which to post the form . @param token AuthenticationToken used for the request @param nvps List of form variables .
public APIResponse post(String endpoint, AuthenticationToken token, List <NameValuePair> nvps)
    throws APIClientException {
		if (StringUtils.isEmpty(endpoint)) {
			throw new APIClientException("No endpoint provided");
		}
		if (token == null) {
			throw new APIClientException("No authenticatino token provided");
		}
		HttpClient httpClient = null;
        try {
        	httpClient = getAuthenticatedClient(endpoint, token.getUsername(), token.getToken());
            HttpPost post = new HttpPost(endpoint);
            post.setEntity(new UrlEncodedFormEntity(nvps));
            HttpResponse response = httpClient.execute(post);
            try {
                log.debug(response.getStatusLine());
                HttpEntity entity = response.getEntity();
                String body = EntityUtils.toString(entity, "UTF-8");
                EntityUtils.consume(entity);
                return new APIResponse(body);
            } finally {
                post.releaseConnection();
            }
        } 
        catch (APIClientException e) {
        	throw e;
        }
        catch (Exception e) {
        	throw new APIClientException("Failed to perform PUT on " + endpoint, e);
        } 
        finally {
            try { httpClient.getConnectionManager().shutdown(); } catch (Exception e) {}
        }
    }
public APIResponse post ( String endpoint , AuthenticationToken token , List < NameValuePair > nvps ) throws APIClientException { if ( StringUtils . isEmpty ( endpoint ) ) { throw new APIClientException ( "No endpoint provided" ) ; } if ( token == null ) { throw new APIClientException ( "No authenticatino token provided" ) ; } HttpClient httpClient = null ; try { httpClient = getAuthenticatedClient ( endpoint , token . getUsername ( ) , token . getToken ( ) ) ; HttpPost post = new HttpPost ( endpoint ) ; post . setEntity ( new UrlEncodedFormEntity ( nvps ) ) ; HttpResponse response = httpClient . execute ( post ) ; try { log . debug ( response . getStatusLine ( ) ) ; HttpEntity entity = response . getEntity ( ) ; String body = EntityUtils . toString ( entity , "UTF-8" ) ; EntityUtils . consume ( entity ) ; return new APIResponse ( body ) ; } finally { post . releaseConnection ( ) ; } } catch ( APIClientException e ) { throw e ; } catch ( Exception e ) { throw new APIClientException ( "Failed to perform PUT on " + endpoint , e ) ; } finally { try { httpClient . getConnectionManager ( ) . shutdown ( ) ; } catch ( Exception e ) { } } }
@param endpoint URL to which to post the form.
@param endpoint URL to which to post the form .