01: // ProxyRequestObserver.java
02: // $Id: ProxyRequestObserver.java,v 1.16 2003/02/25 16:48:00 ylafon Exp $
03: // (c) COPYRIGHT MIT and INRIA, 1996.
04: // Please first read the full copyright statement in file COPYRIGHT.html
05:
06: package org.w3c.jigsaw.proxy;
07:
08: import java.io.IOException;
09: import java.io.InputStream;
10:
11: import org.w3c.jigsaw.http.Reply;
12:
13: import org.w3c.www.protocol.http.ContinueEvent;
14: import org.w3c.www.protocol.http.Request;
15: import org.w3c.www.protocol.http.RequestEvent;
16: import org.w3c.www.protocol.http.RequestObserver;
17:
18: public class ProxyRequestObserver implements RequestObserver {
19: /**
20: * Our client, ie the one that sends us a request to fulfill.
21: */
22: org.w3c.jigsaw.http.Request request = null;
23: // our calling frame, for dupRequest/Reply (FIXME, should be a static
24: // somewhere
25: ForwardFrame frame = null;
26:
27: /**
28: * Call back, invoked by the HttpManager callback thread.
29: * Each time a request status changes (due to progress in its processing)
30: * this callback gets called, with the new status as an argument.
31: * @param preq The pending request that has made some progress.
32: * @param event The event to broadcast.
33: */
34:
35: public void notifyProgress(RequestEvent event) {
36: Request req = event.request;
37:
38: if (event instanceof ContinueEvent) {
39: // We need to forward this straight to the client:
40: // FIXME 1/ why not using req?
41: // should be check100Continue() or something
42: ContinueEvent cevent = (ContinueEvent) event;
43: if ((req.getMajorVersion() == 1)
44: && (req.getMinorVersion() == 1)) {
45: try {
46: if ((cevent.packet != null) && (frame != null)) {
47: Reply r = null;
48: try {
49: r = frame.dupReply(request, cevent.packet);
50: r.setStream((InputStream) null);
51: } catch (Exception ex) {
52: }
53: request.getClient().sendContinue(r);
54: } else {
55: request.getClient().sendContinue();
56: }
57: } catch (IOException ex) {
58: }
59: }
60: // String exp = request.getExpect();
61: // if (exp != null && (exp.equalsIgnoreCase("100-continue"))) {
62: // try {
63: // request.getClient().sendContinue();
64: // } catch (IOException ex) {
65: // // This will fail latter on too, forget about it (!)
66: // }
67: // }
68: }
69: }
70:
71: public ProxyRequestObserver(org.w3c.jigsaw.http.Request request) {
72: this .request = request;
73: }
74:
75: public ProxyRequestObserver(org.w3c.jigsaw.http.Request request,
76: ForwardFrame frame) {
77: this.request = request;
78: this.frame = frame;
79: }
80: }
|