/**
   * Whether the original request received by the synapse is REST
   *
   * @param originalInMsgCtx request message
   * @return <code>true</code> if the request was a REST request
   */
  private static boolean isRequestRest(MessageContext originalInMsgCtx) {

    boolean isRestRequest =
        originalInMsgCtx.getProperty(NhttpConstants.REST_REQUEST_CONTENT_TYPE) != null;

    if (!isRestRequest) {

      String httpMethod =
          (String) originalInMsgCtx.getProperty(Constants.Configuration.HTTP_METHOD);

      isRestRequest =
          Constants.Configuration.HTTP_METHOD_GET.equals(httpMethod)
              || Constants.Configuration.HTTP_METHOD_DELETE.equals(httpMethod)
              || Constants.Configuration.HTTP_METHOD_PUT.equals(httpMethod)
              || RESTConstants.METHOD_OPTIONS.equals(httpMethod)
              || Constants.Configuration.HTTP_METHOD_HEAD.equals(httpMethod);

      if (!isRestRequest) {

        isRestRequest =
            Constants.Configuration.HTTP_METHOD_POST.equals(httpMethod)
                && HTTPTransportUtils.isRESTRequest(
                    String.valueOf(
                        originalInMsgCtx.getProperty(Constants.Configuration.MESSAGE_TYPE)));

        if (!isRestRequest) {
          isRestRequest =
              (String.valueOf(originalInMsgCtx.getProperty(Constants.Configuration.MESSAGE_TYPE))
                      .equals(HTTPConstants.MEDIA_TYPE_TEXT_XML)
                  && originalInMsgCtx.getSoapAction() == null);
        }
      }
    }
    return isRestRequest;
  }
Пример #2
0
  private void processEntityEnclosingMethod() {

    try {
      Header contentType = request.getFirstHeader(HTTP.CONTENT_TYPE);
      String contentTypeStr = contentType != null ? contentType.getValue() : inferContentType();

      String charSetEncoding = BuilderUtil.getCharSetEncoding(contentTypeStr);
      msgContext.setProperty(Constants.Configuration.CHARACTER_SET_ENCODING, charSetEncoding);

      if (HTTPTransportUtils.isRESTRequest(contentTypeStr) || isRest(contentTypeStr)) {
        RESTUtil.processPOSTRequest(
            msgContext, is, os, request.getRequestLine().getUri(), contentType, isRestDispatching);
      } else {

        Header soapAction = request.getFirstHeader(SOAPACTION);
        HTTPTransportUtils.processHTTPPostRequest(
            msgContext,
            is,
            os,
            contentTypeStr,
            (soapAction != null ? soapAction.getValue() : null),
            request.getRequestLine().getUri());
      }

    } catch (Exception e) {
      handleException("Error processing POST request ", e);
    }
  }