use of org.motechproject.mds.exception.rest.RestBadBodyFormatException in project motech by motech.
the class MdsRestController method doPost.
private Object doPost(String entityName, String moduleName, String namespace, HttpServletRequest request) {
debugRequest("POST", entityName, moduleName, namespace);
MdsRestFacade restFacade = restFacadeRetriever.getRestFacade(entityName, moduleName, namespace);
try (InputStream bodyInStream = request.getInputStream()) {
return restFacade.create(bodyInStream);
} catch (IOException e) {
throw new RestBadBodyFormatException("Unable to read request body", e);
}
}
use of org.motechproject.mds.exception.rest.RestBadBodyFormatException in project motech by motech.
the class MdsRestController method doPut.
private Object doPut(String entityName, String moduleName, String namespace, HttpServletRequest request) {
debugRequest("PUT", entityName, moduleName, namespace);
MdsRestFacade restFacade = restFacadeRetriever.getRestFacade(entityName, moduleName, namespace);
try (InputStream bodyInStream = request.getInputStream()) {
return restFacade.update(bodyInStream);
} catch (IOException e) {
throw new RestBadBodyFormatException("Unable to read request body", e);
}
}
use of org.motechproject.mds.exception.rest.RestBadBodyFormatException in project motech by motech.
the class MdsRestControllerTest method shouldReturn400ForBadBody.
@Test
public void shouldReturn400ForBadBody() throws Exception {
when(restFacadeRetriever.getRestFacade(ENTITY_NAME, MODULE_NAME, NAMESPACE)).thenReturn(restFacade);
when(restFacade.create(any(InputStream.class))).thenThrow(new RestBadBodyFormatException("bad body"));
mockMvc.perform(post(buildUrl(ENTITY_NAME, MODULE_NAME, NAMESPACE)).body("Bad body".getBytes(Charset.forName("UTF-8")))).andExpect(status().isBadRequest());
verify(restFacade).create(any(InputStream.class));
}
Aggregations