1 16 package org.mortbay.http.handler; 17 18 import java.io.IOException ; 19 import java.util.Arrays ; 20 import java.util.Collections ; 21 import java.util.HashMap ; 22 import java.util.Iterator ; 23 import java.util.List ; 24 import java.util.Map ; 25 26 import org.apache.commons.logging.Log; 27 import org.mortbay.log.LogFactory; 28 import org.mortbay.http.HttpException; 29 import org.mortbay.http.HttpRequest; 30 import org.mortbay.http.HttpResponse; 31 32 33 39 public class SetResponseHeadersHandler extends AbstractHttpHandler 40 { 41 private static Log log = LogFactory.getLog(SetResponseHeadersHandler.class); 42 43 44 48 private Map _fields=new HashMap (); 49 50 51 55 public void setHeaderValue(String name,String value) 56 { 57 _fields.put(name,Collections.singletonList(value)); 58 } 59 60 61 67 public void setHeaderValues(String name,String [] values) 68 { 69 _fields.put(name,Arrays.asList(values)); 70 } 71 72 73 84 public void handle(String pathInContext, 85 String pathParams, 86 HttpRequest request, 87 HttpResponse response) 88 throws HttpException,IOException 89 { 90 log.debug("SetResponseHeadersHandler.handle()"); 91 92 for (Iterator iterator=_fields.entrySet().iterator();iterator.hasNext();) 93 { 94 Map.Entry entry=(Map.Entry )iterator.next(); 95 String name=(String )entry.getKey(); 96 List values=(List )entry.getValue(); 97 response.setField(name,values); 98 } 99 } 100 } 101 | Popular Tags |