/** * Returns the HTTP URL for accessing the {@link ResourcesServlet}. * <p> * NOTE: This method will only return a correct result if the calling thread originated in the * {@link #doGet(HttpServletRequest, HttpServletResponse)} or * {@link #doPost(HttpServletRequest, HttpServletResponse)} of this class (or has been spawned as a child thread by * such a thread). * </p> * * @return URL, never <code>null</code> (without trailing slash or question mark) */ public static String getResourcesUrl() { return getContext().getResourcesUrl(); }
private void bindContextToThread( HttpServletRequest request, Credentials credentials ) { RequestContext context = new RequestContext( request, credentials, hardcodedServicesUrl, hardcodedResourcesUrl ); CONTEXT.set( context ); LOG.debug( "Initialized RequestContext for Thread " + Thread.currentThread() + "=" + context ); }
private static String getHttpURL() { RequestContext context = getContext(); String xForwardedHost = context.getXForwardedHost(); if ( xForwardedHost != null && xForwardedHost != "" ) { String contextServiceUrl = context.getServiceUrl(); try { URL serviceUrl = new URL( contextServiceUrl ); return buildUrlFromForwardedHeader( context, serviceUrl ); } catch ( MalformedURLException e ) { LOG.warn( "Could not parse service URL as URL: " + contextServiceUrl ); } } return context.getServiceUrl(); }
private static String buildUrlFromForwardedHeader( RequestContext context, URL serviceUrl ) throws MalformedURLException { String xForwardedPort = context.getXForwardedPort(); String xForwardedHost = context.getXForwardedHost(); String xForwardedProto = context.getXForwardedProto(); String protocol = parseProtocol( xForwardedProto, serviceUrl ); String port = parsePort( xForwardedPort, serviceUrl ); String path = serviceUrl.getPath(); StringBuffer urlBuilder = new StringBuffer(); urlBuilder.append( protocol ).append( "://" ).append( xForwardedHost ); if ( port != null ) urlBuilder.append( ":" ).append( port ); if ( path != null && !"".equals( path ) ) urlBuilder.append( path ); return urlBuilder.toString(); }
@Override protected void exportCapas( String getUrl, String postUrl, MapService service, HttpResponseBuffer response, ServiceIdentification identification, ServiceProvider provider, Map<String, String> customParameters, WMSController controller, OWSMetadataProvider metadata ) throws IOException, OWSException { response.setContentType( "application/vnd.ogc.wms_xml" ); String userAgent = OGCFrontController.getContext().getUserAgent(); if ( userAgent != null && userAgent.toLowerCase().contains( "mozilla" ) ) { response.setContentType( "application/xml" ); } response.addHeader( "Content-Disposition", "inline; filename=\"capabilities.xml\"" ); try { XMLStreamWriter xmlWriter = response.getXMLWriter(); new Capabilities111XMLAdapter( identification, provider, metadata, getUrl, postUrl, service, controller ).export( xmlWriter ); } catch ( XMLStreamException e ) { throw new IOException( e ); } }
/** * Returns the URL for contacting the {@link OGCFrontController} instance via HTTP (including OGC service instance * path info, if available). * * @return the URL (without trailing slash or question mark), never <code>null</code> */ public String getServiceUrl() { if ( hardcodedServicesUrl != null ) { return getServiceUrlWithPathInfo( hardcodedServicesUrl ); } return requestedEndpointUrl; }
/** * @param request * request for which the context will be created, must not be <code>null</code> * @param credentials * credentials associated with the request, can be <code>null</code> * @param hardcodedServicesUrl * URL to be used for accessing the OGCFrontController, can be <code>null</code> (derive from request) * @param hardcodedResourcesUrl * URL to be used for accessing the ResourcesServlet, can be <code>null</code> (derive from request) */ RequestContext( HttpServletRequest request, Credentials credentials, String hardcodedServicesUrl, String hardcodedResourcesUrl ) { this.hardcodedServicesUrl = hardcodedServicesUrl; this.hardcodedResourcesUrl = hardcodedResourcesUrl; this.credentials = credentials; pathInfo = request.getPathInfo(); requestedEndpointUrl = request.getRequestURL().toString(); webappBaseUrl = deriveWebappBaseUrl( requestedEndpointUrl, request ); userAgent = request.getHeader( "user-agent" ); xForwardedPort = request.getHeader( "X-Forwarded-Port" ); xForwardedHost = request.getHeader( "X-Forwarded-Host" ); xForwardedProto = request.getHeader( "X-Forwarded-Proto" ); if ( LOG.isDebugEnabled() ) { LOG.debug( "Request URL: " + requestedEndpointUrl ); LOG.debug( "Webapp base URL (derived from request): " + webappBaseUrl ); LOG.debug( "Hardcoded services URL: " + hardcodedServicesUrl ); LOG.debug( "Hardcoded resources URL: " + hardcodedResourcesUrl ); } }
String userAgent = null; if ( OGCFrontController.getContext() != null ) { userAgent = OGCFrontController.getContext().getUserAgent();
String userAgent = null; if ( OGCFrontController.getContext() != null ) { userAgent = OGCFrontController.getContext().getUserAgent();
public String getRestURL() { return OGCFrontController.getContext().getResourcesUrl() + "../rest" + UriBuilder.fromResource( WSDLResource.class ).path( WSDLResource.class, "get" ).build( "ALL" ).toString(); } }