Example usage for java.net HttpURLConnection HTTP_INTERNAL_ERROR

List of usage examples for java.net HttpURLConnection HTTP_INTERNAL_ERROR

Introduction

In this page you can find the example usage for java.net HttpURLConnection HTTP_INTERNAL_ERROR.

Prototype

int HTTP_INTERNAL_ERROR

To view the source code for java.net HttpURLConnection HTTP_INTERNAL_ERROR.

Click Source Link

Document

HTTP Status-Code 500: Internal Server Error.

Usage

From source file:i5.las2peer.services.gamificationLevelService.GamificationLevelService.java

/**
 * Update a level/*from   ww  w  . j  a va2  s . co  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.resources.ApplicationConfigResource.java

/**
 * Update the jar files for a given application.
 *
 * @param id   The id of the application to update the jar files for. Not
 *             null/empty/blank./*from w ww.  ja va 2 s  .  c  o m*/
 * @param jars The jar files to replace existing jar files with. Not
 *             null/empty/blank.
 * @return The active set of application jars
 * @throws GenieException For any error
 */
@PUT
@Path("/{id}/jars")
@Consumes(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Update jar files for an application", notes = "Replace the existing jar files for application with given id.", 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> updateJarsForApplication(
        @ApiParam(value = "Id of the application to update configurations for.", required = true) @PathParam("id") final String id,
        @ApiParam(value = "The jar files to replace existing with.", required = true) final Set<String> jars)
        throws GenieException {
    LOG.info("Called with id " + id + " and jars " + jars);
    return this.applicationConfigService.updateJarsForApplication(id, jars);
}

From source file:i5.las2peer.services.gamificationActionService.GamificationActionService.java

/**
 * Update an action/*w ww  .  java  2s.  c o m*/
 * @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:rapture.repo.VersionedRepo.java

@Override
public RaptureDNCursor getNextDNCursor(RaptureDNCursor cursor, int count) {
    throw RaptureExceptionFactory.create(HttpURLConnection.HTTP_INTERNAL_ERROR, "Not yet implemented");
}

From source file:com.netflix.genie.server.resources.ClusterConfigResource.java

/**
 * Remove the all commands from a given cluster.
 *
 * @param id The id of the cluster to delete the commands from. Not
 *           null/empty/blank./* www.  j  a  v a 2 s.c  o  m*/
 * @return Empty set if successful
 * @throws GenieException For any error
 */
@DELETE
@Path("/{id}/commands")
@ApiOperation(value = "Remove all commands from an cluster", notes = "Remove all the commands from the cluster with given id.", response = Command.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 List<Command> removeAllCommandsForCluster(
        @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.removeAllCommandsForCluster(id);
}

From source file:com.netflix.genie.server.resources.CommandConfigResource.java

/**
 * Delete the all tags from a given command.
 *
 * @param id The id of the command to delete the tags from.
 *           Not null/empty/blank./*from w w  w .  jav  a  2s.  c o  m*/
 * @return Empty set if successful
 * @throws GenieException For any error
 */
@DELETE
@Path("/{id}/tags")
@ApiOperation(value = "Remove all tags from a command", notes = "Remove all the tags 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> removeAllTagsForCommand(
        @ApiParam(value = "Id of the command to delete from.", required = true) @PathParam("id") final String id)
        throws GenieException {
    LOG.info("Called with id " + id);
    return this.commandConfigService.removeAllTagsForCommand(id);
}

From source file:co.cask.cdap.client.rest.RestStreamClientTest.java

@Test
public void testServerErrorCreate() throws IOException {
    try {/* w  w w.jav a  2  s.c  o m*/
        streamClient.create(StringUtils.EMPTY);
        Assert.fail("Expected HttpFailureException");
    } catch (HttpFailureException e) {
        Assert.assertEquals(HttpURLConnection.HTTP_INTERNAL_ERROR, e.getStatusCode());
    }
}

From source file:org.projectbuendia.client.ui.OdkActivityLauncher.java

private static void handleFetchError(VolleyError error) {
    FetchXformFailedEvent.Reason reason = FetchXformFailedEvent.Reason.SERVER_UNKNOWN;
    if (error.networkResponse != null) {
        switch (error.networkResponse.statusCode) {
        case HttpURLConnection.HTTP_FORBIDDEN:
        case HttpURLConnection.HTTP_UNAUTHORIZED:
            reason = FetchXformFailedEvent.Reason.SERVER_AUTH;
            break;
        case HttpURLConnection.HTTP_NOT_FOUND:
            reason = FetchXformFailedEvent.Reason.SERVER_BAD_ENDPOINT;
            break;
        case HttpURLConnection.HTTP_INTERNAL_ERROR:
        default://ww  w .j a  v a  2s  . c o m
            reason = FetchXformFailedEvent.Reason.SERVER_UNKNOWN;
        }
    }
    EventBus.getDefault().post(new FetchXformFailedEvent(reason, error));
}

From source file:com.netflix.genie.server.resources.ApplicationConfigResource.java

/**
 * Delete the all jar files from a given application.
 *
 * @param id The id of the application to delete the jar files from. Not
 *           null/empty/blank.//  w ww. j  a  va2 s.co  m
 * @return Empty set if successful
 * @throws GenieException For any error
 */
@DELETE
@Path("/{id}/jars")
@ApiOperation(value = "Remove all jar files from an application", notes = "Remove all the jar files from the application with given id.", 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> removeAllJarsForApplication(
        @ApiParam(value = "Id of the application to delete from.", required = true) @PathParam("id") final String id)
        throws GenieException {
    LOG.info("Called with id " + id);
    return this.applicationConfigService.removeAllJarsForApplication(id);
}

From source file:i5.las2peer.services.gamificationAchievementService.GamificationAchievementService.java

/**
 * Update an achievement/*w  w w .  j a  v  a  2  s .c om*/
 * @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);
        }
    }

}