diff --git a/apache-thrift/src/main/java/com/baeldung/thrift/Application.java b/apache-thrift/src/main/java/com/baeldung/thrift/Application.java index 09d5cc74f3..3321a0927a 100644 --- a/apache-thrift/src/main/java/com/baeldung/thrift/Application.java +++ b/apache-thrift/src/main/java/com/baeldung/thrift/Application.java @@ -1,8 +1,10 @@ package com.baeldung.thrift; +import org.apache.thrift.transport.TTransportException; + public class Application { - public static void main(String[] args) { + public static void main(String[] args) throws TTransportException { CrossPlatformServiceServer server = new CrossPlatformServiceServer(); server.start(); } diff --git a/apache-thrift/src/main/java/com/baeldung/thrift/CrossPlatformServiceServer.java b/apache-thrift/src/main/java/com/baeldung/thrift/CrossPlatformServiceServer.java index 9a21512b52..32c7891ef2 100644 --- a/apache-thrift/src/main/java/com/baeldung/thrift/CrossPlatformServiceServer.java +++ b/apache-thrift/src/main/java/com/baeldung/thrift/CrossPlatformServiceServer.java @@ -6,25 +6,22 @@ import org.apache.thrift.server.TServer; import org.apache.thrift.server.TSimpleServer; import org.apache.thrift.transport.TServerSocket; import org.apache.thrift.transport.TServerTransport; +import org.apache.thrift.transport.TTransportException; public class CrossPlatformServiceServer { private TServer server; - public void start() { - try { - TServerTransport serverTransport = new TServerSocket(9090); - server = new TSimpleServer(new TServer.Args(serverTransport) - .processor(new CrossPlatformService.Processor<>(new CrossPlatformServiceImpl()))); + public void start() throws TTransportException { + TServerTransport serverTransport = new TServerSocket(9090); + server = new TSimpleServer(new TServer.Args(serverTransport) + .processor(new CrossPlatformService.Processor<>(new CrossPlatformServiceImpl()))); - System.out.print("Starting the server... "); + System.out.print("Starting the server... "); - server.serve(); + server.serve(); - System.out.println("done."); - } catch (Exception e) { - e.printStackTrace(); - } + System.out.println("done."); } public void stop() { diff --git a/apache-thrift/src/test/java/com/baeldung/thrift/CrossPlatformServiceTest.java b/apache-thrift/src/test/java/com/baeldung/thrift/CrossPlatformServiceTest.java index 8a7022a281..4ba9ef2914 100644 --- a/apache-thrift/src/test/java/com/baeldung/thrift/CrossPlatformServiceTest.java +++ b/apache-thrift/src/test/java/com/baeldung/thrift/CrossPlatformServiceTest.java @@ -1,5 +1,6 @@ package com.baeldung.thrift; +import org.apache.thrift.transport.TTransportException; import org.junit.After; import org.junit.Assert; import org.junit.Before; @@ -11,7 +12,13 @@ public class CrossPlatformServiceTest { @Before public void setUp() { - new Thread(() -> server.start()).start(); + new Thread(() -> { + try { + server.start(); + } catch (TTransportException e) { + e.printStackTrace(); + } + }).start(); try { // wait for the server start up Thread.sleep(1000);