springrestspring-mvcgwtresty-gwt

RestyGWT- custom url mapping for spring rest service


I have problem that my Spring Rest Controllers is mapped other way than RestyGWT would like. My application is on: http://localhost:8080/restgwt/

According to web.xml:

<servlet>
    <servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/classes/action-servlet.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
    <url-pattern>/service/*</url-pattern>
</servlet-mapping>

My Spring service/controller listen on: http://localhost:8080/restgwt/service/test

But my RestyGWT service calls this url: http://localhost:8080/restgwt/restgwt/test

And I don't know how to tell to RestyGWT to change url. Please help.

I know that the simplest solution would be changing in web.xml file servlet url-pattern parameter

from: <url-pattern>/service/*</url-pattern>

to: <url-pattern>/restgwt/*</url-pattern>

but I would like to make RestyGWT to change it's behaviour.


Here paste some additional code:

TestService on GWT side

package pl.korbeldaniel.restgwt.client;

import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;

import org.fusesource.restygwt.client.MethodCallback;
import org.fusesource.restygwt.client.RestService;

public interface TestService extends RestService {
    @GET
    @Path("test")
    public void getInfo(MethodCallback<TestPojo> test);
}

TestService on Spring side

package pl.korbeldaniel.restgwt.server;

import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

@RestController()
public class TestService {
    @RequestMapping(value = "test", method = RequestMethod.GET)
    public @ResponseBody TestEntity getInfo() {
        TestEntity test = new TestEntity();
        System.out.println("Hit server for getting _1");
        return new TestEntity();
    }
}

Solution

  • Reffering to the official documentation:

    Configuring service root URLs There are two ways to configure service root URLs which are appended with the @Path annotation property when building the final service URL. For single service root URL the Defaults.setServiceRoot(String) method can be used. When several services with different service roots are used the @Options annotation is equipped with the serviceRootKey property which can be set to read service root entries provided with the static ServiceRoots.add(String, String) method.

    Defaults.setServiceRoot(new Resource( GWT.getModuleBaseURL()).resolve("../rest").getUri());
    

    So my REST path for RestyGWT becomes http://domain-name/myGwtAppModuleName/rest/furtherPath where furtherPath is javax.ws.rs @Path(..) value Putting the line directly in GIN ClientModule failed with java.lang.UnsatisfiedLinkError: com.google.gwt.core.client.impl.Impl.getModuleBaseURL()Ljava/lang/String To avoid error this I've wrapped it up

        public class ClientModule extends AbstractPresenterModule {
            @Override
            protected void configure(){
               //your installs and binds here
               bind(RestyGwtConfig.class).asEagerSingleton();
            }
        }
    
        public class RestyGwtConfig {
        static {
        Defaults
    .setServiceRoot(new Resource( GWT.getModuleBaseURL()).resolve("../rest").getUri());
        }
        }