コード例 #1
0
 public static RequestParameters parseRequestWoQuery(String requestStr) {
   RequestParameters params = new RequestParameters();
   params.sessionId =
       ResponseUtils.substringBetween(requestStr, "kotlinServer&sessionId=", "&type=");
   params.type = ResponseUtils.substringBetween(requestStr, "&type=", "&args=");
   params.args = ResponseUtils.substringAfter(requestStr, "&args=");
   return params;
 }
コード例 #2
0
  private void writeResponse(
      SolrQueryResponse solrRsp, QueryResponseWriter responseWriter, Method reqMethod)
      throws IOException {
    try {
      Object invalidStates = solrReq.getContext().get(CloudSolrClient.STATE_VERSION);
      // This is the last item added to the response and the client would expect it that way.
      // If that assumption is changed , it would fail. This is done to avoid an O(n) scan on
      // the response for each request
      if (invalidStates != null) solrRsp.add(CloudSolrClient.STATE_VERSION, invalidStates);
      // Now write it out
      final String ct = responseWriter.getContentType(solrReq, solrRsp);
      // don't call setContentType on null
      if (null != ct) response.setContentType(ct);

      if (solrRsp.getException() != null) {
        NamedList info = new SimpleOrderedMap();
        int code = ResponseUtils.getErrorInfo(solrRsp.getException(), info, log);
        solrRsp.add("error", info);
        response.setStatus(code);
      }

      if (Method.HEAD != reqMethod) {
        OutputStream out =
            new CloseShieldOutputStream(
                response.getOutputStream()); // Prevent close of container streams, see SOLR-8933
        QueryResponseWriterUtil.writeQueryResponse(out, responseWriter, solrReq, solrRsp, ct);
      }
      // else http HEAD request, nothing to write out, waited this long just to get ContentType
    } catch (EOFException e) {
      log.info("Unable to write response, client closed connection or we are shutting down", e);
    }
  }
コード例 #3
0
 /**
  * 生成验证码
  *
  * @param req
  * @param res
  * @throws IOException
  */
 public void get(HttpServletRequest request, HttpServletResponse response) throws IOException {
   if (RequestUtils.isRobot(request)) {
     return;
   }
   ResponseUtils.closeCache(response);
   response.setContentType("image/png");
   _render(_generateRegKey(request, response), response.getOutputStream(), WIDTH, HEIGHT);
 }
コード例 #4
0
  /**
   * @param verb
   * @param url
   * @return {@link Response}
   * @throws TwitterException si la response est <code>null</code> ou si son code est différent de
   *     200
   */
  public static Response getResponse(Verb verb, String url) throws TwitterException {

    Response response = getRequestSigned(verb, url).send();

    ResponseUtils.validateResponse(response);

    return response;
  }
コード例 #5
0
 protected void sendError(Throwable ex) throws IOException {
   Exception exp = null;
   SolrCore localCore = null;
   try {
     SolrQueryResponse solrResp = new SolrQueryResponse();
     if (ex instanceof Exception) {
       solrResp.setException((Exception) ex);
     } else {
       solrResp.setException(new RuntimeException(ex));
     }
     localCore = core;
     if (solrReq == null) {
       final SolrParams solrParams;
       if (req != null) {
         // use GET parameters if available:
         solrParams = SolrRequestParsers.parseQueryString(req.getQueryString());
       } else {
         // we have no params at all, use empty ones:
         solrParams = new MapSolrParams(Collections.<String, String>emptyMap());
       }
       solrReq = new SolrQueryRequestBase(core, solrParams) {};
     }
     QueryResponseWriter writer = core.getQueryResponseWriter(solrReq);
     writeResponse(solrResp, writer, Method.GET);
   } catch (Exception e) { // This error really does not matter
     exp = e;
   } finally {
     try {
       if (exp != null) {
         SimpleOrderedMap info = new SimpleOrderedMap();
         int code = ResponseUtils.getErrorInfo(ex, info, log);
         sendError(code, info.toString());
       }
     } finally {
       if (core == null && localCore != null) {
         localCore.close();
       }
     }
   }
 }
コード例 #6
0
  @Override
  public RestLiResponseEnvelope buildRestLiResponseData(
      RestRequest request,
      RoutingResult routingResult,
      Object result,
      Map<String, String> headers,
      List<HttpCookie> cookies) {
    if (result instanceof BatchCreateKVResult) {
      BatchCreateKVResult<?, ?> list = (BatchCreateKVResult<?, ?>) result;
      if (list.getResults() == null) {
        throw new RestLiServiceException(
            HttpStatus.S_500_INTERNAL_SERVER_ERROR,
            "Unexpected null encountered. Null List inside of a BatchCreateKVResult returned by the resource method: "
                + routingResult.getResourceMethod());
      }
      List<CreateCollectionResponseEnvelope.CollectionCreateResponseItem> collectionCreateList =
          new ArrayList<CreateCollectionResponseEnvelope.CollectionCreateResponseItem>(
              list.getResults().size());

      for (CreateKVResponse e : list.getResults()) {
        if (e == null) {
          throw new RestLiServiceException(
              HttpStatus.S_500_INTERNAL_SERVER_ERROR,
              "Unexpected null encountered. Null element inside of List inside of a BatchCreateResult returned by the resource method: "
                  + routingResult.getResourceMethod());
        } else {
          Object id =
              ResponseUtils.translateCanonicalKeyToAlternativeKeyIfNeeded(e.getId(), routingResult);
          if (e.getError() == null) {
            CreateIdEntityStatus<Object, RecordTemplate> entry =
                new CreateIdEntityStatus<Object, RecordTemplate>(
                    e.getStatus().getCode(),
                    id,
                    e.getEntity(),
                    null,
                    ProtocolVersionUtil.extractProtocolVersion(headers));
            collectionCreateList.add(
                new CreateCollectionResponseEnvelope.CollectionCreateResponseItem(entry));
          } else {
            collectionCreateList.add(
                new CreateCollectionResponseEnvelope.CollectionCreateResponseItem(
                    e.getError(), id));
          }
        }
      }
      return new CreateCollectionResponseEnvelope(collectionCreateList, headers, cookies);
    } else {
      BatchCreateResult<?, ?> list = (BatchCreateResult<?, ?>) result;

      // Verify that a null list was not passed into the BatchCreateResult. If so, this is a
      // developer error.
      if (list.getResults() == null) {
        throw new RestLiServiceException(
            HttpStatus.S_500_INTERNAL_SERVER_ERROR,
            "Unexpected null encountered. Null List inside of a BatchCreateResult returned by the resource method: "
                + routingResult.getResourceMethod());
      }

      List<CreateCollectionResponseEnvelope.CollectionCreateResponseItem> collectionCreateList =
          new ArrayList<CreateCollectionResponseEnvelope.CollectionCreateResponseItem>(
              list.getResults().size());
      for (CreateResponse e : list.getResults()) {
        // Verify that a null element was not passed into the BatchCreateResult list. If so, this is
        // a developer error.
        if (e == null) {
          throw new RestLiServiceException(
              HttpStatus.S_500_INTERNAL_SERVER_ERROR,
              "Unexpected null encountered. Null element inside of List inside of a BatchCreateResult returned by the resource method: "
                  + routingResult.getResourceMethod());
        } else {
          Object id =
              ResponseUtils.translateCanonicalKeyToAlternativeKeyIfNeeded(e.getId(), routingResult);
          if (e.getError() == null) {
            CreateIdStatus<Object> entry =
                new CreateIdStatus<Object>(
                    e.getStatus().getCode(),
                    id,
                    null,
                    ProtocolVersionUtil.extractProtocolVersion(headers));
            collectionCreateList.add(
                new CreateCollectionResponseEnvelope.CollectionCreateResponseItem(entry));
          } else {
            collectionCreateList.add(
                new CreateCollectionResponseEnvelope.CollectionCreateResponseItem(
                    e.getError(), id));
          }
        }
      }

      return new CreateCollectionResponseEnvelope(collectionCreateList, headers, cookies);
    }
  }
コード例 #7
0
ファイル: NumberSelectTag.java プロジェクト: dalinhuang/nymis
  /*
   * (non-Javadoc)
   *
   * @see javax.servlet.jsp.tagext.TagSupport#doStartTag()
   */
  @Override
  public int doStartTag() throws JspException {
    log.debug(this);

    StringBuffer str = new StringBuffer("<select ");
    if (name != null) {
      str.append("name=\"" + name + "\" ");
    }

    if (id != null) {
      str.append("id=\"" + id + "\" ");
    }

    if (multiple != null) {
      str.append("mutiple=\"" + multiple + "\" ");
    }

    if (size != null) {
      str.append("size=\"" + size + "\" ");
    }

    if (style != null) {
      str.append("style=\"" + style + "\"");
    }

    if (disable != null) {
      str.append("style=\"" + disable + "\"");
    }

    if (onChange != null) {
      str.append("onChange=\"" + onChange + "\"");
    }

    str.append(">\n");

    int start = 0;
    int end = 0;
    int length = 0;
    int value = 0;

    if (this.start != null) {
      start = Integer.parseInt(this.start);
    }
    if (this.end != null) {
      end = Integer.parseInt(this.end);
    }
    if (this.length != null) {
      length = Integer.parseInt(this.length);
    }
    log.debug("this.value=" + this.value);
    if (this.value != null) {
      value = Integer.parseInt(this.value);
    }

    str.append(nullOption);

    // 目前只支持升序降序两种方法,将不为升序的sort字符串赋值为降序
    if (!S_ASCE.equals(sort)) {
      sort = S_DESC;
    }

    // 初始化current
    if (S_DESC.equals(sort)) {
      current = end;
    } else {
      current = start;
    }

    if (length == 0) {
      length = end - start + 1;
    }

    for (int i = 0; i < length; i++) {
      int n = getNext();
      str.append("<option value=\"" + n);

      log.debug("value=" + value);
      log.debug("n=" + n);

      str.append("\"");
      if (value == n) {
        str.append(" selected ");
      }
      str.append(">");

      if (prefix != null) {
        str.append(prefix);
      }

      str.append(n);

      if (suffix != null) {
        str.append(suffix);
      }

      str.append("</option>\n");
    }

    str.append("</select>");

    log.debug("General number select html:\n" + str);

    ResponseUtils.write(pageContext, str.toString());

    return EVAL_BODY_INCLUDE;
  }