org.eclipse.jetty.server.NetworkConnector#getHost ( )源码实例Demo

下面列出了org.eclipse.jetty.server.NetworkConnector#getHost ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: syndesis   文件: ODataTestServer.java
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;
    }
}
 
源代码2 项目: attic-polygene-java   文件: AbstractJettyMixin.java
@Override
@SuppressWarnings( "ValueOfIncrementOrDecrementUsed" )
public final Interface[] interfacesServed()
{
    Connector[] connectors = server.getConnectors();
    Interface[] result = new Interface[ connectors.length ];
    int index = 0;
    for( Connector connector : connectors )
    {
        if( connector instanceof NetworkConnector )
        {
            NetworkConnector netConnector = (NetworkConnector) connector;
            String host = configuration().hostName().get();
            if( host == null )
            {
                host = netConnector.getHost();
                if( host == null ) // If serving all interfaces.
                {
                    try
                    {
                        host = InetAddress.getLocalHost().getHostAddress();
                    }
                    catch( UnknownHostException e )
                    {
                        throw new InternalError( "UnknownHost for local interface.", e );
                    }
                }
            }
            result[ index++] = new InterfaceImpl( host, netConnector.getPort(), servedProtocol() );
        }
    }
    return result;
}
 
源代码3 项目: knox   文件: GatewayServer.java
public InetSocketAddress[] getAddresses() {
  InetSocketAddress[] addresses = new InetSocketAddress[ jetty.getConnectors().length ];
  for( int i=0, n=addresses.length; i<n; i++ ) {
    NetworkConnector connector = (NetworkConnector)jetty.getConnectors()[ i ];
    String host = connector.getHost();
    if( host == null ) {
      addresses[ i ] = new InetSocketAddress( connector.getLocalPort() );
    } else {
      addresses[ i ] = new InetSocketAddress( host, connector.getLocalPort() );
    }
  }
  return addresses;
}