BAEL-598 Removed try-catch block, added throws declaration

This commit is contained in:
Predrag Maric 2017-02-04 15:59:49 +01:00
parent bd6fe7269e
commit f69deeca2d
3 changed files with 19 additions and 13 deletions

View File

@ -1,8 +1,10 @@
package com.baeldung.thrift; package com.baeldung.thrift;
import org.apache.thrift.transport.TTransportException;
public class Application { public class Application {
public static void main(String[] args) { public static void main(String[] args) throws TTransportException {
CrossPlatformServiceServer server = new CrossPlatformServiceServer(); CrossPlatformServiceServer server = new CrossPlatformServiceServer();
server.start(); server.start();
} }

View File

@ -6,13 +6,13 @@ import org.apache.thrift.server.TServer;
import org.apache.thrift.server.TSimpleServer; import org.apache.thrift.server.TSimpleServer;
import org.apache.thrift.transport.TServerSocket; import org.apache.thrift.transport.TServerSocket;
import org.apache.thrift.transport.TServerTransport; import org.apache.thrift.transport.TServerTransport;
import org.apache.thrift.transport.TTransportException;
public class CrossPlatformServiceServer { public class CrossPlatformServiceServer {
private TServer server; private TServer server;
public void start() { public void start() throws TTransportException {
try {
TServerTransport serverTransport = new TServerSocket(9090); TServerTransport serverTransport = new TServerSocket(9090);
server = new TSimpleServer(new TServer.Args(serverTransport) server = new TSimpleServer(new TServer.Args(serverTransport)
.processor(new CrossPlatformService.Processor<>(new CrossPlatformServiceImpl()))); .processor(new CrossPlatformService.Processor<>(new CrossPlatformServiceImpl())));
@ -22,9 +22,6 @@ public class CrossPlatformServiceServer {
server.serve(); server.serve();
System.out.println("done."); System.out.println("done.");
} catch (Exception e) {
e.printStackTrace();
}
} }
public void stop() { public void stop() {

View File

@ -1,5 +1,6 @@
package com.baeldung.thrift; package com.baeldung.thrift;
import org.apache.thrift.transport.TTransportException;
import org.junit.After; import org.junit.After;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
@ -11,7 +12,13 @@ public class CrossPlatformServiceTest {
@Before @Before
public void setUp() { public void setUp() {
new Thread(() -> server.start()).start(); new Thread(() -> {
try {
server.start();
} catch (TTransportException e) {
e.printStackTrace();
}
}).start();
try { try {
// wait for the server start up // wait for the server start up
Thread.sleep(1000); Thread.sleep(1000);