8000 - Removed the HttpPreprocessor class. The original motivation for th… · javaxt-project/javaxt-jetty@d794072 · GitHub
[go: up one dir, main page]

Skip to content

Commit d794072

Browse files
author
pborissow
committed
- Removed the HttpPreprocessor class. The original motivation for the HttpPreprocessor came from the initial implementation of the WebSockets plugin. The logic there has changed making the HttpPreprocessor class obsolete.
git-svn-id: svn://192.168.0.80/JavaXT/javaxt-jetty@916 2c7b0aa6-e0b2-3c4e-bb4a-8b65b6c465ff
1 parent 55e02a8 commit d794072

File tree

5 files changed

+40
-87
lines changed

5 files changed

+40
-87
lines changed

src/javaxt/http/Server.java

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -401,24 +401,17 @@ private RequestHandler(HttpServlet servlet, SessionDataStore sessionStore){
401401
@Override
402402
public void doStart() throws Exception {
403403

404-
//Initialize preprocessors
405-
for (javaxt.http.servlet.HttpPreprocessor preprocessor : servlet.getPreprocessors()){
406-
preprocessor.init(this);
407-
}
408404

409-
//Initialize servlet
410-
init();
405+
//Initialize ServletContext
406+
ContextHandler.Context context=ContextHandler.getCurrentContext();
407+
javax.servlet.ServletContext servletContext=context==null?new ContextHandler.StaticContext():context;
411408

412409

413-
//Call parent
414-
super.doStart();
415-
}
416-
417-
private void init() throws javaxt.http.servlet.ServletException{
410+
//Add the RequestHandler to the ServletContext
411+
servletContext.setAttribute("org.eclipse.jetty.server.Handler", this);
412+
418413

419-
//Initialize ServletContext
420-
ContextHandler.Context context=ContextHandler.getCurrentContext();
421-
javax.servlet.ServletContext servletContext=context==null?new ContextHandler.StaticContext():context;
414+
//Add ServletContext to the HttpServlet
422415
servlet.setServletContext(new ServletContext(servletContext));
423416

424417

@@ -455,6 +448,10 @@ private void init() throws javaxt.http.servlet.ServletException{
455448

456449
javax.servlet.ServletConfig ServletConfig = null;
457450
servlet.init(ServletConfig);
451+
452+
453+
//Call parent
454+
super.doStart();
458455
}
459456

460457
@Override
@@ -464,23 +461,24 @@ public void handle(
464461
javax.servlet.http.HttpServletResponse response)
465462
throws IOException, javax.servlet.ServletException {
466463

467-
468-
for (javaxt.http.servlet.HttpPreprocessor preprocessor : servlet.getPreprocessors()){
469-
boolean processedRequest = preprocessor.processRequest(request, response);
470-
if (processedRequest){
471-
baseRequest.setHandled(true);
472-
return;
473-
}
474-
}
475-
464+
//Add reference to the baseRequest to the HttpServletRequest
465+
request.setAttribute("org.eclipse.jetty.server.Request", baseRequest);
466+
476467

477468
//Set session handler
478469
baseRequest.setSessionHandler(sessionHandler);
479470

480471

481472
//Jetty doesn't return the correct scheme for HTTPS so we need to update the baseRequest
482473
org.eclipse.jetty.io.EndPoint endPoint = baseRequest.getHttpChannel().getEndPoint();
483-
baseRequest.setScheme((endPoint instanceof SslConnection.DecryptedEndPoint)? "https" : "http");
474+
if (endPoint instanceof SslConnection.DecryptedEndPoint){
475+
baseRequest.setScheme("https");
476+
baseRequest.setSecure(true);
477+
}
478+
else{
479+
baseRequest.setScheme("http");
480+
baseRequest.setSecure(false);
481+
}
484482

485483

486484
//Instantiate the JavaXT versions of Request and Response objects

src/javaxt/http/servlet/HttpPreprocessor.java

Lines changed: 0 additions & 35 deletions
This file was deleted.

src/javaxt/http/servlet/HttpServlet.java

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public abstract class HttpServlet {
2020
private javax.net.ssl.TrustManager[] tms;
2121
private String sslProvider;
2222
private ServletContext servletContext;
23-
private java.util.List<HttpPreprocessor> preprocessors = new java.util.LinkedList<>();
23+
2424

2525
//**************************************************************************
2626
//** init
@@ -77,27 +77,7 @@ public void setServletContext(ServletContext servletContext){
7777
public void log(String str){
7878
//TODO: Implement logger
7979
}
80-
81-
82-
//**************************************************************************
83-
//** getPreprocessors
84-
//**************************************************************************
85-
public java.util.List<HttpPreprocessor> getPreprocessors(){
86-
return preprocessors;
87-
}
8880

89-
90-
//**************************************************************************
91-
//** addPreprocessor
92-
//**************************************************************************
93-
/** Used to add a Preprocessor to the servlet container.
94-
*/
95-
public void addPreprocessor(HttpPreprocessor preprocessor){
96-
synchronized(preprocessors){
97-
preprocessors.add(preprocessor);
98-
preprocessors.notify();
99-
}
100-
}
10181

10282

10383
// //**************************************************************************

src/javaxt/http/servlet/HttpServletRequest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ public HttpServletRequest(javax.servlet.http.HttpServletRequest request, HttpSer
6767

6868
}
6969

70+
protected javax.servlet.http.HttpServletRequest getBaseRequest(){
71+
return request;
72+
}
73+
7074

7175
//**************************************************************************
7276
//** getRemoteAddr

src/javaxt/http/servlet/HttpServletResponse.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,22 @@ public HttpServletResponse(HttpServletRequest request, javax.servlet.http.HttpSe
4848
this.response = response;
4949

5050

51-
//Set default response headers
52-
//setHeader("Accept-Ranges", "bytes");
53-
setHeader("Connection", (request.isKeepAlive() ? "Keep-Alive" : "Close"));
54-
setHeader("Server", request.getServletContext().getServerInfo());
55-
setHeader("Date", getDate(Calendar.getInstance()));
56-
setStatus(200, "OK");
51+
//Set default response headers for standard HTTP/S requests. WebSockets and
52+
//other upgrade requests should be handled differently.
53+
if (request.getHeader("Upgrade")==null){
54+
//if (request.getHeader("Upgrade")
55+
//setHeader("Accept-Ranges", "bytes");
56+
setHeader("Connection", (request.isKeepAlive() ? "Keep-Alive" : "Close"));
57+
setHeader("Server", request.getServletContext().getServerInfo());
58+
setHeader("Date", getDate(Calendar.getInstance()));
59+
setStatus(200, "OK");
60+
}
5761
}
5862

5963

60-
64+
protected javax.servlet.http.HttpServletResponse getBaseResponse(){
65+
return response;
66+
}
6167

6268
//**************************************************************************
6369
//** addCookie

0 commit comments

Comments
 (0)
0