From 4f298042a1561b11f7932a73039be8b3d5a948b5 Mon Sep 17 00:00:00 2001 From: knaas Date: Sun, 16 Mar 2008 00:21:23 +0000 Subject: [PATCH] Use standard HttpServletResponse constants for servlet sendError calls. --- .../transport/http/HttpIncomingTransport.java | 2 +- .../transport/http/HttpOutgoingTransport.java | 15 +++++++-------- .../org/jumpmind/symmetric/web/AlertServlet.java | 4 ++-- .../org/jumpmind/symmetric/web/PullServlet.java | 2 +- .../org/jumpmind/symmetric/web/PushServlet.java | 2 +- .../org/jumpmind/symmetric/web/WebConstants.java | 2 -- 6 files changed, 12 insertions(+), 15 deletions(-) diff --git a/symmetric/src/main/java/org/jumpmind/symmetric/transport/http/HttpIncomingTransport.java b/symmetric/src/main/java/org/jumpmind/symmetric/transport/http/HttpIncomingTransport.java index d532bd695f..739723a6a3 100644 --- a/symmetric/src/main/java/org/jumpmind/symmetric/transport/http/HttpIncomingTransport.java +++ b/symmetric/src/main/java/org/jumpmind/symmetric/transport/http/HttpIncomingTransport.java @@ -57,7 +57,7 @@ public BufferedReader open() throws IOException { throw new RegistrationNotOpenException(); } else if (WebConstants.REGISTRATION_REQUIRED == connection.getResponseCode()) { throw new RegistrationRequiredException(); - } else if (WebConstants.CONNECTION_REJECTED == connection.getResponseCode()) { + } else if (HttpServletResponse.SC_SERVICE_UNAVAILABLE == connection.getResponseCode()) { throw new ConnectionRejectedException(); } else if (HttpServletResponse.SC_FORBIDDEN == connection.getResponseCode()) { throw new AuthenticationException(); diff --git a/symmetric/src/main/java/org/jumpmind/symmetric/transport/http/HttpOutgoingTransport.java b/symmetric/src/main/java/org/jumpmind/symmetric/transport/http/HttpOutgoingTransport.java index 4108f4b909..0d8eeea4bd 100644 --- a/symmetric/src/main/java/org/jumpmind/symmetric/transport/http/HttpOutgoingTransport.java +++ b/symmetric/src/main/java/org/jumpmind/symmetric/transport/http/HttpOutgoingTransport.java @@ -35,21 +35,20 @@ import org.jumpmind.symmetric.transport.AuthenticationException; import org.jumpmind.symmetric.transport.ConnectionRejectedException; import org.jumpmind.symmetric.transport.IOutgoingWithResponseTransport; -import org.jumpmind.symmetric.web.WebConstants; public class HttpOutgoingTransport implements IOutgoingWithResponseTransport { - URL url; + private URL url; - BufferedWriter writer; + private BufferedWriter writer; - BufferedReader reader; + private BufferedReader reader; - HttpURLConnection connection; + private HttpURLConnection connection; - int httpTimeout; + private int httpTimeout; - boolean useCompression; + private boolean useCompression; public HttpOutgoingTransport(URL url, int httpTimeout, boolean useCompression) { this.url = url; @@ -104,7 +103,7 @@ public BufferedWriter open() throws IOException { public BufferedReader readResponse() throws IOException { closeWriter(); - if (WebConstants.CONNECTION_REJECTED == connection.getResponseCode()) { + if (HttpServletResponse.SC_SERVICE_UNAVAILABLE == connection.getResponseCode()) { throw new ConnectionRejectedException(); } else if (HttpServletResponse.SC_FORBIDDEN == connection.getResponseCode()) { throw new AuthenticationException(); diff --git a/symmetric/src/main/java/org/jumpmind/symmetric/web/AlertServlet.java b/symmetric/src/main/java/org/jumpmind/symmetric/web/AlertServlet.java index dd4479263b..6cf9bef101 100644 --- a/symmetric/src/main/java/org/jumpmind/symmetric/web/AlertServlet.java +++ b/symmetric/src/main/java/org/jumpmind/symmetric/web/AlertServlet.java @@ -31,6 +31,7 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import org.apache.commons.lang.time.FastDateFormat; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.jumpmind.symmetric.common.Constants; @@ -59,7 +60,7 @@ public class AlertServlet extends AbstractServlet { private static final int MAX_ERRORS = 1000; - private static final String DATE_FORMAT = "yyyy-MM-dd HH:mm:ss"; + private static final FastDateFormat formatter = FastDateFormat.getInstance("yyyy-MM-dd HH:mm:ss"); @Override public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { @@ -107,7 +108,6 @@ private SyndEntry createEntry(String title, String value) { } private String formatDate(Date date) { - SimpleDateFormat formatter = new SimpleDateFormat(DATE_FORMAT); return formatter.format(date); } diff --git a/symmetric/src/main/java/org/jumpmind/symmetric/web/PullServlet.java b/symmetric/src/main/java/org/jumpmind/symmetric/web/PullServlet.java index 27dbf6f53d..572f5d629a 100644 --- a/symmetric/src/main/java/org/jumpmind/symmetric/web/PullServlet.java +++ b/symmetric/src/main/java/org/jumpmind/symmetric/web/PullServlet.java @@ -82,7 +82,7 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws S logger.warn("Socket error while procesing pull data for " + nodeId + ". " + ex.getMessage()); } catch (Exception ex) { logger.error("Error while pulling data for " + nodeId, ex); - resp.sendError(501); + resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED); // SC_INTERNAL_SERVER_ERROR? } } diff --git a/symmetric/src/main/java/org/jumpmind/symmetric/web/PushServlet.java b/symmetric/src/main/java/org/jumpmind/symmetric/web/PushServlet.java index a2275f0740..1101fecb99 100644 --- a/symmetric/src/main/java/org/jumpmind/symmetric/web/PushServlet.java +++ b/symmetric/src/main/java/org/jumpmind/symmetric/web/PushServlet.java @@ -59,7 +59,7 @@ protected void doPut(HttpServletRequest req, HttpServletResponse resp) logger .error("Error while processing pushed data for " + nodeId, ex); - resp.sendError(501); + resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED); // SC_INTERNAL_SERVER_ERROR? } if (logger.isDebugEnabled()) { diff --git a/symmetric/src/main/java/org/jumpmind/symmetric/web/WebConstants.java b/symmetric/src/main/java/org/jumpmind/symmetric/web/WebConstants.java index 06ee223cc3..70678e5bb2 100644 --- a/symmetric/src/main/java/org/jumpmind/symmetric/web/WebConstants.java +++ b/symmetric/src/main/java/org/jumpmind/symmetric/web/WebConstants.java @@ -28,8 +28,6 @@ public class WebConstants { public static final int REGISTRATION_REQUIRED = 657; - public static final int CONNECTION_REJECTED = 503; - public static final String ACK_BATCH_NAME = "batch-"; public static final String ACK_BATCH_OK = "ok";