简体   繁体   English

GWT RequestFactory客户端方案

[英]GWT RequestFactory client scenarios

My understanding is that the GWT RequestFactory ( RF ) API is for building data-oriented services whereby a client-side entity can communicate directly with it's server-side DAO. 我的理解是,GWT RequestFactory( RF )API用于构建面向数据的服务,客户端实体可以直接与其服务器端DAO通信。

My understanding is that when you fire a RF method from the client-side, a RequestFactoryServlet living on the server is what first receives the request. 我的理解是,当您从客户端启动RF方法时,首先接收请求的是RequestFactoryServlet在服务器上的RequestFactoryServlet This servlet acts like a DispatchServlet and routes the request on to the correct service, which is tied to a single entity (model) in the data store. 该Servlet就像DispatchServlet ,将请求路由到正确的服务,该服务绑定到数据存储中的单个实体(模型)。

I'm used to writing servlets that might pass the request on to some business logic (like an EJB), and then compute some response to send back. 我习惯于编写servlet,这些servlet可能会将请求传递给某些业务逻辑(例如EJB),然后计算一些响应以将其发送回去。 This might be a JSP view, some complicated JSON (Jackson) object, or anything else. 这可能是JSP视图,某些复杂的JSON(Jackson)对象或其他任何东西。

In all the RF examples, I see no such existence of these servlets, and I'm wondering if they even exist in GWT-RF land. 在所有的RF示例中,我看不到这些servlet的存在,并且我想知道它们是否甚至存在于GWT-RF领域。 If the RequestFactoryServlet is automagically routing requests to the correct DAO and method, and the DAO method is what is returned in the response, then I can see a scenario where GWT RF doesn't even utilize traditional servlets. 如果RequestFactoryServlet自动将请求路由到正确的DAO和方法,并且DAO方法是响应中返回的内容,那么我可以看到GWT RF甚至没有利用传统Servlet的情况。 (1) Is this the case? (1)是这样吗?

Regardless, there are times in my GWT application where I want to hit a specific url, such as http://www.example.com?foo=bar . 无论如何,在我的GWT应用程序中,有时候我想访问特定的URL,例如http://www.example.com?foo=bar (2) Can I use RF for this, and if so, how? (2)我可以为此使用RF吗?

I think if I could see two specific examples, side-by-side of GWT RF in action, I'd be able to connect all the dots: 我认为,如果我能看到两个具体的示例,在运行中并排使用GWT RF,那么我将能够连接所有点:

  • Scenario #1 : I have a Person entity with methods like isHappy() , isSad() , etc. that would require interaction with a server-side DAO; 场景1:我有一个Person实体,该方法isHappy()isSad()等方法,需要与服务器端DAO进行交互; and
  • Scenario #2 : I want to fire an HTTP request to http://www.example.com?foo=bar and manually inspect the HTTP response 方案2:我想向http://www.example.com?foo=bar发出HTTP请求并手动检查HTTP响应

If it's possible to accomplish both with the RF API, that would be my first preference. 如果可以同时使用RF API做到这两者,那将是我的第一选择。 If the latter scenario can't be accomplished with RF, then please explain why and what is the GWT-preferred alternative. 如果使用RF无法完成后一种情况,请解释为什么以及GWT首选的替代方法是什么。 Thanks in advance! 提前致谢!

1.- Request factory not only works for Entities but Services, so you could define any service in server-side with methods which you call from client. 1.-请求工厂不仅适用于实体,而且适用于服务,因此您可以使用从客户端调用的方法在服务器端定义任何服务。 Of course when you use RF services they are able to deal with certain types (primitive, boxed primitives, sets, lists and RF proxies) 当然,当您使用RF服务时,它们能够处理某些类型(原始,装箱的原始,集合,列表和RF代理)

@Service(value=RfService.class, locator=RfServiceLocator.class)
public interface TwService extends RequestContext {
  Request<String> parse(String value);
}

public class RfService {
public String parse(String value) {
  return value.replace("a", "b");
}

2.- RF is not thought to receive other message payloads than the RF servlet produces, and the most you can do in client side with RF is ask for that services hosted in a different site (when you deploy your server and client sides in different hosts). 2.- RF不被认为会收到RF servlet产生的其他消息负载,在RF客户端上您能做的最大事情就是要求托管在不同站点中的服务(当您在不同位置部署服务器和客户端时)主机)。

You can use other mechanisms in gwt world to get data from other urls, take a look to gwtquery Ajax and data-binding or this article 您可以使用gwt世界中的其他机制从其他url获取数据,看看gwtquery Ajax数据绑定本文

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

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