/* * Create and return a HttpMethodBase for a Rest request based on the passed * HttpCallBean and CougarMessageProtocolRequestTypeEnum. * * @param httpCallBean * @param protocolRequestType * @return */ public HttpUriRequest getRestMethod( HttpCallBean httpCallBean, CougarMessageProtocolRequestTypeEnum protocolRequestType) { Object postQueryObject = httpCallBean.getPostQueryObjectsByEnum(protocolRequestType); String postQuery; if (postQueryObject == null) { postQuery = null; } else { postQuery = (String) postQueryObject; } String serviceExtension = httpCallBean.getServiceExtension(); String version = httpCallBean.getVersion(); Map<String, String> queryParams = httpCallBean.getQueryParams(); String host = httpCallBean.getHost(); String port = httpCallBean.getPort(); String path = httpCallBean.getPath(); String altURL = httpCallBean .getAlternativeURL(); // Will be "" for standard URL, or "/www" for alternative URL boolean batchedQuery = httpCallBean.getJSONRPC(); String fullPath = httpCallBean.getFullPath(); String methodURL = ""; if (batchedQuery) { // If request is a batched JSON request set the URL to the appropriate // baseline URL postQuery = createBatchedPostString( httpCallBean .getBatchedRequests()); // Build the post string out of the list of requests to // batch methodURL = "http://" + host + ":" + port + "/json-rpc"; } else { // else build the request URL String queryParamString = ""; if (queryParams != null) { int counter = 0; StringBuilder queryBuff = new StringBuilder(); for (Map.Entry<String, String> entry : queryParams.entrySet()) { String value = entry.getValue(); String key = entry.getKey(); if (counter == 0) { String firstQuery = "?" + key + "=" + value; queryBuff.append(firstQuery); } else { String nextQuery = "&" + key + "=" + value; queryBuff.append(nextQuery); } counter++; } queryParamString = queryBuff.toString(); } if (fullPath != null) { methodURL = "http://" + host + ":" + port + fullPath + queryParamString; } else { methodURL = "http://" + host + ":" + port + altURL + "/" + serviceExtension + "/" + version + "/" + path + queryParamString; } } // if (logger.isDebugEnabled()) { // } if ((postQuery != null) && (!postQuery.equalsIgnoreCase(""))) { HttpPost method = new HttpPost(methodURL); try { method.setEntity(new StringEntity(postQuery, null, UTF8)); return method; } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } } else { return new HttpGet(methodURL); } }