1 28 29 package HTTPClient; 30 31 import java.io.IOException ; 32 import java.net.ProtocolException ; 33 34 35 42 43 class DefaultModule implements HTTPClientModule, GlobalConstants 44 { 45 46 private int req_timeout_retries; 47 48 49 51 54 DefaultModule() 55 { 56 req_timeout_retries = 3; 57 } 58 59 60 62 65 public int requestHandler(Request req, Response[] resp) 66 { 67 return REQ_CONTINUE; 68 } 69 70 71 74 public void responsePhase1Handler(Response resp, RoRequest req) 75 { 76 } 77 78 79 82 public int responsePhase2Handler(Response resp, Request req) 83 throws IOException 84 { 85 86 87 int sts = resp.getStatusCode(); 88 switch(sts) 89 { 90 case 408: 92 if (req_timeout_retries-- == 0 || req.getStream() != null) 93 { 94 if (DebugMods) 95 System.err.println("DefM: Status " + sts + " " + 96 resp.getReasonLine() + " not handled - " + 97 "maximum number of retries exceeded"); 98 99 return RSP_CONTINUE; 100 } 101 else 102 { 103 if (DebugMods) 104 System.err.println("DefM: Handling " + sts + " " + 105 resp.getReasonLine() + " - " + 106 "resending request"); 107 108 return RSP_REQUEST; 109 } 110 111 case 411: if (req.getStream() != null && 113 req.getStream().getLength() == -1) 114 return RSP_CONTINUE; 115 116 try { resp.getInputStream().close(); } 117 catch (IOException ioe) { } 118 if (req.getData() != null) 119 throw new ProtocolException ("Received status code 411 even"+ 120 " though Content-Length was sent"); 121 122 if (DebugMods) 123 System.err.println("DefM: Handling " + sts + " " + 124 resp.getReasonLine() + " - resending " + 125 "request with 'Content-length: 0'"); 126 127 req.setData(new byte[0]); return RSP_REQUEST; 129 130 case 505: return RSP_CONTINUE; 132 133 default: 134 return RSP_CONTINUE; 135 } 136 } 137 138 139 142 public void responsePhase3Handler(Response resp, RoRequest req) 143 { 144 } 145 146 147 150 public void trailerHandler(Response resp, RoRequest req) 151 { 152 } 153 } 154 155 | Popular Tags |