Search in sources :

Example 1 with FieldParam

use of core.framework.impl.log.filter.FieldParam in project core-ng-project by neowu.

the class ResponseHandler method putCookies.

private void putCookies(ResponseImpl response, HttpServerExchange exchange) {
    if (response.cookies != null) {
        Map<String, Cookie> cookies = exchange.getResponseCookies();
        response.cookies.forEach((spec, value) -> {
            CookieImpl cookie = cookie(spec, value);
            cookies.put(spec.name, cookie);
            logger.debug("[response:cookie] name={}, value={}, domain={}, path={}, secure={}, httpOnly={}, maxAge={}", spec.name, new FieldParam(spec.name, cookie.getValue()), cookie.getDomain(), cookie.getPath(), cookie.isSecure(), cookie.isHttpOnly(), cookie.getMaxAge());
        });
    }
}
Also used : Cookie(io.undertow.server.handlers.Cookie) CookieImpl(io.undertow.server.handlers.CookieImpl) FieldParam(core.framework.impl.log.filter.FieldParam)

Example 2 with FieldParam

use of core.framework.impl.log.filter.FieldParam in project core-ng-project by neowu.

the class ResponseHandler method putHeaders.

private void putHeaders(ResponseImpl response, HttpServerExchange exchange) {
    HeaderMap headers = exchange.getResponseHeaders();
    response.headers.forEach((name, value) -> {
        headers.put(name, value);
        logger.debug("[response:header] {}={}", name, new FieldParam(name, value));
    });
}
Also used : HeaderMap(io.undertow.util.HeaderMap) FieldParam(core.framework.impl.log.filter.FieldParam)

Example 3 with FieldParam

use of core.framework.impl.log.filter.FieldParam in project core-ng-project by neowu.

the class RequestParser method parseForm.

private void parseForm(RequestImpl request, HttpServerExchange exchange) {
    FormData formData = exchange.getAttachment(FormDataParser.FORM_DATA);
    if (formData == null)
        return;
    for (String name : formData) {
        FormData.FormValue value = formData.getFirst(name);
        if (value.isFile()) {
            if (!Strings.isEmpty(value.getFileName())) {
                // browser passes empty file name if not choose file in form
                logger.debug("[request:file] {}={}, size={}", name, value.getFileName(), Files.size(value.getPath()));
                request.files.put(name, new MultipartFile(value.getPath(), value.getFileName(), value.getHeaders().getFirst(Headers.CONTENT_TYPE)));
            }
        } else {
            logger.debug("[request:form] {}={}", name, new FieldParam(name, value.getValue()));
            request.formParams.put(name, value.getValue());
        }
    }
}
Also used : FormData(io.undertow.server.handlers.form.FormData) MultipartFile(core.framework.web.MultipartFile) FieldParam(core.framework.impl.log.filter.FieldParam) HttpString(io.undertow.util.HttpString)

Example 4 with FieldParam

use of core.framework.impl.log.filter.FieldParam in project core-ng-project by neowu.

the class HTTPClientImpl method httpRequest.

HttpUriRequest httpRequest(HTTPRequest request) {
    HTTPMethod method = request.method();
    String uri = request.uri();
    logger.debug("[request] method={}, uri={}", method, uri);
    RequestBuilder builder = RequestBuilder.create(method.name());
    try {
        builder.setUri(uri);
    } catch (IllegalArgumentException e) {
        throw new HTTPClientException("uri is invalid, uri=" + uri, "INVALID_URL", e);
    }
    request.headers().forEach((name, value) -> {
        logger.debug("[request:header] {}={}", name, new FieldParam(name, value));
        builder.setHeader(name, value);
    });
    request.params().forEach((name, value) -> {
        logger.debug("[request:param] {}={}", name, value);
        builder.addParameter(name, value);
    });
    byte[] body = request.body();
    if (body != null) {
        ContentType contentType = request.contentType();
        logRequestBody(request, contentType);
        org.apache.http.entity.ContentType type = org.apache.http.entity.ContentType.create(contentType.mediaType(), contentType.charset().orElse(null));
        builder.setEntity(new ByteArrayEntity(request.body(), type));
    }
    return builder.build();
}
Also used : RequestBuilder(org.apache.http.client.methods.RequestBuilder) FieldParam(core.framework.impl.log.filter.FieldParam) ContentType(core.framework.http.ContentType) ByteArrayEntity(org.apache.http.entity.ByteArrayEntity) HTTPMethod(core.framework.http.HTTPMethod) HTTPClientException(core.framework.http.HTTPClientException)

Aggregations

FieldParam (core.framework.impl.log.filter.FieldParam)4 ContentType (core.framework.http.ContentType)1 HTTPClientException (core.framework.http.HTTPClientException)1 HTTPMethod (core.framework.http.HTTPMethod)1 MultipartFile (core.framework.web.MultipartFile)1 Cookie (io.undertow.server.handlers.Cookie)1 CookieImpl (io.undertow.server.handlers.CookieImpl)1 FormData (io.undertow.server.handlers.form.FormData)1 HeaderMap (io.undertow.util.HeaderMap)1 HttpString (io.undertow.util.HttpString)1 RequestBuilder (org.apache.http.client.methods.RequestBuilder)1 ByteArrayEntity (org.apache.http.entity.ByteArrayEntity)1