com.mercateo.rest.schemagen.spring.HttpRequestMapper Maven / Gradle / Ivy
package com.mercateo.rest.schemagen.spring;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
class HttpRequestMapper {
Map> requestHeaders(HttpServletRequest httpServletRequest) {
HashMap> requestHeaders = new HashMap<>();
Enumeration headerNames = httpServletRequest.getHeaderNames();
for (String headerName : Collections.list(headerNames)) {
final Enumeration headers = httpServletRequest.getHeaders(headerName);
requestHeaders.put(headerName, Collections.list(headers));
}
return requestHeaders;
}
URI getDefaultBaseUri(HttpServletRequest request) throws URISyntaxException {
final URI uri = new URI(request.getRequestURL().toString());
String path = request.getContextPath() + request.getServletPath();
return new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(), path, null, null);
}
}