本文整理汇总了Java中org.eclipse.jetty.server.NetworkConnector类的典型用法代码示例。如果您正苦于以下问题:Java NetworkConnector类的具体用法?Java NetworkConnector怎么用?Java NetworkConnector使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
NetworkConnector类属于org.eclipse.jetty.server包,在下文中一共展示了NetworkConnector类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: bindServer
import org.eclipse.jetty.server.NetworkConnector; //导入依赖的package包/类
/**
* Bind method for the Jetty server. The test port is filled here.
*
* @param server
* The Jetty server.
*/
public void bindServer(final Server server) {
Connector[] connectors = server.getConnectors();
for (int i = 0, n = connectors.length; (i < n) && (testPort == 0); i++) {
if (connectors[i] instanceof NetworkConnector) {
NetworkConnector networkConnector = (NetworkConnector) connectors[i];
List<String> protocols = networkConnector.getProtocols();
boolean httpAvailable = false;
Iterator<String> protocolIterator = protocols.iterator();
while (!httpAvailable && protocolIterator.hasNext()) {
String protocol = protocolIterator.next();
if (protocol.toLowerCase().startsWith("http")) {
httpAvailable = true;
}
}
if (httpAvailable) {
int localPort = networkConnector.getLocalPort();
if (localPort > 0) {
testPort = localPort;
}
}
}
}
}
示例2: start
import org.eclipse.jetty.server.NetworkConnector; //导入依赖的package包/类
@PostConstruct
@RetryFor(attempts = 5, value = Exception.class)
public void start() {
server = new Server(0);
server.setHandler(new ZonemasterHandler());
try {
server.start();
} catch (Exception e) {
throw new RuntimeException(e);
}
this.port = ((NetworkConnector)server.getConnectors()[0]).getLocalPort();
final String baseUrl = String.format("http://localhost:%s/zonemaster", getPort());
LOGGER.info("Zonemaster dummy server restUrl: {}", baseUrl);
ReflectionTestUtils.setField(zonemasterClient, "baseUrl", baseUrl);
}
示例3: start
import org.eclipse.jetty.server.NetworkConnector; //导入依赖的package包/类
@PostConstruct
@RetryFor(attempts = 5, value = Exception.class)
public void start() {
server = new Server(0);
server.setHandler(new CrowdTestHandler());
try {
server.start();
} catch (Exception e) {
throw new RuntimeException(e);
}
this.port = ((NetworkConnector)server.getConnectors()[0]).getLocalPort();
final String restUrl = String.format("http://localhost:%s/crowd", getPort());
LOGGER.info("Crowd dummy server restUrl: {}", restUrl);
ReflectionTestUtils.setField(crowdClient, "restUrl", restUrl);
}
示例4: startServer
import org.eclipse.jetty.server.NetworkConnector; //导入依赖的package包/类
@BeforeClass
public static void startServer() throws Exception {
// Let server pick its own random, available port.
server = new Server(0);
ServletContextHandler handler = new ServletContextHandler();
handler.setContextPath("/");
Class<?> config = CommonsMultipartResolverTestConfig.class;
ServletHolder commonsResolverServlet = new ServletHolder(DispatcherServlet.class);
commonsResolverServlet.setInitParameter("contextConfigLocation", config.getName());
commonsResolverServlet.setInitParameter("contextClass", AnnotationConfigWebApplicationContext.class.getName());
handler.addServlet(commonsResolverServlet, "/commons-resolver/*");
config = StandardMultipartResolverTestConfig.class;
ServletHolder standardResolverServlet = new ServletHolder(DispatcherServlet.class);
standardResolverServlet.setInitParameter("contextConfigLocation", config.getName());
standardResolverServlet.setInitParameter("contextClass", AnnotationConfigWebApplicationContext.class.getName());
standardResolverServlet.getRegistration().setMultipartConfig(new MultipartConfigElement(""));
handler.addServlet(standardResolverServlet, "/standard-resolver/*");
server.setHandler(handler);
server.start();
Connector[] connectors = server.getConnectors();
NetworkConnector connector = (NetworkConnector) connectors[0];
baseUrl = "http://localhost:" + connector.getLocalPort();
}
示例5: start
import org.eclipse.jetty.server.NetworkConnector; //导入依赖的package包/类
@Override
public void start() throws Exception {
this.jettyServer.start();
Connector[] connectors = jettyServer.getConnectors();
NetworkConnector connector = (NetworkConnector) connectors[0];
this.port = connector.getLocalPort();
}
示例6: startJettyServer
import org.eclipse.jetty.server.NetworkConnector; //导入依赖的package包/类
@BeforeClass
public static void startJettyServer() throws Exception {
// Let server pick its own random, available port.
jettyServer = new Server(0);
ServletContextHandler handler = new ServletContextHandler();
byte[] bytes = helloWorld.getBytes("utf-8");
handler.addServlet(new ServletHolder(new GetServlet(bytes, textContentType)), "/get");
handler.addServlet(new ServletHolder(new GetServlet(new byte[0], textContentType)), "/get/nothing");
handler.addServlet(new ServletHolder(new GetServlet(bytes, null)), "/get/nocontenttype");
handler.addServlet(
new ServletHolder(new PostServlet(helloWorld, "/post/1", bytes, textContentType)),
"/post");
handler.addServlet(
new ServletHolder(new JsonPostServlet("/jsonpost/1", jsonContentType)),
"/jsonpost");
handler.addServlet(new ServletHolder(new StatusCodeServlet(204)), "/status/nocontent");
handler.addServlet(new ServletHolder(new StatusCodeServlet(304)), "/status/notmodified");
handler.addServlet(new ServletHolder(new ErrorServlet(404)), "/status/notfound");
handler.addServlet(new ServletHolder(new ErrorServlet(500)), "/status/server");
handler.addServlet(new ServletHolder(new UriServlet()), "/uri/*");
handler.addServlet(new ServletHolder(new MultipartServlet()), "/multipart");
handler.addServlet(new ServletHolder(new FormServlet()), "/form");
handler.addServlet(new ServletHolder(new DeleteServlet()), "/delete");
handler.addServlet(
new ServletHolder(new PutServlet(helloWorld, bytes, textContentType)),
"/put");
jettyServer.setHandler(handler);
jettyServer.start();
Connector[] connectors = jettyServer.getConnectors();
NetworkConnector connector = (NetworkConnector) connectors[0];
port = connector.getLocalPort();
baseUrl = "http://localhost:" + port;
}
示例7: startJettyServer
import org.eclipse.jetty.server.NetworkConnector; //导入依赖的package包/类
@BeforeClass
public static void startJettyServer() throws Exception {
// Let server pick its own random, available port.
jettyServer = new Server(0);
ServletContextHandler handler = new ServletContextHandler();
handler.setContextPath("/");
handler.addServlet(new ServletHolder(new EchoServlet()), "/echo");
handler.addServlet(new ServletHolder(new ParameterServlet()), "/params");
handler.addServlet(new ServletHolder(new StatusServlet(200)), "/status/ok");
handler.addServlet(new ServletHolder(new StatusServlet(404)), "/status/notfound");
handler.addServlet(new ServletHolder(new MethodServlet("DELETE")), "/methods/delete");
handler.addServlet(new ServletHolder(new MethodServlet("GET")), "/methods/get");
handler.addServlet(new ServletHolder(new MethodServlet("HEAD")), "/methods/head");
handler.addServlet(new ServletHolder(new MethodServlet("OPTIONS")), "/methods/options");
handler.addServlet(new ServletHolder(new PostServlet()), "/methods/post");
handler.addServlet(new ServletHolder(new MethodServlet("PUT")), "/methods/put");
handler.addServlet(new ServletHolder(new MethodServlet("PATCH")), "/methods/patch");
jettyServer.setHandler(handler);
jettyServer.start();
Connector[] connectors = jettyServer.getConnectors();
NetworkConnector connector = (NetworkConnector) connectors[0];
baseUrl = "http://localhost:" + connector.getLocalPort();
}
示例8: interfacesServed
import org.eclipse.jetty.server.NetworkConnector; //导入依赖的package包/类
@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;
}
示例9: createServer
import org.eclipse.jetty.server.NetworkConnector; //导入依赖的package包/类
public Server createServer(Set<MappedServlet> servlets, Set<MappedFilter> filters, Set<MappedListener> listeners) {
ThreadPool threadPool = createThreadPool();
Server server = new Server(threadPool);
server.setStopAtShutdown(true);
server.setStopTimeout(1000L);
server.setHandler(createHandler(servlets, filters, listeners));
if (maxFormContentSize > 0) {
server.setAttribute("org.eclipse.jetty.server.Request.maxFormContentSize", maxFormContentSize);
}
if (maxFormKeys > 0) {
server.setAttribute("org.eclipse.jetty.server.Request.maxFormKeys", maxFormKeys);
}
createRequestLog(server);
Collection<ConnectorFactory> connectorFactories = connectorFactories(server);
Collection<ConnectorDescriptor> connectorDescriptors = new ArrayList<>(2);
if (connectorFactories.isEmpty()) {
LOGGER.warn("Jetty starts with no connectors configured. Is that expected?");
} else {
connectorFactories.forEach(cf -> {
NetworkConnector connector = cf.createConnector(server);
server.addConnector(connector);
connectorDescriptors.add(new ConnectorDescriptor(connector));
});
}
server.addLifeCycleListener(new ServerLifecycleLogger(connectorDescriptors, context));
return server;
}
示例10: start
import org.eclipse.jetty.server.NetworkConnector; //导入依赖的package包/类
/**
* Starts the server asynchronously. To stop the server, see {@link #stop()}.
*
* @throws Exception if the server could not be successfully started.
*/
public void start()
throws Exception {
metricsReporters.forEach((reporterName, metricsReporter) -> {
log.info("Registering the metrics reporter : {}, with source : {}.", reporterName, METRICS_SOURCE);
metricsReporter.register(METRICS_SOURCE, metricsRegistry);
log.info("Starting the metrics reporter : {}.", reporterName);
metricsReporter.start();
});
log.info("Starting server on port {}", ((NetworkConnector) server.getConnectors()[0]).getPort());
server.start();
log.info("Server is running");
}
示例11: testStartShouldStartTheMetricsReportersAndServer
import org.eclipse.jetty.server.NetworkConnector; //导入依赖的package包/类
@Test
public void testStartShouldStartTheMetricsReportersAndServer() throws Exception {
NetworkConnector connector = Mockito.mock(NetworkConnector.class);
int testServerPort = 100;
Mockito.doReturn(testServerPort).when(connector).getPort();
Mockito.when(server.getConnectors()).thenReturn(new NetworkConnector[]{connector});
Mockito.doNothing().when(server).start();
samzaRestService.start();
Mockito.verify(metricsReporter).start();
Mockito.verify(metricsReporter).register("SamzaRest", metricsRegistry);
Mockito.verify(server).start();
}
示例12: start
import org.eclipse.jetty.server.NetworkConnector; //导入依赖的package包/类
public void start() {
try {
server.start();
} catch (Exception e) {
Log.warn("Exception when trying to start server", e);
}
port = ((NetworkConnector) server.getConnectors()[0]).getLocalPort();
}
示例13: createAndStartServer
import org.eclipse.jetty.server.NetworkConnector; //导入依赖的package包/类
@RetryFor(attempts = 5, value = Exception.class)
private Server createAndStartServer(int port, HandlerList handlers) throws Exception {
final Server server = new Server(port);
server.setHandler(handlers);
server.setStopAtShutdown(true);
server.start();
this.port = ((NetworkConnector)server.getConnectors()[0]).getLocalPort();
LOGGER.info("Jetty started on port {}", this.port);
return server;
}
示例14: ConnectorDescriptor
import org.eclipse.jetty.server.NetworkConnector; //导入依赖的package包/类
public ConnectorDescriptor(NetworkConnector connector) {
this.connector = connector;
}
示例15: http1Port
import org.eclipse.jetty.server.NetworkConnector; //导入依赖的package包/类
private static int http1Port() {
return ((NetworkConnector) http1server.getConnectors()[0]).getLocalPort();
}