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:i5.las2peer.services.gamificationApplicationService.GamificationApplicationService.java
/** * Get all application list separated into two categories. All apps registered for the member and other apps. * //from w w w . j a v a2s. c o m * * @return HttpResponse with the returnString */ @GET @Path("/list/separated") @Produces(MediaType.APPLICATION_JSON) @ApiOperation(value = "getSeparateApplicationInfo", notes = "Get all application list separated into two categories. All apps registered for the member and other apps.") @ApiResponses(value = { @ApiResponse(code = HttpURLConnection.HTTP_OK, message = "List of apps"), @ApiResponse(code = HttpURLConnection.HTTP_UNAUTHORIZED, message = "Unauthorized"), @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = "Database error"), @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = "JsonProcessingException") }) public HttpResponse getSeparateApplicationInfo() { // Request log L2pLogger.logEvent(this, Event.SERVICE_CUSTOM_MESSAGE_99, "GET " + "gamification/applications/list/separated"); JSONObject objResponse = new JSONObject(); Connection conn = null; UserAgent userAgent = (UserAgent) getContext().getMainAgent(); String name = userAgent.getLoginName(); if (name.equals("anonymous")) { return unauthorizedMessage(); } ObjectMapper objectMapper = new ObjectMapper(); //Set pretty printing of json objectMapper.enable(SerializationFeature.INDENT_OUTPUT); try { conn = dbm.getConnection(); List<List<ApplicationModel>> allApps = applicationAccess.getSeparateApplicationsWithMemberId(conn, name); try { String response = objectMapper.writeValueAsString(allApps); allApps.clear(); L2pLogger.logEvent(Event.SERVICE_CUSTOM_MESSAGE_11, "" + name); return new HttpResponse(response, HttpURLConnection.HTTP_OK); } catch (JsonProcessingException e) { e.printStackTrace(); allApps.clear(); // return HTTP Response on error objResponse.put("message", "Cannot delete Application. JsonProcessingException." + e.getMessage()); 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", "Database error"); 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:com.netflix.genie.server.resources.ClusterConfigResource.java
/** * Delete the all tags from a given cluster. * * @param id The id of the cluster to delete the tags from. * Not null/empty/blank.//from w w w .j a va2 s . c o m * @return Empty set if successful * @throws GenieException For any error */ @DELETE @Path("/{id}/tags") @ApiOperation(value = "Remove all tags from a cluster", notes = "Remove all the tags from the cluster with given id. Note that the genie name space tags" + "prefixed with genie.id and genie.name cannot be deleted.", 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> removeAllTagsForCluster( @ApiParam(value = "Id of the cluster to delete from.", required = true) @PathParam("id") final String id) throws GenieException { LOG.info("Called with id " + id); return this.clusterConfigService.removeAllTagsForCluster(id); }
From source file:i5.las2peer.services.servicePackage.TemplateService.java
@GET @Path("/users") @Produces(MediaType.APPLICATION_JSON)/* w ww . j a v a 2 s.co m*/ public HttpResponse getUsers() { Connection conn = null; PreparedStatement stmnt = null; ResultSet rs = null; ToJSON converter = new ToJSON(); JSONArray json = new JSONArray(); try { // get connection from connection pool conn = dbm.getConnection(); // prepare statement stmnt = conn.prepareStatement("SELECT author FROM urch group by author;"); // retrieve result set rs = stmnt.executeQuery(); json = converter.toJSONArray(rs); return new HttpResponse(json.toString(), 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.resources.ApplicationConfigResource.java
/** * Get all the commands this application is associated with. * * @param id The id of the application to get the commands for. Not * NULL/empty/blank.//from w w w .j a v a 2s .co m * @param statuses The various statuses of the commands to retrieve * @return The set of commands. * @throws GenieException For any error */ @GET @Path("/{id}/commands") @ApiOperation(value = "Get the commands this application is associated with", notes = "Get the commands which this application supports.", response = Command.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 List<Command> getCommandsForApplication( @ApiParam(value = "Id of the application to get the commands for.", required = true) @PathParam("id") final String id, @ApiParam(value = "The statuses of the commands to find.", allowableValues = "ACTIVE, DEPRECATED, INACTIVE") @QueryParam("status") final Set<String> statuses) throws GenieException { LOG.info("Called with id " + id); Set<CommandStatus> enumStatuses = null; if (!statuses.isEmpty()) { enumStatuses = EnumSet.noneOf(CommandStatus.class); for (final String status : statuses) { if (StringUtils.isNotBlank(status)) { enumStatuses.add(CommandStatus.parse(status)); } } } return this.applicationConfigService.getCommandsForApplication(id, enumStatuses); }
From source file:com.netflix.genie.server.resources.CommandConfigResource.java
/** * Remove an tag from a given command.//from w ww . j av a 2 s . co m * * @param id The id of the command to delete the tag from. Not * null/empty/blank. * @param tag The tag to remove. Not null/empty/blank. * @return The active set of tags for the command. * @throws GenieException For any error */ @DELETE @Path("/{id}/tags/{tag}") @ApiOperation(value = "Remove a tag from a command", notes = "Remove the given tag from the command with given id. Note that the genie name space tags" + "prefixed with genie.id and genie.name cannot be deleted.", 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> removeTagForCommand( @ApiParam(value = "Id of the command to delete from.", required = true) @PathParam("id") final String id, @ApiParam(value = "The tag to remove.", required = true) @PathParam("tag") final String tag) throws GenieException { LOG.info("Called with id " + id + " and tag " + tag); return this.commandConfigService.removeTagForCommand(id, tag); }
From source file:com.netflix.genie.server.resources.ClusterConfigResource.java
/** * Remove an tag from a given cluster./*from www.j a v a 2 s .co m*/ * * @param id The id of the cluster to delete the tag from. Not * null/empty/blank. * @param tag The tag to remove. Not null/empty/blank. * @return The active set of tags for the cluster. * @throws GenieException For any error */ @DELETE @Path("/{id}/tags/{tag}") @ApiOperation(value = "Remove a tag from a cluster", notes = "Remove the given tag from the cluster with given id. Note that the genie name space tags" + "prefixed with genie.id and genie.name cannot be deleted.", 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> removeTagForCluster( @ApiParam(value = "Id of the cluster to delete from.", required = true) @PathParam("id") final String id, @ApiParam(value = "The tag to remove.", required = true) @PathParam("tag") final String tag) throws GenieException { LOG.info("Called with id " + id + " and tag " + tag); return this.clusterConfigService.removeTagForCluster(id, tag); }
From source file:com.netflix.genie.server.resources.ApplicationConfigResource.java
/** * Remove an tag from a given application. * * @param id The id of the application to delete the tag from. Not * null/empty/blank./* w ww. j a v a 2 s.c om*/ * @param tag The tag to remove. Not null/empty/blank. * @return The active set of tags for the application. * @throws GenieException For any error */ @DELETE @Path("/{id}/tags/{tag}") @ApiOperation(value = "Remove a tag from a application", notes = "Remove the given tag from the application with given id. Note that the genie name space tags" + "prefixed with genie.id and genie.name cannot be deleted.", 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> removeTagForApplication( @ApiParam(value = "Id of the application to delete from.", required = true) @PathParam("id") final String id, @ApiParam(value = "The tag to remove.", required = true) @PathParam("tag") final String tag) throws GenieException { LOG.info("Called with id " + id + " and tag " + tag); return this.applicationConfigService.removeTagForApplication(id, tag); }
From source file:i5.las2peer.services.gamificationActionService.GamificationActionService.java
/** * Delete an action data with specified ID * @param appId applicationId// ww w . ja va2 s . c o m * @param actionId actionId * @return HttpResponse returned as JSON object */ @DELETE @Path("/{appId}/{actionId}") @Produces(MediaType.APPLICATION_JSON) @ApiResponses(value = { @ApiResponse(code = HttpURLConnection.HTTP_OK, message = "Action is deleted"), @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = "Action not found"), @ApiResponse(code = HttpURLConnection.HTTP_BAD_REQUEST, message = "Bad Request"), }) @ApiOperation(value = "", notes = "delete an action") public HttpResponse deleteAction(@PathParam("appId") String appId, @PathParam("actionId") String actionId) { // Request log L2pLogger.logEvent(this, Event.SERVICE_CUSTOM_MESSAGE_99, "DELETE " + "gamification/actions/" + appId + "/" + actionId); long randomLong = new Random().nextLong(); //To be able to match 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(); L2pLogger.logEvent(Event.SERVICE_CUSTOM_MESSAGE_20, "" + randomLong); try { if (!actionAccess.isAppIdExist(conn, appId)) { objResponse.put("message", "Cannot delete action. 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 delete action. 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 (!actionAccess.isActionIdExist(conn, appId, actionId)) { objResponse.put("message", "Cannot delete action. Failed to delete the action. Action ID is not exist!"); L2pLogger.logEvent(this, Event.SERVICE_ERROR, (String) objResponse.get("message")); return new HttpResponse(objResponse.toJSONString(), HttpURLConnection.HTTP_BAD_REQUEST); } actionAccess.deleteAction(conn, appId, actionId); objResponse.put("message", "Action deleted"); L2pLogger.logEvent(Event.SERVICE_CUSTOM_MESSAGE_21, "" + randomLong); L2pLogger.logEvent(Event.SERVICE_CUSTOM_MESSAGE_30, "" + name); L2pLogger.logEvent(Event.SERVICE_CUSTOM_MESSAGE_31, "" + appId); return new HttpResponse(objResponse.toJSONString(), HttpURLConnection.HTTP_OK); } catch (SQLException e) { e.printStackTrace(); objResponse.put("message", "Cannot delete action. Database error. " + 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.gamificationApplicationService.GamificationApplicationService.java
/** * Remove a member from the application/* w w w . j a v a 2s . c o m*/ * @param appId applicationId * @param memberId memberId * @return HttpResponse status if a member is removed */ @DELETE @Path("/data/{appId}/{memberId}") @Produces(MediaType.APPLICATION_JSON) @ApiOperation(value = "removeMemberFromApp", notes = "delete a member from an app") @ApiResponses(value = { @ApiResponse(code = HttpURLConnection.HTTP_OK, message = "Member is removed from app"), @ApiResponse(code = HttpURLConnection.HTTP_BAD_REQUEST, message = "App not found"), @ApiResponse(code = HttpURLConnection.HTTP_BAD_REQUEST, message = "Error checking app ID exist"), @ApiResponse(code = HttpURLConnection.HTTP_BAD_REQUEST, message = "No member found"), @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = "Database error") }) public HttpResponse removeMemberFromApp( @ApiParam(value = "Application ID", required = true) @PathParam("appId") String appId, @ApiParam(value = "Member ID", required = true) @PathParam("memberId") String memberId) { // Request log L2pLogger.logEvent(this, Event.SERVICE_CUSTOM_MESSAGE_99, "DELETE " + "gamification/applications/data/" + appId + "/" + memberId); 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 remove member from Application. App not found"); L2pLogger.logEvent(this, Event.SERVICE_ERROR, (String) objResponse.get("message")); return new HttpResponse(objResponse.toJSONString(), HttpURLConnection.HTTP_BAD_REQUEST); } try { if (!applicationAccess.isMemberRegistered(conn, memberId)) { objResponse.put("message", "Cannot remove member from Application. No member found"); L2pLogger.logEvent(this, Event.SERVICE_ERROR, (String) objResponse.get("message")); return new HttpResponse(objResponse.toJSONString(), HttpURLConnection.HTTP_BAD_REQUEST); } applicationAccess.removeMemberFromApp(conn, memberId, appId); objResponse.put("message", memberId + "is removed from " + appId); L2pLogger.logEvent(Event.SERVICE_CUSTOM_MESSAGE_5, "" + memberId); L2pLogger.logEvent(Event.SERVICE_CUSTOM_MESSAGE_6, "" + appId); return new HttpResponse(objResponse.toJSONString(), HttpURLConnection.HTTP_OK); } catch (SQLException e) { e.printStackTrace(); objResponse.put("message", "Cannot remove member from Application. Database error. " + e.getMessage()); 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 remove member from Application. Error checking app ID exist " + 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:com.google.wave.api.AbstractRobot.java
/** * Processes the incoming HTTP request to obtain the verification token. * * @param req the HTTP request.// w ww.j ava2s .co m * @param resp the HTTP response. */ private void processVerifyToken(HttpServletRequest req, HttpServletResponse resp) { if (verificationToken == null || verificationToken.isEmpty()) { LOG.info("Please register a verification token by calling " + "AbstractRobot.setVerificationToken()."); resp.setStatus(HttpURLConnection.HTTP_INTERNAL_ERROR); return; } String incomingSecurityToken = req.getParameter(SECURITY_TOKEN_PARAMETER_KEY); if (securityToken != null && !securityToken.equals(incomingSecurityToken)) { LOG.info("The incoming security token " + incomingSecurityToken + " does not match the " + "expected security token " + securityToken + "."); resp.setStatus(HttpURLConnection.HTTP_UNAUTHORIZED); return; } resp.setContentType(TEXT_MIME_TYPE); resp.setCharacterEncoding(UTF_8); try { resp.getWriter().write(verificationToken); } catch (IOException e) { resp.setStatus(HttpURLConnection.HTTP_INTERNAL_ERROR); return; } resp.setStatus(HttpURLConnection.HTTP_OK); }