設置返回的Content-Type

@ResponseBody
	@RequestMapping(value="tmall/udw18")
	protected void udwUTF8(HttpServletRequest request, HttpServletResponse response) throws IOException {
		maxUdwThread = new AtomicInteger(Integer.parseInt(maxUdwThreadStr));
		logger.info(LifeUtil.packLog("tmall-udwUTF8-udw-start >>>>>>>>>>>"));
		
		logger.info("UdwRest-udwUTF8當前使用的併發量爲" + currentUdwThread + ",最大併發量爲" + maxUdwThread);
		long begin = System.currentTimeMillis();
		List<String> listStr = new ArrayList<String>();
		
		//返回淘寶xml
		response.setHeader("Content-type", "application/xml;charset=GBK");
		response.setCharacterEncoding("GBK");
		try {
			//當前支持的併發量加1
			incrementCount();
			
			//簽名校驗
			boolean signFlag = false;
			String xml = "";
			
			ServletInputStream sis = request.getInputStream();
			comId = request.getParameter("com_id");
			logger.info("UdwRest-udwUTF8-comId=" + comId);

			if(maskPw){
				String sign=request.getParameter("sign");
				logger.info("UdwRest-udwUTF8簽名sign"+sign);
				xml = SignUtil.readXmlFromInputStream(sis);
				signFlag = SignUtil.validateSign(xml, sign);
			}else{
				xml = SignUtil.readXmlFromInputStream(sis);
				signFlag= true;
			}
			
			if(!signFlag){
				Map<String, String> mp = new HashMap<String, String>();
				mp.put("ComId", comId);
				mp.put("RequestType", "01");
				mp.put("ResponseCode", "0");
				mp.put("ErrorMessage", "簽名驗證失敗");
				
				listStr.add(TmallResponse.udwPackage(mp));
				logger.info("tmall>>>>>>>>>>>>udw>>>>>>>>>>>>>>>>>returnXML=" 
								+ TmallResponse.packPackageList(listStr));
				response.getWriter().write(TmallResponse.packPackageList(listStr));
			}
			
			listStr = convertData(xml, request);
			logger.info("tmall>>>>>>>>>>>>udw>>>>>>>>>>>>>>>>>returnXML=" + TmallResponse.packPackageList(listStr));
			long end = System.currentTimeMillis();
			logger.info("tmall>>>>>>>>>udw>>>>>>>>time=" + (end-begin) + "ms");
			
			
			response.getWriter().write(TmallResponse.packPackageList(listStr));
			
		} catch (Exception e) {
			logger.error("UdwRest-udwUTF8-error:" + e.getMessage());
			e.printStackTrace();
			Map<String, String> mp = new HashMap<String, String>();
			mp.put("ComId", comId);
			mp.put("RequestType", "01");
			mp.put("ResponseCode", "1");
			mp.put("ErrorMessage", "系統異常");
			listStr.add(TmallResponse.udwPackage(mp));
			logger.info("tmall>>>>>>>>>>>>udw>>>>>>>>>>>>>>>>>returnXML=" 
								+ TmallResponse.packPackageList(listStr));
			response.getWriter().write(TmallResponse.packPackageList(listStr));

		} finally {
			//當前支持的最大併發量減1
			decrementCount();
		}
	}

response.setHeader("Content-type", "application/xml;charset=GBK");
 response.setCharacterEncoding("GBK");併發

 return  response.getWriter().write(TmallResponse.packPackageList(listStr));
 app

相關文章
相關標籤/搜索