package earlgrey.core;


import java.util.Enumeration;

import javax.servlet.http.HttpServletRequest;

import org.json.JSONObject;

import earlgrey.def.HttpActionDef;
import earlgrey.def.SessionDef;
import earlgrey.interfaces.Request;

public class HttpRequest implements Request{
	/////////////////////////////////////////////////////////////
	// PATRON ESTANDARD DE UN REQUEST
	// ESTA CLASE CONTIENE LA INFORMACION NECESARIA PARA EFECTUAR EL REQUEST EN UN ACTION
	// DEFINIMOS LAS VARIABLES DEL OBJETO REQUEST
	/////////////////////////////////////////////////////////////
	JSONObject header;
	JSONObject params;
	SessionDef session;
	HttpServletRequest request;
	HttpActionDef action;
	
	//CONSTRUCTOR
	public HttpRequest(JSONObject params, HttpServletRequest request, HttpActionDef httpActionDef)  {
		this.params = params;
		this.request = request;
		this.action = httpActionDef;
		this.session = httpActionDef.getSession();
		this.readHeaders();
	}
	private void readHeaders(){
		this.header = new JSONObject();
		Enumeration<String> names = this.request.getAttributeNames();
		while(names.hasMoreElements()){
			String key = names.nextElement();
			this.header.put(key, request.getHeader(key));
		}
	}
	@Override
	public String getParam(String key) {
		// TODO Auto-generated method stub
		if(params.has(key)) return params.getString(key);
		return null;
	}
	@Override
	public JSONObject getParams() {
		return this.params;
	}
	@Override
	public SessionDef getSession() {
		return this.session;
	}
	@Override
	public JSONObject getHeader() {
		return this.header;
	}
}
@@ -589,16 +589,40 @@
 header;%0A
+%09JSONObject attributes;%0A
 %09JSONObj
@@ -633,16 +633,16 @@
 params;%0A
-
 %09Session
@@ -970,16 +970,41 @@
 ders();%0A
+%09%09this.readAttributes();%0A
 %09%7D%0A%09priv
@@ -1107,25 +1107,22 @@
 uest.get
-Attribute
+Header
 Names();
@@ -1246,19 +1246,283 @@
 ));%0A%09%09%7D%0A
-
 %09%7D%0A
+%09%0A%09private void readAttributes()%7B%0A%09%09this.header = new JSONObject();%0A%09%09Enumeration%3CString%3E names = this.request.getAttributeNames();%0A%09%09while(names.hasMoreElements())%7B%0A%09%09%09String key = names.nextElement();%0A%09%09%09this.header.put(key, request.getAttribute(key));%0A%09%09%7D%0A%09%7D%0A%09%0A
 %09@Overri

Fix the httprequest header and add attributes