use of java.net.Socket in project camel by apache.
the class UnsharableCodecsConflictsTest method canSupplyMultipleCodecsToEndpointPipeline.
@Test
public void canSupplyMultipleCodecsToEndpointPipeline() throws Exception {
byte[] sPort1 = new byte[8192];
byte[] sPort2 = new byte[16383];
Arrays.fill(sPort1, (byte) 0x38);
Arrays.fill(sPort2, (byte) 0x39);
byte[] bodyPort1 = (new String(LENGTH_HEADER) + new String(sPort1)).getBytes();
byte[] bodyPort2 = (new String(LENGTH_HEADER) + new String(sPort2)).getBytes();
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedBodiesReceived(new String(sPort2) + "9");
Socket server1 = getSocket("localhost", port1);
Socket server2 = getSocket("localhost", port2);
try {
sendSopBuffer(bodyPort2, server2);
sendSopBuffer(bodyPort1, server1);
sendSopBuffer(new String("9").getBytes(), server2);
} catch (Exception e) {
log.error("", e);
} finally {
server1.close();
server2.close();
}
mock.assertIsSatisfied();
}
use of java.net.Socket in project camel by apache.
the class UnsharableCodecsConflictsTest method getSocket.
private static Socket getSocket(String host, int port) throws IOException {
Socket s = new Socket(host, port);
s.setSoTimeout(60000);
return s;
}
use of java.net.Socket in project camel by apache.
the class NettyProducerHangTest method acceptReplyAcceptClose.
private void acceptReplyAcceptClose() throws IOException {
byte[] buf = new byte[128];
ServerSocket serverSocket = new ServerSocket(PORT);
Socket soc = serverSocket.accept();
log.info("Open socket and accept data");
try (InputStream is = soc.getInputStream();
OutputStream os = soc.getOutputStream()) {
// read first message
is.read(buf);
// reply to the first message
os.write("response\n".getBytes());
// read second message
is.read(buf);
// do not reply, just close socket (emulate network problem)
} finally {
soc.close();
serverSocket.close();
}
log.info("Close socket");
}
use of java.net.Socket in project camel by apache.
the class NettyTcpWithInOutUsingPlainSocketTest method sendAndReceive.
private String sendAndReceive(String input) throws IOException {
byte[] buf = new byte[128];
Socket soc = new Socket();
soc.connect(new InetSocketAddress("localhost", getPort()));
// Send message using plain Socket to test if this works
OutputStream os = null;
InputStream is = null;
try {
os = soc.getOutputStream();
// must append the line delimiter
os.write((input + "\n").getBytes());
is = soc.getInputStream();
int len = is.read(buf);
if (len == -1) {
// no data received
return null;
}
} finally {
if (is != null) {
is.close();
}
if (os != null) {
os.close();
}
soc.close();
}
// convert the buffer to chars
StringBuilder sb = new StringBuilder();
for (byte b : buf) {
char ch = (char) b;
if (ch == '\n' || ch == 0) {
// newline denotes end of text (added in the end in the processor below)
break;
} else {
sb.append(ch);
}
}
return sb.toString();
}
use of java.net.Socket in project camel by apache.
the class UnsharableCodecsConflictsTest method getSocket.
private static Socket getSocket(String host, int port) throws IOException {
Socket s = new Socket(host, port);
s.setSoTimeout(60000);
return s;
}
Aggregations