@Test
public void sendTextMessageThroughTcp() throws Exception {
// replace existing implementation for testing purposes
_testKit.removeService("SecuredGreetingService");
final MockHandler greetingService = _testKit.registerInOnlyService("SecuredGreetingService");
greetingService.forwardInToOut();
KeyStore keystore = KeyStore.getInstance("JKS");
keystore.load(new FileInputStream("users.jks"), "changeit".toCharArray());
TrustManagerFactory tmf = TrustManagerFactory.getInstance("SunX509");
tmf.init(keystore);
SSLContext context = SSLContext.getInstance("TLS");
KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
keyManagerFactory.init(keystore, "changeit".toCharArray());
context.init(keyManagerFactory.getKeyManagers(), tmf.getTrustManagers(), null);
SSLSocketFactory sf = context.getSocketFactory();
Socket clientSocket = sf.createSocket("localhost", 3939);
DataOutputStream outputStream = new DataOutputStream(clientSocket.getOutputStream());
// lets write payload directly as bytes to avoid encoding mismatches
outputStream.write(PAYLOAD.getBytes());
outputStream.flush();
// sleep a bit to receive message on camel side
Thread.sleep(50);
clientSocket.close();
greetingService.waitForOKMessage();
final LinkedBlockingQueue<Exchange> recievedMessages = greetingService.getMessages();
assertThat(recievedMessages, is(notNullValue()));
final Exchange recievedExchange = recievedMessages.iterator().next();
assertThat(PAYLOAD, is(equalTo(recievedExchange.getMessage().getContent(String.class))));
}