001: // ExtFrame.java
002: // $Id: ExtFrame.java,v 1.6 2007/02/11 10:58:21 ylafon Exp $
003: // (c) COPYRIGHT MIT and INRIA, 1998.
004: // Please first read the full copyright statement in file COPYRIGHT.html
005: package org.w3c.jigsaw.tests;
006:
007: import java.util.Dictionary;
008: import java.util.Enumeration;
009: import java.io.InputStream;
010:
011: import org.w3c.jigsaw.frames.HTTPExtFrame;
012: import org.w3c.jigsaw.http.Reply;
013: import org.w3c.jigsaw.http.Request;
014: import org.w3c.tools.resources.ProtocolException;
015: import org.w3c.tools.resources.ResourceException;
016: import org.w3c.www.http.HeaderValue;
017: import org.w3c.www.http.HttpExtList;
018: import org.w3c.www.http.HttpExt;
019:
020: /**
021: * @version $Revision: 1.6 $
022: * @author Benoît Mahé (bmahe@w3.org)
023: */
024: public class ExtFrame extends HTTPExtFrame {
025:
026: static {
027: String classname = "org.w3c.jigsaw.tests.ExtFrame";
028: registerExtension("http://www.w3.org/exts/test", "GET",
029: classname);
030: registerExtension("http://www.w3.org/exts/test", "HEAD",
031: classname);
032: registerExtension("http://www.w3.org/exts/test2", "GET",
033: classname);
034: registerExtension("http://www.w3.org/exts/test2", "HEAD",
035: classname);
036: }
037:
038: /**
039: * Perform a GET.
040: * @exception org.w3c.tools.resources.ProtocolException if processing
041: * the request failed.
042: * @exception org.w3c.tools.resources.ResourceException if the resource
043: * got a fatal error.
044: */
045: public Reply get(Request request) throws ProtocolException,
046: ResourceException {
047: HttpExtList extl = null;
048: HttpExtList reply_extl = null;
049: Reply reply = super .get(request);
050:
051: //Mandatory End-to-End
052: extl = request.getHttpManExtDecl();
053: if (extl != null) {
054: reply_extl = new HttpExtList(extl);
055: reply.setHttpManExtDecl(reply_extl);
056: HttpExt exts[] = extl.getHttpExts();
057: HttpExt rexts[] = reply_extl.getHttpExts();
058: for (int i = 0; i < exts.length; i++) {
059: HttpExt ext = exts[i];
060: Dictionary headers = request.getExtensionHeaders(ext);
061: Enumeration e = headers.keys();
062: String resp_header = "";
063: while (e.hasMoreElements()) {
064: String name = (String) e.nextElement();
065: HeaderValue value = (HeaderValue) headers.get(name);
066: resp_header += "[" + name + ": "
067: + value.toExternalForm() + "] ";
068: }
069: reply.setExtensionHeader(rexts[i], "receipt",
070: resp_header);
071: }
072: if (rexts.length > 0)
073: reply.setEnd2EndExtensionAcknowledgmentHeader();
074: }
075:
076: //Mandatory Hop-by-Hop
077: extl = request.getHttpCManExtDecl();
078: if (extl != null) {
079: reply_extl = new HttpExtList(extl);
080: reply.setHttpCManExtDecl(reply_extl);
081: HttpExt exts[] = extl.getHttpExts();
082: HttpExt rexts[] = reply_extl.getHttpExts();
083: for (int i = 0; i < exts.length; i++) {
084: HttpExt ext = exts[i];
085: Dictionary headers = request.getExtensionHeaders(ext);
086: Enumeration e = headers.keys();
087: String resp_header = "";
088: while (e.hasMoreElements()) {
089: String name = (String) e.nextElement();
090: HeaderValue value = (HeaderValue) headers.get(name);
091: resp_header += "[" + name + ": "
092: + value.toExternalForm() + "] ";
093: }
094: reply.setExtensionHeader(rexts[i], "receipt",
095: resp_header);
096: }
097: if (rexts.length > 0)
098: reply.setHopByHopExtensionAcknowledgmentHeader();
099: }
100:
101: //Optionnal End-to-End
102: extl = request.getHttpOptExtDecl();
103: if (extl != null) {
104: reply_extl = new HttpExtList(extl);
105: reply.setHttpOptExtDecl(reply_extl);
106: HttpExt exts[] = extl.getHttpExts();
107: HttpExt rexts[] = reply_extl.getHttpExts();
108: for (int i = 0; i < exts.length; i++) {
109: HttpExt ext = exts[i];
110: Dictionary headers = request.getExtensionHeaders(ext);
111: Enumeration e = headers.keys();
112: String resp_header = "";
113: while (e.hasMoreElements()) {
114: String name = (String) e.nextElement();
115: HeaderValue value = (HeaderValue) headers.get(name);
116: resp_header += "[" + name + ": "
117: + value.toExternalForm() + "] ";
118: }
119: reply.setExtensionHeader(rexts[i], "receipt",
120: resp_header);
121: }
122: }
123:
124: //Optionnal Hop-by-Hop
125: extl = request.getHttpCOptExtDecl();
126: if (extl != null) {
127: reply_extl = new HttpExtList(extl);
128: reply.setHttpCOptExtDecl(reply_extl);
129: HttpExt exts[] = extl.getHttpExts();
130: HttpExt rexts[] = reply_extl.getHttpExts();
131: for (int i = 0; i < exts.length; i++) {
132: HttpExt ext = exts[i];
133: Dictionary headers = request.getExtensionHeaders(ext);
134: Enumeration e = headers.keys();
135: String resp_header = "";
136: while (e.hasMoreElements()) {
137: String name = (String) e.nextElement();
138: HeaderValue value = (HeaderValue) headers.get(name);
139: resp_header += "[" + name + ": "
140: + value.toExternalForm() + "] ";
141: }
142: reply.setExtensionHeader(rexts[i], "receipt",
143: resp_header);
144: }
145: }
146:
147: return reply;
148: }
149:
150: /**
151: * Perform a HEAD.
152: * @exception org.w3c.tools.resources.ProtocolException if processing
153: * the request failed.
154: * @exception org.w3c.tools.resources.ResourceException if the resource
155: * got a fatal error.
156: */
157: public Reply head(Request request) throws ProtocolException,
158: ResourceException {
159: Reply reply = null;
160: reply = get(request);
161: reply.setStream((InputStream) null);
162: return reply;
163: }
164:
165: }
|