We have a message processing server, which
now the client want to have a web service server on the server, they will be able to querying the message processing server, with a web service client. e.g. give me all the messages for today, or delete the message with id....
the problem are:
Tomcat is a web server of its own, so a separate web server like Apache is not required. You probably will want to change Tomcat's port though, since it defaults to 8080 and web sites are usually on port 80.
One of the most popular uses is as a web server, using one of the many supported embedded servlet containers and template engines. However, Spring Boot has a number of uses that do not require a web server: console applications, job scheduling, batch or stream processing, serverless applications, and more.
You can use Spring Boot without embedded Tomcat web server if you don't need it. Just exclude embedded Tomcat from Spring Boot Web Starter (spring-boot-starter-web).
You don't need a third party library to use jax-ws annotations. J2SE ships with jax-ws, so all the annotations are still available to you. You can achieve lightweight results with the following solution, but for anything optimized/multi-threaded, it's on your own head to implement:
Design a SEI, service endpoint interface, which is basically a java interface with web-service annotations. This is not mandatory, it's just a point of good design from basic OOP.
import javax.jws.WebService;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.soap.SOAPBinding;
import javax.jws.soap.SOAPBinding.Style;
@WebService
@SOAPBinding(style = Style.RPC) //this annotation stipulates the style of your ws, document or rpc based. rpc is more straightforward and simpler. And old.
public interface MyService{
@WebMethod String getString();
}
Implement the SEI in a java class called a SIB service implementation bean.
@WebService(endpointInterface = "com.yours.wsinterface") //this binds the SEI to the SIB
public class MyServiceImpl implements MyService {
public String getResult() { return "result"; }
}
Expose the service using an Endpoint
import javax.xml.ws.Endpoint;
public class MyServiceEndpoint{
public static void main(String[] params){
Endpoint endPoint = EndPoint.create(new MyServiceImpl());
endPoint.publish("http://localhost:9001/myService"); //supply your desired url to the publish method to actually expose the service.
}
}
The snippets above, like I said, are pretty basic, and will perform poorly in production. You'll need to work out a threading model for requests. The endpoint API accepts an instance of Executor to support concurrent requests. Threading's not really my thing, so I'm unable to give you pointers.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With