Search in sources :

Example 66 with NameValuePair

use of org.apache.http.NameValuePair in project cas by apereo.

the class WSFederationAuthenticationServiceSelectionStrategy method getRealmAsParameter.

private static Optional<NameValuePair> getRealmAsParameter(final Service service) {
    try {
        final URIBuilder builder = new URIBuilder(service.getId());
        final Optional param = builder.getQueryParams().stream().filter(p -> p.getName().equals(WSFederationConstants.WTREALM)).findFirst();
        return param;
    } catch (final Exception e) {
        LOGGER.error(e.getMessage(), e);
    }
    return Optional.empty();
}
Also used : AuthenticationServiceSelectionStrategy(org.apereo.cas.authentication.AuthenticationServiceSelectionStrategy) Ordered(org.springframework.core.Ordered) Slf4j(lombok.extern.slf4j.Slf4j) URIBuilder(org.apache.http.client.utils.URIBuilder) WSFederationConstants(org.apereo.cas.ws.idp.WSFederationConstants) Service(org.apereo.cas.authentication.principal.Service) Optional(java.util.Optional) NameValuePair(org.apache.http.NameValuePair) ServiceFactory(org.apereo.cas.authentication.principal.ServiceFactory) Optional(java.util.Optional) URIBuilder(org.apache.http.client.utils.URIBuilder)

Example 67 with NameValuePair

use of org.apache.http.NameValuePair in project cas by apereo.

the class WSFederationAuthenticationServiceSelectionStrategy method getReplyAsParameter.

private static Optional<NameValuePair> getReplyAsParameter(final Service service) {
    try {
        final URIBuilder builder = new URIBuilder(service.getId());
        final Optional param = builder.getQueryParams().stream().filter(p -> p.getName().equals(WSFederationConstants.WREPLY)).findFirst();
        return param;
    } catch (final Exception e) {
        LOGGER.error(e.getMessage(), e);
    }
    return Optional.empty();
}
Also used : AuthenticationServiceSelectionStrategy(org.apereo.cas.authentication.AuthenticationServiceSelectionStrategy) Ordered(org.springframework.core.Ordered) Slf4j(lombok.extern.slf4j.Slf4j) URIBuilder(org.apache.http.client.utils.URIBuilder) WSFederationConstants(org.apereo.cas.ws.idp.WSFederationConstants) Service(org.apereo.cas.authentication.principal.Service) Optional(java.util.Optional) NameValuePair(org.apache.http.NameValuePair) ServiceFactory(org.apereo.cas.authentication.principal.ServiceFactory) Optional(java.util.Optional) URIBuilder(org.apache.http.client.utils.URIBuilder)

Example 68 with NameValuePair

use of org.apache.http.NameValuePair in project felix by apache.

the class ITScriptConsolePlugin method execute2.

private void execute2(String code) throws Exception {
    RequestBuilder rb = new RequestBuilder(ServerConfiguration.getServerUrl());
    List<NameValuePair> params = new ArrayList<NameValuePair>();
    params.add(new BasicNameValuePair("lang", "groovy"));
    params.add(new BasicNameValuePair("code", code));
    final HttpEntity entity = new UrlEncodedFormEntity(params);
    // Add Sling POST options
    executor.execute(rb.buildPostRequest("/system/console/sc").withEntity(entity).withCredentials("admin", "admin")).assertStatus(200);
}
Also used : BasicNameValuePair(org.apache.http.message.BasicNameValuePair) NameValuePair(org.apache.http.NameValuePair) RequestBuilder(org.apache.sling.testing.tools.http.RequestBuilder) HttpEntity(org.apache.http.HttpEntity) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) ArrayList(java.util.ArrayList) UrlEncodedFormEntity(org.apache.http.client.entity.UrlEncodedFormEntity)

Example 69 with NameValuePair

use of org.apache.http.NameValuePair in project sling by apache.

the class FormTest method testForm.

@Test
public void testForm() throws ClientException, URISyntaxException {
    MicrodataHtmlClient client = new MicrodataHtmlClient(httpServer.getURI().toString());
    Document doc = client.enter(GET_URL);
    Items items = doc.items();
    Assert.assertThat(items.length(), equalTo(1));
    Items form = doc.form("test");
    Assert.assertThat(form.length(), equalTo(2));
    List<NameValuePair> data = new ArrayList<NameValuePair>();
    data.add(new BasicNameValuePair("f1", "val1"));
    // url encode enctype
    Document doc2 = form.at(0).submit(data);
    Assert.assertThat(doc2.items().length(), equalTo(1));
    // the multipart enctype
    Document doc3 = form.at(1).submit(data);
    Assert.assertThat(doc3.items().length(), equalTo(1));
}
Also used : BasicNameValuePair(org.apache.http.message.BasicNameValuePair) NameValuePair(org.apache.http.NameValuePair) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) ArrayList(java.util.ArrayList) Items(org.apache.sling.hapi.client.Items) MicrodataHtmlClient(org.apache.sling.hapi.client.impl.microdata.MicrodataHtmlClient) Document(org.apache.sling.hapi.client.Document) Test(org.junit.Test)

Example 70 with NameValuePair

use of org.apache.http.NameValuePair in project sling by apache.

the class RemoteTestHttpClient method runTests.

public RequestExecutor runTests(String testClassesSelector, String testMethodSelector, String extension, Map<String, String> requestOptions) throws ClientProtocolException, IOException {
    final RequestBuilder builder = new RequestBuilder(junitServletUrl);
    // Optionally let the client to consume the response entity
    final RequestExecutor executor = new RequestExecutor(new DefaultHttpClient()) {

        @Override
        protected void consumeEntity() throws ParseException, IOException {
            if (consumeContent) {
                super.consumeEntity();
            }
        }
    };
    // Build path for POST request to execute the tests
    // Test classes selector
    subpath = new StringBuilder();
    if (!junitServletUrl.endsWith(SLASH)) {
        subpath.append(SLASH);
    }
    subpath.append(testClassesSelector);
    // Test method selector
    if (testMethodSelector != null && testMethodSelector.length() > 0) {
        subpath.append("/");
        subpath.append(testMethodSelector);
    }
    // Extension
    if (!extension.startsWith(DOT)) {
        subpath.append(DOT);
    }
    subpath.append(extension);
    // Request options if any
    final List<NameValuePair> opt = new ArrayList<NameValuePair>();
    if (requestOptions != null) {
        for (Map.Entry<String, String> e : requestOptions.entrySet()) {
            opt.add(new BasicNameValuePair(e.getKey(), e.getValue()));
        }
    }
    log.info("Executing test remotely, path={} JUnit servlet URL={}", subpath, junitServletUrl);
    final Request r = builder.buildPostRequest(subpath.toString()).withCredentials(username, password).withCustomizer(requestCustomizer).withEntity(new UrlEncodedFormEntity(opt));
    executor.execute(r).assertStatus(200);
    return executor;
}
Also used : BasicNameValuePair(org.apache.http.message.BasicNameValuePair) NameValuePair(org.apache.http.NameValuePair) RequestBuilder(org.apache.sling.testing.tools.http.RequestBuilder) RequestExecutor(org.apache.sling.testing.tools.http.RequestExecutor) ArrayList(java.util.ArrayList) Request(org.apache.sling.testing.tools.http.Request) UrlEncodedFormEntity(org.apache.http.client.entity.UrlEncodedFormEntity) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) Map(java.util.Map)

Aggregations

NameValuePair (org.apache.http.NameValuePair)713 BasicNameValuePair (org.apache.http.message.BasicNameValuePair)592 ArrayList (java.util.ArrayList)478 UrlEncodedFormEntity (org.apache.http.client.entity.UrlEncodedFormEntity)256 HttpPost (org.apache.http.client.methods.HttpPost)218 HttpResponse (org.apache.http.HttpResponse)150 IOException (java.io.IOException)125 HttpEntity (org.apache.http.HttpEntity)108 Test (org.junit.Test)85 URI (java.net.URI)79 Map (java.util.Map)72 HashMap (java.util.HashMap)68 HttpGet (org.apache.http.client.methods.HttpGet)66 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)59 UnsupportedEncodingException (java.io.UnsupportedEncodingException)58 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)55 URISyntaxException (java.net.URISyntaxException)52 Document (org.jsoup.nodes.Document)51 URIBuilder (org.apache.http.client.utils.URIBuilder)50 HttpClient (org.apache.http.client.HttpClient)46