Swagger not working after packaged into uber jar

49 views
Skip to first unread message

Hansen

unread,
Oct 14, 2015, 11:44:27 AM10/14/15
to Swagger

I have a Jersey application running in an embedded Grizzly with Swagger hooked into it. Swagger works fine when I run the application from Eclipse. The URL http://localhost:8080/myapp/api-docs returns the expected JSON response

{
"apiVersion": "1.0.0",
"swaggerVersion": "1.2",
"apis": [
    {
        "path": "/myresource",
        "description": "Hello my resource description"
    }
]}

However, after packaging the application into a single jar and running the resultant jar, Swagger stops working. Accessing the same URL http://localhost:8080/myapp/api-docs now returns HTTP status of 500. The application itself works fine - I can fire request to the web services.

Here is my pom.xml I use to package the application.


<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

    <modelVersion>4.0.0</modelVersion>

    <groupId>com.example</groupId>
    <artifactId>simple-service</artifactId>
    <packaging>jar</packaging>
    <version>1.0-SNAPSHOT</version>
    <name>simple-service</name>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.glassfish.jersey</groupId>
                <artifactId>jersey-bom</artifactId>
                <version>${jersey.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependencies>
        <dependency>
            <groupId>org.glassfish.jersey.containers</groupId>
            <artifactId>jersey-container-grizzly2-http</artifactId>
        </dependency>
        <dependency>
            <groupId>org.glassfish.jersey.media</groupId>
            <artifactId>jersey-media-moxy</artifactId>
        </dependency>
        <dependency>
            <groupId>com.wordnik</groupId>
            <artifactId>swagger-jersey2-jaxrs_2.10</artifactId>
            <version>1.3.12</version>
        </dependency>
        <dependency>
          <groupId>ch.qos.logback</groupId>
          <artifactId>logback-classic</artifactId>
          <version>1.0.1</version>
          <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.9</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.5.1</version>
                <inherited>true</inherited>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>1.6</version>
                <configuration>
                    <createDependencyReducedPom>true</createDependencyReducedPom>
                    <filters>
                        <filter>
                            <artifact>*:*</artifact>
                            <excludes>
                                <exclude>META-INF/*.SF</exclude>
                                <exclude>META-INF/*.DSA</exclude>
                                <exclude>META-INF/*.RSA</exclude>
                            </excludes>
                        </filter>
                    </filters>
                </configuration>

                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <transformers>
                                <transformer
                                    implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
                                <transformer
                                    implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                    <manifestEntries>
                                        <Main-Class>com.example.Main</Main-Class>
                                    </manifestEntries>
                                </transformer>
                            </transformers>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>1.2.1</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>java</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <mainClass>com.example.Main</mainClass>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <properties>
        <jersey.version>2.22.1</jersey.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
</project>

Ron Ratovsky

unread,
Oct 14, 2015, 12:11:55 PM10/14/15
to Swagger
Do you see anything in the logs? You should see something if you're getting a 500 error.

--
You received this message because you are subscribed to the Google Groups "Swagger" group.
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
-----------------------------------------
http://swagger.io
https://twitter.com/SwaggerApi
-----------------------------------------

Hansen Candrawinata

unread,
Oct 14, 2015, 6:23:29 PM10/14/15
to swagger-sw...@googlegroups.com
Hi Ron,

There's nothing in the log file, unfortunately.  It just seems the path api-docs/ isn't reachable and that's why, it returns 500.

If it's any useful, the stacks I'm using: Grizzly, Jersey, Maven - all packaged into a single executable jar.


--
You received this message because you are subscribed to a topic in the Google Groups "Swagger" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/swagger-swaggersocket/k7iLll_dq9U/unsubscribe.
To unsubscribe from this group and all its topics, send an email to swagger-swaggers...@googlegroups.com.

Ron Ratovsky

unread,
Oct 14, 2015, 6:38:51 PM10/14/15
to Swagger

500 is an internal server error so it should supply a log error, unlike 404 which suggests the path isn't found. Without an error it would be very difficult to figure out the issue.

Is there any way you can share the app?

Hansen Candrawinata

unread,
Oct 15, 2015, 2:55:59 AM10/15/15
to swagger-sw...@googlegroups.com
Hi Ron,

This is a Jersey app I forked out from https://github.com/riteshmodi/JerseySwagger/tree/master/src/main/webapp.  I'll see if I can easily share the app by deleting all the proprietary information.

The log messages are output to stdout.  Here is what I could find when it tries to load api-docs/.  Does it mean anything to you?

17:46:35.639 [Grizzly-worker(2)] DEBUG c.w.s.j.listing.ApiListingCache$ - loading cache
17:46:39.181 [Grizzly-worker(2)] DEBUG c.w.swagger.jaxrs.JaxrsApiReader - checking for implicits
17:46:39.182 [Grizzly-worker(2)] DEBUG c.w.s.converter.ModelPropertyParser - processing class class com.example.jersey2.grizzly2.swagger.demo.MyResource
17:46:39.182 [Grizzly-worker(2)] DEBUG c.w.s.converter.ModelPropertyParser - processing method public java.lang.String com.example.jersey2.grizzly2.swagger.demo.MyResource.getIt()
17:46:39.182 [Grizzly-worker(2)] DEBUG c.w.s.converter.ModelPropertyParser - validating datatype java.lang.String against 12 keys, got java.lang.String
17:46:39.182 [Grizzly-worker(2)] DEBUG c.w.s.converter.ModelPropertyParser - inspecting java.lang.String
17:46:39.182 [Grizzly-worker(2)] DEBUG c.w.s.converter.ModelPropertyParser - validating datatype String against 12 keys, got string
17:46:39.182 [Grizzly-worker(2)] DEBUG c.w.s.converter.ModelPropertyParser - validating datatype string against 12 keys, got string
17:46:39.182 [Grizzly-worker(2)] DEBUG c.w.s.converter.ModelPropertyParser - added param type java.lang.String for field it
17:46:39.183 [Grizzly-worker(2)] DEBUG c.w.s.converter.ModelPropertyParser - processing class class java.lang.Object
17:46:39.183 [Grizzly-worker(2)] DEBUG c.w.s.converter.ModelPropertyParser - processing method public final void java.lang.Object.wait() throws java.lang.InterruptedException
17:46:39.183 [Grizzly-worker(2)] DEBUG c.w.s.converter.ModelPropertyParser - processing method public java.lang.String java.lang.Object.toString()
17:46:39.183 [Grizzly-worker(2)] DEBUG c.w.s.converter.ModelPropertyParser - processing method public native int java.lang.Object.hashCode()
17:46:39.183 [Grizzly-worker(2)] DEBUG c.w.s.converter.ModelPropertyParser - processing method public final native java.lang.Class java.lang.Object.getClass()
17:46:39.184 [Grizzly-worker(2)] DEBUG c.w.s.converter.ModelPropertyParser - inspecting null
17:46:39.184 [Grizzly-worker(2)] DEBUG c.w.s.converter.ModelPropertyParser - skipping class
17:46:39.184 [Grizzly-worker(2)] DEBUG c.w.s.converter.ModelPropertyParser - processing method public final native void java.lang.Object.notify()
17:46:39.184 [Grizzly-worker(2)] DEBUG c.w.s.converter.ModelPropertyParser - processing method public final native void java.lang.Object.notifyAll()
17:46:39.185 [Grizzly-worker(2)] DEBUG c.w.s.converter.ModelPropertyParser - processing class class com.example.jersey2.grizzly2.swagger.demo.MyResource
17:46:39.185 [Grizzly-worker(2)] DEBUG c.w.s.converter.ModelPropertyParser - processing method public java.lang.String com.example.jersey2.grizzly2.swagger.demo.MyResource.getIt()
17:46:39.186 [Grizzly-worker(2)] DEBUG c.w.s.converter.ModelPropertyParser - validating datatype java.lang.String against 12 keys, got java.lang.String
17:46:39.186 [Grizzly-worker(2)] DEBUG c.w.s.converter.ModelPropertyParser - inspecting java.lang.String
17:46:39.186 [Grizzly-worker(2)] DEBUG c.w.s.converter.ModelPropertyParser - validating datatype String against 12 keys, got string
17:46:39.186 [Grizzly-worker(2)] DEBUG c.w.s.converter.ModelPropertyParser - validating datatype string against 12 keys, got string
17:46:39.186 [Grizzly-worker(2)] DEBUG c.w.s.converter.ModelPropertyParser - added param type java.lang.String for field it
17:46:39.186 [Grizzly-worker(2)] DEBUG c.w.s.converter.ModelPropertyParser - processing class class java.lang.Object
17:46:39.186 [Grizzly-worker(2)] DEBUG c.w.s.converter.ModelPropertyParser - processing method public final void java.lang.Object.wait() throws java.lang.InterruptedException
17:46:39.186 [Grizzly-worker(2)] DEBUG c.w.s.converter.ModelPropertyParser - processing method public java.lang.String java.lang.Object.toString()
17:46:39.187 [Grizzly-worker(2)] DEBUG c.w.s.converter.ModelPropertyParser - processing method public native int java.lang.Object.hashCode()
17:46:39.187 [Grizzly-worker(2)] DEBUG c.w.s.converter.ModelPropertyParser - processing method public final native java.lang.Class java.lang.Object.getClass()
17:46:39.187 [Grizzly-worker(2)] DEBUG c.w.s.converter.ModelPropertyParser - inspecting null
17:46:39.187 [Grizzly-worker(2)] DEBUG c.w.s.converter.ModelPropertyParser - skipping class
17:46:39.187 [Grizzly-worker(2)] DEBUG c.w.s.converter.ModelPropertyParser - processing method public final native void java.lang.Object.notify()
17:46:39.188 [Grizzly-worker(2)] DEBUG c.w.s.converter.ModelPropertyParser - processing method public final native void java.lang.Object.notifyAll()



 

Hansen Candrawinata

unread,
Oct 15, 2015, 2:58:31 AM10/15/15
to swagger-sw...@googlegroups.com
Sorry, that's the wrong URL.  Here is the correct one:

https://github.com/SingleMalt/jersey2-grizzly2-swagger-demo

Thanks.

Hansen Candrawinata

unread,
Oct 15, 2015, 3:08:23 AM10/15/15
to swagger-sw...@googlegroups.com
Inside the ZIP file, you'll find the Maven project and the jar file, which can be run with

    java -jar simple-service-1.0-SNAPSHOT.jar

The app can be accessed at http://localhost:8080/myapp/myresources.

The Swagger's http://localhost:8080/myapp/api-docs is returning 500.  But, if you run the Main.java in the project from Eclipse or command line, it works fine.

Reply all
Reply to author
Forward
0 new messages