Java Code Examples for org.eclipse.jetty.http.HttpTester#newRequest()

The following examples show how to use org.eclipse.jetty.http.HttpTester#newRequest() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ServletTestUtils.java    From java-slack-sdk with MIT License 6 votes vote down vote up
public static HttpTester.Request prepareRequest(String signingSecret, String requestBody) {
    HttpTester.Request request = HttpTester.newRequest();
    request.setMethod("POST");
    request.setHeader("Host", "tester"); // must be "tester"
    request.setURI("/");
    request.setVersion("HTTP/1.1");
    request.setHeader("content-type", "application/json");
    request.setHeader("Connection", "close");
    String timestamp = String.valueOf((System.currentTimeMillis() / 1000));
    SlackSignature.Generator signatureGenerator = new SlackSignature.Generator(signingSecret);
    String signature = signatureGenerator.generate(timestamp, requestBody);
    request.setHeader(SlackSignature.HeaderNames.X_SLACK_REQUEST_TIMESTAMP, timestamp);
    request.setHeader(SlackSignature.HeaderNames.X_SLACK_SIGNATURE, signature);
    request.setContent(requestBody);
    return request;
}
 
Example 2
Source File: TestUtils.java    From java-slack-sdk with MIT License 5 votes vote down vote up
public static HttpTester.Request prepareRequest() {
    HttpTester.Request request = HttpTester.newRequest();
    request.setMethod("POST");
    request.setHeader("Host", "tester"); // must be "tester"
    request.setURI("/");
    request.setVersion("HTTP/1.1");
    request.setHeader("content-type", "application/json");
    request.setHeader("Connection", "close");
    return request;
}
 
Example 3
Source File: WebEndpointTest.java    From java-slack-sdk with MIT License 5 votes vote down vote up
private HttpTester.Request buildRequest(String method, String uri) {
    HttpTester.Request request = HttpTester.newRequest();
    request.setMethod(method);
    request.setHeader("Host", "tester"); // must be "tester"
    request.setURI(uri);
    request.setVersion("HTTP/1.1");
    request.setHeader("Connection", "close");
    return request;
}
 
Example 4
Source File: EventsApiHandlerTest.java    From java-slack-sdk with MIT License 5 votes vote down vote up
private static HttpTester.Request prepareRequest() {
    HttpTester.Request request = HttpTester.newRequest();
    request.setMethod("POST");
    request.setHeader("Host", "tester"); // should be "tester"
    request.setURI("/");
    request.setVersion("HTTP/1.1");
    request.setHeader("content-type", "application/json");
    request.setHeader("Connection", "close");
    return request;
}
 
Example 5
Source File: UsernameFunctionProcessorTest.java    From knox with Apache License 2.0 5 votes vote down vote up
private void testSetup(String username, Map<String,String> initParams ) throws Exception {
  String descriptorUrl = getTestResource( "rewrite.xml" ).toExternalForm();

  Log.setLog( new NoOpLogger() );

  server = new ServletTester();
  server.setContextPath( "/" );
  server.getContext().addEventListener( new UrlRewriteServletContextListener() );
  server.getContext().setInitParameter(
      UrlRewriteServletContextListener.DESCRIPTOR_LOCATION_INIT_PARAM_NAME, descriptorUrl );

  FilterHolder setupFilter = server.addFilter( SetupFilter.class, "/*", EnumSet.of( DispatcherType.REQUEST ) );
  setupFilter.setFilter( new SetupFilter( username ) );
  FilterHolder rewriteFilter = server.addFilter( UrlRewriteServletFilter.class, "/*", EnumSet.of( DispatcherType.REQUEST ) );
  if( initParams != null ) {
    for( Map.Entry<String,String> entry : initParams.entrySet() ) {
      rewriteFilter.setInitParameter( entry.getKey(), entry.getValue() );
    }
  }
  rewriteFilter.setFilter( new UrlRewriteServletFilter() );

  interactions = new ArrayDeque<>();

  ServletHolder servlet = server.addServlet( MockServlet.class, "/" );
  servlet.setServlet( new MockServlet( "mock-servlet", interactions ) );

  server.start();

  interaction = new MockInteraction();
  request = HttpTester.newRequest();
  response = null;
}
 
Example 6
Source File: UrlRewriteServletFilterTest.java    From knox with Apache License 2.0 5 votes vote down vote up
private void testSetUp(Map<String,String> initParams ) throws Exception {
  String descriptorUrl = getTestResource( "rewrite.xml" ).toExternalForm();

  server = new ServletTester();
  server.setContextPath( "/" );
  server.getContext().addEventListener( new UrlRewriteServletContextListener() );
  server.getContext().setInitParameter(
      UrlRewriteServletContextListener.DESCRIPTOR_LOCATION_INIT_PARAM_NAME, descriptorUrl );

  FilterHolder setupFilter = server.addFilter( SetupFilter.class, "/*", EnumSet.of( DispatcherType.REQUEST ) );
  setupFilter.setFilter( new SetupFilter() );
  FilterHolder rewriteFilter = server.addFilter( UrlRewriteServletFilter.class, "/*", EnumSet.of( DispatcherType.REQUEST ) );
  if( initParams != null ) {
    for( Map.Entry<String,String> entry : initParams.entrySet() ) {
      rewriteFilter.setInitParameter( entry.getKey(), entry.getValue() );
    }
  }
  rewriteFilter.setFilter( new UrlRewriteServletFilter() );

  interactions = new ArrayDeque<>();

  ServletHolder servlet = server.addServlet( MockServlet.class, "/" );
  servlet.setServlet( new MockServlet( "mock-servlet", interactions ) );

  server.start();

  interaction = new MockInteraction();
  request = HttpTester.newRequest();
  response = null;
}
 
Example 7
Source File: ServiceRegistryFunctionsTest.java    From knox with Apache License 2.0 4 votes vote down vote up
private void testSetup(String username, Map<String,String> initParams ) throws Exception {
  ServiceRegistry mockServiceRegistry = EasyMock.createNiceMock( ServiceRegistry.class );
  EasyMock.expect( mockServiceRegistry.lookupServiceURL( "test-cluster", "NAMENODE" ) ).andReturn( "test-nn-scheme://test-nn-host:411" ).anyTimes();
  EasyMock.expect( mockServiceRegistry.lookupServiceURL( "test-cluster", "JOBTRACKER" ) ).andReturn( "test-jt-scheme://test-jt-host:511" ).anyTimes();

  GatewayServices mockGatewayServices = EasyMock.createNiceMock( GatewayServices.class );
  EasyMock.expect( mockGatewayServices.getService(ServiceType.SERVICE_REGISTRY_SERVICE) ).andReturn( mockServiceRegistry ).anyTimes();

  EasyMock.replay( mockServiceRegistry, mockGatewayServices );

  String descriptorUrl = getTestResource( "rewrite.xml" ).toExternalForm();

  Log.setLog( new NoOpLogger() );

  server = new ServletTester();
  server.setContextPath( "/" );
  server.getContext().addEventListener( new UrlRewriteServletContextListener() );
  server.getContext().setInitParameter(
      UrlRewriteServletContextListener.DESCRIPTOR_LOCATION_INIT_PARAM_NAME, descriptorUrl );
  server.getContext().setAttribute( GatewayServices.GATEWAY_CLUSTER_ATTRIBUTE, "test-cluster" );
  server.getContext().setAttribute( GatewayServices.GATEWAY_SERVICES_ATTRIBUTE, mockGatewayServices );

  FilterHolder setupFilter = server.addFilter( SetupFilter.class, "/*", EnumSet.of( DispatcherType.REQUEST ) );
  setupFilter.setFilter( new SetupFilter( username ) );
  FilterHolder rewriteFilter = server.addFilter( UrlRewriteServletFilter.class, "/*", EnumSet.of( DispatcherType.REQUEST ) );
  if( initParams != null ) {
    for( Map.Entry<String,String> entry : initParams.entrySet() ) {
      rewriteFilter.setInitParameter( entry.getKey(), entry.getValue() );
    }
  }
  rewriteFilter.setFilter( new UrlRewriteServletFilter() );

  interactions = new ArrayDeque<>();

  ServletHolder servlet = server.addServlet( MockServlet.class, "/" );
  servlet.setServlet( new MockServlet( "mock-servlet", interactions ) );

  server.start();

  interaction = new MockInteraction();
  request = HttpTester.newRequest();
  response = null;
}
 
Example 8
Source File: FrontendFunctionProcessorTest.java    From knox with Apache License 2.0 4 votes vote down vote up
private void testSetup(String username, Map<String, String> initParams, Attributes attributes) throws Exception {
  ServiceRegistry mockServiceRegistry = EasyMock.createNiceMock( ServiceRegistry.class );
  EasyMock.expect( mockServiceRegistry.lookupServiceURL( "test-cluster", "NAMENODE" ) ).andReturn( "test-nn-scheme://test-nn-host:411" ).anyTimes();
  EasyMock.expect( mockServiceRegistry.lookupServiceURL( "test-cluster", "JOBTRACKER" ) ).andReturn( "test-jt-scheme://test-jt-host:511" ).anyTimes();

  GatewayServices mockGatewayServices = EasyMock.createNiceMock( GatewayServices.class );
  EasyMock.expect( mockGatewayServices.getService(ServiceType.SERVICE_REGISTRY_SERVICE) ).andReturn( mockServiceRegistry ).anyTimes();

  EasyMock.replay( mockServiceRegistry, mockGatewayServices );

  String descriptorUrl = TestUtils.getResourceUrl( FrontendFunctionProcessorTest.class, "rewrite.xml" ).toExternalForm();

  Log.setLog( new NoOpLogger() );

  server = new ServletTester();
  server.setContextPath( "/" );
  server.getContext().addEventListener( new UrlRewriteServletContextListener() );
  server.getContext().setInitParameter(
      UrlRewriteServletContextListener.DESCRIPTOR_LOCATION_INIT_PARAM_NAME, descriptorUrl );

  if( attributes != null ) {
    server.getContext().setAttributes( attributes );
  }
  server.getContext().setAttribute( GatewayServices.GATEWAY_CLUSTER_ATTRIBUTE, "test-cluster" );
  server.getContext().setAttribute( GatewayServices.GATEWAY_SERVICES_ATTRIBUTE, mockGatewayServices );

  FilterHolder setupFilter = server.addFilter( SetupFilter.class, "/*", EnumSet.of( DispatcherType.REQUEST ) );
  setupFilter.setFilter( new SetupFilter( username ) );
  FilterHolder rewriteFilter = server.addFilter( UrlRewriteServletFilter.class, "/*", EnumSet.of( DispatcherType.REQUEST ) );
  if( initParams != null ) {
    for( Map.Entry<String,String> entry : initParams.entrySet() ) {
      rewriteFilter.setInitParameter( entry.getKey(), entry.getValue() );
    }
  }
  rewriteFilter.setFilter( new UrlRewriteServletFilter() );

  interactions = new ArrayDeque<>();

  ServletHolder servlet = server.addServlet( MockServlet.class, "/" );
  servlet.setServlet( new MockServlet( "mock-servlet", interactions ) );

  server.start();

  interaction = new MockInteraction();
  request = HttpTester.newRequest();
  response = null;
}