本文整理汇总了Java中org.eclipse.jetty.http.HttpScheme.HTTP属性的典型用法代码示例。如果您正苦于以下问题:Java HttpScheme.HTTP属性的具体用法?Java HttpScheme.HTTP怎么用?Java HttpScheme.HTTP使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.eclipse.jetty.http.HttpScheme
的用法示例。
在下文中一共展示了HttpScheme.HTTP属性的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: verifyConfiguration
/**
* 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);
}
}
示例2: defaultHttpConfiguration
/**
* 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);
}
}
示例3: defaultConnector
/**
* 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);
}
}
示例4: addConnector
/**
* Adds and starts connector to Jetty based on passed in configuration.
*/
public ServerConnector addConnector(final ConnectorConfiguration connectorConfiguration)
{
final HttpScheme httpScheme = connectorConfiguration.getScheme();
verifyConfiguration(httpScheme);
final HttpConfiguration httpConfiguration =
connectorConfiguration.customize(defaultHttpConfiguration(httpScheme));
final ServerConnector connectorPrototype =
defaultConnector(httpScheme);
final ServerConnector serverConnector;
if (HttpScheme.HTTP == httpScheme) {
serverConnector = new ServerConnector(
server,
connectorPrototype.getAcceptors(),
connectorPrototype.getSelectorManager().getSelectorCount(),
new InstrumentedConnectionFactory(
new HttpConnectionFactory(httpConfiguration)
)
);
}
else if (HttpScheme.HTTPS == httpScheme) {
final SslContextFactory sslContextFactory = bean(SSL_CONTEXT_FACTORY_ID, SslContextFactory.class);
serverConnector = new ServerConnector(
server,
connectorPrototype.getAcceptors(),
connectorPrototype.getSelectorManager().getSelectorCount(),
new InstrumentedConnectionFactory(
new SslConnectionFactory(sslContextFactory, "http/1.1")
),
new HttpConnectionFactory(httpConfiguration)
);
}
else {
throw new UnsupportedHttpSchemeException(httpScheme);
}
serverConnector.setHost(connectorPrototype.getHost());
serverConnector.setPort(connectorConfiguration.getPort());
serverConnector.setIdleTimeout(connectorPrototype.getIdleTimeout());
serverConnector.setSoLingerTime(connectorPrototype.getSoLingerTime());
serverConnector.setAcceptorPriorityDelta(connectorPrototype.getAcceptorPriorityDelta());
serverConnector.setAcceptQueueSize(connectorPrototype.getAcceptQueueSize());
managedConnectors.put(connectorConfiguration, serverConnector);
server.addConnector(serverConnector);
try {
serverConnector.start();
}
catch (Exception e) {
log.warn("Could not start connector: {}", connectorConfiguration, e);
throw new RuntimeException(e);
}
return serverConnector;
}
示例5: lowLevelApiTest
@Test
public void lowLevelApiTest() throws Exception {
// start the test server
class MyServlet extends HttpServlet {
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
resp.getWriter().write("<html> <header> ...");
}
};
WebServer server = WebServer.servlet(new MyServlet())
.start();
// create a low-level jetty HTTP/2 client
HTTP2Client lowLevelClient = new HTTP2Client();
lowLevelClient.start();
// create a new session which will open a (multiplexed) connection to the server
FuturePromise<Session> sessionFuture = new FuturePromise<>();
lowLevelClient.connect(new InetSocketAddress("localhost", server.getLocalport()), new Session.Listener.Adapter(), sessionFuture);
Session session = sessionFuture.get();
// create the header frame
MetaData.Request metaData = new MetaData.Request("GET", HttpScheme.HTTP, new HostPortHttpField("localhost:" + server.getLocalport()), "/", HttpVersion.HTTP_2, new HttpFields());
HeadersFrame frame = new HeadersFrame(1, metaData, null, true);
// ... and perform the http transaction
PrintingFramesHandler framesHandler = new PrintingFramesHandler();
session.newStream(frame, new Promise.Adapter<Stream>(), framesHandler);
// wait until response is received (PrintingFramesHandler will write the response frame to console)
framesHandler.getCompletedFuture().get();
// shut down the client and server
lowLevelClient.stop();
server.stop();
}
示例6: pushApiTest
@Test
public void pushApiTest() throws Exception {
// start the test server
class MyServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
Request jettyRequest = (Request) req;
if (jettyRequest.getRequestURI().equals("/myrichpage.html") && jettyRequest.isPushSupported()) {
jettyRequest.getPushBuilder()
.path("/pictures/logo.jpg")
.push();
}
if (jettyRequest.getRequestURI().equals("/myrichpage.html")) {
resp.getWriter().write("<html> <header> ...");
} else {
resp.getWriter().write("���� ?JFIF d d �� ?Ducky ? P �...");
}
}
};
WebServer server = WebServer.servlet(new MyServlet())
.start();
// create a low-level jetty HTTP/2 client
HTTP2Client lowLevelClient = new HTTP2Client();
lowLevelClient.start();
// create a new session which will open a (multiplexed) connection to the server
FuturePromise<Session> sessionFuture = new FuturePromise<>();
lowLevelClient.connect(new InetSocketAddress("localhost", server.getLocalport()), new Session.Listener.Adapter(), sessionFuture);
Session session = sessionFuture.get();
// create the header frame
MetaData.Request metaData = new MetaData.Request("GET", HttpScheme.HTTP, new HostPortHttpField("localhost:" + server.getLocalport()), "/myrichpage.html", HttpVersion.HTTP_2, new HttpFields());
HeadersFrame frame = new HeadersFrame(1, metaData, null, true);
// ... and perform the http transaction
PrintingFramesHandler framesHandler = new PrintingFramesHandler();
session.newStream(frame, new Promise.Adapter<Stream>(), framesHandler);
// wait until response is received (PrintingFramesHandler will write the response frame to console)
framesHandler.getCompletedFuture().get();
// shut down the client and server
lowLevelClient.stop();
server.stop();
}