Package com.google.greaze.definition

Examples of com.google.greaze.definition.HeaderMapSpec


  @Override
  public RestResponseBase<I, R> receive(HttpURLConnection conn) {
    try {
      handleResponseCode(conn);
      HeaderMapSpec paramSpec = getSpec().getHeadersSpec();
      Type bodyType = getSpec().getResourceType();
      // read response
      HeaderMap responseParams = readResponseHeaders(conn, paramSpec);
      R responseBody = readResponseBody(conn, bodyType);
      return new RestResponseBase<I, R>(getSpec(), responseParams, responseBody);
View Full Code Here


    return converter.getMap();
  }

  private Map<String, String> getAsStringMap(HeaderMap requestParams) {
    Map<String, String> map = new HashMap<String, String>();
    HeaderMapSpec spec = requestParams.getSpec();
    for (Map.Entry<String, Object> entry : requestParams.entrySet()) {
      String paramName = entry.getKey();
      Type type = spec.getTypeFor(paramName);
      Object value = entry.getValue();
      String json = stripEnclosingQuotes(gson.toJson(value, type));
      map.put(paramName, json);
    }
    return map;
View Full Code Here

      addComposite(null, urlParams.getParamsObject(), spec.getType());
    }
  }

  public void add(HeaderMap urlParamsMap) {
    HeaderMapSpec spec = urlParamsMap.getSpec();
    for (Map.Entry<String, Object> entry : urlParamsMap.entrySet()) {
      Object value = entry.getValue();
      String paramName = entry.getKey();
      Type type = spec.getTypeFor(paramName);
      addComposite(paramName, value, type);
    }
  }
View Full Code Here

  }
 
  public WebServiceResponse receive(HttpURLConnection conn) {
    try {
      handleResponseCode(conn);
      HeaderMapSpec paramSpec = spec.getHeadersSpec();
      ResponseBodySpec bodySpec = spec.getBodySpec();
      // read response
      HeaderMap responseParams = readResponseHeaders(conn, paramSpec);
      ResponseBody responseBody = readResponseBody(conn, bodySpec);
      return new WebServiceResponse(responseParams, responseBody);
View Full Code Here

* @author Inderjeet Singh
*/
public class RequestReceiverTest extends TestCase {
 
  public void testUrlParams() {
    HeaderMapSpec headersSpec = new HeaderMapSpec.Builder().build();
    UrlParamsSpec urlParamSpec = new UrlParamsSpec.Builder().put("foo", String.class).build();
    RequestBodySpec bodySpec = new RequestBodySpec.Builder().build();
    RequestSpec spec = new RequestSpec(headersSpec, urlParamSpec, bodySpec);
    RequestReceiver receiver = new RequestReceiver(new GsonBuilder(), spec);
    HttpServletRequest req = new HttpServletRequestFake()
View Full Code Here

    ResourceQueryParams queryParams =
      (ResourceQueryParams) webServiceRequest.getUrlParameters().getParamsObject();
    WebContext context = new WebContextExtractor(webContextSpec).extract(webServiceRequest.getHeaders());
    List results = resourceQuery.query(queryParams, context);
    HeaderMapSpec headerSpec = new HeaderMapSpec.Builder().build();
    HeaderMap responseHeaders = new HeaderMap.Builder(headerSpec).build();
    ResponseBodySpec bodySpec = new ResponseBodySpec.Builder()
      .setListBody(resourceQuery.getResourceType())
      .build();
    ResponseBody responseBody = new ResponseBody.Builder(bodySpec)
View Full Code Here

    super.setUp();
    sender = new RequestSender(new Gson());
  }

  public void testContentTypeHeaderSkippedForGetAndDelete() {
    HeaderMapSpec requestHeaderSpec = new HeaderMapSpec.Builder().build();
    HeaderMap requestHeaders = new HeaderMap.Builder(requestHeaderSpec).build();
    RequestBodySpec requestBodySpec = new RequestBodySpec.Builder()
      .setSimpleBody(String.class)
      .build();
    RequestBody requestBody = new RequestBody.Builder(requestBodySpec).build();
View Full Code Here

      assertNull(conn.getHeaders().get("Content-Type"));
    }
  }

  public void testBodyAndContentTypeHeaderForPostAndPut() {
    HeaderMapSpec requestHeaderSpec = new HeaderMapSpec.Builder().build();
    HeaderMap requestHeaders = new HeaderMap.Builder(requestHeaderSpec).build();
    RequestBodySpec requestBodySpec = new RequestBodySpec.Builder()
      .setSimpleBody(String.class)
      .build();
    RequestBody requestBody = new RequestBody.Builder(requestBodySpec)
View Full Code Here

      assertEquals("hello world", conn.getBodyAsString());
    }
  }

  public void testStringAndPrimitiveValueHeader() {
    HeaderMapSpec requestHeaderSpec = new HeaderMapSpec.Builder()
      .put("X-Name", String.class)
      .put("X-Salary", Integer.class)
      .build();
    HeaderMap requestHeaders = new HeaderMap.Builder(requestHeaderSpec)
      .put("X-Name", "bob")
View Full Code Here

    assertEquals("bob", conn.getHeaders().get("X-Name"));
    assertEquals("10000", conn.getHeaders().get("X-Salary"));
  }

  public void testJsonValueHeader() {
    HeaderMapSpec requestHeaderSpec = new HeaderMapSpec.Builder()
      .put("X-Number", ComplexNumber.class)
      .build();
    HeaderMap requestHeaders = new HeaderMap.Builder(requestHeaderSpec)
      .put("X-Number", new ComplexNumber(10, 3))
      .build();
View Full Code Here

TOP

Related Classes of com.google.greaze.definition.HeaderMapSpec

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.