Search in sources :

Example 1 with HttpMessageNotWritableException

use of cn.taketoday.http.converter.HttpMessageNotWritableException in project today-framework by TAKETODAY.

the class AbstractJsonHttpMessageConverter method writeInternal.

@Override
protected final void writeInternal(Object object, @Nullable Type type, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException {
    Writer writer = getWriter(outputMessage);
    if (this.jsonPrefix != null) {
        writer.append(this.jsonPrefix);
    }
    try {
        writeInternal(object, type, writer);
    } catch (Exception ex) {
        throw new HttpMessageNotWritableException("Could not write JSON: " + ex.getMessage(), ex);
    }
    writer.flush();
}
Also used : HttpMessageNotWritableException(cn.taketoday.http.converter.HttpMessageNotWritableException) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter) HttpMessageNotReadableException(cn.taketoday.http.converter.HttpMessageNotReadableException) IOException(java.io.IOException) HttpMessageNotWritableException(cn.taketoday.http.converter.HttpMessageNotWritableException)

Example 2 with HttpMessageNotWritableException

use of cn.taketoday.http.converter.HttpMessageNotWritableException in project today-framework by TAKETODAY.

the class ResponseEntityExceptionHandlerTests method httpMessageNotWritable.

@Test
public void httpMessageNotWritable() {
    Exception ex = new HttpMessageNotWritableException("");
    testException(ex);
}
Also used : HttpMessageNotWritableException(cn.taketoday.http.converter.HttpMessageNotWritableException) MissingRequestPartException(cn.taketoday.web.bind.resolver.MissingRequestPartException) MissingPathVariableException(cn.taketoday.web.bind.MissingPathVariableException) ServletException(jakarta.servlet.ServletException) HttpRequestMethodNotSupportedException(cn.taketoday.web.HttpRequestMethodNotSupportedException) MissingRequestParameterException(cn.taketoday.web.bind.MissingRequestParameterException) RequestBindingException(cn.taketoday.web.bind.RequestBindingException) ConversionNotSupportedException(cn.taketoday.beans.ConversionNotSupportedException) HttpMessageNotReadableException(cn.taketoday.http.converter.HttpMessageNotReadableException) TypeMismatchException(cn.taketoday.beans.TypeMismatchException) HttpMediaTypeNotSupportedException(cn.taketoday.web.HttpMediaTypeNotSupportedException) HttpMediaTypeNotAcceptableException(cn.taketoday.web.HttpMediaTypeNotAcceptableException) BindException(cn.taketoday.validation.BindException) AsyncRequestTimeoutException(cn.taketoday.web.context.async.AsyncRequestTimeoutException) HttpMessageNotWritableException(cn.taketoday.http.converter.HttpMessageNotWritableException) MethodArgumentNotValidException(cn.taketoday.web.bind.MethodArgumentNotValidException) Test(org.junit.jupiter.api.Test)

Example 3 with HttpMessageNotWritableException

use of cn.taketoday.http.converter.HttpMessageNotWritableException in project today-framework by TAKETODAY.

the class AbstractWireFeedHttpMessageConverter method writeInternal.

@Override
protected void writeInternal(T wireFeed, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException {
    Charset charset = (StringUtils.isNotEmpty(wireFeed.getEncoding()) ? Charset.forName(wireFeed.getEncoding()) : DEFAULT_CHARSET);
    MediaType contentType = outputMessage.getHeaders().getContentType();
    if (contentType != null) {
        contentType = new MediaType(contentType, charset);
        outputMessage.getHeaders().setContentType(contentType);
    }
    WireFeedOutput feedOutput = new WireFeedOutput();
    try {
        Writer writer = new OutputStreamWriter(outputMessage.getBody(), charset);
        feedOutput.output(wireFeed, writer);
    } catch (FeedException ex) {
        throw new HttpMessageNotWritableException("Could not write WireFeed: " + ex.getMessage(), ex);
    }
}
Also used : HttpMessageNotWritableException(cn.taketoday.http.converter.HttpMessageNotWritableException) WireFeedOutput(com.rometools.rome.io.WireFeedOutput) FeedException(com.rometools.rome.io.FeedException) Charset(java.nio.charset.Charset) MediaType(cn.taketoday.http.MediaType) OutputStreamWriter(java.io.OutputStreamWriter) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter)

Example 4 with HttpMessageNotWritableException

use of cn.taketoday.http.converter.HttpMessageNotWritableException in project today-infrastructure by TAKETODAY.

the class AbstractWireFeedHttpMessageConverter method writeInternal.

@Override
protected void writeInternal(T wireFeed, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException {
    Charset charset = (StringUtils.isNotEmpty(wireFeed.getEncoding()) ? Charset.forName(wireFeed.getEncoding()) : DEFAULT_CHARSET);
    MediaType contentType = outputMessage.getHeaders().getContentType();
    if (contentType != null) {
        contentType = new MediaType(contentType, charset);
        outputMessage.getHeaders().setContentType(contentType);
    }
    WireFeedOutput feedOutput = new WireFeedOutput();
    try {
        Writer writer = new OutputStreamWriter(outputMessage.getBody(), charset);
        feedOutput.output(wireFeed, writer);
    } catch (FeedException ex) {
        throw new HttpMessageNotWritableException("Could not write WireFeed: " + ex.getMessage(), ex);
    }
}
Also used : HttpMessageNotWritableException(cn.taketoday.http.converter.HttpMessageNotWritableException) WireFeedOutput(com.rometools.rome.io.WireFeedOutput) FeedException(com.rometools.rome.io.FeedException) Charset(java.nio.charset.Charset) MediaType(cn.taketoday.http.MediaType) OutputStreamWriter(java.io.OutputStreamWriter) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter)

Example 5 with HttpMessageNotWritableException

use of cn.taketoday.http.converter.HttpMessageNotWritableException in project today-infrastructure by TAKETODAY.

the class AbstractJsonHttpMessageConverter method writeInternal.

@Override
protected final void writeInternal(Object object, @Nullable Type type, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException {
    Writer writer = getWriter(outputMessage);
    if (this.jsonPrefix != null) {
        writer.append(this.jsonPrefix);
    }
    try {
        writeInternal(object, type, writer);
    } catch (Exception ex) {
        throw new HttpMessageNotWritableException("Could not write JSON: " + ex.getMessage(), ex);
    }
    writer.flush();
}
Also used : HttpMessageNotWritableException(cn.taketoday.http.converter.HttpMessageNotWritableException) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter) HttpMessageNotReadableException(cn.taketoday.http.converter.HttpMessageNotReadableException) IOException(java.io.IOException) HttpMessageNotWritableException(cn.taketoday.http.converter.HttpMessageNotWritableException)

Aggregations

HttpMessageNotWritableException (cn.taketoday.http.converter.HttpMessageNotWritableException)5 OutputStreamWriter (java.io.OutputStreamWriter)4 Writer (java.io.Writer)4 HttpMessageNotReadableException (cn.taketoday.http.converter.HttpMessageNotReadableException)3 MediaType (cn.taketoday.http.MediaType)2 FeedException (com.rometools.rome.io.FeedException)2 WireFeedOutput (com.rometools.rome.io.WireFeedOutput)2 IOException (java.io.IOException)2 Charset (java.nio.charset.Charset)2 ConversionNotSupportedException (cn.taketoday.beans.ConversionNotSupportedException)1 TypeMismatchException (cn.taketoday.beans.TypeMismatchException)1 BindException (cn.taketoday.validation.BindException)1 HttpMediaTypeNotAcceptableException (cn.taketoday.web.HttpMediaTypeNotAcceptableException)1 HttpMediaTypeNotSupportedException (cn.taketoday.web.HttpMediaTypeNotSupportedException)1 HttpRequestMethodNotSupportedException (cn.taketoday.web.HttpRequestMethodNotSupportedException)1 MethodArgumentNotValidException (cn.taketoday.web.bind.MethodArgumentNotValidException)1 MissingPathVariableException (cn.taketoday.web.bind.MissingPathVariableException)1 MissingRequestParameterException (cn.taketoday.web.bind.MissingRequestParameterException)1 RequestBindingException (cn.taketoday.web.bind.RequestBindingException)1 MissingRequestPartException (cn.taketoday.web.bind.resolver.MissingRequestPartException)1