コード例 #1
0
 private String getLogoutSuccessResponse(String responseType) {
   StringBuffer sb = new StringBuffer();
   if (BaseCmd.RESPONSE_TYPE_JSON.equalsIgnoreCase(responseType)) {
     sb.append("{ \"logoutresponse\" : { \"description\" : \"success\" } }");
   } else {
     sb.append("<logoutresponse><description>success</description></logoutresponse>");
   }
   return sb.toString();
 }
コード例 #2
0
  // FIXME: rather than isError, we might was to pass in the status code to give more flexibility
  private void writeResponse(
      HttpServletResponse resp, String response, int responseCode, String responseType) {
    try {
      if (BaseCmd.RESPONSE_TYPE_JSON.equalsIgnoreCase(responseType)) {
        resp.setContentType(ApiServer.jsonContentType + "; charset=UTF-8");
      } else {
        resp.setContentType("text/xml; charset=UTF-8");
      }

      resp.setStatus(responseCode);
      resp.getWriter().print(response);
    } catch (IOException ioex) {
      if (s_logger.isTraceEnabled()) {
        s_logger.trace("exception writing response: " + ioex);
      }
    } catch (Exception ex) {
      if (!(ex instanceof IllegalStateException)) {
        s_logger.error("unknown exception writing api response", ex);
      }
    }
  }
コード例 #3
0
  @SuppressWarnings("rawtypes")
  private String getLoginSuccessResponse(HttpSession session, String responseType) {
    StringBuffer sb = new StringBuffer();
    int inactiveInterval = session.getMaxInactiveInterval();

    if (BaseCmd.RESPONSE_TYPE_JSON.equalsIgnoreCase(responseType)) {
      sb.append("{ \"loginresponse\" : { ");
      Enumeration attrNames = session.getAttributeNames();
      if (attrNames != null) {
        sb.append("\"timeout\" : \"" + inactiveInterval + "\"");
        while (attrNames.hasMoreElements()) {
          String attrName = (String) attrNames.nextElement();
          Object attrObj = session.getAttribute(attrName);
          if ((attrObj instanceof String) || (attrObj instanceof Long)) {
            sb.append(", \"" + attrName + "\" : \"" + attrObj.toString() + "\"");
          }
        }
      }
      sb.append(" } }");
    } else {
      sb.append("<loginresponse>");
      sb.append("<timeout>" + inactiveInterval + "</timeout>");
      Enumeration attrNames = session.getAttributeNames();
      if (attrNames != null) {
        while (attrNames.hasMoreElements()) {
          String attrName = (String) attrNames.nextElement();
          Object attrObj = session.getAttribute(attrName);
          if (attrObj instanceof String || attrObj instanceof Long || attrObj instanceof Short) {
            sb.append("<" + attrName + ">" + attrObj.toString() + "</" + attrName + ">");
          }
        }
      }

      sb.append("</loginresponse>");
    }
    return sb.toString();
  }
コード例 #4
0
  // FIXME: rather than isError, we might was to pass in the status code to give more flexibility
  private void writeResponse(
      HttpResponse resp,
      final String responseText,
      final int statusCode,
      String responseType,
      String reasonPhrase) {
    try {
      resp.setStatusCode(statusCode);
      resp.setReasonPhrase(reasonPhrase);

      BasicHttpEntity body = new BasicHttpEntity();
      if (BaseCmd.RESPONSE_TYPE_JSON.equalsIgnoreCase(responseType)) {
        // JSON response
        body.setContentType(jsonContentType);
        if (responseText == null) {
          body.setContent(
              new ByteArrayInputStream(
                  "{ \"error\" : { \"description\" : \"Internal Server Error\" } }"
                      .getBytes("UTF-8")));
        }
      } else {
        body.setContentType("text/xml");
        if (responseText == null) {
          body.setContent(
              new ByteArrayInputStream("<error>Internal Server Error</error>".getBytes("UTF-8")));
        }
      }

      if (responseText != null) {
        body.setContent(new ByteArrayInputStream(responseText.getBytes("UTF-8")));
      }
      resp.setEntity(body);
    } catch (Exception ex) {
      s_logger.error("error!", ex);
    }
  }