本文整理汇总了Java中org.simpleframework.transport.connect.Connection类的典型用法代码示例。如果您正苦于以下问题:Java Connection类的具体用法?Java Connection怎么用?Java Connection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Connection类属于org.simpleframework.transport.connect包,在下文中一共展示了Connection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: startHttpServer
import org.simpleframework.transport.connect.Connection; //导入依赖的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.transport.connect.Connection; //导入依赖的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: createServer
import org.simpleframework.transport.connect.Connection; //导入依赖的package包/类
public static ServerCriteria createServer() throws Exception {
Container container = new Container() {
public void handle(Request request, Response response) {
try {
PrintStream out = response.getPrintStream();
response.setValue("Content-Type", "text/plain");
response.setValue("Connection", "close");
out.print("TEST " + new Date());
response.close();
}catch(Exception e) {
e.printStackTrace();
try {
response.close();
}catch(Exception ex) {
ex.printStackTrace();
}
}
}
};
ContainerServer server = new ContainerServer(container);
Connection connection = new SocketConnection(server);
InetSocketAddress address = (InetSocketAddress)connection.connect(null); // ephemeral port
return new ServerCriteria(connection, address);
}
示例4: createServer
import org.simpleframework.transport.connect.Connection; //导入依赖的package包/类
public static Connection createServer(boolean certificateRequired, int listenPort) throws Exception {
System.setProperty("sun.security.ssl.allowUnsafeRenegotiation", "true");
System.setProperty("sun.security.ssl.allowLegacyHelloMessages", "true");
File file = new File("C:\\work\\development\\async_http\\yieldbroker-proxy-trading\\etc\\uat.yieldbroker.com.pfx");
KeyStoreReader reader = new KeyStoreReader(KeyStoreType.PKCS12, file, "p", "p");
SecureSocketContext context = new SecureSocketContext(reader, SecureProtocol.TLS);
SSLContext sslContext = context.getContext();
Agent agent = new MockAgent();
TransportProcessor processor = new TransportProcessor();
ProcessorServer server = new ProcessorServer(processor);
ConfigurableCertificateServer certServer = new ConfigurableCertificateServer(server);
SocketConnection con = new SocketConnection(certServer, agent);
SocketAddress serverAddress = new InetSocketAddress(listenPort);
certServer.setCertRequired(certificateRequired);
con.connect(serverAddress, sslContext);
return con;
}
示例5: validateSignatureWhenThereIsNoContent
import org.simpleframework.transport.connect.Connection; //导入依赖的package包/类
@Test
public void validateSignatureWhenThereIsNoContent() throws Exception {
Connection connection = null;
try {
// Start the server
ValidatingHttpServer server = new SignatureValidatingHttpServer(port, secretKey);
connection = server.connect();
// Create a client with the filter that is under test
Client client = createClient();
client.addFilter(new HmacClientFilter(apiKey, secretKey, client.getMessageBodyWorkers()));
// Send a request with no content in the request body
client.resource(server.getUri()).get(String.class);
} finally {
if (connection != null) {
connection.close();
}
}
}
示例6: main
import org.simpleframework.transport.connect.Connection; //导入依赖的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 + ".");
}
示例7: main
import org.simpleframework.transport.connect.Connection; //导入依赖的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);
}
示例8: testStop
import org.simpleframework.transport.connect.Connection; //导入依赖的package包/类
public void testStop() throws Exception {
ThreadDumper dumper = new ThreadDumper();
dumper.start();
dumper.waitUntilStarted();
ThreadMXBean threadBean = ManagementFactory.getThreadMXBean();
int initialThreads = threadBean.getThreadCount();
for(int i = 0; i < ITERATIONS; i++) {
try {
ServerCriteria criteria = createServer();
InetSocketAddress address = criteria.getAddress();
Connection connection = criteria.getConnection();
Client client = createClient(address, String.format("[%s of %s]", i, ITERATIONS));
Thread.sleep(2000); // allow some requests to execute
connection.close();
Thread.sleep(100); // ensure client keeps executing
client.close();
Thread.sleep(1000); // wait for threads to terminate
}catch(Exception e) {
e.printStackTrace();
}
assertEquals(initialThreads, threadBean.getThreadCount());
}
dumper.kill();
}
示例9: main
import org.simpleframework.transport.connect.Connection; //导入依赖的package包/类
public static void main(String[] list) throws Exception {
Connection serverCon = createServer(false, 443);
/*SSLSocket socketCon = createClient();
OutputStream out = socketCon.getOutputStream();
for(int i = 0; i < 1000; i++) {
out.write("TEST".getBytes());
out.flush();
Thread.sleep(5000);
}*/
Thread.sleep(1000000);
serverCon.close();
}
示例10: connect
import org.simpleframework.transport.connect.Connection; //导入依赖的package包/类
public Connection connect() throws Exception {
Server server = new ContainerServer(this);
Connection connection = new SocketConnection(server);
SocketAddress address = new InetSocketAddress(port);
connection.connect(address);
return connection;
}
示例11: validateSignatureWhenContentIsPojo
import org.simpleframework.transport.connect.Connection; //导入依赖的package包/类
@Test
public void validateSignatureWhenContentIsPojo() throws Exception {
Connection connection = null;
try {
// Start the server
RequestConfiguration requestConfiguration =
RequestConfiguration.builder().withApiKeyQueryParamName("passkey")
.withSignatureHttpHeader("duck-duck-signature-header")
.withTimestampHttpHeader("duck-duck-timestamp-header")
.withVersionHttpHeader("duck-duck-version-header")
.build();
ValidatingHttpServer server = new SignatureValidatingHttpServer(port, secretKey, requestConfiguration);
connection = server.connect();
// Create a client with the filter that is under test
Client client = createClient();
client.addFilter(new HmacClientFilter(apiKey, secretKey, client.getMessageBodyWorkers(), requestConfiguration));
client.addFilter(new GZIPContentEncodingFilter(true));
// Send a pizza in the request body
Pizza pizza = new Pizza();
pizza.setTopping("olive");
client.resource(server.getUri())
.type(MediaType.APPLICATION_JSON_TYPE)
.put(pizza);
} finally {
if (connection != null) {
connection.close();
}
}
}
示例12: validateSignatureWhenContentIsBinary
import org.simpleframework.transport.connect.Connection; //导入依赖的package包/类
@Test
public void validateSignatureWhenContentIsBinary() throws Exception {
Connection connection = null;
try {
// Start the server
RequestConfiguration requestConfiguration =
RequestConfiguration.builder()
.withApiKeyQueryParamName("passkey")
.withSignatureHttpHeader("duck-duck-signature-header")
.withTimestampHttpHeader("duck-duck-timestamp-header")
.withVersionHttpHeader("duck-duck-version-header")
.build();
ValidatingHttpServer server = new SignatureValidatingHttpServer(port, secretKey, requestConfiguration);
connection = server.connect();
// Create a client with the filter that is under test
Client client = createClient();
client.addFilter(new HmacClientFilter(apiKey, secretKey, client.getMessageBodyWorkers(),requestConfiguration));
// Send some random binary data in the request body
byte[] binaryData = new byte[2];
new Random().nextBytes(binaryData);
client.resource(server.getUri())
.type(MediaType.APPLICATION_OCTET_STREAM_TYPE)
.put(binaryData);
} finally {
if (connection != null) {
connection.close();
}
}
}
示例13: validateSignatureWhenPathHasQueryParams
import org.simpleframework.transport.connect.Connection; //导入依赖的package包/类
@Test
public void validateSignatureWhenPathHasQueryParams() throws Exception {
Connection connection = null;
try {
// Start the server
RequestConfiguration requestConfiguration =
RequestConfiguration.builder()
.withApiKeyQueryParamName("passkey")
.withSignatureHttpHeader("duck-duck-signature-header")
.withTimestampHttpHeader("duck-duck-timestamp-header")
.withVersionHttpHeader("duck-duck-version-header")
.build();
ValidatingHttpServer server = new SignatureValidatingHttpServer(port, secretKey, requestConfiguration);
connection = server.connect();
// Create a client with the filter that is under test
Client client = createClient();
client.addFilter(new HmacClientFilter(apiKey, secretKey, client.getMessageBodyWorkers(), requestConfiguration));
// Send the request to a path other than "/" and that also includes an additional query parameter
URI uri = UriBuilder.fromUri(server.getUri())
.segment("api", "v1", "pizza")
.queryParam("sort", "toppings")
.build();
client.resource(uri).get(String.class);
} finally {
if (connection != null) {
connection.close();
}
}
}
示例14: startServing
import org.simpleframework.transport.connect.Connection; //导入依赖的package包/类
/**
* Starts serving HTTPS encrypted traffic from this container.
*
* @param numThreads the number of threads to handle the HTTP requests.
* @param context a valid SSLContext for serving secure connections.
* @throws IOException thrown if HTTP serving could not be started.
*/
void startServing(int numThreads, SSLContext context) throws IOException {
final ContainerSocketProcessor processor = new ContainerSocketProcessor(this, numThreads);
// Since this server will run forever, no need to close connection.
final Connection connection = new SocketConnection(processor);
final SocketAddress address = new InetSocketAddress(mPort);
connection.connect(address, context);
LOG.info("Listening to: " + address.toString());
}
示例15: startServing
import org.simpleframework.transport.connect.Connection; //导入依赖的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());
}
}