12

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.

Community
  • 1
  • 1
Marged
  • 10,577
  • 10
  • 57
  • 99
  • You're mixing probably two idioms: RPC and state transfer. httpInvoker is about remote procedure calls. You call simply a method, pass in some arguments and get some sort of result. In REST you're dealing pretty much with changing a particular state of something (it's basically the REST idea). I guess, the best solution for such a case would be having two different facades in front of your service which follow the principles of each API style. – mp911de Apr 23 '15 at 21:08
  • I think both techniques allow to change the state. In REST it is a http GET, with httpInvoker you call a getMethod. For modifying/creating values REST uses PUT/POST and httpInvoker calls set/create. But when you are talking about the two facades this is where it get's interesting: how can this be done in an elegant way ? – Marged Apr 24 '15 at 19:43
  • @Marged why would you want to use a deprecated tool like Spring's HttpInvoker? It was already deprecated in Spring 2.0, I don't think Spring Boot will autoconfigure that or even manage the dependency. – Michael Técourt Apr 27 '15 at 14:45
  • I did not yet check support for httpinvoker in spring boot, so missing support from boot might become an issue. Do you have a source for the deprecation of httpinvoker ? I know its support was changed in spring integration but I consider it as actively supported even in current versions of spring – Marged Apr 27 '15 at 19:04
  • Cant you configure your bean as a usual Rest service and expose it using httpinvoker? HttpInvoker configuration is pretty simple and you could do it by yourself without SpringBoot – Plínio Pantaleão Apr 29 '15 at 14:24

6 Answers6

3

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.

Maleen Abewardana
  • 13,600
  • 4
  • 36
  • 39
  • Creating a jar that calls the REST interface is the approach I dumped. I seek an easy approach where the biggest part gets created automatically. This works for httpinvoker and REST when I use each technique isolatedly. – Marged Apr 24 '15 at 08:28
3

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.

Michael Piefel
  • 18,660
  • 9
  • 81
  • 112
2

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.

TJ H
  • 21
  • 1
2

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

2

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.

0

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.

Community
  • 1
  • 1
Shawn Clark
  • 3,330
  • 2
  • 18
  • 30
  • 1
    Perhaps I am misinterpreting this but just because Spring _Integration_ drops support for the HttpInvoker it does not meen that Sprint itself dropped or deprecated it. Because I am not using Spring Integration I should not run into problems. – Marged Apr 30 '15 at 20:36
  • Yes... you are correct. http://docs.spring.io/spring/docs/current/spring-framework-reference/html/remoting.html – Shawn Clark Apr 30 '15 at 21:36