如何从非GWT(但Java) gapplication调用服务器上的GWT RPC方法?

时间:2023-01-24 18:12:38

I have a regular Java application and want to access an GWT RPC endpoint. Any idea how to make this happen? My GWT application is on a GAE/J and I could use REST for example but I already have the GWT RPC endpoints and don't want to build another façade.

我有一个常规的Java应用程序,并希望访问GWT RPC端点。你知道怎么做吗?我的GWT应用程序位于GAE/J上,我可以使用REST作为例子,但是我已经有了GWT RPC端点,不想构建另一个facade。

Yes, I have seen Invoke a GWT RPC service from Java directly, but this discussion goes into a different direction.

是的,我已经看到直接从Java调用GWT RPC服务,但是这次讨论的方向不同。

5 个解决方案

#1


6  

GWT SyncProxy allows you to access GWT RPC services (e.g methods) from pure Java (not JSNI) code.

GWT SyncProxy允许您访问GWT RPC服务(e)。g方法)来自纯Java(不是JSNI)代码。

See http://www.gdevelop.com/w/blog/2010/01/10/testing-gwt-rpc-services/ for details.

有关详细信息,请参阅http://www.gdevelop.com/w/blog/2010/01/10/testing-gwt-rpc-services/。

#2


4  

The Java implementation in GWT of the RPC protocol in the packages com.google.gwt.user.server.rpc and com.google.gwt.user.server.rpc.impl unfortunately only covers deserialization of requests and serialization of responses. The real work is done in the classes ServerSerializationStreamReader and ServerSerializationStreamWriter (each appr. 750 lines of code).

包com.google. GWT .server中RPC协议GWT中的Java实现。rpc和com.google.gwt.user.server.rpc。不幸的是,impl只涉及请求的反序列化和响应的序列化。真正的工作是在ServerSerializationStreamReader和ServerSerializationStreamWriter(每个appr)类中完成的。750行代码)。

To implement a client, you obviously need to serialze the request and deserialize the response, but since there's no documentation available for the protocol and AFAIK no Java client implementations available, you probably would have to reverse-engineer the (de)serialization classes and write your own code to do everything "the other way around".

实现一个客户,你显然需要serialze请求和反序列化的反应,但因为没有文档可用于协议和AFAIK没有Java客户端实现,您可能必须逆向工程(反)序列化类和编写自己的代码来尽“相反”。

You can find some high-level info about the protocol here

您可以在这里找到一些关于协议的高级信息

#3


2  

You can find what you search in this article about GwtRpcCommLayer : http://googlewebtoolkit.blogspot.com/2010/07/gwtrpccommlayer-extending-gwt-rpc-to-do.html

您可以在本文中找到关于GwtRpcCommLayer的内容:http://googlewebtoolkit.blogspot.com/2010/07/gwtrpccommlayer-extending-gwt- rpcto -do.html

#4


1  

Unfortunately, I think jarnbjo is right about having to reimplement the browser's half of the RPC mechanism.

不幸的是,我认为jarnbjo需要重新实现浏览器的RPC机制的一半是正确的。

Alternately, if you end up having to write a REST interface for remote clients, you can switch your GWT app away from the RPCs and use the REST interface there too, and share your client library between the external clients and the GWT's client-side interface.

或者,如果您最终不得不为远程客户端编写一个REST接口,那么您可以将GWT应用程序从rpc中切换到REST接口,并在外部客户端和GWT的客户端接口之间共享您的客户端库。

#5


1  

I have explored all the answer and today I succeed to working as a pure java client.

我已经探索了所有的答案,今天我成功地作为一个纯java客户机工作。

the SyncProxy needs you have the entire code of the GWT project(server side). And to do so, you just create one additional class which fire the SyncProxy into it. In this class you should import all needed classes and functions, that why you need server code.

SyncProxy需要您拥有GWT项目的全部代码(服务器端)。要做到这一点,只需创建一个额外的类,将SyncProxy放入其中。在这个类中,您应该导入所有需要的类和函数,这就是您需要服务器代码的原因。

and you should check following file could be downloaded from server:

您应该检查以下文件是否可以从服务器下载:

compilation-mappings.txt
*.nocache.js
*.cache.html
*.gwt.rpc

I add the code before cookiemanager, because my server side uri is HTTPS. And my class include a login action then fire the GWT request. This is my code(I have upgraded SyncProxy a bit, because it doesn't support cookie/session auth check.):

我在cookiemanager之前添加代码,因为我的服务器端uri是HTTPS。我的类包括一个登录操作,然后启动GWT请求。这是我的代码(我升级了SyncProxy,因为它不支持cookie/session auth检查):

package com.xxx.xxx.x.xx;

import java.io.IOException;
import java.net.CookieManager;
import java.net.URISyntaxException;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.security.cert.X509Certificate;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSession;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;

import net.customware.gwt.dispatch.client.standard.StandardDispatchService;
import net.customware.gwt.dispatch.shared.DispatchException;

import com.gdevelop.gwt.syncrpc.LoginUtils;
import com.gdevelop.gwt.syncrpc.ProxySettings;
import com.gdevelop.gwt.syncrpc.SyncProxy;

public class TestRemoteExecuteAction {

            static Logger logger = Logger.getLogger(TestRemoteExecuteAction.class.getName());
              public static void main(String[] arg) {

                  SyncProxy.setLoggingLevel(Level.ALL);

                try {

                      // Create a trust manager that does not validate certificate chains
                    TrustManager[] trustAllCerts = new TrustManager[] {new X509TrustManager() {
                            public java.security.cert.X509Certificate[] getAcceptedIssuers() {
                                return null;
                            }
                            public void checkClientTrusted(X509Certificate[] certs, String authType) {
                            }
                            public void checkServerTrusted(X509Certificate[] certs, String authType) {
                            }
                        }
                    };

                    // Install the all-trusting trust manager
                    SSLContext sc = SSLContext.getInstance("SSL");
                    sc.init(null, trustAllCerts, new java.security.SecureRandom());
                    HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());

                    // Create all-trusting host name verifier
                    HostnameVerifier allHostsValid = new HostnameVerifier() {
                        public boolean verify(String hostname, SSLSession session) {
                            return true;
                        }
                    };

                    // Install the all-trusting host verifier
                    HttpsURLConnection.setDefaultHostnameVerifier(allHostsValid);

                    CookieManager cookiemanager = LoginUtils.loginFormBasedJ2EE("https:XXXXX", "XXXX", "XXXX");

                    SyncProxy.setBaseURL("https://XXXXXX");

                    StandardDispatchService rpcService =  SyncProxy.createProxy(StandardDispatchService.class,
                            new ProxySettings().setCookieManager(cookiemanager));

                    System.out.println(cookiemanager.getCookieStore().getCookies().get(0));
                    String JSESSIONID = cookiemanager.getCookieStore().getCookies().get(0).getValue();

                    rpcService.execute(new XXXXXAction("XXX"));



                } catch (NoSuchAlgorithmException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (KeyManagementException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (URISyntaxException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (DispatchException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } 

              }
}

Some outside link you may want:

你可能想要一些外部链接:

https://code.google.com/p/gwt-syncproxy/wiki/QuickStart http://cancerberonia.blogspot.de/2012/10/testing-gwt-service-classes.html

https://code.google.com/p/gwt-syncproxy/wiki/QuickStart http://cancerberonia.blogspot.de/2012/10/testing-gwt-service-classes.html

#1


6  

GWT SyncProxy allows you to access GWT RPC services (e.g methods) from pure Java (not JSNI) code.

GWT SyncProxy允许您访问GWT RPC服务(e)。g方法)来自纯Java(不是JSNI)代码。

See http://www.gdevelop.com/w/blog/2010/01/10/testing-gwt-rpc-services/ for details.

有关详细信息,请参阅http://www.gdevelop.com/w/blog/2010/01/10/testing-gwt-rpc-services/。

#2


4  

The Java implementation in GWT of the RPC protocol in the packages com.google.gwt.user.server.rpc and com.google.gwt.user.server.rpc.impl unfortunately only covers deserialization of requests and serialization of responses. The real work is done in the classes ServerSerializationStreamReader and ServerSerializationStreamWriter (each appr. 750 lines of code).

包com.google. GWT .server中RPC协议GWT中的Java实现。rpc和com.google.gwt.user.server.rpc。不幸的是,impl只涉及请求的反序列化和响应的序列化。真正的工作是在ServerSerializationStreamReader和ServerSerializationStreamWriter(每个appr)类中完成的。750行代码)。

To implement a client, you obviously need to serialze the request and deserialize the response, but since there's no documentation available for the protocol and AFAIK no Java client implementations available, you probably would have to reverse-engineer the (de)serialization classes and write your own code to do everything "the other way around".

实现一个客户,你显然需要serialze请求和反序列化的反应,但因为没有文档可用于协议和AFAIK没有Java客户端实现,您可能必须逆向工程(反)序列化类和编写自己的代码来尽“相反”。

You can find some high-level info about the protocol here

您可以在这里找到一些关于协议的高级信息

#3


2  

You can find what you search in this article about GwtRpcCommLayer : http://googlewebtoolkit.blogspot.com/2010/07/gwtrpccommlayer-extending-gwt-rpc-to-do.html

您可以在本文中找到关于GwtRpcCommLayer的内容:http://googlewebtoolkit.blogspot.com/2010/07/gwtrpccommlayer-extending-gwt- rpcto -do.html

#4


1  

Unfortunately, I think jarnbjo is right about having to reimplement the browser's half of the RPC mechanism.

不幸的是,我认为jarnbjo需要重新实现浏览器的RPC机制的一半是正确的。

Alternately, if you end up having to write a REST interface for remote clients, you can switch your GWT app away from the RPCs and use the REST interface there too, and share your client library between the external clients and the GWT's client-side interface.

或者,如果您最终不得不为远程客户端编写一个REST接口,那么您可以将GWT应用程序从rpc中切换到REST接口,并在外部客户端和GWT的客户端接口之间共享您的客户端库。

#5


1  

I have explored all the answer and today I succeed to working as a pure java client.

我已经探索了所有的答案,今天我成功地作为一个纯java客户机工作。

the SyncProxy needs you have the entire code of the GWT project(server side). And to do so, you just create one additional class which fire the SyncProxy into it. In this class you should import all needed classes and functions, that why you need server code.

SyncProxy需要您拥有GWT项目的全部代码(服务器端)。要做到这一点,只需创建一个额外的类,将SyncProxy放入其中。在这个类中,您应该导入所有需要的类和函数,这就是您需要服务器代码的原因。

and you should check following file could be downloaded from server:

您应该检查以下文件是否可以从服务器下载:

compilation-mappings.txt
*.nocache.js
*.cache.html
*.gwt.rpc

I add the code before cookiemanager, because my server side uri is HTTPS. And my class include a login action then fire the GWT request. This is my code(I have upgraded SyncProxy a bit, because it doesn't support cookie/session auth check.):

我在cookiemanager之前添加代码,因为我的服务器端uri是HTTPS。我的类包括一个登录操作,然后启动GWT请求。这是我的代码(我升级了SyncProxy,因为它不支持cookie/session auth检查):

package com.xxx.xxx.x.xx;

import java.io.IOException;
import java.net.CookieManager;
import java.net.URISyntaxException;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.security.cert.X509Certificate;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSession;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;

import net.customware.gwt.dispatch.client.standard.StandardDispatchService;
import net.customware.gwt.dispatch.shared.DispatchException;

import com.gdevelop.gwt.syncrpc.LoginUtils;
import com.gdevelop.gwt.syncrpc.ProxySettings;
import com.gdevelop.gwt.syncrpc.SyncProxy;

public class TestRemoteExecuteAction {

            static Logger logger = Logger.getLogger(TestRemoteExecuteAction.class.getName());
              public static void main(String[] arg) {

                  SyncProxy.setLoggingLevel(Level.ALL);

                try {

                      // Create a trust manager that does not validate certificate chains
                    TrustManager[] trustAllCerts = new TrustManager[] {new X509TrustManager() {
                            public java.security.cert.X509Certificate[] getAcceptedIssuers() {
                                return null;
                            }
                            public void checkClientTrusted(X509Certificate[] certs, String authType) {
                            }
                            public void checkServerTrusted(X509Certificate[] certs, String authType) {
                            }
                        }
                    };

                    // Install the all-trusting trust manager
                    SSLContext sc = SSLContext.getInstance("SSL");
                    sc.init(null, trustAllCerts, new java.security.SecureRandom());
                    HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());

                    // Create all-trusting host name verifier
                    HostnameVerifier allHostsValid = new HostnameVerifier() {
                        public boolean verify(String hostname, SSLSession session) {
                            return true;
                        }
                    };

                    // Install the all-trusting host verifier
                    HttpsURLConnection.setDefaultHostnameVerifier(allHostsValid);

                    CookieManager cookiemanager = LoginUtils.loginFormBasedJ2EE("https:XXXXX", "XXXX", "XXXX");

                    SyncProxy.setBaseURL("https://XXXXXX");

                    StandardDispatchService rpcService =  SyncProxy.createProxy(StandardDispatchService.class,
                            new ProxySettings().setCookieManager(cookiemanager));

                    System.out.println(cookiemanager.getCookieStore().getCookies().get(0));
                    String JSESSIONID = cookiemanager.getCookieStore().getCookies().get(0).getValue();

                    rpcService.execute(new XXXXXAction("XXX"));



                } catch (NoSuchAlgorithmException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (KeyManagementException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (URISyntaxException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (DispatchException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } 

              }
}

Some outside link you may want:

你可能想要一些外部链接:

https://code.google.com/p/gwt-syncproxy/wiki/QuickStart http://cancerberonia.blogspot.de/2012/10/testing-gwt-service-classes.html

https://code.google.com/p/gwt-syncproxy/wiki/QuickStart http://cancerberonia.blogspot.de/2012/10/testing-gwt-service-classes.html