use of org.geosdi.geoplatform.services.request.WMSHeaderParam in project geo-platform by geosdi.
the class OGCService method getCapabilitiesAuth.
@Override
public ArrayList<? extends GPLayerGrid> getCapabilitiesAuth(String serverUrl, HttpServletRequest httpServletRequest, Long idServer) throws GeoPlatformException {
try {
HttpSession session = httpServletRequest.getSession();
String token = (String) session.getAttribute("GOOGLE_TOKEN");
/**
*@TODO think a way to have this configured*
*/
String authValue = httpServletRequest.getHeader("iv-user");
// Enumeration<String> headerNames = httpServletRequest.getHeaderNames();
List<WMSHeaderParam> headerParams = Lists.newArrayList();
if ((authValue != null) && !(authValue.trim().isEmpty())) {
headerParams.add(new WMSHeaderParam("iv-user", authValue));
}
// List<WMSHeaderParam> headerKeyValues = Collections.list(headerNames)
// .stream()
// .filter(key -> ((httpServletRequest.getHeader(key) != null)))
// .map(key -> new WMSHeaderParam(key, httpServletRequest.getHeader(key)))
// .collect(toList());
logger.trace("###########################HEADERS_TO_PASS_TO_SERVICE : {}\n", headerParams);
RequestByID req = new RequestByID(idServer);
GSAccount gsAccount = this.sessionUtility.getLoggedAccount(httpServletRequest).getGsAccount();
String authKey = null;
if (gsAccount != null) {
authKey = gsAccount.getAuthkey();
}
ServerDTO server = geoPlatformWMSServiceClient.getCapabilitiesAuth(serverUrl, req, token, authKey, headerParams);
return dtoServerConverter.createRasterLayerList(server.getLayerList());
} catch (ResourceNotFoundFault ex) {
logger.error("Error GetCapabilities: " + ex);
throw new GeoPlatformException(ex.getMessage());
} catch (GPSessionTimeout timeout) {
throw new GeoPlatformException(timeout);
}
}
use of org.geosdi.geoplatform.services.request.WMSHeaderParam in project geo-platform by geosdi.
the class GeoSDIHttpClient5 method get.
/**
* Executes an HTTP GET request against the provided URL and returns the server response.
*
* <p>If an HTTP authentication {@link #getUser() user} and {@link #getPassword() password} is
* set, the appropriate authentication HTTP header will be sent with the request.
*
* <p>If a {@link #getConnectTimeout() connection timeout} is set, the http connection will be
* set to respect that timeout.
*
* <p>If a {@link #getReadTimeout() read timeout} is set, the http connection will be set to
* respect it.
*
* @param url the URL to retrieve
* @return an {@link HTTPResponse} encapsulating the response to the HTTP GET request
*/
@Override
public HTTPResponse get(URL url) throws IOException {
logger.info("Inject OpenAM Cookie Method [GET]");
HttpGet httpGet = new HttpGet(url.toExternalForm());
if (this.tryGzip) {
httpGet.setHeader("Accept-Encoding", "gzip");
}
logger.info("HEADERS : " + this.headers);
if ((this.headers != null) && !(this.headers.isEmpty())) {
for (WMSHeaderParam wmsHeaderParam : this.headers) {
httpGet.setHeader(wmsHeaderParam.getHeaderKey(), wmsHeaderParam.getHeaderValue());
}
}
CloseableHttpResponse response = null;
if (((this.user != null) && !(this.user.trim().isEmpty())) && ((this.password != null) && !(this.password.trim().isEmpty()))) {
logger.trace("############################Using BasicAuth with user : {} - password : {}\n", this.user, this.password);
try {
URI uri = url.toURI();
HttpClientContext localContext = create();
HttpHost targetHost = new HttpHost(uri.getScheme(), uri.getHost(), this.retrieveNoSetPort(uri));
BasicScheme basicAuth = new BasicScheme();
basicAuth.initPreemptive(new UsernamePasswordCredentials(this.user, this.password.toCharArray()));
localContext.resetAuthExchange(targetHost, basicAuth);
response = this.httpClient.execute(targetHost, httpGet, localContext);
} catch (URISyntaxException ex) {
throw new IOException("URISyntaxException error : " + ex.getMessage() + " for URL " + url.toExternalForm());
}
} else {
response = this.httpClient.execute(httpGet);
}
int responseCode = response.getCode();
if (200 != responseCode) {
response.close();
throw new IOException("Server returned HTTP error code " + responseCode + " for URL " + url.toExternalForm());
} else {
return new GeoSDIHttpClient5.HttpMethodResponse(response);
}
}
Aggregations