Rest controllers not working after upgrade to 6.3.2 from 6.2

I built an angular 2 application that was communicating through a custom rest api. I modified portal-security-spring.xml to remove security from the endpoints. I was able to add/update/delete and find data. Since upgrading I receive 404 errors while trying to access my end points.

I’ve attached my web.xml and portal-security-spring.xml and other in hopes that it’ll help you figure out what broke during the upgrade.

I followed the documentation on how to use the REST API 2.
The instructions requested me to create a file call rest-dispatcher-spring.xml. I added this to the local-app.properties within the web-inf folder of app-portal. How do I know if the rest-dispatcher-spring.xml gets loaded correctly?
Can you please help me? Do you guys have a migration guide, or a good sample project that would help me identify why this worked in 6.2 but doesn’t now?

web.xml (4.5K)

rest-dispatcher-spring.xml (1.5K)

portal-dispatcher-spring.xml (1.5K)

portal-security-spring.xml (3.4K)

portal-spring.xml (3.4K)

Hi Kent,

Did you change your controllers mapping when you migrated to 6.3 or their URLs started with /rest when your project was on CUBA 6.2?

I’m asking this because since v6.3 there are two dispatcher servlets. If you take a look at the web.xml you will find that requests with the /rest/* pattern are processed by the CubaRestApiServlet and other requests by the CubaDispatcherServlet. Different servlets mean different Spring contexts - so your issues may be because of that.

I created a demo project that has examples of 3 different REST controllers. You can find it here: https://github.com/gorbunkov/sample-rest-controllers

If it doesn’t solve your problem, let us now - we will continue an investigation.

Where are you telling it to load up the rest-dispatcher-spring.xml file?

I went through your example and modified my project to match. I’m still getting this error when trying to access any of my endpoints.


<!DOCTYPE html>
<html>
    <head>
        <title>Apache Tomcat/8.0.35 - Error report</title>
        <style type="text/css">H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}.line {height: 1px; background-color: #525D76; border: none;}</style>
    </head>
    <body>
        <h1>HTTP Status 500 - No WebApplicationContext found: no ContextLoaderListener or DispatcherServlet registered?</h1>
        <div class="line"></div>
        <p>
            <b>type</b> Exception report
        </p>
        <p>
            <b>message</b>
            <u>No WebApplicationContext found: no ContextLoaderListener or DispatcherServlet registered?</u>
        </p>
        <p>
            <b>description</b>
            <u>The server encountered an internal error that prevented it from fulfilling this request.</u>
        </p>
        <p>
            <b>exception</b>
        </p>
        <pre>java.lang.IllegalStateException: No WebApplicationContext found: no ContextLoaderListener or DispatcherServlet registered?
	org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:252)
</pre>
        <p>
            <b>note</b>
            <u>The full stack trace of the root cause is available in the Apache Tomcat/8.0.35 logs.</u>
        </p>
        <hr class="line">
        <h3>Apache Tomcat/8.0.35</h3>
    </body>
</html>

In the CubaRestApiServlet.getContextConfigLocation() method the value of the cuba.restSpringContextConfig property is processed. The rest-dispatcher-spring.xml must be specified in this property

There was an error in the web.xml template for portal module.

portal servlet definition there looked like this:


    <servlet>
        <servlet-name>portal</servlet-name>
        <servlet-class>com.haulmont.cuba.portal.sys.PortalDispatcherServlet</servlet-class>
        <init-param>
            <param-name>load-on-startup</param-name>
            <param-value>1</param-value>
        </init-param>
    </servlet>

but it must be:


    <servlet>
        <servlet-name>portal</servlet-name>
        <servlet-class>com.haulmont.cuba.portal.sys.PortalDispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

Try to change your web.xml. The template fix will appear in Studio 6.3.1

Yes, I changed that earlier and it made a difference. Thank you, I should have posted that I found a solution.