Example usage for org.xml.sax SAXException printStackTrace

List of usage examples for org.xml.sax SAXException printStackTrace

Introduction

In this page you can find the example usage for org.xml.sax SAXException printStackTrace.

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:i5.las2peer.services.mobsos.SurveyService.java

/**
 * TODO: write documentation/*from ww  w .ja  v  a 2  s.co m*/
 * 
 * @param id
 * @return
 */
@GET
@Produces(MediaType.TEXT_CSV)
@Path("surveys/{id}/responses")
@Summary("retrieve response data for given survey.")
@Notes("Use resource <i>/surveys</i> to retrieve list of existing surveys.")
@ApiResponses(value = { @ApiResponse(code = 200, message = "Survey response data in CSV format."),
        @ApiResponse(code = 404, message = "Survey does not exist -or- No questionnaire defined for survey.") })
public HttpResponse getSurveyResponses(@PathParam("id") int id,
        @QueryParam(name = "sepline", defaultValue = "0") int sepline,
        @QueryParam(name = "sep", defaultValue = ",") String sep) {

    String onAction = "retrieving responses for survey " + id;

    try {
        int exown = checkExistenceOwnership(id, 0);

        // check if survey exists. If not, respond with not found.
        if (exown == -1) {
            HttpResponse result = new HttpResponse("Survey " + id + " does not exist.");
            result.setStatus(404);
            return result;
        }

        // check if a questionnaire for survey is defined. If not, respond with not found.
        int qid = getQuestionnaireIdForSurvey(id);
        if (qid == -1) {
            HttpResponse result = new HttpResponse("No questionnaire defined for survey " + id + "!");
            result.setStatus(404);
            return result;
        }

        // retrieve questionnaire form for survey to do answer validation
        HttpResponse r = downloadQuestionnaireForm(qid);

        // if questionnaire form does not exist, pass on response containing error status
        if (200 != r.getStatus()) {
            return r;
        }

        // parse form to XML document incl. validation; will later on be necessary to build query for
        // questionnaire answer table
        Document form;

        try {
            form = validateQuestionnaireData(r.getResult());
        } catch (SAXException e) {
            e.printStackTrace();
            HttpResponse result = new HttpResponse("Questionnaire form is invalid! Cause: " + e.getMessage());
            result.setStatus(400);
            return result;
        }

        // now check, if a survey response view exists. If not, create it.
        if (!existsResponseView(id)) {
            createResponseView(id, form);
        }

        // execute generated query
        Connection conn = null;
        PreparedStatement stmt = null;
        ResultSet rset = null;

        try {
            conn = dataSource.getConnection();
            stmt = conn.prepareStatement("select * from " + jdbcSchema + ".responses_survey_" + id);
            rset = stmt.executeQuery();

            // format and return result
            String res = createCSVQuestionnaireResult(rset, sep);

            if (sepline > 0) {
                // add separator declaration
                res = "sep=" + sep + "\r\n" + res;
            }

            HttpResponse result = new HttpResponse(res);
            result.setStatus(200);
            return result;

        } catch (SQLException | UnsupportedOperationException e) {
            return internalError(onAction);
        } finally {
            try {
                if (rset != null)
                    rset.close();
            } catch (Exception e) {
                e.printStackTrace();
                return internalError(onAction);
            }
            try {
                if (stmt != null)
                    stmt.close();
            } catch (Exception e) {
                e.printStackTrace();
                return internalError(onAction);
            }
            try {
                if (conn != null)
                    conn.close();
            } catch (Exception e) {
                e.printStackTrace();
                return internalError(onAction);
            }
        }

    } catch (Exception e) {
        e.printStackTrace();
        return internalError(onAction + "cause: " + e.getMessage());
    }
}

From source file:i5.las2peer.services.mobsos.SurveyService.java

/**
 * TODO: write documentation//from  w  w w.j a v a2s  .co m
 * 
 * @param id
 * @param answerXml
 * @return
 */
@POST
@Consumes(MediaType.TEXT_XML)
@Path("surveys/{id}/responses")
public HttpResponse submitSurveyResponseXML(@PathParam("id") int id, @ContentParam String answerXml) {

    String onAction = "submitting response to survey " + id;

    try {
        Document answer;
        // parse answer to XML document incl. validation
        try {
            answer = validateQuestionnaireData(answerXml);
        } catch (SAXException e) {
            HttpResponse result = new HttpResponse("Questionnaire form is invalid! Cause: " + e.getMessage());
            result.setStatus(400);
            return result;
        }

        return submitSurveyResponseJSON(id, convertResponseXMLtoJSON(answer).toJSONString());

    } catch (Exception e) {
        e.printStackTrace();
        return internalError(onAction);
    }
}

From source file:i5.las2peer.services.mobsos.SurveyService.java

/**
 * TODO: write documentation/*from  www . j  ava2 s  . c  om*/
 * @param id
 * @param formXml
 * @return
 */
@PUT
@Consumes(MediaType.TEXT_XML)
@Path("questionnaires/{id}/form")
@Summary("Upload for for given questionnaire.")
@Notes("Requires authentication and ownership of questionnaire.")
@ApiResponses(value = { @ApiResponse(code = 200, message = "Questionnaire form upload successful."),
        @ApiResponse(code = 400, message = "Questionnaire form data invalid."),
        @ApiResponse(code = 401, message = "Questionnaire form may only be uploaded by owner. -or- Questionnaire form upload requires authentication."),
        @ApiResponse(code = 404, message = "Questionnaire does not exist.") })
public HttpResponse uploadQuestionnaireForm(@PathParam("id") int id, @ContentParam String formXml) {

    if (getActiveAgent().getId() == getActiveNode().getAnonymous().getId()) {
        HttpResponse noauth = new HttpResponse("Please authenticate to upload questionnaire form!");
        noauth.setStatus(401);
    }

    String onAction = "uploading form for questionnaire " + id;

    try {
        Connection conn = null;
        PreparedStatement stmt = null;
        ResultSet rset = null;

        try {

            // 
            int exown = checkExistenceOwnership(id, 1);

            // check if questionnaire exists; if not, return 404.
            if (exown == -1) {
                HttpResponse result = new HttpResponse("Questionnaire " + id + " does not exist.");
                result.setStatus(404);
                return result;
            }
            // if questionnaire exists, check if active agent is owner. if not, return 401.
            else if (exown == 0) {
                HttpResponse result = new HttpResponse(
                        "Form for questionnaire " + id + "  may only be uploaded by its owner.");
                result.setStatus(401);
                return result;
            }

            // before storing to database validate questionnaire form
            try {
                // validate form XML against MobSOS Survey XML Schema. Since the schema also defines valid responses, a next check
                // is needed to make sure the passed and valid XML is a questionnaire form, and not a response. 
                Document form = validateQuestionnaireData(formXml);

                if (!form.getDocumentElement().getNodeName().equals("qu:Questionnaire")) {
                    HttpResponse result = new HttpResponse(
                            "Document is not a questionnaire form! Cause: Document element must be 'qu:Questionnaire'.");
                    result.setStatus(400);
                    return result;
                }

                String lang = form.getDocumentElement().getAttribute("xml:lang");
                //System.out.println("Language detected: " + lang);

            } catch (SAXException e) {

                HttpResponse result = new HttpResponse(
                        "Questionnaire form is invalid! Cause: " + e.getMessage());
                result.setStatus(400);
                return result;
            }

            // store valid form to database
            conn = dataSource.getConnection();
            stmt = conn.prepareStatement("update " + jdbcSchema + ".questionnaire set form=? where id = ?");

            stmt.setString(1, formXml);
            stmt.setInt(2, id);
            stmt.executeUpdate();

            // respond to user
            HttpResponse result = new HttpResponse("Form upload for questionnaire " + id + " successful.");
            result.setStatus(200);
            return result;

        } catch (SQLException | UnsupportedOperationException e) {
            return internalError(onAction);
        } finally {
            try {
                if (rset != null)
                    rset.close();
            } catch (Exception e) {
                e.printStackTrace();
                return internalError(onAction);
            }
            try {
                if (stmt != null)
                    stmt.close();
            } catch (Exception e) {
                e.printStackTrace();
                return internalError(onAction);
            }
            try {
                if (conn != null)
                    conn.close();
            } catch (Exception e) {
                e.printStackTrace();
                return internalError(onAction);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        return internalError(onAction);
    }
}

From source file:com.atlassian.jira.webtests.JIRAWebTest.java

public void addEventType(String name, String description, String template) {
    gotoAdmin();/*  www .  j a  v a  2s .com*/
    clickLink("eventtypes");
    setFormElement("name", name);
    setFormElement("description", description);
    selectOption("templateId", template);
    submit("Add");
    checkEventTypeDetails(name, description, EVENT_TYPE_INACTIVE_STATUS, template, null, null);

    WebTable fieldTable;
    try {
        fieldTable = getDialog().getResponse().getTableWithID(EVENT_TYPE_TABLE);

        String eventTypeCellText = fieldTable.getCellAsText(fieldTable.getRowCount() - 1,
                EVENT_TYPE_TABLE_NAME_COL);
        assertTrue(eventTypeCellText.contains(name));
    } catch (SAXException e) {
        e.printStackTrace();
    }
}

From source file:com.atlassian.jira.webtests.JIRAWebTest.java

public void checkNotificationForEvent(String eventTypeName, String notificationType, String template) {
    gotoAdmin();//  w  w w .  ja  v  a  2 s. com
    clickLink("notification_schemes");
    clickLinkWithText("Default Notification Scheme");

    WebTable fieldTable;
    try {
        final String NOTIFICATION_SCHEME_TABLE = "notificationSchemeTable";
        fieldTable = getDialog().getResponse().getTableWithID(NOTIFICATION_SCHEME_TABLE);

        // First row is a headings row so skip it
        for (int i = 1; i < fieldTable.getRowCount(); i++) {
            int NOTIFICATION_TABLE_NAME_COL = 0;
            String field = fieldTable.getCellAsText(i, NOTIFICATION_TABLE_NAME_COL);
            if (field.contains(eventTypeName)) {
                int NOTIFICATION_TABLE_TYPE_COL = 1;
                TableCell notificationCell = fieldTable.getTableCell(i, NOTIFICATION_TABLE_TYPE_COL);

                if (notificationType == null) {
                    assertTrue(!notificationCell.asText().contains(notificationType));
                } else {
                    assertTrue(notificationCell.asText().contains(notificationType));
                }
            }
        }

        gotoAdmin();
        clickLink("eventtypes");

    } catch (SAXException e) {
        e.printStackTrace();
    }
}

From source file:com.atlassian.jira.webtests.JIRAWebTest.java

public void checkEventTypeDetails(String eventTypeName, String eventTypeDesc, String status, String template,
        String notificationScheme, String workflow) {
    gotoAdmin();/*from w  w w  .  j a v a 2 s  . c o  m*/
    clickLink("eventtypes");

    WebTable fieldTable;
    try {
        fieldTable = getDialog().getResponse().getTableWithID(EVENT_TYPE_TABLE);

        // First row is a headings row so skip it
        for (int i = 1; i < fieldTable.getRowCount(); i++) {
            String field = fieldTable.getCellAsText(i, EVENT_TYPE_TABLE_NAME_COL);
            if (field.contains(eventTypeName)) {
                int EVENT_TYPE_TABLE_DESC_COL = 1;
                String eventTypeCellText = fieldTable.getCellAsText(i, EVENT_TYPE_TABLE_DESC_COL);
                assertTrue(eventTypeCellText.contains(eventTypeDesc));
                int EVENT_TYPE_TABLE_STATUS_COL = 2;
                eventTypeCellText = fieldTable.getCellAsText(i, EVENT_TYPE_TABLE_STATUS_COL);
                assertTrue(eventTypeCellText.contains(status));
                int EVENT_TYPE_TABLE_TEMPLATE_COL = 3;
                eventTypeCellText = fieldTable.getCellAsText(i, EVENT_TYPE_TABLE_TEMPLATE_COL);
                assertTrue(eventTypeCellText.contains(template));

                if (notificationScheme != null && !notificationScheme.equals("")) {
                    int EVENT_TYPE_TABLE_NOTIFIC_COL = 4;
                    eventTypeCellText = fieldTable.getCellAsText(i, EVENT_TYPE_TABLE_NOTIFIC_COL);
                    assertTrue(eventTypeCellText.contains(notificationScheme));
                }

                if (workflow != null && !workflow.equals("")) {
                    int EVENT_TYPE_TABLE_WORKFLOW_COL = 5;
                    eventTypeCellText = fieldTable.getCellAsText(i, EVENT_TYPE_TABLE_WORKFLOW_COL);
                    assertTrue(eventTypeCellText.contains(workflow));
                }
            }
        }
    } catch (SAXException e) {
        e.printStackTrace();
    }
}

From source file:com.atlassian.jira.webtests.JIRAWebTest.java

private void bulkOperationCheckIssues(Collection keys) {
    try {//from  w  w  w. ja v  a2 s.co m
        int checkBoxColumn = 0;
        WebTable table = getDialog().getResponse().getTableWithID(ISSUETABLE_ID);
        int keyColumn = -1;
        for (int i = 0; i < table.getColumnCount(); i++) {
            String headerCell = table.getCellAsText(ISSUETABLE_HEADER_ROW, i);
            if (headerCell.trim().equals("Key")) {
                keyColumn = i;
            }
        }

        if (keyColumn < 0) {
            fail("Could not find column for Key");
        }

        int checkBoxesChecked = 0;
        for (int i = 0; i < table.getRowCount(); i++) {
            String key = table.getCellAsText(i, keyColumn);
            if (keys.contains(key.trim())) {
                TableCell checkBoxCell = table.getTableCell(i, checkBoxColumn);
                String[] elementNames = checkBoxCell.getElementNames();
                boolean foundCheckbox = false;
                for (String elementName : elementNames) {
                    if (elementName.startsWith("bulkedit_")) {
                        checkCheckbox(elementName);
                        if (++checkBoxesChecked >= keys.size()) {
                            // If we have selected all provided issue keys then there us no need to continue
                            // looking through the table. Return out of the method.
                            return;
                        } else {
                            // Otherwise no need to loop through the nodes. Continue with the next table row.
                            foundCheckbox = true;
                            break;
                        }
                    }
                }

                if (!foundCheckbox) {
                    fail("Could not find the check box for issue with key '" + key + "'.");
                }
            }
        }

    } catch (SAXException e) {
        e.printStackTrace();
        fail("Error occurred selecting issues.");
    }
}

From source file:com.atlassian.jira.webtests.JIRAWebTest.java

public String findRowWithName(String fieldTableName, int column, String fieldName) {
    try {//from   w w  w  . j ava2 s. co m
        WebTable fieldTable = getDialog().getResponse().getTableWithID(fieldTableName);
        //if the table doesn't exist *no* fields are currently configured at all.
        if (fieldTable == null) {
            return null;
        }
        // First row is a headings row so skip it
        for (int i = 1; i < fieldTable.getRowCount(); i++) {
            String field = fieldTable.getCellAsText(i, column);
            if (field.contains(fieldName)) {
                // As we skipped the first row subtract 1
                return Integer.toString(i - 1);
            }
        }
        return null;
    } catch (SAXException e) {
        fail("Cannot find table with id '" + FIELD_TABLE_ID + "'.");
        e.printStackTrace();
    }
    return null;
}

From source file:com.atlassian.jira.webtests.JIRAWebTest.java

public void setRequiredField(String fieldName) {
    assertViewIssueFields();/* w  w w. j  a  va 2s .c om*/

    try {
        WebTable fieldTable = getDialog().getResponse().getTableWithID(FIELD_TABLE_ID);
        // First row is a headings row so skip it
        for (int i = 1; i < fieldTable.getRowCount(); i++) {
            String field = fieldTable.getCellAsText(i, FIELD_TABLE_FIELD_NAME_COLUMN_INDEX);
            if (field.contains(fieldName)) {
                TableCell linkCell = fieldTable.getTableCell(i, FIELD_TABLE_OPERATIONS_COLUMN_INDEX);
                WebLink requiredLink = linkCell.getLinkWith("Required");
                if (requiredLink == null) {
                    fail("Cannot find 'required' link for field '" + fieldName + "'.");
                } else {
                    requiredLink.click();
                    return;
                }
            }
        }

        fail("Cannot find field with id '" + fieldName + "'.");
    } catch (SAXException e) {
        fail("Cannot find table with id '" + FIELD_TABLE_ID + "'.");
        e.printStackTrace();
    } catch (IOException e) {
        fail("Cannot click 'required' link for field id '" + fieldName + "'.");
    }
}

From source file:com.atlassian.jira.webtests.JIRAWebTest.java

public void doFieldOperation(String fieldName, String linkName) {
    assertViewIssueFields();/*from   w  w  w. java  2s.  c  o m*/

    try {
        WebTable fieldTable = getDialog().getResponse().getTableWithID(FIELD_TABLE_ID);
        // First row is a headings row so skip it
        for (int i = 1; i < fieldTable.getRowCount(); i++) {
            String field = fieldTable.getCellAsText(i, FIELD_TABLE_FIELD_NAME_COLUMN_INDEX);
            if (field.contains(fieldName)) {
                TableCell linkCell = fieldTable.getTableCell(i, FIELD_TABLE_OPERATIONS_COLUMN_INDEX);
                WebLink link = linkCell.getLinkWith(linkName);
                if (link == null) {
                    // This is usually OK, as this happens when e.g. hiding a field that is already hidden
                    log("Link with name '" + linkName + "' does not exist.");
                    return;
                } else {
                    link.click();
                    return;
                }
            }
        }
        fail("Cannot find field with id '" + fieldName + "'.");
    } catch (SAXException e) {
        fail("Cannot find table with id '" + FIELD_TABLE_ID + "'.");
        e.printStackTrace();
    } catch (IOException e) {
        fail("Cannot click '" + linkName + "' link for field id '" + fieldName + "'.");
    }
}