List of usage examples for org.apache.commons.httpclient.methods GetMethod GetMethod
public GetMethod()
From source file:com.agiletec.plugins.jpcasclient.aps.system.services.controller.control.CasClientTicketValidationUtil.java
/** * ticket validation /*from w w w.ja va 2 s. c o m*/ * */ public Assertion validateTicket(String service, String ticket_key) throws ApsSystemException { Assertion assertion = null; MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager(); _client = new HttpClient(connectionManager); GetMethod authget = new GetMethod(); Map<String, String> params = new HashMap<String, String>(); params.put("service", service); params.put("ticket", ticket_key); authget.getParams().setCookiePolicy(CookiePolicy.DEFAULT); String responseBodyValidation = null; String responseAssertion = null; String responseUser = null; responseBodyValidation = this.CASgetMethod(authget, _client, this._urlCasValidate, params); try { // controllo della risposta sulla richiesta validazione ticket if (null != responseBodyValidation && responseBodyValidation.length() > 0) { InputStreamReader reader; reader = new InputStreamReader(authget.getResponseBodyAsStream()); BufferedReader bufferedReader = new BufferedReader(reader); responseAssertion = bufferedReader.readLine(); if (responseAssertion.equals(_positiveResponse)) { responseUser = bufferedReader.readLine(); } ApsSystemUtils.getLogger().info("CasClientTicketValidationUtil - Assertion: " + responseAssertion + " user: " + responseUser); } } catch (Throwable t) { _logger.error("Error in CasClientTicketValidationUtil - validateTicket", t); throw new ApsSystemException("Error in CasClientTicketValidationUtil - validateTicket", t); } if (null != responseAssertion && null != responseUser && responseAssertion.equalsIgnoreCase(_positiveResponse) && responseUser.length() > 0) { assertion = new AssertionImpl(responseUser); } return assertion; }
From source file:de.innovationgate.contentmanager.modules.LinkChecker.java
private int innerCheck(HttpClient client, URI uri, int redirectCounter) throws HttpException, IOException { if (redirectCounter >= DEFAULT_MAX_REDIRECTS) { throw new IllegalStateException( "Max redirects '" + DEFAULT_MAX_REDIRECTS + "' reached. Might be an endless redirect."); }//from w w w . j a v a2s . com GetMethod targetGET = new GetMethod(); targetGET.setURI(uri); targetGET.setFollowRedirects(false); int result = client.executeMethod(targetGET); if (result == 301 || result == 302 || result == 303 || result == 307) { // follow redirect Header locationHeader = targetGET.getResponseHeader("location"); if (locationHeader != null) { String redirectLocation = locationHeader.getValue(); targetGET.releaseConnection(); return innerCheck(client, new URI(uri, redirectLocation, true), redirectCounter + 1); } else { targetGET.releaseConnection(); return 404; } } else { targetGET.releaseConnection(); return result; } }
From source file:com.xerox.amazonws.sdb.Item.java
/** * Gets attributes of a given name. The parameter limits the results to those of * the name given./*from www . j av a2s. co m*/ * * @param attributeName a name that limits the results * @return the list of attributes * @throws SDBException wraps checked exceptions */ public List<ItemAttribute> getAttributes(String attributeName) throws SDBException { Map<String, String> params = new HashMap<String, String>(); params.put("DomainName", domainName); params.put("ItemName", identifier); if (attributeName != null) { params.put("AttributeName", attributeName); } GetMethod method = new GetMethod(); try { GetAttributesResponse response = makeRequest(method, "GetAttributes", params, GetAttributesResponse.class); List<ItemAttribute> ret = new ArrayList<ItemAttribute>(); List<Attribute> attrs = response.getGetAttributesResult().getAttributes(); for (Attribute attr : attrs) { ret.add(new ItemAttribute(attr.getName(), attr.getValue(), false)); } return ret; } catch (JAXBException ex) { throw new SDBException("Problem parsing returned message.", ex); } catch (HttpException ex) { throw new SDBException(ex.getMessage(), ex); } catch (IOException ex) { throw new SDBException(ex.getMessage(), ex); } finally { method.releaseConnection(); } }
From source file:fr.cls.atoll.motu.library.misc.cas.HttpClientTutorial.java
public static void test() { HttpClient client = new HttpClient(); client.getParams().setParameter("http.useragent", "Test Client"); client.getParams().setParameter("http.connection.timeout", new Integer(5000)); GetMethod method = new GetMethod(); FileOutputStream fos = null;/*www . j a v a2 s. c om*/ try { method.setURI(new URI("http://www.google.com", true)); int returnCode = client.executeMethod(method); if (returnCode != HttpStatus.SC_OK) { System.err.println("Unable to fetch default page, status code: " + returnCode); } System.err.println(method.getResponseBodyAsString()); method.setURI(new URI("http://www.google.com/images/logo.gif", true)); returnCode = client.executeMethod(method); if (returnCode != HttpStatus.SC_OK) { System.err.println("Unable to fetch image, status code: " + returnCode); } byte[] imageData = method.getResponseBody(); fos = new FileOutputStream(new File("google.gif")); fos.write(imageData); HostConfiguration hostConfig = new HostConfiguration(); hostConfig.setHost("www.yahoo.com", null, 80, Protocol.getProtocol("http")); method.setURI(new URI("/", true)); client.executeMethod(hostConfig, method); System.err.println(method.getResponseBodyAsString()); } catch (HttpException he) { System.err.println(he); } catch (IOException ie) { System.err.println(ie); } finally { method.releaseConnection(); if (fos != null) { try { fos.close(); } catch (Exception fe) { } } } }