Search in sources :

Example 41 with Args

use of org.apache.hc.core5.util.Args in project commons-vfs by apache.

the class NHttpFileServer method main.

public static void main(final String[] args) throws Exception {
    if (args.length < 1) {
        System.err.println("Please specify document root directory");
        System.exit(1);
    }
    // Document root directory
    final File docRoot = new File(args[0]);
    int port = 8080;
    if (args.length >= 2) {
        port = Integer.parseInt(args[1]);
    }
    new NHttpFileServer(port, docRoot).start().awaitTermination();
}
Also used : File(java.io.File) ListenerEndpoint(org.apache.hc.core5.reactor.ListenerEndpoint)

Example 42 with Args

use of org.apache.hc.core5.util.Args in project eomcs-java by eomcs.

the class Exam0110 method main.

public static void main(final String[] args) throws Exception {
    final SocketConfig socketConfig = // 
    SocketConfig.custom().setSoTimeout(15, // 
    TimeUnit.SECONDS).setTcpNoDelay(// 
    true).build();
    final HttpServer server = // 
    ServerBootstrap.bootstrap().setListenerPort(// 웹서버 포트 번호 설정
    9999).setSocketConfig(// 기본 소켓 동작 설정
    socketConfig).setSslContext(// SSL 설정
    null).setExceptionListener(// 예외 처리자 설정
    new MyExceptionListener()).register("*", // 요청 처리자 설정
    new HttpFileHandler()).create();
    // 웹서버를 시작시킨다.
    server.start();
    // 웹서버를 종료시키는 스레드를 등록한다.
    Runtime.getRuntime().addShutdownHook(new Thread() {

        @Override
        public void run() {
            server.close(CloseMode.GRACEFUL);
        }
    });
    System.out.println("서버 시작(9999)!");
    server.awaitTermination(TimeValue.MAX_VALUE);
}
Also used : SocketConfig(org.apache.hc.core5.http.io.SocketConfig) HttpServer(org.apache.hc.core5.http.impl.bootstrap.HttpServer)

Example 43 with Args

use of org.apache.hc.core5.util.Args in project eomcs-java by eomcs.

the class Exam0210 method main.

public static void main(final String[] args) throws Exception {
    final SocketConfig socketConfig = // 
    SocketConfig.custom().setSoTimeout(15, // 
    TimeUnit.SECONDS).setTcpNoDelay(// 
    true).build();
    final HttpServer server = // 
    ServerBootstrap.bootstrap().setListenerPort(// 웹서버 포트 번호 설정
    9999).setSocketConfig(// 기본 소켓 동작 설정
    socketConfig).setSslContext(// SSL 설정
    null).setExceptionListener(// 예외 처리자 설정
    new MyExceptionListener()).register("*", // 요청 처리자 설정
    new MyRequestHandler()).create();
    // 웹서버를 시작시킨다.
    server.start();
    // 웹서버를 종료시키는 스레드를 등록한다.
    Runtime.getRuntime().addShutdownHook(new Thread() {

        @Override
        public void run() {
            server.close(CloseMode.GRACEFUL);
        }
    });
    System.out.println("서버 시작(9999)!");
    server.awaitTermination(TimeValue.MAX_VALUE);
}
Also used : SocketConfig(org.apache.hc.core5.http.io.SocketConfig) HttpServer(org.apache.hc.core5.http.impl.bootstrap.HttpServer)

Example 44 with Args

use of org.apache.hc.core5.util.Args in project easeagent by megaease.

the class HttpClient5DoExecuteInterceptorTest method before.

@Test
public void before() {
    Context context = EaseAgent.getContext();
    HttpGet httpGet = new HttpGet("http://127.0.0.1:8080");
    BasicHttpResponse basicHttpResponse = new BasicHttpResponse(200);
    basicHttpResponse.setHeader(TestConst.RESPONSE_TAG_NAME, TestConst.RESPONSE_TAG_VALUE);
    MethodInfo methodInfo = MethodInfo.builder().args(new Object[] { httpGet }).retValue(basicHttpResponse).build();
    HttpClient5DoExecuteInterceptor httpClient5DoExecuteInterceptor = new HttpClient5DoExecuteInterceptor();
    MockEaseAgent.cleanLastSpan();
    httpClient5DoExecuteInterceptor.before(methodInfo, context);
    httpClient5DoExecuteInterceptor.after(methodInfo, context);
    ReportSpan mockSpan = MockEaseAgent.getLastSpan();
    assertNotNull(mockSpan);
    assertEquals(Span.Kind.CLIENT.name(), mockSpan.kind());
    assertEquals(TestConst.RESPONSE_TAG_VALUE, mockSpan.tag(TestConst.RESPONSE_TAG_NAME));
    assertNull(mockSpan.parentId());
    Span span = context.nextSpan();
    try (Scope ignored = span.maybeScope()) {
        httpClient5DoExecuteInterceptor.doBefore(methodInfo, context);
        httpClient5DoExecuteInterceptor.doAfter(methodInfo, context);
        mockSpan = MockEaseAgent.getLastSpan();
        assertEquals(span.traceIdString(), mockSpan.traceId());
        assertEquals(span.spanIdString(), mockSpan.parentId());
        assertNotNull(mockSpan.id());
    }
}
Also used : Context(com.megaease.easeagent.plugin.api.Context) ReportSpan(com.megaease.easeagent.plugin.report.tracing.ReportSpan) BasicHttpResponse(org.apache.hc.core5.http.message.BasicHttpResponse) Scope(com.megaease.easeagent.plugin.api.trace.Scope) HttpGet(org.apache.hc.client5.http.classic.methods.HttpGet) MethodInfo(com.megaease.easeagent.plugin.interceptor.MethodInfo) ReportSpan(com.megaease.easeagent.plugin.report.tracing.ReportSpan) Span(com.megaease.easeagent.plugin.api.trace.Span) Test(org.junit.Test)

Example 45 with Args

use of org.apache.hc.core5.util.Args in project LinkAgent by shulieTech.

the class HttpClientv5MethodInterceptor method exceptionTrace.

@Override
public SpanRecord exceptionTrace(Advice advice) {
    Object[] args = advice.getParameterArray();
    HttpRequest request = (HttpRequest) args[1];
    SpanRecord record = new SpanRecord();
    if (advice.getThrowable() instanceof SocketTimeoutException) {
        record.setResultCode(ResultCode.INVOKE_RESULT_TIMEOUT);
    } else {
        record.setResultCode(ResultCode.INVOKE_RESULT_FAILED);
    }
    try {
        record.setRequest(getParameters(request));
    } catch (Throwable e) {
    }
    record.setResponse(advice.getThrowable());
    return record;
}
Also used : ClassicHttpRequest(org.apache.hc.core5.http.ClassicHttpRequest) HttpRequest(org.apache.hc.core5.http.HttpRequest) SpanRecord(com.pamirs.pradar.interceptor.SpanRecord) SocketTimeoutException(java.net.SocketTimeoutException) JSONObject(com.alibaba.fastjson.JSONObject)

Aggregations

HttpHost (org.apache.hc.core5.http.HttpHost)32 HttpRequest (org.apache.hc.core5.http.HttpRequest)25 HttpResponse (org.apache.hc.core5.http.HttpResponse)24 StatusLine (org.apache.hc.core5.http.message.StatusLine)22 IOReactorConfig (org.apache.hc.core5.reactor.IOReactorConfig)22 IOException (java.io.IOException)21 HttpGet (org.apache.hc.client5.http.classic.methods.HttpGet)19 CloseableHttpClient (org.apache.hc.client5.http.impl.classic.CloseableHttpClient)19 HttpConnection (org.apache.hc.core5.http.HttpConnection)19 CloseableHttpResponse (org.apache.hc.client5.http.impl.classic.CloseableHttpResponse)17 Header (org.apache.hc.core5.http.Header)17 HttpException (org.apache.hc.core5.http.HttpException)16 CountDownLatch (java.util.concurrent.CountDownLatch)13 SimpleHttpRequest (org.apache.hc.client5.http.async.methods.SimpleHttpRequest)13 SimpleHttpResponse (org.apache.hc.client5.http.async.methods.SimpleHttpResponse)12 ClassicHttpRequest (org.apache.hc.core5.http.ClassicHttpRequest)12 StringAsyncEntityConsumer (org.apache.hc.core5.http.nio.entity.StringAsyncEntityConsumer)12 HttpContext (org.apache.hc.core5.http.protocol.HttpContext)12 EntityDetails (org.apache.hc.core5.http.EntityDetails)11 Http1StreamListener (org.apache.hc.core5.http.impl.Http1StreamListener)11