Marged
Marged

Reputation: 10953

Is it possible to remotely expose a bean in spring boot using REST and httpInvoker

I need to expose some service for remote use by Java clients (they shall use httpinvoker) and other languages (they shall use REST).

Can I configure spring boot to expose both ? (I would not mind if two separate instances with different ports would be used, like in this post).

I dumped the idea of providing an API for the Java clients that internally uses REST because it is rather tedious to wire all REST endpoints into the code manually using RestTemplate. I like the concept of HttpInvoker because a ProxyFactoryBean gets used automagically. If Spring Remoting would be able to do this in a way it can be done for JMS, AMQP and the others I would head this way.

Upvotes: 12

Views: 5486

Answers (6)

Dawid Krysiak
Dawid Krysiak

Reputation: 51

Spring HTTP Invoker is dangerous to be used in case when the trust of the caller can't be verified. It is deprecated from quite a long time and its support will be removed in Spring 6 so don't use it.

It's best to implement the communication as REST call and wrap it in easy to use method, like some other answers suggest, i.e. the Maleen Abewardana's one - https://stackoverflow.com/a/29840971/3673367.

References:

P.S. Yes, I know this question is very old and I'm sure OP doesn't need the answer anymore, but I write it with all the other future readers in mind, so that they don't use Spring HTTP Invoker nor any other RPC/RMI-like Spring features.

Upvotes: 3

George Georgovassilis
George Georgovassilis

Reputation: 135

Have a look at the spring-rest-invoker. It binds Java interfaces to REST services. This doesn't solve the problem of "exposing" the service, but makes it much easier to consume it.

https://github.com/ggeorgovassilis/spring-rest-invoker

Upvotes: 2

Michael Piefel
Michael Piefel

Reputation: 19968

Exposing HTTP invoker endpoints in Spring Boot is actually so easy that it looks as if something was missing. In a @SpringBootApplication that has spring-webmvc on its path (for instance using the spring-boot-starter-web POM), add the following bean definition:

@Bean(name = "/my.service")
public HttpInvokerServiceExporter myHttpInvokerServiceExporter(MyService myServiceImpl) {
    HttpInvokerServiceExporter exporter = new HttpInvokerServiceExporter();
    exporter.setServiceInterface(MyService.class);
    exporter.setService(myServiceImpl);
    return exporter;
}

The HTTP invoker endpoint is now exposed at /my.service and will not affect any other mappings. You can add as many such endpoint as you want; and then some @RequestMappings for REST on top.

Upvotes: 3

TJ H
TJ H

Reputation: 21

We use both techniques here. HttpInvoker for Java-to-Java invocations. Plain-old JSON over HTTP for other clients (similar to REST but not true REST). I think that the project jsonrpc4j provides a nice way to implement the HTTP stuff.

Upvotes: 2

Shawn Clark
Shawn Clark

Reputation: 3440

HttpInvoker was dropped after spring-integration 2.x: http://docs.spring.io/spring-integration/docs/2.0.x/reference/html/httpinvoker.html (!Important header gives details). There is a reference to HTTP Support in 3.x and 4.x versions: http://docs.spring.io/spring-integration/docs/latest-ga/reference/html/http.html

There is also another SO post with someone asking about HTTP support and spring boot with some relevant information: Spring Integration Http with Spring Boot and @RequestMapping

Hopefully this gets you part of the way out of the rabbit hole.

Upvotes: 0

Maleen Abewardana
Maleen Abewardana

Reputation: 14552

You can use something like this. Expose your services as a rest service. Then make your java clients to consume those services using http or some other library. If any other party is interested also, they can consume it in their own way too.

Else you can create your own jar consuming your rest services and let your java clients use that, without the knowledge about the rest service.

Upvotes: 3

Related Questions