boolean doit = true;
LookupState ls = new LookupState(request);
LookupResult lr = new LookupResult(root.getResourceReference());
try {
if ( root.lookup(ls, lr) ) {
ResourceReference target = lr.getTarget();
if (target != null) {
try {
// this is plain ugly and won't work for proxy
// not based on this resource
// do we need another way to to this?
FramedResource fr = (FramedResource) target.lock();
Class cff = Class.forName(
"org.w3c.jigsaw.proxy.ForwardFrame");
doit = (fr.getFrameReference(cff) == null);
} catch (Exception ex) {
// fail miserably to the fallback
} finally {
target.unlock();
}
}
}
} catch (Exception ex) {};
if (doit) {
Reply reply = request.makeReply(HTTP.OK);
reply.setNoCache(); // don't cache this
reply.setMaxAge(-1);
// Dump the request as the body
// Removed unused headers:
// FIXME should be something else for chuncked stream
ByteArrayOutputStream ba = new ByteArrayOutputStream();
try {
reply.setContentType(new MimeType("message/http"));
request.dump(ba);
reply.setContentLength(ba.size());
} catch (Exception ex) {
ex.printStackTrace();
}
reply.setStream(new ByteArrayInputStream(ba.toByteArray()));
return reply;
}
}
// Create a lookup state, and a lookup result:
ProtocolException error = null;
LookupState ls = null;
LookupResult lr = null;
// Run the lookup algorithm of root resource:
// catch exception to get error (FIXME)
try {
lr = new LookupResult(root.getResourceReference());
ls = new LookupState(request);
if ( root.lookup(ls, lr) ) {
if (lr.hasReply())
return lr.getReply();
}
} catch (ProtocolException ex) {
error = ex;
} catch (Exception ex) {
/*
* We have a problem here, the error can be a configuration
* or resource/extension problem, and it should be a
* 5xx error, or it is a client side error and it should be
* a 4xx error, ex, try with "Authorization:" and it fails.
* For now we will reply with a 400, but with a FIXME
*/
Reply err = request.makeReply(HTTP.BAD_REQUEST);
err.setContent("<html><head><title>Bad Request</title></head>\n"
+ "<body><p>The server was not able to "
+ "understand this request</p></body></html>");
error = new ProtocolException(err);
}
// Let the target resource perform the method
ResourceReference target = lr.getTarget();
Reply reply = null;
ResourceFilter filters[] = lr.getFilters();
int infilter = 0;
if (error == null) {
//call the ingoing filters:
try {
// temporary target resource !!! WARNING
request.setTargetResource(target);
if ( filters != null ) {
for ( ; infilter < filters.length ; infilter++ ) {
if ( filters[infilter] == null )
continue;
reply = (Reply)filters[infilter].
ingoingFilter(request,
filters,
infilter);
if ( reply != null ) {
return reply;
}
}
}
} catch (ProtocolException ex) {
error = ex;
}
//perform the request:
if ((error == null) && (target != null)) {
request.setFilters(filters, infilter);
request.setTargetResource(target);
try {
FramedResource res = (FramedResource)target.lock();
reply = (Reply) res.perform(request);
if (reply == null) {
reply = request.makeReply(HTTP.NOT_FOUND);
if (uri_error) {
reply.setContent("<html><head><title>Not Found" +
"</title></head>\n"+
"<body><h1>Invalid" +
" URL</h1><p>The URL <b>"+
request.getURL()+
"</b> that you requested is not" +
" available "+
" for this protocol.</body>\n"
+"</html>");
} else {
reply.setContent("<html><head><title>Not Found" +
"</title></head>\n"+
"<body><h1>Invalid" +
" URL</h1><p>The URL" +
"</b> that you requested is not" +
" available "+
" for this protocol.</body>\n"
+"</html>");
}
reply.setContentType(org.w3c.www.mime.MimeType.
TEXT_HTML);
}
} catch (InvalidResourceException ex) {
//FIXME
reply = request.makeReply(HTTP.NOT_FOUND);
if (uri_error) {
reply.setContent("<html><head><title>Not"+
" Found</title>"+
"</head><body><b>The URL <b>"+
request.getURL()+
"</b> that you requested is not " +
"available, "+
" probably deleted.</body></html>");
} else {
reply.setContent("<html><head><title>Not"+
" Found</title>"+
"</head><body><b>The URL"+
" that you requested is not " +
"available, "+
" probably deleted.</body></html>");
}
reply.setContentType(org.w3c.www.mime.MimeType.TEXT_HTML);
} finally {
target.unlock();
}
} else {
reply = request.makeReply(HTTP.NOT_FOUND);
if (uri_error) {
reply.setContent("<html><head>\n"+