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.gamificationLevelService.GamificationLevelService.java
/** * Delete a level data with specified ID * @param appId applicationId/*from w ww .ja va 2 s .c o m*/ * @param levelNum levelNum * @return HttpResponse with the returnString */ @DELETE @Path("/{appId}/{levelNum}") @Produces(MediaType.APPLICATION_JSON) @ApiResponses(value = { @ApiResponse(code = HttpURLConnection.HTTP_OK, message = "Level Delete Success"), @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = "Level not found"), @ApiResponse(code = HttpURLConnection.HTTP_BAD_REQUEST, message = "Bad Request"), }) @ApiOperation(value = "deleteLevel", notes = "delete a level") public HttpResponse deleteLevel( @ApiParam(value = "Application ID to delete a level", required = true) @PathParam("appId") String appId, @ApiParam(value = "Level number that will be deleted", required = true) @PathParam("levelNum") int levelNum) { // Request log L2pLogger.logEvent(this, Event.SERVICE_CUSTOM_MESSAGE_99, "DELETE " + "gamification/levels/" + appId + "/" + levelNum); 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 (!levelAccess.isAppIdExist(conn, appId)) { objResponse.put("message", "Cannot delete 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 delete 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 delete level. Level not found"); L2pLogger.logEvent(this, Event.SERVICE_ERROR, (String) objResponse.get("message")); return new HttpResponse(objResponse.toJSONString(), HttpURLConnection.HTTP_BAD_REQUEST); } levelAccess.deleteLevel(conn, appId, levelNum); objResponse.put("message", "Level 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 level. Cannot delete level. " + 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.gamificationActionService.GamificationActionService.java
/** * Get a list of actions from database//from w w w . j a va2 s . com * @param appId applicationId * @param currentPage current cursor page * @param windowSize size of fetched data * @param searchPhrase search word * @return HttpResponse returned as JSON object */ @GET @Path("/{appId}") @Produces(MediaType.APPLICATION_JSON) @ApiResponses(value = { @ApiResponse(code = HttpURLConnection.HTTP_OK, message = "Found a list of actions"), @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = "Internal Error"), @ApiResponse(code = HttpURLConnection.HTTP_UNAUTHORIZED, message = "Unauthorized") }) @ApiOperation(value = "getActionList", notes = "Returns a list of actions", response = ActionModel.class, responseContainer = "List") public HttpResponse getActionList(@ApiParam(value = "Application ID") @PathParam("appId") String appId, @ApiParam(value = "Page number for retrieving data") @QueryParam("current") int currentPage, @ApiParam(value = "Number of data size") @QueryParam("rowCount") int windowSize, @ApiParam(value = "Search phrase parameter") @QueryParam("searchPhrase") String searchPhrase) { // Request log L2pLogger.logEvent(this, Event.SERVICE_CUSTOM_MESSAGE_99, "GET " + "gamification/actions/" + appId); List<ActionModel> achs = 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(); L2pLogger.logEvent(this, Event.AGENT_GET_STARTED, "Get Actions"); try { if (!actionAccess.isAppIdExist(conn, appId)) { objResponse.put("message", "Cannot get actions. 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 get actions. 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); } int offset = (currentPage - 1) * windowSize; int totalNum = actionAccess.getNumberOfActions(conn, appId); if (windowSize == -1) { offset = 0; windowSize = totalNum; } achs = actionAccess.getActionsWithOffsetAndSearchPhrase(conn, appId, offset, windowSize, searchPhrase); ObjectMapper objectMapper = new ObjectMapper(); //Set pretty printing of json objectMapper.enable(SerializationFeature.INDENT_OUTPUT); String actionString = objectMapper.writeValueAsString(achs); JSONArray actionArray = (JSONArray) JSONValue.parse(actionString); logger.info(actionArray.toJSONString()); objResponse.put("current", currentPage); objResponse.put("rowCount", windowSize); objResponse.put("rows", actionArray); objResponse.put("total", totalNum); L2pLogger.logEvent(Event.SERVICE_CUSTOM_MESSAGE_10, "Actions fetched" + " : " + appId + " : " + userAgent); L2pLogger.logEvent(this, Event.AGENT_GET_SUCCESS, "Actions fetched" + " : " + appId + " : " + userAgent); return new HttpResponse(objResponse.toJSONString(), HttpURLConnection.HTTP_OK); } catch (SQLException e) { e.printStackTrace(); // return HTTP Response on error objResponse.put("message", "Cannot get actions. 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 actions. JSON processing error. " + e.getMessage()); L2pLogger.logEvent(this, Event.SERVICE_ERROR, (String) objResponse.get("message")); return new HttpResponse(e.getMessage(), HttpURLConnection.HTTP_INTERNAL_ERROR); } // always close connections finally { try { conn.close(); } catch (SQLException e) { logger.printStackTrace(e); } } }
From source file:rapture.repo.VersionedRepo.java
@Override public RaptureQueryResult runNativeQuery(String repoType, List<String> queryParams) { throw RaptureExceptionFactory.create(HttpURLConnection.HTTP_INTERNAL_ERROR, ERROR_CANNOT_RUN); }
From source file:rapture.repo.VersionedRepo.java
@Override public RaptureNativeQueryResult runNativeQueryWithLimitAndBounds(String repoType, List<String> queryParams, int limit, int offset) { throw RaptureExceptionFactory.create(HttpURLConnection.HTTP_INTERNAL_ERROR, ERROR_CANNOT_RUN); }
From source file:i5.las2peer.services.gamificationBadgeService.GamificationBadgeService.java
/** * Get a badge data with specific ID from database * @param appId applicationId//ww w. j ava 2 s.com * @param badgeId badge id * @return HttpResponse returned as JSON object */ @GET @Path("/{appId}/{badgeId}") @Produces(MediaType.APPLICATION_JSON) @ApiResponses(value = { @ApiResponse(code = HttpURLConnection.HTTP_OK, message = "Found a badges"), @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = "Internal Error"), @ApiResponse(code = HttpURLConnection.HTTP_UNAUTHORIZED, message = "Unauthorized") }) @ApiOperation(value = "Find point for specific App ID and badge ID", notes = "Returns a badge", response = BadgeModel.class, responseContainer = "List", authorizations = @Authorization(value = "api_key")) public HttpResponse getBadgeWithId(@ApiParam(value = "Application ID") @PathParam("appId") String appId, @ApiParam(value = "Badge ID") @PathParam("badgeId") String badgeId) { // Request log L2pLogger.logEvent(this, Event.SERVICE_CUSTOM_MESSAGE_99, "GET " + "gamification/badges/" + appId + "/" + badgeId); long randomLong = new Random().nextLong(); //To be able to match BadgeModel badge = 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(); L2pLogger.logEvent(Event.SERVICE_CUSTOM_MESSAGE_16, "" + randomLong); try { if (!badgeAccess.isAppIdExist(conn, appId)) { objResponse.put("message", "Cannot get badge. 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 get badge. 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); } badge = badgeAccess.getBadgeWithId(conn, appId, badgeId); if (badge == null) { objResponse.put("message", "Cannot get badge. Badge model is null."); L2pLogger.logEvent(this, Event.SERVICE_ERROR, (String) objResponse.get("message")); return new HttpResponse(objResponse.toJSONString(), HttpURLConnection.HTTP_INTERNAL_ERROR); } ObjectMapper objectMapper = new ObjectMapper(); //Set pretty printing of json objectMapper.enable(SerializationFeature.INDENT_OUTPUT); String badgeString = objectMapper.writeValueAsString(badge); 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(badgeString, HttpURLConnection.HTTP_OK); } catch (JsonProcessingException e) { e.printStackTrace(); objResponse.put("message", "Cannot get badge. Cannot process JSON." + 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 get badge. 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.gamificationLevelService.GamificationLevelService.java
/** * Get a list of levels from database//from w w w .ja va 2 s .c o m * @param appId applicationId * @param currentPage current cursor page * @param windowSize size of fetched data * @param searchPhrase search word * @return HttpResponse Returned as JSON object */ @GET @Path("/{appId}") @Produces(MediaType.APPLICATION_JSON) @ApiResponses(value = { @ApiResponse(code = HttpURLConnection.HTTP_OK, message = "Found a list of levels"), @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = "Internal Error"), @ApiResponse(code = HttpURLConnection.HTTP_UNAUTHORIZED, message = "Unauthorized") }) @ApiOperation(value = "getLevelList", notes = "Returns a list of levels", response = LevelModel.class, responseContainer = "List") public HttpResponse getLevelList(@ApiParam(value = "Application ID to return") @PathParam("appId") String appId, @ApiParam(value = "Page number for retrieving data") @QueryParam("current") int currentPage, @ApiParam(value = "Number of data size") @QueryParam("rowCount") int windowSize, @ApiParam(value = "Search phrase parameter") @QueryParam("searchPhrase") String searchPhrase) { // Request log L2pLogger.logEvent(this, Event.SERVICE_CUSTOM_MESSAGE_99, "GET " + "gamification/levels/" + appId); List<LevelModel> model = 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(); L2pLogger.logEvent(this, Event.AGENT_GET_STARTED, "Get Levels"); try { if (!levelAccess.isAppIdExist(conn, appId)) { objResponse.put("message", "Cannot get levels. 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 get levels. 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); } int offset = (currentPage - 1) * windowSize; ObjectMapper objectMapper = new ObjectMapper(); //Set pretty printing of json objectMapper.enable(SerializationFeature.INDENT_OUTPUT); int totalNum = levelAccess.getNumberOfLevels(conn, appId); if (windowSize == -1) { offset = 0; windowSize = totalNum; } model = levelAccess.getLevelsWithOffsetAndSearchPhrase(conn, appId, offset, windowSize, searchPhrase); String modelString = objectMapper.writeValueAsString(model); JSONArray modelArray = (JSONArray) JSONValue.parse(modelString); logger.info(modelArray.toJSONString()); objResponse.put("current", currentPage); objResponse.put("rowCount", windowSize); objResponse.put("rows", modelArray); objResponse.put("total", totalNum); L2pLogger.logEvent(Event.SERVICE_CUSTOM_MESSAGE_30, "Levels fetched : " + appId + " : " + userAgent); L2pLogger.logEvent(this, Event.AGENT_GET_SUCCESS, "Levels fetched : " + appId + " : " + userAgent); return new HttpResponse(objResponse.toJSONString(), HttpURLConnection.HTTP_OK); } catch (SQLException e) { e.printStackTrace(); // return HTTP Response on error objResponse.put("message", "Cannot get levels. 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 levels. JSON processing 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.gamificationAchievementService.GamificationAchievementService.java
/** * Delete an achievement data with specified ID * @param appId applicationId/*w w w.ja va 2s .co m*/ * @param achievementId achievementId * @return HttpResponse returned as JSON object */ @DELETE @Path("/{appId}/{achievementId}") @Produces(MediaType.APPLICATION_JSON) @ApiResponses(value = { @ApiResponse(code = HttpURLConnection.HTTP_OK, message = "Achievement Delete Success"), @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = "Achievements not found"), @ApiResponse(code = HttpURLConnection.HTTP_BAD_REQUEST, message = "Bad Request"), }) @ApiOperation(value = "deleteAchievement", notes = "Delete an achievement") public HttpResponse deleteAchievement(@PathParam("appId") String appId, @PathParam("achievementId") String achievementId) { // Request log L2pLogger.logEvent(this, Event.SERVICE_CUSTOM_MESSAGE_99, "DELETE " + "gamification/achievements/" + appId + "/" + achievementId); long randomLong = new Random().nextLong(); //To be able to match 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(); L2pLogger.logEvent(Event.SERVICE_CUSTOM_MESSAGE_20, "" + randomLong); try { if (!achievementAccess.isAppIdExist(conn, appId)) { objResponse.put("message", "Cannot delete achievement. 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 achievement. 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 (!achievementAccess.isAchievementIdExist(conn, appId, achievementId)) { objResponse.put("message", "Cannot delete achievement. Achievement not found"); L2pLogger.logEvent(this, Event.SERVICE_ERROR, (String) objResponse.get("message")); return new HttpResponse(objResponse.toJSONString(), HttpURLConnection.HTTP_BAD_REQUEST); } achievementAccess.deleteAchievement(conn, appId, achievementId); objResponse.put("message", "Cannot delete achievement. Achievement 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 achievement. Cannot delete Achievement. " + 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.gamificationQuestService.GamificationQuestService.java
/** * Delete a quest data with specified ID * @param appId applicationId//from ww w. j ava 2s. c o m * @param questId questId * @return HttpResponse with the returnString */ @DELETE @Path("/{appId}/{questId}") @Produces(MediaType.APPLICATION_JSON) @ApiResponses(value = { @ApiResponse(code = HttpURLConnection.HTTP_OK, message = "quest Delete Success"), @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = "quest not found"), @ApiResponse(code = HttpURLConnection.HTTP_BAD_REQUEST, message = "Bad Request"), }) @ApiOperation(value = "deleteQuest", notes = "delete a quest") public HttpResponse deleteQuest(@PathParam("appId") String appId, @PathParam("questId") String questId) { // Request log L2pLogger.logEvent(this, Event.SERVICE_CUSTOM_MESSAGE_99, "DELETE" + "gamification/quests/" + appId + "/" + questId); 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 (!questAccess.isAppIdExist(conn, appId)) { objResponse.put("message", "Cannot delete quest. 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 quest. 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 (!questAccess.isQuestIdExist(conn, appId, questId)) { objResponse.put("message", "Cannot delete quest. Failed to delete the quest. Quest ID is not exist!"); L2pLogger.logEvent(this, Event.SERVICE_ERROR, (String) objResponse.get("message")); return new HttpResponse(objResponse.toJSONString(), HttpURLConnection.HTTP_BAD_REQUEST); } questAccess.deleteQuest(conn, appId, questId); objResponse.put("message", "quest 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 quest. 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:com.google.wave.api.AbstractRobot.java
/** * Processes the incoming HTTP request to obtain the capabilities.xml file. * * @param req the HTTP request.//from w w w . ja v a2s . c o m * @param resp the HTTP response. */ private void processCapabilities(HttpServletRequest req, HttpServletResponse resp) { StringBuilder xml = new StringBuilder(); xml.append("<?xml version=\"1.0\"?>\n"); xml.append("<w:robot xmlns:w=\"http://wave.google.com/extensions/robots/1.0\">\n"); xml.append(" <w:version>"); xml.append(version); xml.append("</w:version>\n"); xml.append(" <w:protocolversion>"); xml.append(PROTOCOL_VERSION); xml.append("</w:protocolversion>\n"); xml.append(" <w:capabilities>\n"); for (Entry<String, Capability> entry : capabilityMap.entrySet()) { xml.append(" <w:capability name=\"" + entry.getKey() + "\""); Capability capability = entry.getValue(); if (capability != null) { // Append context. if (capability.contexts().length != 0) { xml.append(" context=\""); boolean first = true; for (Context context : capability.contexts()) { if (first) { first = false; } else { xml.append(','); } xml.append(context.name()); } xml.append("\""); } // Append filter. if (capability.filter() != null && !capability.filter().isEmpty()) { xml.append(" filter=\""); xml.append(capability.filter()); xml.append("\""); } } xml.append("/>\n"); } xml.append(" </w:capabilities>\n"); if (!consumerData.keySet().isEmpty()) { xml.append(" <w:consumer_keys>\n"); for (ConsumerData consumerDataObj : consumerData.values()) { xml.append(" <w:consumer_key for=\"" + consumerDataObj.getRpcServerUrl() + "\">" + consumerDataObj.getConsumerKey() + "</w:consumer_key>\n"); } xml.append(" </w:consumer_keys>\n"); } xml.append("</w:robot>\n"); // Write the result into the output stream. resp.setContentType(XML_MIME_TYPE); resp.setCharacterEncoding(UTF_8); try { resp.getWriter().write(xml.toString()); } catch (IOException e) { resp.setStatus(HttpURLConnection.HTTP_INTERNAL_ERROR); return; } resp.setStatus(HttpURLConnection.HTTP_OK); }
From source file:i5.las2peer.services.gamificationApplicationService.GamificationApplicationService.java
/** * Add a member to the application/*from w w w . j a v a 2 s . c om*/ * @param appId applicationId * @param memberId memberId * @return HttpResponse status if the member is added */ @POST @Path("/data/{appId}/{memberId}") @Produces(MediaType.APPLICATION_JSON) @ApiResponses(value = { @ApiResponse(code = HttpURLConnection.HTTP_OK, message = "Member is Added"), @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_INTERNAL_ERROR, message = "Database error") }) @ApiOperation(value = "addMemberToApp", notes = "add a member to an app") public HttpResponse addMemberToApp( @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, "POST " + "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 add member to Application. App not found"); L2pLogger.logEvent(this, Event.SERVICE_ERROR, (String) objResponse.get("message")); return new HttpResponse(objResponse.toJSONString(), HttpURLConnection.HTTP_BAD_REQUEST); } try { applicationAccess.addMemberToApp(conn, appId, memberId); objResponse.put("success", memberId + " is added to " + appId); L2pLogger.logEvent(Event.SERVICE_CUSTOM_MESSAGE_3, "" + memberId); L2pLogger.logEvent(Event.SERVICE_CUSTOM_MESSAGE_4, "" + appId); return new HttpResponse(objResponse.toJSONString(), HttpURLConnection.HTTP_OK); } catch (SQLException e) { e.printStackTrace(); objResponse.put("message", "Cannot add member to 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 add member to 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); } } }