Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RemoteExporter in SpringBoot 3.0.0 #303

Open
b-artur opened this issue Dec 11, 2022 · 4 comments
Open

RemoteExporter in SpringBoot 3.0.0 #303

b-artur opened this issue Dec 11, 2022 · 4 comments

Comments

@b-artur
Copy link

b-artur commented Dec 11, 2022

Unfortunately application with jsonrpc4j fails on run in a new release of SpringBoot 3.0.0

ERROR 22396 --- [           main] o.s.boot.SpringApplication               : Application run failed

java.lang.NoClassDefFoundError: org/springframework/remoting/support/RemoteExporter
@cyb3r4nt
Copy link
Contributor

New major Spring Framework version 6 has removed the RemoteExporter class and RPC-style remoting:

spring-projects/spring-framework#25379 (comment)
spring-projects/spring-framework#27422

It is still possible to use this library without Spring integration and by creating the JsonRpcHttpClient and JsonRpcServer objects manually,
and propagating them as beans to application context.
https://github.com/briandilley/jsonrpc4j#without-the-spring-framework

Then you can use the library to create and handle requests.
To use JsonRpcServer you may create explicit Spring MVC controllers,
and redirect request handling to jsonrpc4j

@Controller
class SZv2JsonRpcController {

    private final JsonRpcServer myJsonRpcServer;

    SZv2JsonRpcController(JsonRpcServer myJsonRpcServer) {
        this.myJsonRpcServer = myJsonRpcServer;
    }

    @PostMapping(path = "/api")
    public void handleMyRequest(
        jakarta.servlet.http.HttpServletRequest req,
        jakarta.servlet.http.HttpServletResponse resp
    ) throws IOException {
        this.myJsonRpcServer.handle(
            new Jakarta2JavaxHttpServletRequestAdapter(req),
            new Jakarta2JavaxHttpServletResponseAdapter(resp)
        );
    }
}

The used API is https://github.com/briandilley/jsonrpc4j/blob/master/src/main/java/com/googlecode/jsonrpc4j/JsonRpcServer.java#L107-L140
There is one more obstacle because of javax -> jakarta namespace migration in the newer Spring Framework,
and you will need to create some adapter classes.

But this is a working solution you can use until better solution is introduced into jsonrpc4j

@nixel2007
Copy link

@cyb3r4nt maybe you have a complete example for spring boot 6?

@cyb3r4nt
Copy link
Contributor

cyb3r4nt commented Mar 1, 2023

@cyb3r4nt maybe you have a complete example for spring boot 6?

The example provided above works with Spring Framework 6.
The only thing is that it does not use the Spring integration from jsonrpc4j,
and you need to define required controllers manually and route requests to proper JsonRpcServer.
It is possible to register required beans in the application context ,
and define JsonRpcServer implementation beans and corresponding Spring MVC controllers.
Such routing requires some more wiring code, but it may solve current problems.

Spring Framework 6 integration in jsonrpc4j is broken at the moment, because when you use it,
then you will get NoClassDefFoundError because RemoteExporter is no more in the classpath.
@JsonRpcService and @AutoJsonRpcServiceImpl auto-discovery annotations cannot be used because of RemoteExporter usage in the AbstractJsonServiceExporter.

(PS Spring Boot and Spring Framework are different projects, and they have different versioning. Please do not mix them)

@cyb3r4nt
Copy link
Contributor

cyb3r4nt commented Mar 1, 2023

Also, just checked the RemoteExporter usage and how beans are registered in the AutoJsonRpcServiceImplExporter.
At very first look it seems that RemoteExporter is used only because of serviceInterface , service and proxyForService class properties,
and uses them only to get the request handler object when creating JsonRpcServer instance.

Otherwise, all created JsonRpcServer instances are registered in the Spring IoC container using bean-name-as-web-path scheme (see BeanNameUrlHandlerMapping for more details) and this is more or less standard way how Spring Web works.
It also seems that org.springframework.remoting is not really used and there are no any RPC-like registrations.

Those properties used in AutoJsonRpcServiceImplExporter may be pulled down from the RemoteExporter and this inheritance may be removed/discarded.

Will try to develop and provide some patches in spare time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants