1 16 package com.psibt.framework.net; 17 18 import java.io.*; 19 import java.net.*; 20 import java.util.*; 21 22 28 public class RootRequestHandler implements HTTPRequestHandler { 29 30 private String title; 31 private String description; 32 private String handledPath; 33 private String ReplyType = "Content-type: text/html\r\n\r\n"; 34 private String ReplyHTML = "<HTML><HEAD><TITLE>Root</TITLE></HEAD>\r\n" 35 + "<BODY><H1>Root</H1>\r\n" 36 + "</BODY></HTML>\r\n"; 37 38 41 public RootRequestHandler() { 42 this.setTitle("root page"); 43 this.setDescription("root page"); 44 this.setHandledPath("/"); 45 } 46 47 52 public String getReplyType() { 53 return this.ReplyType; 54 } 55 56 61 public void setReplyType(String ReplyType) { 62 this.ReplyType = ReplyType; 63 } 64 65 70 public String getReplyHTML() { 71 return this.ReplyHTML; 72 } 73 74 79 public void setReplyHTML(String ReplyHTML) { 80 this.ReplyHTML = ReplyHTML; 81 } 82 83 86 public String getTitle() { 87 return this.title; 88 } 89 90 93 public void setTitle(String title) { 94 this.title = title; 95 } 96 97 100 public String getDescription() { 101 return this.description; 102 } 103 104 107 public void setDescription(String description) { 108 this.description = description; 109 } 110 111 116 public String getHandledPath() { 117 return this.handledPath; 118 } 119 120 125 public void setHandledPath(String path) { 126 this.handledPath = path; 127 } 128 129 136 public boolean handleRequest(String request, Writer out) { 137 String path = ""; 138 String query = null; 139 try { 140 URL url = new URL("http://localhost"+request); 141 path = url.getPath(); 142 query = url.getPath(); 143 if (path.equals(handledPath) == false) { 144 return false; 145 } 146 147 out.write("HTTP/1.0 200 OK\r\n"); 148 if (ReplyType != null) 149 out.write(ReplyType); 150 if (ReplyHTML != null) 151 out.write(ReplyHTML); 152 out.flush(); 153 return true; 154 } catch (Exception ex) { 155 return false; 156 } 157 } 158 } | Popular Tags |