List of usage examples for org.springframework.beans TypeMismatchException TypeMismatchException
public TypeMismatchException(@Nullable Object value, @Nullable Class<?> requiredType)
From source file:edu.wisc.http.converter.xml.JaxbMarshallingHttpMessageConverter.java
@Override protected Object readFromSource(Class<?> clazz, HttpHeaders headers, Source source) throws IOException { try {//from w ww. j av a 2 s. c o m final Unmarshaller unmarshaller = this.jaxbContext.createUnmarshaller(); Object result = unmarshaller.unmarshal(source, clazz); if (result instanceof JAXBElement<?>) { result = ((JAXBElement<?>) result).getValue(); } if (!clazz.isInstance(result)) { throw new TypeMismatchException(result, clazz); } return result; } catch (JAXBException e) { throw new HttpMessageNotReadableException("Could not read [" + clazz + "]", e); } }
From source file:org.syncope.core.rest.controller.AbstractController.java
protected TaskUtil getTaskUtil(final Task task) { TaskUtil result = (task instanceof PropagationTask) ? TaskUtil.PROPAGATION : (task instanceof NotificationTask) ? TaskUtil.NOTIFICATION : (task instanceof SyncTask) ? TaskUtil.SYNC : (task instanceof SchedTask) ? TaskUtil.SCHED : null; if (result == null) { LOG.error("Task not supported: " + task.getClass().getName()); throw new TypeMismatchException(task.getClass().getName(), TaskUtil.class); }/*from w w w . ja va2 s. co m*/ return result; }
From source file:org.syncope.core.rest.controller.AbstractController.java
protected TaskUtil getTaskUtil(final TaskTO taskTO) { TaskUtil result = (taskTO instanceof PropagationTaskTO) ? TaskUtil.PROPAGATION : (taskTO instanceof SyncTaskTO) ? TaskUtil.SYNC : (taskTO instanceof SchedTaskTO) ? TaskUtil.SCHED : null; if (result == null) { LOG.error("Task not supported: " + taskTO.getClass().getName()); throw new TypeMismatchException(taskTO.getClass().getName(), TaskUtil.class); }//from w w w. j a v a2 s . com return result; }
From source file:org.nobel.highriseapi.mapper.SimpleXmlHttpMessageConverter.java
@Override protected Object readInternal(Class<? extends Object> clazz, HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException { Reader source = new InputStreamReader(inputMessage.getBody(), getCharset(inputMessage.getHeaders())); try {// w w w .j a v a 2 s. c o m Object result = this.serializer.read(clazz, source); if (!clazz.isInstance(result)) { throw new TypeMismatchException(result, clazz); } return result; } catch (Exception ex) { throw new HttpMessageNotReadableException("Could not read [" + clazz + "]", ex); } }
From source file:jails.http.converter.xml.MarshallingHttpMessageConverter.java
@Override protected Object readFromSource(Class<?> clazz, HttpHeaders headers, Source source) throws IOException { Assert.notNull(this.unmarshaller, "Property 'unmarshaller' is required"); try {/*from w ww . jav a 2 s . c om*/ Object result = this.unmarshaller.unmarshal(source); if (!clazz.isInstance(result)) { throw new TypeMismatchException(result, clazz); } return result; } catch (UnmarshallingFailureException ex) { throw new HttpMessageNotReadableException("Could not read [" + clazz + "]", ex); } }
From source file:com.monarchapis.driver.spring.rest.ApiErrorResponseEntityExceptionHandlerTest.java
@Test public void testTypeMismatchException() { performTest(// new TypeMismatchException("test", Object.class), // 400, // "typeMismatch"); }
From source file:org.openmrs.module.radiology.web.controller.PortletsControllerTest.java
/** * @see PortletsController#handleTypeMismatchException(TypeMismatchException) * @verifies populate model with exception text and invalid value *///from w w w . ja va 2 s . co m @Test public void handleTypeMismatchException_shouldPopulateModelWithExceptionTextAndInvalidValue() throws Exception { //given TypeMismatchException typeMismatchException = new TypeMismatchException("13", Date.class); ModelAndView mav = portletsController.handleTypeMismatchException(typeMismatchException); assertThat(mav, is(notNullValue())); assertThat(mav.getModelMap(), hasKey("invalidValue")); String invalidValue = (String) mav.getModelMap().get("invalidValue"); assertThat(invalidValue, is(notNullValue())); assertThat(invalidValue, is("13")); assertThat(mav.getModelMap(), hasKey("exceptionText")); String exceptionText = (String) mav.getModelMap().get("exceptionText"); assertThat(exceptionText, is(notNullValue())); assertThat(exceptionText, is("typeMismatch.java.util.Date")); }
From source file:org.openmrs.module.radiology.web.controller.PortletsControllerTest.java
/** * @see PortletsController#handleTypeMismatchException(TypeMismatchException) * @verifies populate model with exception text *//*from w w w .j ava2 s. c o m*/ @Test public void handleTypeMismatchException_shouldPopulateModelWithExceptionText() throws Exception { //given TypeMismatchException typeMismatchException = new TypeMismatchException("13", Object.class); ModelAndView mav = portletsController.handleTypeMismatchException(typeMismatchException); assertThat(mav, is(notNullValue())); assertThat(mav.getModelMap(), not(hasKey("invalidValue"))); assertThat(mav.getModelMap(), hasKey("exceptionText")); String exceptionText = (String) mav.getModelMap().get("exceptionText"); assertThat(exceptionText, is(notNullValue())); }
From source file:org.jtalks.jcommune.web.exception.PrettyLogExceptionResolverTest.java
@Test public void testLogExceptionWithIncomingTypeMismatchException() throws Exception { Log mockLog = replaceLoggerWithMock(prettyLogExceptionResolver); MockHttpServletRequest request = new MockHttpServletRequest("GET", "/"); TypeMismatchException typeMismatchException = new TypeMismatchException("Not a number", Number.class); String logMessage = String.format("[%s][%s][%s][%s]", request.getMethod(), request.getRequestURL().toString(), request.getHeader("Cookie"), typeMismatchException.getMessage()); request.setContent("".getBytes()); prettyLogExceptionResolver.logException(typeMismatchException, request); verify(mockLog).info(logMessage);//from ww w.ja v a2s . c o m }