Package org.apache.shindig.protocol.conversion

Examples of org.apache.shindig.protocol.conversion.BeanConverter


    if (token == null) {
      sendSecurityError(servletResponse);
      return;
    }

    BeanConverter converter = getConverterForRequest(servletRequest);

    handleSingleRequest(servletRequest, servletResponse, token, converter);
  }
View Full Code Here


    return dispatcher.getRestHandler(path, method.toUpperCase());
  }

  public BeanConverter getConverterForRequest(HttpServletRequest servletRequest) {
    String formatString = null;
    BeanConverter converter = null;
    String contentType = null;

    try {
      formatString = servletRequest.getParameter(FORMAT_PARAM);
    } catch (Throwable t) {
View Full Code Here

        LOG.fine("Unexpected error : content type is null " + t.toString());
      }
    }

    // Get BeanConverter for Request payload.
    BeanConverter requestConverter = getConverterForRequest(contentType, format);

    // Get BeanConverter for Response body.
    BeanConverter responseConverter = getConverterForFormat(format);

    Reader bodyReader = null;
    if (!servletRequest.getMethod().equals("GET") && !servletRequest.getMethod().equals("HEAD")) {
      bodyReader = servletRequest.getReader();
    }

    // Execute the request
    @SuppressWarnings("unchecked")
    Map<String, String[]> parameterMap = servletRequest.getParameterMap();
    Future<?> future = handler.execute(parameterMap, bodyReader, token, requestConverter);
    ResponseItem responseItem = getResponseItem(future);

    servletResponse.setContentType(responseConverter.getContentType());
    if (responseItem.getErrorCode() >= 200 && responseItem.getErrorCode() < 400) {
      PrintWriter writer = servletResponse.getWriter();
      Object response = responseItem.getResponse();
      // TODO: ugliness resulting from not using RestfulItem
      if (!(response instanceof DataCollection) && !(response instanceof RestfulCollection)) {
        response = ImmutableMap.of("entry", response);
      }

      // JSONP style callbacks
      String callback = (HttpUtil.isJSONP(servletRequest) &&
          ContentTypes.OUTPUT_JSON_CONTENT_TYPE.equals(responseConverter.getContentType())) ?
          servletRequest.getParameter("callback") : null;

      if (callback != null) writer.write(callback + '(');
      writer.write(responseConverter.convertToString(response));
      if (callback != null) writer.write(");\n");
    } else {
      sendError(servletResponse, responseItem);
    }
  }
View Full Code Here

        LOG.fine("Unexpected error : content type is null " + t.toString());
      }
    }

    // Get BeanConverter for Request payload.
    BeanConverter requestConverter = getConverterForRequest(contentType, format);

    // Get BeanConverter for Response body.
    BeanConverter responseConverter = getConverterForFormat(format);

    Reader bodyReader = null;
    if (!servletRequest.getMethod().equals("GET") && !servletRequest.getMethod().equals("HEAD")) {
      bodyReader = servletRequest.getReader();
    }

    // Execute the request
    @SuppressWarnings("unchecked")
    Map<String, String[]> parameterMap = servletRequest.getParameterMap();
    Future<?> future = handler.execute(parameterMap, bodyReader, token, requestConverter);
    ResponseItem responseItem = getResponseItem(future);

    servletResponse.setContentType(responseConverter.getContentType());
    if (responseItem.getErrorCode() >= 200 && responseItem.getErrorCode() < 400) {
      PrintWriter writer = servletResponse.getWriter();
      Object response = responseItem.getResponse();
      // TODO: ugliness resulting from not using RestfulItem
      if (!(response instanceof DataCollection) && !(response instanceof RestfulCollection)) {
        response = ImmutableMap.of("entry", response);
      }

      // JSONP style callbacks
      String callback = (this.isJSONPAllowed && HttpUtil.isJSONP(servletRequest) &&
          ContentTypes.OUTPUT_JSON_CONTENT_TYPE.equals(responseConverter.getContentType())) ?
          servletRequest.getParameter("callback") : null;

      if (callback != null) writer.write(callback + '(');
      writer.write(responseConverter.convertToString(response));
      if (callback != null) writer.write(");\n");
    } else {
      sendError(servletResponse, responseItem);
    }
  }
View Full Code Here

        LOG.fine("Unexpected error : content type is null " + t.toString());
      }
    }

    // Get BeanConverter for Request payload.
    BeanConverter requestConverter = getConverterForRequest(contentType, format);

    // Get BeanConverter for Response body.
    BeanConverter responseConverter = getConverterForFormat(format);

    Reader bodyReader = null;
    if (!servletRequest.getMethod().equals("GET") && !servletRequest.getMethod().equals("HEAD")) {
      bodyReader = servletRequest.getReader();
    }

    // Execute the request
    @SuppressWarnings("unchecked")
    Map<String, String[]> parameterMap = servletRequest.getParameterMap();
    Future<?> future = handler.execute(parameterMap, bodyReader, token, requestConverter);
    ResponseItem responseItem = getResponseItem(future);

    servletResponse.setContentType(responseConverter.getContentType());
    if (responseItem.getErrorCode() >= 200 && responseItem.getErrorCode() < 400) {
      PrintWriter writer = servletResponse.getWriter();
      Object response = responseItem.getResponse();
      // TODO: ugliness resulting from not using RestfulItem
      if (!(response instanceof DataCollection) && !(response instanceof RestfulCollection)) {
        response = ImmutableMap.of("entry", response);
      }

      // JSONP style callbacks
      String callback = (HttpUtil.isJSONP(servletRequest) &&
          ContentTypes.OUTPUT_JSON_CONTENT_TYPE.equals(responseConverter.getContentType())) ?
          servletRequest.getParameter("callback") : null;

      if (callback != null) writer.write(callback + '(');
      writer.write(responseConverter.convertToString(response));
      if (callback != null) writer.write(");\n");
    } else {
      sendError(servletResponse, responseItem);
    }
  }
View Full Code Here

      return;
    }

    HttpUtil.setCORSheader(servletResponse, containerConfig.<String>getList(token.getContainer(), "gadgets.parentOrigins"));

    BeanConverter converter = getConverterForRequest(servletRequest);

    handleSingleRequest(servletRequest, servletResponse, token, converter);
  }
View Full Code Here

    return dispatcher.getRestHandler(path, method.toUpperCase());
  }

  public BeanConverter getConverterForRequest(HttpServletRequest servletRequest) {
    String formatString = null;
    BeanConverter converter = null;
    String contentType = null;

    try {
      formatString = servletRequest.getParameter(FORMAT_PARAM);
    } catch (Throwable t) {
View Full Code Here

TOP

Related Classes of org.apache.shindig.protocol.conversion.BeanConverter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.