Version 1

    This document gives you a sample project pattern that you can adapt to your needs to build a JEE application with the following characteristics:

    - Targets Jboss7.1.1.Final

    - Uses spring (3.2.2.RELEASE) either packaged or as a jboss module

    - Uses CXF (Jboss' version - 2.4.6)

    - Web service is contract first, exposed with jboss' CXF and spring-enabled

    - Uses skinny war

    - Logic is isolated in a project (acme-book-impl)

     

    The first goal of the project is to show a way of organizing a typical web service project using the technologies already mentioned.

    The second goal is to show how to use the Jboss' CXF integration along with spring injection. The spring wiring is tricky: I had to google a bit before finding the right recipe.

    The solution is simple: use a post-creation annotation to call spring in order to manage injection and make sure to use @Autowired (neither @Resource nor @Inject will do: only @Autowired)

     

    The result is class BookWebService.java:

    ...

    @WebService(endpointInterface = "org.acme.book.ws.BookService")

    public class BookWebService implements BookService {

     

              @Resource

              private WebServiceContext context;

     

              @Autowired

              private BookServiceImpl bookService;

     

              @PostConstruct

              public void init() {

                        SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext(this);

              }

     

              @Override

              public BookingResponse book(BookingRequest pkg) {

                        return bookService.book(pkg);

              }

    }

     

    The last goal for the project is to document a small issue with the jboss module system: When spring is used as a module and there is no network (i.e you are traveling with you laptop offline), the application will not work at all because the spring schema cannot be loaded, neither from the classpath nor from the net.

     

    Your first thought should be: easy! simply import META-INF/**

    Ex:

    <?xml version="1.0" encoding="UTF-8"?>

    <jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.0">

              <deployment>

                        <dependencies>

                                  <module

                                            name="org.springframework"

                                            slot="3.2.2.RELEASE"

                                            export="true">

                                            <imports>

                                                      <include path="META-INF**" />

                                                      <include path="org**" />

                                            </imports>

                                  </module>

                        </dependencies>

              </deployment>

    </jboss-deployment-structure>

     

    But no, this doesn't work.

     

    This should not a big issue since many production systems will be able to access the internet... Or maybe not ?

    Imagine a highly secured environment where access to the internet is controled: the application would work only with spring packaged in the EAR because the firewall denies access to the schemas.

     

    Also, this is the kind of problem which may mask another, more subtil, issue...

    I think there is that kind of small, subtil, issue in the jboss module system.

    This small project is a way to observe the issue.

     

    Simply unzip the package and compile with maven:

    "mvn clean install eclipse:clean eclipse:eclipse"

     

    Use the zip file in the acme-book-jboss-module-spring project to install a spring module which is used by project acme-book-skinny-ear.

    When the deployments are completed, use soapUI to send a request.

    URL = http://localhost:8080/bookskinny/BookWebService

    and : http://localhost:8080/book/BookWebService

     

    When the internet is open, both projects work as expected (acme-book-dep-ear-0.0.1-SNAPSHOT and acme-book-skinny-ear-0.0.1-SNAPSHOT). Now, unplug the internet (or turn off the wifi card) and restart: acme-book-dep-ear-0.0.1-SNAPSHOT works but acme-book-skinny-ear-0.0.1-SNAPSHOT fails.

     

    The error message is:

    ...

    Caused by: org.xml.sax.SAXParseException; lineNumber: 6; columnNumber: 72; cvc-elt.1: Cannot find the declaration of element 'beans'.

              at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:196)

              at org.apache.xerces.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:132)

              at org.apache.xerces.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:390)

              at org.apache.xerces.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:322)

              at org.apache.xerces.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:281)

    ...

     

    Again, I googled here and there but (at the time of writing this) I did not found an explanation for this behavior.

    If you have an explanation, please step forward and tell us!