我在 Tomcat7-Container 中的 HCP-Trial-Account 上运行的 Java 应用程序的 httpPost 出现问题。我使用 HttpClient 4.5.3。
该代码在我的本地 Tomcat7-Server 上运行良好并且可以正常工作。但是,如果将其部署到 HCP,则会出现问题。
public static Notebook getAllNotebooks(String code, String redirectUri) throws IOException, URISyntaxException{
ClassLoader classLoader = Connection.class.getClassLoader();
URL resource = classLoader.getResource("org/apache/http/impl/client/HttpClientBuilder.class");
String returnUri = "https://login.live.com/oauth20_token.srf";
HttpPost tokenRequest = new HttpPost(returnUri);
HttpClient client = new DefaultHttpClient();//HttpClientBuilder.create().build(); //Exception: http://stackoverflow.com/questions/22330848/httpclient-example-exception-in-thread-main-java-lang-nosuchfielderror-inst
tokenRequest.setHeader(HttpHeaders.CONTENT_TYPE, "application/x-www-form-urlencoded");
tokenRequest.setEntity(new UrlEncodedFormEntity(Connection.getParametersForURLBody(code, redirectUri), Consts.UTF_8));
tokenRequest.addHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.3; WOW64; rv:28.0) Gecko/20100101 Firefox/28.0");
HttpResponse tokenResponse = client.execute(tokenRequest); //Here it gets stuck
执行 tokenRequest 时会出现问题。应用程序卡住了,并且 tokenRequest 永远运行。
以下是我可以在调试模式下看到的永远运行的线程:
SAP JVM Debug Target
Daemon Thread [NioBlockingSelector.BlockPoller-1] (Running)
Daemon Thread [NioBlockingSelector.BlockPoller-2] (Running)
Daemon Thread [RMI TCP Connection(1)-127.0.0.1] (Running)
Thread [Timer-0] (Running)
Daemon Thread [RMI TCP Connection(2)-10.117.35.76] (Running)
Thread [pool-1-thread-1] (Running)
Thread [Timer-1] (Running)
Daemon Thread [ContainerBackgroundProcessor[StandardEngine[Catalina]]] (Running)
Daemon Thread [JCoTimeoutChecker] (Running)
Daemon Thread [http-bio-8001-Acceptor-0] (Running)
Daemon Thread [http-bio-8001-AsyncTimeout] (Running)
Daemon Thread [http-nio-127.0.0.1-9001-ClientPoller-0] (Running)
Daemon Thread [http-nio-127.0.0.1-9001-Acceptor-0] (Running)
Daemon Thread [http-nio-8041-ClientPoller-0] (Running)
Daemon Thread [http-nio-8041-Acceptor-0] (Running)
Daemon Thread [ajp-bio-8009-Acceptor-0] (Running)
Daemon Thread [ajp-bio-8009-AsyncTimeout] (Running)
Daemon Thread [RMI TCP Connection(10)-127.0.0.1] (Running)
Daemon Thread [RMI TCP Connection(11)-10.117.10.34] (Running)
Thread [main] (Running)
Daemon Thread [http-nio-8041-exec-1] (Running)
Daemon Thread [http-nio-8041-exec-2] (Running)
Daemon Thread [http-nio-8041-exec-3] (Running)
Daemon Thread [http-nio-8041-exec-4] (Running)
Daemon Thread [http-nio-8041-exec-5] (Running)
Thread [pool-2-thread-1] (Running)
Daemon Thread [http-nio-8041-exec-6] (Stepping)
Daemon Thread [http-nio-8041-exec-7] (Running)
Daemon Thread [http-nio-8041-exec-8] (Running)
Daemon Thread [http-nio-8041-exec-9] (Running)
Daemon Thread [http-nio-8041-exec-10] (Running)
Daemon Thread [RMI TCP Connection(idle)] (Running)
Daemon Thread [RMI TCP Connection(idle)] (Running)
程序在这一点上卡住了。
我不知道该怎么做,非常感谢一些提示和帮助:)。
问候马弗林