com.sun.jersey.api.client.filter.LoggingFilter Java Examples

The following examples show how to use com.sun.jersey.api.client.filter.LoggingFilter. 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: DockerClient.java    From docker-java with Apache License 2.0 6 votes vote down vote up
private DockerClient(Config config) {
	restEndpointUrl = config.url + "/v" + config.version;
	ClientConfig clientConfig = new DefaultClientConfig();
	//clientConfig.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE);

	SchemeRegistry schemeRegistry = new SchemeRegistry();
	schemeRegistry.register(new Scheme("http", config.url.getPort(), PlainSocketFactory.getSocketFactory()));
	schemeRegistry.register(new Scheme("https", 443, SSLSocketFactory.getSocketFactory()));

	PoolingClientConnectionManager cm = new PoolingClientConnectionManager(schemeRegistry);
	// Increase max total connection
	cm.setMaxTotal(1000);
	// Increase default max connection per route
	cm.setDefaultMaxPerRoute(1000);

	HttpClient httpClient = new DefaultHttpClient(cm);
	client = new ApacheHttpClient4(new ApacheHttpClient4Handler(httpClient, null, false), clientConfig);

	client.setReadTimeout(10000);
	//Experimental support for unix sockets:
	//client = new UnixSocketClient(clientConfig);

	client.addFilter(new JsonClientFilter());
	client.addFilter(new LoggingFilter());
}
 
Example #2
Source File: ApiClient.java    From forge-api-java-client with Apache License 2.0 6 votes vote down vote up
/**
 * Build the Client used to make HTTP requests with the latest settings,
 * i.e. objectMapper and debugging.
 * TODO: better to use the Builder Pattern?
 */
public ApiClient rebuildHttpClient() {
  // Add the JSON serialization support to Jersey
  JacksonJsonProvider jsonProvider = new JacksonJsonProvider(objectMapper);
  DefaultClientConfig conf = new DefaultClientConfig();
  conf.getSingletons().add(jsonProvider);
  Client client = Client.create(conf);
  if (debugging) {
    client.addFilter(new LoggingFilter());
  }
  
  //to solve the issue of GET:metadata/:guid with accepted encodeing is 'gzip' 
  //in the past, when clients use gzip header, actually it doesn't trigger a gzip encoding... So everything is fine 
  //After the release, the content is return in gzip, while the sdk doesn't handle it correctly
  client.addFilter(new GZIPContentEncodingFilter(false));

  this.httpClient = client;
  return this;
}
 
Example #3
Source File: TestRMWebServicesDelegationTokens.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Test
public void testCreateDelegationToken() throws Exception {
  rm.start();
  this.client().addFilter(new LoggingFilter(System.out));
  final String renewer = "test-renewer";
  String jsonBody = "{ \"renewer\" : \"" + renewer + "\" }";
  String xmlBody =
      "<delegation-token><renewer>" + renewer
          + "</renewer></delegation-token>";
  String[] mediaTypes =
      { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML };
  Map<String, String> bodyMap = new HashMap<String, String>();
  bodyMap.put(MediaType.APPLICATION_JSON, jsonBody);
  bodyMap.put(MediaType.APPLICATION_XML, xmlBody);
  for (final String mediaType : mediaTypes) {
    final String body = bodyMap.get(mediaType);
    for (final String contentType : mediaTypes) {
      if (isKerberosAuth == true) {
        verifyKerberosAuthCreate(mediaType, contentType, body, renewer);
      } else {
        verifySimpleAuthCreate(mediaType, contentType, body);
      }
    }
  }

  rm.stop();
  return;
}
 
Example #4
Source File: ApiClient.java    From docusign-java-client with MIT License 5 votes vote down vote up
/**
 * Build the Client used to make HTTP requests with the latest settings,
 * i.e. objectMapper and debugging.
 * TODO: better to use the Builder Pattern?
 * @return API client
 */
public ApiClient rebuildHttpClient() {
  // Add the JSON serialization support to Jersey
  JacksonJsonProvider jsonProvider = new JacksonJsonProvider(objectMapper);
  DefaultClientConfig conf = new DefaultClientConfig();
  conf.getSingletons().add(jsonProvider);
  Client client = Client.create(conf);
  client.addFilter(new GZIPContentEncodingFilter(false));
  if (debugging) {
    client.addFilter(new LoggingFilter());
  }
  this.httpClient = client;
  return this;
}
 
Example #5
Source File: JAXRSTester.java    From ice with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * This operation checks posting updates to the server.
 */
@Test
public void checkPostingUpdates() {

	// Create the json message
	String message = "post={\"item_id\":\"5\", "
			+ "\"client_key\":\"1234567890ABCDEFGHIJ1234567890ABCDEFGHIJ\", "
			+ "\"posts\":[{\"type\":\"UPDATER_STARTED\",\"message\":\"\"},"
			+ "{\"type\":\"FILE_MODIFIED\","
			+ "\"message\":\"/tmp/file\"}]}";

	// Create the client
	Client jaxRSClient = Client.create();
	// Create the filter that will let us login with basic HTTP
	// authentication.
	final HTTPBasicAuthFilter authFilter = new HTTPBasicAuthFilter("ice",
			"veryice");
	jaxRSClient.addFilter(authFilter);
	// Add a filter for logging. This filter will automatically dump stuff
	// to stdout.
	jaxRSClient.addFilter(new LoggingFilter());

	// Get the handle to the server as a web resource
	WebResource webResource = jaxRSClient
			.resource("http://localhost:8080/ice");

	// Get the normal response from the server to make sure we can connect
	// to it
	webResource.accept(MediaType.TEXT_PLAIN).header("X-FOO", "BAR")
			.get(String.class);

	// Try posting something to the update page
	webResource.path("update").type(MediaType.APPLICATION_FORM_URLENCODED_TYPE).post(String.class, message);

	return;
}
 
Example #6
Source File: ApiClient.java    From netphony-topology with Apache License 2.0 5 votes vote down vote up
/**
 * Get an existing client or create a new client to handle HTTP request.
 */
private Client getClient() {
  if(!hostMap.containsKey(basePath)) {
    Client client = Client.create();
    if (debugging)
      client.addFilter(new LoggingFilter());
    hostMap.put(basePath, client);
  }
  return hostMap.get(basePath);
}
 
Example #7
Source File: ApiClient.java    From qbit-microservices-examples with Apache License 2.0 5 votes vote down vote up
/**
 * Get an existing client or create a new client to handle HTTP request.
 */
private Client getClient() {
  if(!hostMap.containsKey(basePath)) {
    Client client = Client.create();
    if (debugging)
      client.addFilter(new LoggingFilter());
    hostMap.put(basePath, client);
  }
  return hostMap.get(basePath);
}
 
Example #8
Source File: ApiClient.java    From qbit-microservices-examples with Apache License 2.0 5 votes vote down vote up
/**
 * Get an existing client or create a new client to handle HTTP request.
 */
private Client getClient() {
  if(!hostMap.containsKey(basePath)) {
    Client client = Client.create();
    if (debugging)
      client.addFilter(new LoggingFilter());
    hostMap.put(basePath, client);
  }
  return hostMap.get(basePath);
}
 
Example #9
Source File: ApiClient.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
/**
 * Build the Client used to make HTTP requests with the latest settings,
 * i.e. objectMapper and debugging.
 * TODO: better to use the Builder Pattern?
 * @return API client
 */
public ApiClient rebuildHttpClient() {
  // Add the JSON serialization support to Jersey
  JacksonJsonProvider jsonProvider = new JacksonJsonProvider(objectMapper);
  DefaultClientConfig conf = new DefaultClientConfig();
  conf.getSingletons().add(jsonProvider);
  Client client = Client.create(conf);
  client.addFilter(new GZIPContentEncodingFilter(false));
  if (debugging) {
    client.addFilter(new LoggingFilter());
  }
  this.httpClient = client;
  return this;
}
 
Example #10
Source File: TestRMWebServicesAppsModification.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetAppQueue() throws Exception {
  client().addFilter(new LoggingFilter(System.out));
  boolean isCapacityScheduler =
      rm.getResourceScheduler() instanceof CapacityScheduler;
  rm.start();
  MockNM amNodeManager = rm.registerNode("127.0.0.1:1234", 2048);
  String[] contentTypes =
      { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML };
  for (String contentType : contentTypes) {
    RMApp app = rm.submitApp(CONTAINER_MB, "", webserviceUserName);
    amNodeManager.nodeHeartbeat(true);
    ClientResponse response =
        this
          .constructWebResource("apps", app.getApplicationId().toString(),
            "queue").accept(contentType).get(ClientResponse.class);
    assertEquals(Status.OK, response.getClientResponseStatus());
    String expectedQueue = "default";
    if(!isCapacityScheduler) {
      expectedQueue = "root." + webserviceUserName;
    }
    if (contentType.equals(MediaType.APPLICATION_JSON)) {
      verifyAppQueueJson(response, expectedQueue);
    } else {
      verifyAppQueueXML(response, expectedQueue);
    }
  }
  rm.stop();
}
 
Example #11
Source File: TestRMWebServicesAppsModification.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetNewApplication() throws Exception {
  client().addFilter(new LoggingFilter(System.out));
  rm.start();
  String mediaTypes[] =
      { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML };
  for (String acceptMedia : mediaTypes) {
    testGetNewApplication(acceptMedia);
  }
  rm.stop();
}
 
Example #12
Source File: ApiClient.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
/**
 * Build the Client used to make HTTP requests with the latest settings,
 * i.e. objectMapper and debugging.
 */
public ApiClient rebuildHttpClient() {
    // Add the JSON serialization support to Jersey
    JacksonJsonProvider jsonProvider = new JacksonJsonProvider(objectMapper);
    DefaultClientConfig conf = new DefaultClientConfig();
    conf.getSingletons().add(jsonProvider);
    Client client = Client.create(conf);
    if (debugging) {
        client.addFilter(new LoggingFilter());
    }
    this.httpClient = client;
    return this;
}
 
Example #13
Source File: TestRMWebServicesDelegationTokens.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Test
public void testCreateDelegationToken() throws Exception {
  rm.start();
  this.client().addFilter(new LoggingFilter(System.out));
  final String renewer = "test-renewer";
  String jsonBody = "{ \"renewer\" : \"" + renewer + "\" }";
  String xmlBody =
      "<delegation-token><renewer>" + renewer
          + "</renewer></delegation-token>";
  String[] mediaTypes =
      { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML };
  Map<String, String> bodyMap = new HashMap<String, String>();
  bodyMap.put(MediaType.APPLICATION_JSON, jsonBody);
  bodyMap.put(MediaType.APPLICATION_XML, xmlBody);
  for (final String mediaType : mediaTypes) {
    final String body = bodyMap.get(mediaType);
    for (final String contentType : mediaTypes) {
      if (isKerberosAuth == true) {
        verifyKerberosAuthCreate(mediaType, contentType, body, renewer);
      } else {
        verifySimpleAuthCreate(mediaType, contentType, body);
      }
    }
  }

  rm.stop();
  return;
}
 
Example #14
Source File: TestRMWebServicesAppsModification.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetAppQueue() throws Exception {
  client().addFilter(new LoggingFilter(System.out));
  boolean isCapacityScheduler =
      rm.getResourceScheduler() instanceof CapacityScheduler;
  rm.start();
  MockNM amNodeManager = rm.registerNode("127.0.0.1:1234", 2048);
  String[] contentTypes =
      { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML };
  for (String contentType : contentTypes) {
    RMApp app = rm.submitApp(CONTAINER_MB, "", webserviceUserName);
    amNodeManager.nodeHeartbeat(true);
    ClientResponse response =
        this
          .constructWebResource("apps", app.getApplicationId().toString(),
            "queue").accept(contentType).get(ClientResponse.class);
    assertEquals(Status.OK, response.getClientResponseStatus());
    String expectedQueue = "default";
    if(!isCapacityScheduler) {
      expectedQueue = "root." + webserviceUserName;
    }
    if (contentType.equals(MediaType.APPLICATION_JSON)) {
      verifyAppQueueJson(response, expectedQueue);
    } else {
      verifyAppQueueXML(response, expectedQueue);
    }
  }
  rm.stop();
}
 
Example #15
Source File: TestRMWebServicesAppsModification.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetNewApplication() throws Exception {
  client().addFilter(new LoggingFilter(System.out));
  rm.start();
  String mediaTypes[] =
      { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML };
  for (String acceptMedia : mediaTypes) {
    testGetNewApplication(acceptMedia);
  }
  rm.stop();
}
 
Example #16
Source File: TestRMWebServicesAppsModification.java    From big-c with Apache License 2.0 4 votes vote down vote up
@Test(timeout = 90000)
public void testAppMove() throws Exception {

  client().addFilter(new LoggingFilter(System.out));

  boolean isCapacityScheduler =
      rm.getResourceScheduler() instanceof CapacityScheduler;

  // default root queue allows anyone to have admin acl
  CapacitySchedulerConfiguration csconf =
      new CapacitySchedulerConfiguration();
  String[] queues = { "default", "test" };
  csconf.setQueues("root", queues);
  csconf.setCapacity("root.default", 50.0f);
  csconf.setCapacity("root.test", 50.0f);
  csconf.setAcl("root", QueueACL.ADMINISTER_QUEUE, "someuser");
  csconf.setAcl("root.default", QueueACL.ADMINISTER_QUEUE, "someuser");
  csconf.setAcl("root.test", QueueACL.ADMINISTER_QUEUE, "someuser");
  rm.getResourceScheduler().reinitialize(csconf, rm.getRMContext());

  rm.start();
  MockNM amNodeManager = rm.registerNode("127.0.0.1:1234", 2048);
  String[] mediaTypes =
      { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML };
  MediaType[] contentTypes =
      { MediaType.APPLICATION_JSON_TYPE, MediaType.APPLICATION_XML_TYPE };
  for (String mediaType : mediaTypes) {
    for (MediaType contentType : contentTypes) {
      RMApp app = rm.submitApp(CONTAINER_MB, "", webserviceUserName);
      amNodeManager.nodeHeartbeat(true);
      AppQueue targetQueue = new AppQueue("test");
      Object entity;
      if (contentType.equals(MediaType.APPLICATION_JSON_TYPE)) {
        entity = appQueueToJSON(targetQueue);
      } else {
        entity = targetQueue;
      }
      ClientResponse response =
          this
            .constructWebResource("apps", app.getApplicationId().toString(),
              "queue").entity(entity, contentType).accept(mediaType)
            .put(ClientResponse.class);

      if (!isAuthenticationEnabled()) {
        assertEquals(Status.UNAUTHORIZED, response.getClientResponseStatus());
        continue;
      }
      assertEquals(Status.OK, response.getClientResponseStatus());
      String expectedQueue = "test";
      if(!isCapacityScheduler) {
        expectedQueue = "root.test";
      }
      if (mediaType.equals(MediaType.APPLICATION_JSON)) {
        verifyAppQueueJson(response, expectedQueue);
      } else {
        verifyAppQueueXML(response, expectedQueue);
      }
      Assert.assertEquals(expectedQueue, app.getQueue());

      // check unauthorized
      app = rm.submitApp(CONTAINER_MB, "", "someuser");
      amNodeManager.nodeHeartbeat(true);
      response =
          this
            .constructWebResource("apps", app.getApplicationId().toString(),
              "queue").entity(entity, contentType).accept(mediaType)
            .put(ClientResponse.class);
      assertEquals(Status.FORBIDDEN, response.getClientResponseStatus());
      if(isCapacityScheduler) {
        Assert.assertEquals("default", app.getQueue());
      }
      else {
        Assert.assertEquals("root.someuser", app.getQueue());
      }

    }
  }
  rm.stop();
}
 
Example #17
Source File: TestRMWebServicesAppsModification.java    From hadoop with Apache License 2.0 4 votes vote down vote up
@Test(timeout = 90000)
public void testAppMove() throws Exception {

  client().addFilter(new LoggingFilter(System.out));

  boolean isCapacityScheduler =
      rm.getResourceScheduler() instanceof CapacityScheduler;

  // default root queue allows anyone to have admin acl
  CapacitySchedulerConfiguration csconf =
      new CapacitySchedulerConfiguration();
  String[] queues = { "default", "test" };
  csconf.setQueues("root", queues);
  csconf.setCapacity("root.default", 50.0f);
  csconf.setCapacity("root.test", 50.0f);
  csconf.setAcl("root", QueueACL.ADMINISTER_QUEUE, "someuser");
  csconf.setAcl("root.default", QueueACL.ADMINISTER_QUEUE, "someuser");
  csconf.setAcl("root.test", QueueACL.ADMINISTER_QUEUE, "someuser");
  rm.getResourceScheduler().reinitialize(csconf, rm.getRMContext());

  rm.start();
  MockNM amNodeManager = rm.registerNode("127.0.0.1:1234", 2048);
  String[] mediaTypes =
      { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML };
  MediaType[] contentTypes =
      { MediaType.APPLICATION_JSON_TYPE, MediaType.APPLICATION_XML_TYPE };
  for (String mediaType : mediaTypes) {
    for (MediaType contentType : contentTypes) {
      RMApp app = rm.submitApp(CONTAINER_MB, "", webserviceUserName);
      amNodeManager.nodeHeartbeat(true);
      AppQueue targetQueue = new AppQueue("test");
      Object entity;
      if (contentType.equals(MediaType.APPLICATION_JSON_TYPE)) {
        entity = appQueueToJSON(targetQueue);
      } else {
        entity = targetQueue;
      }
      ClientResponse response =
          this
            .constructWebResource("apps", app.getApplicationId().toString(),
              "queue").entity(entity, contentType).accept(mediaType)
            .put(ClientResponse.class);

      if (!isAuthenticationEnabled()) {
        assertEquals(Status.UNAUTHORIZED, response.getClientResponseStatus());
        continue;
      }
      assertEquals(Status.OK, response.getClientResponseStatus());
      String expectedQueue = "test";
      if(!isCapacityScheduler) {
        expectedQueue = "root.test";
      }
      if (mediaType.equals(MediaType.APPLICATION_JSON)) {
        verifyAppQueueJson(response, expectedQueue);
      } else {
        verifyAppQueueXML(response, expectedQueue);
      }
      Assert.assertEquals(expectedQueue, app.getQueue());

      // check unauthorized
      app = rm.submitApp(CONTAINER_MB, "", "someuser");
      amNodeManager.nodeHeartbeat(true);
      response =
          this
            .constructWebResource("apps", app.getApplicationId().toString(),
              "queue").entity(entity, contentType).accept(mediaType)
            .put(ClientResponse.class);
      assertEquals(Status.FORBIDDEN, response.getClientResponseStatus());
      if(isCapacityScheduler) {
        Assert.assertEquals("default", app.getQueue());
      }
      else {
        Assert.assertEquals("root.someuser", app.getQueue());
      }

    }
  }
  rm.stop();
}
 
Example #18
Source File: YarnHttpClient.java    From cloudbreak with Apache License 2.0 4 votes vote down vote up
public WebResource getNewWebResource(String url) {
    ClientConfig clientConfig = new DefaultClientConfig();
    Client client = Client.create(clientConfig);
    client.addFilter(new LoggingFilter());
    return client.resource(url);
}
 
Example #19
Source File: WebServiceClient.java    From nextreports-server with Apache License 2.0 4 votes vote down vote up
protected Client createJerseyClient() {
		ClientConfig config = new DefaultClientConfig();
//		DefaultApacheHttpClientConfig config = new DefaultApacheHttpClientConfig();  
		config.getClasses().add(XStreamXmlProvider.class);
//		ApacheHttpClient client = ApacheHttpClient.create(config);
		
		if (server.startsWith("https")) {
			log("* Use https protocol");			
			try {				
				initSSL(config);								
			} catch (Exception ex) {	
				if (tm != null) {
					try {
					    installCertificates();					    
					    initSSL(config);	
					} catch (Exception e) {
						throw new RuntimeException(e);
					}
				} else {				
					throw new RuntimeException(ex);
				}
			}
		}
		
		Client client = Client.create(config);
		
		if (isDebug()) {
			client.addFilter(new LoggingFilter());
		}
		if ((username != null) && (password != null)) {
//			client.addFilter(new HTTPBasicAuthFilter(username, password));
			String encodedPassword = password;
			if (passwordEncoder != null) {
				encodedPassword = passwordEncoder.encode(password);
			} 
			client.addFilter(new HttpBasicAuthenticationFilter(username, encodedPassword));
//			config.getState().setCredentials(null, null, -1, username, encodedPassword);
		}
		
		if (timeout != UNDEFINED) {
			client.setConnectTimeout(timeout);
		}
		
		return client;
	}