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:
parent
2ad885d6df
commit
cdca6fff8f
@ -176,6 +176,20 @@ public class RefineServlet extends Butterfly {
|
|||||||
logger.trace("> POST {}", commandKey);
|
logger.trace("> POST {}", commandKey);
|
||||||
command.doPost(request, response);
|
command.doPost(request, response);
|
||||||
logger.trace("< POST {}", commandKey);
|
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 {
|
} else {
|
||||||
response.sendError(405);
|
response.sendError(405);
|
||||||
}
|
}
|
||||||
|
@ -86,6 +86,18 @@ public abstract class Command {
|
|||||||
throw new UnsupportedOperationException();
|
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
|
* Whether each request to this command should be logged. For some commands
|
||||||
* that can get called too frequently, such as GetProcessesCommand, logging
|
* that can get called too frequently, such as GetProcessesCommand, logging
|
||||||
|
@ -90,6 +90,6 @@ public class RefineServletStub extends RefineServlet {
|
|||||||
* @param commandName
|
* @param commandName
|
||||||
*/
|
*/
|
||||||
public void removeCommand( String commandName ){
|
public void removeCommand( String commandName ){
|
||||||
unregisterCommand(commandName);
|
unregisterCommand("core/" + commandName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -71,6 +71,8 @@ public class RefineServletTests extends RefineTest {
|
|||||||
|
|
||||||
final static private String POST = "POST";
|
final static private String POST = "POST";
|
||||||
final static private String GET = "GET";
|
final static private String GET = "GET";
|
||||||
|
final static private String PUT = "PUT";
|
||||||
|
final static private String DELETE = "DELETE";
|
||||||
|
|
||||||
// mocks
|
// mocks
|
||||||
HttpServletRequest request = null;
|
HttpServletRequest request = null;
|
||||||
@ -148,7 +150,7 @@ public class RefineServletTests extends RefineTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//----------------doPost tests-------------------------
|
//----------------doPost tests-------------------------
|
||||||
@Test(enabled=false) // TODO: Fails when run with doGetRegressionTest()
|
@Test
|
||||||
public void doPostRegressionTest(){
|
public void doPostRegressionTest(){
|
||||||
whenGetCommandNameThenReturn(TEST_COMMAND_PATH);
|
whenGetCommandNameThenReturn(TEST_COMMAND_PATH);
|
||||||
whenGetMethodThenReturn(POST);
|
whenGetMethodThenReturn(POST);
|
||||||
@ -161,7 +163,7 @@ public class RefineServletTests extends RefineTest {
|
|||||||
Assert.fail();
|
Assert.fail();
|
||||||
}
|
}
|
||||||
|
|
||||||
verifyGetCommandNameCalled(3);
|
verifyGetCommandNameCalled(2);
|
||||||
try {
|
try {
|
||||||
verify(command,times(1)).doPost(request, response);
|
verify(command,times(1)).doPost(request, response);
|
||||||
} catch (ServletException e) {
|
} catch (ServletException e) {
|
||||||
@ -188,6 +190,88 @@ public class RefineServletTests extends RefineTest {
|
|||||||
verifyError404Called();
|
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----------------
|
//----------------getCommandName tests----------------
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
Loading…
Reference in New Issue
Block a user