0
votes

I'm trying to integrate swagger in MYcommercewebservices. I read post and done all steps listed on it, but still having this error.

https://localhost:9002/mycommercewebservices/v2/v2/api-docs working fine. https://localhost:9002/mycommercewebservices/v2/swagger-ui.html - return UnknownResourceError.

Furthermore - if I navigate to https://localhost:9002/mycommercewebservices/swagger-ui.html (without 'v2') it'll show me this message (javascript alert):

Unable to infer base URL. This is common when using dynamic servlet registration or when the API is behind an API Gateway. The base URL is the root of where all the swagger resources are served. For e.g. if the API is available at http://example.org/api/v2/api-docs then the base URL is http://example.org/api/. Please enter the location manually:

I found this controller, and probably part of the problem was in it because it was throwing an exception when I navigated to https://localhost:9002/mycommercewebservices/v2/swagger-ui.html

@Controller
public class DefaultController
{
    @RequestMapping
    public void defaultRequest(final HttpServletRequest request)
    {
        throw new UnknownResourceException("There is no resource for path " + YSanitizer.sanitize(request.getRequestURI()));
    }
}

Now I disabled controller, but still having the same exception, but now it's in json format instead of .xml.

Thank you!

1
I'm not. But v2/v2 is the correct path for api-docs - one for services version and another for api-docs version(at least all sources on hybris help saying this). - Evgenii
so is api-docs available at localhost:9002/mycommercewebservices/v2/v2/api-docs ? - pvpkiran
yes, it is available. Hybris sees api urls and documentation, but UI(swagger-ui.html page) not working. - Evgenii

1 Answers

0
votes

The main problem was in DefaultController (in MYcommercewebservices)

@Controller
public class DefaultController
{
    @RequestMapping
    public void defaultRequest(final HttpServletRequest request)
    {
        throw new UnknownResourceException("There is no resource for path " + YSanitizer.sanitize(request.getRequestURI()));
    }
}

It was catching my request and throwing the exception.
When I disabled this controller, I continued to receive an exception, but now it was in json format(before it was in xml).

Than I added this to springmvc-v2-servlet.xml

<mvc:default-servlet-handler/>
<mvc:resources mapping="swagger-ui.html" location="classpath:/META-INF/resources/"/>
<mvc:resources mapping="/webjars/**" location="classpath:/META-INF/resources/webjars/"/>

Now UI works fine!

Also there were another manipulation before all this, but you can find them in hybris experts(quite big post).