Note that there are some explanatory texts on larger screens.

plurals
  1. POGrizzly Jersey swallowing exceptions
    primarykey
    data
    text
    <p>I'm building a Jersey Moxy service using the quickstart archetype at the end. My code works fine and I can get some JSON returned. However as I'm developing, if I make a mistake, say the request handler has an unsupported type, I will get an empty 500 response, which makes debugging difficult. For example, if I decorate an attribute incorrectly with @XmlElementRef, I will get a response like:</p> <pre><code>$ curl -i http://localhost:8080/myapp/test HTTP/1.1 500 Internal Server Error Date: Thu, 05 Sep 2013 10:27:55 GMT Connection: close Content-Length: 0 </code></pre> <p>The server will act as if nothing is wrong:</p> <pre><code>Sep 5, 2013 11:27:46 AM org.glassfish.grizzly.http.server.HttpServer start INFO: [HttpServer] Started. Jersey app started with WADL available at http://localhost:8080/application.wadl Hit enter to stop it... </code></pre> <p>I tried using a log config file with:</p> <pre><code>-Djava.util.logging.config.file=log.conf </code></pre> <p>This produces plenty of output, but still doesn't show any kind of exception.</p> <p>I've tried looking into Grizzly config but I can't find a way turn off graceful error handling. Ideally I would like the server to throw an exception. Any suggestions on what I'm missing?</p> <p>Here's my main code:</p> <pre><code>import org.glassfish.grizzly.http.server.HttpServer; import org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory; import org.glassfish.jersey.moxy.json.MoxyJsonConfig; import org.glassfish.jersey.server.ResourceConfig; import javax.ws.rs.ext.ContextResolver; import javax.ws.rs.ext.Provider; import java.io.IOException; import java.net.URI; import java.util.*; public class Main { // Base URI the Grizzly HTTP server will listen on public static final String BASE_URI = "http://localhost:8080/"; /** * Starts Grizzly HTTP server exposing JAX-RS resources defined in this application. * @return Grizzly HTTP server. */ public static HttpServer startServer() { // create a resource config that scans for JAX-RS resources and providers // in com.myapp package final ResourceConfig rc = new ResourceConfig().packages("com.myapp").registerInstances(new JsonMoxyConfigurationContextResolver()); // create and start a new instance of grizzly http server // exposing the Jersey application at BASE_URI return GrizzlyHttpServerFactory.createHttpServer(URI.create(BASE_URI), rc); } /** * Main method. * @param args * @throws IOException */ public static void main(String[] args) throws IOException { final HttpServer server = startServer(); System.out.println(String.format("Jersey app started with WADL available at " + "%sapplication.wadl\nHit enter to stop it...", BASE_URI)); System.in.read(); server.stop(); } @Provider final static class JsonMoxyConfigurationContextResolver implements ContextResolver&lt;MoxyJsonConfig&gt; { @Override public MoxyJsonConfig getContext(Class&lt;?&gt; objectType) { final MoxyJsonConfig configuration = new MoxyJsonConfig(); Map&lt;String, String&gt; namespacePrefixMapper = new HashMap&lt;String, String&gt;(1); namespacePrefixMapper.put("http://www.w3.org/2001/XMLSchema-instance", "xsi"); configuration.setNamespacePrefixMapper(namespacePrefixMapper); configuration.setNamespaceSeparator(':'); return configuration; } } } </code></pre> <p>The code is almost identical to the example here:</p> <p><a href="https://github.com/jersey/jersey/tree/2.2/examples/json-moxy/src/main/java/org/glassfish/jersey/examples/jsonmoxy" rel="noreferrer">https://github.com/jersey/jersey/tree/2.2/examples/json-moxy/src/main/java/org/glassfish/jersey/examples/jsonmoxy</a></p> <p>Full archetype generation I used:</p> <pre><code>mvn archetype:generate -DarchetypeArtifactId=jersey-quickstart-grizzly2 \ -DarchetypeGroupId=org.glassfish.jersey.archetypes -DinteractiveMode=false \ -DgroupId=com.myapp -DartifactId=yarese-service -Dpackage=com.myapp \ -DarchetypeVersion=2.2 </code></pre> <p>Suggestions gratefully received.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload