接受http响应

 @RequestMapping(value = "respurl.xt") 
 public void respurl(HttpServletRequest req,HttpServletResponse resp) throws IOException{
  String filePath=req.getServletContext().getRealPath("/");   
  ServletContext application=req.getServletContext();
  logfile=(TraceLog) application.getAttribute("log");
  if(logfile==null){
   logfile = new TraceLog(filePath+"/WEB-INF/log/AppCallInfo", 5, 10 * 1024 * 1024);
   application.setAttribute("log", logfile);
  } 
  Map<String,String> map=new HashMap<String,String>();
  String respString="";
  Enumeration headers=req.getHeaderNames();
  while(headers.hasMoreElements()){
   String key=(String) headers.nextElement();
   String value=req.getHeader(key);
   map.put(key.toLowerCase(), value);
   logfile.TraceLn(0, key.toLowerCase()+":"+value);
   System.out.println(key.toLowerCase()+":"+value);
  }
  
  BufferedReader br;
  String data = null;
  StringBuffer input=null;
  try {
   br = new BufferedReader(new InputStreamReader(
     (ServletInputStream) req.getInputStream(),"UTF-8"));
    input = new StringBuffer();
   while ((data = br.readLine()) != null) {
    input.append(data);
   }
   br.close();
  } catch (UnsupportedEncodingException e) {   
   e.printStackTrace();
  } catch (IOException e) {   
   e.printStackTrace();
  }
  logfile.TraceLn(0, input.toString());
         String result="";
      String strcode="0000";
      result="<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n"
        +"<Response>\r\n"
        +"<statusCode>"+strcode+"</statusCode>\r\n"
        +"</Response>\r\n";  
      PrintWriter out = resp.getWriter();
      out.print(result); 
      out.flush(); 
      out.close();
      return ;
 }

 

你可能感兴趣的:(http)