List of usage examples for java.net HttpURLConnection HTTP_INTERNAL_ERROR
int HTTP_INTERNAL_ERROR
To view the source code for java.net HttpURLConnection HTTP_INTERNAL_ERROR.
Click Source Link
From source file:com.netflix.genie.server.resources.ClusterConfigResource.java
/** * Get all the configuration files for a given cluster. * * @param id The id of the cluster to get the configuration files for. Not * NULL/empty/blank./*ww w .j ava 2 s . c o m*/ * @return The active set of configuration files. * @throws GenieException For any error */ @GET @Path("/{id}/configs") @ApiOperation(value = "Get the configuration files for a cluster", notes = "Get the configuration files 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> getConfigsForCluster( @ApiParam(value = "Id of the cluster to get configurations for.", required = true) @PathParam("id") final String id) throws GenieException { LOG.info("Called with id " + id); return this.clusterConfigService.getConfigsForCluster(id); }
From source file:be.cytomine.client.HttpClient.java
public static BufferedImage readBufferedImageFromRETRIEVAL(String url, String publicKey, String privateKey, String host) throws IOException { log.debug("readBufferedImageFromURL:" + url); URL URL = new URL(url); HttpHost targetHost = new HttpHost(URL.getHost(), URL.getPort()); log.debug("targetHost:" + targetHost); DefaultHttpClient client = new DefaultHttpClient(); log.debug("client:" + client); // Add AuthCache to the execution context BasicHttpContext localcontext = new BasicHttpContext(); log.debug("localcontext:" + localcontext); Header[] headers = authorizeFromRETRIEVAL("GET", URL.toString(), "", "", publicKey, privateKey, host); log.debug("headers:" + headers.length); BufferedImage img = null;/*from ww w . j a v a2s .c o m*/ HttpGet httpGet = new HttpGet(URL.toString()); httpGet.setHeaders(headers); HttpResponse response = client.execute(targetHost, httpGet, localcontext); int code = response.getStatusLine().getStatusCode(); log.info("url=" + url + " is " + code + "(OK=" + HttpURLConnection.HTTP_OK + ",MOVED=" + HttpURLConnection.HTTP_MOVED_TEMP + ")"); boolean isOK = (code == HttpURLConnection.HTTP_OK); boolean isFound = (code == HttpURLConnection.HTTP_MOVED_TEMP); boolean isErrorServer = (code == HttpURLConnection.HTTP_INTERNAL_ERROR); if (!isOK && !isFound & !isErrorServer) { throw new IOException(url + " cannot be read: " + code); } HttpEntity entity = response.getEntity(); if (entity != null) { log.debug("img=" + entity.getContent()); img = ImageIO.read(entity.getContent()); } return img; }
From source file:com.netflix.genie.server.resources.JobResource.java
/** * Get all the tags for a given job.// ww w . j av a2 s .co m * * @param id The id of the job to get the tags for. Not * NULL/empty/blank. * @return The active set of tags. * @throws GenieException For any error */ @GET @Path("/{id}/tags") @ApiOperation(value = "Get the tags for a job", notes = "Get the tags for the job with the supplied id.", response = String.class, responseContainer = "List") @ApiResponses(value = { @ApiResponse(code = HttpURLConnection.HTTP_BAD_REQUEST, message = "Bad Request"), @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = "Job for id does not exist."), @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> getTagsForJob( @ApiParam(value = "Id of the job to get tags for.", required = true) @PathParam("id") final String id) throws GenieException { LOG.info("Called with id " + id); return this.jobService.getTagsForJob(id); }
From source file:rapture.repo.mongodb.MongoDbDataStore.java
@Override public RaptureNativeQueryResult runNativeQueryWithLimitAndBounds(String repoType, final List<String> queryParams, final int limit, final int offset) { if (repoType.toUpperCase().equals(MONGODB)) { MongoRetryWrapper<RaptureNativeQueryResult> wrapper = new MongoRetryWrapper<RaptureNativeQueryResult>() { @Override/*from w w w . j av a 2s .co m*/ public FindIterable<Document> makeCursor() { // This is like a native query, except that we need to (a) // add in // the displayname (the key) into the // results, and force a limit and offset (so the queryParams // will // only be of size 2). Document queryObj = getQueryObjFromQueryParams(queryParams); // Document fieldObj = // getFieldObjFromQueryParams(queryParams); // if (!fieldObj.keySet().isEmpty()) { // fieldObj.put(KEY, "1"); // } MongoCollection<Document> collection = MongoDBFactory.getCollection(instanceName, tableName); FindIterable<Document> cursor = collection.find(queryObj); cursor = cursor.skip(offset).limit(limit); return cursor; } @Override public RaptureNativeQueryResult action(FindIterable<Document> iterable) { RaptureNativeQueryResult res = new RaptureNativeQueryResult(); for (Document d : iterable) { RaptureNativeRow row = new RaptureNativeRow(); row.setName(d.get(KEY).toString()); row.setContent(new JsonContent(d.get(VALUE).toString())); res.addRowContent(row); } return res; } }; return wrapper.doAction(); } else { throw RaptureExceptionFactory.create(HttpURLConnection.HTTP_INTERNAL_ERROR, mongoMsgCatalog.getMessage("Mismatch", repoType)); } }
From source file:i5.las2peer.services.servicePackage.TemplateService.java
@GET @Path("/persist/graph/{dataset}") @Produces(MediaType.APPLICATION_JSON)//from w w w. j a v a2s.c o m public HttpResponse getNewGraph(@PathParam("dataset") String dataset) { Connection conn = null; PreparedStatement stmnt = null; ResultSet rs = null; ToJSON converter = new ToJSON(); JSONObject json = new JSONObject(); EntityManagement em = new EntityManagement(); String query = null; Graph graph = new Graph(); try { // get connection from connection pool conn = dbm.getConnection(); switch (dataset) { case "urch": query = "SELECT id,content,author FROM urch order by author"; break; case "stdoctor": query = "SELECT id, content author FROM stdoctor order by author"; break; } // prepare statement stmnt = conn.prepareStatement(query); //stmnt.setString(1, dataSet); // retrieve result set rs = stmnt.executeQuery(); //create necessary tables em.createNodeTable(conn); em.createGraphTable(conn); //persist graph built form dataset graph = em.persistNewGraph(rs, conn); //for print information about persisted graph json = converter.graphToJson(graph); return new HttpResponse("Graph with " + json.toString() + " saved in database", HttpURLConnection.HTTP_OK); } catch (Exception e) { return new HttpResponse("Internal error: " + e.getMessage(), HttpURLConnection.HTTP_INTERNAL_ERROR); } finally { // free resources if exception or not if (rs != null) { try { rs.close(); } catch (Exception e) { Context.logError(this, e.getMessage()); // return HTTP Response on error return new HttpResponse("Internal error: " + e.getMessage(), HttpURLConnection.HTTP_INTERNAL_ERROR); } } if (stmnt != null) { try { stmnt.close(); } catch (Exception e) { Context.logError(this, e.getMessage()); // return HTTP Response on error return new HttpResponse("Internal error: " + e.getMessage(), HttpURLConnection.HTTP_INTERNAL_ERROR); } } if (conn != null) { try { conn.close(); } catch (Exception e) { Context.logError(this, e.getMessage()); // return HTTP Response on error return new HttpResponse("Internal error: " + e.getMessage(), HttpURLConnection.HTTP_INTERNAL_ERROR); } } } }
From source file:com.netflix.genie.server.services.impl.GenieExecutionServiceImpl.java
/** {@inheritDoc} */ @Override/*from w w w . j a v a2s. co m*/ public JobStatusResponse getJobStatus(String jobId) { logger.info("called for jobId: " + jobId); JobStatusResponse response; JobInfoElement jInfo; try { jInfo = pm.getEntity(jobId, JobInfoElement.class); } catch (Exception e) { logger.error("Failed to get job results from database: ", e); response = new JobStatusResponse( new CloudServiceException(HttpURLConnection.HTTP_INTERNAL_ERROR, e.getMessage())); return response; } if (jInfo == null) { String msg = "Job not found: " + jobId; logger.error(msg); response = new JobStatusResponse(new CloudServiceException(HttpURLConnection.HTTP_NOT_FOUND, msg)); return response; } else { response = new JobStatusResponse(); response.setMessage("Returning status for job: " + jobId); response.setStatus(jInfo.getStatus()); return response; } }
From source file:com.netflix.genie.server.resources.CommandConfigResource.java
/** * Update the configuration files for a given command. * * @param id The id of the command to update the configuration files for. * Not null/empty/blank.//from ww w . j a va 2 s . c om * @param configs The configuration files to replace existing configuration * files with. Not null/empty/blank. * @return The new set of command configurations. * @throws GenieException For any error */ @PUT @Path("/{id}/configs") @Consumes(MediaType.APPLICATION_JSON) @ApiOperation(value = "Update configuration files for an command", notes = "Replace the existing configuration files for command with given id.", response = String.class, responseContainer = "List") @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 Set<String> updateConfigsForCommand( @ApiParam(value = "Id of the command to update configurations for.", required = true) @PathParam("id") final String id, @ApiParam(value = "The configuration files to replace existing with.", required = true) final Set<String> configs) throws GenieException { LOG.info("Called with id " + id + " and configs " + configs); return this.commandConfigService.updateConfigsForCommand(id, configs); }
From source file:i5.las2peer.services.gamificationLevelService.GamificationLevelService.java
/** * Get a level data with specific ID from database * @param appId applicationId// w w w .j a va 2s . c o m * @param levelNum level number * @return HttpResponse Returned as JSON object */ @GET @Path("/{appId}/{levelNum}") @Produces(MediaType.APPLICATION_JSON) @ApiResponses(value = { @ApiResponse(code = HttpURLConnection.HTTP_OK, message = "Found a level"), @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = "Internal Error"), @ApiResponse(code = HttpURLConnection.HTTP_UNAUTHORIZED, message = "Unauthorized") }) @ApiOperation(value = "getlevelWithNum", notes = "Get level details with specific level number", response = LevelModel.class) public HttpResponse getlevelWithNum(@ApiParam(value = "Application ID") @PathParam("appId") String appId, @ApiParam(value = "Level number") @PathParam("levelNum") int levelNum) { // Request log L2pLogger.logEvent(this, Event.SERVICE_CUSTOM_MESSAGE_99, "GET " + "gamification/levels/" + appId + "/" + levelNum); long randomLong = new Random().nextLong(); //To be able to match LevelModel level = null; Connection conn = null; JSONObject objResponse = new JSONObject(); UserAgent userAgent = (UserAgent) getContext().getMainAgent(); String name = userAgent.getLoginName(); if (name.equals("anonymous")) { return unauthorizedMessage(); } try { conn = dbm.getConnection(); try { L2pLogger.logEvent(Event.SERVICE_CUSTOM_MESSAGE_16, "" + randomLong); try { if (!levelAccess.isAppIdExist(conn, appId)) { objResponse.put("message", "Cannot fetched level. App not found"); L2pLogger.logEvent(this, Event.SERVICE_ERROR, (String) objResponse.get("message")); return new HttpResponse(objResponse.toJSONString(), HttpURLConnection.HTTP_BAD_REQUEST); } } catch (SQLException e1) { e1.printStackTrace(); objResponse.put("message", "Cannot fetched level. Cannot check whether application ID exist or not. Database error. " + e1.getMessage()); L2pLogger.logEvent(this, Event.SERVICE_ERROR, (String) objResponse.get("message")); return new HttpResponse(objResponse.toJSONString(), HttpURLConnection.HTTP_INTERNAL_ERROR); } if (!levelAccess.isLevelNumExist(conn, appId, levelNum)) { objResponse.put("message", "Cannot fetched level. level not found"); L2pLogger.logEvent(this, Event.SERVICE_ERROR, (String) objResponse.get("message")); return new HttpResponse(objResponse.toJSONString(), HttpURLConnection.HTTP_BAD_REQUEST); } level = levelAccess.getLevelWithNumber(conn, appId, levelNum); if (level != null) { ObjectMapper objectMapper = new ObjectMapper(); //Set pretty printing of json objectMapper.enable(SerializationFeature.INDENT_OUTPUT); String levelString = objectMapper.writeValueAsString(level); L2pLogger.logEvent(Event.SERVICE_CUSTOM_MESSAGE_17, "" + randomLong); L2pLogger.logEvent(Event.SERVICE_CUSTOM_MESSAGE_26, "" + name); L2pLogger.logEvent(Event.SERVICE_CUSTOM_MESSAGE_27, "" + appId); return new HttpResponse(levelString, HttpURLConnection.HTTP_OK); } else { objResponse.put("message", "Cannot fetched level. Cannot find level with " + levelNum); L2pLogger.logEvent(this, Event.SERVICE_ERROR, (String) objResponse.get("message")); return new HttpResponse(objResponse.toJSONString(), HttpURLConnection.HTTP_INTERNAL_ERROR); } } catch (SQLException e) { e.printStackTrace(); objResponse.put("message", "Cannot fetched level. DB Error. " + e.getMessage()); L2pLogger.logEvent(this, Event.SERVICE_ERROR, (String) objResponse.get("message")); return new HttpResponse(objResponse.toJSONString(), HttpURLConnection.HTTP_BAD_REQUEST); } } catch (JsonProcessingException e) { e.printStackTrace(); objResponse.put("message", "Cannot fetched level. JSON processing error. " + e.getMessage()); L2pLogger.logEvent(this, Event.SERVICE_ERROR, (String) objResponse.get("message")); return new HttpResponse(e.getMessage(), HttpURLConnection.HTTP_INTERNAL_ERROR); } catch (SQLException e) { e.printStackTrace(); objResponse.put("message", "Cannot fetched level. DB Error. " + e.getMessage()); L2pLogger.logEvent(this, Event.SERVICE_ERROR, (String) objResponse.get("message")); return new HttpResponse(objResponse.toJSONString(), HttpURLConnection.HTTP_BAD_REQUEST); } // always close connections finally { try { conn.close(); } catch (SQLException e) { logger.printStackTrace(e); } } }
From source file:i5.las2peer.services.gamificationApplicationService.GamificationApplicationService.java
/** * Get an app data with specified ID/* www .j av a2s. co m*/ * @param appId applicationId * @return Application data in JSON */ @GET @Path("/data/{appId}") @Produces(MediaType.APPLICATION_JSON) @ApiOperation(value = "getApplicationDetails", notes = "Get an application data with specific ID") @ApiResponses(value = { @ApiResponse(code = HttpURLConnection.HTTP_OK, message = "Return application data with specific ID"), @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = "Method not found"), @ApiResponse(code = HttpURLConnection.HTTP_BAD_REQUEST, message = "App not found"), @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = "Cannot connect to database"), @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = "Database Error"), @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = "Failed to process JSON") }) public HttpResponse getApplicationDetails( @ApiParam(value = "Application ID", required = true) @PathParam("appId") String appId) { // Request log L2pLogger.logEvent(this, Event.SERVICE_CUSTOM_MESSAGE_99, "GET " + "gamification/applications/data/" + appId); JSONObject objResponse = new JSONObject(); Connection conn = null; UserAgent userAgent = (UserAgent) getContext().getMainAgent(); String name = userAgent.getLoginName(); if (name.equals("anonymous")) { return unauthorizedMessage(); } try { conn = dbm.getConnection(); if (!applicationAccess.isAppIdExist(conn, appId)) { objResponse.put("message", "Cannot get Application detail. App not found"); L2pLogger.logEvent(this, Event.SERVICE_ERROR, (String) objResponse.get("message")); return new HttpResponse(objResponse.toJSONString(), HttpURLConnection.HTTP_BAD_REQUEST); } // Add Member to App ApplicationModel app = applicationAccess.getApplicationWithId(conn, appId); ObjectMapper objectMapper = new ObjectMapper(); //Set pretty printing of json objectMapper.enable(SerializationFeature.INDENT_OUTPUT); String appString = objectMapper.writeValueAsString(app); return new HttpResponse(appString, HttpURLConnection.HTTP_OK); } catch (SQLException e) { e.printStackTrace(); objResponse.put("message", "Cannot get Application detail. Database Error. " + e.getMessage()); L2pLogger.logEvent(this, Event.SERVICE_ERROR, (String) objResponse.get("message")); return new HttpResponse(objResponse.toJSONString(), HttpURLConnection.HTTP_INTERNAL_ERROR); } catch (JsonProcessingException e) { e.printStackTrace(); objResponse.put("message", "Cannot get Application detail. Failed to process JSON. " + e.getMessage()); L2pLogger.logEvent(this, Event.SERVICE_ERROR, (String) objResponse.get("message")); return new HttpResponse(objResponse.toJSONString(), HttpURLConnection.HTTP_INTERNAL_ERROR); } // always close connections finally { try { conn.close(); } catch (SQLException e) { logger.printStackTrace(e); } } }
From source file:i5.las2peer.services.loadStoreGraphService.LoadStoreGraphService.java
/** * //from w w w . ja va 2s .c om * Returns the API documentation of all annotated resources for purposes of Swagger documentation. * * @return The resource's documentation * */ @GET @Path("/swagger.json") @Produces(MediaType.APPLICATION_JSON) public HttpResponse getSwaggerJSON() { Swagger swagger = new Reader(new Swagger()).read(this.getClass()); if (swagger == null) { return new HttpResponse("Swagger API declaration not available!", HttpURLConnection.HTTP_NOT_FOUND); } try { return new HttpResponse(Json.mapper().writeValueAsString(swagger), HttpURLConnection.HTTP_OK); } catch (JsonProcessingException e) { e.printStackTrace(); return new HttpResponse(e.getMessage(), HttpURLConnection.HTTP_INTERNAL_ERROR); } }