Example usage for org.springframework.http.converter HttpMessageNotWritableException HttpMessageNotWritableException

List of usage examples for org.springframework.http.converter HttpMessageNotWritableException HttpMessageNotWritableException

Introduction

In this page you can find the example usage for org.springframework.http.converter HttpMessageNotWritableException HttpMessageNotWritableException.

Prototype

public HttpMessageNotWritableException(String msg, @Nullable Throwable cause) 

Source Link

Document

Create a new HttpMessageNotWritableException.

Usage

From source file:com.careerly.common.support.msgconverter.JacksonHttpMessageConverter.java

@Override
protected void writeInternal(Object object, HttpOutputMessage outputMessage)
        throws IOException, HttpMessageNotWritableException {

    if (!prettyPrinting) {
        super.writeInternal(object, outputMessage);
        return;//  ww  w . j a v  a2  s  .  co  m
    }

    JsonEncoding encoding = getJsonEncoding(outputMessage.getHeaders().getContentType());
    JsonGenerator jsonGenerator = getObjectMapper().getJsonFactory()
            .createJsonGenerator(outputMessage.getBody(), encoding).useDefaultPrettyPrinter();
    try {
        getObjectMapper().writeValue(jsonGenerator, object);
    } catch (IOException ex) {
        throw new HttpMessageNotWritableException("Could not write JSON: " + ex.getMessage(), ex);
    }
}

From source file:be.wolkmaan.klimtoren.shared.ViewAwareJsonMessageConverter.java

protected void writeView(DataView view, HttpOutputMessage outputMessage)
        throws IOException, HttpMessageNotWritableException {
    JsonEncoding encoding = getJsonEncoding(outputMessage.getHeaders().getContentType());
    ObjectMapper mapper = getMapperForView(view.getView());
    JsonGenerator jsonGenerator = mapper.getJsonFactory().createJsonGenerator(outputMessage.getBody(),
            encoding);// w w w. j a v a  2  s. c  om
    try {
        mapper.writeValue(jsonGenerator, view.getData());
    } catch (IOException ex) {
        throw new HttpMessageNotWritableException("Could not write JSON: " + ex.getMessage(), ex);
    }
}

From source file:edu.wisc.http.converter.xml.JaxbMarshallingHttpMessageConverter.java

@Override
protected void writeToResult(Object o, HttpHeaders headers, Result result) throws IOException {
    try {/* w  ww . jav a2 s .  c o  m*/
        final Marshaller marshaller = this.jaxbContext.createMarshaller();
        marshaller.marshal(o, result);
    } catch (JAXBException e) {
        throw new HttpMessageNotWritableException("Could not write [" + o + "]", e);
    }
}

From source file:com.iflytek.edu.cloud.frame.spring.MappingJackson2HttpMessageConverterExt.java

@Override
protected void writeInternal(Object object, HttpOutputMessage outputMessage)
        throws IOException, HttpMessageNotWritableException {
    outputMessage.getHeaders().setContentType(MediaType.parseMediaType("application/json"));
    JsonEncoding encoding = getJsonEncoding(outputMessage.getHeaders().getContentType());
    JsonGenerator jsonGenerator = this.getObjectMapper().getFactory().createGenerator(outputMessage.getBody(),
            encoding);/*from w  w  w  .  j a va 2  s . c om*/

    // A workaround for JsonGenerators not applying serialization features
    // https://github.com/FasterXML/jackson-databind/issues/12
    if (this.getObjectMapper().isEnabled(SerializationFeature.INDENT_OUTPUT)) {
        jsonGenerator.useDefaultPrettyPrinter();
    }

    String callBack = (String) RestContextHolder.getContext().getParam(Constants.SYS_PARAM_KEY_CALLBACK);
    try {
        if (StringUtils.hasText(callBack)) {
            String json = this.getObjectMapper().writeValueAsString(object);
            json = callBack + "( " + json + " )";
            outputMessage.getBody().write(json.getBytes(Charset.forName("UTF-8")));
            outputMessage.getBody().flush();
        } else {
            this.getObjectMapper().writeValue(jsonGenerator, object);
        }
    } catch (JsonProcessingException ex) {
        throw new HttpMessageNotWritableException("Could not write JSON: " + ex.getMessage(), ex);
    }
}

From source file:de.escalon.hypermedia.spring.uber.UberJackson2HttpMessageConverter.java

@Override
protected void writeInternal(Object t, HttpOutputMessage outputMessage)
        throws IOException, HttpMessageNotWritableException {

    UberMessageModel uberModel = new UberMessageModel(t);
    JsonEncoding encoding = getJsonEncoding(outputMessage.getHeaders().getContentType());
    JsonGenerator jsonGenerator = this.objectMapper.getFactory().createGenerator(outputMessage.getBody(),
            encoding);/* w w  w  . j av  a 2 s . co  m*/

    // A workaround for JsonGenerators not applying serialization features
    // https://github.com/FasterXML/jackson-databind/issues/12
    if (this.objectMapper.isEnabled(SerializationFeature.INDENT_OUTPUT)) {
        jsonGenerator.useDefaultPrettyPrinter();
    }

    try {
        this.objectMapper.writeValue(jsonGenerator, uberModel);
    } catch (JsonProcessingException ex) {
        throw new HttpMessageNotWritableException("Could not write JSON: " + ex.getMessage(), ex);
    }

}

From source file:com.github.hateoas.forms.spring.uber.UberJackson2HttpMessageConverter.java

@Override
protected void writeInternal(Object t, HttpOutputMessage outputMessage)
        throws IOException, HttpMessageNotWritableException {

    UberMessageModel uberModel = new UberMessageModel(t);
    JsonEncoding encoding = getJsonEncoding(outputMessage.getHeaders().getContentType());
    JsonGenerator jsonGenerator = this.objectMapper.getFactory().createGenerator(outputMessage.getBody(),
            encoding);//from  w  w w.  j  a va 2  s .c  o  m

    // A workaround for JsonGenerators not applying serialization features
    // https://github.com/FasterXML/jackson-databind/issues/12
    if (this.objectMapper.isEnabled(SerializationFeature.INDENT_OUTPUT)) {
        jsonGenerator.useDefaultPrettyPrinter();
    }

    try {
        this.objectMapper.writeValue(jsonGenerator, uberModel);
    } catch (JsonProcessingException ex) {
        throw new HttpMessageNotWritableException("Could not write JSON: " + ex.getMessage(), ex);
    }
}

From source file:sys.core.jackson.MappingJacksonHttpMessageConverter.java

@Override
protected void writeInternal(Object object, HttpOutputMessage outputMessage)
        throws IOException, HttpMessageNotWritableException {
    System.out.println("Entro al writeInternal");
    JsonEncoding encoding = getJsonEncoding(outputMessage.getHeaders().getContentType());
    JsonGenerator jsonGenerator = this.objectMapper.getJsonFactory()
            .createJsonGenerator(outputMessage.getBody(), encoding);
    try {/*  w  w w  . j  a v a2 s  . c om*/
        if (this.prefixJson) {
            jsonGenerator.writeRaw("{} && ");
        }
        this.objectMapper.writeValue(jsonGenerator, object);
    } catch (JsonProcessingException ex) {
        throw new HttpMessageNotWritableException("Could not write JSON: " + ex.getMessage(), ex);
    }
}

From source file:org.hobsoft.symmetry.spring.SymmetryHttpMessageConverter.java

@Override
protected void writeInternal(T component, HttpOutputMessage outputMessage) throws IOException {
    OutputStream bodyStream = outputMessage.getBody();
    Charset charset = getCharset(outputMessage);
    Writer bodyWriter = new OutputStreamWriter(bodyStream, charset);

    try {/*from  w w  w .  j a  va2s.  c o  m*/
        reflector.reflect(component, bodyWriter);
    } catch (ReflectorException exception) {
        throw new HttpMessageNotWritableException("Error writing component", exception);
    }

    bodyWriter.flush();
}

From source file:cn.loveapple.service.controller.contents.action.SiteController.java

@RequestMapping(value = "core/registComplete", method = RequestMethod.POST)
public String registComplete(HttpSession session, HttpServletRequest request, Model model, Locale locale) {

    SiteForm siteForm = (SiteForm) session.getAttribute(FORM);
    if (siteForm == null) {
        try {//from  www .  j a  v a  2  s  . c  o  m
            throw new NoSuchRequestHandlingMethodException(request);
        } catch (NoSuchRequestHandlingMethodException e) {
            throw new HttpMessageNotWritableException(e.getMessage(), e);
        }
    }
    /*LoveappleMemberModel member = (LoveappleMemberModel) session.getAttribute(LOVEAPPLE_MEMBER_TMP);
            
    if(member == null){
       try {
    throw new NoSuchRequestHandlingMethodException(request);
       } catch (NoSuchRequestHandlingMethodException e) {
    throw new HttpMessageNotWritableException(e.getMessage(), e);
       }
    }
    member = memberCoreService.insertLoveappleMember(member);
    if(member == null){
       throw new HttpMessageNotWritableException("can not regist member. "
       + ToStringBuilder.reflectionToString(session.getAttribute(LOVEAPPLE_MEMBER_TMP)));
    }
    session.removeAttribute(FORM);
    session.removeAttribute(LOVEAPPLE_MEMBER_TMP);
            
    // ??
    try {
       MimeMessage message = memberCoreService.sendRegistCertificationMail(member);
       log.info("Send mail: " + ToStringBuilder.reflectionToString(message));
    } catch (MailException e) {
       log.warn("?", e);
    }*/

    return "redirect:/member/certification";
}