Commits

Sam Adams committed d5e1358

Minor code tidying and extra logging

  • Participants
  • Parent commits 59c68b5

Comments (0)

Files changed (5)

File chempound-webapp/src/main/java/net/chempound/webapp/content/CollectionResource.java

 import java.io.InputStream;
 
 import static org.restlet.data.MediaType.APPLICATION_ATOM;
+import static org.restlet.engine.http.header.HeaderConstants.ATTRIBUTE_HEADERS;
 
 /**
  * @author Sam Adams
     }
 
     private String getSlug() {
-        final Form headers = (Form) getRequestAttributes().get("org.restlet.http.headers");
+        final Form headers = (Form) getRequestAttributes().get(ATTRIBUTE_HEADERS);
         return headers.getFirstValue("Slug", IGNORE_CASE);
     }
 
     protected boolean isInProgress() throws SwordError {
-        final Form headers = (Form) getRequestAttributes().get("org.restlet.http.headers");
+        final Form headers = (Form) getRequestAttributes().get(ATTRIBUTE_HEADERS);
         final String iph = headers.getFirstValue("In-Progress", IGNORE_CASE);
 
         boolean inProgress = false; // default value
     }
 
     private String getPackaging() {
-        final Form headers = (Form) getRequestAttributes().get("org.restlet.http.headers");
+        final Form headers = (Form) getRequestAttributes().get(ATTRIBUTE_HEADERS);
         String packaging = headers.getFirstValue("Packaging", IGNORE_CASE);
         if (packaging == null || "".equals(packaging)) {
             packaging = UriRegistry.PACKAGE_BINARY;
         if (getRequestEntity().getDisposition() != null) {
             filename = getRequestEntity().getDisposition().getFilename();
         } else {
-            final Form headers = (Form) getRequestAttributes().get("org.restlet.http.headers");
+            final Form headers = (Form) getRequestAttributes().get(ATTRIBUTE_HEADERS);
             final String cd = headers.getFirstValue("Content-Disposition", IGNORE_CASE);
             if (cd != null) {
                 final int i = cd.indexOf("filename=");

File chempound-webapp/src/main/java/net/chempound/webapp/content/ResourceMapResource.java

 import org.restlet.data.MediaType;
 import org.restlet.data.Reference;
 import org.restlet.data.Status;
+import org.restlet.engine.http.header.HeaderConstants;
 import org.restlet.ext.json.JsonRepresentation;
 import org.restlet.representation.Representation;
 import org.restlet.representation.Variant;
 import java.util.Iterator;
 import java.util.Map;
 
+import static org.restlet.engine.http.header.HeaderConstants.ATTRIBUTE_HEADERS;
+
 /**
  * @author Sam Adams
  */
     public Representation getHtml() throws Exception {
         final SplashPageGenerator splashPageGenerator = splashPageGeneratorProvider.get();
         final Representation representation = splashPageGenerator.createSplashPage(aggregationUri);
-        addPickbackHeader();
+        addPingbackHeader();
         return representation;
     }
 
-    private void addPickbackHeader() {
-        Form headers = (Form) getResponseAttributes().get("org.restlet.http.headers");
-        if (headers == null) {
-            headers = new Form();
-            getResponseAttributes().put("org.restlet.http.headers", headers);
-        }
-        headers.set("X-Pingback", pingbackUrl.toString());
-    }
-
     @Get("json")
     public Representation getJson() {
         final JSONObject obj = createJson();
         return getRdf(MediaType.TEXT_RDF_N3);
     }
 
+    private void addPingbackHeader() {
+        Form headers = (Form) getResponseAttributes().get(ATTRIBUTE_HEADERS);
+        if (headers == null) {
+            headers = new Form();
+            getResponseAttributes().put(ATTRIBUTE_HEADERS, headers);
+        }
+        headers.set("X-Pingback", pingbackUrl.toString());
+    }
+
     private Representation getRdf(final MediaType mediaType) {
         final Model model = tripleStore.getModel(aggregationUri);
         final String lang = RDF_LANG_MAP.get(mediaType);

File chempound-webapp/src/main/java/net/chempound/webapp/pingback/PingbackFault.java

 
     GENERIC_FAULT(0, "Error processing request."),
     SOURCE_URI_DOES_NOT_EXIST(16, "The source URI does not exist."),
-    SOURCE_URI_DOES_NOT_LINK_TO_TARGET(17, ""),
+    SOURCE_URI_DOES_NOT_LINK_TO_TARGET(17, "The source URI does not contain a link to the target URI."),
     TARGET_URI_DOES_NOT_EXIST(32, "The specified target URI does not exist."),
     TARGET_URI_INVALID(33, "The specified target URI cannot be used as a target."),
     ALREADY_REGISTERED(48, "The pingback has already been registered."),

File chempound-webapp/src/main/java/net/chempound/webapp/pingback/PingbackResource.java

     private Document handleXmlRpc(final Representation xml) {
         try {
             return handlePayload(readPostXml(xml));
-        } catch (PingbackException exception) {
-            return prepareFaultResponse(exception.getFault());
-        } catch (Exception exception) {
+        } catch (PingbackException e) {
+            return prepareFaultResponse(e.getFault());
+        } catch (Exception e) {
+            LOG.warn("Error handling pingback", e);
             return prepareFaultResponse(PingbackFault.GENERIC_FAULT);
         }
     }

File chempound-webapp/src/main/java/net/chempound/webapp/sword/CollectionResource.java

 import java.io.InputStream;
 
 import static org.restlet.data.MediaType.APPLICATION_ATOM;
+import static org.restlet.engine.http.header.HeaderConstants.ATTRIBUTE_HEADERS;
 
 /**
  * @author sea36
     }
 
     private String getSlug() {
-        final Form headers = (Form) getRequestAttributes().get("org.restlet.http.headers");
+        final Form headers = (Form) getRequestAttributes().get(ATTRIBUTE_HEADERS);
         return headers.getFirstValue("Slug", IGNORE_CASE);
     }
 
     protected boolean isInProgress() throws SwordError {
-        final Form headers = (Form) getRequestAttributes().get("org.restlet.http.headers");
+        final Form headers = (Form) getRequestAttributes().get(ATTRIBUTE_HEADERS);
         final String iph = headers.getFirstValue("In-Progress", IGNORE_CASE);
 
         boolean inProgress = false; // default value
     }
 
     private String getPackaging() {
-        final Form headers = (Form) getRequestAttributes().get("org.restlet.http.headers");
+        final Form headers = (Form) getRequestAttributes().get(ATTRIBUTE_HEADERS);
         String packaging = headers.getFirstValue("Packaging", IGNORE_CASE);
         if (packaging == null || "".equals(packaging)) {
             packaging = UriRegistry.PACKAGE_BINARY;
         if (getRequestEntity().getDisposition() != null) {
             filename = getRequestEntity().getDisposition().getFilename();
         } else {
-            final Form headers = (Form) getRequestAttributes().get("org.restlet.http.headers");
+            final Form headers = (Form) getRequestAttributes().get(ATTRIBUTE_HEADERS);
             final String cd = headers.getFirstValue("Content-Disposition", IGNORE_CASE);
             if (cd != null) {
                 final int i = cd.indexOf("filename=");