gpt4 book ai didi

gwt - 反向代理后面的 GWT 问题 - nginx 或 apache

转载 作者:行者123 更新时间:2023-12-03 03:28:47 27 4
gpt4 key购买 nike

当 GWT 在反向代理后面时,我遇到了这个问题。后端应用程序部署在上下文中 - 我们称之为/context。

当我直接点击时,GWT 应用程序运行良好:

http://host:8080/context/

我可以在它前面配置一个反向代理。这是我的 nginx 示例:

upstream backend {    server 127.0.0.1:8080;}...location / {   proxy_pass        http://backend/context/;}

但是,当我运行反向代理时,GWT 感到困惑,说:

2009-10-04 14:05:41.140:/:WARN:  Login: ERROR: The serialization policy file '/C7F5ECA5E3C10B453290DE47D3BE0F0E.gwt.rpc' was not found; did you forget to include it in this deployment?2009-10-04 14:05:41.140:/:WARN:  Login: WARNING: Failed to get the SerializationPolicy 'C7F5ECA5E3C10B453290DE47D3BE0F0E' for module 'https://hostname:444/'; a legacy, 1.3.3 compatible, serialization policy will be used.  You may experience SerializationExceptions as a result.2009-10-04 14:05:41.292:/:WARN:  StoryService: ERROR: The serialization policy file '/0445C2D48AEF2FB8CB70C4D4A7849D88.gwt.rpc' was not found; did you forget to include it in this deployment?2009-10-04 14:05:41.292:/:WARN:  StoryService: WARNING: Failed to get the SerializationPolicy '0445C2D48AEF2FB8CB70C4D4A7849D88' for module 'https://hostname:444/'; a legacy, 1.3.3 compatible, serialization policy will be used.  You may experience SerializationExceptions as a result.

换句话来说,GWT 在查找 C7F5ECA5E3C10B453290DE47D3BE0F0E.gwt.rpc 时不会得到需要在/context/前面添加的字词,但仅当请求通过代理时才会出现。解决方法是将上下文添加到网站的 URL:

location /context/ {    proxy_pass        http://backend/context/;}

但这意味着上下文现在是用户看到的 URL 的一部分,这很丑陋。

有人知道在这种情况下如何让 GWT 满意吗?

软件版本:
GWT - 1.7.0(与 1.7.1 相同的问题)
Jetty - 6.1.21(但在tomcat下也存在同样的问题)
nginx - 0.7.62(apache 2.x 下同样的问题)

我使用DonsProxy查看了代理和后端之间的流量。 ,但没有什么值得注意的。

最佳答案

我有同样的问题,我打开了一个错误报告:

http://code.google.com/p/google-web-toolkit/issues/detail?id=4817

问题是它被标记为“As Design”,所以我认为它不会被修复。

我为我找到了这个解决方案。我扩展了 RemoteServiceServlet 类,并强制 GWT 从 ContextName 而不是 URL 开始加载序列化策略文件。然后我扩展了我的服务类而不是 RemoteServiceServlet 类。这样,应用程序将与调用它的 url 取消链接。

这是我的自定义类:

import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.text.ParseException;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import com.google.gwt.user.server.rpc.SerializationPolicy;
import com.google.gwt.user.server.rpc.SerializationPolicyLoader;

public class MyRemoteServiceServlet extends RemoteServiceServlet
{
@Override
protected SerializationPolicy doGetSerializationPolicy(HttpServletRequest request, String moduleBaseURL, String strongName)
{
return MyRemoteServiceServlet.loadSerializationPolicy(this, request, moduleBaseURL, strongName);
}


/**
* Used by HybridServiceServlet.
*/
static SerializationPolicy loadSerializationPolicy(HttpServlet servlet,
HttpServletRequest request, String moduleBaseURL, String strongName) {
// The serialization policy path depends only by contraxt path
String contextPath = request.getContextPath();

SerializationPolicy serializationPolicy = null;


String contextRelativePath = contextPath + "/";



String serializationPolicyFilePath = SerializationPolicyLoader.getSerializationPolicyFileName(contextRelativePath
+ strongName);

// Open the RPC resource file and read its contents.
InputStream is = servlet.getServletContext().getResourceAsStream(
serializationPolicyFilePath);
try {
if (is != null) {
try {
serializationPolicy = SerializationPolicyLoader.loadFromStream(is,
null);
} catch (ParseException e) {
servlet.log("ERROR: Failed to parse the policy file '"
+ serializationPolicyFilePath + "'", e);
} catch (IOException e) {
servlet.log("ERROR: Could not read the policy file '"
+ serializationPolicyFilePath + "'", e);
}
} else {
String message = "ERROR: The serialization policy file '"
+ serializationPolicyFilePath
+ "' was not found; did you forget to include it in this deployment?";
servlet.log(message);
}
} finally {
if (is != null) {
try {
is.close();
} catch (IOException e) {
// Ignore this error
}
}
}

return serializationPolicy;
}
}

关于gwt - 反向代理后面的 GWT 问题 - nginx 或 apache,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1517290/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com