Hi Dominique
As suggested by Chris on the other thread related if you are
rebundling Jersey you need to use the maven shade plugin and
especially you need to use the ServicesResourceTransformer:
http://maven.apache.org/plugins/maven-shade-plugin/examples/resource-transformers.html
to ensure the META-INF/services files of various jars get included and
merged correctly.
Paul.
On Jul 20, 2010, at 3:34 PM, Dominique Guinard wrote:
> Dear Jersey folks,
>
> After a couple of years of Restlet app dev I decided to give a try to
> Jersey. I actually really enjoyed using it but I'm stuck with a
> problem
> right now.
>
> I embed my Jersey app in Grizzly and develop the whole thing as a
> maven
> project in netbeans 6.9. So far so good, however when I try packaging
> the app as a standalone project I keep getting the following message,
> whatever resource I ask for in whatever representation:
>
> ul 20, 2010 3:28:46 PM com.sun.jersey.spi.container.ContainerResponse
> write
> SEVERE: A message body writer for Java class java.lang.String, and
> Java
> type class java.lang.String, and MIME media type text/plain was not
> found
> Jul 20, 2010 3:28:46 PM com.sun.grizzly.http.servlet.ServletAdapter
> doService
> SEVERE: service exception:
> javax.ws.rs.WebApplicationException
> at
> com
> .sun
> .jersey.spi.container.ContainerResponse.write(ContainerResponse.java:
> 267)
> at
> com
> .sun
> .jersey
> .server
> .impl
> .application
> .WebApplicationImpl._handleRequest(WebApplicationImpl.java:1043)
> at
> com
> .sun
> .jersey
> .server
> .impl
> .application
> .WebApplicationImpl.handleRequest(WebApplicationImpl.java:947)
> at
> com
> .sun
> .jersey
> .server
> .impl
> .application
> .WebApplicationImpl.handleRequest(WebApplicationImpl.java:938)
> at
> com
> .sun
> .jersey.spi.container.servlet.WebComponent.service(WebComponent.java:
> 399)
> at
> com
> .sun
> .jersey
> .spi
> .container.servlet.ServletContainer.service(ServletContainer.java:478)
> at
> com
> .sun
> .jersey
> .spi
> .container.servlet.ServletContainer.service(ServletContainer.java:663)
> at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
> at
> com
> .sun
> .grizzly.http.servlet.FilterChainImpl.doFilter(FilterChainImpl.java:
> 195)
> at
> com
> .sun
> .grizzly
> .http.servlet.FilterChainImpl.invokeFilterChain(FilterChainImpl.java:
> 139)
> at
> com
> .sun
> .grizzly.http.servlet.ServletAdapter.doService(ServletAdapter.java:
> 376)
> at
> com
> .sun.grizzly.http.servlet.ServletAdapter.service(ServletAdapter.java:
> 324)
> at
> com
> .sun.grizzly.tcp.http11.GrizzlyAdapter.service(GrizzlyAdapter.java:
> 166)
> at
> com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:
> 791)
> at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:
> 693)
> at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:954)
> at
> com
> .sun
> .grizzly
> .http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:170)
> at
> com
> .sun
> .grizzly
> .DefaultProtocolChain
> .executeProtocolFilter(DefaultProtocolChain.java:135)
> at
> com
> .sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:
> 102)
> at
> com
> .sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:
> 88)
> at
> com
> .sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:76)
> at
> com
> .sun
> .grizzly
> .ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:53)
> at
> com
> .sun
> .grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:57)
> at com.sun.grizzly.ContextTask.run(ContextTask.java:69)
> at com.sun.grizzly.util.AbstractThreadPool
> $Worker.doWork(AbstractThreadPool.java:330)
> at com.sun.grizzly.util.AbstractThreadPool
> $Worker.run(AbstractThreadPool.java:309)
> at java.lang.Thread.run(Thread.java:619)
>
>
> I seems to me like a JAXB problem but JAXB IS packaged, here is my
> manifest:
>
> Manifest-Version: 1.0
> Archiver-Version: Plexus Archiver
> Created-By: Apache Maven
> Built-By: misterdom
> Build-Jdk: 1.6.0_20
> Main-Class: com.webofthings.webplogg.web.App
> Class-Path: jersey-server-1.2.jar jersey-core-1.2.jar jsr311-api-1.1.1
> .jar asm-3.1.jar jersey-client-1.2.jar jersey-json-1.2.jar jettison-1
> .1.jar stax-api-1.0.1.jar jaxb-impl-2.1.jar jaxb-api-2.1.jar stax-api
> -1.0-2.jar activation-1.1.jar jackson-core-asl-1.1.1.jar grizzly-serv
> let-webserver-1.9.18-i.jar grizzly-http-1.9.18-i.jar grizzly-framewor
> k-1.9.18-i.jar grizzly-utils-1.9.18-i.jar grizzly-rcm-1.9.18-i.jar gr
> izzly-portunif-1.9.18-i.jar grizzly-http-servlet-1.9.18-i.jar servlet
> -api-2.5.jar comm-3.0.jar
>
>
> Here is the resource in question (see below), any help is very
> welcomed,
> I'm clueless right now!
>
> /*
> * This class is part of the Energie Visible WebofThings project.
> * http://www.webofthings.com/energievisible/
> * (c) Dominique Guinard (www.guinard.org)
> * Institute for Pervasive Computing, ETH Zurich
> * and Cudrefin02.ch.
> */
> package com.webofthings.webplogg.web.resources;
>
> import com.webofthings.webplogg.meter.SmartMeter;
> import com.webofthings.webplogg.meter.ConsumptionData;
> import com.webofthings.webplogg.meter.SmartMeterManager;
> import com.webofthings.webplogg.meter.Status;
> import com.webofthings.webplogg.meter.config.Configurator;
> import com.webofthings.webplogg.meter.plogg.PloggManager;
> import java.net.URI;
> import java.util.ArrayList;
> import java.util.List;
> import javax.ws.rs.Consumes;
> import javax.ws.rs.GET;
> import javax.ws.rs.PUT;
> import javax.ws.rs.Path;
> import javax.ws.rs.PathParam;
> import javax.ws.rs.Produces;
> import javax.ws.rs.core.MediaType;
> import javax.ws.rs.core.UriBuilder;
>
> /**
> * This is the Smart Meter resource which is the first application
> related
> * resource clients will get to.
> * @author <a href="http://www.guinard.org">Dominique Guinard</a>
> */
> @Path("/smartmeters")
> @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON,
> MediaType.APPLICATION_ATOM_XML})
> public class SmartMeterResource {
>
> private static SmartMeterManager ploggMgr =
> PloggManager.getInstance();
>
> public SmartMeterResource() {
> }
>
>
> @GET
> public List<SmartMeter> getSmartMeters() {
> return new
> ArrayList(ploggMgr.getManagedSmartMeters().values());
> }
>
> /**
> * This produces an HTML representation of all the SmartMeters.
> I.e.
> * a list with links to the each SmartMeter.
> * @return The HTML representation of the list of SmartMeters.
> */
> @GET
> @Produces("text/html")
> public String getSmartMetersHTML() {
> StringBuilder htmlOut = new StringBuilder("<html><body>");
> for (SmartMeter currentSmartMeter :
> ploggMgr.getManagedSmartMeters().values()) {
>
> /* Build URLs to child-resources (SmartMeter) */
> UriBuilder builder =
> UriBuilder.fromPath("/smartmeters/{id}");
> int port = Integer.parseInt(Configurator.getInstance().
> getProperty("WEB_SERVER_PORT"));
> String host =
> Configurator.getInstance().getProperty("WEB_SERVER_HOST");
> builder.scheme("http").port(port).host(host);
> UriBuilder clone = builder.clone();
> URI uri = clone.build(currentSmartMeter.getId());
>
> htmlOut.append("<p>Name: " + currentSmartMeter.getName() +
> "</br>");
> htmlOut.append("ID: " + "<a href=\"");
> htmlOut.append(uri.toString());
> htmlOut.append("\">" + currentSmartMeter.getId() + "</a>");
> htmlOut.append("</p>");
> }
>
> htmlOut.append("</body></hmtl>");
> return htmlOut.toString();
> }
>
> @Path("/{smartMeterId}")
> @GET
> public ConsumptionData getMeterData(@PathParam("smartMeterId")
> String smartMeterId) {
> return ploggMgr.getDataFromMeter(smartMeterId);
> }
>
> /**
> * This produces an HTML representation of a given SmartMeter.
> * @return The HTML representation of the list of SmartMeters.
> */
> @Path("/{smartMeterId}")
> @GET
> @Produces("text/html")
> public String getMeterDataHTML(@PathParam("smartMeterId") String
> smartMeterId) {
> StringBuilder htmlOut = new StringBuilder("<html><body>");
> ConsumptionData cons = ploggMgr.getDataFromMeter(smartMeterId);
>
> /* Build URLs to child-resources (SmartMeter) */
> UriBuilder builder = UriBuilder.fromPath("/smartmeters/");
> int port = Integer.parseInt(Configurator.getInstance().
> getProperty("WEB_SERVER_PORT"));
> String host =
> Configurator.getInstance().getProperty("WEB_SERVER_HOST");
> builder.scheme("http").port(port).host(host);
> UriBuilder clone = builder.clone();
> URI uri = clone.build();
>
> htmlOut.append("<p>Watts: " + cons.getWatt() + "</p>");
> htmlOut.append("<p><a href=\"");
> htmlOut.append(uri.toString());
> htmlOut.append("\"></a>");
>
>
> htmlOut.append("</body></hmtl>");
> return htmlOut.toString();
> }
>
>
> @Path("/{smartMeterId}/status")
> @GET
> public Status getMeterStatus(@PathParam("smartMeterId") String
> smartMeterId) {
> return ploggMgr.getSmartMeter(smartMeterId).getStatus();
> }
>
> @Path("/{smartMeterId}/status")
> @PUT
> @Consumes("text/plain")
> public void setMeterStatus(@PathParam("smartMeterId") String
> smartMeterId, String message) {
> if (message.toLowerCase().equals("off")) {
> ploggMgr.turnOffPower(smartMeterId);
> } else {
> ploggMgr.turnOnPower(smartMeterId);
> }
>
> }
> }
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>