List of usage examples for org.apache.commons.httpclient HttpException getCause
public Throwable getCause()
From source file:org.dasein.persist.riak.RiakCache.java
@Override public T get(Object keyValue) throws PersistenceException { if (keyValue == null) { return null; }//from w w w . j av a 2 s .com final String primaryKey = keyValue.toString(); try { CacheLoader<T> loader; loader = new CacheLoader<T>() { public T load(Object... args) { startCall("loadObject"); try { if (std.isDebugEnabled()) { std.debug("get - cache miss, loading " + primaryKey); } StringBuilder url = new StringBuilder(); url.append(getEndpoint()); url.append("buckets/"); url.append(getBucket()); url.append("/keys/"); url.append(primaryKey); HttpClient client = getClient(); GetMethod get = new GetMethod(url.toString()); int code; try { if (wire.isDebugEnabled()) { try { wire.debug(get.getName() + " " + url.toString()); wire.debug(""); for (Header h : get.getRequestHeaders()) { wire.debug(h.getName() + ": " + h.getValue()); } wire.debug(""); } catch (Throwable ignore) { // ignore } } code = client.executeMethod(get); } catch (HttpException e) { throw new RuntimeException("HttpException during GET: " + e.getMessage()); } catch (IOException e) { throw new RuntimeException("IOException during GET: " + e.getMessage()); } try { final String body = get.getResponseBodyAsString(); if (wire.isDebugEnabled()) { try { wire.debug("----------------------------------------"); wire.debug(""); wire.debug(get.getStatusLine().getStatusCode() + " " + get.getStatusLine().getReasonPhrase()); wire.debug(""); if (body != null) { wire.debug(body); wire.debug(""); } } catch (Throwable ignore) { // ignore } } if (code != HttpStatus.SC_OK) { if (code == HttpStatus.SC_NOT_FOUND) { return null; } throw new RuntimeException(code + ": " + body); } JSONObject ob = new JSONObject(body); String version = "0"; if (ob.has("SCHEMA_VERSION")) { version = ob.getString("SCHEMA_VERSION"); } return toTargetFromJSON(version, ob); } catch (IOException e) { throw new RuntimeException(e); } catch (PersistenceException e) { throw new RuntimeException(e); } catch (JSONException e) { throw new RuntimeException(e); } } finally { endCall("loadObject"); } } }; if (std.isDebugEnabled()) { std.debug("get - looking in cache for " + keyValue); } return getCache().find(getPrimaryKeyField(), keyValue, loader, getPrimaryKeyField(), keyValue); } catch (CacheManagementException e) { throw new PersistenceException(e); } catch (RuntimeException e) { Throwable t = e.getCause(); if (t != null && t instanceof PersistenceException) { throw (PersistenceException) t; } throw new PersistenceException(e); } }