List of usage examples for java.net HttpURLConnection HTTP_BAD_REQUEST
int HTTP_BAD_REQUEST
To view the source code for java.net HttpURLConnection HTTP_BAD_REQUEST.
Click Source Link
From source file:rapture.kernel.StructuredApiImpl.java
private void validateCursorCount(int count) { if (!validator.isCursorCountValid(count)) { throw RaptureExceptionFactory.create(HttpURLConnection.HTTP_BAD_REQUEST, "Cursor count must be greater than 0"); }//from ww w .j a v a 2s . c o m }
From source file:i5.las2peer.services.gamificationLevelService.GamificationLevelService.java
/** * Update a level//from w w w. java 2 s .c o m * @param appId applicationId * @param levelNum levelNum * @param formData form data * @param contentType content type * @return HttpResponse with the returnString */ @PUT @Path("/{appId}/{levelNum}") @Produces(MediaType.APPLICATION_JSON) @ApiResponses(value = { @ApiResponse(code = HttpURLConnection.HTTP_OK, message = "Level Updated"), @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = "Error occured"), @ApiResponse(code = HttpURLConnection.HTTP_BAD_REQUEST, message = "Bad request"), @ApiResponse(code = HttpURLConnection.HTTP_UNAUTHORIZED, message = "Unauthorized") }) @ApiOperation(value = "updateLevel", notes = "A method to update an level with details (Level number, level name, level point value, level point id)") public HttpResponse updateLevel( @ApiParam(value = "Application ID to store a new level", required = true) @PathParam("appId") String appId, @PathParam("levelNum") int levelNum, @ApiParam(value = "Content type in header", required = true) @HeaderParam(value = HttpHeaders.CONTENT_TYPE) String contentType, @ApiParam(value = "Level detail in multiple/form-data type", required = true) @ContentParam byte[] formData) { // Request log L2pLogger.logEvent(this, Event.SERVICE_CUSTOM_MESSAGE_99, "PUT " + "gamification/levels/" + appId + "/" + levelNum); long randomLong = new Random().nextLong(); //To be able to match // parse given multipart form data JSONObject objResponse = new JSONObject(); String levelname = null; int levelpointvalue = 0; //boolean levelnotifcheck = false; String levelnotifmessage = null; Connection conn = null; 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_18, "" + randomLong); try { if (!levelAccess.isAppIdExist(conn, appId)) { objResponse.put("message", "Cannot update 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 update 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 update level. Level not found"); L2pLogger.logEvent(this, Event.SERVICE_ERROR, (String) objResponse.get("message")); return new HttpResponse(objResponse.toJSONString(), HttpURLConnection.HTTP_BAD_REQUEST); } Map<String, FormDataPart> parts = MultipartHelper.getParts(formData, contentType); if (levelNum == 0) { objResponse.put("message", "Cannot update level. Level ID cannot be null"); L2pLogger.logEvent(this, Event.SERVICE_ERROR, (String) objResponse.get("message")); return new HttpResponse(objResponse.toJSONString(), HttpURLConnection.HTTP_BAD_REQUEST); } LevelModel model = levelAccess.getLevelWithNumber(conn, appId, levelNum); if (model != null) { FormDataPart partName = parts.get("levelname"); if (partName != null) { levelname = partName.getContent(); if (levelname != null) { model.setName(levelname); } } FormDataPart partPV = parts.get("levelpointvalue"); if (partPV != null) { // optional description text input form element levelpointvalue = Integer.parseInt(partPV.getContent()); if (levelpointvalue != 0) { model.setPointValue(levelpointvalue); } } FormDataPart partNotificationCheck = parts.get("levelnotificationcheck"); if (partNotificationCheck != null) { // checkbox is checked model.useNotification(true); } else { model.useNotification(false); } FormDataPart partNotificationMsg = parts.get("levelnotificationmessage"); if (partNotificationMsg != null) { levelnotifmessage = partNotificationMsg.getContent(); if (levelnotifmessage != null) { model.setNotificationMessage(levelnotifmessage); } } try { levelAccess.updateLevel(conn, appId, model); objResponse.put("message", "Level updated"); L2pLogger.logEvent(Event.SERVICE_CUSTOM_MESSAGE_19, "" + randomLong); L2pLogger.logEvent(Event.SERVICE_CUSTOM_MESSAGE_28, "" + name); L2pLogger.logEvent(Event.SERVICE_CUSTOM_MESSAGE_29, "" + appId); return new HttpResponse(objResponse.toJSONString(), HttpURLConnection.HTTP_OK); } catch (SQLException e) { e.printStackTrace(); objResponse.put("message", "Cannot update level. 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); } } else { // model is null objResponse.put("message", "Cannot update level. Level not found in database"); 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 update level. DB Error " + e1.getMessage()); L2pLogger.logEvent(this, Event.SERVICE_ERROR, (String) objResponse.get("message")); return new HttpResponse(objResponse.toJSONString(), HttpURLConnection.HTTP_INTERNAL_ERROR); } } catch (MalformedStreamException e) { // the stream failed to follow required syntax objResponse.put("message", "Cannot update level. Failed to upload " + levelNum + ". " + e.getMessage()); L2pLogger.logEvent(this, Event.SERVICE_ERROR, (String) objResponse.get("message")); return new HttpResponse(objResponse.toJSONString(), HttpURLConnection.HTTP_BAD_REQUEST); } catch (IOException e) { // a read or write error occurred objResponse.put("message", "Cannot update level. Failed to upload " + levelNum + ". " + e.getMessage()); L2pLogger.logEvent(this, Event.SERVICE_ERROR, (String) objResponse.get("message")); return new HttpResponse(objResponse.toJSONString(), HttpURLConnection.HTTP_INTERNAL_ERROR); } catch (SQLException e1) { e1.printStackTrace(); objResponse.put("message", "Cannot update level. DB Error " + e1.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.netflix.genie.server.services.impl.GenieExecutionServiceImpl.java
private void validateJobParams(JobInfoElement jobInfo) throws CloudServiceException { logger.debug("called"); if (jobInfo == null) { String msg = "Missing jobInfo object"; logger.error(msg);/*from w w w . j a va2s .c o m*/ throw new CloudServiceException(HttpURLConnection.HTTP_BAD_REQUEST, msg); } // check if userName is valid validateNameValuePair("userName", jobInfo.getUserName()); // check if cmdArgs is valid validateNameValuePair("cmdArgs", jobInfo.getCmdArgs()); // check if jobType is valid validateNameValuePair("jobType", jobInfo.getJobType()); // check if Hive Params include "-e" or "-f" if (Types.JobType.parse(jobInfo.getJobType()) == Types.JobType.HIVE) { validateNameValuePair("hiveArgs", jobInfo.getCmdArgs()); } // check if schedule is valid validateNameValuePair("schedule", jobInfo.getSchedule()); // check if configuration is valid for Hive/Pig if (Types.JobType.parse(jobInfo.getJobType()) != Types.JobType.HADOOP) { validateNameValuePair("configuration", jobInfo.getConfiguration()); } // generate job id, if need be if (jobInfo.getJobID() == null || jobInfo.getJobID().isEmpty()) { UUID uuid = UUID.randomUUID(); jobInfo.setJobID(uuid.toString()); } jobInfo.setJobStatus(JobStatus.INIT, "Initializing job"); }
From source file:rapture.kernel.DocApiImpl.java
@Override public String getDoc(CallingContext context, String docUri) { RaptureURI internalUri = new RaptureURI(docUri, Scheme.DOCUMENT); Repository repository = getRepoFromCache(internalUri.getAuthority()); if (repository == null) { throw RaptureExceptionFactory.create(HttpURLConnection.HTTP_BAD_REQUEST, apiMessageCatalog.getMessage("NoSuchRepo", internalUri.toAuthString())); //$NON-NLS-1$ }/*from w w w .ja v a 2s. co m*/ // check if they specified an attribute in the display name e.g. // order/1/$link/linkeddoc if (internalUri.hasAttribute()) { DocumentAttribute att = repository.getDocAttribute(internalUri); return (att == null) ? null : att.getValue(); } BaseDirective baseDirective = getDirective(internalUri, repository); return repository.getDocument(internalUri.getDocPath(), baseDirective); }
From source file:i5.las2peer.services.gamificationActionService.GamificationActionService.java
/** * Update an action//from w ww .j a va 2 s . c om * @param appId applicationId * @param actionId actionId * @param formData form data * @param contentType content type * @return HttpResponse returned as JSON object */ @PUT @Path("/{appId}/{actionId}") @Produces(MediaType.APPLICATION_JSON) @ApiResponses(value = { @ApiResponse(code = HttpURLConnection.HTTP_OK, message = "Action Updated"), @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = "Error occured"), @ApiResponse(code = HttpURLConnection.HTTP_BAD_REQUEST, message = "Bad request"), @ApiResponse(code = HttpURLConnection.HTTP_UNAUTHORIZED, message = "Unauthorized") }) @ApiOperation(value = "Update an action", notes = "A method to update an action with details (action ID, action name, action description, action point value") public HttpResponse updateAction( @ApiParam(value = "Application ID to store an updated action", required = true) @PathParam("appId") String appId, @PathParam("actionId") String actionId, @ApiParam(value = "action detail in multiple/form-data type", required = true) @HeaderParam(value = HttpHeaders.CONTENT_TYPE) String contentType, @ContentParam byte[] formData) { // Request log L2pLogger.logEvent(this, Event.SERVICE_CUSTOM_MESSAGE_99, "PUT " + "gamification/actions/" + appId + "/" + actionId); long randomLong = new Random().nextLong(); //To be able to match // parse given multipart form data JSONObject objResponse = new JSONObject(); logger.info(actionId); String actionname = null; String actiondesc = null; int actionpointvalue = 0; //boolean actionnotifcheck = false; String actionnotifmessage = null; 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_18, "" + randomLong); Map<String, FormDataPart> parts = MultipartHelper.getParts(formData, contentType); if (actionId == null) { logger.info("action ID cannot be null >> "); objResponse.put("message", "action ID cannot be null"); L2pLogger.logEvent(this, Event.SERVICE_ERROR, (String) objResponse.get("message")); return new HttpResponse(objResponse.toJSONString(), HttpURLConnection.HTTP_BAD_REQUEST); } try { if (!actionAccess.isAppIdExist(conn, appId)) { logger.info("App not found >> "); objResponse.put("message", "App not found"); L2pLogger.logEvent(this, Event.SERVICE_ERROR, (String) objResponse.get("message")); return new HttpResponse(objResponse.toJSONString(), HttpURLConnection.HTTP_BAD_REQUEST); } ActionModel action = actionAccess.getActionWithId(conn, appId, actionId); if (action == null) { // action is null logger.info("action not found in database >> "); objResponse.put("message", "action not found in database"); L2pLogger.logEvent(this, Event.SERVICE_ERROR, (String) objResponse.get("message")); return new HttpResponse(objResponse.toJSONString(), HttpURLConnection.HTTP_BAD_REQUEST); } FormDataPart partName = parts.get("actionname"); if (partName != null) { actionname = partName.getContent(); if (actionname != null) { action.setName(actionname); } } FormDataPart partDesc = parts.get("actiondesc"); if (partDesc != null) { // optional description text input form element actiondesc = partDesc.getContent(); if (actiondesc != null) { action.setDescription(actiondesc); } } FormDataPart partPV = parts.get("actionpointvalue"); if (partPV != null) { // optional description text input form element actionpointvalue = Integer.parseInt(partPV.getContent()); if (actionpointvalue != 0) { action.setPointValue(actionpointvalue); } } FormDataPart partNotificationCheck = parts.get("actionnotificationcheck"); if (partNotificationCheck != null) { // checkbox is checked action.useNotification(true); } else { action.useNotification(false); } FormDataPart partNotificationMsg = parts.get("actionnotificationmessage"); if (partNotificationMsg != null) { actionnotifmessage = partNotificationMsg.getContent(); if (actionnotifmessage == null) { action.setNotificationMessage(actionnotifmessage); } } actionAccess.updateAction(conn, appId, action); logger.info("action updated >> "); objResponse.put("message", "action updated"); L2pLogger.logEvent(Event.SERVICE_CUSTOM_MESSAGE_19, "" + randomLong); L2pLogger.logEvent(Event.SERVICE_CUSTOM_MESSAGE_28, "" + name); L2pLogger.logEvent(Event.SERVICE_CUSTOM_MESSAGE_29, "" + appId); return new HttpResponse(objResponse.toJSONString(), HttpURLConnection.HTTP_OK); } catch (SQLException e) { e.printStackTrace(); System.out.println(e.getMessage()); logger.info("SQLException >> " + e.getMessage()); objResponse.put("message", "Cannot connect to database"); L2pLogger.logEvent(this, Event.SERVICE_ERROR, (String) objResponse.get("message")); return new HttpResponse(objResponse.toJSONString(), HttpURLConnection.HTTP_INTERNAL_ERROR); } } catch (MalformedStreamException e) { // the stream failed to follow required syntax logger.log(Level.SEVERE, e.getMessage(), e); logger.info("MalformedStreamException >> "); objResponse.put("message", "Failed to upload " + actionId + ". " + e.getMessage()); L2pLogger.logEvent(this, Event.SERVICE_ERROR, (String) objResponse.get("message")); return new HttpResponse(objResponse.toJSONString(), HttpURLConnection.HTTP_BAD_REQUEST); } catch (IOException e) { // a read or write error occurred logger.log(Level.SEVERE, e.getMessage(), e); logger.info("IOException >> "); objResponse.put("message", "Failed to upload " + actionId + "."); L2pLogger.logEvent(this, Event.SERVICE_ERROR, (String) objResponse.get("message")); return new HttpResponse(objResponse.toJSONString(), HttpURLConnection.HTTP_INTERNAL_ERROR); } catch (SQLException e) { e.printStackTrace(); System.out.println(e.getMessage()); logger.info("SQLException >> " + e.getMessage()); objResponse.put("message", "Cannot connect to database"); 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.betaconceptframework.astroboa.resourceapi.resource.TaxonomyResource.java
private Response getTopicInTaxonomyInternal(String taxonomyIdOrName, String topicPathWithIdsOrSystemNames, Output output, String callback, boolean prettyPrint) { try {/*from w w w .j a va 2 s .co m*/ Topic topic = findTopicByTaxonomyIdOrNameAndTopicPathWithIdsOrNames(taxonomyIdOrName, topicPathWithIdsOrSystemNames); if (topic == null) { throw new WebApplicationException(HttpURLConnection.HTTP_NOT_FOUND); } // Lazy load topic children so they will be rendered in XML or JSON response topic.getChildren(); StringBuilder topicAsXMLOrJSON = new StringBuilder(); switch (output) { case XML: { if (StringUtils.isBlank(callback)) { topicAsXMLOrJSON.append(topic.xml(prettyPrint)); } else { ContentApiUtils.generateXMLP(topicAsXMLOrJSON, topic.xml(prettyPrint), callback); } break; } case JSON: if (StringUtils.isBlank(callback)) { topicAsXMLOrJSON.append(topic.json(prettyPrint)); } else { ContentApiUtils.generateXMLP(topicAsXMLOrJSON, topic.json(prettyPrint), callback); } break; } return ContentApiUtils.createResponse(topicAsXMLOrJSON, output, callback, null); } catch (Exception e) { logger.error("Taxonomy IdOrName: " + taxonomyIdOrName + ", Topic Path with Ids Or Names: " + topicPathWithIdsOrSystemNames, e); throw new WebApplicationException(HttpURLConnection.HTTP_BAD_REQUEST); } }
From source file:rapture.kernel.DocApiImpl.java
@Override public DocumentWithMeta getDocAndMeta(CallingContext context, String docUri) { RaptureURI internalUri = new RaptureURI(docUri, Scheme.DOCUMENT); Repository repository = getRepoFromCache(internalUri.getAuthority()); if (repository == null) { throw RaptureExceptionFactory.create(HttpURLConnection.HTTP_BAD_REQUEST, apiMessageCatalog.getMessage("NoSuchRepo", internalUri.toAuthString())); //$NON-NLS-1$ }/*from ww w . ja va 2 s . c o m*/ if (repository.hasMetaContent()) { BaseDirective directive = getDirective(internalUri, repository); return repository.getDocAndMeta(internalUri.getDocPath(), directive); } else { return constructDefaultDocumentWithMeta(getDoc(context, docUri), internalUri.getDocPath()); } }
From source file:org.eclipse.orion.server.tests.servlets.git.GitConfigTest.java
@Test public void testCreateInvalidConfigEntry() throws Exception { URI workspaceLocation = createWorkspace(getMethodName()); IPath[] clonePaths = createTestProjects(workspaceLocation); for (IPath clonePath : clonePaths) { // clone a repo String contentLocation = clone(clonePath).getString(ProtocolConstants.KEY_CONTENT_LOCATION); // get project metadata WebRequest request = getGetRequest(contentLocation); WebResponse response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); JSONObject project = new JSONObject(response.getText()); JSONObject gitSection = project.getJSONObject(GitConstants.KEY_GIT); String gitConfigUri = gitSection.getString(GitConstants.KEY_CONFIG); final String INVALID_ENTRY_KEY = "a"; // no name specified, dot missing final String ENTRY_VALUE = "v"; // try to set entry with invalid key request = getPostGitConfigRequest(gitConfigUri, INVALID_ENTRY_KEY, ENTRY_VALUE); response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_BAD_REQUEST, response.getResponseCode()); }/* ww w.ja v a 2 s.co m*/ }
From source file:i5.las2peer.services.gamificationAchievementService.GamificationAchievementService.java
/** * Update an achievement//from www .j a va 2 s . c o m * @param appId applicationId * @param achievementId achievementId * @param formData form data * @param contentType content type * @return HttpResponse returned as JSON object */ @PUT @Path("/{appId}/{achievementId}") @Produces(MediaType.APPLICATION_JSON) @ApiResponses(value = { @ApiResponse(code = HttpURLConnection.HTTP_OK, message = "Achievement Updated"), @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = "Error occured"), @ApiResponse(code = HttpURLConnection.HTTP_BAD_REQUEST, message = "Bad request"), @ApiResponse(code = HttpURLConnection.HTTP_UNAUTHORIZED, message = "Unauthorized") }) @ApiOperation(value = "updateAchievement", notes = "A method to update an achievement with details (achievement ID, achievement name, achievement description, achievement point value, achievement point id, achievement badge id") public HttpResponse updateAchievement( @ApiParam(value = "Application ID to update an achievement", required = true) @PathParam("appId") String appId, @PathParam("achievementId") String achievementId, @ApiParam(value = "Achievement data in multiple/form-data type", required = true) @HeaderParam(value = HttpHeaders.CONTENT_TYPE) String contentType, @ContentParam byte[] formData) { // Request log L2pLogger.logEvent(this, Event.SERVICE_CUSTOM_MESSAGE_99, "PUT " + "gamification/achievements/" + appId + "/" + achievementId); long randomLong = new Random().nextLong(); //To be able to match // parse given multipart form data JSONObject objResponse = new JSONObject(); String achievementname = null; String achievementdesc = null; int achievementpointvalue = 0; String achievementbadgeid = null; String achievementnotifmessage = null; 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_18, "" + randomLong); Map<String, FormDataPart> parts = MultipartHelper.getParts(formData, contentType); if (achievementId == null) { objResponse.put("message", "Cannot update achievement. Achievement ID cannot be null"); L2pLogger.logEvent(this, Event.SERVICE_ERROR, (String) objResponse.get("message")); return new HttpResponse(objResponse.toJSONString(), HttpURLConnection.HTTP_BAD_REQUEST); } try { try { if (!achievementAccess.isAppIdExist(conn, appId)) { objResponse.put("message", "Cannot update 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 update 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 update achievement. Achievement not found"); L2pLogger.logEvent(this, Event.SERVICE_ERROR, (String) objResponse.get("message")); return new HttpResponse(objResponse.toJSONString(), HttpURLConnection.HTTP_BAD_REQUEST); } AchievementModel currentAchievement = achievementAccess.getAchievementWithId(conn, appId, achievementId); if (currentAchievement == null) { // currentAchievement is null objResponse.put("message", "Cannot update achievement. Achievement not found in database"); L2pLogger.logEvent(this, Event.SERVICE_ERROR, (String) objResponse.get("message")); return new HttpResponse(objResponse.toJSONString(), HttpURLConnection.HTTP_BAD_REQUEST); } FormDataPart partName = parts.get("achievementname"); if (partName != null) { achievementname = partName.getContent(); if (achievementname != null) { currentAchievement.setName(achievementname); } } FormDataPart partDesc = parts.get("achievementdesc"); if (partDesc != null) { // optional description text input form element achievementdesc = partDesc.getContent(); if (achievementdesc != null) { currentAchievement.setDescription(achievementdesc); } } FormDataPart partPV = parts.get("achievementpointvalue"); if (partPV != null) { // optional description text input form element achievementpointvalue = Integer.parseInt(partPV.getContent()); if (achievementpointvalue != 0) { currentAchievement.setPointValue(achievementpointvalue); } } FormDataPart partBID = parts.get("achievementbadgeid"); if (partBID != null) { // optional description text input form element achievementbadgeid = partBID.getContent(); logger.info(achievementbadgeid); if (achievementbadgeid != null) { if (achievementbadgeid.equals("")) { achievementbadgeid = null; } currentAchievement.setBadgeId(achievementbadgeid); } } FormDataPart partNotificationCheck = parts.get("achievementnotificationcheck"); if (partNotificationCheck != null) { // checkbox is checked currentAchievement.useNotification(true); } else { currentAchievement.useNotification(false); } FormDataPart partNotificationMsg = parts.get("achievementnotificationmessage"); if (partNotificationMsg != null) { achievementnotifmessage = partNotificationMsg.getContent(); if (achievementnotifmessage != null) { currentAchievement.setNotificationMessage(achievementnotifmessage); } } achievementAccess.updateAchievement(conn, appId, currentAchievement); objResponse.put("message", "Achievement updated"); L2pLogger.logEvent(Event.SERVICE_CUSTOM_MESSAGE_19, "" + randomLong); L2pLogger.logEvent(Event.SERVICE_CUSTOM_MESSAGE_28, "" + name); L2pLogger.logEvent(Event.SERVICE_CUSTOM_MESSAGE_29, "" + appId); return new HttpResponse(objResponse.toJSONString(), HttpURLConnection.HTTP_OK); } catch (SQLException e) { e.printStackTrace(); objResponse.put("message", "Cannot update achievement. DB Error. " + e.getMessage()); L2pLogger.logEvent(this, Event.SERVICE_ERROR, (String) objResponse.get("message")); return new HttpResponse(objResponse.toJSONString(), HttpURLConnection.HTTP_BAD_REQUEST); } } catch (MalformedStreamException e) { // the stream failed to follow required syntax objResponse.put("message", "Cannot update achievement. Failed to upload " + achievementId + ". " + e.getMessage()); L2pLogger.logEvent(this, Event.SERVICE_ERROR, (String) objResponse.get("message")); return new HttpResponse(objResponse.toJSONString(), HttpURLConnection.HTTP_BAD_REQUEST); } catch (IOException e) { // a read or write error occurred objResponse.put("message", "Cannot update achievement. Failed to upload " + achievementId + "."); 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 update achievement. 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:com.netflix.genie.server.services.impl.GenieExecutionServiceImpl.java
private void validateNameValuePair(String name, String value) throws CloudServiceException { logger.debug("called"); String msg;/*from w w w .ja va 2s.c om*/ // ensure that the value is not null/empty if (value == null || value.isEmpty()) { msg = "Invalid " + name + " parameter, can't be null or empty"; logger.error(msg); throw new CloudServiceException(HttpURLConnection.HTTP_BAD_REQUEST, msg); } // now validate various parameters if (name.equals("jobType") && (Types.JobType.parse(value) == null)) { msg = "Invalid " + name + ", Valid types are hadoop or hive or pig. Wrong value received: " + value; logger.error(msg); throw new CloudServiceException(HttpURLConnection.HTTP_BAD_REQUEST, msg); } else if (name.equals("hiveArgs")) { if ((!value.contains("-f")) && (!value.contains("-e"))) { msg = "Hive arguments must include either the -e or -f flag"; logger.error(msg); throw new CloudServiceException(HttpURLConnection.HTTP_BAD_REQUEST, msg); } } else if (name.equals("schedule") && (Types.Schedule.parse(value) == null)) { msg = "Invalid " + name + " type, Valid values are adhoc, sla or bonus. Wrong value received: " + value; logger.error(msg); throw new CloudServiceException(HttpURLConnection.HTTP_BAD_REQUEST, msg); } else if (name.equals("configuration") && (Types.Configuration.parse(value) == null)) { msg = "Invalid " + name + " type, Valid values are prod or test or unittest. Wrong value received: " + value; logger.error(msg); throw new CloudServiceException(HttpURLConnection.HTTP_BAD_REQUEST, msg); } }