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:com.netflix.genie.server.resources.ClusterConfigResource.java

/**
 * Remove an command from a given cluster.
 *
 * @param id    The id of the cluster to delete the command from. Not
 *              null/empty/blank./*  w  w w .j  a  va  2  s  . com*/
 * @param cmdId The id of the command to remove. Not null/empty/blank.
 * @return The active set of commands for the cluster.
 * @throws GenieException For any error
 */
@DELETE
@Path("/{id}/commands/{cmdId}")
@ApiOperation(value = "Remove a command from a cluster", notes = "Remove the given command 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> removeCommandForCluster(
        @ApiParam(value = "Id of the cluster to delete from.", required = true) @PathParam("id") final String id,
        @ApiParam(value = "The id of the command to remove.", required = true) @PathParam("cmdId") final String cmdId)
        throws GenieException {
    LOG.info("Called with id " + id + " and command id " + cmdId);
    return this.clusterConfigService.removeCommandForCluster(id, cmdId);
}

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

/**
 * Set the application for the given command.
 *
 * @param id          The id of the command to add the applications to. Not
 *                    null/empty/blank./* www .ja  va  2s .co  m*/
 * @param application The application to set. Not null.
 * @return The active applications for this command.
 * @throws GenieException For any error
 */
@POST
@Path("/{id}/application")
@Consumes(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Set the application for a command", notes = "Set the supplied application to the command "
        + "with the supplied id. Applications should already "
        + "have been created.", response = Application.class)
@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 Application setApplicationForCommand(
        @ApiParam(value = "Id of the command to set application for.", required = true) @PathParam("id") final String id,
        @ApiParam(value = "The application to add.", required = true) final Application application)
        throws GenieException {
    LOG.info("Called with id " + id + " and application " + application);
    return this.commandConfigService.setApplicationForCommand(id, application);
}

From source file:i5.las2peer.services.gamificationBadgeService.GamificationBadgeService.java

/**
 * Update a badge/* www  . j  a v  a  2  s  .  com*/
 * @param appId application id
 * @param badgeId badge id
 * @param formData form data
 * @param contentType content type
 * @return HttpResponse returned as JSON object
 */
@PUT
@Path("/{appId}/{badgeId}")
@Produces(MediaType.APPLICATION_JSON)
@ApiResponses(value = { @ApiResponse(code = HttpURLConnection.HTTP_OK, message = "Badge 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 a badge", notes = "A method to update a badge with details (badge ID, badge name, badge description, and badge image")
public HttpResponse updateBadge(
        @ApiParam(value = "Application ID to store a new badge", required = true) @PathParam("appId") String appId,
        @PathParam("badgeId") String badgeId,
        @ApiParam(value = "Badge 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/badges/" + appId + "/" + badgeId);
    long randomLong = new Random().nextLong(); //To be able to match 

    // parse given multipart form data
    JSONObject objResponse = new JSONObject();
    String filename = null;
    byte[] filecontent = null;
    String mimeType = null;
    // Badge ID for the filesystem is appended with app id to make sure it is unique
    String badgename = null;
    String badgedescription = null;
    //boolean badgeusenotification = false;
    String badgenotificationmessage = 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);

        try {
            if (!badgeAccess.isAppIdExist(conn, appId)) {
                objResponse.put("message", "Cannot update 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 update 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);
        }
        Map<String, FormDataPart> parts = MultipartHelper.getParts(formData, contentType);

        if (badgeId == null) {
            objResponse.put("message", "Cannot update badge. Badge ID cannot be null");
            L2pLogger.logEvent(this, Event.SERVICE_ERROR, (String) objResponse.get("message"));
            return new HttpResponse(objResponse.toJSONString(), HttpURLConnection.HTTP_BAD_REQUEST);
        }
        BadgeModel currentBadge = badgeAccess.getBadgeWithId(conn, appId, badgeId);
        if (currentBadge == null) {
            // currentBadge is null
            objResponse.put("message", "Cannot update badge. Badge not found");
            L2pLogger.logEvent(this, Event.SERVICE_ERROR, (String) objResponse.get("message"));
            return new HttpResponse(objResponse.toJSONString(), HttpURLConnection.HTTP_BAD_REQUEST);

        }
        FormDataPart partBadgeName = parts.get("badgename");
        if (partBadgeName != null) {
            badgename = partBadgeName.getContent();
            if (badgename != null) {
                currentBadge.setName(badgename);
            }
        }
        FormDataPart partDescription = parts.get("badgedesc");
        if (partDescription != null) {
            // optional description text input form element
            badgedescription = partDescription.getContent();
            if (badgedescription != null) {
                currentBadge.setDescription(badgedescription);
            }
        }
        FormDataPart partFilecontent = parts.get("badgeimageinput");
        if (partFilecontent != null) {
            // these data belong to the file input form element
            filename = partFilecontent.getHeader(HEADER_CONTENT_DISPOSITION).getParameter("filename");
            byte[] filecontentbefore = partFilecontent.getContentRaw();
            mimeType = partFilecontent.getContentType();
            //                   validate input

            if (filecontentbefore != null) {
                try {
                    // in unit test, resize image will turn the image into null BufferedImage
                    // but, it works in web browser
                    FormDataPart partDev = parts.get("dev");
                    if (partDev != null) {
                        filecontent = filecontentbefore;
                    } else {
                        filecontent = resizeImage(filecontentbefore);
                    }
                    //filecontent = resizeImage(filecontentbefore);
                    storeBadgeDataToSystem(appId, badgeId, filename, filecontent, mimeType, badgedescription);
                    logger.info("upload request (" + filename + ") of mime type '" + mimeType
                            + "' with content length " + filecontent.length);

                } catch (AgentNotKnownException | L2pServiceException | L2pSecurityException
                        | InterruptedException | TimeoutException e) {
                    e.printStackTrace();
                    objResponse.put("message",
                            "Cannot update badge. Failed to upload " + badgeId + ". " + e.getMessage());
                    L2pLogger.logEvent(this, Event.SERVICE_ERROR, (String) objResponse.get("message"));
                    return new HttpResponse(objResponse.toJSONString(), HttpURLConnection.HTTP_INTERNAL_ERROR);
                } catch (IllegalArgumentException e) {
                    objResponse.put("message",
                            "Cannot update badge. Badge image is not updated. " + e.getMessage());
                    L2pLogger.logEvent(this, Event.SERVICE_ERROR, (String) objResponse.get("message"));
                    return new HttpResponse(objResponse.toJSONString(), HttpURLConnection.HTTP_INTERNAL_ERROR);

                }
            }
        }
        FormDataPart partNotificationCheck = parts.get("badgenotificationcheck");

        if (partNotificationCheck != null) {
            currentBadge.useNotification(true);

        } else {
            currentBadge.useNotification(false);

        }
        FormDataPart partNotificationMsg = parts.get("badgenotificationmessage");

        if (partNotificationMsg != null) {
            badgenotificationmessage = partNotificationMsg.getContent();
            if (badgenotificationmessage != null) {
                currentBadge.setNotificationMessage(badgenotificationmessage);
            }
        }

        try {
            badgeAccess.updateBadge(conn, appId, currentBadge);
            objResponse.put("message", "Badge 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 badge. Database Error. " + e.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 badge. Failed to upload " + badgeId + ". " + 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 badge. Failed to upload " + badgeId + "." + 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 badge. Database 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

/**
 * Add new tags to a given application.//from   ww w  .j  a  v a  2s.  c  o  m
 *
 * @param id   The id of the application to add the tags to. Not
 *             null/empty/blank.
 * @param tags The tags to add. Not null/empty/blank.
 * @return The active tags for this application.
 * @throws GenieException For any error
 */
@POST
@Path("/{id}/tags")
@Consumes(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Add new tags to a application", notes = "Add the supplied tags to the application with the supplied 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> addTagsForApplication(
        @ApiParam(value = "Id of the application to add configuration to.", required = true) @PathParam("id") final String id,
        @ApiParam(value = "The tags to add.", required = true) final Set<String> tags) throws GenieException {
    LOG.info("Called with id " + id + " and config " + tags);
    return this.applicationConfigService.addTagsForApplication(id, tags);
}

From source file:i5.las2peer.services.servicePackage.TemplateService.java

@GET
@Path("/linkedGraphs/graphweight")
@Produces(MediaType.APPLICATION_JSON)//from  w  w  w.ja  va 2s  .c  o  m
public HttpResponse getGraphWeight() {
    Connection conn = null;
    PreparedStatement stmnt = null;
    PreparedStatement stmnt1 = null;
    ResultSet senders = null;
    ResultSet receivers = null;
    ToJSON converter = new ToJSON();
    TextProcessor tp = new TextProcessor();
    JSONArray json = new JSONArray();
    EntityManagement em = new EntityManagement();
    WordConverter wordConv = new WordConverter();
    Array2DRowRealMatrix matrix = new Array2DRowRealMatrix();

    try {
        // get connection from connection pool
        conn = dbm.getConnection();

        // prepare statement
        stmnt = conn.prepareStatement("SELECT sender,receiver FROM biojava group by sender,receiver;");
        senders = stmnt.executeQuery();

        while (senders.next()) {
            JSONObject obj = wordConv.generateWeights(senders.getInt("sender"), senders.getInt("receiver"),
                    conn);
            json.put(obj);
        }

        //LinkedList<LinkedNode> nodes = em.listLinkedNodes(rs);   // listing nodes and textpreprocessing of content
        //json = wordConv.getWeightedGraph();      // creating term matrix, computing tf- idf, converting to json array for visualization

        return new HttpResponse(json.toString(), HttpURLConnection.HTTP_OK);

    } catch (Exception e) {

        return new HttpResponse("Internal error: " + e.getMessage(), HttpURLConnection.HTTP_INTERNAL_ERROR);

    } finally {
        // free resources if exception or not
        if (senders != null) {
            try {
                senders.close();
            } catch (Exception e) {
                Context.logError(this, e.getMessage());

                // return HTTP Response on error
                return new HttpResponse("Internal error: " + e.getMessage(),
                        HttpURLConnection.HTTP_INTERNAL_ERROR);
            }
        }
        if (receivers != null) {
            try {
                receivers.close();
            } catch (Exception e) {
                Context.logError(this, e.getMessage());

                // return HTTP Response on error
                return new HttpResponse("Internal error: " + e.getMessage(),
                        HttpURLConnection.HTTP_INTERNAL_ERROR);
            }
        }
        if (stmnt != null) {
            try {
                stmnt.close();
            } catch (Exception e) {
                Context.logError(this, e.getMessage());

                // return HTTP Response on error
                return new HttpResponse("Internal error: " + e.getMessage(),
                        HttpURLConnection.HTTP_INTERNAL_ERROR);
            }
        }
        if (conn != null) {
            try {
                conn.close();
            } catch (Exception e) {
                Context.logError(this, e.getMessage());

                // return HTTP Response on error
                return new HttpResponse("Internal error: " + e.getMessage(),
                        HttpURLConnection.HTTP_INTERNAL_ERROR);
            }
        }
    }

}

From source file:i5.las2peer.services.gamificationApplicationService.GamificationApplicationService.java

/**
 * Delete an application data with specified ID
 * @param appId applicationId/*from w  ww.j  av  a2  s  .  c o m*/
 * @return HttpResponse with the returnString
 */
@DELETE
@Path("/data/{appId}")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Delete Application", notes = "This method deletes an App")
@ApiResponses(value = { @ApiResponse(code = HttpURLConnection.HTTP_OK, message = "Application Deleted"),
        @ApiResponse(code = HttpURLConnection.HTTP_BAD_REQUEST, message = "Application not found"),
        @ApiResponse(code = HttpURLConnection.HTTP_BAD_REQUEST, message = "Application not found"),
        @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = "Cannot connect to database"),
        @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = "Error checking app ID exist"),
        @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = "Database error"),
        @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = "Error delete storage"),
        @ApiResponse(code = HttpURLConnection.HTTP_UNAUTHORIZED, message = "Unauthorized") })

public HttpResponse deleteApplication(
        @ApiParam(value = "Application ID", required = true) @PathParam("appId") String appId) {
    // Request log
    L2pLogger.logEvent(this, Event.SERVICE_CUSTOM_MESSAGE_99,
            "DELETE " + "gamification/applications/data/" + appId);

    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 delete Application. App not found.");
            L2pLogger.logEvent(this, Event.SERVICE_ERROR, (String) objResponse.get("message"));
            return new HttpResponse(objResponse.toJSONString(), HttpURLConnection.HTTP_BAD_REQUEST);
        }
        try {
            if (cleanStorage(appId)) {
                //if(applicationAccess.removeApplicationInfo(appId)){

                L2pLogger.logEvent(Event.SERVICE_CUSTOM_MESSAGE_12, "" + name);
                if (applicationAccess.deleteApplicationDB(conn, appId)) {
                    objResponse.put("message", "Application deleted");
                    L2pLogger.logEvent(Event.SERVICE_CUSTOM_MESSAGE_13, "" + name);
                    return new HttpResponse(objResponse.toJSONString(), HttpURLConnection.HTTP_OK);
                }
                //}
                objResponse.put("message", "Cannot delete Application. Database error. ");
                L2pLogger.logEvent(this, Event.SERVICE_ERROR, (String) objResponse.get("message"));
                return new HttpResponse(objResponse.toJSONString(), HttpURLConnection.HTTP_INTERNAL_ERROR);
            }
        } catch (AgentNotKnownException | L2pServiceException | L2pSecurityException | InterruptedException
                | TimeoutException e) {
            e.printStackTrace();
            L2pLogger.logEvent(Event.RMI_FAILED, "Failed to clean storage");
            objResponse.put("message", "RMI error. Failed to clean storage. ");
            return new HttpResponse(objResponse.toJSONString(), HttpURLConnection.HTTP_INTERNAL_ERROR);

        }
    } catch (SQLException e) {
        e.printStackTrace();
        objResponse.put("message", "Cannot delete 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);
        }
    }

    objResponse.put("message", "Cannot delete Application. Error delete storage.");
    L2pLogger.logEvent(this, Event.SERVICE_ERROR, (String) objResponse.get("message"));
    return new HttpResponse(objResponse.toJSONString(), HttpURLConnection.HTTP_INTERNAL_ERROR);
}

From source file:i5.las2peer.services.gamificationQuestService.GamificationQuestService.java

/**
 * Update a quest/*from ww w. j  ava2  s.  co m*/
 * @param appId applicationId
 * @param questId questId
 * @param contentB data
 * @return HttpResponse with the returnString
 */
@PUT
@Path("/{appId}/{questId}")
@Produces(MediaType.TEXT_PLAIN)
@Consumes(MediaType.APPLICATION_JSON)
@ApiResponses(value = { @ApiResponse(code = HttpURLConnection.HTTP_OK, message = "Quest 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 = "updateQuest", notes = "A method to update a quest with details")
public HttpResponse updateQuest(
        @ApiParam(value = "Application ID to store a new quest", required = true) @PathParam("appId") String appId,
        @ApiParam(value = "Quest ID") @PathParam("questId") String questId,
        @ApiParam(value = "Quest detail in JSON", required = true) @ContentParam byte[] contentB) {

    // Request log
    L2pLogger.logEvent(this, Event.SERVICE_CUSTOM_MESSAGE_99,
            "PUT " + "gamification/quests/" + appId + "/" + questId);
    long randomLong = new Random().nextLong(); //To be able to match

    // parse given multipart form data
    JSONObject objResponse = new JSONObject();
    Connection conn = null;

    String content = new String(contentB);
    if (content.equals(null)) {
        objResponse.put("message", "Cannot update quest. Cannot parse json data into string");

        L2pLogger.logEvent(this, Event.SERVICE_ERROR, (String) objResponse.get("message"));
        return new HttpResponse(objResponse.toJSONString(), HttpURLConnection.HTTP_INTERNAL_ERROR);

    }

    String questname;
    String questdescription;
    String queststatus;
    String questachievementid;
    boolean questquestflag = false;
    String questquestidcompleted = null;
    boolean questpointflag = false;
    int questpointvalue = 0;
    List<Pair<String, Integer>> questactionids = new ArrayList<Pair<String, Integer>>();

    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);

        try {
            if (!questAccess.isAppIdExist(conn, appId)) {
                logger.info("App not found >> ");
                objResponse.put("message", "Cannot update 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();
            logger.info(
                    "Cannot check whether application ID exist or not. Database error. >> " + e1.getMessage());
            objResponse.put("message",
                    "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 (questId == null) {
            logger.info("quest ID cannot be null >> ");
            objResponse.put("message", "Cannot update quest. quest ID cannot be null");

            L2pLogger.logEvent(this, Event.SERVICE_ERROR, (String) objResponse.get("message"));
            return new HttpResponse(objResponse.toJSONString(), HttpURLConnection.HTTP_BAD_REQUEST);
        }

        QuestModel quest = questAccess.getQuestWithId(conn, appId, questId);
        if (!questAccess.isQuestIdExist(conn, appId, questId)) {
            objResponse.put("message",
                    "Cannot update quest. Failed to update the quest. Quest ID is not exist!");
            L2pLogger.logEvent(this, Event.SERVICE_ERROR, (String) objResponse.get("message"));
            return new HttpResponse(objResponse.toJSONString(), HttpURLConnection.HTTP_INTERNAL_ERROR);
        }
        JSONObject obj = (JSONObject) JSONValue.parseWithException(content);

        try {
            questname = stringfromJSON(obj, "questname");
            quest.setName(questname);
        } catch (IOException e) {
            e.printStackTrace();
            logger.info("Cannot parse questname");
        }
        try {
            queststatus = stringfromJSON(obj, "queststatus");
            quest.setStatus(QuestStatus.valueOf(queststatus));
        } catch (IOException e) {
            e.printStackTrace();
        }
        try {
            questachievementid = stringfromJSON(obj, "questachievementid");
            quest.setAchievementId(questachievementid);
        } catch (IOException e) {
            e.printStackTrace();
        }
        questdescription = (String) obj.get("questdescription");
        if (!questdescription.equals(null)) {
            quest.setDescription(questdescription);
        }
        questquestidcompleted = (String) obj.get("questidcompleted");
        if (questquestflag) {
            if (questquestidcompleted.equals(null) || questquestidcompleted.equals("")) {
                objResponse.put("message",
                        "Cannot update quest. Completed quest ID cannot be null if it is selected");
                L2pLogger.logEvent(this, Event.SERVICE_ERROR, (String) objResponse.get("message"));
                return new HttpResponse(objResponse.toJSONString(), HttpURLConnection.HTTP_INTERNAL_ERROR);
            }
        }
        questquestflag = boolfromJSON(obj, "questquestflag");
        questpointflag = boolfromJSON(obj, "questpointflag");
        questpointvalue = intfromJSON(obj, "questpointvalue");

        quest.setQuestFlag(questquestflag);
        quest.setPointFlag(questpointflag);
        quest.setQuestIdCompleted(questquestidcompleted);
        quest.setPointValue(questpointvalue);
        try {
            questactionids = listPairfromJSON(obj, "questactionids", "action", "times");
            quest.setActionIds(questactionids);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        questAccess.updateQuest(conn, appId, quest);
        logger.info("Quest Updated ");
        objResponse.put("message", "Quest updated " + questId);
        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 quest. DB Error. " + e.getMessage());
        L2pLogger.logEvent(this, Event.SERVICE_ERROR, (String) objResponse.get("message"));
        return new HttpResponse(objResponse.toJSONString(), HttpURLConnection.HTTP_INTERNAL_ERROR);

    } catch (ParseException e) {
        e.printStackTrace();
        objResponse.put("message", "Cannot update quest. ParseExceptionr. " + e.getMessage());
        L2pLogger.logEvent(this, Event.SERVICE_ERROR, (String) objResponse.get("message"));
        return new HttpResponse(objResponse.toJSONString(), HttpURLConnection.HTTP_INTERNAL_ERROR);
    } catch (IOException e) {
        e.printStackTrace();
        objResponse.put("message", "Cannot update quest. Problem with the model. " + 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.netflix.genie.server.resources.ClusterConfigResource.java

/**
 * Add new tags to a given cluster./*from ww w .  j av a 2 s. c  om*/
 *
 * @param id   The id of the cluster to add the tags to. Not
 *             null/empty/blank.
 * @param tags The tags to add. Not null/empty/blank.
 * @return The active tags for this cluster.
 * @throws GenieException For any error
 */
@POST
@Path("/{id}/tags")
@Consumes(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Add new tags to a cluster", notes = "Add the supplied tags to the cluster with the supplied id.", response = String.class, responseContainer = "List")
@ApiResponses(value = { @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = "Cluster not found"),
        @ApiResponse(code = HttpURLConnection.HTTP_PRECON_FAILED, message = "Invalid required parameter supplied"),
        @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = "Genie Server Error due to Unknown Exception") })
public Set<String> addTagsForCluster(
        @ApiParam(value = "Id of the cluster to add configuration to.", required = true) @PathParam("id") final String id,
        @ApiParam(value = "The tags to add.", required = true) final Set<String> tags) throws GenieException {
    LOG.info("Called with id " + id + " and tags " + tags);
    return this.clusterConfigService.addTagsForCluster(id, tags);
}

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

/**
 * Get the application configured for a given command.
 *
 * @param id The id of the command to get the application files for. Not
 *           NULL/empty/blank.//from w  w w . j av  a 2  s .co  m
 * @return The active application for the command.
 * @throws GenieException For any error
 */
@GET
@Path("/{id}/application")
@ApiOperation(value = "Get the application for a command", notes = "Get the application for the command with the supplied id.", response = Application.class)
@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 Application getApplicationForCommand(
        @ApiParam(value = "Id of the command to get the application for.", required = true) @PathParam("id") final String id)
        throws GenieException {
    LOG.info("Called with id " + id);
    return this.commandConfigService.getApplicationForCommand(id);
}

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

/**
 * Get all the tags for a given application.
 *
 * @param id The id of the application to get the tags for. Not
 *           NULL/empty/blank.//w  w w.j  av a  2 s.  com
 * @return The active set of tags.
 * @throws GenieException For any error
 */
@GET
@Path("/{id}/tags")
@ApiOperation(value = "Get the tags for a application", notes = "Get the tags for the application with the supplied 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> getTagsForApplication(
        @ApiParam(value = "Id of the application to get tags for.", required = true) @PathParam("id") final String id)
        throws GenieException {
    LOG.info("Called with id " + id);
    return this.applicationConfigService.getTagsForApplication(id);
}