Simple WS endpoint deployment with JAXWS 2.2 HTTP container abstraction

Recently I’ve been playing with the JAXWS Endpoint.publish(..) API. For those not really involved in WS development, JAXWS includes an API for easily deploying an endpoint in JSE environment while starting a http server just for serving calls to the specified endpoint.

Endpoint endpoint = Endpoint.create(new EndpointBean());
endpoint.publish("http://localhost:8080/jaxws-endpoint1");
//invoke endpoint...
endpoint.stop();

While from a user point of view this API is of few interest on a JavaEE environment, this is still quite interesting in JSE env as well as whenever having the need for a quick/easy testing of basic endpoints.
Moreover, JAXWS 2.2 added a HTTP SPI for establishing / fixing the layer between http server containers and JAXWS stack implementations. This basically allows any jaxws 2.2 compliant implementation to be used on top of any “compatible” http server.
Jitendra Kotamraju (current JSR-224 spec lead) recently provided a bridge project for making Grizzly compatible with the JAXWS 2.2 HTTP SPI. I’ve done the same for the httpserver included in the JDK6 com.sun.net.httpserver.HttpServer. There’s also a similar project for Jetty. So, with the additions of spec 2.2 and the required vendor implementations to comply on that, users can finally do the following with any JAXWS compliant implementation:

import javax.xml.ws.spi.http.HttpContext;
..
HttpContext context = ..;
Endpoint endpoint = Endpoint.create(new EndpointBean());
endpoint.publish(context);
//invoke endpoint
endpoint.stop();

where the context is obtained according to the selected containers, for instance (using my bridge to the JDK6 httpserver):

import com.sun.net.httpserver.HttpServer;
..
HttpServer server = HttpServer.create(new InetSocketAddress(currentPort), 0);
HttpContext context = HttpServerContextFactory.createHttpContext(server, contextPath, path);
server.start();
..
//here comes the endpoint publish and usage as shown above
..
server.stop(0);

Quite handy, isn’t it? ;-)

JavaDay in Rome

Just a short note to tell you an interesting event on Java is taking place in Rome next Saturday (Jan, 30th). If you’re around, you might want to attend that: http://roma.javaday.it/javaday2010/

Most of the talks are going to be in Italian, but at least three of them will be in English. The talks are going to be quite technical and should also cover interesting topics like scalability, concurrency, management and tuning.

Analysing jar dependencies

Something like 2 months ago I wrote a post on how different classloaders can potentially cause you problems if you’re not that careful on where your libs are loaded from. Well, I’ve just had to face another issue of that type, with a library of mine loaded from the bootstrap classloader and referencing a class from servlet API that I don’t want to be loaded by that classloader too. The easy solution of course would have been to pull my lib out of the endorsed dir (the one the bootstrap classloader loads libs from), but how could I be sure that I did not break anything in my app? Besides running tests, I finally decided to give JBoss Tattletale a try… I saw all the hype around it when it was released some month ago, but I did not have the chance to use it for a practical issue before.

Well, in less than five minutes I checked out he project, built it and ran it against my endorsed lib dir. I got a report and some graphs basically showing no libraries in that dir (hence loaded by the bootstrap classloader) where directly depending on my library, thus it’s safe to pull it out of the endorsed dir. The easy solution was indeed OK and thanks to this tool I have a theoretical proof of that ;-)

Take a look at JBoss Tattletale, it’s really a cool tool. Perhaps you can start from its author’s blog: http://blog.hibernate.org/11166.lace

Java Application Server Day 2009

This post is to let you know a really interesting event that’s taking place soon in Genoa (Italy): the Java Application Server Day 2009.

As you can read on www.serverday.org, the event will be open to the entire Italian Java Community; international experts, developers and students will discuss the state of the art
and the future of Java Application Servers, with a focus on the innovations of
the recently released JBoss 5.0, Spring dm Server, GlassFish 3.0 & Oracle/WebLogic.

I’ve been asked to be there on behalf of JBoss / Red Hat, so I’ll present the recent changes in JBoss AS 5.

Hope you can join the event on May, 21st. Stay tuned for further updates.

JBossWS wsconsume error “undefined element declaration ‘sch:schema’”

Today I was importing a .NET generated wsdl and getting this error using JBossWS wsconsume.sh tool (yes I’m not using Wise for this particular case!! But the problem would be the same in Wise since it use wsconsume under the hood) :

[WARNING] src-resolve.4.2: Error resolving component 'sch:schema'. It was detected that 'sch:schema' is in namespace 'http://www.w3.org/2001/XMLSchema', but components from this namespace are not referenceable from schema document 'file:/home/oracle/Desktop/security.asmx#types?schema1'. If this is the incorrect namespace, perhaps the prefix of 'sch:schema' needs to be changed. If this is the correct namespace, then an appropriate 'import' tag should be added to 'file:/home/oracle/Desktop/security.asmx#types?schema1'.
  line 85 of file:/home/oracle/Desktop/security.asmx#types?schema1
[ERROR] undefined element declaration 'sch:schema'
  line 85 of file:/home/oracle/Desktop/security.asmx
[ERROR] undefined element declaration 'sch:schema'
  line 178 of file:/home/oracle/Desktop/security.asmx
[ERROR] undefined element declaration 'sch:schema'
  line 217 of file:/home/oracle/Desktop/security.asmx
[ERROR] undefined element declaration 'sch:schema'
  line 231 of file:/home/oracle/Desktop/security.asmx
[ERROR] undefined element declaration 'sch:schema'
  line 245 of file:/home/oracle/Desktop/security.asmx
[ERROR] undefined element declaration 'sch:schema'
  line 259 of file:/home/oracle/Desktop/security.asmx
[ERROR] undefined element declaration 'sch:schema'
  line 273 of file:/home/oracle/Desktop/security.asmx

Failed to invoke WsImport
java.lang.NullPointerException
        at com.sun.tools.xjc.reader.internalizer.SCDBasedBindingSet.apply(SCDBasedBindingSet.java:237)
        at com.sun.tools.xjc.ModelLoader.createXSOM(ModelLoader.java:518)
        at com.sun.tools.xjc.api.impl.s2j.SchemaCompilerImpl.bind(SchemaCompilerImpl.java:232)
        at com.sun.tools.xjc.api.impl.s2j.SchemaCompilerImpl.bind(SchemaCompilerImpl.java:85)
        at com.sun.tools.ws.processor.modeler.wsdl.JAXBModelBuilder.bind(JAXBModelBuilder.java:134)
        at com.sun.tools.ws.processor.modeler.wsdl.WSDLModeler.buildJAXBModel(WSDLModeler.java:2244)
        at com.sun.tools.ws.processor.modeler.wsdl.WSDLModeler.internalBuildModel(WSDLModeler.java:187)
        at com.sun.tools.ws.processor.modeler.wsdl.WSDLModeler.buildModel(WSDLModeler.java:133)
        at com.sun.tools.ws.wscompile.WsimportTool.run(WsimportTool.java:182)
        at org.jboss.ws.tools.jaxws.impl.SunRIConsumerImpl.consume(SunRIConsumerImpl.java:217)
        at org.jboss.wsf.spi.tools.cmd.WSConsume.importServices(WSConsume.java:223)
        at org.jboss.wsf.spi.tools.cmd.WSConsume.main(WSConsume.java:81)

After some search Alessio pointed me to this excellent post where the problem is well explained and solution provided. The “problem” is not specific to JBossWS and solution explained there is fine for JBossWS too.

Hoping this cross post could help someone looking for the error in relation to JBossWS in google ;)