Search code examples
javajakarta-eewebsphereswaggerwebsphere-liberty

How to deploy Swagger generated JAXRS server code in Websphere


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.


Solution

  • 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.