users@jersey.java.net

Re: [Jersey] WadlResource, stylesheets for Wadl documents, custom marshalling

From: Ari Heino <ext.ari.heino_at_tieto.com>
Date: Tue, 6 Oct 2009 05:23:39 -0700 (PDT)

I get the same NPE even when using Jersey's default wadler:

6.10.2009 15:20:06 com.sun.jersey.server.impl.wadl.WadlResource getWadl
WARNING: Could not marshal wadl Application.
java.lang.NullPointerException
        at
com.sun.jersey.server.impl.wadl.WadlResource.getWadl(WadlResource.java:83)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:79)
        at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:618)
        at
com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$ResponseOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:175)
        at
com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:67)
        at
com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:163)
        at
com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:71)
        at
com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:111)
        at
com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:63)
        at
com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:689)
        at
com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:647)
        at
com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:638)
        at
com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:309)
        at
com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:425)
        at
com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:590)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
        at
org.eclipse.equinox.http.servlet.internal.ServletRegistration.handleRequest(ServletRegistration.java:90)
        at
org.eclipse.equinox.http.servlet.internal.ProxyServlet.processAlias(ProxyServlet.java:111)
        at
org.eclipse.equinox.http.servlet.internal.ProxyServlet.service(ProxyServlet.java:67)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
        at
org.eclipse.equinox.http.jetty.internal.HttpServerManager$InternalHttpServiceServlet.service(HttpServerManager.java:318)
        at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:502)
        at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:380)
        at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)
        at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
        at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
        at org.mortbay.jetty.Server.handle(Server.java:324)
        at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:535)
        at
org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:865)
        at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:540)
        at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:213)
        at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
        at
org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:409)
        at
org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:520)


Paul Sandoz wrote:
>
> Hi,
>
> There have been a number of emails on the use of WadlResource,
> stylesheets for transforming the the WADL document, and JAXB custom
> marshalling of the WADL.
>
> I thought it would be easier to consolidate all the threads into one
> new response.
>
>
> In 1.0.3-SNAPSHOT it is now possible to write your own WADL resource
> (see end of email of the Jersey implementation of WadlResource) by
> injecting WadlApplicationContext.
>
> From the WadlApplicationContext you can get an instance of the JAXB
> bean com.sun.research.ws.wadl.Application. And then you can serialize
> that bean as you wish.
>
> The next steps are to:
>
> 1) To incorporate Jame's patch:
>
> https://jersey.dev.java.net/issues/show_bug.cgi?id=223
>
> to help with using WADL with implicit views.
>
> 2) Allow a developer to declare their own implementation of WadlResource
> at the relative URL "application.wadl"
>
> @Path("application.wadl")
> public MyWadlResource extends WadlResource { ... }
>
>
> For setting the style sheet see:
>
> https://jaxb.dev.java.net/nonav/2.1.10/docs/
> vendorProperties.html#xmlheader
>
> You can do this:
>
> Marshaller m = ...
> m.setProperty("com.sun.xml.bind.xmlHeaders", "<?xml-
> stylesheet type='text/xsl' href='foobar.xsl' ?>");
>
> Paul.
>
>
> @Produces({"application/vnd.sun.wadl+xml", "application/xml"})
> @Singleton
> public final class WadlResource {
>
> private static final Logger LOGGER =
> Logger.getLogger(WadlResource.class.getName());
>
> private WadlApplicationContext wadlContext;
>
> private Application application;
>
> private byte[] wadlXmlRepresentation;
>
> public WadlResource(@Context WadlApplicationContext wadlContext) {
> this.wadlContext = wadlContext;
> this.application = wadlContext.getApplication();
> }
>
> @GET
> public synchronized Response getWadl(@Context UriInfo uriInfo) {
> if (wadlXmlRepresentation == null) {
> if (application.getResources().getBase() == null) {
>
> application.getResources().setBase(uriInfo.getBaseUri().toString());
> }
> try {
> final Marshaller marshaller =
> wadlContext.getJAXBContext().createMarshaller();
>
> marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
> final ByteArrayOutputStream os = new
> ByteArrayOutputStream();
> marshaller.marshal(application, os);
> wadlXmlRepresentation = os.toByteArray();
> os.close();
> } catch (Exception e) {
> LOGGER.log(Level.WARNING, "Could not marshal wadl
> Application.", e);
> return Response.ok(application).build();
> }
> }
>
> return Response.ok(new
> ByteArrayInputStream(wadlXmlRepresentation)).build();
> }
> }
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>
>
>

-- 
View this message in context: http://n2.nabble.com/WadlResource-stylesheets-for-Wadl-documents-custom-marshalling-tp2454900p3774656.html
Sent from the Jersey mailing list archive at Nabble.com.