List of usage examples for org.apache.http.client ClientProtocolException ClientProtocolException
public ClientProtocolException(final String message, final Throwable cause)
From source file:monasca.common.middleware.TokenCache.java
public String getToken(String key) throws ClientProtocolException { String value = null;/* ww w .j av a 2 s . c om*/ try { value = cache.get(key); } catch (ExecutionException e) { logger.info("Failed to get token", e); throw new ClientProtocolException(e.getMessage(), e); } return value; }
From source file:com.wudaosoft.net.httpclient.SAXSourceResponseHandler.java
private SAXSource readSAXSource(InputStream body) throws IOException { try {/* w w w . j av a 2 s .c om*/ XMLReader reader = XMLReaderFactory.createXMLReader(); reader.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true); reader.setFeature("http://xml.org/sax/features/external-general-entities", false); reader.setEntityResolver(NO_OP_ENTITY_RESOLVER); return new SAXSource(reader, new InputSource(body)); } catch (SAXException ex) { throw new ClientProtocolException("Could not parse document: " + ex.getMessage(), ex); } }
From source file:monasca.common.middleware.HttpAuthClient.java
private String verifyUUIDToken(String token, String newUri, Header[] headers) throws ClientProtocolException { HttpGet httpGet = new HttpGet(newUri); try {/* w w w .j a va 2 s . co m*/ httpGet.setHeader("Accept", APPLICATION_JSON); httpGet.setHeader("Content-Type", APPLICATION_JSON); if (headers != null) { for (Header header : headers) { httpGet.setHeader(header); } } HttpResponse response = sendGet(httpGet); HttpEntity entity = response.getEntity(); int code = response.getStatusLine().getStatusCode(); InputStream instream; try { if (code == 404) { instream = entity.getContent(); instream.close(); // // Don't log the whole token, just the last ten characters // throw new AuthException("Authorization failed for user token ending with: " + token.substring(token.length() - 10)); } if (code != 200) { adminToken = null; instream = entity.getContent(); instream.close(); String reasonPhrase = response.getStatusLine().getReasonPhrase(); throw new AuthException("Failed to validate via HTTP " + code + " " + reasonPhrase); } } catch (IOException e) { throw new ClientProtocolException("IO Exception: problem closing stream ", e); } return parseResponse(response); } finally { httpGet.releaseConnection(); } }
From source file:monasca.common.middleware.HttpAuthClient.java
private HttpResponse sendGet(HttpGet httpGet) throws ClientProtocolException { HttpResponse response;// w ww . j a v a 2 s . co m if (appConfig.getAdminAuthMethod().equalsIgnoreCase(Config.TOKEN)) { httpGet.setHeader(new BasicHeader(TOKEN, appConfig.getAdminToken())); } else { httpGet.setHeader(new BasicHeader(TOKEN, getAdminToken())); } try { response = client.execute(httpGet); } catch (ConnectException c) { httpGet.abort(); throw new ServiceUnavailableException(c.getMessage()); } catch (IOException e) { httpGet.abort(); throw new ClientProtocolException("IO Exception during GET request ", e); } return response; }
From source file:com.esri.geoportal.commons.http.BotsHttpClient.java
private URI applyPHP(URI uri) throws ClientProtocolException { if (bots != null) { try {/*from w w w .jav a 2 s .c o m*/ String orgUri = uri.toString(); PHP php = parsePHP(bots.getHost()); if (php != null) { uri = updateURI(uri, php); } if (!uri.toString().equals(orgUri)) { LOG.debug(String.format("Uri updated from %s to %s", orgUri, uri)); } } catch (URISyntaxException ex) { throw new ClientProtocolException("Unable to apply host robots.txt host directive.", ex); } } return uri; }