本文整理汇总了Java中com.sun.grizzly.http.embed.GrizzlyWebServer类的典型用法代码示例。如果您正苦于以下问题:Java GrizzlyWebServer类的具体用法?Java GrizzlyWebServer怎么用?Java GrizzlyWebServer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
GrizzlyWebServer类属于com.sun.grizzly.http.embed包,在下文中一共展示了GrizzlyWebServer类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: instantiateGrizzlyWebServer
import com.sun.grizzly.http.embed.GrizzlyWebServer; //导入依赖的package包/类
/**
* Instantiates the Grizzly Web Server
*/
private void instantiateGrizzlyWebServer() {
webServer = new GrizzlyWebServer(PORT);
final ServletAdapter sa = new ServletAdapter();
Servlet servletInstance = null;
try {
servletInstance = (HttpServlet) Class.forName("com.sun.jersey.spi.container.servlet.ServletContainer").newInstance();
} catch (final Exception ex) {
log.error("Cannot instantiate the Grizzly Servlet Container", ex);
}
sa.setServletInstance(servletInstance);
sa.addFilter(new RestApiLoginFilter(), "jerseyfilter", null);
sa.addInitParameter("javax.ws.rs.Application", OlatRestApplication.class.getName());
sa.setContextPath("/" + CONTEXT_PATH);
webServer.addGrizzlyAdapter(sa, null);
}
示例2: start
import com.sun.grizzly.http.embed.GrizzlyWebServer; //导入依赖的package包/类
@Override
public MkContainer start(final int prt) throws IOException {
if (this.port != 0) {
throw new IllegalStateException(
String.format(
"already listening on port %d, use #stop() first",
this.port
)
);
}
this.port = prt;
this.gws = new GrizzlyWebServer(this.port);
this.gws.addGrizzlyAdapter(this.adapter, new String[] {"/"});
this.gws.start();
Logger.info(this, "started on port #%s", prt);
return this;
}
示例3: start
import com.sun.grizzly.http.embed.GrizzlyWebServer; //导入依赖的package包/类
public void start() throws IOException {
System.out.println("Starting grizzly ...");
boolean useSSL = cfg.useSSL();
gws = new GrizzlyWebServer(cfg.getPort(), "/tmp/23cxv45345/2131xc2/", useSSL);
// BUG: Grizzly needs a doc root if you are going to register multiple adapters
for (Endpoint e : cfg.getEndpoints()) {
ZooKeeperService.mapContext(e.getContext(), e);
gws.addGrizzlyAdapter(createJerseyAdapter(e), new String[] { e
.getContext() });
}
if (useSSL) {
System.out.println("Starting SSL ...");
String jks = cfg.getJKS("keys/rest.jks");
String jksPassword = cfg.getJKSPassword();
SSLConfig sslConfig = new SSLConfig();
URL resource = getClass().getClassLoader().getResource(jks);
if (resource == null) {
LOG.error("Unable to find the keystore file: " + jks);
System.exit(2);
}
try {
sslConfig.setKeyStoreFile(new File(resource.toURI())
.getAbsolutePath());
} catch (URISyntaxException e1) {
LOG.error("Unable to load keystore: " + jks, e1);
System.exit(2);
}
sslConfig.setKeyStorePass(jksPassword);
gws.setSSLConfig(sslConfig);
}
gws.start();
}
示例4: main
import com.sun.grizzly.http.embed.GrizzlyWebServer; //导入依赖的package包/类
static public void main(String[] args) throws Exception {
GrizzlyWebServer ws = new GrizzlyWebServer(9080);
try {
GrizzlyAdapter ga = new HttpServerMain();
ws.addGrizzlyAdapter(ga, new String[] {"/"});
ws.start();
} catch (IOException e){
logger.error("", e);
}
}
示例5: setup
import com.sun.grizzly.http.embed.GrizzlyWebServer; //导入依赖的package包/类
@Before
public void setup() {
sslConfig = mock(SSLConfig.class);
adapter = mock(Adapter.class);
springComponentProviderFactory = mock(SpringComponentProviderFactory.class);
ResourceConfig resourceConfig = mock(ResourceConfig.class);
selectorThread = mock(SelectorThread.class);
webServer = mock(GrizzlyWebServer.class);
when(webServer.getSelectorThread()).thenReturn(selectorThread);
PowerMockito.mockStatic(ContainerFactory.class);
when(ContainerFactory.createContainer(eq(Adapter.class), eq(resourceConfig), isA(SpringComponentProviderFactory.class))).thenReturn(adapter);
pisssHttpsServer = new PisssHttpsServer() {
@Override
protected GrizzlyWebServer newGrizzlyWebServer(String path) {
assertThat(path, equalTo("https://localhost:8883/"));
return webServer;
}
@Override
protected SSLConfig newSSLConfig() {
return sslConfig;
}
@Override
protected SpringComponentProviderFactory newSpringComponentProviderFactory() {
return springComponentProviderFactory;
}
};
pisssHttpsServer.setKeyStoreLocation(keystoreLocation);
pisssHttpsServer.setPassword(keystorePassword);
pisssHttpsServer.setResourceConfig(resourceConfig);
}
示例6: start
import com.sun.grizzly.http.embed.GrizzlyWebServer; //导入依赖的package包/类
/**
* Start HTTP server.
* @see #RestfulServer()
* @todo #1 Would be nice to add exception mapping here, in order
* to properly wrap exception messages sent to clients
*/
private void start() {
final java.util.logging.Logger root =
LogManager.getLogManager().getLogger("");
final Handler[] handlers = root.getHandlers();
for (int pos = 0; pos < handlers.length; pos += 1) {
root.removeHandler(handlers[pos]);
}
SLF4JBridgeHandler.install();
final GrizzlyWebServer gws = new GrizzlyWebServer(this.port(), ".");
final ServletAdapter adapter = new ServletAdapter();
adapter.addInitParameter(
"com.sun.jersey.config.property.packages",
"com.ymock.server"
);
adapter.setContextPath(RestfulServer.CONTEXT);
adapter.setServletInstance(new ServletContainer());
gws.addGrizzlyAdapter(adapter, new String[] {RestfulServer.CONTEXT});
try {
gws.start();
} catch (java.io.IOException ex) {
throw new IllegalStateException(ex);
}
Logger.debug(
this,
"#start(): server started"
);
}
示例7: main
import com.sun.grizzly.http.embed.GrizzlyWebServer; //导入依赖的package包/类
public static void main(String[] args) {
// static content is linked from here
GrizzlyWebServer server = new GrizzlyWebServer(8010);
//For very slow response extractors:
SelectorThread st = server.getSelectorThread();
st.setTransactionTimeout(700000);
//create UI resources
ServletAdapter ui = new ServletAdapter();
ui.addInitParameter(
"javax.ws.rs.Application",
"fr.eurecom.hotspots.web.hypertext.RegisterUI");
ui.setServletInstance(new ServletContainer());
// REST resources
ServletAdapter api = new ServletAdapter();
api.addInitParameter(
"javax.ws.rs.Application",
"fr.eurecom.hotspots.web.api.RegisterAPI");
api.setContextPath("/api");
api.setServletInstance(new ServletContainer());
// static content adapter
ServletAdapter staticContent = new ServletAdapter("ui");
staticContent.setContextPath("/");
staticContent.setHandleStaticResources(true);
// register all above defined adapters
server.addGrizzlyAdapter(api, new String[] {"/api"});
server.addGrizzlyAdapter(staticContent, new String[] {"/"});
// let's Grizzly run
try {
server.start();
} catch (IOException e) {
e.printStackTrace();
}
}
示例8: newGrizzlyWebServer
import com.sun.grizzly.http.embed.GrizzlyWebServer; //导入依赖的package包/类
protected GrizzlyWebServer newGrizzlyWebServer(String path) {
return new GrizzlyWebServer(port, path, true);
}