Search in sources :

Example 16 with LoggingFilter

use of com.sun.jersey.api.client.filter.LoggingFilter in project ORCID-Source by ORCID.

the class GetFromSalesForce method init.

private void init() {
    client = Client.create();
    client.addFilter(new LoggingFilter());
    if (StringUtils.isBlank(query)) {
        try {
            query = IOUtils.toString(new FileReader(queryFile));
        } catch (IOException e) {
            throw new RuntimeException("Error reading query file", e);
        }
    }
}
Also used : LoggingFilter(com.sun.jersey.api.client.filter.LoggingFilter) FileReader(java.io.FileReader) IOException(java.io.IOException)

Example 17 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)

Example 18 with LoggingFilter

use of com.sun.jersey.api.client.filter.LoggingFilter in project coprhd-controller by CoprHD.

the class RESTClientUtil method authenticate.

private void authenticate(final Client c, final int authenticateCallCount) throws NoSuchAlgorithmException {
    final String methodName = "authenticate(): ";
    log.debug(methodName + "Called");
    disableCertificateValidation();
    c.setFollowRedirects(false);
    if (log.isTraceEnabled()) {
        c.addFilter(new LoggingFilter());
    }
    c.addFilter(new HTTPBasicAuthFilter(this._username, this._password));
    c.addFilter(new ClientFilter() {

        private Object authToken;

        // private int callCount = authenticateCallCount;
        @Override
        public ClientResponse handle(ClientRequest request) throws ClientHandlerException {
            if (authToken != null) {
                request.getHeaders().put(AUTH_TOKEN_HEADER, Collections.singletonList(authToken));
            }
            ClientResponse response = getNext().handle(request);
            if (response.getHeaders() != null && response.getHeaders().containsKey(AUTH_TOKEN_HEADER)) {
                authToken = (response.getHeaders().getFirst(AUTH_TOKEN_HEADER));
            }
            if (response.getStatus() == 302) {
                WebResource wb = c.resource(response.getLocation());
                response = wb.header(AUTH_TOKEN_HEADER, authToken).get(ClientResponse.class);
            }
            return response;
        }
    });
}
Also used : ClientHandlerException(com.sun.jersey.api.client.ClientHandlerException) ClientResponse(com.sun.jersey.api.client.ClientResponse) LoggingFilter(com.sun.jersey.api.client.filter.LoggingFilter) ClientFilter(com.sun.jersey.api.client.filter.ClientFilter) WebResource(com.sun.jersey.api.client.WebResource) HTTPBasicAuthFilter(com.sun.jersey.api.client.filter.HTTPBasicAuthFilter) ClientRequest(com.sun.jersey.api.client.ClientRequest)

Example 19 with LoggingFilter

use of com.sun.jersey.api.client.filter.LoggingFilter in project coprhd-controller by CoprHD.

the class ScaleIORestClient method authenticate.

@Override
protected void authenticate() {
    log.info("Authenticating");
    _client.removeAllFilters();
    _client.addFilter(new HTTPBasicAuthFilter(_username, _password));
    if (log.isDebugEnabled()) {
        _client.addFilter(new LoggingFilter(System.out));
    }
    URI requestURI = _base.resolve(URI.create(ScaleIOConstants.API_LOGIN));
    ClientResponse response = _client.resource(requestURI).type(MediaType.APPLICATION_JSON).get(ClientResponse.class);
    if (response.getClientResponseStatus() != ClientResponse.Status.OK && response.getClientResponseStatus() != ClientResponse.Status.CREATED) {
        throw ScaleIOException.exceptions.authenticationFailure(_base.toString());
    }
    _authToken = response.getEntity(String.class).replace("\"", "");
    _client.removeAllFilters();
    _client.addFilter(new HTTPBasicAuthFilter(_username, _authToken));
    if (log.isDebugEnabled()) {
        _client.addFilter(new LoggingFilter(System.out));
    }
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) LoggingFilter(com.sun.jersey.api.client.filter.LoggingFilter) HTTPBasicAuthFilter(com.sun.jersey.api.client.filter.HTTPBasicAuthFilter) URI(java.net.URI)

Example 20 with LoggingFilter

use of com.sun.jersey.api.client.filter.LoggingFilter in project cloudbreak by hortonworks.

the class YarnHttpClient method getNewWebResource.

public WebResource getNewWebResource(String url) {
    ClientConfig clientConfig = new DefaultClientConfig();
    Client client = Client.create(clientConfig);
    client.addFilter(new LoggingFilter());
    return client.resource(url);
}
Also used : DefaultClientConfig(com.sun.jersey.api.client.config.DefaultClientConfig) LoggingFilter(com.sun.jersey.api.client.filter.LoggingFilter) DefaultClientConfig(com.sun.jersey.api.client.config.DefaultClientConfig) ClientConfig(com.sun.jersey.api.client.config.ClientConfig) Client(com.sun.jersey.api.client.Client)

Aggregations

LoggingFilter (com.sun.jersey.api.client.filter.LoggingFilter)20 ClientResponse (com.sun.jersey.api.client.ClientResponse)14 Test (org.junit.Test)9 WebResource (com.sun.jersey.api.client.WebResource)7 HTTPBasicAuthFilter (com.sun.jersey.api.client.filter.HTTPBasicAuthFilter)7 ClientConfig (com.sun.jersey.api.client.config.ClientConfig)5 DefaultClientConfig (com.sun.jersey.api.client.config.DefaultClientConfig)5 ClientFilter (com.sun.jersey.api.client.filter.ClientFilter)5 ArrayList (java.util.ArrayList)5 RMApp (org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp)5 Client (com.sun.jersey.api.client.Client)4 JSONObject (org.codehaus.jettison.json.JSONObject)4 ClientHandlerException (com.sun.jersey.api.client.ClientHandlerException)3 ClientRequest (com.sun.jersey.api.client.ClientRequest)3 IOException (java.io.IOException)3 MediaType (javax.ws.rs.core.MediaType)3 NewCookie (javax.ws.rs.core.NewCookie)3 MockNM (org.apache.hadoop.yarn.server.resourcemanager.MockNM)3 CapacityScheduler (org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacityScheduler)3 URI (java.net.URI)2