gpt4 book ai didi

java.lang.RuntimeException : Failed : HTTP error code : 500

转载 作者:行者123 更新时间:2023-12-01 11:19:47 25 4
gpt4 key购买 nike

我正在尝试检索 json 对象,然后使用其中存在的信息。但在 Json 请求时,它抛出运行时异常。这是代码

public URL getURL(){                

try{
URL domain = new URL("http.....");
URL url = new URL(domain + cookieValue);
System.out.println(url);
return url;
}
catch (MalformedURLException ex) {
log_loginBean.logger(ex);
}

return null;
}

public static JSONObject JSONRequest(URL url_comp){

try {
URL url = url_comp;
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.setRequestProperty("Accept", "application/json");

if (conn.getResponseCode() != 200) {
throw new RuntimeException("Failed : HTTP error code : "
+ conn.getResponseCode());
}

BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()));

String jsonText = readAll(br);
JSONObject json = new JSONObject(jsonText);
conn.disconnect();
return json;

}
catch (MalformedURLException e) {
log_loginBean.logger(e);
}
catch (IOException e) {
log_loginBean.logger(e);

}
catch(JSONException e) {
log_loginBean.logger(e);
}

return null;
}

// This will extract some particular information (UserId, Email) from the extracted JSON Object.

public void parseJSON(){
try{
JSONObject obj = JSONRequest(getURL());
userId = obj.getString("UserID");
Email = obj.getString("Email");

}
catch(JSONException e){
log_loginBean.logger(e);
}
}

这是我的堆栈跟踪

    SEVERE: Servlet.service() for servlet [Faces Servlet] in context with path [/CDCandTR] threw exception [Failed : HTTP error code : 500] with root cause
java.lang.RuntimeException: Failed : HTTP error code : 500
at com.walmart.cdctraffic.login.LoginBean.JSONRequest(LoginBean.java:183)
at com.walmart.cdctraffic.login.LoginBean.parseJSON(LoginBean.java:226)
at com.walmart.cdctraffic.login.LoginBean.login(LoginBean.java:266)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.el.parser.AstValue.invoke(AstValue.java:278)
at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:273)
at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
at com.sun.faces.facelets.tag.jsf.core.DeclarativeSystemEventListener.processEvent(EventHandler.java:128)
at javax.faces.component.UIComponent$ComponentSystemEventListenerAdapter.processEvent(UIComponent.java:2603)
at javax.faces.event.SystemEvent.processListener(SystemEvent.java:108)
at javax.faces.event.ComponentSystemEvent.processListener(ComponentSystemEvent.java:118)
at com.sun.faces.application.ApplicationImpl.processListeners(ApplicationImpl.java:2187)
at com.sun.faces.application.ApplicationImpl.invokeComponentListenersFor(ApplicationImpl.java:2135)
at com.sun.faces.application.ApplicationImpl.publishEvent(ApplicationImpl.java:289)
at com.sun.faces.application.ApplicationImpl.publishEvent(ApplicationImpl.java:247)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:107)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:219)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:647)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at com.walmart.cdctraffic.utilities.ResponseHeaderFilter.doFilter(ResponseHeaderFilter.java:30)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:203)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:610)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at com.walmart.infraweb.valves.SecureErrorReportValve.invoke(SecureErrorReportValve.java:102)
at org.apache.catalina.valves.StuckThreadDetectionValve.invoke(StuckThreadDetectionValve.java:221)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1070)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611)
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2440)
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2429)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)

所以现在我无法找到它抛出 HTTP 500 错误的原因以及如何解决这一切?然后在IF语句之后,是否需要在finally中放入else并断开连接?请帮忙。

最佳答案

根据提供的堆栈跟踪,我怀疑您没有正确传递登录信息,因为它显然在 LoginBean 内的某个地方失败了:

com.walmart.cdctraffic.login.LoginBean.JSONRequest(LoginBean.java:183)

关于java.lang.RuntimeException : Failed : HTTP error code : 500,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31383919/

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