NoHttpResponseException: The server corporbank.dccnet.com failed to respond
2016-03-10 16:05
615 查看
ception in thread "main" org.apache.commons.httpclient.NoHttpResponseException: The server corporbank.dccnet.com failed to respond
服务器没有响应。
使用jdk httpserver 一些业务逻辑,导致异常,没有返回给客户端数据,导致异常。
服务器没有响应。
使用jdk httpserver 一些业务逻辑,导致异常,没有返回给客户端数据,导致异常。
package com.cyyun.xc.command.util; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.net.InetSocketAddress; import java.util.HashMap; import java.util.Map; import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.StringUtils; import org.apache.log4j.Logger; import com.sun.net.httpserver.HttpExchange; import com.sun.net.httpserver.HttpHandler; import com.sun.net.httpserver.HttpServer; import com.sun.net.httpserver.spi.HttpServerProvider; @SuppressWarnings("all") public abstract class ScreenshotHandler { private static Logger log = Logger.getLogger(ScreenshotHandler.class); private int port = 6666; private String path = "test"; public ScreenshotHandler() { } public ScreenshotHandler(int port, String path) { this.port = port; this.path = path; } // 启动服务,监听来自客户端的请求 public void httpserverService() throws IOException { HttpServerProvider provider = HttpServerProvider.provider(); HttpServer httpserver = provider.createHttpServer( new InetSocketAddress(port), 100);// 监听端口6666,能同时接 受100个请求 httpserver.createContext(path, new MyHttpHandler()); httpserver.setExecutor(null); httpserver.start(); // System.out.println("server started"); log.info("server started"); } // Http请求处理类 public class MyHttpHandler implements HttpHandler { public void handle(HttpExchange httpExchange) throws IOException { // String responseMsg = "{result:success}"; // 响应信息 log.error("MyHttpHandler。。。。。。。。。。。。。。。。。。。。。。。"); String responseMsg = ""; InputStream in = null; BufferedReader reader = null; OutputStream out = null; try { in = httpExchange.getRequestBody(); // 获得输入流 reader = new BufferedReader(new InputStreamReader(in)); String temp = null; StringBuilder params = new StringBuilder(); while ((temp = reader.readLine()) != null) { log.info("client request:" + temp); params.append(temp); } Map<String, String> map = convertMap(params.toString()); responseMsg = callback(map); } catch (Exception e) { log.error(e.getMessage(), e); } finally { httpExchange.sendResponseHeaders(200, responseMsg.length()); // 设置响应头属性及响应信息的长度 out = httpExchange.getResponseBody(); // 获得输出流 out.write(responseMsg.getBytes()); out.flush(); if (in != null) { in.close(); } if (reader != null) { reader.close(); } if (out != null) { out.close(); } httpExchange.close(); } } } /** * 回调方法,返回结果"{result:success}" * * @param map * @return */ public abstract String callback(Map<String, String> map); public static Map<String, String> convertMap(String str) { Map<String, String> map = new HashMap<String, String>(); if (StringUtils.isEmpty(str)) { return map; } String[] names = str.split("\\&"); if (ArrayUtils.isEmpty(names)) { return map; } try { for (String name : names) { if (StringUtils.isNotEmpty(name)) { String[] vals = name.split("\\="); if (ArrayUtils.isNotEmpty(vals)) { if (vals.length == 1) { map.put(vals[0], null); } else { map.put(vals[0], vals[1]); } } } } } catch (Exception e) { log.error(e.getMessage(), e); } return map; } }
public static String getConfigValue(String key) { Locale locale = Locale.getDefault(); ResourceBundle localResource = ResourceBundle.getBundle("configParameter", locale); return localResource.getString(key); }
相关文章推荐
- 将main方法打成jar包,并引用第三方的maven jar包
- org.xml.sax.SAXParseException: Content is not allowed in trailing section
- BroadcastShardOperationFailedException TooManyClauses[maxClauseCount is set to
- Failed to execute goal 拒绝访问
- mybatis 批量增加 Parameter '__frch_item_0' not found. Available parameters are [lis
- 开源IMDG之GridGain
- maven install时报错Failed to execute goal org.apache.maven.plugins:maven-compiler-p
- 内存管理(retain,assign,copy,strong,weak)
- (转)清理AIX的/var文件系统大小
- AIX下如何根据端口号查找相应的进程
- AIX下tar解包问题
- AIX碎碎念
- Fatal error: Call to undefined function bindtextdomain()
- LeetCode "Palindrome Pairs"
- Codeforces Round #345 (Div. 2)-B. Beautiful Paintings(暴力)
- 如何利用sendmail发送外部邮件?
- Error: Cannot retrieve metalink for repository: epel. Please verify its path and try again
- 初学MCMC(Markov Chain Monte Carlo)
- 初学MCMC(Markov Chain Monte Carlo)
- Genymotion问题二 Initialize Engine: failed