0

I generated JAX-RS server code for Uber API example in swagger. It is the default Json which can be found by opening http://editor.swagger.io/#/

Now I tried to deploy it in websphere but I see below message:

Error 404: javax.servlet.ServletException: java.io.FileNotFoundException: SRVE0190E: File not found: /v1/swagger.json

when I access this url: http://localhost:9080/swagger-jaxrs-server/v1/swagger.json

I didn't make any changes to auto generated code.

I am using wlp-javaee7-8.5.5.9

This is how my server.xml file looks like:

<server description="new server">

<!-- Enable features -->
<featureManager>
    <feature>javaee-7.0</feature>
    <feature>localConnector-1.0</feature>
    <feature>apiDiscovery-1.0</feature>
</featureManager>    

<basicRegistry id="basic" realm="BasicRealm"> 
    <!-- <user name="yourUserName" password="" />  --> 
</basicRegistry>

<!-- To access this server from a remote client add a host attribute to the following element, e.g. host="*" -->
<httpEndpoint httpPort="9080" httpsPort="9443" id="defaultHttpEndpoint"/>

<!-- Automatically expand WAR files and EAR files -->
<applicationManager autoExpand="true"/>

<applicationMonitor updateTrigger="mbean"/>

<webApplication id="swagger-jaxrs-server" location="swagger-jaxrs-server.war" name="swagger-jaxrs-server"/>

Can someone point what is missing here.

UPDATE:1

This URL is working fine: http://localhost:8080/swagger-jaxrs-server/swagger.json. This is the part of Json :

enter image description here

So, I tried the below two urls.. but both didn't work.

http://localhost:8080/swagger-jaxrs-server/estimates/price
http://localhost:8080/swagger-jaxrs-server/v1/estimates/price

I don't see web.xml with autogenerated code.

javaMan
  • 6,352
  • 20
  • 67
  • 94

1 Answers1

2

This path would almost work: http://localhost:9080/swagger-jaxrs-server/swagger.json for serving the json file (where swagger-jaxrs-server is the implied context root), though it overlaps with the @ApplicationPath("/") in the generated war. BUT...

The issue is with the context root.

The swagger.json has "basePath" : "/v1", but doesn't include anything in the generated classes to change that base path to include the v1, and servlet containers are somewhat limited in how they allocate context roots.

I would suggest tweaking the generated RestApplication so it has @ApplicationPath("/v1"), in which case http://localhost:9080/swagger-jaxrs-server/swagger.json would work to retrieve the json, and http://localhost:9080/swagger-jaxrs-server/v1/products would match the expected REST endpoints.

ebullient
  • 1,250
  • 7
  • 16
  • where should I add this @ApplicationPath("/v1"). I don't see any class that is extending Application Class. Should I create new class? Please take a look at update section in my question. – javaMan Sep 13 '16 at 03:59
  • 1
    In the generated code, src/main/java/io/swagger/api/RestApplication.java if you generated using the "Jaxrs spec" flavor, which relies the most on the underlying container to do the work with the fewest assumptions about what that container is (the JAX-RS generator uses Jersey, which does not always port well between app servers) – ebullient Sep 13 '16 at 04:17
  • Earlier I used JAX-RS generator. After your suggestion I used Jaxrs spec and everything worked fine. Wondering what is the difference between those two generators. – javaMan Sep 13 '16 at 04:32
  • I was going to ask which generator you used first. ;) as I said, the JAX-RS generator relies on Jersey, IIRC. There is one that uses cxf, and another for RESTEasy. Should be easy enough to compare what was generated... – ebullient Sep 13 '16 at 04:53