jan*_*jan 6 java validation google-app-engine hidden hidden-files
To verify a SSL certificate, I need to upload a hidden folder ("/.well-known" containing some files to my application.
I am deploying java application with eclipse, but these files do not receive at the application on appengine. I guess they are filtered out.
I tried to add the hidden folder as static file to the appengine-web.xml, but it did not help.
<!-- Configure serving/caching of GWT files -->
<static-files>
<include path="**" />
<include path=".**" />
<include path="**.*" expiration="0s" />
<include path="**.well-known" expiration="0s" />
<include path="**.nocache.*" expiration="0s" />
<include path="**.cache.*" expiration="365d" />
<include path="**.css" expiration="30d"/>
<exclude path="**.gwt.rpc" />
<exclude path="**.html" />
</static-files>
Run Code Online (Sandbox Code Playgroud)
Any ideas how I could upload these folder and the files?
对于在 Google App Engine 中尝试以静态方式为 letencrypt 提供挑战并失败后来到这里的其他任何人,以下为我做了:(一个人可能实际上可以静态地做到这一点,但我没有尝试因为我不想花更多的时间尝试一些东西,而 Ian 显然尝试过,但无法使其工作 [也许在 Google App Engine 内部完成的复制命令忽略了以点开头的目录])
摘自http://igorartamonov.com/2015/12/lets-encrypt-ssl-google-appengine/致谢 Igor Artamonov。
只需构建一个 servlet,如:
公共类 LetsencryptServlet 扩展 HttpServlet {
public static final Map<String, String> challenges = new HashMap<String, String>();
static {
challenges.put("RzrvZ9gd7EH3i_TsJM-B0vdEMslD4oo_lwsagGskp6c",
"RzrvZ9gd7EH3i_TsJM-B0vdEMslD4oo_lwsagGskp6c.ONrZa3UelibSWEX270nTUiRZKPFXw096nENWbMGw0-E");
}
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
if (!req.getRequestURI().startsWith("/.well-known/acme-challenge/")) {
resp.sendError(404);
return;
}
String id = req.getRequestURI().substring("/.well-known/acme-challenge/".length());
if (!challenges.containsKey(id)) {
resp.sendError(404);
return;
}
resp.setContentType("text/plain");
resp.getOutputStream().print(challenges.get(id));
}
}
Run Code Online (Sandbox Code Playgroud)
并添加到以下内容中web.xml:
<servlet>
<servlet-name>letsencrypt</servlet-name>
<servlet-class>...LetsencryptServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>letsencrypt</servlet-name>
<url-pattern>/.well-known/acme-challenge/*</url-pattern>
</servlet-mapping>
Run Code Online (Sandbox Code Playgroud)
当然,请确保 servlet 类具有您创建的 Servlet 的完整类路径。
该博客文章还涉及生成和安装证书所需的其他步骤。
伊恩:你确定你部署的servlet很好吗?检查日志,确保您正在测试正确的版本.. 也许您有编译问题..
干杯
我在尝试提供assetlinks.json文件时遇到了这个问题。确实看起来以 . 无法在 App Engine 的静态上下文中访问。João Antunes 解决方法的更通用版本如下。
首先,创建不带 . 并在其中放置任何所需的文件。
然后,我们需要创建一个 servlet,当收到对隐藏文件夹的请求时,该 servlet 将响应正确的数据。
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStream;
/**
* Created by Will Calderwood on 17/05/2017.
* <p>
* It would appear to not be possible to upload hidden folders to app engine. So when files need
* to be served from a hidden folder the URL can be bounced through this servlet
*/
public class StaticFileServer extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
// We'll remove the dots from the path
String uri = req.getRequestURI().replace("/.", "/");
// Do anything else that needs doing here
if (uri.toLowerCase().contains(".json")) {
resp.setContentType("application/json");
}
// Read and return the resource from the non-hidden folder
try (InputStream in = getServletContext().getResourceAsStream(uri)) {
if (in == null){
resp.sendError(404);
return;
}
byte[] buffer = new byte[8192];
int count;
while ((count = in.read(buffer)) > 0) {
resp.getOutputStream().write(buffer, 0, count);
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
然后将以下内容添加到您的web.xml文件中,将隐藏文件夹指向我们的 servlet
<servlet>
<servlet-name>StaticFileServer</servlet-name>
<servlet-class>main.com.you.StaticFileServer</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>StaticFileServer</servlet-name>
<url-pattern>/.well-known/*</url-pattern>
</servlet-mapping>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1167 次 |
| 最近记录: |