List of usage examples for java.net HttpURLConnection HTTP_NOT_FOUND
int HTTP_NOT_FOUND
To view the source code for java.net HttpURLConnection HTTP_NOT_FOUND.
Click Source Link
From source file:com.netflix.genie.server.resources.ClusterConfigResource.java
/** * Add new tags to a given cluster.//from w w w.j a v a 2 s . c om * * @param id The id of the cluster to add the tags to. Not * null/empty/blank. * @param tags The tags to add. Not null/empty/blank. * @return The active tags for this cluster. * @throws GenieException For any error */ @POST @Path("/{id}/tags") @Consumes(MediaType.APPLICATION_JSON) @ApiOperation(value = "Add new tags to a cluster", notes = "Add the supplied tags to the cluster with the supplied id.", response = String.class, responseContainer = "List") @ApiResponses(value = { @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = "Cluster not found"), @ApiResponse(code = HttpURLConnection.HTTP_PRECON_FAILED, message = "Invalid required parameter supplied"), @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = "Genie Server Error due to Unknown Exception") }) public Set<String> addTagsForCluster( @ApiParam(value = "Id of the cluster to add configuration to.", required = true) @PathParam("id") final String id, @ApiParam(value = "The tags to add.", required = true) final Set<String> tags) throws GenieException { LOG.info("Called with id " + id + " and tags " + tags); return this.clusterConfigService.addTagsForCluster(id, tags); }
From source file:com.netflix.genie.server.resources.CommandConfigResource.java
/** * Get the application configured for a given command. * * @param id The id of the command to get the application files for. Not * NULL/empty/blank.//from www.j a v a 2 s .c o m * @return The active application for the command. * @throws GenieException For any error */ @GET @Path("/{id}/application") @ApiOperation(value = "Get the application for a command", notes = "Get the application for the command with the supplied id.", response = Application.class) @ApiResponses(value = { @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = "Command not found"), @ApiResponse(code = HttpURLConnection.HTTP_PRECON_FAILED, message = "Invalid required parameter supplied"), @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = "Genie Server Error due to Unknown Exception") }) public Application getApplicationForCommand( @ApiParam(value = "Id of the command to get the application for.", required = true) @PathParam("id") final String id) throws GenieException { LOG.info("Called with id " + id); return this.commandConfigService.getApplicationForCommand(id); }
From source file:com.netflix.genie.server.resources.ApplicationConfigResource.java
/** * Get all the tags for a given application. * * @param id The id of the application to get the tags for. Not * NULL/empty/blank./*w w w. j av a2 s .c o m*/ * @return The active set of tags. * @throws GenieException For any error */ @GET @Path("/{id}/tags") @ApiOperation(value = "Get the tags for a application", notes = "Get the tags for the application with the supplied id.", response = String.class, responseContainer = "List") @ApiResponses(value = { @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = "Application not found"), @ApiResponse(code = HttpURLConnection.HTTP_PRECON_FAILED, message = "Invalid ID supplied"), @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = "Genie Server Error due to Unknown Exception") }) public Set<String> getTagsForApplication( @ApiParam(value = "Id of the application to get tags for.", required = true) @PathParam("id") final String id) throws GenieException { LOG.info("Called with id " + id); return this.applicationConfigService.getTagsForApplication(id); }
From source file:com.day.cq.wcm.foundation.impl.Rewriter.java
/** * Process a page.// w ww . ja va2 s. c o m */ public void rewrite(HttpServletRequest request, HttpServletResponse response) throws IOException { try { targetURL = new URI(target); } catch (URISyntaxException e) { IOException ioe = new IOException("Bad URI syntax: " + target); ioe.initCause(e); throw ioe; } setHostPrefix(targetURL); HttpClient httpClient = new HttpClient(); HttpState httpState = new HttpState(); HostConfiguration hostConfig = new HostConfiguration(); HttpMethodBase httpMethod; // define host hostConfig.setHost(targetURL.getHost(), targetURL.getPort()); // create http method String method = (String) request.getAttribute("cq.ext.app.method"); if (method == null) { method = request.getMethod(); } method = method.toUpperCase(); boolean isPost = "POST".equals(method); String urlString = targetURL.getPath(); StringBuffer query = new StringBuffer(); if (targetURL.getQuery() != null) { query.append("?"); query.append(targetURL.getQuery()); } //------------ GET --------------- if ("GET".equals(method)) { // add internal props Iterator<String> iter = extraParams.keySet().iterator(); while (iter.hasNext()) { String name = iter.next(); String value = extraParams.get(name); if (query.length() == 0) { query.append("?"); } else { query.append("&"); } query.append(Text.escape(name)); query.append("="); query.append(Text.escape(value)); } if (passInput) { // add request params @SuppressWarnings("unchecked") Enumeration<String> e = request.getParameterNames(); while (e.hasMoreElements()) { String name = e.nextElement(); if (targetParamName.equals(name)) { continue; } String[] values = request.getParameterValues(name); for (int i = 0; i < values.length; i++) { if (query.length() == 0) { query.append("?"); } else { query.append("&"); } query.append(Text.escape(name)); query.append("="); query.append(Text.escape(values[i])); } } } httpMethod = new GetMethod(urlString + query); //------------ POST --------------- } else if ("POST".equals(method)) { PostMethod m = new PostMethod(urlString + query); httpMethod = m; String contentType = request.getContentType(); boolean mp = contentType != null && contentType.toLowerCase().startsWith("multipart/"); if (mp) { //------------ MULTPART POST --------------- List<Part> parts = new LinkedList<Part>(); Iterator<String> iter = extraParams.keySet().iterator(); while (iter.hasNext()) { String name = iter.next(); String value = extraParams.get(name); parts.add(new StringPart(name, value)); } if (passInput) { // add request params @SuppressWarnings("unchecked") Enumeration<String> e = request.getParameterNames(); while (e.hasMoreElements()) { String name = e.nextElement(); if (targetParamName.equals(name)) { continue; } String[] values = request.getParameterValues(name); for (int i = 0; i < values.length; i++) { parts.add(new StringPart(name, values[i])); } } } m.setRequestEntity( new MultipartRequestEntity(parts.toArray(new Part[parts.size()]), m.getParams())); } else { //------------ NORMAL POST --------------- // add internal props Iterator<String> iter = extraParams.keySet().iterator(); while (iter.hasNext()) { String name = iter.next(); String value = extraParams.get(name); m.addParameter(name, value); } if (passInput) { // add request params @SuppressWarnings("unchecked") Enumeration e = request.getParameterNames(); while (e.hasMoreElements()) { String name = (String) e.nextElement(); if (targetParamName.equals(name)) { continue; } String[] values = request.getParameterValues(name); for (int i = 0; i < values.length; i++) { m.addParameter(name, values[i]); } } } } } else { log.error("Unsupported method ''{0}''", method); throw new IOException("Unsupported http method " + method); } log.debug("created http connection for method {0} to {1}", method, urlString + query); // add some request headers httpMethod.addRequestHeader("User-Agent", request.getHeader("User-Agent")); httpMethod.setFollowRedirects(!isPost); httpMethod.getParams().setSoTimeout(soTimeout); httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(connectionTimeout); // send request httpClient.executeMethod(hostConfig, httpMethod, httpState); String contentType = httpMethod.getResponseHeader("Content-Type").getValue(); log.debug("External app responded: {0}", httpMethod.getStatusLine()); log.debug("External app contenttype: {0}", contentType); // check response code int statusCode = httpMethod.getStatusCode(); if (statusCode >= HttpURLConnection.HTTP_BAD_REQUEST) { PrintWriter writer = response.getWriter(); writer.println("External application returned status code: " + statusCode); return; } else if (statusCode == HttpURLConnection.HTTP_MOVED_TEMP || statusCode == HttpURLConnection.HTTP_MOVED_PERM) { String location = httpMethod.getResponseHeader("Location").getValue(); if (location == null) { response.sendError(HttpURLConnection.HTTP_NOT_FOUND); return; } response.sendRedirect(rewriteURL(location, false)); return; } // open input stream InputStream in = httpMethod.getResponseBodyAsStream(); // check content type if (contentType != null && contentType.startsWith("text/html")) { rewriteHtml(in, contentType, response); } else { // binary mode if (contentType != null) { response.setContentType(contentType); } OutputStream outs = response.getOutputStream(); try { byte buf[] = new byte[8192]; int len; while ((len = in.read(buf)) != -1) { outs.write(buf, 0, len); } } finally { if (in != null) { in.close(); } } } }
From source file:com.netflix.genie.server.resources.CommandConfigResource.java
/** * Remove the application from a given command. * * @param id The id of the command to delete the application from. Not * null/empty/blank./* w ww. j av a 2 s .c o m*/ * @return The active set of applications for the command. * @throws GenieException For any error */ @DELETE @Path("/{id}/application") @ApiOperation(value = "Remove an application from a command", notes = "Remove the application from the command with given id.", response = Application.class) @ApiResponses(value = { @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = "Command not found"), @ApiResponse(code = HttpURLConnection.HTTP_PRECON_FAILED, message = "Invalid required parameter supplied"), @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = "Genie Server Error due to Unknown Exception") }) public Application removeApplicationForCommand( @ApiParam(value = "Id of the command to delete from.", required = true) @PathParam("id") final String id) throws GenieException { LOG.info("Called with id '" + id + "'."); return this.commandConfigService.removeApplicationForCommand(id); }
From source file:com.netflix.genie.server.resources.ClusterConfigResource.java
/** * Get all the tags for a given cluster. * * @param id The id of the cluster to get the tags for. Not * NULL/empty/blank.//from w ww. j a va 2 s .com * @return The active set of tags. * @throws GenieException For any error */ @GET @Path("/{id}/tags") @ApiOperation(value = "Get the tags for a cluster", notes = "Get the tags for the cluster with the supplied id.", response = String.class, responseContainer = "List") @ApiResponses(value = { @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = "Cluster not found"), @ApiResponse(code = HttpURLConnection.HTTP_PRECON_FAILED, message = "Invalid required parameter supplied"), @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = "Genie Server Error due to Unknown Exception") }) public Set<String> getTagsForCluster( @ApiParam(value = "Id of the cluster to get tags for.", required = true) @PathParam("id") final String id) throws GenieException { LOG.info("Called with id " + id); return this.clusterConfigService.getTagsForCluster(id); }
From source file:org.eclipse.orion.server.docker.server.DockerServer.java
private DockerResponse.StatusCode getDockerResponse(DockerResponse dockerResponse, HttpURLConnection httpURLConnection) { try {/*from w w w . j av a 2 s.co m*/ int responseCode = httpURLConnection.getResponseCode(); if (responseCode == HttpURLConnection.HTTP_OK) { dockerResponse.setStatusCode(DockerResponse.StatusCode.OK); return DockerResponse.StatusCode.OK; } else if (responseCode == HttpURLConnection.HTTP_CREATED) { dockerResponse.setStatusCode(DockerResponse.StatusCode.CREATED); return DockerResponse.StatusCode.CREATED; } else if (responseCode == HttpURLConnection.HTTP_NO_CONTENT) { dockerResponse.setStatusCode(DockerResponse.StatusCode.STARTED); return DockerResponse.StatusCode.STARTED; } else if (responseCode == HttpURLConnection.HTTP_BAD_REQUEST) { dockerResponse.setStatusCode(DockerResponse.StatusCode.BAD_PARAMETER); dockerResponse.setStatusMessage(httpURLConnection.getResponseMessage()); return DockerResponse.StatusCode.BAD_PARAMETER; } else if (responseCode == HttpURLConnection.HTTP_NOT_FOUND) { dockerResponse.setStatusCode(DockerResponse.StatusCode.NO_SUCH_CONTAINER); dockerResponse.setStatusMessage(httpURLConnection.getResponseMessage()); return DockerResponse.StatusCode.NO_SUCH_CONTAINER; } else if (responseCode == HttpURLConnection.HTTP_INTERNAL_ERROR) { dockerResponse.setStatusCode(DockerResponse.StatusCode.SERVER_ERROR); dockerResponse.setStatusMessage(httpURLConnection.getResponseMessage()); return DockerResponse.StatusCode.SERVER_ERROR; } else { throw new RuntimeException("Unknown status code :" + responseCode); } } catch (IOException e) { setDockerResponse(dockerResponse, e); if (e instanceof ConnectException && e.getLocalizedMessage().contains("Connection refused")) { // connection refused means the docker server is not running. dockerResponse.setStatusCode(DockerResponse.StatusCode.CONNECTION_REFUSED); return DockerResponse.StatusCode.CONNECTION_REFUSED; } } return DockerResponse.StatusCode.SERVER_ERROR; }
From source file:net.myrrix.client.ClientRecommender.java
/** * @param userID user for which recommendations are to be computed * @param howMany desired number of recommendations * @param considerKnownItems if true, items that the user is already associated to are candidates * for recommendation. Normally this is {@code false}. * @param rescorerParams optional parameters to send to the server's {@code RescorerProvider} * @return {@link List} of recommended {@link RecommendedItem}s, ordered from most strongly recommend to least * @throws NoSuchUserException if the user is not known in the model * @throws NotReadyException if the recommender has no model available yet * @throws TasteException if another error occurs * @throws UnsupportedOperationException if rescorer is not null *///from ww w .j a va 2 s. c o m public List<RecommendedItem> recommend(long userID, int howMany, boolean considerKnownItems, String[] rescorerParams) throws TasteException { StringBuilder urlPath = new StringBuilder(); urlPath.append("/recommend/"); urlPath.append(userID); appendCommonQueryParams(howMany, considerKnownItems, rescorerParams, urlPath); TasteException savedException = null; for (HostAndPort replica : choosePartitionAndReplicas(userID)) { HttpURLConnection connection = null; try { connection = buildConnectionToReplica(replica, urlPath.toString(), "GET"); switch (connection.getResponseCode()) { case HttpURLConnection.HTTP_OK: return consumeItems(connection); case HttpURLConnection.HTTP_NOT_FOUND: throw new NoSuchUserException(userID); case HttpURLConnection.HTTP_UNAVAILABLE: throw new NotReadyException(); default: throw new TasteException(connection.getResponseCode() + " " + connection.getResponseMessage()); } } catch (TasteException te) { log.info("Can't access {} at {}: ({})", urlPath, replica, te.toString()); savedException = te; } catch (IOException ioe) { log.info("Can't access {} at {}: ({})", urlPath, replica, ioe.toString()); savedException = new TasteException(ioe); } finally { if (connection != null) { connection.disconnect(); } } } throw savedException; }
From source file:com.netflix.genie.server.resources.ApplicationConfigResource.java
/** * Update the tags for a given application. * * @param id The id of the application to update the tags for. * Not null/empty/blank./*from w w w.ja v a 2s .com*/ * @param tags The tags to replace existing configuration * files with. Not null/empty/blank. * @return The new set of application tags. * @throws GenieException For any error */ @PUT @Path("/{id}/tags") @Consumes(MediaType.APPLICATION_JSON) @ApiOperation(value = "Update tags for a application", notes = "Replace the existing tags for application with given id.", response = String.class, responseContainer = "List") @ApiResponses(value = { @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = "Application not found"), @ApiResponse(code = HttpURLConnection.HTTP_PRECON_FAILED, message = "Invalid ID supplied"), @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = "Genie Server Error due to Unknown Exception") }) public Set<String> updateTagsForApplication( @ApiParam(value = "Id of the application to update tags for.", required = true) @PathParam("id") final String id, @ApiParam(value = "The tags to replace existing with.", required = true) final Set<String> tags) throws GenieException { LOG.info("Called with id " + id + " and tags " + tags); return this.applicationConfigService.updateTagsForApplication(id, tags); }
From source file:com.google.wave.api.AbstractRobot.java
@Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) { this.request = req; if (req.getRequestURI().equals(RPC_PATH)) { processRpc(req, resp);// ww w . j a v a 2s .c o m } else { resp.setStatus(HttpURLConnection.HTTP_NOT_FOUND); } }