简体   繁体   English

轻量级Java Web服务

[英]Light Weight Java Web Services

I have Java EE applications (ear) running on separate JBoss instances and on different hardware. 我有Java EE应用程序(耳)在单独的JBoss实例和不同的硬件上运行。 I want to call from 我想打给

  1. one application to another which is in another server JBOSS. 一个应用程序到另一个在另一个服务器JBOSS中的应用程序。
  2. Same JBOSS, between two ear. 同一JBOSS,在两只耳朵之间。
  3. Same Server, between two JBOss. 同一服务器,在两个JBO之间。

The communication data types can be any type. 通信数据类型可以是任何类型。 For instance; 例如; JSON or Objects. JSON或对象。 I want to know what lightweight, Open source Java web frameworks I can use to call from one to another? 我想知道我可以使用哪种轻量级的开源Java Web框架来调用? Here some of them. 这里有一些。 But I don't have any experience from them. 但是我没有任何经验。 Commonly, SOAP and RESTful services are used and there are many implementation frameworks of them. 通常,使用SOAP和RESTful服务,并且它们有许多实现框架。

Please suggest me know from your experience what are the available frameworks which suit for my requirement? 请根据您的经验告诉我,哪些是适合我要求的可用框架? Let me have source which explain any comparison. 让我有解释任何比较的资料。 My concerns are that, the communication methodology should be light weight, should support to transfer any type of data, there should not be much configurations, or standards. 我担心的是,通信方法应该轻巧,应该支持传输任何类型的数据,应该没有太多的配置或标准。 The framework should support to transfer simply (all communications are done in my applications. so no need well structured, standardized weight configurations) and securely. 该框架应支持简单安全地传输(所有通信都在我的应用程序中完成,因此不需要结构合理,标准化的权重配置)。 and it should be in Java. 它应该是Java语言。 I use Java 7. 我使用Java 7。

From my understanding of your situation, I think ESB would be a good solution for your problem. 从我对您的情况的了解来看,我认为ESB将是解决您的问题的好方法。

http://en.wikipedia.org/wiki/Enterprise_service_bus http://en.wikipedia.org/wiki/Enterprise_service_bus

The one from WSO2 is a pretty light-weight open-source ESB and has a good active community. WSO2的一个是相当轻量级的开源ESB,并且拥有一个活跃的社区。 http://wso2.com/products/enterprise-service-bus/ http://wso2.com/products/enterprise-service-bus/

This is a typical integration problem. 这是一个典型的集成问题。 For integrating, mediating, proxying etc. different services and even transferring data, use Apache Camel . 为了集成,中介,代理等不同的服务,甚至传输数据,请使用Apache Camel For a short answer what Camel is, see What exactly is Apache Camel? 有关Camel是什么的简短回答,请参阅Apache Camel到底是什么?

In Camel you define routes using a Java DSL or a XML Spring DSL. 在Camel中,您可以使用Java DSL或XML Spring DSL定义路由。 Proxying a web service is described here . 这里描述代理Web服务。 Using the XML Spring DSL, the route would look as follows: 使用XML Spring DSL,路由如下所示:

<route>
    <from uri="jetty:http://0.0.0.0:8080/myapp?matchOnUriPrefix=true"/>
    <to uri="jetty:http://realserverhostname:8090/myapp?bridgeEndpoint=true&amp;throwExceptionOnFailure=false"/>
</route>

Using the Java DSL, this would become: 使用Java DSL,它将变成:

from("jetty:http://0.0.0.0:8080/myapp?matchOnUriPrefix=true"
    .to("jetty:http://realserverhostname:8090/myapp?bridgeEndpoint=true&amp;throwExceptionOnFailure=false")

There are many different protocols that are supported by Camel such as JSM, SOAP WS, RESTful WS, plain HTTP, TCP. Camel支持许多不同的协议,例如JSM,SOAP WS,RESTful WS,纯HTTP,TCP。 Have a look at https://camel.apache.org/components.html for all possibilities. 查看所有可能的https://camel.apache.org/components.html

The next example shows you how easy it is to define a RESTful server using the Restlet component : 下一个示例向您展示使用Restlet组件定义RESTful服务器是多么容易:

from("restlet:http://localhost:8400/orders/{id}?restletMethod=post")
    .process(new Processor() {
        @Override
        public void process(final Exchange exchange) throws Exception {
            final String res = "received [" + exchange.getIn().getBody(String.class) + "] with order id = " + exchange.getIn().getHeader("id");
            exchange.getIn().setBody(res);
        }
   });

The corresponding client looks as follows: 相应的客户端如下所示:

 from("direct:start")
     .setBody(constant("Hello, world!!"))
     .to("http://localhost:8400/orders/22?restletMethod=post")
     .log("order: direct start body result = ${bodyAs(String)}")

That said, Camel supports a plentitude of enterprise integration patterns such as splitter, aggregator etc. that can be used for your needs. 也就是说,Camel支持多种企业集成模式,例如拆分器,聚合器等,可用于您的需求。 Have a look at http://camel.apache.org/enterprise-integration-patterns.html for more information about that. 有关更多信息,请访问http://camel.apache.org/enterprise-integration-patterns.html

You can just use "normal" Java classes for transforming data and hook them into the routes. 您可以只使用“普通” Java类来转换数据并将它们挂接到路由中。 Beside that there are many integrated type converter for transforming one data type to another. 除此之外,还有许多用于将一种数据类型转换为另一种数据的集成类型转换器。 These converters can easily be extended. 这些转换器可以轻松扩展。 See https://camel.apache.org/type-converter.html . 参见https://camel.apache.org/type-converter.html

You could use Camel as your base integration framework and add eg JMS/ActiveMQ for the communication. 您可以使用Camel作为基础集成框架,并添加例如JMS / ActiveMQ进行通信。 However, it is also possible to use ActiveMQ as your base and add Camel for transforming the data, see https://activemq.apache.org/broker-camel-component.html : "The broker camel component makes this even easier - which intercepts messages as they move through the broker itself, allowing them to be modified and manipulated before they are persisted to the message store or delivered to end consumers." 但是,也可以使用ActiveMQ作为基础并添加Camel来转换数据,请参见https://activemq.apache.org/broker-camel-component.html :“代理骆驼组件使此操作变得更加容易-当消息在代理程序中移动时,它们会截获消息,从而可以在将消息持久化到消息存储库或传递给最终用户之前对其进行修改和处理。” However, I prefer to use Camel as the base and add JMS/ActiveMQ for the asynchronous communication (eg if message persistence is needed or if the communication has to occur between different hosts). 但是,我更喜欢使用Camel作为基础,并为异步通信添加JMS / ActiveMQ(例如,如果需要消息持久性,或者如果通信必须在不同主机之间进行)。

Camel supports a huge amount of different protocols and formats. 骆驼支持大量不同的协议和格式。 However, you don't have to use them, if you don't need them. 但是,如果不需要它们,则不必使用它们。 Just add the dependencies to your pom.xml if you need them. 如果需要,只需将依赖项添加到pom.xml Apache Camel is a small library (11.2 MB) with minimal dependencies for easy embedding in any Java application. Apache Camel是一个小型库(11.2 MB),具有最小的依赖关系,可轻松嵌入任何Java应用程序中。 Camel runs standalone, in a Servlet engine, or in an OSGI container such as Karaf/ServiceMix/JBoss Fuse ESB. Camel可在Servlet引擎中或在OSGI容器(如Karaf / ServiceMix / JBoss Fuse ESB)中独立运行。 You can start small and the application can grow, if your needs are growing. 如果您的需求不断增长,则可以从小处着手,应用程序可以成长。

For starting using Camel, read the excellent book by Claus Ibsen: http://www.manning.com/ibsen/ . 要开始使用Camel,请阅读Claus Ibsen的出色著作: http : //www.manning.com/ibsen/

you could use jax-ws to provide the webservices from your JBoss and call them using javax.xml.soap. 您可以使用jax-ws从JBoss提供Web服务,并使用javax.xml.soap对其进行调用。 What i dont know is if its possible to send object data, maybe you have to serialize from and to xml end send it encoded as base64 string. 我不知道的是,是否有可能发送对象数据,也许您必须从​​XML序列化到XML端,并将其编码为base64字符串。

Another way might be jms. 另一种方法可能是jms。

If all of the other solutions listed here do not fit your needs, you could interact with the applications by sending JSON or XML data over HTTP. 如果此处列出的所有其他解决方案都不满足您的需求,则可以通过HTTP发送JSON或XML数据来与应用程序进行交互。

Spark is a micro web framework for Java that lets you quickly create web endpoints. Spark是Java的微型Web框架,可让您快速创建Web端点。

By default, Spark runs on an embedded server, but it can easily run on an existing JBoss server instead. 默认情况下,Spark在嵌入式服务器上运行,但可以轻松地在现有JBoss服务器上运行。 Here is a sample that I put together a few months ago to demonstrate how it works and how to get it working with JBoss. 是我几个月前汇总的一个示例,以演示其工作原理以及如何使其与JBoss一起使用。

You can have each application that needs to receive data expose a HTTP endpoint and have the calling applications send a simple HTTP request. 您可以让每个需要接收数据的应用程序公开一个HTTP端点,并让调用应用程序发送一个简单的HTTP请求。

Simple and open win. 简单而开放的胜利。 You can expose objects remotely in many different ways, but Java RMI and EJB limit you to Java only clients. 您可以通过许多不同的方式远程公开对象,但是Java RMI和EJB将您限制为仅Java客户端。

The most open, easiest way to do it is to use HTTP as your protocol and web services, either SOAP or REST (my preference). 最开放,最简单的方法是使用HTTP作为您的协议和Web服务(SOAP或REST)(我的偏爱)。 These will interact easily with any client, even those that aren't Java. 它们可以与任何客户端轻松交互,即使不是Java的客户端也可以。 Clients need not know or care that you chose Java and JBOSS to implement your server logic. 客户端不需要知道或关心您选择Java和JBOSS来实现服务器逻辑。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM