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);
}
}
}
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;
}
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;
}
});
}
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));
}
}
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);
}
Aggregations