Search in sources :

Example 81 with BasicHttpResponse

use of org.graylog.shaded.elasticsearch7.org.apache.http.message.BasicHttpResponse in project opencast by opencast.

the class TrustedHttpClientImplTest method setUp.

@Before
public void setUp() throws Exception {
    // Setup bundle context for TrustedHttpClientImpl
    bundleContextMock = createNiceMock(BundleContext.class);
    expect(bundleContextMock.getProperty(TrustedHttpClientImpl.DIGEST_AUTH_USER_KEY)).andReturn("matterhorn_system_account");
    expect(bundleContextMock.getProperty(TrustedHttpClientImpl.DIGEST_AUTH_PASS_KEY)).andReturn("CHANGE_ME");
    expect(bundleContextMock.getProperty(TrustedHttpClientImpl.NONCE_TIMEOUT_RETRY_KEY)).andReturn("3");
    expect(bundleContextMock.getProperty(TrustedHttpClientImpl.NONCE_TIMEOUT_RETRY_BASE_TIME_KEY)).andReturn("0");
    expect(bundleContextMock.getProperty(TrustedHttpClientImpl.NONCE_TIMEOUT_RETRY_MAXIMUM_VARIABLE_TIME_KEY)).andReturn("0");
    replay(bundleContextMock);
    componentContextMock = createNiceMock(ComponentContext.class);
    expect(componentContextMock.getBundleContext()).andReturn(bundleContextMock).anyTimes();
    replay(componentContextMock);
    long currentJobId = 20L;
    Job currentJob = createNiceMock(Job.class);
    expect(currentJob.getId()).andReturn(currentJobId).anyTimes();
    replay(currentJob);
    securityService = createNiceMock(SecurityService.class);
    expect(securityService.getOrganization()).andReturn(new DefaultOrganization()).anyTimes();
    expect(securityService.getUser()).andReturn(new JaxbUser()).anyTimes();
    replay(securityService);
    serviceRegistry = createNiceMock(ServiceRegistry.class);
    expect(serviceRegistry.getCurrentJob()).andReturn(currentJob).anyTimes();
    expect(serviceRegistry.getJob(currentJobId)).andReturn(currentJob).anyTimes();
    replay(serviceRegistry);
    client = new TrustedHttpClientImpl("matterhorn_system_account", "CHANGE_ME");
    client.setServiceRegistry(serviceRegistry);
    client.setSecurityService(securityService);
    client.activate(componentContextMock);
    // Setup responses.
    String digestValue = "Digest realm=\"testrealm@host.com\"," + "qop=\"auth,auth-int\"," + "nonce=\"dcd98b7102dd2f0e8b11d0f600bfb0c093\"," + "opaque=\"5ccc069c403ebaf9f0171e9517f40e41\"";
    okResponse = new BasicHttpResponse(new BasicStatusLine(new ProtocolVersion("Http", 1, 1), 200, "Good to go"));
    digestResponse = new BasicHttpResponse(new ProtocolVersion("Http", 1, 1), 401, "Unauthorized");
    digestResponse.addHeader("WWW-Authenticate", digestValue);
    nonceResponse = new BasicHttpResponse(new BasicStatusLine(new ProtocolVersion("Http", 1, 1), 401, "Nonce has expired/timed out"));
}
Also used : ComponentContext(org.osgi.service.component.ComponentContext) JaxbUser(org.opencastproject.security.api.JaxbUser) ProtocolVersion(org.apache.http.ProtocolVersion) BasicStatusLine(org.apache.http.message.BasicStatusLine) BasicHttpResponse(org.apache.http.message.BasicHttpResponse) SecurityService(org.opencastproject.security.api.SecurityService) ServiceRegistry(org.opencastproject.serviceregistry.api.ServiceRegistry) Job(org.opencastproject.job.api.Job) BundleContext(org.osgi.framework.BundleContext) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) Before(org.junit.Before)

Example 82 with BasicHttpResponse

use of org.graylog.shaded.elasticsearch7.org.apache.http.message.BasicHttpResponse in project opencast by opencast.

the class HttpNotificationWorkflowOperationHandlerTest method setUp.

@Before
public void setUp() throws Exception {
    MediaPackageBuilder builder = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder();
    // test resources
    URI uriMP = getClass().getResource("/concat_mediapackage.xml").toURI();
    mp = builder.loadFromXml(uriMP.toURL().openStream());
    // set up mock trusted http client
    client = EasyMock.createNiceMock(TrustedHttpClient.class);
    HttpResponse response = new BasicHttpResponse(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), HttpStatus.SC_ACCEPTED, ""));
    EasyMock.expect(client.execute((HttpUriRequest) EasyMock.anyObject(), EasyMock.anyInt(), EasyMock.anyInt())).andReturn(response);
    EasyMock.replay(client);
    // set up service
    operationHandler = new HttpNotificationWorkflowOperationHandler();
}
Also used : TrustedHttpClient(org.opencastproject.security.api.TrustedHttpClient) BasicHttpResponse(org.apache.http.message.BasicHttpResponse) MediaPackageBuilder(org.opencastproject.mediapackage.MediaPackageBuilder) BasicHttpResponse(org.apache.http.message.BasicHttpResponse) HttpResponse(org.apache.http.HttpResponse) ProtocolVersion(org.apache.http.ProtocolVersion) URI(java.net.URI) BasicStatusLine(org.apache.http.message.BasicStatusLine) Before(org.junit.Before)

Example 83 with BasicHttpResponse

use of org.graylog.shaded.elasticsearch7.org.apache.http.message.BasicHttpResponse in project android-volley by mcxiaoke.

the class HurlStack method performRequest.

@Override
public HttpResponse performRequest(Request<?> request, Map<String, String> additionalHeaders) throws IOException, AuthFailureError {
    String url = request.getUrl();
    HashMap<String, String> map = new HashMap<String, String>();
    map.putAll(request.getHeaders());
    map.putAll(additionalHeaders);
    if (mUrlRewriter != null) {
        String rewritten = mUrlRewriter.rewriteUrl(url);
        if (rewritten == null) {
            throw new IOException("URL blocked by rewriter: " + url);
        }
        url = rewritten;
    }
    URL parsedUrl = new URL(url);
    HttpURLConnection connection = openConnection(parsedUrl, request);
    for (String headerName : map.keySet()) {
        connection.addRequestProperty(headerName, map.get(headerName));
    }
    setConnectionParametersForRequest(connection, request);
    // Initialize HttpResponse with data from the HttpURLConnection.
    ProtocolVersion protocolVersion = new ProtocolVersion("HTTP", 1, 1);
    int responseCode = connection.getResponseCode();
    if (responseCode == -1) {
        // Signal to the caller that something was wrong with the connection.
        throw new IOException("Could not retrieve response code from HttpUrlConnection.");
    }
    StatusLine responseStatus = new BasicStatusLine(protocolVersion, connection.getResponseCode(), connection.getResponseMessage());
    BasicHttpResponse response = new BasicHttpResponse(responseStatus);
    if (hasResponseBody(request.getMethod(), responseStatus.getStatusCode())) {
        response.setEntity(entityFromConnection(connection));
    }
    for (Entry<String, List<String>> header : connection.getHeaderFields().entrySet()) {
        if (header.getKey() != null) {
            Header h = new BasicHeader(header.getKey(), header.getValue().get(0));
            response.addHeader(h);
        }
    }
    return response;
}
Also used : HashMap(java.util.HashMap) IOException(java.io.IOException) ProtocolVersion(org.apache.http.ProtocolVersion) URL(java.net.URL) BasicStatusLine(org.apache.http.message.BasicStatusLine) BasicStatusLine(org.apache.http.message.BasicStatusLine) StatusLine(org.apache.http.StatusLine) BasicHttpResponse(org.apache.http.message.BasicHttpResponse) HttpURLConnection(java.net.HttpURLConnection) Header(org.apache.http.Header) BasicHeader(org.apache.http.message.BasicHeader) List(java.util.List) BasicHeader(org.apache.http.message.BasicHeader)

Example 84 with BasicHttpResponse

use of org.graylog.shaded.elasticsearch7.org.apache.http.message.BasicHttpResponse in project android-volley by mcxiaoke.

the class BasicNetworkTest method headersAndPostParams.

@Test
public void headersAndPostParams() throws Exception {
    MockHttpStack mockHttpStack = new MockHttpStack();
    BasicHttpResponse fakeResponse = new BasicHttpResponse(new ProtocolVersion("HTTP", 1, 1), 200, "OK");
    fakeResponse.setEntity(new StringEntity("foobar"));
    mockHttpStack.setResponseToReturn(fakeResponse);
    BasicNetwork httpNetwork = new BasicNetwork(mockHttpStack);
    Request<String> request = new Request<String>(Request.Method.GET, "http://foo", null) {

        @Override
        protected Response<String> parseNetworkResponse(NetworkResponse response) {
            return null;
        }

        @Override
        protected void deliverResponse(String response) {
        }

        @Override
        public Map<String, String> getHeaders() {
            Map<String, String> result = new HashMap<String, String>();
            result.put("requestheader", "foo");
            return result;
        }

        @Override
        public Map<String, String> getParams() {
            Map<String, String> result = new HashMap<String, String>();
            result.put("requestpost", "foo");
            return result;
        }
    };
    httpNetwork.performRequest(request);
    assertEquals("foo", mockHttpStack.getLastHeaders().get("requestheader"));
    assertEquals("requestpost=foo&", new String(mockHttpStack.getLastPostBody()));
}
Also used : StringEntity(org.apache.http.entity.StringEntity) MockHttpStack(com.android.volley.mock.MockHttpStack) BasicHttpResponse(org.apache.http.message.BasicHttpResponse) HashMap(java.util.HashMap) Request(com.android.volley.Request) NetworkResponse(com.android.volley.NetworkResponse) ProtocolVersion(org.apache.http.ProtocolVersion) Test(org.junit.Test)

Example 85 with BasicHttpResponse

use of org.graylog.shaded.elasticsearch7.org.apache.http.message.BasicHttpResponse in project jo-client-platform by jo-source.

the class HttpClientStub method post.

private HttpResponse post(final HttpPost request) throws IOException, ClientProtocolException {
    postInvocations.incrementAndGet();
    final StatusLine status = postStatus.get();
    if (status.getStatusCode() == 200) {
        try {
            queue.put((MessageStub) new ObjectInputStream(request.getEntity().getContent()).readObject());
        } catch (final Exception e) {
            throw new RuntimeException(e);
        }
    }
    return new BasicHttpResponse(status);
}
Also used : BasicStatusLine(org.apache.http.message.BasicStatusLine) StatusLine(org.apache.http.StatusLine) BasicHttpResponse(org.apache.http.message.BasicHttpResponse) ClientProtocolException(org.apache.http.client.ClientProtocolException) IOException(java.io.IOException) ObjectInputStream(java.io.ObjectInputStream)

Aggregations

BasicHttpResponse (org.apache.http.message.BasicHttpResponse)107 BasicStatusLine (org.apache.http.message.BasicStatusLine)64 ProtocolVersion (org.apache.http.ProtocolVersion)58 HttpResponse (org.apache.http.HttpResponse)51 StatusLine (org.apache.http.StatusLine)39 Test (org.junit.Test)39 StringEntity (org.apache.http.entity.StringEntity)34 IOException (java.io.IOException)33 List (java.util.List)24 Header (org.apache.http.Header)22 HttpHost (org.apache.http.HttpHost)19 HashMap (java.util.HashMap)18 URL (java.net.URL)17 BasicHeader (org.apache.http.message.BasicHeader)17 HttpURLConnection (java.net.HttpURLConnection)16 HttpEntity (org.apache.http.HttpEntity)14 MainResponse (org.elasticsearch.action.main.MainResponse)14 Before (org.junit.Before)13 BasicHttpEntity (org.apache.http.entity.BasicHttpEntity)12 ElasticsearchException (org.elasticsearch.ElasticsearchException)12