简体   繁体   English

在线Web应用程序中出现500错误,但本地版本中没有

[英]500 Error in online web app, but not in local version

I'm using Google App Engine to create a web application in Java that gets a json string from a website and simply just spits it into the response message. 我正在使用Google App Engine用Java创建一个Web应用程序,该Web应用程序从网站获取一个json字符串,只是将其吐入响应消息中。 The problem is that when I run it online at http://1-dot-inventory-getter.appspot.com/inventoryretriever?userId=26432253 , it gives me a 500 error. 问题是,当我在http://1-dot-inventory-getter.appspot.com/inventoryretriever?userId=26432253在线运行它时,出现500错误。 It works fine in a local test server though. 不过,它在本地测试服务器中工作正常。 I'm not sure what's going on here. 我不确定这是怎么回事。 I checked the logs and this was the only thing I saw: 我检查了日志,这是我唯一看到的内容:

Uncaught exception from servlet servlet未捕获的异常

java.io.IOException: 
    at ... com.invret.main.InventoryRetrieverServlet.doGet(InventoryRetrieverServlet.java:72) ...

This is the line of code that it's pointing to: 这是它指向的代码行:

BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));

I'm not sure what's causing it to error right there. 我不确定是什么原因导致它在那里错误。 Does anyone else know? 还有谁知道吗?

public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
    // Parameters \\
    String userId = req.getParameter("userId");

    if (userId == null) {
        resp.getWriter().println("User ID cannot be null");
        return;
    }

    String[] urlsToFetch = {
            "https://www.roblox.com/users/inventory/list-json?assetTypeId=8&itemsPerPage=100&pageNumber=1&thumbHeight=110&thumbWidth=110&userId=" + userId
    };

    HttpURLConnection con = (HttpURLConnection) new URL(urlsToFetch[0]).openConnection();
    con.setRequestMethod("GET");
    con.setRequestProperty("User-Agent", USER_AGENT);

    BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
    String inputLine;
    StringBuffer response = new StringBuffer();

    while ((inputLine = in.readLine()) != null) {
        response.append(inputLine);
    }

    in.close();
    resp.getWriter().print(response.toString());
}

Here's the complete stack trace that I found in the logs: 这是我在日志中找到的完整堆栈跟踪:

Uncaught exception from servlet
java.io.IOException: 
    at com.google.appengine.api.urlfetch.URLFetchServiceImpl.convertApplicationException(URLFetchServiceImpl.java:185)
    at com.google.appengine.api.urlfetch.URLFetchServiceImpl.fetch(URLFetchServiceImpl.java:45)
    at com.google.apphosting.utils.security.urlfetch.URLFetchServiceStreamHandler$Connection.fetchResponse(URLFetchServiceStreamHandler.java:543)
    at com.google.apphosting.utils.security.urlfetch.URLFetchServiceStreamHandler$Connection.getInputStream(URLFetchServiceStreamHandler.java:422)
    at com.invret.main.InventoryRetrieverServlet.doGet(InventoryRetrieverServlet.java:72)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166)
    at com.google.apphosting.utils.servlet.ParseBlobUploadFilter.doFilter(ParseBlobUploadFilter.java:125)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.apphosting.runtime.jetty.SaveSessionFilter.doFilter(SaveSessionFilter.java:37)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.apphosting.utils.servlet.JdbcMySqlConnectionCleanupFilter.doFilter(JdbcMySqlConnectionCleanupFilter.java:60)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:50)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388)
    at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
    at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
    at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
    at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)
    at com.google.apphosting.runtime.jetty.AppVersionHandlerMap.handle(AppVersionHandlerMap.java:260)
    at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
    at org.mortbay.jetty.Server.handle(Server.java:326)
    at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
    at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:923)
    at com.google.apphosting.runtime.jetty.RpcRequestParser.parseAvailable(RpcRequestParser.java:78)
    at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
    at com.google.apphosting.runtime.jetty.JettyServletEngineAdapter.serviceRequest(JettyServletEngineAdapter.java:148)
    at com.google.apphosting.runtime.JavaRuntime$RequestRunnable.run(JavaRuntime.java:504)
    at com.google.tracing.TraceContext$TraceContextRunnable.runInContext(TraceContext.java:446)
    at com.google.tracing.TraceContext$TraceContextRunnable$1.run(TraceContext.java:453)
    at com.google.tracing.CurrentContext.runInContext(CurrentContext.java:276)
    at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContextNoUnref(TraceContext.java:312)
    at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContext(TraceContext.java:304)
    at com.google.tracing.TraceContext$TraceContextRunnable.run(TraceContext.java:450)
    at com.google.apphosting.runtime.ThreadGroupPool$PoolEntry.run(ThreadGroupPool.java:235)
    at java.lang.Thread.run(Thread.java:745)

EDIT : I still can't figure out how to fix the problem. 编辑 :我仍然不知道如何解决该问题。 The problem is because I'm trying to make a request that you have to use HttpsURLConnection to connect to I guess? 问题是因为我试图发出一个请求,您必须使用HttpsURLConnection才能连接到我猜? I'm not exactly sure how that works. 我不确定这是如何工作的。 I just know that whenever I switched the URL with one that does not have https://, it works. 我只知道,只要我用没有https://的URL切换URL,它就会起作用。

You can use instead: 您可以改用:

req.getParameter(ParamName);

and remove the bufferedreader 并删除bufferedreader

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

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