org.eclipse.jetty.http.HttpScheme Java Examples

The following examples show how to use org.eclipse.jetty.http.HttpScheme. 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: ConnectorManager.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Verifies all the needed bits are present in Jetty XML configuration (as HTTPS must be enabled by users).
 */
private void verifyConfiguration(final HttpScheme httpScheme) {
  try {
    if (HttpScheme.HTTP == httpScheme) {
      bean(HTTP_CONFIG_ID, HttpConfiguration.class);
      bean(HTTP_CONNECTOR_ID, ServerConnector.class);
    }
    else if (HttpScheme.HTTPS == httpScheme) {
      bean(SSL_CONTEXT_FACTORY_ID, SslContextFactory.class);
      bean(HTTPS_CONFIG_ID, HttpConfiguration.class);
      bean(HTTPS_CONNECTOR_ID, ServerConnector.class);
    }
    else {
      throw new UnsupportedHttpSchemeException(httpScheme);
    }
  }
  catch (IllegalStateException e) {
    throw new IllegalStateException("Jetty HTTPS is not enabled in Nexus", e);
  }
}
 
Example #2
Source File: ConnectorRegistrarImpl.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
private void validate(final ConnectorConfiguration connectorConfiguration) {
  // connector is not already added
  checkArgument(!managedConfigurations.containsKey(connectorConfiguration));

  // schema is not null and is available
  final HttpScheme httpScheme = connectorConfiguration.getScheme();
  checkNotNull(httpScheme);
  if (!availableSchemes().contains(httpScheme)) {
    throw new UnsupportedHttpSchemeException(httpScheme);
  }

  // port is ok and free
  final int port = connectorConfiguration.getPort();
  checkArgument(port > 0);
  checkArgument(port < 65536);
  checkArgument(!unavailablePorts().contains(port));
}
 
Example #3
Source File: ConnectorManager.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Returns the OOTB defined configuration for given HTTP scheme.
 */
private HttpConfiguration defaultHttpConfiguration(final HttpScheme httpScheme) {
  if (HttpScheme.HTTP == httpScheme) {
    return bean(HTTP_CONFIG_ID, HttpConfiguration.class);
  }
  else if (HttpScheme.HTTPS == httpScheme) {
    return bean(HTTPS_CONFIG_ID, HttpConfiguration.class);
  }
  else {
    throw new UnsupportedHttpSchemeException(httpScheme);
  }
}
 
Example #4
Source File: ConnectorManager.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Returns the OOTB defined connector for given HTTP scheme.
 */
private ServerConnector defaultConnector(final HttpScheme httpScheme) {
  if (HttpScheme.HTTP == httpScheme) {
    return bean(HTTP_CONNECTOR_ID, ServerConnector.class);
  }
  else if (HttpScheme.HTTPS == httpScheme) {
    return bean(HTTPS_CONNECTOR_ID, ServerConnector.class);
  }
  else {
    throw new UnsupportedHttpSchemeException(httpScheme);
  }
}
 
Example #5
Source File: ConnectorRegistrarImpl.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public List<HttpScheme> availableSchemes() {
  final List<HttpScheme> result = new ArrayList<>();
  for (ConnectorConfiguration defaultConnector : serverConfiguration.defaultConnectors()) {
    result.add(defaultConnector.getScheme());
  }
  return result;
}
 
Example #6
Source File: VmRuntimeWebAppContext.java    From appengine-java-vm-runtime with Apache License 2.0 5 votes vote down vote up
/**
 * Checks if the request was made over HTTPS. If so it modifies the request so that
 * {@code HttpServletRequest#isSecure()} returns true, {@code HttpServletRequest#getScheme()}
 * returns "https", and {@code HttpServletRequest#getServerPort()} returns 443. Otherwise it sets
 * the scheme to "http" and port to 80.
 *
 * @param request The request to modify.
 */
private void setSchemeAndPort(Request request) {
  String https = request.getHeader(VmApiProxyEnvironment.HTTPS_HEADER);
  String proto = request.getHeader(VmApiProxyEnvironment.X_FORWARDED_PROTO_HEADER);
  if ("on".equals(https) || "https".equals(proto)) {
    request.setSecure(true);
    request.setScheme(HttpScheme.HTTPS.toString());
    request.setAuthority(request.getServerName(), 443);
  } else {
    request.setSecure(false);
    request.setScheme(HttpScheme.HTTP.toString());
    request.setAuthority(request.getServerName(), defaultEnvironment.getServerPort());
  }
}
 
Example #7
Source File: UnsupportedHttpSchemeException.java    From nexus-public with Eclipse Public License 1.0 4 votes vote down vote up
public UnsupportedHttpSchemeException(final HttpScheme httpScheme) {
  super("Unsupported HTTP Scheme: " + httpScheme);
  this.httpScheme = httpScheme;
}
 
Example #8
Source File: UnsupportedHttpSchemeException.java    From nexus-public with Eclipse Public License 1.0 4 votes vote down vote up
public HttpScheme getHttpScheme() {
  return httpScheme;
}
 
Example #9
Source File: ConnectorRegistrar.java    From nexus-public with Eclipse Public License 1.0 2 votes vote down vote up
/**
 * Returns the list of available HTTP schemes. This list depends on current Jetty XML configuration (is HTTPS
 * enabled). If schema is not available, method {@link #addConnector(ConnectorConfiguration)} will reject to add it.
 */
List<HttpScheme> availableSchemes();
 
Example #10
Source File: ConnectorConfiguration.java    From nexus-public with Eclipse Public License 1.0 2 votes vote down vote up
/**
 * The required connector scheme.
 */
HttpScheme getScheme();