List of usage examples for org.apache.commons.httpclient.methods GetMethod setQueryString
public void setQueryString(String queryString)
From source file:org.wso2.scim.sample.group.CreateGroup.java
private static String getSCIMIdOfUser(String userName) throws Exception { String userId = null;/* w w w . j a v a 2 s . c o m*/ try { //create http client HttpClient httpFilterUserClient = new HttpClient(); //create get method for filtering GetMethod getMethod = new GetMethod(SCIMSamplesUtils.userEndpointURL); //add authorization header String authHeader = SCIMSamplesUtils.getAuthorizationHeader(); getMethod.addRequestHeader(SCIMConstants.AUTHORIZATION_HEADER, authHeader); //get corresponding userIds String filter = SCIMSamplesUtils.USER_FILTER + userName; getMethod.setQueryString(filter); int responseCode = httpFilterUserClient.executeMethod(getMethod); String response = getMethod.getResponseBodyAsString(); SCIMClient scimClient = new SCIMClient(); //check for success of the response if (scimClient.evaluateResponseStatus(responseCode)) { ListedResource listedUserResource = scimClient.decodeSCIMResponseWithListedResource(response, SCIMConstants.identifyFormat(SCIMSamplesUtils.CONTENT_TYPE), SCIMConstants.USER_INT); List<SCIMObject> filteredUsers = listedUserResource.getScimObjects(); for (SCIMObject filteredUser : filteredUsers) { //we expect only one result here userId = ((User) filteredUser).getId(); } } } catch (IOException e) { throw new Exception("Error in obtaining the SCIM Id for user: " + userName); } catch (CharonException e) { throw new Exception("Error in obtaining the SCIM Id for user: " + userName); } return userId; }
From source file:org.wso2.scim.sample.group.DeleteGroup.java
private static String getSCIMIdOfGroup(String groupName) throws Exception { String groupId = null;/*from ww w . j a v a 2 s . c o m*/ try { //create http client HttpClient httpFilterUserClient = new HttpClient(); //create get method for filtering GetMethod getMethod = new GetMethod(SCIMSamplesUtils.groupEndpointURL); //add authorization header String authHeader = SCIMSamplesUtils.getAuthorizationHeader(); getMethod.addRequestHeader(SCIMConstants.AUTHORIZATION_HEADER, authHeader); //get corresponding userIds String filter = SCIMSamplesUtils.GROUP_FILTER + groupName; getMethod.setQueryString(filter); int responseCode = httpFilterUserClient.executeMethod(getMethod); String response = getMethod.getResponseBodyAsString(); SCIMClient scimClient = new SCIMClient(); //check for success of the response if (scimClient.evaluateResponseStatus(responseCode)) { ListedResource listedUserResource = scimClient.decodeSCIMResponseWithListedResource(response, SCIMConstants.identifyFormat(SCIMSamplesUtils.CONTENT_TYPE), SCIMConstants.GROUP_INT); List<SCIMObject> filteredGroups = listedUserResource.getScimObjects(); for (SCIMObject filteredGroup : filteredGroups) { //we expect only one result here groupId = ((Group) filteredGroup).getId(); } } } catch (IOException e) { throw new Exception("Error in obtaining the SCIM Id for group: " + groupName); } catch (CharonException e) { throw new Exception("Error in obtaining the SCIM Id for group: " + groupName); } return groupId; }
From source file:org.wso2.scim.sample.group.UpdateGroup.java
private static String getSCIMIdOfGroup(String groupName) throws Exception { String groupId = null;//from w w w.j a va2s .co m try { //create http client HttpClient httpFilterUserClient = new HttpClient(); //create get method for filtering GetMethod getMethod = new GetMethod(SCIMSamplesUtils.groupEndpointURL); //add authorization header String authHeader = SCIMSamplesUtils.getAuthorizationHeader(); getMethod.addRequestHeader(SCIMConstants.AUTHORIZATION_HEADER, authHeader); //get corresponding userIds String filter = SCIMSamplesUtils.GROUP_FILTER + groupName; getMethod.setQueryString(filter); int responseCode = httpFilterUserClient.executeMethod(getMethod); String response = getMethod.getResponseBodyAsString(); SCIMClient scimClient = new SCIMClient(); //check for success of the response if (scimClient.evaluateResponseStatus(responseCode)) { ListedResource listedGroupResource = scimClient.decodeSCIMResponseWithListedResource(response, SCIMConstants.identifyFormat(SCIMSamplesUtils.CONTENT_TYPE), SCIMConstants.GROUP_INT); List<SCIMObject> filteredGroups = listedGroupResource.getScimObjects(); for (SCIMObject filteredGroup : filteredGroups) { //we expect only one result here groupId = ((Group) filteredGroup).getId(); } } } catch (IOException e) { throw new Exception("Error in obtaining the SCIM Id for user: " + groupName); } catch (CharonException e) { throw new Exception("Error in obtaining the SCIM Id for user: " + groupName); } return groupId; }
From source file:org.zend.php.zendserver.deployment.core.targets.OpenShiftTargetInitializer.java
private HttpMethodBase createGetRequest(String url, Map<String, String> params) { GetMethod method = new GetMethod(url); NameValuePair[] query = new NameValuePair[params.size()]; Set<String> keyList = params.keySet(); int i = 0;//from ww w . java2s . co m for (String key : keyList) { query[i++] = new NameValuePair(key, params.get(key)); } method.setQueryString(query); return method; }
From source file:oscar.oscarLab.ca.bc.PathNet.Communication.HTTP.java
public InputStream Get(String queryString) throws IOException, HttpException { GetMethod method = new GetMethod(url); method.setQueryString(queryString); logger.error(this.client.executeMethod(method)); method.getResponseBodyAsString();//from ww w . j a v a 2 s . c om InputStream response = method.getResponseBodyAsStream(); method.releaseConnection(); return response; }
From source file:oscar.oscarLab.ca.bc.PathNet.Communication.HTTP.java
public String GetString(String queryString) throws IOException, HttpException { GetMethod method = new GetMethod(url); method.setQueryString(queryString); this.client.executeMethod(method); String response = method.getResponseBodyAsString(); method.releaseConnection();//w w w . jav a 2s. co m return response; }
From source file:oscar.oscarLabs.PathNet.Communication.HTTP.java
public InputStream Get(String queryString) throws IOException, HttpException { GetMethod method = new GetMethod(url); method.setQueryString(queryString); System.err.println(this.client.executeMethod(method)); method.getResponseBodyAsString();/*from w w w . j ava 2s.c o m*/ InputStream response = method.getResponseBodyAsStream(); method.releaseConnection(); return response; }
From source file:uk.ac.ebi.arrayexpress.servlets.GenomeSpaceUploadServlet.java
private Integer getFileUploadURL(UploadFileInfo fileInfo, String target, String gsToken) throws IOException { GetMethod get = new GetMethod(GS_DM_ROOT_URL + "/uploadurl" + target.replaceAll("^/?(.+[^/])/?$", "/$1/") + fileInfo.getFile().getName()); get.getParams().setCookiePolicy(CookiePolicy.IGNORE_COOKIES); get.setQueryString(new NameValuePair[] { new NameValuePair("Content-Length", fileInfo.getContentLength()), new NameValuePair("Content-Type", fileInfo.GetContentType()), new NameValuePair("Content-MD5", fileInfo.getContentMD5()) }); get.setRequestHeader("Cookie", "gs-token=" + gsToken); Integer statusCode = null;/*from www.ja v a2 s . c o m*/ try { statusCode = httpClient.executeMethod(get); if (HttpServletResponse.SC_OK == statusCode) { fileInfo.setUploadURL(StringTools.streamToString(get.getResponseBodyAsStream(), "US-ASCII")); } else { logger.error("Unable to obtain upload URL, status code [{}]", statusCode); } } catch (HttpException x) { logger.error("Caught an exception:", x); } finally { get.releaseConnection(); } return statusCode; }
From source file:uk.ac.ebi.arrayexpress.servlets.HttpProxyServlet.java
@Override protected void doRequest(HttpServletRequest request, HttpServletResponse response, RequestType requestType) throws ServletException, IOException { RegexHelper MATCH_URL_REGEX = new RegexHelper("/+(.+)", "i"); RegexHelper TEST_HOST_IN_URL_REGEX = new RegexHelper("^http\\:/{2}([^/]+)/", "i"); RegexHelper SQUARE_BRACKETS_REGEX = new RegexHelper("\\[\\]", "g"); logRequest(logger, request, requestType); String url = MATCH_URL_REGEX.matchFirst(request.getPathInfo()); url = url.replaceFirst("http:/{1,2}", "http://"); // stupid hack as tomcat 6.0 removes second forward slash String queryString = request.getQueryString(); if (0 < url.length()) { if (!TEST_HOST_IN_URL_REGEX.test(url)) { // no host here, will self url = "http://localhost:" + String.valueOf(request.getLocalPort()) + "/" + url; }//from www . java2 s . co m logger.debug("Will access [{}]", url); GetMethod getMethod = new GetMethod(url); if (null != queryString) { queryString = SQUARE_BRACKETS_REGEX.replace(queryString, "%5B%5D"); getMethod.setQueryString(queryString); } Enumeration requestHeaders = request.getHeaderNames(); while (requestHeaders.hasMoreElements()) { String name = (String) requestHeaders.nextElement(); String value = request.getHeader(name); if (null != value) { getMethod.setRequestHeader(name, value); } } try { httpClient.executeMethod(getMethod); int statusCode = getMethod.getStatusCode(); long contentLength = getMethod.getResponseContentLength(); logger.debug("Got response [{}], length [{}]", statusCode, contentLength); Header[] responseHeaders = getMethod.getResponseHeaders(); for (Header responseHeader : responseHeaders) { String name = responseHeader.getName(); String value = responseHeader.getValue(); if (null != name && null != value && !(name.equals("Server") || name.equals("Date") || name.equals("Transfer-Encoding"))) { response.setHeader(responseHeader.getName(), responseHeader.getValue()); } } if (200 != statusCode) { response.setStatus(statusCode); } InputStream inStream = getMethod.getResponseBodyAsStream(); if (null != inStream) { BufferedReader in = new BufferedReader(new InputStreamReader(inStream)); BufferedWriter out = new BufferedWriter(new OutputStreamWriter(response.getOutputStream())); CharBuffer buffer = CharBuffer.allocate(PROXY_BUFFER_SIZE); while (in.read(buffer) >= 0) { buffer.flip(); out.append(buffer); buffer.clear(); } in.close(); out.close(); } } catch (Exception x) { if (x.getClass().getName().equals("org.apache.catalina.connector.ClientAbortException")) { logger.warn("Client aborted connection"); } else { logger.error("Caught an exception:", x); response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, x.getMessage()); } } finally { getMethod.releaseConnection(); } } }
From source file:zz.pseas.ghost.utils.HttpClinetUtil.java
/** * @author GS// w w w .ja va 2s .co m * @param url * @param para * get?? * @return * @throws IOException */ public static String get(String url, Map<String, String> para) throws IOException { String responseBody = null; GetMethod getMethod = new GetMethod(url); getMethod.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler()); // ???? NameValuePair[] data = new NameValuePair[para.size()]; int index = 0; for (String s : para.keySet()) { data[index++] = new NameValuePair(s, para.get(s)); // ?? } getMethod.setQueryString(data); // ? try { int statusCode = hc.executeMethod(getMethod); if (statusCode != HttpStatus.SC_OK) { LOG.error("Method failed: " + getMethod.getStatusLine()); } responseBody = getMethod.getResponseBodyAsString(); } catch (SocketTimeoutException e) { e.printStackTrace(); LOG.error("??" + e.getMessage()); } catch (UnknownHostException e) { e.printStackTrace(); LOG.error("?,UnknownHostException,?" + e.getMessage()); } catch (HttpException e) { // ? e.printStackTrace(); LOG.error("?" + e.getMessage()); } catch (IOException e) { // ? e.printStackTrace(); LOG.error("?" + e.getMessage()); } finally { getMethod.releaseConnection(); // } return responseBody; }