package com.javahonk.action;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Action;

import com.opensymphony.xwork2.ActionSupport;

public class XMLResponseAction extends ActionSupport {

	private static final long serialVersionUID = 1L;

	@Override
	@Action(value = "/xMLResponseAction")
	public String execute() throws Exception {
		
		HttpServletResponse response = ServletActionContext.getResponse();

		PrintWriter printWriter = null;
		response.setContentType("text/xml;charset=UTF-8");
		response.setHeader("Cache-Control", "no-cache");

		StringBuilder stringBuilder = new StringBuilder("<person>");
		
		try {
			
			printWriter = response.getWriter();
			stringBuilder.append("<firstName>" + "Java" + "</firstName>");
			stringBuilder.append("<lastName>" + "Honk" + "</lastName>");
			stringBuilder.append("</person>");
			printWriter.print(stringBuilder.toString());
			
		} catch (IOException ioException) {
			ioException.printStackTrace();			
		} finally {
			printWriter.close();
			printWriter = null;
		}
		return NONE;
	}	

}
