org.apache.hc.core5.http.HttpResponse Java Examples

The following examples show how to use org.apache.hc.core5.http.HttpResponse. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ListenpointHttp2.java    From mts with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean sendMessage(Msg msg, String remoteHost, int remotePort, String transport) throws Exception {
    MsgHttp2 beginMsg = (MsgHttp2) msg.getTransaction().getBeginMsg();

    MsgHttp2 msgHttp2 = (MsgHttp2) msg;
    msgHttp2.setType(beginMsg.getType());
    msgHttp2.setListenpoint(beginMsg.getListenpoint());
    HttpResponse msgResponse = (HttpResponse) msgHttp2.getMessage();
    if (msgHttp2.getMessageContent() == null) {
        beginMsg.getResponseTrigger().submitResponse(new BasicResponseProducer(msgResponse), beginMsg.getContext());
    } else {
        beginMsg.getResponseTrigger().submitResponse(new BasicResponseProducer(msgResponse, new BasicAsyncEntityProducer(msgHttp2.getMessageContent().getBytes())), beginMsg.getContext());
    }
    GlobalLogger.instance().getApplicationLogger().debug(TextEvent.Topic.PROTOCOL, "Listenpoint: sendMessage() ", msgHttp2);
    return true;
}
 
Example #2
Source File: HttpLoaderServer.java    From mts with GNU General Public License v3.0 6 votes vote down vote up
public void receiveResponse(String method, String uri, int numberRequest)throws HttpException, IOException
{
    HttpResponse response;
    try
    {
        for(int i=0; i < numberRequest; i++)
        {
            BasicHttpRequest br = new BasicHttpRequest(method, uri+i);
            //response=myclass.doReceiveResponse(br,Clientconn,context);
            //System.out.println(EntityUtils.toString(response.getEntity()));
           // response.getEntity().consumeContent();
            //System.out.println(response.getStatusLine());
        }
    }
    catch(Exception e)
    {}
}
 
Example #3
Source File: Http5FileContentInfoFactory.java    From commons-vfs with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public FileContentInfo create(final FileContent fileContent) throws FileSystemException {
    String contentMimeType = null;
    String contentCharset = null;

    try (final Http5FileObject<Http5FileSystem> http4File = (Http5FileObject<Http5FileSystem>) FileObjectUtils
            .getAbstractFileObject(fileContent.getFile())) {
        final HttpResponse lastHeadResponse = http4File.getLastHeadResponse();

        final Header header = lastHeadResponse.getFirstHeader(HttpHeaders.CONTENT_TYPE);

        if (header != null) {
            final ContentType contentType = ContentType.parse(header.getValue());
            contentMimeType = contentType.getMimeType();

            if (contentType.getCharset() != null) {
                contentCharset = contentType.getCharset().name();
            }
        }

        return new DefaultFileContentInfo(contentMimeType, contentCharset);
    } catch (final IOException e) {
        throw new FileSystemException(e);
    }
}
 
Example #4
Source File: DemoIntegrationAT.java    From n2o-framework with Apache License 2.0 5 votes vote down vote up
/**
 * Проверка отдачи статики
 */
@Test
@Order(1)
public void checkStaticContent() throws IOException {
    HttpUriRequest request = new HttpGet("http://localhost:" + port + "/index.html");
    HttpResponse httpResponse = HttpClientBuilder.create().build().execute(request);
    assertThat(httpResponse.getCode(), equalTo(HttpStatus.SC_OK));
}
 
Example #5
Source File: TraceeHttpResponseInterceptor.java    From tracee with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public final void process(HttpResponse response, HttpContext context) {
	final TraceeFilterConfiguration filterConfiguration = backend.getConfiguration(profile);
	final Iterator<Header> headerIterator = response.headerIterator(TraceeConstants.TPIC_HEADER);
	if (headerIterator != null && headerIterator.hasNext() && filterConfiguration.shouldProcessContext(IncomingResponse)) {
		final List<String> stringTraceeHeaders = new ArrayList<>();
		while (headerIterator.hasNext()) {
			stringTraceeHeaders.add(headerIterator.next().getValue());
		}
		backend.putAll(filterConfiguration.filterDeniedParams(transportSerialization.parse(stringTraceeHeaders), IncomingResponse));
	}
}
 
Example #6
Source File: TraceeHttpResponseInterceptorTest.java    From tracee with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void testResponseInterceptorParsesHttpHeaderToBackend() throws Exception {
	final HttpResponse httpResponse = new BasicHttpResponse(new BasicStatusLine(HttpVersion.HTTP_1_1, 404, "not found"));
	httpResponse.setHeader(TraceeConstants.TPIC_HEADER, "foobi=bar");
	unit.process(httpResponse, mock(HttpContext.class));
	assertThat(backend.get("foobi"), equalTo("bar"));
}
 
Example #7
Source File: TraceeHttpInterceptorsIT.java    From tracee with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void testWritesToServerAndParsesResponse() throws IOException {

	HttpClientBuilder httpClientBuilder = HttpClientBuilder.create();
	httpClientBuilder.addInterceptorLast(new TraceeHttpRequestInterceptor());
	httpClientBuilder.addInterceptorFirst(new TraceeHttpResponseInterceptor());
	CloseableHttpClient httpClient = httpClientBuilder.build();

	HttpGet getMethod = new HttpGet(serverEndpoint);
	Tracee.getBackend().put("before Request", "yip");
	final HttpResponse response = httpClient.execute(getMethod);

	assertThat(response.getStatusLine().getStatusCode(), equalTo(HttpServletResponse.SC_NO_CONTENT));
	assertThat(Tracee.getBackend().get("responseFromServer"), equalTo("yes Sir"));
}
 
Example #8
Source File: Http5FileObject.java    From commons-vfs with Apache License 2.0 5 votes vote down vote up
/**
 * Return the last executed HEAD {@code HttpResponse} object.
 *
 * @return the last executed HEAD {@code HttpResponse} object
 * @throws IOException if IO error occurs
 */
HttpResponse getLastHeadResponse() throws IOException {
    if (lastHeadResponse != null) {
        return lastHeadResponse;
    }

    return executeHttpUriRequest(new HttpHead(getInternalURI()));
}