Search in sources :

Example 1 with Http2ServiceRequest

use of com.networknt.client.http.Http2ServiceRequest in project light-4j by networknt.

the class RestClientTemplate method execute.

protected <T> T execute(ServiceDef serviceDef, String path, Class<T> responseType, Map<String, ?> headerMap, HttpString method, String requestBody) throws RestClientException {
    try {
        Http2ServiceRequest http2ServiceRequest = new Http2ServiceRequest(serviceDef, path, method);
        if (statusCodesValid.isPresent())
            http2ServiceRequest.setStatusCodesValid(statusCodesValid.get());
        http2ServiceRequest.setRequestHeaders(headerMap);
        if (requestBody != null)
            http2ServiceRequest.setRequestBody(requestBody);
        return http2ServiceRequest.callForTypedObject(responseType).get();
    } catch (Exception e) {
        String errorStr = "execute the restful API call error:";
        logger.error(errorStr + e);
        throw new RestClientException(errorStr, e);
    }
}
Also used : Http2ServiceRequest(com.networknt.client.http.Http2ServiceRequest) HttpString(io.undertow.util.HttpString)

Example 2 with Http2ServiceRequest

use of com.networknt.client.http.Http2ServiceRequest in project light-4j by networknt.

the class RestClientTemplate method execute.

protected <T> T execute(String url, String path, Class<T> responseType, Map<String, ?> headerMap, HttpString method, String requestBody) throws RestClientException {
    try {
        Http2ServiceRequest http2ServiceRequest = new Http2ServiceRequest(new URI(url), path, method);
        if (statusCodesValid.isPresent())
            http2ServiceRequest.setStatusCodesValid(statusCodesValid.get());
        http2ServiceRequest.setRequestHeaders(headerMap);
        if (requestBody != null)
            http2ServiceRequest.setRequestBody(requestBody);
        return http2ServiceRequest.callForTypedObject(responseType).get();
    } catch (Exception e) {
        String errorStr = "execute the restful API call error:";
        logger.error(errorStr + e);
        throw new RestClientException(errorStr, e);
    }
}
Also used : Http2ServiceRequest(com.networknt.client.http.Http2ServiceRequest) HttpString(io.undertow.util.HttpString) URI(java.net.URI)

Aggregations

Http2ServiceRequest (com.networknt.client.http.Http2ServiceRequest)2 HttpString (io.undertow.util.HttpString)2 URI (java.net.URI)1