1 16 17 package org.apache.coyote.tomcat3; 18 19 import java.util.Enumeration ; 20 import java.util.Hashtable ; 21 22 import org.apache.coyote.ActionCode; 23 import org.apache.coyote.ProtocolHandler; 24 import org.apache.tomcat.core.BaseInterceptor; 25 import org.apache.tomcat.core.Context; 26 import org.apache.tomcat.core.ContextManager; 27 import org.apache.tomcat.core.TomcatException; 28 import org.apache.tomcat.util.IntrospectionUtils; 29 import org.apache.tomcat.util.net.SSLSupport; 30 31 78 public class CoyoteInterceptor2 extends BaseInterceptor 79 { 80 public static final String REDIRECT_PORT_ATTR = 81 "org.apache.tomcat.request.redirectPort"; 82 private String processorClassName="org.apache.coyote.http11.Http11Protocol"; 83 Tomcat3Adapter adapter; 84 ProtocolHandler proto; 85 int protocolNote; 86 int redirectPort = -1; 87 88 public CoyoteInterceptor2() { 89 super(); 90 this.setAttribute( "port", "8080" ); 92 this.setAttribute( "soLinger", "-1" ); 93 } 94 95 97 99 public void setProcessorClassName(String pcn) { 100 processorClassName = pcn; 101 } 102 103 Hashtable attributes=new Hashtable (); 105 106 public void setAttribute( String prop, Object value) { 107 attributes.put( translateAttributeName(prop), value ); 108 } 109 110 111 public void setProperty( String prop, String value ) { 112 setAttribute( prop, value ); 113 } 114 115 118 public void setRedirectPort(int rp) { 119 redirectPort = rp; 120 setAttribute("redirectPort", new Integer (rp)); 121 } 122 123 126 public int getRedirectPort() { 127 return redirectPort; 128 } 129 130 132 public void engineInit(ContextManager cm) throws TomcatException { 133 super.engineInit( cm ); 134 135 protocolNote = cm.getNoteId(ContextManager.MODULE_NOTE, 136 "coyote.protocol"); 137 adapter=new Tomcat3Adapter(cm, this); 138 try { 139 Class c=Class.forName(processorClassName); 140 proto=(ProtocolHandler)c.newInstance(); 141 setNote(protocolNote, proto); 142 } catch( Exception ex ) { 143 ex.printStackTrace(); 144 } 145 146 this.setAttribute("jkHome", cm.getHome()); 147 148 proto.setAdapter( adapter ); 149 try { 150 Enumeration keys=attributes.keys(); 151 while( keys.hasMoreElements() ) { 152 String k=(String )keys.nextElement(); 153 Object o=attributes.get(k); 154 if( o instanceof String ) 155 IntrospectionUtils.setProperty( proto, k, (String )o ); 156 else 157 IntrospectionUtils.setAttribute( proto, k, o ); 158 } 159 proto.init(); 160 } catch( Exception ex ) { 161 throw new TomcatException( "Error setting protocol properties ", ex ); 162 } 163 } 164 165 167 public void engineStart(ContextManager cm) throws TomcatException { 168 try { 169 proto.start(); 170 } catch( Exception ex ) { 171 ex.printStackTrace(); 172 throw new TomcatException( ex ); 173 } 174 } 175 176 public void engineShutdown(ContextManager cm) throws TomcatException { 177 try { 178 proto.destroy(); 179 } catch( Exception ex ) { 180 throw new TomcatException( ex ); 181 } 182 } 183 184 186 188 public int preService(org.apache.tomcat.core.Request request, 189 org.apache.tomcat.core.Response response) { 190 if(response instanceof Tomcat3Response) { 191 try { 192 ((Tomcat3Response)response).sendAcknowledgement(); 193 } catch(Exception ex) { 194 log("Can't send ACK", ex); 195 } 196 } 197 return 0; 198 } 199 200 public int postRequest(org.apache.tomcat.core.Request request, 201 org.apache.tomcat.core.Response response) { 202 if(request instanceof Tomcat3Request) { 203 try { 204 Tomcat3Request httpReq=(Tomcat3Request)request; 205 org.apache.coyote.Request cReq = httpReq.getCoyoteRequest(); 206 cReq.action( ActionCode.ACTION_POST_REQUEST , null); 207 } catch(Exception ex) { 208 log("Can't send ACK", ex); 209 } 210 } 211 return 0; 212 } 213 214 219 public Object getInfo( Context ctx, org.apache.tomcat.core.Request request, 220 int id, String key ) { 221 if( ! ( request instanceof Tomcat3Request ) ) 222 return null; 223 224 Tomcat3Request httpReq=(Tomcat3Request)request; 225 226 if( httpReq == null || httpReq.getConnector() != this ) { 227 return null; 228 } 229 230 if(key!=null ){ 231 org.apache.coyote.Request cReq = httpReq.getCoyoteRequest(); 232 Object info = cReq.getAttribute(key); 233 if( info != null) 234 return info; 235 if(isSSLAttribute(key)) { 238 cReq.action(ActionCode.ACTION_REQ_SSL_ATTRIBUTE, 239 httpReq.getCoyoteRequest() ); 240 Object [] value = (Object []) cReq.getAttribute(SSLSupport.CERTIFICATE_KEY); 242 if( value != null ) { 243 cReq.setAttribute(SSLSupport.CERTIFICATE_KEY, value[0]); 244 } 245 246 return cReq.getAttribute(key); 247 } else if(key.equals(REDIRECT_PORT_ATTR)) { 248 return new Integer (redirectPort); 249 } 250 251 return cReq.getAttribute( key ); 252 } 253 return super.getInfo(ctx,request,id,key); 254 } 255 256 public int setInfo( Context ctx, org.apache.tomcat.core.Request request, 257 int id, String key, String object ) { 258 if( ! ( request instanceof Tomcat3Request ) ) 259 return DECLINED; 260 261 Tomcat3Request httpReq=(Tomcat3Request)request; 262 263 if(key!=null && httpReq!=null ){ 264 org.apache.coyote.Request cReq = httpReq.getCoyoteRequest(); 265 cReq.setAttribute(key, object); 266 return OK; 267 } 268 return super.setInfo(ctx, request, id, key, object); 269 } 270 271 274 public static boolean isSSLAttribute(String key) { 275 return SSLSupport.CIPHER_SUITE_KEY.equals(key) || 276 SSLSupport.KEY_SIZE_KEY.equals(key) || 277 SSLSupport.CERTIFICATE_KEY.equals(key) || 278 SSLSupport.SESSION_ID_KEY.equals(key); 279 } 280 281 private String translateAttributeName(String name) { 282 if ("clientAuth".equals(name)) { 283 return "clientauth"; 284 } else if ("keystoreFile".equals(name)) { 285 return "keystore"; 286 } else if ("randomFile".equals(name)) { 287 return "randomfile"; 288 } else if ("rootFile".equals(name)) { 289 return "rootfile"; 290 } else if ("keystorePass".equals(name)) { 291 return "keypass"; 292 } else if ("keystoreType".equals(name)) { 293 return "keytype"; 294 } else if ("sslProtocol".equals(name)) { 295 return "protocol"; 296 } else if ("sslProtocols".equals(name)) { 297 return "protocols"; 298 } 299 return name; 300 } 301 302 } 303 304 | Popular Tags |