List of usage examples for org.apache.commons.httpclient HttpStatus SC_NOT_FOUND
int SC_NOT_FOUND
To view the source code for org.apache.commons.httpclient HttpStatus SC_NOT_FOUND.
Click Source Link
From source file:org.dasein.persist.riak.RiakCache.java
private Iterable<T> execFind(boolean cursor, @Nonnull SearchTerm[] terms, @Nullable final JiteratorFilter<T> filter, @Nullable Boolean orderDesc, @Nullable String... orderFields) throws PersistenceException { if (std.isTraceEnabled()) { std.trace("ENTER: " + RiakCache.class.getName() + ".find(" + Arrays.toString(terms) + "," + filter + "," + orderDesc + "," + Arrays.toString(orderFields) + ")"); }/* ww w . j a v a 2 s. c om*/ try { if ((orderFields == null || orderFields.length < 1) && (terms.length == 1 || (terms.length == 2 && terms[1].getValue() != null && terms[0].getValue() != null && Number.class.isAssignableFrom(terms[0].getValue().getClass()) && (terms[1].getValue() instanceof Boolean)))) { boolean equals = true; for (SearchTerm t : terms) { if (!t.getOperator().equals(Operator.EQUALS)) { equals = false; break; } } if (equals) { Key key = matchKeys(terms); if (key != null) { StringBuilder url = new StringBuilder(); String value; url.append(getEndpoint()); url.append("buckets/"); url.append(getBucket()); url.append("/index/"); for (int i = 0; i < key.getFields().length; i++) { url.append(key.getFields()[i].toLowerCase()); if (i < key.getFields().length - 1) { url.append("-"); } } url.append("_"); try { if (key.getFields().length > 1) { StringBuilder v = new StringBuilder(); url.append("bin"); for (int i = 0; i < key.getFields().length; i++) { String f = key.getFields()[i]; for (SearchTerm t : terms) { if (t.getColumn().equalsIgnoreCase(f)) { Object ob = t.getValue(); if (ob == null) { ob = "=*="; } v.append(ob.toString()); if (i < key.getFields().length - 1) { v.append("\n"); } break; } } } value = Base64.encodeBase64String(v.toString().getBytes("utf-8")); } else if (terms[0].getValue() == null || (!(terms[0].getValue() instanceof Long) && !(terms[0].getValue() instanceof Integer) && !(terms[0].getValue() instanceof Short))) { url.append("bin"); value = Base64.encodeBase64String( (terms[0].getValue() == null ? "" : terms[0].getValue().toString()) .getBytes("utf-8")); } else { url.append("int"); value = String.valueOf(((Number) terms[0].getValue()).longValue()); } } catch (UnsupportedEncodingException e) { throw new PersistenceException(e); } url.append("/"); url.append(value); if (filter == null) { return list(cursor, url.toString(), null); } else { return list(cursor, url.toString(), filter); } } } } startCall("findWithMapReduce"); try { HashMap<String, Object> request = new HashMap<String, Object>(); ArrayList<Map<String, Object>> query = new ArrayList<Map<String, Object>>(); HashMap<String, Object> maps = new HashMap<String, Object>(); HashMap<String, Object> map = new HashMap<String, Object>(); HashMap<String, Object> inputs = new HashMap<String, Object>(); terms = matchKeys(inputs, terms); if (inputs.size() < 1) { request.put("inputs", getBucket()); } else { inputs.put("bucket", getBucket()); request.put("inputs", inputs); } map.put("language", "javascript"); map.put("source", buildMapFunction(false, terms)); map.put("keep", true); maps.put("map", map); query.add(maps); if (orderFields != null && orderFields.length > 0) { HashMap<String, Object> reduces = new HashMap<String, Object>(); HashMap<String, Object> reduce = new HashMap<String, Object>(); reduce.put("language", "javascript"); reduce.put("keep", true); reduce.put("source", buildReduceSort(orderDesc != null && orderDesc, orderFields)); reduces.put("reduce", reduce); query.add(reduces); } request.put("query", query); String json = (new JSONObject(request)).toString(); HttpClient client = getClient(); PostMethod post = new PostMethod(getEndpoint() + "mapred"); int code; try { post.setRequestEntity(new StringRequestEntity(json, "application/json", "utf-8")); if (wire.isDebugEnabled()) { try { wire.debug(post.getName() + " " + getEndpoint() + "mapred"); wire.debug(""); for (Header h : post.getRequestHeaders()) { wire.debug(h.getName() + ": " + h.getValue()); } wire.debug("Content-length: " + post.getRequestEntity().getContentLength()); wire.debug("Content-type: " + post.getRequestEntity().getContentType()); wire.debug(""); wire.debug(((StringRequestEntity) post.getRequestEntity()).getContent()); wire.debug(""); } catch (Throwable ignore) { // ignore } } code = client.executeMethod(post); } catch (HttpException e) { throw new PersistenceException("HttpException during POST: " + e.getMessage()); } catch (IOException e) { throw new PersistenceException("IOException during POST: " + e.getMessage()); } try { String body = post.getResponseBodyAsString(); try { if (wire.isDebugEnabled()) { wire.debug("----------------------------------------"); wire.debug(""); wire.debug(post.getStatusLine().getStatusCode() + " " + post.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 Collections.emptyList(); } throw new PersistenceException(code + ": " + body); } final JSONArray results = ((orderFields != null && orderFields.length > 0) ? (new JSONArray(body)).getJSONArray(0) : new JSONArray(body)); final int len = results.length(); if (cursor) { CursorPopulator<T> populator = new CursorPopulator<T>(getTarget().getName() + ".find", null) { @Override public void populate(ForwardCursor<T> cursor) { try { for (int i = 0; i < len; i++) { JSONObject ob = results.getJSONObject(i); if (std.isDebugEnabled()) { std.debug("find - checking cache for " + ob.get(getPrimaryKeyField())); } T item = getCache().find(getPrimaryKeyField(), ob.get(getPrimaryKeyField())); if (item == null) { if (std.isDebugEnabled()) { std.debug("find - cache miss, loading " + ob.get(getPrimaryKeyField())); } String version = "0"; if (ob.has("SCHEMA_VERSION")) { version = ob.getString("SCHEMA_VERSION"); } item = toTargetFromJSON(version, ob); if (item != null) { getCache().cache(item); } } if (item != null) { try { if (filter == null || filter.filter(item)) { cursor.push(item); } } catch (Throwable t) { throw new RuntimeException(t); } } } } catch (Throwable t) { throw new JiteratorLoadException(t); } } }; populator.populate(); if (filter == null) { populator.setSize(len); } return populator.getCursor(); } else { PopulatorThread<T> populator = new PopulatorThread<T>(new JiteratorPopulator<T>() { @Override public void populate(@Nonnull Jiterator<T> iterator) throws Exception { for (int i = 0; i < len; i++) { JSONObject ob = results.getJSONObject(i); if (std.isDebugEnabled()) { std.debug("find - checking cache for " + ob.get(getPrimaryKeyField())); } T item = getCache().find(getPrimaryKeyField(), ob.get(getPrimaryKeyField())); if (item == null) { if (std.isDebugEnabled()) { std.debug("find - cache miss, loading " + ob.get(getPrimaryKeyField())); } String version = "0"; if (ob.has("SCHEMA_VERSION")) { version = ob.getString("SCHEMA_VERSION"); } item = toTargetFromJSON(version, ob); if (item != null) { getCache().cache(item); } } if (item != null) { try { if (filter == null || filter.filter(item)) { iterator.push(item); } } catch (Throwable t) { throw new RuntimeException(t); } } } } }); populator.populate(); if (filter == null) { populator.setSize(len); } return populator.getResult(); } } catch (Exception e) { std.error(e.getMessage(), e); throw new PersistenceException(e); } } finally { endCall("findWithMapReduce"); } } finally { if (std.isTraceEnabled()) { std.trace("EXIT: " + RiakCache.class.getName() + ".find()"); } } }
From source file:org.dasein.persist.riak.RiakCache.java
private JSONObject findKeysInBucketAsJSON() throws PersistenceException { startCall("findKeysInBucket"); try {/*from w ww. j a v a 2 s . c om*/ StringBuilder url = new StringBuilder(); url.append(getEndpoint()); url.append("buckets/"); url.append(getBucket()); url.append("/index/$bucket/"); url.append(getBucket()); HttpClient client = getClient(); GetMethod get = new GetMethod(url.toString()); int code; 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 } } try { code = client.executeMethod(get); } catch (HttpException e) { throw new PersistenceException("HttpException during GET: " + e.getMessage()); } catch (IOException e) { throw new PersistenceException("IOException during GET: " + e.getMessage()); } try { String json = get.getResponseBodyAsString(); try { if (wire.isDebugEnabled()) { wire.debug("----------------------------------------"); wire.debug(""); wire.debug( get.getStatusLine().getStatusCode() + " " + get.getStatusLine().getReasonPhrase()); wire.debug(""); if (json != null) { wire.debug(json); wire.debug(""); } } } catch (Throwable ignore) { // ignore } if (code != HttpStatus.SC_OK) { if (code == HttpStatus.SC_NOT_FOUND) { return new JSONObject("{\"keys\" : []}"); } else { throw new PersistenceException(code + ": " + json); } } return new JSONObject(json); } catch (JSONException e) { throw new PersistenceException(e); } catch (IOException e) { std.error("Failed to load JSON key list from Riak: " + e.getMessage()); throw new PersistenceException(e); } } finally { endCall("findKeysInBucket"); } }
From source file:org.dasein.persist.riak.RiakCache.java
@Override public T get(Object keyValue) throws PersistenceException { if (keyValue == null) { return null; }//from ww w .ja v a2s.c o m 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); } }
From source file:org.dasein.persist.riak.RiakCache.java
private @Nonnull Iterable<T> list(boolean asCursor, @Nonnull String listEndpoint, final @Nullable JiteratorFilter<T> filter) throws PersistenceException { if (std.isTraceEnabled()) { std.trace("ENTER: " + RiakCache.class.getName() + ".list(" + listEndpoint + ")"); }/*from w w w.j a v a 2s .com*/ try { startCall("list"); try { HttpClient client = getClient(); GetMethod get = new GetMethod(listEndpoint); int code; if (wire.isDebugEnabled()) { try { wire.debug(get.getName() + " " + listEndpoint); wire.debug(""); for (Header h : get.getRequestHeaders()) { wire.debug(h.getName() + ": " + h.getValue()); } wire.debug(""); } catch (Throwable ignore) { // ignore } } try { code = client.executeMethod(get); } catch (HttpException e) { throw new PersistenceException("HttpException during GET: " + e.getMessage()); } catch (IOException e) { throw new PersistenceException("IOException during GET: " + e.getMessage()); } try { final String body = get.getResponseBodyAsString(); try { if (wire.isDebugEnabled()) { 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 Collections.emptyList(); } throw new PersistenceException(code + ": " + body); } JSONObject ob = new JSONObject(body); if (ob.has("keys")) { final JSONArray keys = ob.getJSONArray("keys"); final int len = keys.length(); if (asCursor) { CursorPopulator<T> populator = new CursorPopulator<T>(getTarget().getName() + ".list", null) { @Override public void populate(ForwardCursor<T> cursor) { try { for (int i = 0; i < len; i++) { String key = keys.getString(i); T item = get(key); if (item != null) { try { if (filter == null || filter.filter(item)) { cursor.push(item); } } catch (Throwable t) { throw new JiteratorLoadException(t); } } } } catch (JSONException e) { throw new JiteratorLoadException(e); } catch (PersistenceException e) { throw new JiteratorLoadException(e); } } }; populator.populate(); if (filter == null) { populator.setSize(len); } return populator.getCursor(); } else { PopulatorThread<T> populator; populator = new PopulatorThread<T>(new JiteratorPopulator<T>() { public void populate(@Nonnull Jiterator<T> iterator) throws Exception { for (int i = 0; i < len; i++) { String key = keys.getString(i); T item = get(key); if (item != null) { try { if (filter == null || filter.filter(item)) { iterator.push(item); } } catch (Throwable t) { throw new RuntimeException(t); } } } } }); populator.populate(); if (filter == null) { populator.setSize(len); } return populator.getResult(); } } return Collections.emptyList(); } catch (IOException e) { throw new PersistenceException(e); } catch (JSONException e) { throw new PersistenceException(e); } } finally { endCall("list"); } } finally { if (std.isTraceEnabled()) { std.trace("EXIT: " + RiakCache.class.getName() + ".list()"); } } }
From source file:org.dasein.persist.riak.RiakCache.java
@Override public void remove(Transaction xaction, T item) throws PersistenceException { startCall("remove"); try {/*from w w w . ja va2 s . c om*/ StringBuilder url = new StringBuilder(); url.append(getEndpoint()); url.append("buckets/"); url.append(getBucket()); url.append("/keys/"); url.append(getKeyValue(item)); HttpClient client = getClient(); DeleteMethod delete = new DeleteMethod(url.toString()); int code; try { if (wire.isDebugEnabled()) { try { wire.debug(delete.getName() + " " + url.toString()); wire.debug(""); for (Header h : delete.getRequestHeaders()) { wire.debug(h.getName() + ": " + h.getValue()); } wire.debug(""); } catch (Throwable ignore) { // ignore } } code = client.executeMethod(delete); } catch (HttpException e) { throw new PersistenceException("HttpException during GET: " + e.getMessage()); } catch (IOException e) { throw new PersistenceException("IOException during GET: " + e.getMessage()); } try { String body = delete.getResponseBodyAsString(); if (wire.isDebugEnabled()) { try { wire.debug("----------------------------------------"); wire.debug(""); wire.debug(delete.getStatusLine().getStatusCode() + " " + delete.getStatusLine().getReasonPhrase()); wire.debug(""); if (body != null) { wire.debug(body); wire.debug(""); } } catch (Throwable ignore) { // ignore } } if (code != HttpStatus.SC_NO_CONTENT && code != HttpStatus.SC_NOT_FOUND) { throw new PersistenceException(code + ": " + body); } getCache().release(item); } catch (IOException e) { throw new PersistenceException(e); } } finally { endCall("remove"); } }
From source file:org.dcm4chex.archive.hsm.module.castor.CAStorHSMModule.java
/** * The method that is called by the SyncFileStatus service to check the * status of a study tarball in nearline storage (i.e. on CAStor). * /*from w w w . j a v a 2 s.c o m*/ * @param fsID * The file system ID for nearline storage. * @param filePath * The relative path to the study tarball in nearline storage. * @param userInfo * The user information for the tar file. * @return A <code>FileStatus</code> constant that denotes the status of the * queried file. * @throws HSMException */ @Override public Integer queryStatus(String fsID, String filePath, String userInfo) throws HSMException { logger.debug("queryStatus called with fsID=" + fsID + ", filePath=" + filePath + ", userInfo=" + userInfo); // filePath is just the object UUID String uuid = filePath; logger.debug("Querying CAStor for object " + uuid); try { if (client == null) { createClient(); } // The first parameter for ScspClient.info (String UUID) is not used // when requesting a named object and hence is set to empty ScspResponse response = client.info(uuid, "", new ScspQueryArgs(), new ScspHeaders()); switch (response.getHttpStatusCode()) { case HttpStatus.SC_OK: return FileStatus.ARCHIVED; case HttpStatus.SC_NOT_FOUND: break; default: logger.error("Unexpected INFO response: " + response.toString()); } } catch (ScspExecutionException e) { throw new HSMException("Could not query CAStor for object " + uuid, e); } catch (Exception e) { throw new HSMException("Could not get the status of " + filePath + " in nearline storage", e); } return FileStatus.DEFAULT; }
From source file:org.duracloud.snapshot.bridge.rest.RestoreResource.java
@Path("{restorationId}") @GET//from w w w . ja v a 2s .com @Produces(MediaType.APPLICATION_JSON) /** * Returns the status of a restoration. * @param snapshotId * @return */ public Response get(@PathParam("restorationId") String restorationId) { try { Restoration restoration = this.restorationManager.get(restorationId); return Response.ok().entity(toGetRestoreBridgeResult(restoration)).build(); } catch (RestorationNotFoundException ex) { log.error(ex.getMessage(), ex); return Response.status(HttpStatus.SC_NOT_FOUND).entity(new ResponseDetails(ex.getMessage())).build(); } catch (Exception ex) { log.error(ex.getMessage(), ex); return Response.serverError().entity(new ResponseDetails(ex.getMessage())).build(); } }
From source file:org.duracloud.snapshot.bridge.rest.RestoreResource.java
@Path("by-snapshot/{snapshotId}") @GET/*from ww w. jav a 2 s . c o m*/ @Produces(MediaType.APPLICATION_JSON) /** * Returns the status of a restoration by snapshot id. * @param snapshotId * @return */ public Response getBySnapshot(@PathParam("snapshotId") String snapshotId) { try { Restoration restoration = this.restorationManager.getBySnapshotId(snapshotId); return Response.ok().entity(toGetRestoreBridgeResult(restoration)).build(); } catch (RestorationNotFoundException ex) { log.error(ex.getMessage(), ex); return Response.status(HttpStatus.SC_NOT_FOUND).entity(new ResponseDetails(ex.getMessage())).build(); } catch (Exception ex) { log.error(ex.getMessage(), ex); return Response.serverError().entity(new ResponseDetails(ex.getMessage())).build(); } }
From source file:org.duracloud.snapshot.bridge.rest.RestoreResource.java
@Path("{restorationId}/complete") @POST/* w w w . ja v a2s .co m*/ @Produces(MediaType.APPLICATION_JSON) public Response restoreComplete(@PathParam("restorationId") String restorationId) { try { Restoration restoration = this.restorationManager.restoreCompleted(restorationId); log.info("executed restoreComplete for {}", restoration); return Response.ok() .entity(new CompleteRestoreBridgeResult(restoration.getStatus(), restoration.getStatusText())) .build(); } catch (RestorationNotFoundException ex) { log.error(ex.getMessage(), ex); return Response.status(HttpStatus.SC_NOT_FOUND).entity(new ResponseDetails(ex.getMessage())).build(); } catch (Exception ex) { log.error(ex.getMessage(), ex); return Response.serverError().entity(new ResponseDetails(ex.getMessage())).build(); } }
From source file:org.duracloud.snapshot.bridge.rest.SnapshotResource.java
@Path("{snapshotId}") @GET/*w w w. ja v a 2 s . c om*/ @Produces(MediaType.APPLICATION_JSON) /** * Returns the status of a snapshot. The fields available in the response will match * those in <code>SnapshotStatus</code>. * @param snapshotId * @return */ public Response getSnapshot(@PathParam("snapshotId") String snapshotId) { try { Snapshot snapshot = this.snapshotRepo.findByName(snapshotId); if (snapshot == null) { throw new SnapshotNotFoundException(snapshotId); } GetSnapshotBridgeResult result = new GetSnapshotBridgeResult(); DuracloudEndPointConfig source = snapshot.getSource(); result.setDescription(snapshot.getDescription()); result.setSnapshotDate(snapshot.getSnapshotDate()); result.setSnapshotId(snapshot.getName()); result.setSourceHost(source.getHost()); result.setSourceSpaceId(source.getSpaceId()); result.setSourceStoreId(source.getStoreId()); result.setStatus(snapshot.getStatus()); result.setTotalSizeInBytes(snapshot.getTotalSizeInBytes()); result.setContentItemCount(snapshotContentItemRepo.countBySnapshotName(snapshotId)); log.debug("got snapshot:" + result); return Response.ok().entity(result).build(); } catch (SnapshotNotFoundException ex) { log.error(ex.getMessage(), ex); return Response.status(HttpStatus.SC_NOT_FOUND).entity(new ResponseDetails(ex.getMessage())).build(); } catch (Exception ex) { log.error(ex.getMessage(), ex); return Response.serverError().entity(new ResponseDetails(ex.getMessage())).build(); } }