Package com.linkedin.r2.message.rest

Examples of com.linkedin.r2.message.rest.RestRequest


  @Test
  public void testTunneledPut() throws Exception
  {
    // Just test another request type
    RestRequest request = new RestRequestBuilder(new URI("http://localhost:7279?q=one&x=10&y=15"))
                                       .setMethod("PUT")
                                       .setEntity(new String("{\name\":\"value\"}").getBytes())
                                       .setHeader("Content-Type", "application/json").build();

    RestRequest tunneled = QueryTunnelUtil.decode(QueryTunnelUtil.encode(request, 0));
    Assert.assertEquals(request.getURI(), tunneled.getURI());
    Assert.assertEquals(request.getMethod(), tunneled.getMethod());
    Assert.assertEquals(request.getEntity(), tunneled.getEntity());
    Assert.assertEquals(request.getHeader("Content-Type"), tunneled.getHeader("Content-Type"));
  }
View Full Code Here


  public void testTunneledMissingContentType() throws Exception
  {
    // When using R2 to encode, there should always be a Content-Type in any encoded request
    // But someone could hand-construct a query without one, so test that we catch it and throw an
    // exception
    RestRequest request = new RestRequestBuilder(new URI("http://localhost:7279?q=one&x=10&y=15"))
        .setMethod("PUT")
        .setEntity(new String("{\"name\":\"value\"}").getBytes()).build();

    try {
      // Should fail because there is no Content-Type specified
View Full Code Here

  @Test
  public void testTunneledHandConstructedOverride() throws Exception
  {
    // Example of a hand-constructed "encoded" request
    RestRequest request = new RestRequestBuilder(new URI("http://localhost:7279"))
        .setMethod("POST")
        .setHeader("X-HTTP-Method-Override", "GET")
        .setHeader("Content-Type", "application/x-www-form-urlencoded")
        .setEntity(new String("q=123").getBytes()).build();

    RestRequest decoded = QueryTunnelUtil.decode(request);
    Assert.assertEquals(decoded.getURI().toString(), "http://localhost:7279?q=123");
    Assert.assertEquals(decoded.getMethod(), "GET");
  }
View Full Code Here

    ByteArrayOutputStream os = new ByteArrayOutputStream();
    multi.writeTo(os);

    // Create request with multi-part body and query args
    RestRequest request = new RestRequestBuilder(new URI("http://localhost:7279?args=xyz"))
        .setMethod("PUT")
        .setHeader("Content-Type", multi.getContentType())
        .setEntity(ByteString.copy(os.toByteArray())).build();

    // Encode and verify
    RestRequest encoded = QueryTunnelUtil.encode(request, 0);
    Assert.assertEquals(encoded.getMethod(), "POST");
    Assert.assertEquals(encoded.getURI().toString(), "http://localhost:7279");
    Assert.assertTrue(encoded.getEntity().length() > 0);
    Assert.assertTrue(encoded.getHeader("Content-Type").startsWith("multipart/mixed"));

    // Decode and make sure we have the original request back
    RestRequest decoded = QueryTunnelUtil.decode(request);
    Assert.assertEquals(decoded.getURI().toString(), "http://localhost:7279?args=xyz");
    Assert.assertEquals(decoded.getMethod(), "PUT");
    Assert.assertEquals(decoded.getEntity(), request.getEntity());
    Assert.assertTrue(encoded.getHeader("Content-Type").startsWith("multipart/mixed"));
  }
View Full Code Here

    String query= "q=queryString";
    for(int i=0; i<10000; i++)
      query += "&a="+i;

    RestRequest request = new RestRequestBuilder(new URI("http://localhost:7279?" + query))
                                      .setMethod("GET").build();

    RestRequest encoded = QueryTunnelUtil.encode(request, query.length()-1)// Set threshold < query length
    Assert.assertEquals(encoded.getMethod(), "POST");
    Assert.assertEquals(encoded.getURI().toString(), "http://localhost:7279");
    Assert.assertTrue(encoded.getEntity().length() == query.length());
    Assert.assertEquals(encoded.getHeader("Content-Type"), "application/x-www-form-urlencoded");

    RestRequest decoded = QueryTunnelUtil.decode(encoded);
    Assert.assertEquals(decoded.getURI(), request.getURI());
    Assert.assertEquals(decoded.getMethod(), "GET");
  }
View Full Code Here

    // we re-append the query correctly
    // This test is motivated by some test frameworks that add params to queries in EI

    String query= "q=queryString&a=1&b=2";

    RestRequest request = new RestRequestBuilder(new URI("http://localhost:7279?" + query))
        .setMethod("GET").build();

    RestRequest encoded = QueryTunnelUtil.encode(request, query.length()-1)// Set threshold < query length
    Assert.assertEquals(encoded.getMethod(), "POST");
    Assert.assertEquals(encoded.getURI().toString(), "http://localhost:7279");
    Assert.assertTrue(encoded.getEntity().length() == query.length());
    Assert.assertEquals(encoded.getHeader("Content-Type"), "application/x-www-form-urlencoded");

    RestRequestBuilder rb = encoded.builder()
                             .setURI(new URI(encoded.getURI().toString() + "?"));
    RestRequest modified = rb.build();

    RestRequest decoded = QueryTunnelUtil.decode(modified);
    Assert.assertEquals(decoded.getURI().toString(), "http://localhost:7279?" + query);
  }
View Full Code Here

    // Test case where someone has added a query param to the request underneath us
    // This test is motivated by some test frameworks that add params to queries in EI

    String query= "q=queryString&a=1&b=2";

    RestRequest request = new RestRequestBuilder(new URI("http://localhost:7279?" + query))
        .setMethod("GET").build();

    RestRequest encoded = QueryTunnelUtil.encode(request, query.length()-1)// Set threshold < query length
    Assert.assertEquals(encoded.getMethod(), "POST");
    Assert.assertEquals(encoded.getURI().toString(), "http://localhost:7279");
    Assert.assertTrue(encoded.getEntity().length() == query.length());
    Assert.assertEquals(encoded.getHeader("Content-Type"), "application/x-www-form-urlencoded");

    RestRequestBuilder rb = encoded.builder()
        .setURI(new URI(encoded.getURI().toString() + "?uh=f"));
    RestRequest modified = rb.build();

    RestRequest decoded = QueryTunnelUtil.decode(modified);
    Assert.assertEquals(decoded.getURI().toString(), "http://localhost:7279?uh=f&" + query);
  }
View Full Code Here

  @Test
  public void testEmptyArgsQuery() throws Exception
  {
    // test query with "?" but nothing after it

    RestRequest request = new RestRequestBuilder(new URI("http://localhost:7279/foo?"))
        .setMethod("GET").build();

    RestRequest encoded = QueryTunnelUtil.encode(request, 0);
    Assert.assertEquals(encoded.getMethod(), "GET"); // SHould not actually encode this case
    Assert.assertEquals(encoded.getURI().toString(), "http://localhost:7279/foo?");

    RestRequest decoded = QueryTunnelUtil.decode(encoded);
    Assert.assertEquals(decoded.getURI().toString(), "http://localhost:7279/foo?");
  }
View Full Code Here

  @Test(dataProvider = "data")
  public void test(String compressionConfig, String[] operations, boolean headerShouldBePresent)
      throws URISyntaxException
  {
    RestRequest restRequest = new RestRequestBuilder(new URI(URI)).build();
    ClientCompressionFilter clientCompressionFilter = new ClientCompressionFilter(EncodingType.IDENTITY.getHttpName(),
                                                                                  ACCEPT_COMPRESSIONS,
                                                                                  Arrays.asList(compressionConfig.split(",")));

    for (String operation: operations)
View Full Code Here

  {
    Map<String, ResourceModel> pathRootResourceMap = buildResourceModels(StatusCollectionResource.class);
    _router = new RestLiRouter(pathRootResourceMap);

    // #1 simple GET
    RestRequest request = createRequest(uri, "GET", version);

    RoutingResult result = _router.process(request, new RequestContext());
    assertNotNull(result);

    ResourceMethodDescriptor resourceMethodDescriptor = result.getResourceMethod();
View Full Code Here

TOP

Related Classes of com.linkedin.r2.message.rest.RestRequest

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.