开发者

What approach for java web service to use?

I'm developing a web application with multiple frameworks (spring, hibernate, spring-security, ZK for GUI), and using Tomcat as app server. I must say I have absolutely no experience with java web services technologies. Thing is, I will almost certainly have to expose number of services for some external applications in the near future, and I was wondering what would be the way to go (considering the frameworks I'm using)...

I saw and read various tutorials and some questions (link) regarding Axis, Axis2, JAX-WS... Thing that confuses me a little bit is that I don't know what is the common practice (if any) to integrate services within existing web application (mainly in the terms of project organization). As I see it now, the开发者_StackOverflowse services that I need to implement will rely partially on the existing source code, so I don't know whether I should use completely separate project, or I can put it inside my existing web app folder (which I tried with Axis2, but don't know if it's a good practice).

Thanks.


How to organize the projects?

In general I agree with @ericacm, but there is one thing you should keep in mind... You said you're going to develop a number of services in the near future. You may come to a point at which you want to host the services on a separate server, e.g. for performance, availability or maintainability reasons. This may influence your decision of separating the projects. Furthermore, separation "enforces" loose coupling, but therefore introduces other challenges like session sharing across multiple WARs. It's a case-by-case decision.

If I were in your situation I'd first ask myself whether the service(s) logically belongs to the web application or not.

Implementation

When in comes to WS-* implementations you have to make 2 decisions:

  1. Decide for an API to use; today, I can't see any reason for not going with JAX-WS together with JAXB as API, they work well and they are standardized.
  2. Decide for a Framework; I've experience using Axis2 as well as METRO (keep in mind that JSE 1.6+ provides basic JAX-WS support). Both work well. It's fairly easy to change the frameworks if you use the JAX-WS APIs.


I have good experience with Spring-WS 2+ and manual Castor mapping . Is is easy but powerful combination.

Spring-ws 2:

  • provides contract-first development (specially good for the web app with number of services).
  • provides WS annotation
  • supports XML mapping (Castor, JaxB, etc)

Castor:

  • mapping based on xml configuration
  • allows map multiple messages (requests/responses) to one java object (based on xml configuration)

If you are using some Java EE 6 server, consider also JAXB for manual mapping:

  • mapping based on annotation
  • should be faster than Castor
  • allows map multiple messages (requests/response) to one java object (when you use java inheritance)


You can go ahead and put them into the same project. Each web service will be an additional interface and implementation class along with some configuration.

Since you are using Spring CXF is a good choice as a for JAX-WS as it integrates well with Spring. See this page as a starter.


Spring-WS is complex framework for simple web services. If you want to understand web services completely and to know the nuts and bolts of web services, learn Spring-WS. It is extremely flexible and provides lot of options.

Else, if you want simpler alternative use JAX-WS. Spring supports JAX-WS annotations. Refer to the section 17.5.7. Exporting web services using the JAX-WS RI's Spring support.

http://static.springsource.org/spring/docs/2.5.x/reference/remoting.html


Is it possible to create WS Server and WS Client manually (without generators) by JAX-WS? Specially if you are developing a big application you want to re-use objects but generators are generating a lot of classes that can be in 99% the same (for example if your app is WS Client and you have to connect to badly designed external WS Server). Is there some tutorial how co create ws manually?

There is a lot of reasons why I don't like generators and completely agree with http://ogrigas.eu/spring/2010/04/spring-ws-and-jaxb-without-a-code-generator

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜