| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
|
| 21 |
|
package jalview.httpserver; |
| 22 |
|
|
| 23 |
|
import java.io.IOException; |
| 24 |
|
import java.net.BindException; |
| 25 |
|
import java.util.Collections; |
| 26 |
|
|
| 27 |
|
import javax.servlet.ServletException; |
| 28 |
|
import javax.servlet.http.HttpServletRequest; |
| 29 |
|
import javax.servlet.http.HttpServletResponse; |
| 30 |
|
|
| 31 |
|
import org.eclipse.jetty.server.Request; |
| 32 |
|
import org.eclipse.jetty.server.handler.AbstractHandler; |
| 33 |
|
|
| 34 |
|
|
| 35 |
|
|
| 36 |
|
@author |
| 37 |
|
|
| 38 |
|
|
| |
|
| 0% |
Uncovered Elements: 35 (35) |
Complexity: 11 |
Complexity Density: 0.44 |
|
| 39 |
|
public abstract class AbstractRequestHandler extends AbstractHandler |
| 40 |
|
{ |
| 41 |
|
|
| 42 |
|
|
| 43 |
|
|
| 44 |
|
|
| 45 |
|
|
| 46 |
|
private String path; |
| 47 |
|
|
| 48 |
|
|
| 49 |
|
|
| 50 |
|
|
| 51 |
|
private String uri; |
| 52 |
|
|
| 53 |
|
|
| 54 |
|
|
| 55 |
|
|
| |
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 3 |
Complexity Density: 0.38 |
|
| 56 |
0 |
@Override... |
| 57 |
|
public void handle(String target, Request baseRequest, |
| 58 |
|
HttpServletRequest request, HttpServletResponse response) |
| 59 |
|
throws IOException, ServletException |
| 60 |
|
{ |
| 61 |
0 |
try |
| 62 |
|
{ |
| 63 |
|
|
| 64 |
0 |
processRequest(request, response); |
| 65 |
|
} catch (Throwable t) |
| 66 |
|
{ |
| 67 |
|
|
| 68 |
|
|
| 69 |
|
|
| 70 |
0 |
jalview.bin.Console.errPrintln("Exception handling request " |
| 71 |
|
+ request.getRequestURI() + " : " + t.getMessage()); |
| 72 |
0 |
if (response.isCommitted()) |
| 73 |
|
{ |
| 74 |
|
|
| 75 |
|
|
| 76 |
|
|
| 77 |
0 |
jalview.bin.Console.errPrintln( |
| 78 |
|
"Unable to return HTTP 500 as response already committed"); |
| 79 |
|
} |
| 80 |
|
else |
| 81 |
|
{ |
| 82 |
0 |
response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); |
| 83 |
|
} |
| 84 |
|
} finally |
| 85 |
|
{ |
| 86 |
0 |
response.getWriter().flush(); |
| 87 |
0 |
baseRequest.setHandled(true); |
| 88 |
|
} |
| 89 |
|
} |
| 90 |
|
|
| 91 |
|
|
| 92 |
|
|
| 93 |
|
|
| 94 |
|
@param |
| 95 |
|
@param |
| 96 |
|
@throws |
| 97 |
|
|
| 98 |
|
protected abstract void processRequest(HttpServletRequest request, |
| 99 |
|
HttpServletResponse response) throws IOException; |
| 100 |
|
|
| 101 |
|
|
| 102 |
|
|
| 103 |
|
|
| 104 |
|
@param |
| 105 |
|
|
| |
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
|
| 106 |
0 |
protected void dumpRequest(HttpServletRequest request)... |
| 107 |
|
{ |
| 108 |
0 |
jalview.bin.Console.outPrintln(request.getMethod()); |
| 109 |
0 |
jalview.bin.Console.outPrintln(request.getRequestURL()); |
| 110 |
0 |
for (String hdr : Collections.list(request.getHeaderNames())) |
| 111 |
|
{ |
| 112 |
0 |
for (String val : Collections.list(request.getHeaders(hdr))) |
| 113 |
|
{ |
| 114 |
0 |
jalview.bin.Console.outPrintln(hdr + ": " + val); |
| 115 |
|
} |
| 116 |
|
} |
| 117 |
0 |
for (String param : Collections.list(request.getParameterNames())) |
| 118 |
|
{ |
| 119 |
0 |
for (String val : request.getParameterValues(param)) |
| 120 |
|
{ |
| 121 |
0 |
jalview.bin.Console.outPrintln(param + "=" + val); |
| 122 |
|
} |
| 123 |
|
} |
| 124 |
|
} |
| 125 |
|
|
| 126 |
|
|
| 127 |
|
|
| 128 |
|
|
| 129 |
|
@return |
| 130 |
|
|
| 131 |
|
public abstract String getName(); |
| 132 |
|
|
| 133 |
|
|
| 134 |
|
|
| 135 |
|
|
| 136 |
|
@throws |
| 137 |
|
|
| |
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 2 |
Complexity Density: 0.5 |
|
| 138 |
0 |
public void shutdown()... |
| 139 |
|
{ |
| 140 |
0 |
try |
| 141 |
|
{ |
| 142 |
0 |
HttpServer.getInstance().removeHandler(this); |
| 143 |
0 |
stop(); |
| 144 |
|
} catch (Exception e) |
| 145 |
|
{ |
| 146 |
0 |
jalview.bin.Console.errPrintln( |
| 147 |
|
"Error stopping " + getName() + ": " + e.getMessage()); |
| 148 |
|
} |
| 149 |
|
} |
| 150 |
|
|
| 151 |
|
|
| 152 |
|
|
| 153 |
|
|
| 154 |
|
@return |
| 155 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 156 |
0 |
public String getUri()... |
| 157 |
|
{ |
| 158 |
0 |
return this.uri; |
| 159 |
|
} |
| 160 |
|
|
| 161 |
|
|
| 162 |
|
|
| 163 |
|
|
| 164 |
|
@param |
| 165 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 166 |
0 |
protected void setUri(String u)... |
| 167 |
|
{ |
| 168 |
0 |
this.uri = u; |
| 169 |
|
} |
| 170 |
|
|
| 171 |
|
|
| 172 |
|
|
| 173 |
|
|
| 174 |
|
|
| 175 |
|
@param |
| 176 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 177 |
0 |
protected void setPath(String p)... |
| 178 |
|
{ |
| 179 |
0 |
this.path = p; |
| 180 |
|
} |
| 181 |
|
|
| 182 |
|
|
| 183 |
|
|
| 184 |
|
|
| 185 |
|
|
| 186 |
|
@return |
| 187 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 188 |
0 |
public String getPath()... |
| 189 |
|
{ |
| 190 |
0 |
return this.path; |
| 191 |
|
} |
| 192 |
|
|
| 193 |
|
|
| 194 |
|
|
| 195 |
|
|
| 196 |
|
@throws |
| 197 |
|
|
| 198 |
|
@throws |
| 199 |
|
@link |
| 200 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 201 |
0 |
protected void registerHandler() throws BindException... |
| 202 |
|
{ |
| 203 |
0 |
HttpServer.getInstance().registerHandler(this); |
| 204 |
|
} |
| 205 |
|
} |