Search in sources :

Example 11 with LoggingFilter

use of com.sun.jersey.api.client.filter.LoggingFilter in project hadoop by apache.

the class TestNMWebServicesContainers method testNodeHelper.

public void testNodeHelper(String path, String media) throws JSONException, Exception {
    WebResource r = resource();
    Application app = new MockApp(1);
    nmContext.getApplications().put(app.getAppId(), app);
    addAppContainers(app);
    Application app2 = new MockApp(2);
    nmContext.getApplications().put(app2.getAppId(), app2);
    addAppContainers(app2);
    client().addFilter(new LoggingFilter());
    ClientResponse response = r.path("ws").path("v1").path("node").path(path).accept(media).get(ClientResponse.class);
    assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8, response.getType().toString());
    JSONObject json = response.getEntity(JSONObject.class);
    JSONObject info = json.getJSONObject("containers");
    assertEquals("incorrect number of elements", 1, info.length());
    JSONArray conInfo = info.getJSONArray("container");
    assertEquals("incorrect number of elements", 4, conInfo.length());
    for (int i = 0; i < conInfo.length(); i++) {
        verifyNodeContainerInfo(conInfo.getJSONObject(i), nmContext.getContainers().get(ContainerId.fromString(conInfo.getJSONObject(i).getString("id"))));
    }
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) JSONObject(org.codehaus.jettison.json.JSONObject) LoggingFilter(com.sun.jersey.api.client.filter.LoggingFilter) JSONArray(org.codehaus.jettison.json.JSONArray) WebResource(com.sun.jersey.api.client.WebResource) Application(org.apache.hadoop.yarn.server.nodemanager.containermanager.application.Application)

Example 12 with LoggingFilter

use of com.sun.jersey.api.client.filter.LoggingFilter in project gfm_viewer by satyagraha.

the class WebServiceClientDefault method transform.

@Override
public String transform(String mdText) {
    if (StringUtils.isBlank(config.getApiUrl())) {
        String responseText = String.format("<pre>\n%s\n</pre>", StringEscapeUtils.escapeHtml4(mdText));
        return responseText;
    }
    Client client = getClient(config.getApiUrl());
    LOGGER.fine("client: " + client);
    String username = config.getUsername();
    if (username != null && username.length() > 0) {
        String password = config.getPassword();
        client.removeFilter(null);
        client.addFilter(new HTTPBasicAuthFilter(username, password));
    }
    client.addFilter(new LoggingFilter(LOGGER));
    WebResource webResource = client.resource(config.getApiUrl());
    Markdown markdown = new Markdown(mdText);
    ClientResponse response = webResource.path("markdown").type(MediaType.APPLICATION_JSON).entity(markdown).accept(MediaType.TEXT_HTML).post(ClientResponse.class);
    String responseText = response.getEntity(String.class);
    return responseText;
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) LoggingFilter(com.sun.jersey.api.client.filter.LoggingFilter) WebResource(com.sun.jersey.api.client.WebResource) Client(com.sun.jersey.api.client.Client) WebServiceClient(code.satyagraha.gfm.support.api.WebServiceClient) HTTPBasicAuthFilter(com.sun.jersey.api.client.filter.HTTPBasicAuthFilter)

Aggregations

LoggingFilter (com.sun.jersey.api.client.filter.LoggingFilter)12 ClientResponse (com.sun.jersey.api.client.ClientResponse)10 Test (org.junit.Test)9 RMApp (org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp)5 WebResource (com.sun.jersey.api.client.WebResource)4 JSONObject (org.codehaus.jettison.json.JSONObject)4 MediaType (javax.ws.rs.core.MediaType)3 MockNM (org.apache.hadoop.yarn.server.resourcemanager.MockNM)3 CapacityScheduler (org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacityScheduler)3 CapacitySchedulerConfiguration (org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration)3 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 ServletException (javax.servlet.ServletException)2 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)2 Application (org.apache.hadoop.yarn.server.nodemanager.containermanager.application.Application)2 DelegationToken (org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.DelegationToken)2 JSONArray (org.codehaus.jettison.json.JSONArray)2 JSONException (org.codehaus.jettison.json.JSONException)2 SAXException (org.xml.sax.SAXException)2 WebServiceClient (code.satyagraha.gfm.support.api.WebServiceClient)1