本文整理汇总了Java中org.simpleframework.http.core.Container类的典型用法代码示例。如果您正苦于以下问题:Java Container类的具体用法?Java Container怎么用?Java Container使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Container类属于org.simpleframework.http.core包,在下文中一共展示了Container类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: startHttpServer
import org.simpleframework.http.core.Container; //导入依赖的package包/类
public synchronized static void startHttpServer(int port) {
if (!started) {
try {
Container container = new CommandListener();
@SuppressWarnings("resource") Connection connection = new SocketConnection(container);
SocketAddress address = new InetSocketAddress(port);
System.out.println("Starting httpserver on port " + port);
LOG.info("Starting httpserver on port " + port);
connection.connect(address);
started = true;
} catch (IOException e) {
LOG.error(LogUtil.getLogMessage("Error starting httpServer: " + e), e);
throw new RuntimeException(e);
}
}
}
示例2: startHttpServer
import org.simpleframework.http.core.Container; //导入依赖的package包/类
public synchronized static void startHttpServer(int port, StandaloneAgentStartup standaloneAgentStartup) {
if (!started) {
agentStarter = standaloneAgentStartup;
try {
Container container = new CommandListener();
@SuppressWarnings("resource") Connection connection = new SocketConnection(container);
SocketAddress address = new InetSocketAddress(port);
System.out.println("Starting httpserver on port " + port);
connection.connect(address);
started = true;
} catch (IOException e) {
LOG.error("Error starting httpServer: " + e, e);
throw new RuntimeException(e);
}
}
}
示例3: testServingIndexHtml
import org.simpleframework.http.core.Container; //导入依赖的package包/类
@Test
public void testServingIndexHtml() throws IOException {
WebRequestContainer container =
new WebRequestContainer(123, mMockServerCreator, mImageServer, mMockResourceLoader);
when(mMockResourceLoader.load(anyString())).thenReturn(new byte[]{1, 2, 23, 42});
container.start();
ArgumentCaptor<Container> containerCaptor = ArgumentCaptor.forClass(Container.class);
verify(mMockServer).startServing(containerCaptor.capture());
OutputStream mockOutputStream = mock(OutputStream.class);
Response mockResponse = mock(Response.class);
when(mockResponse.getOutputStream()).thenReturn(mockOutputStream);
// Simulate request to unavailable address.
containerCaptor.getValue().handle(createMockRequestForUrl("/"), mockResponse);
verify(mockResponse).setStatus(Status.OK);
verify(mockResponse).setContentType("text/html");
verify(mockResponse).close();
verify(mockOutputStream).write(eq(new byte[]{1, 2, 23, 42}));
verify(mockOutputStream).close();
}
示例4: testServingImageFileNotSet
import org.simpleframework.http.core.Container; //导入依赖的package包/类
@Test
public void testServingImageFileNotSet() throws IOException {
WebRequestContainer container =
new WebRequestContainer(123, mMockServerCreator, mImageServer, mMockResourceLoader);
when(mMockResourceLoader.load(anyString())).thenReturn(new byte[]{1, 2, 23, 42});
container.start();
ArgumentCaptor<Container> containerCaptor = ArgumentCaptor.forClass(Container.class);
verify(mMockServer).startServing(containerCaptor.capture());
OutputStream mockOutputStream = mock(OutputStream.class);
Response mockResponse = mock(Response.class);
when(mockResponse.getOutputStream()).thenReturn(mockOutputStream);
// Simulate request to image URL..
containerCaptor.getValue().handle(createMockRequestForUrl("/now.jpg"), mockResponse);
verify(mockResponse).setStatus(Status.OK);
verify(mockResponse).setContentType("image/jpeg");
verify(mockResponse).close();
// We never set the image
verify(mockOutputStream).write(eq(new byte[0]));
verify(mockOutputStream).close();
}
示例5: testServingImageFileSet
import org.simpleframework.http.core.Container; //导入依赖的package包/类
@Test
public void testServingImageFileSet() throws IOException {
WebRequestContainer container =
new WebRequestContainer(123, mMockServerCreator, mImageServer, mMockResourceLoader);
when(mMockResourceLoader.load(anyString())).thenReturn(new byte[]{1, 2, 23, 42});
container.start();
mImageServer.updateCurrentFile(() -> Optional.of(new byte[]{1, 2, 3, 5, 8, 13, 21}));
ArgumentCaptor<Container> containerCaptor = ArgumentCaptor.forClass(Container.class);
verify(mMockServer).startServing(containerCaptor.capture());
OutputStream mockOutputStream = mock(OutputStream.class);
Response mockResponse = mock(Response.class);
when(mockResponse.getOutputStream()).thenReturn(mockOutputStream);
// Simulate request to image URL..
containerCaptor.getValue().handle(createMockRequestForUrl("/now.jpg"), mockResponse);
verify(mockResponse).setStatus(Status.OK);
verify(mockResponse).setContentType("image/jpeg");
verify(mockResponse).close();
// We never set the image
verify(mockOutputStream).write(eq(new byte[]{1, 2, 3, 5, 8, 13, 21}));
verify(mockOutputStream).close();
}
示例6: testServingThrowsException
import org.simpleframework.http.core.Container; //导入依赖的package包/类
@Test
public void testServingThrowsException() throws IOException {
WebRequestContainer container =
new WebRequestContainer(123, mMockServerCreator, mImageServer, mMockResourceLoader);
when(mMockResourceLoader.load(anyString())).thenReturn(new byte[]{1, 2, 23, 42});
container.start();
ArgumentCaptor<Container> containerCaptor = ArgumentCaptor.forClass(Container.class);
verify(mMockServer).startServing(containerCaptor.capture());
OutputStream mockOutputStream = mock(OutputStream.class);
Response mockResponse = mock(Response.class);
doThrow(new IOException()).when(mockOutputStream).write(any());
when(mockResponse.getOutputStream()).thenReturn(mockOutputStream);
containerCaptor.getValue().handle(createMockRequestForUrl("/"), mockResponse);
// Even though it throws, response should be closed.
verify(mockResponse).close();
}
示例7: testResponseCloseThrows
import org.simpleframework.http.core.Container; //导入依赖的package包/类
@Test
public void testResponseCloseThrows() throws IOException {
WebRequestContainer container =
new WebRequestContainer(123, mMockServerCreator, mImageServer, mMockResourceLoader);
when(mMockResourceLoader.load(anyString())).thenReturn(new byte[]{1, 2, 23, 42});
container.start();
ArgumentCaptor<Container> containerCaptor = ArgumentCaptor.forClass(Container.class);
verify(mMockServer).startServing(containerCaptor.capture());
OutputStream mockOutputStream = mock(OutputStream.class);
Response mockResponse = mock(Response.class);
doThrow(new IOException()).when(mockResponse).close();
when(mockResponse.getOutputStream()).thenReturn(mockOutputStream);
containerCaptor.getValue().handle(createMockRequestForUrl("/"), mockResponse);
// Nothing horrible should happen if response.close throws.
}
示例8: main
import org.simpleframework.http.core.Container; //导入依赖的package包/类
public static void main(String args[]) throws Exception {
// use port if given
try {
port = Integer.parseInt(args[0]);
} catch(Exception e) {
// silently keep port at 8080
}
// initialize the Stanford Core NLP
pipeline = new StanfordCoreNLP();
// start the server
Container container = new StanfordCoreNLPXMLServer();
Server server = new ContainerServer(container);
Connection connection = new SocketConnection(server);
SocketAddress address = new InetSocketAddress(port);
connection.connect(address);
log.info("Initialized server at port " + port + ".");
}
示例9: main
import org.simpleframework.http.core.Container; //导入依赖的package包/类
public static void main(String[] list) throws Exception {
Container container = new BlobStationServer();
Server server = new ContainerServer(container);
Connection connection = new SocketConnection(server);
SocketAddress address = new InetSocketAddress(8080);
connection.connect(address);
}
示例10: startServing
import org.simpleframework.http.core.Container; //导入依赖的package包/类
public void startServing(Container container) {
try {
ContainerSocketProcessor processor =
new ContainerSocketProcessor(container, mNumThreads);
Connection connection = new SocketConnection(processor);
SocketAddress address = new InetSocketAddress(mPort);
connection.connect(address);
LOG.info("Listening to: " + address.toString());
} catch (IOException e) {
LOG.error("Cannot start webserver: " + e.getMessage());
}
}
示例11: testServingUnmappedUrl
import org.simpleframework.http.core.Container; //导入依赖的package包/类
@Test
public void testServingUnmappedUrl() throws IOException {
WebRequestContainer container =
new WebRequestContainer(123, mMockServerCreator, mImageServer, mMockResourceLoader);
when(mMockResourceLoader.load(anyString())).thenReturn(new byte[]{1, 2, 23, 42});
container.start();
ArgumentCaptor<Container> containerCaptor = ArgumentCaptor.forClass(Container.class);
verify(mMockServer).startServing(containerCaptor.capture());
Response mockResponse = mock(Response.class);
// Simulate request to unavailable address.
containerCaptor.getValue().handle(createMockRequestForUrl("doesNotExist"), mockResponse);
verify(mockResponse).setStatus(Status.NOT_FOUND);
}
示例12: main
import org.simpleframework.http.core.Container; //导入依赖的package包/类
public static void main(String[] list) throws Exception
{
try {
Container container = new WebApp();
Server server = new ContainerServer(container);
Connection connection = new SocketConnection(server);
SocketAddress address = new InetSocketAddress(port);
connection.connect(address);
} catch(InternalException e)
{
System.err.println(e.what);
}
}
示例13: AbstractServerMockUsingTest
import org.simpleframework.http.core.Container; //导入依赖的package包/类
public AbstractServerMockUsingTest(Container container) {
this.container = container;
}
示例14: start
import org.simpleframework.http.core.Container; //导入依赖的package包/类
/**
* Start the tracker thread.
*/
public void start() throws IOException {
LOG.info("Starting BitTorrent tracker on {}...", getAnnounceUrls());
synchronized (lock) {
if (this.metrics == null) {
Object trackerId = Iterables.getFirst(getListenAddresses(), System.identityHashCode(this));
this.metrics = new TrackerMetrics(getMetricsRegistry(), trackerId);
metrics.addGauge("torrentCount", new Gauge<Integer>() {
@Override
public Integer value() {
return torrents.size();
}
});
}
for (Map.Entry<InetSocketAddress, Listener> e : listeners.entrySet()) {
Listener listener = e.getValue();
if (listener.connection == null) {
// Creates a thread via: SocketConnection
// -> ListenerManager -> Listener
// -> DirectReactor -> ActionDistributor -> Daemon
Container container = new TrackerService(version, torrents, metrics);
Server server = new ContainerServer(container);
listener.connection = new SocketConnection(server);
listener.connectionAddress = listener.connection.connect(e.getKey());
}
}
if (this.scheduler == null || this.scheduler.isShutdown()) {
// TODO: Set a thread timeout, nothing is time critical.
this.scheduler = new ScheduledThreadPoolExecutor(1);
this.scheduler.scheduleWithFixedDelay(new PeerCollector(),
PEER_COLLECTION_FREQUENCY_SECONDS,
PEER_COLLECTION_FREQUENCY_SECONDS,
TimeUnit.SECONDS);
}
}
LOG.info("Started BitTorrent tracker on {}...", getAnnounceUrls());
}
示例15: main
import org.simpleframework.http.core.Container; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
// Starting the server
Container container = new DistantAPISimulator();
Server server = new ContainerServer(container);
Connection connection = new SocketConnection(server);
SocketAddress address = new InetSocketAddress(1337);
connection.connect(address);
try {
// Creating the pixie instance
APIPixie pixie = new APIPixie("http://localhost:1337");
// Create a user
APIService<User, Long> userService = pixie.getService(User.class);
User user = new User();
user.setName("Vincent DURMONT");
user.setEmail("[email protected]");
user = userService.post(user);
System.out.println("Created user: " + user);
// Create a project
APIService<Project, Long> projectService = pixie.getService(Project.class);
Project project = new Project();
project.setOwner(user);
project.setTitle("My awesome project");
// Create some tags
List<String> tags = new LinkedList<>();
tags.add("test");
tags.add("java");
project.setTags(tags);
// Create some issues
List<Issue> issues = new LinkedList<>();
Issue issue1 = new Issue();
issue1.setAuthor(user);
issue1.setText("the first issue!");
issues.add(issue1);
Issue issue2 = new Issue();
issue2.setAuthor(user);
issue2.setText("the second issue!");
issues.add(issue2);
project.setIssues(issues);
project = projectService.post(project);
System.out.println("Created project: " + project);
System.out.println("List of users: " + userService.getAll());
System.out.println("List of projects: " + projectService.getAll());
APIService<Issue, Long> issueService = pixie.getService(Issue.class);
System.out.println("List of issues: " + issueService.getAll());
} catch (Exception e) {
e.printStackTrace();
}
// Stopping the server
server.stop();
connection.close();
}