How to generate EJB from WSDL
I know how to use @WebService and @Stateless annotation to write an EJB and expose it into a WebService.
But because we're try to use other tools to generate WSDL first and then create Java code. I can use WebLogic's WSDLC to generate a service code from WSDL. But the problem is that the code generated by WSDLC is not EJB. Is there any suggestion to do WSDL -> EJB?
If it's possible, I prefer not to use A开发者_如何转开发XIS.
I am working in EJB and Web Services for quite some time and did not come across any such tools. Logically it makes sense,
Web services themselves are not components but as a a facade for some business component (EJB in this case). They are decoupled from each other.
WSDL base code generators will generate these facade or annotated Pojos.
Whether that POJO/Facade uses EJB or any other services to delegate further, entirely depend on the implementation.
This is the reason I feel there wont be such tool to generate EJB directly from WSDL. But again I am limited by my experience. I would be curious to know if such tool exists.
EDIT: Just FYI, there is WSDL EJB Extension. But it needs existing EJBs to bind its operation to WSDL. (It does not create EJB code)
Well, not that the new EJB 3.1 isn't A LOT better than the old versions, but I still preffer to use Apache CXF for web-services implementation:
http://cxf.apache.org/
It has a nice wsdl2java tool (which can be also used as a maven plugin):
http://cxf.apache.org/docs/wsdl-to-java.html
which takes your WSDL file, validates it, and then generates very clean Java template code for the implementation of your web-service: you have JAXB classes for marshalling the requests and responses, a very simple (coded to interface) webservice implementation class with methods for each ws operation (which methods you must ofcourse implement yourself with your business logic), and optionally a nice Java client stub that another Java app can use to access your service easily. Even without the client stub, you still get a nice clean and standard implementation which is basicaly just Java classes, no EJB container needed to start (or test) your web service.
SAP NetWeaver Developer Studio supports to generate a EJB WebService from WSDL. I just try it. http://help.sap.com/saphelp_nw72/helpdata/en/46/7f2fef88190ad3e10000000a11466f/content.htm
And I also check the code generated by Apache CXF, WebLogic wsdlc and SAP. They are similar. And if you use EJB 3, you can just add @Stateless annotation to the code generated by Apache CXF or WebLogic to let it be a EJB.
But I think it's not a good idea to expose business EJB to a WebService directly. There should be a service layer. The benefit to use EJB as a service layer is that it can use injection to access other EJB easily.
精彩评论