use of com.webpieces.http2.api.dto.lowlevel.lib.Http2Header in project webpieces by deanhiller.
the class HttpsJsonClient method sendHttpRequest.
/**
* <b>DO NOT USE FOR PUBLIC HTTP REQUEST THIS IS FOR INTERNAL USE ONLY</b>
*/
public <T> XFuture<T> sendHttpRequest(Method method, Object request, Endpoint endpoint, Class<T> responseType) {
InetSocketAddress apiAddress = endpoint.getServerAddress();
String httpMethod = endpoint.getHttpMethod();
String endpointPath = endpoint.getUrlPath();
Http2Request httpReq = createHttpReq(apiAddress, httpMethod, endpointPath);
RequestCloseListener closeListener = new RequestCloseListener(schedulerSvc);
Http2Socket httpSocket = createSocket(apiAddress, closeListener);
XFuture<Void> connect = httpSocket.connect(apiAddress);
String jsonRequest = marshal(request);
byte[] reqAsBytes = jsonRequest.getBytes(StandardCharsets.UTF_8);
if (jsonRequest.equals("null")) {
// hack
reqAsBytes = new byte[0];
}
DataWrapper data = WRAPPER_GEN.wrapByteArray(reqAsBytes);
if (httpReq.getKnownMethod() == Http2Method.POST) {
httpReq.addHeader(new Http2Header(Http2HeaderName.CONTENT_LENGTH, String.valueOf(data.getReadableSize())));
}
httpReq.addHeader(new Http2Header(Http2HeaderName.SCHEME, "https"));
FullRequest fullRequest = new FullRequest(httpReq, data, null);
log.info("curl request on socket(" + httpSocket + ")" + createCurl(fullRequest, apiAddress.getPort()));
Map<String, Object> fullContext = Context.getContext();
if (fullContext == null) {
throw new IllegalStateException("Missing webserver filters? Context.getFullContext() must contain data");
}
Map<String, String> ctxMap = MDC.getCopyOfContextMap();
Contexts contexts = new Contexts(ctxMap, fullContext);
long start = System.currentTimeMillis();
XFuture<T> future = futureUtil.catchBlockWrap(() -> sendAndTranslate(contexts, apiAddress, responseType, httpSocket, connect, fullRequest, jsonRequest), (t) -> translateException(httpReq, t));
// // Track metrics with future.handle()
// // If method is null, then no need to track metrics
// // If monitoring is null, then this call probably came from OrderlyTest
// if (method != null && monitoring != null) {
// future = future.handle((r, e) -> {
// String clientId = context.getRequest().getRequestState(OrderlyHeaders.CLIENT_ID.getHeaderName());
// monitoring.endHttpClientTimer(method, clientId, endpoint, start);
//
// if (e != null) {
// monitoring.incrementHttpClientExceptionMetric(method, clientId, endpoint, e.getClass().getSimpleName());
// return XFuture.<T>failedFuture(e);
// }
//
// monitoring.incrementHttpClientSuccessMetric(method, clientId, endpoint);
// return XFuture.completedFuture(r);
// }).thenCompose(Function.identity());
// }
// so we can cancel the future exactly when the socket closes
closeListener.setFuture(future);
return future;
}
use of com.webpieces.http2.api.dto.lowlevel.lib.Http2Header in project webpieces by deanhiller.
the class HttpsJsonClient method createHttpReq.
public Http2Request createHttpReq(InetSocketAddress apiAddress, String method, String path) {
Http2Request httpReq = new Http2Request();
httpReq.addHeader(new Http2Header(Http2HeaderName.METHOD, method));
httpReq.addHeader(new Http2Header(Http2HeaderName.AUTHORITY, apiAddress.getHostString()));
httpReq.addHeader(new Http2Header(Http2HeaderName.PATH, path));
httpReq.addHeader(new Http2Header(Http2HeaderName.USER_AGENT, "Webpieces Generated API Client"));
// Http2HeaderName.ACCEPT
httpReq.addHeader(new Http2Header(Http2HeaderName.ACCEPT, "application/json"));
httpReq.addHeader(new Http2Header(Http2HeaderName.CONTENT_TYPE, "application/json"));
Map<String, String> headers = (Map<String, String>) Context.get(Context.HEADERS);
for (Map.Entry<String, String> entry : headers.entrySet()) {
httpReq.addHeader(new Http2Header(entry.getKey(), entry.getValue()));
}
return httpReq;
}
use of com.webpieces.http2.api.dto.lowlevel.lib.Http2Header in project webpieces by deanhiller.
the class RequestCreator method createHttp2Request.
public static Http2Request createHttp2Request() {
Http2Request request = new Http2Request();
request.setEndOfStream(true);
request.addHeader(new Http2Header(Http2HeaderName.METHOD, "/"));
request.addHeader(new Http2Header(Http2HeaderName.PATH, "/"));
request.addHeader(new Http2Header(Http2HeaderName.AUTHORITY, "myhost.com"));
request.addHeader(new Http2Header(Http2HeaderName.SCHEME, "http"));
return request;
}
use of com.webpieces.http2.api.dto.lowlevel.lib.Http2Header in project webpieces by deanhiller.
the class RequestCreator method createHttp2Response.
public static Http2Response createHttp2Response(int streamId) {
Http2Response resp = new Http2Response();
resp.addHeader(new Http2Header(Http2HeaderName.STATUS, "200"));
resp.addHeader(new Http2Header("serverid", "3"));
resp.setEndOfStream(true);
resp.setStreamId(streamId);
return resp;
}
use of com.webpieces.http2.api.dto.lowlevel.lib.Http2Header in project webpieces by deanhiller.
the class Http2Requests method createPush.
public static Http2Push createPush(int streamId) {
Http2Push push = new Http2Push();
push.setStreamId(streamId);
push.addHeader(new Http2Header(Http2HeaderName.SERVER, "me"));
return push;
}
Aggregations