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:rapture.repo.VersionedRepo.java
public void visitFolderFromTree(String folder, RepoVisitor visitor, TreeObject ptObj) { TreeObject tObj = ptObj;/*from w ww .ja va2 s . co m*/ if (!folder.isEmpty()) { String[] parts = folder.split("/"); for (String p : parts) { if (tObj.getTrees().containsKey(p)) { tObj = objDb.getTree(tObj.getTrees().get(p)); } else { throw RaptureExceptionFactory.create(HttpURLConnection.HTTP_INTERNAL_ERROR, "Not found"); } } } // Now tObj is where we should be for (DocumentBagReference bagRef : tObj.getDocuments()) { DocumentBagObject dObj = objDb.getDocumentBag(bagRef.getBagRef()); for (Map.Entry<String, String> docEntries : dObj.getDocRefs().entrySet()) { if (!docEntries.getKey().isEmpty()) { visitor.visit(docEntries.getKey(), objDb.getDocument(docEntries.getValue()).getContent(), false); } } } for (Map.Entry<String, String> folderEntries : tObj.getTrees().entrySet()) { visitor.visit(folderEntries.getKey(), null, true); } }
From source file:i5.las2peer.services.gamificationAchievementService.GamificationAchievementService.java
/** * Get a list of achievements from database * @param appId applicationId//from w ww. j a va 2s . co m * @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 achievements"), @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = "Internal Error"), @ApiResponse(code = HttpURLConnection.HTTP_UNAUTHORIZED, message = "Unauthorized") }) @ApiOperation(value = "getAchievementList", notes = "Returns a list of achievements", response = AchievementModel.class, responseContainer = "List") public HttpResponse getAchievementList( @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/achievements/" + appId); List<AchievementModel> 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(); try { if (!achievementAccess.isAppIdExist(conn, appId)) { objResponse.put("message", "Cannot get achievements. 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 achievements. 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 = achievementAccess.getNumberOfAchievements(conn, appId); if (windowSize == -1) { offset = 0; windowSize = totalNum; } achs = achievementAccess.getAchievementsWithOffsetAndSearchPhrase(conn, appId, offset, windowSize, searchPhrase); ObjectMapper objectMapper = new ObjectMapper(); //Set pretty printing of json objectMapper.enable(SerializationFeature.INDENT_OUTPUT); String achievementString = objectMapper.writeValueAsString(achs); JSONArray achievementArray = (JSONArray) JSONValue.parse(achievementString); logger.info(achievementArray.toJSONString()); objResponse.put("current", currentPage); objResponse.put("rowCount", windowSize); objResponse.put("rows", achievementArray); objResponse.put("total", totalNum); return new HttpResponse(objResponse.toJSONString(), HttpURLConnection.HTTP_OK); } catch (SQLException e) { e.printStackTrace(); objResponse.put("message", "Cannot get achievements. Database error. " + e.getMessage()); // return HTTP Response on error 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 achievements. 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:com.google.wave.api.AbstractRobot.java
/** * Processes the incoming HTTP request to obtain robot's profile. * * @param req the HTTP request./*from w w w .ja v a2 s . co m*/ * @param resp the HTTP response. */ private void processProfile(HttpServletRequest req, HttpServletResponse resp) { ParticipantProfile profile = null; // Try to get custom profile. String proxiedName = req.getParameter(NAME_QUERY_PARAMETER_KEY); if (proxiedName != null) { profile = getCustomProfile(proxiedName); } // Set the default profile. if (profile == null) { profile = new ParticipantProfile(getRobotName(), getRobotAvatarUrl(), getRobotProfilePageUrl()); } // Write the result into the output stream. resp.setContentType(JSON_MIME_TYPE); resp.setCharacterEncoding(UTF_8); try { resp.getWriter().write(SERIALIZER.toJson(profile)); } catch (IOException e) { resp.setStatus(HttpURLConnection.HTTP_INTERNAL_ERROR); return; } resp.setStatus(HttpURLConnection.HTTP_OK); }
From source file:i5.las2peer.services.gamificationQuestService.GamificationQuestService.java
/** * Get a list of quests from database/* w w w .ja va 2s.c om*/ * @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 quests"), @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = "Internal Error"), @ApiResponse(code = HttpURLConnection.HTTP_UNAUTHORIZED, message = "Unauthorized") }) @ApiOperation(value = "getQuestList", notes = "Returns a list of quests", response = QuestModel.class, responseContainer = "List") public HttpResponse getQuestList(@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/quests/" + appId); List<QuestModel> qs = 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 (!questAccess.isAppIdExist(conn, appId)) { objResponse.put("message", "Cannot get quests. 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 quests. 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 = questAccess.getNumberOfQuests(conn, appId); if (windowSize == -1) { offset = 0; windowSize = totalNum; } qs = questAccess.getQuestsWithOffsetAndSearchPhrase(conn, appId, offset, windowSize, searchPhrase); ObjectMapper objectMapper = new ObjectMapper(); //Set pretty printing of json objectMapper.enable(SerializationFeature.INDENT_OUTPUT); String questString = objectMapper.writeValueAsString(qs); JSONArray questArray = (JSONArray) JSONValue.parse(questString); //logger.info(questArray.toJSONString()); for (int i = 0; i < qs.size(); i++) { JSONArray actionArray = listPairtoJSONArray(qs.get(i).getActionIds()); JSONObject questObject = (JSONObject) questArray.get(i); questObject.replace("actionIds", actionArray); questArray.set(i, questObject); } objResponse.put("current", currentPage); objResponse.put("rowCount", windowSize); objResponse.put("rows", questArray); objResponse.put("total", totalNum); L2pLogger.logEvent(Event.SERVICE_CUSTOM_MESSAGE_37, "Quests fetched" + " : " + appId + " : " + userAgent); L2pLogger.logEvent(this, Event.AGENT_GET_SUCCESS, "Quests 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 quests. 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 quests. JSON process error. " + e.getMessage()); L2pLogger.logEvent(this, Event.SERVICE_ERROR, (String) objResponse.get("message")); return new HttpResponse(e.getMessage(), HttpURLConnection.HTTP_INTERNAL_ERROR); } catch (IOException e) { e.printStackTrace(); objResponse.put("message", "Cannot get quests. IO Exception. " + 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 that contains the event bundle. * * @param req the HTTP request.// w w w . java 2 s . com * @param resp the HTTP response. */ private void processRpc(HttpServletRequest req, HttpServletResponse resp) { // Deserialize and process the incoming events. EventMessageBundle events = null; try { events = deserializeEvents(req); } catch (IOException e) { resp.setStatus(HttpURLConnection.HTTP_INTERNAL_ERROR); return; } // Append robot.notifyCapabilitiesHash operation before processing the // events. OperationQueue operationQueue = events.getWavelet().getOperationQueue(); operationQueue.appendOperation(OperationType.ROBOT_NOTIFY_CAPABILITIES_HASH, Parameter.of(ParamsProperty.CAPABILITIES_HASH, version)); // Call the robot event handlers. processEvents(events); // Serialize the operations. serializeOperations(operationQueue.getPendingOperations(), resp); operationQueue.clear(); }
From source file:i5.las2peer.services.gamificationApplicationService.GamificationApplicationService.java
/** * Validate member and add to the database as the new member if he/she is not registered yet * @return HttpResponse status if validation success */// w w w .j a va 2 s . c om @POST @Path("/validation") @Produces(MediaType.APPLICATION_JSON) @ApiOperation(value = "memberLoginValidation", notes = "Simple function to validate a member login.") @ApiResponses(value = { @ApiResponse(code = HttpURLConnection.HTTP_OK, message = "Member is registered"), @ApiResponse(code = HttpURLConnection.HTTP_UNAUTHORIZED, message = "Unauthorized"), @ApiResponse(code = HttpURLConnection.HTTP_BAD_REQUEST, message = "User data error to be retrieved"), @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = "Cannot connect to database"), @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = "User data error to be retrieved. Not JSON object") }) public HttpResponse memberLoginValidation() { // Request log L2pLogger.logEvent(this, Event.SERVICE_CUSTOM_MESSAGE_99, "POST " + "gamification/applications/validation"); JSONObject objResponse = new JSONObject(); MemberModel member; Connection conn = null; UserAgent userAgent = (UserAgent) getContext().getMainAgent(); // take username as default name String name = userAgent.getLoginName(); System.out.println("User name : " + name); if (name.equals("anonymous")) { return unauthorizedMessage(); } // try to fetch firstname/lastname from user data received from OpenID Serializable userData = userAgent.getUserData(); if (userData != null) { Object jsonUserData = JSONValue.parse(userData.toString()); if (jsonUserData instanceof JSONObject) { JSONObject obj = (JSONObject) jsonUserData; Object firstnameObj = obj.get("given_name"); Object lastnameObj = obj.get("family_name"); Object emailObj = obj.get("email"); String firstname, lastname, email; if (firstnameObj != null) { firstname = ((String) firstnameObj); } else { firstname = ""; } if (lastnameObj != null) { lastname = ((String) lastnameObj); } else { lastname = ""; } if (emailObj != null) { email = ((String) emailObj); } else { email = ""; } member = new MemberModel(name, firstname, lastname, email); //logger.info(member.getId()+" "+member.getFullName()+" "+member.getEmail()); try { conn = dbm.getConnection(); if (!applicationAccess.isMemberRegistered(conn, member.getId())) { applicationAccess.registerMember(conn, member); objResponse.put("message", "Welcome " + member.getId() + "!"); L2pLogger.logEvent(Event.SERVICE_CUSTOM_MESSAGE_7, "" + member.getId()); return new HttpResponse(objResponse.toJSONString(), HttpURLConnection.HTTP_OK); } } catch (SQLException e) { e.printStackTrace(); objResponse.put("message", "Cannot validate member login. 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); } } } else { //logger.warning("Parsing user data failed! Got '" + jsonUserData.getClass().getName() + " instead of "+ JSONObject.class.getName() + " expected!"); objResponse.put("message", "Cannot validate member login. User data error to be retrieved. Not JSON object."); L2pLogger.logEvent(this, Event.SERVICE_ERROR, (String) objResponse.get("message")); return new HttpResponse(objResponse.toJSONString(), HttpURLConnection.HTTP_INTERNAL_ERROR); } objResponse.put("message", "Member already registered"); L2pLogger.logEvent(Event.SERVICE_CUSTOM_MESSAGE_8, "" + member.getId()); return new HttpResponse(objResponse.toJSONString(), HttpURLConnection.HTTP_OK); } else { objResponse.put("message", "Cannot validate member login. User data error to be retrieved."); L2pLogger.logEvent(this, Event.SERVICE_ERROR, (String) objResponse.get("message")); return new HttpResponse(objResponse.toJSONString(), HttpURLConnection.HTTP_BAD_REQUEST); } }
From source file:i5.las2peer.services.gamificationBadgeService.GamificationBadgeService.java
/** * Delete a badge data with specified ID * @param appId application id/*from w w w .j a va 2 s . co m*/ * @param badgeId badge id * @return HttpResponse returned as JSON object */ @DELETE @Path("/{appId}/{badgeId}") @Produces(MediaType.APPLICATION_JSON) @ApiResponses(value = { @ApiResponse(code = HttpURLConnection.HTTP_OK, message = "Badge Delete Success"), @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = "Badges not found"), @ApiResponse(code = HttpURLConnection.HTTP_BAD_REQUEST, message = "Bad Request"), }) @ApiOperation(value = "", notes = "delete a badge") public HttpResponse deleteBadge(@PathParam("appId") String appId, @PathParam("badgeId") String badgeId) { // Request log L2pLogger.logEvent(this, Event.SERVICE_CUSTOM_MESSAGE_99, "DELETE " + "gamification/badges/" + appId + "/" + badgeId); 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 (!badgeAccess.isAppIdExist(conn, appId)) { objResponse.put("message", "Cannot delete 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 delete 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); } if (!badgeAccess.isBadgeIdExist(conn, appId, badgeId)) { logger.info("Badge not found >> "); objResponse.put("message", "Cannot delete badge. Badge not found"); L2pLogger.logEvent(this, Event.SERVICE_ERROR, (String) objResponse.get("message")); return new HttpResponse(objResponse.toJSONString(), HttpURLConnection.HTTP_BAD_REQUEST); } badgeAccess.deleteBadge(conn, appId, badgeId); if (!LocalFileManager.deleteFile(LocalFileManager.getBasedir() + "/" + appId + "/" + badgeId)) { logger.info("Delete File Failed >> "); objResponse.put("message", "Cannot delete badge. Delete File Failed"); L2pLogger.logEvent(this, Event.SERVICE_ERROR, (String) objResponse.get("message")); return new HttpResponse(objResponse.toJSONString(), HttpURLConnection.HTTP_INTERNAL_ERROR); } objResponse.put("message", "File 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 badge. Cannot delete file. " + e.getMessage()); L2pLogger.logEvent(this, Event.SERVICE_ERROR, (String) objResponse.get("message")); return new HttpResponse(objResponse.toJSONString(), HttpURLConnection.HTTP_OK); } }
From source file:rapture.repo.VersionedRepo.java
@Override public List<DocumentVersionInfo> getVersionHistory(String key) { throw RaptureExceptionFactory.create(HttpURLConnection.HTTP_INTERNAL_ERROR, Messages.getString("BaseSimpleRepo.notsupp")); //$NON-NLS-1$ }
From source file:i5.las2peer.services.gamificationBadgeService.GamificationBadgeService.java
/** * Get a list of badges from database//w w w. ja v a 2 s. c o m * @param appId application id * @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_INTERNAL_ERROR, message = "Internal Error"), @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = "Badge not found"), @ApiResponse(code = HttpURLConnection.HTTP_UNAUTHORIZED, message = "Unauthorized") }) @ApiOperation(value = "Find badges for specific App ID", notes = "Returns a list of badges", response = BadgeModel.class, responseContainer = "List", authorizations = @Authorization(value = "api_key")) public HttpResponse getBadgeList( @ApiParam(value = "Application ID that contains badges", required = true) @PathParam("appId") String appId, @ApiParam(value = "Page number cursor for retrieving data") @QueryParam("current") int currentPage, @ApiParam(value = "Number of data size per fetch") @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/badges/" + appId); List<BadgeModel> badges = 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 Badges"); try { if (!badgeAccess.isAppIdExist(conn, appId)) { objResponse.put("message", "Cannot get badges. 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(); logger.info( "Cannot check whether application ID exist or not. Database error. >> " + e1.getMessage()); objResponse.put("message", "Cannot get badges. 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); } // Check app id exist or not int offset = (currentPage - 1) * windowSize; int totalNum = badgeAccess.getNumberOfBadges(conn, appId); if (windowSize == -1) { offset = 0; windowSize = totalNum; } badges = badgeAccess.getBadgesWithOffsetAndSearchPhrase(conn, appId, offset, windowSize, searchPhrase); ObjectMapper objectMapper = new ObjectMapper(); //Set pretty printing of json objectMapper.enable(SerializationFeature.INDENT_OUTPUT); String badgeString = objectMapper.writeValueAsString(badges); JSONArray badgeArray = (JSONArray) JSONValue.parse(badgeString); objResponse.put("current", currentPage); objResponse.put("rowCount", windowSize); objResponse.put("rows", badgeArray); objResponse.put("total", totalNum); logger.info(objResponse.toJSONString()); L2pLogger.logEvent(Event.SERVICE_CUSTOM_MESSAGE_24, "Badges fetched" + " : " + appId + " : " + userAgent); L2pLogger.logEvent(this, Event.AGENT_GET_SUCCESS, "Badges fetched" + " : " + appId + " : " + userAgent); return new HttpResponse(objResponse.toJSONString(), HttpURLConnection.HTTP_OK); } catch (SQLException e) { e.printStackTrace(); objResponse.put("message", "Cannot get badges. Internal Error. Database connection failed. " + 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 badges. Cannot connect to database. " + 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:org.eclipse.orion.server.tests.servlets.git.GitCloneTest.java
@Test public void testCloneAlreadyExists() throws Exception { URI workspaceLocation = createWorkspace(getMethodName()); String workspaceId = workspaceIdFromLocation(workspaceLocation); JSONObject project = createProjectOrLink(workspaceLocation, getMethodName(), null); clone(workspaceId, project);/* w w w. ja va 2s .co m*/ // clone again into the same path IPath clonePath = getClonePath(workspaceId, project); WebRequest request = getPostGitCloneRequest(new URIish(gitDir.toURI().toURL()).toString(), clonePath); WebResponse response = webConversation.getResponse(request); ServerStatus status = waitForTask(response); assertEquals(HttpURLConnection.HTTP_INTERNAL_ERROR, status.getHttpCode()); assertEquals("Error cloning git repository", status.getMessage()); assertTrue(status.toString(), status.getException().getMessage().contains("not an empty directory")); // no project should be created request = new GetMethodWebRequest(workspaceLocation.toString()); setAuthentication(request); response = webConversation.getResponse(request); JSONObject workspace = new JSONObject(response.getText()); assertEquals(1, workspace.getJSONArray(ProtocolConstants.KEY_CHILDREN).length()); }