Exemple #1
1
  public void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    response.setContentType("text/html");
    HttpSession session = request.getSession();
    PrintWriter out = response.getWriter();
    StringBuilder sb = new StringBuilder();

    HashMap<String, String> userInfo = (HashMap<String, String>) session.getAttribute("userInfo");
    String ticket = request.getParameter("ticket");

    if (userInfo == null) {
      response.sendRedirect(response.encodeRedirectUrl(request.getContextPath() + "/SignIn"));
    } else {
      if (userInfo.get("role").equals("technician")) {
        sb.append(LayoutProvider.getInstance().getLoggedInHeader(userInfo.get("name")));
        sb.append("<div id=\"body\">");
        sb.append(
            "<h3>Schedule Confirmation</h3><p>You have scheduled <strong>ticket # "
                + ticket
                + "</strong></p>");
        if (ticket != null) {
          List<String> tickets;
          try {
            if (userInfo.get("tickets").equals("")) {
              tickets = null;
            } else {
              tickets = Arrays.asList(userInfo.get("tickets").split("\\,"));
            }
          } catch (Exception ex) {
            System.out.println("PayBill: error splitting tickets");
            tickets = null;
          }
          String remaining = "";
          if (tickets != null && tickets.size() > 0) {
            for (String t : tickets) {
              if (!t.equals(ticket)) {
                remaining += t + ",";
              }
            }
            if (remaining.length() > 0) remaining = remaining.substring(0, remaining.length() - 1);
          } else {
            remaining = "";
          }
          userInfo.put("tickets", remaining);
        }
        sb.append("</div>");
      } else {
        sb.append("<h2>Error</h2>");
        sb.append("<p>You do not have access to this page.</p>");
        sb.append("</div>");
      }
    }
    out.println(sb.toString());
    out.close();
  }
  public Object executeTask(Object object) throws Exception {
    Map incomingRequest = (Map) object;
    Object result = null;

    try {
      String redirectUrl = (String) incomingRequest.get("redirectUrl");
      HttpServletResponse response =
          (HttpServletResponse) incomingRequest.get("HttpServletResponse");

      result = response.encodeRedirectUrl(redirectUrl);

      this.status = Status.SUCCEEDED;
    } catch (Exception e) {
      this.status = Status.FAILED;
      throw e;
    }
    return result;
  }
 @Override
 public String encodeRedirectUrl(String s) {
   return response.encodeRedirectUrl(s);
 }
  // The tck uses only get & post requests
  protected void processTCKReq(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    LOGGER.entering(LOG_CLASS, "servlet entry");

    PortletRequest portletReq = (PortletRequest) request.getAttribute("javax.portlet.request");
    PortletResponse portletResp = (PortletResponse) request.getAttribute("javax.portlet.response");
    PortletConfig portletConfig = (PortletConfig) request.getAttribute("javax.portlet.config");
    long svtTid = Thread.currentThread().getId();
    long reqTid = (Long) portletReq.getAttribute(THREADID_ATTR);

    PrintWriter writer = ((MimeResponse) portletResp).getWriter();

    JSR286DispatcherReqRespTestCaseDetails tcd = new JSR286DispatcherReqRespTestCaseDetails();

    // Create result objects for the tests

    /* TestCase: V2DispatcherReqRespTests4_SPEC2_19_IncludeServletResourceResponse_containsHeader */
    /* Details: "In a target servlet of a include in the Resource phase,    */
    /* the method HttpServletResponse.containsHeader must return false"     */
    TestResult tr0 =
        tcd.getTestResultFailed(
            V2DISPATCHERREQRESPTESTS4_SPEC2_19_INCLUDESERVLETRESOURCERESPONSE_CONTAINSHEADER);
    try {
      boolean ok = response.containsHeader("Accept");
      tr0.setTcSuccess(ok == false);
    } catch (Exception e) {
      tr0.appendTcDetail(e.toString());
    }
    tr0.writeTo(writer);

    /* TestCase: V2DispatcherReqRespTests4_SPEC2_19_IncludeServletResourceResponse_encodeRedirectURL1 */
    /* Details: "In a target servlet of a include in the Resource phase,    */
    /* the method HttpServletResponse.encodeRedirectURL must return null"   */
    TestResult tr1 =
        tcd.getTestResultFailed(
            V2DISPATCHERREQRESPTESTS4_SPEC2_19_INCLUDESERVLETRESOURCERESPONSE_ENCODEREDIRECTURL1);
    try {
      String isval = response.encodeRedirectURL("http://www.cnn.com/");
      CompareUtils.stringsEqual(isval, null, tr1);
    } catch (Exception e) {
      tr1.appendTcDetail(e.toString());
    }
    tr1.writeTo(writer);

    /* TestCase: V2DispatcherReqRespTests4_SPEC2_19_IncludeServletResourceResponse_encodeRedirectUrl */
    /* Details: "In a target servlet of a include in the Resource phase,    */
    /* the method HttpServletResponse.encodeRedirectUrl must return null"   */
    TestResult tr2 =
        tcd.getTestResultFailed(
            V2DISPATCHERREQRESPTESTS4_SPEC2_19_INCLUDESERVLETRESOURCERESPONSE_ENCODEREDIRECTURL);
    try {
      String isval = response.encodeRedirectUrl("http://www.cnn.com/");
      CompareUtils.stringsEqual(isval, null, tr2);
    } catch (Exception e) {
      tr2.appendTcDetail(e.toString());
    }
    tr2.writeTo(writer);

    /* TestCase: V2DispatcherReqRespTests4_SPEC2_19_IncludeServletResourceResponse_encodeURL1 */
    /* Details: "In a target servlet of a include in the Resource phase,    */
    /* the method HttpServletResponse.encodeURL must provide the same       */
    /* functionality as ResourceResponse.encodeURL"                         */
    TestResult tr3 =
        tcd.getTestResultFailed(
            V2DISPATCHERREQRESPTESTS4_SPEC2_19_INCLUDESERVLETRESOURCERESPONSE_ENCODEURL1);
    try {
      String turl = "http://www.apache.org/";
      String hval = (String) response.encodeURL(turl);
      String pval = (String) portletResp.encodeURL(turl);
      CompareUtils.stringsEqual("HttpServletResponse", hval, "ResourceResponse", pval, tr3);
    } catch (Exception e) {
      tr3.appendTcDetail(e.toString());
    }
    tr3.writeTo(writer);

    /* TestCase: V2DispatcherReqRespTests4_SPEC2_19_IncludeServletResourceResponse_encodeUrl */
    /* Details: "In a target servlet of a include in the Resource phase,    */
    /* the method HttpServletResponse.encodeUrl must provide the same       */
    /* functionality as ResourceResponse.encodeURL"                         */
    TestResult tr4 =
        tcd.getTestResultFailed(
            V2DISPATCHERREQRESPTESTS4_SPEC2_19_INCLUDESERVLETRESOURCERESPONSE_ENCODEURL);
    try {
      String turl = "http://www.apache.org/";
      String hval = (String) response.encodeUrl(turl);
      String pval = (String) portletResp.encodeURL(turl);
      CompareUtils.stringsEqual("HttpServletResponse", hval, "ResourceResponse", pval, tr4);
    } catch (Exception e) {
      tr4.appendTcDetail(e.toString());
    }
    tr4.writeTo(writer);

    /* TestCase: V2DispatcherReqRespTests4_SPEC2_19_IncludeServletResourceResponse_getBufferSize */
    /* Details: "In a target servlet of a include in the Resource phase,    */
    /* the method HttpServletResponse.getBufferSize must provide the same   */
    /* functionality as ResourceResponse.getBufferSize"                     */
    TestResult tr5 =
        tcd.getTestResultFailed(
            V2DISPATCHERREQRESPTESTS4_SPEC2_19_INCLUDESERVLETRESOURCERESPONSE_GETBUFFERSIZE);
    try {
      int hval = response.getBufferSize();
      int pval = ((ResourceResponse) portletResp).getBufferSize();
      String str =
          "Value "
              + hval
              + " from "
              + "HttpServletResponse"
              + " does not equal value "
              + pval
              + " + ResourceResponse";
      if (hval != pval) {
        tr5.appendTcDetail(str);
      }
      tr5.setTcSuccess(hval == pval);
    } catch (Exception e) {
      tr5.appendTcDetail(e.toString());
    }
    tr5.writeTo(writer);

    /* TestCase: V2DispatcherReqRespTests4_SPEC2_19_IncludeServletResourceResponse_getCharacterEncoding */
    /* Details: "In a target servlet of a include in the Resource phase,    */
    /* the method HttpServletResponse.getCharacterEncoding must provide     */
    /* the same functionality as ResourceResponse.getCharacterEncoding"     */
    TestResult tr6 =
        tcd.getTestResultFailed(
            V2DISPATCHERREQRESPTESTS4_SPEC2_19_INCLUDESERVLETRESOURCERESPONSE_GETCHARACTERENCODING);
    try {
      String hval = response.getCharacterEncoding();
      String pval = ((ResourceResponse) portletResp).getCharacterEncoding();
      CompareUtils.stringsEqual("HttpServletResponse", hval, "ResourceResponse", pval, tr6);
    } catch (Exception e) {
      tr6.appendTcDetail(e.toString());
    }
    tr6.writeTo(writer);

    /* TestCase: V2DispatcherReqRespTests4_SPEC2_19_IncludeServletResourceResponse_getContentType */
    /* Details: "In a target servlet of a include in the Resource phase,    */
    /* the method HttpServletResponse.getContentType must provide the       */
    /* same functionality as ResourceResponse.getContentType"               */
    TestResult tr7 =
        tcd.getTestResultFailed(
            V2DISPATCHERREQRESPTESTS4_SPEC2_19_INCLUDESERVLETRESOURCERESPONSE_GETCONTENTTYPE);
    try {
      String hval = response.getContentType();
      String pval = ((ResourceResponse) portletResp).getContentType();
      CompareUtils.stringsEqual("HttpServletResponse", hval, "ResourceResponse", pval, tr7);
    } catch (Exception e) {
      tr7.appendTcDetail(e.toString());
    }
    tr7.writeTo(writer);

    /* TestCase: V2DispatcherReqRespTests4_SPEC2_19_IncludeServletResourceResponse_getLocale */
    /* Details: "In a target servlet of a include in the Resource phase,    */
    /* the method HttpServletResponse.getLocale must provide the same       */
    /* functionality as ResourceResponse.getLocale"                         */
    TestResult tr8 =
        tcd.getTestResultFailed(
            V2DISPATCHERREQRESPTESTS4_SPEC2_19_INCLUDESERVLETRESOURCERESPONSE_GETLOCALE);
    try {
      Locale hl = response.getLocale();
      Locale pl = ((MimeResponse) portletResp).getLocale();
      String hval = hl.getDisplayName();
      String pval = pl.getDisplayName();
      CompareUtils.stringsEqual("HttpServletResponse", hval, "ResourceResponse", pval, tr8);
    } catch (Exception e) {
      tr8.appendTcDetail(e.toString());
    }
    tr8.writeTo(writer);

    /* TestCase: V2DispatcherReqRespTests4_SPEC2_19_IncludeServletResourceResponse_isCommitted */
    /* Details: "In a target servlet of a include in the Resource phase,    */
    /* the method HttpServletResponse.isCommitted must provide the same     */
    /* functionality as ResourceResponse.isCommitted"                       */
    TestResult tr9 =
        tcd.getTestResultFailed(
            V2DISPATCHERREQRESPTESTS4_SPEC2_19_INCLUDESERVLETRESOURCERESPONSE_ISCOMMITTED);
    try {
      boolean hval = response.isCommitted();
      boolean pval = ((ResourceResponse) portletResp).isCommitted();
      String str =
          "Value "
              + hval
              + " from "
              + "HttpServletResponse"
              + " does not equal value "
              + pval
              + " + ResourceResponse";
      if (hval != pval) {
        tr9.appendTcDetail(str);
      }
      tr9.setTcSuccess(hval == pval);
    } catch (Exception e) {
      tr9.appendTcDetail(e.toString());
    }
    tr9.writeTo(writer);
  }
 public synchronized String encodeRedirectUrl(String arg0) {
   return actualResponse.encodeRedirectUrl(arg0);
 }
Exemple #6
0
 /** @deprecated */
 public String encodeRedirectUrl(String url) {
   return rawResponse.encodeRedirectUrl(url);
 }
Exemple #7
0
 public void doGet(HttpServletRequest request, HttpServletResponse response)
     throws ServletException, IOException {
   response.sendRedirect(response.encodeRedirectUrl(request.getContextPath() + "/SignIn"));
 }