List of usage examples for org.apache.commons.httpclient HttpMethod addRequestHeader
public abstract void addRequestHeader(String paramString1, String paramString2);
From source file:com.ebay.recommendations.LatestVersion.java
/** * @param args/* w ww .j a v a2 s. co m*/ */ public static void main(String[] args) { // TODO Auto-generated method stub HttpClient client = new HttpClient(); String fullUri = "https://svcs.ebay.com/services/selling/listingrecommendation/latestVersion"; HttpMethod method = new GetMethod(fullUri); // REPLACE YOUR TOKEN IN THE <YOUR_TOKEN_HERE> PLACE HOLDER method.addRequestHeader("Authorization", "TOKEN <YOUR_TOKEN_HERE>"); method.addRequestHeader("Accept", "application/xml"); try { client.executeMethod(method); String response = method.getResponseBodyAsString(); System.out.println(response); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.ebay.recommendations.ItemRecommendations.java
/** * @param args/*from w w w . j a va 2s . c om*/ */ public static void main(String[] args) { HttpClient client = new HttpClient(); String fullUri = "https://svcs.ebay.com/services/selling/listingrecommendation/v1/item/300878655630/itemRecommendations/"; HttpMethod method = new GetMethod(fullUri); // REPLACE YOUR TOKEN IN THE <YOUR_TOKEN_HERE> PLACE HOLDER method.addRequestHeader("Authorization", "TOKEN <YOUR_TOKEN_HERE>"); method.addRequestHeader("X-EBAY-GLOBAL-ID", "EBAY-US"); method.addRequestHeader("Accept", "application/xml"); try { client.executeMethod(method); String response = method.getResponseBodyAsString(); System.out.println(response); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.ebay.recommendations.RecommendationItemIds.java
/** * @param args/*from w w w .ja v a2s. co m*/ */ public static void main(String[] args) { // TODO Auto-generated method stub HttpClient client = new HttpClient(); String fullUri = "https://svcs.ebay.com/services/selling/listingrecommendation/v1/item/recommendationItemIds?recommendationType=Picture&pageNumber=1&entriesPerPage=5"; HttpMethod method = new GetMethod(fullUri); // REPLACE YOUR TOKEN IN THE <YOUR_TOKEN_HERE> PLACE HOLDER method.addRequestHeader("Authorization", "TOKEN <YOUR_TOKEN_HERE>"); method.addRequestHeader("X-EBAY-GLOBAL-ID", "EBAY-US"); method.addRequestHeader("Accept", "application/xml"); try { client.executeMethod(method); String response = method.getResponseBodyAsString(); System.out.println(response); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.ebay.recommendations.RecommendationsSummary.java
/** * @param args// w w w . j a va 2s . com */ public static void main(String[] args) { // TODO Auto-generated method stub HttpClient client = new HttpClient(); String fullUri = "https://svcs.ebay.com/services/selling/listingrecommendation/v1/item/recommendationsSummary"; HttpMethod method = new GetMethod(fullUri); // REPLACE YOUR TOKEN IN THE <YOUR_TOKEN_HERE> PLACE HOLDER method.addRequestHeader("Authorization", "TOKEN <YOUR_TOKEN_HERE>"); method.addRequestHeader("X-EBAY-GLOBAL-ID", "EBAY-US"); method.addRequestHeader("Accept", "application/xml"); try { client.executeMethod(method); String response = method.getResponseBodyAsString(); System.out.println(response); } catch (Exception e) { e.printStackTrace(); } }
From source file:lucee.commons.net.http.httpclient3.HTTPEngine3Impl.java
private static void setContentType(HttpMethod httpMethod, String charset) { if (charset != null) httpMethod.addRequestHeader("Content-type", "text/html; charset=" + charset); }
From source file:com.tribune.uiautomation.testscripts.Photo.java
private static void setRequestHeaders(HttpMethod method) { method.addRequestHeader(AUTH_HEADER, OAUTH2_BEARER + ' ' + auth); method.addRequestHeader(ACCEPT_HEADER, ACCEPT_VALUE); method.addRequestHeader(ACCEPT_ENCODING_HEADER, ACCEPT_ENCODING_VALUE); }
From source file:lucee.commons.net.http.httpclient3.HTTPEngine3Impl.java
private static void setHeader(HttpMethod httpMethod, Header[] headers) { if (headers != null) { for (int i = 0; i < headers.length; i++) httpMethod.addRequestHeader(headers[i].getName(), headers[i].getValue()); }/*from w ww .j av a 2 s.com*/ }
From source file:eu.eco2clouds.api.bonfire.client.rest.RestClient.java
private static Response executeMethod(HttpMethod httpMethod, String type, String username, String password, String url) {//from ww w. j a va 2s . c o m HttpClient client = getClient(url, username, password); Response response = null; // We set the Heathers httpMethod.setDoAuthentication(true); httpMethod.addRequestHeader(BONFIRE_ASSERTED_ID_HEADER, username); //httpMethod.addRequestHeader(BONFIRE_ASSERTED_ID_HEADER, groups); httpMethod.addRequestHeader("Accept", type); httpMethod.addRequestHeader("Content-Type", type); try { int statusCode = client.executeMethod(httpMethod); String responsePayload = httpMethod.getResponseBodyAsString(); response = new Response(statusCode, responsePayload); } catch (IOException iOException) { System.out.println("ERROR TRYING TO PERFORM GET TO: " + httpMethod.getPath()); System.out.println("ERROR: " + iOException.getMessage()); System.out.println("ERROR: " + iOException.getStackTrace()); } finally { httpMethod.releaseConnection(); } return response; }
From source file:com.zimbra.cs.util.WebClientServiceUtil.java
public static String sendServiceRequestToUiNode(Server server, String serviceUrl) throws ServiceException { if (isServerAtLeast8dot5(server)) { HttpClient client = ZimbraHttpConnectionManager.getExternalHttpConnMgr().newHttpClient(); HttpProxyUtil.configureProxy(client); AuthToken authToken = AuthProvider.getAdminAuthToken(); ZimbraLog.misc.debug("got admin auth token"); String resp = ""; HttpMethod method = null; try {/*from w ww.j a v a 2s . com*/ method = new GetMethod(URLUtil.getServiceURL(server, serviceUrl, false)); ZimbraLog.misc.debug("connecting to ui node %s", server.getName()); method.addRequestHeader(PARAM_AUTHTOKEN, authToken.getEncoded()); int result = HttpClientUtil.executeMethod(client, method); ZimbraLog.misc.debug("resp: %d", result); resp = method.getResponseBodyAsString(); ZimbraLog.misc.debug("got response from ui node: %s", resp); } catch (IOException e) { ZimbraLog.misc.warn("failed to get response from ui node", e); } catch (AuthTokenException e) { ZimbraLog.misc.warn("failed to get authToken", e); } finally { if (method != null) { method.releaseConnection(); } } if (authToken != null && authToken.isRegistered()) { try { authToken.deRegister(); ZimbraLog.misc.debug("de-registered auth token, isRegistered?%s", authToken.isRegistered()); } catch (AuthTokenException e) { ZimbraLog.misc.warn("failed to de-register authToken", e); } } return resp; } return ""; }
From source file:com.zimbra.cs.util.WebClientServiceUtil.java
/** * send service request to one random ui node, keep trying until succeeds. * @param serviceUrl the url that should be matched and handled by ServiceServlet in ZimbraWebClient * reqHeaders the map of req/rsp attributes that need to be set by the UI node * @return response from ui node in String * @throws ServiceException/*from ww w .j a v a 2s .c o m*/ */ public static String sendServiceRequestToOneRandomUiNode(String serviceUrl, Map<String, String> reqHeaders) throws ServiceException { List<Server> servers = Provisioning.getInstance().getAllServers(Provisioning.SERVICE_WEBCLIENT); if (servers == null || servers.isEmpty()) { servers.add(Provisioning.getInstance().getLocalServer()); } HttpClient client = ZimbraHttpConnectionManager.getExternalHttpConnMgr().newHttpClient(); HttpProxyUtil.configureProxy(client); AuthToken authToken = AuthProvider.getAdminAuthToken(); ZimbraLog.misc.debug("got admin auth token"); String resp = ""; for (Server server : servers) { if (isServerAtLeast8dot5(server)) { HttpMethod method = null; try { method = new GetMethod(URLUtil.getServiceURL(server, serviceUrl, false)); ZimbraLog.misc.debug("connecting to ui node %s", server.getName()); method.addRequestHeader(PARAM_AUTHTOKEN, authToken.getEncoded()); // Add all the req headers passed to this function as well for (Map.Entry<String, String> entry : reqHeaders.entrySet()) { method.addRequestHeader(entry.getKey(), entry.getValue()); ZimbraLog.misc.debug("adding request header %s=%s", entry.getKey(), entry.getValue()); } int result = HttpClientUtil.executeMethod(client, method); ZimbraLog.misc.debug("resp: %d", result); resp = method.getResponseBodyAsString(); ZimbraLog.misc.debug("got response from ui node: %s", resp); break; //try ui nodes one by one until one succeeds. } catch (IOException e) { ZimbraLog.misc.warn("failed to get response from ui node", e); } catch (AuthTokenException e) { ZimbraLog.misc.warn("failed to get authToken", e); } finally { if (method != null) { method.releaseConnection(); } } } } if (authToken != null && authToken.isRegistered()) { try { authToken.deRegister(); ZimbraLog.misc.debug("de-registered auth token, isRegistered?%s", authToken.isRegistered()); } catch (AuthTokenException e) { ZimbraLog.misc.warn("failed to de-register authToken", e); } } return resp; }