Search in sources :

Example 1 with RestBadBodyFormatException

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);
    }
}
Also used : RestBadBodyFormatException(org.motechproject.mds.exception.rest.RestBadBodyFormatException) InputStream(java.io.InputStream) MdsRestFacade(org.motechproject.mds.rest.MdsRestFacade) IOException(java.io.IOException)

Example 2 with RestBadBodyFormatException

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);
    }
}
Also used : RestBadBodyFormatException(org.motechproject.mds.exception.rest.RestBadBodyFormatException) InputStream(java.io.InputStream) MdsRestFacade(org.motechproject.mds.rest.MdsRestFacade) IOException(java.io.IOException)

Example 3 with RestBadBodyFormatException

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));
}
Also used : RestBadBodyFormatException(org.motechproject.mds.exception.rest.RestBadBodyFormatException) InputStream(java.io.InputStream) Test(org.junit.Test)

Aggregations

InputStream (java.io.InputStream)3 RestBadBodyFormatException (org.motechproject.mds.exception.rest.RestBadBodyFormatException)3 IOException (java.io.IOException)2 MdsRestFacade (org.motechproject.mds.rest.MdsRestFacade)2 Test (org.junit.Test)1