Java Code Examples for org.eclipse.jetty.server.handler.ContextHandler#getContextPath()

The following examples show how to use org.eclipse.jetty.server.handler.ContextHandler#getContextPath() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ODataTestServer.java    From syndesis with Apache License 2.0 5 votes vote down vote up
private String serverBaseUri(NetworkConnector connector) {
    if (connector == null) {
        return null;
    }

    ContextHandler context = getChildHandlerByClass(ContextHandler.class);

    try {
        String protocol = connector.getDefaultConnectionFactory().getProtocol();
        String scheme = "http";
        if (protocol.startsWith("SSL-") || protocol.equals("SSL"))
            scheme = "https";

        String host = connector.getHost();
        if (context != null && context.getVirtualHosts() != null && context.getVirtualHosts().length > 0)
            host = context.getVirtualHosts()[0];
        if (host == null)
            host = InetAddress.getLocalHost().getHostAddress();

        String path = context == null ? null : context.getContextPath();
        if (path == null) {
            path = FORWARD_SLASH;
        }

        URI uri = new URI(scheme, null, host, connector.getLocalPort(), path, null, null);
        return uri.toString();
    }
    catch(Exception e) {
        LOG.error("Uri error", e);
        return null;
    }
}
 
Example 2
Source File: JettyHTTPServerEngine.java    From cxf with Apache License 2.0 5 votes vote down vote up
private String getHandlerName(URL url, ContextHandler context) {
    String contextPath = context.getContextPath();
    String path = url.getPath();
    if (path.startsWith(contextPath)) {
        if ("/".equals(contextPath)) {
            return path;
        }
        return path.substring(contextPath.length());
    } else {
        return HttpUriMapper.getResourceBase(url.getPath());
    }
}