Checked in Shardul Deo's patch from

http://groups.google.com/group/google-refine-dev/browse_thread/thread/5222a68396c56405
to support HTTP PUT and DELETE.

git-svn-id: http://google-refine.googlecode.com/svn/trunk@2387 7d457c2a-affb-35e4-300a-418c747d4874
This commit is contained in:
David Huynh 2011-11-25 03:48:03 +00:00
parent 2ad885d6df
commit cdca6fff8f
4 changed files with 113 additions and 3 deletions

View File

@ -176,6 +176,20 @@ public class RefineServlet extends Butterfly {
logger.trace("> POST {}", commandKey);
command.doPost(request, response);
logger.trace("< POST {}", commandKey);
} else if (request.getMethod().equals("PUT")) {
if (!logger.isTraceEnabled() && command.logRequests()) {
logger.info("PUT {}", request.getPathInfo());
}
logger.trace("> PUT {}", commandKey);
command.doPut(request, response);
logger.trace("< PUT {}", commandKey);
} else if (request.getMethod().equals("DELETE")) {
if (!logger.isTraceEnabled() && command.logRequests()) {
logger.info("DELETE {}", request.getPathInfo());
}
logger.trace("> DELETE {}", commandKey);
command.doDelete(request, response);
logger.trace("< DELETE {}", commandKey);
} else {
response.sendError(405);
}

View File

@ -86,6 +86,18 @@ public abstract class Command {
throw new UnsupportedOperationException();
};
public void doPut(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
throw new UnsupportedOperationException();
};
public void doDelete(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
throw new UnsupportedOperationException();
};
/**
* Whether each request to this command should be logged. For some commands
* that can get called too frequently, such as GetProcessesCommand, logging

View File

@ -90,6 +90,6 @@ public class RefineServletStub extends RefineServlet {
* @param commandName
*/
public void removeCommand( String commandName ){
unregisterCommand(commandName);
unregisterCommand("core/" + commandName);
}
}

View File

@ -71,6 +71,8 @@ public class RefineServletTests extends RefineTest {
final static private String POST = "POST";
final static private String GET = "GET";
final static private String PUT = "PUT";
final static private String DELETE = "DELETE";
// mocks
HttpServletRequest request = null;
@ -148,7 +150,7 @@ public class RefineServletTests extends RefineTest {
}
//----------------doPost tests-------------------------
@Test(enabled=false) // TODO: Fails when run with doGetRegressionTest()
@Test
public void doPostRegressionTest(){
whenGetCommandNameThenReturn(TEST_COMMAND_PATH);
whenGetMethodThenReturn(POST);
@ -161,7 +163,7 @@ public class RefineServletTests extends RefineTest {
Assert.fail();
}
verifyGetCommandNameCalled(3);
verifyGetCommandNameCalled(2);
try {
verify(command,times(1)).doPost(request, response);
} catch (ServletException e) {
@ -188,6 +190,88 @@ public class RefineServletTests extends RefineTest {
verifyError404Called();
}
//----------------doPut tests-------------------------
@Test
public void doPutRegressionTest(){
whenGetCommandNameThenReturn(TEST_COMMAND_PATH);
whenGetMethodThenReturn(PUT);
try {
SUT.wrapService(request, response);
} catch (ServletException e) {
Assert.fail();
} catch (IOException e) {
Assert.fail();
}
verifyGetCommandNameCalled(2);
try {
verify(command,times(1)).doPut(request, response);
} catch (ServletException e) {
Assert.fail();
} catch (IOException e) {
Assert.fail();
}
}
@Test
public void doPutReturns404WhenCommandNotFound(){
whenGetCommandNameThenReturn(BAD_COMMAND_PATH);
whenGetMethodThenReturn(PUT);
try {
SUT.wrapService(request, response);
} catch (ServletException e) {
Assert.fail();
} catch (IOException e) {
Assert.fail();
}
verifyGetCommandNameCalled(2);
verifyError404Called();
}
//----------------doDelete tests-------------------------
@Test
public void doDeleteRegressionTest(){
whenGetCommandNameThenReturn(TEST_COMMAND_PATH);
whenGetMethodThenReturn(DELETE);
try {
SUT.wrapService(request, response);
} catch (ServletException e) {
Assert.fail();
} catch (IOException e) {
Assert.fail();
}
verifyGetCommandNameCalled(2);
try {
verify(command,times(1)).doDelete(request, response);
} catch (ServletException e) {
Assert.fail();
} catch (IOException e) {
Assert.fail();
}
}
@Test
public void doDeleteReturns404WhenCommandNotFound(){
whenGetCommandNameThenReturn(BAD_COMMAND_PATH);
whenGetMethodThenReturn(DELETE);
try {
SUT.wrapService(request, response);
} catch (ServletException e) {
Assert.fail();
} catch (IOException e) {
Assert.fail();
}
verifyGetCommandNameCalled(2);
verifyError404Called();
}
//----------------getCommandName tests----------------
@Test