Getting error 404 in deployed swagger project

8,957 views
Skip to first unread message

Ivan Sousa

unread,
Apr 22, 2016, 7:07:19 AM4/22/16
to Swagger
Hello, I'm new to developing REST Web Services and Swagger. I'm using JAX-RS/Jersey and Eclipse and I already managed to configure and deploy the project into the server(JBoss) but when I go to http://127.0.0.1:8080/PROJECT i get this:







When I press the ERROR this shows up: {"schemaValidationMessages":[{"level":"error","message":"Can't read from file http://127.0.0.1:8080/PROJECT/swaggerUI/swagger.json"}]}
And when I press "try this operation" I always get a error 404, i know i didn't change anything in the impl dir but it should give me the default response, or shouldn't?



Appreciate any help.

Ron Ratovsky

unread,
Apr 22, 2016, 8:34:20 AM4/22/16
to swagger-sw...@googlegroups.com
For the validation error – which version of swagger-ui do you use?

For the 404, it’s likely you didn’t set your basePath of your application.

--
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.
Message has been deleted

Ivan Sousa

unread,
Apr 22, 2016, 9:02:03 AM4/22/16
to Swagger
Hello Ron, I was using a older version of Swagger UI(2.4.1) but I just updated to 2.1.4 and I still get the ERROR, if I add 
validatorUrl : null,
to 
window.swaggerUi = new SwaggerUi
 the ERROR disappears but i on't know if it's the correct way...

About the 404, how do I change the basePath?

Ron Ratovsky

unread,
Apr 22, 2016, 9:09:07 AM4/22/16
to swagger-sw...@googlegroups.com
It’s the correct way, though should be disabled automatically for localhost.

How do you setup swagger-core in your app? The way to set the basePath depends on the method of initialization you use.

--

Ivan Sousa

unread,
Apr 22, 2016, 9:14:52 AM4/22/16
to Swagger
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggersocket+unsub...@googlegroups.com.

Ron Ratovsky

unread,
Apr 22, 2016, 9:24:42 AM4/22/16
to swagger-sw...@googlegroups.com
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.

Ivan Sousa

unread,
Apr 22, 2016, 9:27:42 AM4/22/16
to Swagger
The one using Jersey Container Servlet in web.xml.

Ron Ratovsky

unread,
Apr 22, 2016, 9:32:02 AM4/22/16
to swagger-sw...@googlegroups.com
If you mean https://github.com/swagger-api/swagger-core/wiki/Swagger-Core-Jersey-1.X-Project-Setup-1.5#using-swaggers-servlet-in-the-webxml you’ll see there’s a parameter there to set the basePath. Make sure that’s the context root of your application where you host your endpoints. That should solve the problem.


To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.

Ivan Sousa

unread,
Apr 22, 2016, 9:38:08 AM4/22/16
to Swagger
It is:
<init-param>
      <param-name>swagger.api.basepath</param-name>
      <param-value>/PROJECT/</param-value>
</init-param>
Should it be something else?

Ron Ratovsky

unread,
Apr 22, 2016, 9:42:01 AM4/22/16
to swagger-sw...@googlegroups.com
It doesn’t seem to be picked up.
Check the swagger.json you get (the one loaded into swagger-ui) and see what the basePath is set to in it, if at all.

I assume you’re not using any of the BeanConfig methods as well because if you do, that would explain the clobbering. 

To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.

Ivan Sousa

unread,
Apr 22, 2016, 9:52:36 AM4/22/16
to Swagger
So, i went to check the json and I had the basePath commented... Now the Requested URL is correct: http://127.0.0.1:8080/PROJECT/profile but it still returns the 404.

Ron Ratovsky

unread,
Apr 22, 2016, 9:54:28 AM4/22/16
to swagger-sw...@googlegroups.com
Can you share your entire web.xml?

To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.

Ivan Sousa

unread,
Apr 22, 2016, 9:57:09 AM4/22/16
to Swagger
<?xml version="1.0" encoding="ISO-8859-1"?>
  <servlet>
    <servlet-name>jersey</servlet-name>
    <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
    <init-param>
      <param-name>com.sun.jersey.config.property.packages</param-name>
      <param-value>io.swagger.jaxrs.json;io.swagger.jaxrs.listing;io.swagger.api</param-value>
    </init-param>
    <init-param>
      <param-name>com.sun.jersey.spi.container.ContainerRequestFilters</param-name>
      <param-value>com.sun.jersey.api.container.filter.PostReplaceFilter</param-value>
    </init-param>
    <init-param>
      <param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
      <param-value>true</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet>
    <servlet-name>DefaultJaxrsConfig</servlet-name>
    <servlet-class>io.swagger.jaxrs.config.DefaultJaxrsConfig</servlet-class>
    <init-param>
      <param-name>api.version</param-name>
      <param-value>1.0.0</param-value>
    </init-param>
    <init-param>
      <param-name>swagger.api.title</param-name>
      <param-value>Swagger Server</param-value>
    </init-param>
    <init-param>
      <param-name>swagger.api.basepath</param-name>
      <param-value>/PROJECT/</param-value>
    </init-param>
    <load-on-startup>2</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>jersey</servlet-name>
    <url-pattern>/jaxrs/*</url-pattern>
  </servlet-mapping>
  <filter>
    <filter-name>ApiOriginFilter</filter-name>
    <filter-class>io.swagger.api.ApiOriginFilter</filter-class>
  </filter>
  <filter-mapping>
    <filter-name>ApiOriginFilter</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
  </welcome-file-list>
</web-app>

Ron Ratovsky

unread,
Apr 22, 2016, 10:10:04 AM4/22/16
to swagger-sw...@googlegroups.com
It looks like your API is hosted under /jaxrs/ so try changing the basePath to that.

To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.

Ivan Sousa

unread,
Apr 22, 2016, 12:38:43 PM4/22/16
to Swagger
<init-param>
      <param-name>swagger.api.basepath</param-name>
      <param-value>/jaxrs/</param-value>
</init-param>
I changed to this and returns the same error.

Ivan Sousa

unread,
Apr 22, 2016, 1:26:20 PM4/22/16
to Swagger
By the way, in the editor http://editor.swagger.io/#/ i also get an error and can't see the result.

Ron Ratovsky

unread,
May 3, 2016, 3:18:34 PM5/3/16
to swagger-sw...@googlegroups.com
Hi Ivan,

Sorry for the delay. Did you manage to work this out?

To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.

Ivan Sousa

unread,
May 4, 2016, 5:17:36 AM5/4/16
to swagger-sw...@googlegroups.com
Hi Ron,

I managed to solve it, it was a problem that the jersey dependencies weren't being loaded by the server. Thanks for your help though.

--
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/kvEZqt-P6hM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to swagger-swaggers...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages