Skip to content

Commit

Permalink
Use standard HttpServletResponse constants for servlet sendError calls.
Browse files Browse the repository at this point in the history
  • Loading branch information
knaas committed Mar 16, 2008
1 parent c3309dc commit 4f29804
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 15 deletions.
Expand Up @@ -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();
Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
}

Expand Down
Expand Up @@ -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?
}
}

Expand Down
Expand Up @@ -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()) {
Expand Down
Expand Up @@ -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";
Expand Down

0 comments on commit 4f29804

Please sign in to comment.