package com.dev.swms.server.web.servlet;

import java.io.IOException;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import com.dev.swms.server.service.interfaceLog.InterfaceLogManager;

/**
 * @author  dev
 * @version $Id: SwmsEDIServlet.java,v 1.2 2010/06/01 09:14:16 peng.lei Exp $
 */

public class SwmsEDIServlet extends HttpServlet {

	/**  */
	private static final long serialVersionUID = 647386364067796026L;

	protected static ApplicationContext ac;
	
	public void init(ServletConfig sc) throws ServletException {
		super.init(sc);
		ac = WebApplicationContextUtils.getRequiredWebApplicationContext(sc.getServletContext());
	}
	
	protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
		doPost(req , res);
	}
	protected void doPost(final HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
		InterfaceLogManager logManager = (InterfaceLogManager) ac.getBean("interfaceLogManager");
		req.setCharacterEncoding("utf-8");
		String value = req.getParameter("indata");//名值对方式
		String strRes = logManager.receive(value);
		res.setContentType("text/xml; charset=utf-8");
		res.getOutputStream().write(strRes.getBytes("UTF-8"));
	}	
}

