1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636
|
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.*;
import java.net.*;
/*
uWSGI Servlet 2.5 Container implementation
*/
class uWSGIServletContext implements ServletContext {
public Object getAttribute(String name) {
System.out.println("uWSGIServletContext getAttribute " + name);
return null;
}
public ServletContext getContext(String uripath) {
return this;
}
public String getContextPath() {
System.out.println("uWSGIServletContext getContextPath");
return "/root/uwsgi";
}
public int getMajorVersion() {
return 2;
}
public int getMinorVersion() {
return 5;
}
public String getMimeType(java.lang.String file) {
System.out.println("uWSGIServletContext getMimeType " + file);
return "text/plain";
}
public java.util.Set getResourcePaths(java.lang.String path) {
System.out.println("uWSGIServletContext getResourcePaths " + path);
return null;
}
public java.net.URL getResource(java.lang.String path) {
System.out.println("uWSGIServletContext getResource " + path);
try {
File myFile;
if (path.equals("/WEB-INF/web.xml")) {
myFile = new File("/root/uwsgi/WEB-INF/web.xml");
}
else {
myFile = new File("/root/uwsgi/foo.jsp");
}
return myFile.toURI().toURL();
}
catch(MalformedURLException e) {
System.out.println("uWSGIServletContext ERROR !!!");
return null;
}
}
public RequestDispatcher getNamedDispatcher(java.lang.String name) {
System.out.println("uWSGIServletContext getNamedDispatcher " + name);
return null;
}
public java.io.InputStream getResourceAsStream(java.lang.String path) {
System.out.println("uWSGIServletContext getResourceAsStream " + path);
try {
FileInputStream fis = new FileInputStream(path);
return fis;
}
catch(FileNotFoundException e) {
return null;
}
}
public RequestDispatcher getRequestDispatcher(java.lang.String path) {
System.out.println("uWSGIServletContext getRequestDispatcher " + path);
return null;
}
public Servlet getServlet(java.lang.String name) {
System.out.println("uWSGIServletContext getServlet");
return null;
}
public java.util.Enumeration getServletNames() {
return null;
}
public java.util.Enumeration getServlets() {
return null;
}
public void log(java.lang.String message, java.lang.Throwable throwable) {
System.out.println("LOG " + message);
}
public void log(java.lang.Exception exception, java.lang.String msg) {
System.out.println("LOG " + msg);
}
public void log(java.lang.String msg) {
System.out.println("LOG " + msg);
}
public String getRealPath(java.lang.String path) {
System.out.println("uWSGIServletContext getRealPath " + path);
return path;
}
public String getServerInfo() {
return "uWSGI";
}
public String getInitParameter(java.lang.String name) {
return null;
}
public Enumeration getInitParameterNames() {
System.out.println("uWSGIServletContext getInitParameterNames()");
return null;
}
public java.util.Enumeration getAttributeNames() {
System.out.println("uWSGIServletContext getAttributeNames");
return null;
}
public String getServletContextName() {
System.out.println("uWSGIServletContext getServletContextName");
return "/jsp";
}
public void removeAttribute(java.lang.String name) {
}
public void setAttribute(java.lang.String name, java.lang.Object object) {
System.out.println("uWSGIServletContext setAttribute " + name);
}
}
class uWSGIServletConfig implements ServletConfig {
uWSGIServletContext context;
public uWSGIServletConfig() {
super();
System.out.println("uWSGIServletConfig allocation");
this.context = new uWSGIServletContext();
}
public String getInitParameter(String name) {
System.out.println("ServletConfig getInitParameter " + name);
return null;
}
public Enumeration<java.lang.String> getInitParameterNames() {
System.out.println("ServletConfig getInitParameterNames");
Vector pNames = new Vector();
return pNames.elements();
}
public ServletContext getServletContext() {
System.out.println("ServletConfig getServletContext");
return this.context;
}
public String getServletName() {
return "/jsp";
}
}
class uWSGIServletOutputStream extends ServletOutputStream {
// append a byte to the writing buffer
public void write(int n) {
System.out.print((char)n);
}
// send them to the client
public void flush() {
System.out.println("FLUSHING");
}
}
class uWSGIServletSession implements HttpSession {
HashMap<String,Object> hm;
public uWSGIServletSession() {
this.hm = new HashMap<String,Object>();
}
public String getId() {
return "uwsgi";
}
public int getMaxInactiveInterval() {
return 3600;
}
public long getLastAccessedTime() {
return 1373874485;
}
public long getCreationTime() {
return 1373874485;
}
public void setMaxInactiveInterval(int interval) {
System.out.println("SESSION INTERVAL " + interval );
}
public HttpSessionContext getSessionContext() {
return null;
}
public ServletContext getServletContext() {
return null;
}
public String[] getValueNames() {
return (String[]) this.hm.keySet().toArray();
}
public void invalidate() {
}
public void removeAttribute(String name) {
this.hm.remove(name);
}
public void removeValue(String name) {
this.hm.remove(name);
}
public void putValue(String name, Object value) {
this.hm.put(name, value);
}
public void setAttribute(String name, Object value) {
this.hm.put(name, value);
}
public Enumeration getAttributeNames() {
return Collections.enumeration(this.hm.keySet());
}
public boolean isNew() {
return false;
}
public Object getAttribute(String name) {
return this.hm.get(name);
}
public Object getValue(String name) {
return this.hm.get(name);
}
}
class uWSGIServletRequest implements HttpServletRequest {
uWSGIServletSession session = null;
public Object getAttribute(String name) {
System.out.println("getAttribute " + name);
return null;
}
public Enumeration getAttributeNames() {
return null;
}
public String getCharacterEncoding() {
return "utf-8";
}
public void setCharacterEncoding(String env) {
}
public String getParameter(String name) {
System.out.println("getParameter " + name);
return null;
}
public Enumeration getParameterNames() {
return null;
}
public String[] getParameterValues(String name) {
return null;
}
public int getContentLength() {
return 0;
}
public String getContentType() {
return "text/plain";
}
public ServletInputStream getInputStream() {
return null;
}
public Map getParameterMap() {
return null;
}
public String getProtocol() {
return "HTTP/1.0";
}
public String getScheme() {
System.out.println("getScheme");
return "http";
}
public String getServerName() {
return "quantal64.local";
}
public int getServerPort() {
return 80;
}
public BufferedReader getReader() {
return null;
}
public String getRemoteAddr() {
return "127.0.0.1";
}
public String getRemoteHost() {
return "localhost";
}
public void setAttribute(String name, Object o) {
}
public void removeAttribute(String name) {
}
public Locale getLocale() {
return null;
}
public Enumeration getLocales() {
return null;
}
public boolean isSecure() {
return false;
}
public RequestDispatcher getRequestDispatcher(String path) {
System.out.println("RequestDispatcher getRequestDispatcher " + path);
return null;
}
public String getRealPath(String path) {
System.out.println("getRealPath " + path);
return "/tmp";
}
public int getRemotePort() {
return 1717;
}
public String getLocalName() {
return "localhost";
}
public String getLocalAddr() {
return "127.0.0.1";
}
public int getLocalPort() {
return 80;
}
public String getAuthType() {
return null;
}
public Cookie[] getCookies() {
return null;
}
public long getDateHeader(String name) {
return -1;
}
public String getHeader(String name) {
System.out.println("getHeader " + name);
return null;
}
public Enumeration getHeaders(String name) {
System.out.println("getHeaders " + name);
return null;
}
public Enumeration getHeaderNames() {
return null;
}
public int getIntHeader(String name) {
return -1;
}
public String getMethod() {
System.out.println("getMethod");
return "GET";
}
public String getPathInfo() {
System.out.println("getPathInfo");
return "";
}
public String getPathTranslated() {
System.out.println("getPathTranslated");
return null;
}
public String getContextPath() {
System.out.println("getContextPath");
return "";
}
public String getQueryString() {
return "r=17";
}
public String getRemoteUser() {
return "kratos";
}
public boolean isUserInRole(String role) {
return false;
}
public java.security.Principal getUserPrincipal() {
return null;
}
public String getRequestedSessionId() {
System.out.println("getRequestedSessionId !!!");
return null;
}
public String getRequestURI() {
System.out.println("getRequestURI");
return "/foo.jsp";
}
public StringBuffer getRequestURL() {
System.out.println("getRequestURL");
//return "http://quantal64.local/roberta?r=17";
return null;
}
public String getServletPath() {
System.out.println("getServletPath");
return "/root/uwsgi/foo.jsp";
}
public HttpSession getSession(boolean create) {
System.out.println(" getSession !!!");
return null;
}
public HttpSession getSession() {
System.out.println("!!! getSession !!!");
if (this.session == null) {
this.session = new uWSGIServletSession();
}
return this.session;
}
public boolean isRequestedSessionIdFromURL() {
return false;
}
public boolean isRequestedSessionIdFromUrl() {
return false;
}
public boolean isRequestedSessionIdFromCookie() {
return false;
}
public boolean isRequestedSessionIdValid() {
return false;
}
}
class uWSGIServletResponse implements HttpServletResponse {
PrintWriter pw;
public uWSGIServletResponse() {
this.pw = new PrintWriter(new uWSGIServletOutputStream());
}
public void addCookie(Cookie cookie) {
}
public boolean containsHeader(String name) {
return false;
}
public String encodeURL(String url) {
System.out.println("URL = " + url);
return url;
}
public String encodeRedirectURL(String url) {
return url;
}
public String encodeUrl(String url) {
return url;
}
public String encodeRedirectUrl(String url) {
return url;
}
public void sendError(int sc, String msg) {
}
public void sendError(int sc) {
}
public void sendRedirect(String location) {
}
public void setDateHeader(String name, long date) {
}
public void addDateHeader(String name, long date) {
}
public void setHeader(String name, String value) {
System.out.println("SET_HEADER " + name + " = " + value);
}
public void addHeader(String name, String value) {
System.out.println("ADD_HEADER " + name + " = " + value);
}
public void setIntHeader(String name, int value) {
}
public void addIntHeader(String name, int value) {
}
public void setStatus(int sc) {
System.out.println("STATUS " + sc);
}
public void setStatus(int sc, String sm) {
System.out.println("STATUS " + sc + " " + sm);
}
public void flushBuffer() {
System.out.println("flushBuffer");
this.pw.flush();
}
public void resetBuffer() {
System.out.println("resetBuffer");
}
public boolean isCommitted() {
return true;
}
public void reset() {
}
public void setLocale(Locale loc) {
}
public Locale getLocale() {
return null;
}
public int getBufferSize() {
return 4096;
}
public void setBufferSize(int size) {
}
public void setContentType(String type) {
System.out.println("setContentType " + type);
}
public void setContentLength(int len) {
}
public void setCharacterEncoding(String charset) {
}
public PrintWriter getWriter() {
System.out.println("getWriter()");
return this.pw;
}
public ServletOutputStream getOutputStream() {
System.out.println("getOutputStream()");
return null;
}
public String getContentType() {
return "text/plain";
}
public String getCharacterEncoding() {
return "utf-8";
}
}
|