Permalink
Browse files

[Jeeves] properly take into account HTTP codes

Now that the security-proxy proxifies HTTP responses even if the status
code is different from 200 OK, it is possible from GeoNetwork to send a
default image (if not found), with the 404 status code. But Jeeves
handles HTTP codes only in case of exception / error reportings.

This patch allows to take into account the error code provided by
GeoNetwork into Jeeves. For example if an image is not found by the GN's
resources.get service, it is possible to send to the client a 404
response with an image as part of the body.

This allows to track down broken images in the ComputeDeadLinks service
correctly.

This patch has been tested on
http://sdi.qualitystreetmap.org/geonetwork/ before commiting.
  • Loading branch information...
1 parent b260255 commit da743120dc86f327de77aac6fa1c127168dbf2bf @pmauduit pmauduit committed Mar 3, 2012
@@ -537,9 +537,18 @@ private String dispatchOutput(ServiceRequest req, ServiceContext context,
{
info(" -> dispatching to output for : "+ req.getService());
+ String strStatusCode = err.getAttributeValue(ConfigFile.Error.Attr.STATUS_CODE);
+ int statusCode;
+ try {
+ if (strStatusCode) {
+ statusCode = Integer.parseInt(strStatusCode);
+ } catch (Exception e)
+ statusCode = 200;
+ }
+ req.setStatusCode(statusCode);
+
//------------------------------------------------------------------------
//--- check if the output page is a foward
-
if (outPage != null)
{
String sForward = outPage.getForward();
@@ -93,15 +93,7 @@ public Element exec(Element params, ServiceContext context) throws Exception
context.info("File is : " +file);
if (!file.exists()) {
- // serving "broken-file.png" instead of giving back
- // an internal server error (500) after proxying by the
- // security-proxy
-
- // TODO : The security-proxy will intercept 404 errors
- // so we have to pass it as a 200 (ok) status code
- // which obviously is wrong (broken images won't appear
- // anymore in the "broken links" admin page)
- return BinaryFile.encode(200, context.getAppPath() + "/images/file_broken.png");
+ return BinaryFile.encode(404, context.getAppPath() + "/images/file_broken.png");
//throw new ResourceNotFoundEx(fname);
}
GeonetContext gc = (GeonetContext) context.getHandlerContext(Geonet.CONTEXT_NAME);

0 comments on commit da74312

Please sign in to comment.