Java web service without web application server

We have a message processing server that

  • start multiple threads
  • message processing
  • interact with the database, etc.

Now the client wants to have a web services server on the server, he will be able to request a message processing server with the web service client. For example, give me all messages for today or delete the message with the identifier ....

The problem is this:

  • The server is just a standard j2se application, it does not start inside the application server, for example, tomcat or glassfish.
  • To handle an Http request do I need to implement an http server?
  • I would like to use a nice j2ee annotation like @webservice, @webmothod etc ... is there any library or wireframe that I can use
+6
source share
2 answers

You do not need a third-party library to use . J2SE comes with , so all annotations are still available to you. You can get easy results with the following solution, but for something optimized / multi-threaded, this is on your own head to implement:

  • Create an SEI endpoint interface, which is basically a Java interface with web service annotations. This is not necessary, it is just a point of good design from a 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(); } 
  • Deploy SEI in a Java class called the SIB bean service implementation.

     @WebService(endpointInterface = "com.yours.wsinterface") //this binds the SEI to the SIB public class MyServiceImpl implements MyService { public String getResult() { return "result"; } } 
  • Open the service using 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 passages above, as I said, are quite simple and will work poorly in production. You will need to develop a threading model for queries. The endpoint API accepts an instance of Executor to support concurrent requests. Threading is not really my thing, so I cannot give you pointers.

+8
source

For j2ee comments, see Apache CXF http://cxf.apache.org/ .

0
source

Source: https://habr.com/ru/post/927575/


All Articles