Search in sources :

Example 16 with HTTPBasicAuthFilter

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

the class OrcidClientHelper method addBasicAuth.

public void addBasicAuth(String username, String password) {
    basicAuthFilter = new HTTPBasicAuthFilter(username, password);
    jerseyClient.addFilter(basicAuthFilter);
}
Also used : HTTPBasicAuthFilter(com.sun.jersey.api.client.filter.HTTPBasicAuthFilter)

Example 17 with HTTPBasicAuthFilter

use of com.sun.jersey.api.client.filter.HTTPBasicAuthFilter in project microservices by pwillhan.

the class ComponentFinder method main.

public static void main(String[] args) {
    Scanner scanner = null;
    try {
        scanner = new Scanner(System.in);
        System.out.println("Enter component type in plural form (e.g. queues, exchanges) ");
        String type = scanner.nextLine();
        System.out.println("Enter vhost (leave empty for default vhost) ");
        String vhost = scanner.nextLine();
        System.out.println("Enter name pattern (leave empty for match-all pattern)");
        String pattern = scanner.nextLine();
        Client client = Client.create();
        String path;
        if (vhost.trim().isEmpty()) {
            path = API_ROOT + "/" + type + "?columns=name";
        } else {
            path = API_ROOT + "/" + type + "/" + vhost + "?columns=name";
        }
        WebResource resource = client.resource(path);
        resource.header("Content-Type", "application/json;charset=UTF-8");
        resource.addFilter(new HTTPBasicAuthFilter("guest", "guest".getBytes()));
        String result = resource.get(String.class);
        JSONArray jsonResult = new JSONArray(result);
        LOGGER.debug("Result: \n" + jsonResult.toString(4));
        filterResult(jsonResult, pattern);
    } finally {
        if (scanner != null) {
            scanner.close();
        }
    }
}
Also used : Scanner(java.util.Scanner) JSONArray(org.json.JSONArray) WebResource(com.sun.jersey.api.client.WebResource) Client(com.sun.jersey.api.client.Client) HTTPBasicAuthFilter(com.sun.jersey.api.client.filter.HTTPBasicAuthFilter)

Example 18 with HTTPBasicAuthFilter

use of com.sun.jersey.api.client.filter.HTTPBasicAuthFilter in project activityinfo by bedatadriven.

the class DataEntrySteps method field_has_downloadable_link.

@Then("^\"([^\"]*)\" field has downloadable link.$")
public void field_has_downloadable_link(String attachmentFieldName) throws Throwable {
    String blobLink = firstDownloadableLinkOfFirstSubmission(attachmentFieldName);
    UserAccount currentUser = driver.setup().getCurrentUser();
    Client client = new Client();
    client.addFilter(new HTTPBasicAuthFilter(currentUser.getEmail(), currentUser.getPassword()));
    client.setFollowRedirects(false);
    ClientResponse clientResponse = client.resource(blobLink).get(ClientResponse.class);
    assertEquals(Response.Status.OK.getStatusCode(), clientResponse.getStatus());
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) Client(com.sun.jersey.api.client.Client) UserAccount(org.activityinfo.test.sut.UserAccount) HTTPBasicAuthFilter(com.sun.jersey.api.client.filter.HTTPBasicAuthFilter) Then(cucumber.api.java.en.Then)

Example 19 with HTTPBasicAuthFilter

use of com.sun.jersey.api.client.filter.HTTPBasicAuthFilter in project activityinfo by bedatadriven.

the class XFormApplicationDriver method submitForm.

@Override
public ResourceId submitForm(String formName, List<FieldValue> values) throws Exception {
    Client client = Client.create();
    if (currentUser != null) {
        client.addFilter(new HTTPBasicAuthFilter(currentUser.getEmail(), currentUser.getPassword()));
    }
    WebResource root = client.resource(server.getRootUrl());
    // root.path("formList").get()
    throw new UnsupportedOperationException();
}
Also used : WebResource(com.sun.jersey.api.client.WebResource) Client(com.sun.jersey.api.client.Client) HTTPBasicAuthFilter(com.sun.jersey.api.client.filter.HTTPBasicAuthFilter)

Example 20 with HTTPBasicAuthFilter

use of com.sun.jersey.api.client.filter.HTTPBasicAuthFilter in project java-docs-samples by GoogleCloudPlatform.

the class MailgunServlet method sendSimpleMessage.

// [START simple]
private ClientResponse sendSimpleMessage(String recipient) {
    Client client = Client.create();
    client.addFilter(new HTTPBasicAuthFilter("api", MAILGUN_API_KEY));
    MultivaluedMapImpl formData = new MultivaluedMapImpl();
    formData.add("from", "Mailgun User <mailgun@" + MAILGUN_DOMAIN_NAME + ">");
    formData.add("to", recipient);
    formData.add("subject", "Simple Mailgun Example");
    formData.add("text", "Plaintext content");
    WebResource webResource = client.resource("https://api.mailgun.net/v3/" + MAILGUN_DOMAIN_NAME + "/messages");
    return webResource.type(MediaType.APPLICATION_FORM_URLENCODED).post(ClientResponse.class, formData);
}
Also used : WebResource(com.sun.jersey.api.client.WebResource) MultivaluedMapImpl(com.sun.jersey.core.util.MultivaluedMapImpl) Client(com.sun.jersey.api.client.Client) HTTPBasicAuthFilter(com.sun.jersey.api.client.filter.HTTPBasicAuthFilter)

Aggregations

HTTPBasicAuthFilter (com.sun.jersey.api.client.filter.HTTPBasicAuthFilter)45 Client (com.sun.jersey.api.client.Client)31 WebResource (com.sun.jersey.api.client.WebResource)19 ClientResponse (com.sun.jersey.api.client.ClientResponse)15 ClientConfig (com.sun.jersey.api.client.config.ClientConfig)14 DefaultClientConfig (com.sun.jersey.api.client.config.DefaultClientConfig)14 LoggingFilter (com.sun.jersey.api.client.filter.LoggingFilter)7 ArrayList (java.util.ArrayList)7 ClientFilter (com.sun.jersey.api.client.filter.ClientFilter)6 HTTPSProperties (com.sun.jersey.client.urlconnection.HTTPSProperties)5 ApacheHttpClient (com.sun.jersey.client.apache.ApacheHttpClient)4 HostnameVerifier (javax.net.ssl.HostnameVerifier)4 SSLSession (javax.net.ssl.SSLSession)4 ClientHandlerException (com.sun.jersey.api.client.ClientHandlerException)3 ClientRequest (com.sun.jersey.api.client.ClientRequest)3 MultivaluedMapImpl (com.sun.jersey.core.util.MultivaluedMapImpl)3 FormDataMultiPart (com.sun.jersey.multipart.FormDataMultiPart)3 FileInputStream (java.io.FileInputStream)3 URI (java.net.URI)3 KeyStore (java.security.KeyStore)3