The Source for Java Technology Collaboration
User: Password:



Kohsuke Kawaguchi

Kohsuke Kawaguchi's Blog

Spring support in JAX-WS RI

Posted by kohsuke on January 04, 2007 at 11:47 AM | Comments (23)

Various people have been asking us to do a better job at Spring integration. So I've been working on it, and the first cut is ready.

The idea behind this is relatively simple. Spring is widely used to configure server applications nowadays. It makes it easy to have your object reference your other objects. Thus when you are using Spring in your application, you usually want your web service implementation classes to be configured by Spring, because those classes need access to other objects in your application. The same goes to handlers, if you have any.

With the Spring support extension in the JAX-WS RI, you can now wire your service implementation classes as well as handlers by using Spring, like this:


<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:ws= "http://jax-ws.dev.java.net/spring/core"
       xmlns:wss="http://jax-ws.dev.java.net/spring/servlet" ...>

  <wss:bindings id="jax-ws.http">
    <wss:bindings>
      <wss:binding url="/stockQuote">
        <wss:service><!-- nested bean is of course fine -->
          <ws:service impl="foo.MyService">
            <ws:handlers>
              <ref bean="myHandler" />
            </ws:handlers>
          </ws:service>
        </wss:service>
      </wss:binding>
    </wss:bindings>
  </wss:bindings>

  <bean id="myHandler" class="foo.MyHandler" />
</beans>

This example configures one service MyService with one handler MyHandler, then expose it to /stockQuote. Those two user classes are now wired by Spring, so you can have other dependencies injected to them in the same way you'd configure other beans in Spring.

Not only that, this extension allows you to configure JAX-WS itself from Spring. For example, by writing <ws:service bindingId="http://www.w3.org/2003/05/soap/bindings/HTTP/" /> you can make this service SOAP 1.2 service. Or to enable addressing, you can do:


<ws:service impl="foo.MyService">
  <ws:features>
    <ws:addressing />
  </ws:features>
</ws:service>

So as you can see, this can effectively replace sun-jaxws.xml. Since Spring support is open-ended, this can be used to enable other JAX-WS extensions. So for example we can use this to configure JMS transport, or to configure JSON encoding, etc.

This is still a work in progress, but since I'm new to Spring, I thought I'd make this available sooner so that people with more Spring experience can give me feedback.

If you're interested in using this (and I hope you are!), all the necessary jar files are available at java.net maven2 repository. A sample application is available at here, and the project website is available here.


Bookmark blog post: del.icio.us del.icio.us Digg Digg DZone DZone Furl Furl Reddit Reddit
Comments
Comments are listed in date ascending order (oldest first) | Post Comment

  • Even though I'm new to it myself I have a few comments... I think when the general Spring user asks for integration, they mean start with the standard bean definition. They're looking for a paradigm that is familar, and right now that means injection and simple setting of properties. This might mean making an adapter to your classes, but then the paradigms will match up a little closer and people interested in integrating jaxws won't have to learn a new dtd/xsd format to make the technologies communicate. I'd suggest looking at the spring list definitions that they provide in the reference for the beginnings to the alternative to what you have here.

    Posted by: ilazarte on January 05, 2007 at 08:27 AM


  • I guess you are saying that you like the plain <bean>, <property>, and <ref> over the custom tags? The main reason I went for custom tags via XBean is that I thought the standard syntax is way too verbose, and I assumed everyone else hated it, too.


    It would be good to hear from other people. You can always configure those beans by using the standard syntax (after all, custom tags are just syntax sugar), the only thing we need to change is the documentation.

    Posted by: kohsuke on January 05, 2007 at 10:07 AM

  • That's pretty much what I'm saying. I would just document a "standard" integration first, and then your custom tag version second. A big selling point in Spring is the uniform integration after all ;)

    Posted by: ilazarte on January 05, 2007 at 10:38 AM

  • Thank you for this initiative. It is very nice to see the Spring now reaching reference implementations of standards!

    Altough competition is good in some areas, we don't need to reinvent the wheel all over the place. We better concentrate on the real challenges.

    I would agree with both of you. It is true that it is easier to understand the configuration if it uses well known and understandable concepts, and therefore the result is kind of self-documented.

    On the other hand, a concise configuration language is very nice as well. (Best would be to offer both, so one could choose the best solution for the situation :-)

    Posted by: laenzlinger on January 05, 2007 at 11:17 AM


  • OK, doing both just means more documentation work. So we'll think about what to do.


    Just out of curiosity, however, when I look at others using Spring, like ActiveMQ or ServiceMix, they only seem to talk about custom tags. Do they document both?

    Posted by: kohsuke on January 05, 2007 at 11:37 AM

  • Thanks for this effort! I'd like to begin playing with it, but I'm unable to find the jars. I poked around in:
    https://maven2-repository.dev.java.net/source/browse/maven2-repository/trunk/www/repository/org/jvnet/jax-ws-commons/
    and
    https://maven-repository.dev.java.net/repository/

    I also looked in the downloads section of the project website.

    Could you please point me to a downloadable jar?

    Thanks!

    Posted by: cmoesel on January 05, 2007 at 12:39 PM

  • Another question-- how do you use Spring to configure and inject dependencies into your service implementation? The tag's "impl" attribute takes the fully qualified classname of the service. In order to inject dependencies into the service implementation, wouldn't we need to pass a reference to a bean rather than passing the fqn?

    Posted by: cmoesel on January 05, 2007 at 12:57 PM

  • Why tag <wss:bindings>nested? Is it a typo?
    Again, what's the difference of <ws:service> and <wss:service>? Is it possible to merger these 2 tags? It looks quite tedious.

    Posted by: zwe on January 07, 2007 at 04:08 PM

  • I'm also having trouble specifying the primaryWSDL. In the sun-jaxws.xml file, I specified it as:
    wsdl='WEB-INF/wsdl/myservice.wsdl'


    I've tried many different ways using the <ws:primaryWsdl> tag in the Spring application context, but can't get it working right. The closest I've come is:

    <ws:primaryWsdl>
    <bean class="java.lang.String">
    <constructor-arg>
    <value>WEB-INF/wsdl/myservice.wsdl</value>
    </constructor-arg>
    </bean>
    </ws:primaryWsdl>

    This still complains, however, that WEB-INF/wsdl/myservice.wsdl is not a valid URL. If I change it to file://WEB-INF/wsdl/myservice.wsdl, I get a completely different error (that it is not a recognized type).


    I've also tried moving my wsdl to META-INF/wsdl directory so that JAX-WS picks it up automatically (per documentation of primaryWsdl element), but I don't think I'm naming the wsdl file right, as it's not picking it up.


    Any help is appreciated. Thanks!

    Posted by: cmoesel on January 08, 2007 at 07:09 AM


  • cmoesel — apparently I haven't deployed the jar to the repository yet. I just did so, and it's now available in the java.net m2 repository. And thank you for pointing out the "Duh" bug. Obviously we need to take a reference to another bean. I'll fix that.


    zwe — Nesting of <wss:bindings> is not a typo. I find that excessive, too, but I couldn't figure out how to get rid of that. I suspect it's a limitation of Spring or XBean. The outer <wss:bindings> is the name of the bean that's defined in this extension, and inner <wss:bindings> are apparently needed as this is a list property. I should probably check XBean source code to see if I can get rid of this.


    cmoesel — thanks for reporting an issue wrt primary WSDL. It's definitely a bug in the impl. I'll check.

    Posted by: kohsuke on January 08, 2007 at 09:54 AM

  • Kohsuke-- Thanks! I'm enjoying the use of JAX-WS 2.1, and Spring integration will make it even more enjoyable!

    Posted by: cmoesel on January 08, 2007 at 11:52 AM

  • The idea is good but I have the impression that the use of IoC is not possible today, so the interest is very limited (if it is possible, how?). It would be necessary to have an integration of jaxws in Spring as good as xfire.

    Posted by: schumnana on January 10, 2007 at 11:36 AM

  • schumnana — Could you elaborate on what you mean by "use of IoC is not possible today"? You can have Spring inject any dependencies to your SEI, since after all JAX-WS gets your service bean instance from Spring. See https://jax-ws-commons.dev.java.net/nonav/spring/

    Posted by: kohsuke on January 10, 2007 at 02:11 PM

  • Would it be possible to show this Spring integration in Java and not XML?

    Posted by: ctaggart on January 16, 2007 at 12:43 PM

  • ctaggart — I'm not sure what you mean. Can you elaborate?

    Posted by: kohsuke on January 16, 2007 at 02:40 PM

  • Hi Kohsuke--

    I saw that you've made some changes to the src to address some of the issues I had brought up earlier. I did a svn update and tried to build it (mvn clean install) but am getting an error (and it looks like it may have something to do with xbean's stuff).

    java.lang.NoClassDefFoundError: javax/servlet/ServletContext


    I checked the pom.xml file and it looks like the servlet API is listed as a dependency, so I'm not sure what's going on here (I don't really know Maven). Any ideas?

    Posted by: cmoesel on January 17, 2007 at 06:08 AM

  • cmoesel — started looking. I'm wondering why it started failing. It used to be working fine.

    Posted by: kohsuke on January 23, 2007 at 02:11 PM

  • Turns out this is a bug in qdox. See https://issues.apache.org/jira/browse/XBEAN-71 and http://jira.codehaus.org/browse/QDOX-110. Now I need to figure out the workaround.

    Posted by: kohsuke on January 23, 2007 at 03:00 PM

  • Thanks Kohsuke-- I appreciate it!

    Posted by: cmoesel on January 24, 2007 at 05:47 AM

  • I'm not getting it. Sample application dose not work because of illegal bean attribute in ws:service tag. I've made today's checkout. My most simple try do not work too with strange explanation Invalid content was found starting with element 'wss:binding'. One of '{WC[##other:"http://jax-ws.dev.java.net/spring/servlet"]}' is expected
    I was only able to get thing working with pure ws and wss tags. Witch means zero integration with rest of the spring beans :(

    Posted by: anthavio on January 26, 2007 at 09:34 AM

  • Since it's hard to do Q&A in blog comment area, I created a forum thread. Please post further questions there.

    Posted by: kohsuke on January 29, 2007 at 02:48 PM

  • I feel disappointed, it takes me 1 week to integrate spring with glass. And i failed. Could you please provide a document for how to use it .

    Posted by: fenixshadow2005 on December 29, 2007 at 04:48 AM

  • fenixshadow2005, it would be great if you can post your issues with more details to the GlassFish forum.

    Posted by: kohsuke on January 02, 2008 at 09:14 AM



Only logged in users may post comments. Login Here.


Powered by
Movable Type 3.01D
 Feed java.net RSS Feeds