Java 类org.springframework.http.converter.HttpMessageNotWritableException 实例源码

项目:linux-memory-monitor    文件:CallbackMappingJackson2HttpMessageConverter.java   
@Override   //Object就是springmvc返回值
protected void writeInternal(Object object, HttpOutputMessage outputMessage) throws IOException,
        HttpMessageNotWritableException {
    // 从threadLocal中获取当前的Request对象
    HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder
            .currentRequestAttributes()).getRequest();

    String callbackParam = request.getParameter(callbackName);
    if (StringUtils.isEmpty(callbackParam)) {
        // 没有找到callback参数,直接返回json数据
        super.writeInternal(object, outputMessage);
    } else {
        JsonEncoding encoding = getJsonEncoding(outputMessage.getHeaders().getContentType());
        try {
            //将对象转换为json串,然后用回调方法包括起来
            String result = callbackParam + "(" + super.getObjectMapper().writeValueAsString(object)
                    + ");";
            IOUtils.write(result, outputMessage.getBody(), encoding.getJavaName());
        } catch (JsonProcessingException ex) {
            throw new HttpMessageNotWritableException("Could not write JSON: " + ex.getMessage(), ex);
        }
    }

}
项目:Server_Management_Common_eSightApi    文件:GsonHttpMessageConverter.java   
protected void writeInternal(Object o, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException {


  Charset charset = this.getCharset(outputMessage.getHeaders());
  OutputStreamWriter writer = new OutputStreamWriter(outputMessage.getBody(), charset);

  try {
    if(this.jsonPrefix != null) {
      writer.append(this.jsonPrefix);
    }

    this.gson.toJson(o, writer);

    writer.close();
  } catch (JsonIOException var7) {
    throw new HttpMessageNotWritableException("Could not write JSON: " + var7.getMessage(), var7);
  }
}
项目:xm-ms-entity    文件:MultipartMixedConverter.java   
@SuppressWarnings("unchecked")
private void writePart(String name, HttpEntity<?> partEntity, OutputStream os) throws IOException {
    Object partBody = partEntity.getBody();
    Class<?> partType = partBody.getClass();
    HttpHeaders partHeaders = partEntity.getHeaders();
    MediaType partContentType = partHeaders.getContentType();
    for (HttpMessageConverter<?> messageConverter : this.partConverters) {
        if (messageConverter.canWrite(partType, partContentType)) {
            HttpOutputMessage multipartMessage = new MultipartMixedConverter.MultipartHttpOutputMessage(os);
            multipartMessage.getHeaders().setContentDispositionFormData(name, null);
            if (!partHeaders.isEmpty()) {
                multipartMessage.getHeaders().putAll(partHeaders);
            }
            ((HttpMessageConverter<Object>) messageConverter).write(partBody, partContentType, multipartMessage);
            return;
        }
    }
    throw new HttpMessageNotWritableException(
        "Could not write request: no suitable HttpMessageConverter found for request type [" + partType.getName()
            + "]");
}
项目:lams    文件:MappingJacksonHttpMessageConverter.java   
@Override
protected void writeInternal(Object object, HttpOutputMessage outputMessage)
        throws IOException, HttpMessageNotWritableException {

    JsonEncoding encoding = getJsonEncoding(outputMessage.getHeaders().getContentType());
    JsonGenerator jsonGenerator =
            this.objectMapper.getJsonFactory().createJsonGenerator(outputMessage.getBody(), encoding);

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

    try {
        if (this.jsonPrefix != null) {
            jsonGenerator.writeRaw(this.jsonPrefix);
        }
        this.objectMapper.writeValue(jsonGenerator, object);
    }
    catch (JsonProcessingException ex) {
        throw new HttpMessageNotWritableException("Could not write JSON: " + ex.getMessage(), ex);
    }
}
项目:flow-platform    文件:RawGsonMessageConverter.java   
@Override
protected void writeInternal(Object o, Type type, HttpOutputMessage outputMessage)
    throws IOException, HttpMessageNotWritableException {
    Charset charset = getCharset(outputMessage.getHeaders());

    try (OutputStreamWriter writer = new OutputStreamWriter(outputMessage.getBody(), charset)) {
        if (ignoreType) {
            gsonForWriter.toJson(o, writer);
            return;
        }

        if (type != null) {
            gsonForWriter.toJson(o, type, writer);
            return;
        }

        gsonForWriter.toJson(o, writer);
    } catch (JsonIOException ex) {
        throw new HttpMessageNotWritableException("Could not write JSON: " + ex.getMessage(), ex);
    }
}
项目:spring4-understanding    文件:GsonHttpMessageConverter.java   
@Override
protected void writeInternal(Object o, Type type, HttpOutputMessage outputMessage)
        throws IOException, HttpMessageNotWritableException {

    Charset charset = getCharset(outputMessage.getHeaders());
    OutputStreamWriter writer = new OutputStreamWriter(outputMessage.getBody(), charset);
    try {
        if (this.jsonPrefix != null) {
            writer.append(this.jsonPrefix);
        }
        if (type != null) {
            this.gson.toJson(o, type, writer);
        }
        else {
            this.gson.toJson(o, writer);
        }
        writer.close();
    }
    catch (JsonIOException ex) {
        throw new HttpMessageNotWritableException("Could not write JSON: " + ex.getMessage(), ex);
    }
}
项目:spring4-understanding    文件:AbstractWireFeedHttpMessageConverter.java   
@Override
protected void writeInternal(T wireFeed, HttpOutputMessage outputMessage)
        throws IOException, HttpMessageNotWritableException {

    String wireFeedEncoding = wireFeed.getEncoding();
    if (!StringUtils.hasLength(wireFeedEncoding)) {
        wireFeedEncoding = DEFAULT_CHARSET.name();
    }
    MediaType contentType = outputMessage.getHeaders().getContentType();
    if (contentType != null) {
        Charset wireFeedCharset = Charset.forName(wireFeedEncoding);
        contentType = new MediaType(contentType.getType(), contentType.getSubtype(), wireFeedCharset);
        outputMessage.getHeaders().setContentType(contentType);
    }

    WireFeedOutput feedOutput = new WireFeedOutput();
    try {
        Writer writer = new OutputStreamWriter(outputMessage.getBody(), wireFeedEncoding);
        feedOutput.output(wireFeed, writer);
    }
    catch (FeedException ex) {
        throw new HttpMessageNotWritableException("Could not write WireFeed: " + ex.getMessage(), ex);
    }
}
项目:spring4-understanding    文件:MarshallingHttpMessageConverterTests.java   
@Test
public void writeWithMarshallingFailureException() throws Exception {
    String body = "<root>Hello World</root>";
    MockHttpOutputMessage outputMessage = new MockHttpOutputMessage();
    MarshallingFailureException ex = new MarshallingFailureException("forced");

    Marshaller marshaller = mock(Marshaller.class);
    willThrow(ex).given(marshaller).marshal(eq(body), isA(Result.class));

    try {
        MarshallingHttpMessageConverter converter = new MarshallingHttpMessageConverter(marshaller);
        converter.write(body, null, outputMessage);
        fail("HttpMessageNotWritableException should be thrown");
    }
    catch (HttpMessageNotWritableException e) {
        assertTrue("Invalid exception hierarchy", e.getCause() == ex);
    }
}
项目:leopard    文件:MappingJackson2HttpMessageConverter.java   
@Override
public void write(Object body, MediaType contentType, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException {
    outputMessage.getHeaders().setContentType(JSON_MEDIA_TYPE);

    // outputMessage.getHeaders().setAccessControlAllowOrigin("*");// FIXME 暂时的写法

    if (corsConfig.isEnable()) {
        HttpServletRequest request = RequestUtil.getCurrentRequest();
        String allowOrigin = corsConfig.getAccessControlAllowOrigin(request);
        if (StringUtils.isNotEmpty(allowOrigin)) {
            outputMessage.getHeaders().set("Access-Control-Allow-Origin", allowOrigin);
            outputMessage.getHeaders().set("Access-Control-Allow-Credentials", "true");
            // outputMessage.getHeaders().set("Access-Control-Allow-Methods", "GET, POST");
            // outputMessage.getHeaders().set("Access-Control-Allow-Headers", "x_requested_with,content-type");
        }
    }

    // System.err.println("ok");
    outputMessage.getBody().write(((String) body).getBytes());
}
项目:spring-cloud-gateway    文件:ProxyExchange.java   
@Override
public ServletInputStream getInputStream() throws IOException {
    Object body = body();
    MethodParameter output = new MethodParameter(
            ClassUtils.getMethod(BodySender.class, "body"), -1);
    ServletOutputToInputConverter response = new ServletOutputToInputConverter(
            this.response);
    ServletWebRequest webRequest = new ServletWebRequest(this.request, response);
    try {
        delegate.handleReturnValue(body, output, mavContainer, webRequest);
    }
    catch (HttpMessageNotWritableException
            | HttpMediaTypeNotAcceptableException e) {
        throw new IllegalStateException("Cannot convert body", e);
    }
    return response.getInputStream();
}
项目:FAIRDataPoint    文件:CatalogMetadataConverter.java   
@Override
protected void writeInternal(CatalogMetadata metadata, 
        HttpOutputMessage outputMessage) throws IOException, 
        HttpMessageNotWritableException {        
    String result;
    try {
        result = MetadataUtils.getString(metadata, format);
    } catch (MetadataException e) {
        throw new HttpMessageNotWritableException("", e);
    }

    OutputStreamWriter writer = new OutputStreamWriter(
            outputMessage.getBody(), StandardCharsets.UTF_8);
    writer.write(result);
    writer.close();
}
项目:FAIRDataPoint    文件:DatasetMetadataConverter.java   
@Override
protected void writeInternal(DatasetMetadata metadata, HttpOutputMessage
        outputMessage) 
        throws IOException, HttpMessageNotWritableException {
    String result;
    try {
        result = MetadataUtils.getString(metadata, format);
    } catch (MetadataException e) {
        throw new HttpMessageNotWritableException("", e);
    }

    OutputStreamWriter writer = new OutputStreamWriter(
            outputMessage.getBody(), StandardCharsets.UTF_8);
    writer.write(result);
    writer.close();
}
项目:FAIRDataPoint    文件:DistributionMetadataConverter.java   
@Override
protected void writeInternal(DistributionMetadata metadata, 
        HttpOutputMessage outputMessage) throws IOException, 
        HttpMessageNotWritableException {

    String result;
    try {
        result = MetadataUtils.getString(metadata, format);
    } catch (MetadataException e) {
        throw new HttpMessageNotWritableException("", e);
    }

    OutputStreamWriter writer = new OutputStreamWriter(
            outputMessage.getBody(), StandardCharsets.UTF_8);
    writer.write(result);
    writer.close();
}
项目:dhis2-core    文件:JsonPMessageConverter.java   
@Override
protected void writeInternal( RootNode rootNode, HttpOutputMessage outputMessage ) throws IOException, HttpMessageNotWritableException
{
    List<String> callbacks = Lists.newArrayList( contextService.getParameterValues( DEFAULT_CALLBACK_PARAMETER ) );

    String callbackParam;

    if ( callbacks.isEmpty() )
    {
        callbackParam = DEFAULT_CALLBACK_PARAMETER;
    }
    else
    {
        callbackParam = callbacks.get( 0 );
    }

    rootNode.getConfig().getProperties().put( Jackson2JsonNodeSerializer.JSONP_CALLBACK, callbackParam );

    nodeService.serialize( rootNode, "application/json", outputMessage.getBody() );
}
项目:jbase    文件:JsonPMessageConverter.java   
@Override
protected void writeInternal(Object obj, HttpOutputMessage outputMessage)
        throws IOException, HttpMessageNotWritableException {

    String text = "";
    if (obj instanceof String || obj instanceof Number || obj instanceof Boolean) {
        text += obj;
    } else {
        text = JSON.toJSONString(obj, getFeatures());
    }

    String call = EffectInteceptor.callBack.get();
    if (StringUtils.isNotBlank(call)) {

        if(obj instanceof String){
            text = call + "(\"" + text + "\")";
        }else{
            text = call + "(" + text + ")";
        }

    }
    OutputStream out = outputMessage.getBody();
    byte[] bytes = text.getBytes(getCharset());
    out.write(bytes);
}
项目:online-whatif    文件:FeatureHttpMessageConverter.java   
@Override
protected void writeInternal(final Object o,
    final HttpOutputMessage outputMessage) throws IOException,
    HttpMessageNotWritableException {
  LOGGER.debug("Entering FeatureHttpMessageConverter.writeInternal().");
  LOGGER.debug("Content type of the outputMessage "
      + outputMessage.getHeaders().getContentType());
  featureJSON.setEncodeFeatureCollectionBounds(true);
  featureJSON.setEncodeNullValues(true);
  // TODO we'll need to enable this once geotools allow us to patch
  // GML2ParsingUtils class and set SRID on each of the features created
  // for the call to encodeCRS not to throw an exception, we'll need to check
  // for the existence of CRS info in the feature collection before we set
  // this flag...
  if (((FeatureCollection) o).getBounds().getCoordinateReferenceSystem() != null) {
    featureJSON.setEncodeFeatureCollectionCRS(true);
  }
  featureJSON.writeFeatureCollection((FeatureCollection) o,
      new OutputStreamWriter(outputMessage.getBody()));
}
项目:cloudstreetmarket.com    文件:YahooQuoteMessageConverter.java   
@Override
protected void writeInternal(QuoteWrapper quotes, HttpOutputMessage httpOutputMessage) throws IOException, HttpMessageNotWritableException {
    CSVWriter writer = new CSVWriter(new OutputStreamWriter(httpOutputMessage.getBody()));
    for (YahooQuote quote : quotes) {
        writer.writeNext(
                new String[]{   quote.getId(),
                                quote.getName(),
                                String.valueOf(quote.getOpen()),
                                String.valueOf(quote.getPreviousClose()),
                                String.valueOf(quote.getLast()),
                                String.valueOf(quote.getLastChange()),
                                String.valueOf(quote.getLastChangePercent()),
                                String.valueOf(quote.getHigh()),
                                String.valueOf(quote.getLow()),
                                String.valueOf(quote.getBid()),
                                String.valueOf(quote.getAsk()),
                                String.valueOf(quote.getVolume()),
                                quote.getExchange(),
                                quote.getCurrency()
                });
    }

    writer.close();
}
项目:cloudstreetmarket.com    文件:YahooHistoMessageConverter.java   
@Override
protected void writeInternal(QuoteWrapper quotes, HttpOutputMessage httpOutputMessage) throws IOException, HttpMessageNotWritableException {
    CSVWriter writer = new CSVWriter(new OutputStreamWriter(httpOutputMessage.getBody()));
    for (YahooQuote quote : quotes) {
        writer.writeNext(
                new String[]{   quote.getId(),
                                quote.getName(),
                                String.valueOf(quote.getOpen()),
                                String.valueOf(quote.getPreviousClose()),
                                String.valueOf(quote.getLast()),
                                String.valueOf(quote.getLastChange()),
                                String.valueOf(quote.getLastChangePercent()),
                                String.valueOf(quote.getHigh()),
                                String.valueOf(quote.getLow()),
                                String.valueOf(quote.getBid()),
                                String.valueOf(quote.getAsk()),
                                String.valueOf(quote.getVolume()),
                                quote.getExchange(),
                                quote.getCurrency()
                });
    }

    writer.close();
}
项目:cloudstreetmarket.com    文件:YahooIntraDayHistoMessageConverter.java   
@Override
protected void writeInternal(QuoteWrapper quotes, HttpOutputMessage httpOutputMessage) throws IOException, HttpMessageNotWritableException {
    CSVWriter writer = new CSVWriter(new OutputStreamWriter(httpOutputMessage.getBody()));
    for (YahooQuote quote : quotes) {
        writer.writeNext(
                new String[]{   quote.getId(),
                                quote.getName(),
                                String.valueOf(quote.getOpen()),
                                String.valueOf(quote.getPreviousClose()),
                                String.valueOf(quote.getLast()),
                                String.valueOf(quote.getLastChange()),
                                String.valueOf(quote.getLastChangePercent()),
                                String.valueOf(quote.getHigh()),
                                String.valueOf(quote.getLow()),
                                String.valueOf(quote.getBid()),
                                String.valueOf(quote.getAsk()),
                                String.valueOf(quote.getVolume()),
                                quote.getExchange(),
                                quote.getCurrency()
                });
    }

    writer.close();
}
项目:data-acquisition    文件:CallbacksService.java   
@ApiOperation(
        value = "Updates metadata status",
        notes = "Privilege level: Consumer of this endpoint must be a member of organization based on valid access token")
@ApiResponses(value = {
        @ApiResponse(code = 200, message = "OK"),
        @ApiResponse(code = 500, message = "Internal server error, see logs for details")
})
@RequestMapping(value = "/metadata/{id}", method = RequestMethod.POST)
public String metadataStatusUpdate(@RequestBody MetadataParseStatus status,
                                   @PathVariable String id) {
    try {
        switch (status.getState()) {
            case DONE:
                flowManager.metadataParsed(id);
                break;
            case FAILED:
                flowManager.requestFailed(id);
                break;
            default:
                LOGGER.warn("No action on metadata status update: " + status.getState());
        }
    } catch (NoSuchRequestInStore e) {
        throw new HttpMessageNotWritableException(e.getMessage(), e);
    }
    return RESPONSE_OK;
}
项目:contestparser    文件:EndpointWebMvcHypermediaManagementContextConfiguration.java   
private Object beforeBodyWrite(Object body, MethodParameter returnType,
        MediaType selectedContentType,
        Class<? extends HttpMessageConverter<?>> selectedConverterType,
        ServletServerHttpRequest request, ServerHttpResponse response) {
    if (body == null || body instanceof Resource) {
        // Assume it already was handled or it already has its links
        return body;
    }
    HttpMessageConverter<Object> converter = findConverter(selectedConverterType,
            selectedContentType);
    if (converter == null || isHypermediaDisabled(returnType)) {
        // Not a resource that can be enhanced with a link
        return body;
    }
    String path = getPath(request);
    try {
        converter.write(new EndpointResource(body, path), selectedContentType,
                response);
    }
    catch (IOException ex) {
        throw new HttpMessageNotWritableException("Cannot write response", ex);
    }
    return null;
}
项目:workbenchauth    文件:FeatureHttpMessageConverter.java   
@Override
protected void writeInternal(final Object o,
    final HttpOutputMessage outputMessage) throws IOException,
    HttpMessageNotWritableException {
  LOGGER.debug("Entering FeatureHttpMessageConverter.writeInternal().");
  LOGGER.debug("Content type of the outputMessage "
      + outputMessage.getHeaders().getContentType());
  featureJSON.setEncodeFeatureCollectionBounds(true);
  featureJSON.setEncodeNullValues(true);
  // TODO we'll need to enable this once geotools allow us to patch
  // GML2ParsingUtils class and set SRID on each of the features created
  // for the call to encodeCRS not to throw an exception, we'll need to check
  // for the existence of CRS info in the feature collection before we set
  // this flag...
  if (((FeatureCollection) o).getBounds().getCoordinateReferenceSystem() != null) {
    featureJSON.setEncodeFeatureCollectionCRS(true);
  }
  featureJSON.writeFeatureCollection((FeatureCollection) o,
      new OutputStreamWriter(outputMessage.getBody()));
}
项目:ShoppingMall    文件:MappingJackson2HttpMessageConverter.java   
@Override
protected void writeInternal(Object object, HttpOutputMessage outputMessage)
        throws IOException, HttpMessageNotWritableException {

    JsonEncoding encoding = getJsonEncoding(outputMessage.getHeaders().getContentType());
    JsonGenerator jsonGenerator =
            this.objectMapper.getFactory().createJsonGenerator(outputMessage.getBody(), encoding);
    try {
        if (this.prefixJson) {
            jsonGenerator.writeRaw("{} && ");
        }
        this.objectMapper.writeValue(jsonGenerator, object);
    }
    catch (IOException ex) {
        throw new HttpMessageNotWritableException("Could not write JSON: " + ex.getMessage(), ex);
    }
}
项目:ShoppingMall    文件:GsonHttpMessageConverter.java   
@Override
protected void writeInternal(Object o, HttpOutputMessage outputMessage)
        throws IOException, HttpMessageNotWritableException {

    OutputStreamWriter writer = new OutputStreamWriter(outputMessage.getBody(), getCharset(outputMessage.getHeaders()));

    try {
        if (this.prefixJson) {
            writer.append("{} && ");
        }
        Type typeOfSrc = getType();
        if (typeOfSrc != null) {
            this.gson.toJson(o, typeOfSrc, writer);
        } else {
            this.gson.toJson(o, writer);
        }
        writer.close();
    } catch(JsonIOException  ex) {
        throw new HttpMessageNotWritableException("Could not write JSON: " + ex.getMessage(), ex);
    }   
}
项目:ShoppingMall    文件:MappingJacksonHttpMessageConverter.java   
@Override
protected void writeInternal(Object object, HttpOutputMessage outputMessage)
        throws IOException, HttpMessageNotWritableException {

    JsonEncoding encoding = getJsonEncoding(outputMessage.getHeaders().getContentType());
    JsonGenerator jsonGenerator =
            this.objectMapper.getJsonFactory().createJsonGenerator(outputMessage.getBody(), encoding);
    try {
        if (this.prefixJson) {
            jsonGenerator.writeRaw("{} && ");
        }
        this.objectMapper.writeValue(jsonGenerator, object);
    }
    catch (IOException ex) {
        throw new HttpMessageNotWritableException("Could not write JSON: " + ex.getMessage(), ex);
    }
}
项目:ShoppingMall    文件:AbstractWireFeedHttpMessageConverter.java   
@Override
protected void writeInternal(T wireFeed, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException {
    String wireFeedEncoding = wireFeed.getEncoding();
    if (!StringUtils.hasLength(wireFeedEncoding)) {
        wireFeedEncoding = DEFAULT_CHARSET.name();
    }
    MediaType contentType = outputMessage.getHeaders().getContentType();
    if (contentType != null) {
        Charset wireFeedCharset = Charset.forName(wireFeedEncoding);
        contentType = new MediaType(contentType.getType(), contentType.getSubtype(), wireFeedCharset);
        outputMessage.getHeaders().setContentType(contentType);
    }

    WireFeedOutput feedOutput = new WireFeedOutput();

    try {
        Writer writer = new OutputStreamWriter(outputMessage.getBody(), wireFeedEncoding);
        feedOutput.output(wireFeed, writer);
    } catch (FeedException ex) {
        throw new HttpMessageNotWritableException("Could not write WiredFeed: " + ex.getMessage(), ex);
    }
}
项目:ShoppingMall    文件:SyndFeedHttpMessageConverter.java   
@Override
protected void writeInternal(SyndFeed syndFeed, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException {
    String syndFeedEncoding = syndFeed.getEncoding();
    if (!StringUtils.hasLength(syndFeedEncoding)) {
        syndFeedEncoding = DEFAULT_CHARSET.name();
    }
    MediaType contentType = outputMessage.getHeaders().getContentType();
    if (contentType != null) {
        Charset syndFeedCharset = Charset.forName(syndFeedEncoding);
        contentType = new MediaType(contentType.getType(), contentType.getSubtype(), syndFeedCharset);
        outputMessage.getHeaders().setContentType(contentType);
    }

    SyndFeedOutput feedOutput = new SyndFeedOutput();

    try {
        Writer writer = new OutputStreamWriter(outputMessage.getBody(), syndFeedEncoding);
        feedOutput.output(syndFeed, writer);
    } catch (FeedException ex) {
        throw new HttpMessageNotWritableException("Could not write SyndFeed: " + ex.getMessage(), ex);
    }
}
项目:AgileAlligators    文件:JsonPMessageConverter.java   
@Override
protected void writeInternal( RootNode rootNode, HttpOutputMessage outputMessage ) throws IOException, HttpMessageNotWritableException
{
    List<String> callbacks = Lists.newArrayList( contextService.getParameterValues( DEFAULT_CALLBACK_PARAMETER ) );

    String callbackParam;

    if ( callbacks.isEmpty() )
    {
        callbackParam = DEFAULT_CALLBACK_PARAMETER;
    }
    else
    {
        callbackParam = callbacks.get( 0 );
    }

    rootNode.getConfig().getProperties().put( Jackson2JsonNodeSerializer.JSONP_CALLBACK, callbackParam );

    nodeService.serialize( rootNode, "application/json", outputMessage.getBody() );
}
项目:telekom-workflow-engine    文件:GsonHttpMessageConverterForSpring3.java   
@Override
protected void writeInternal( Object o, HttpOutputMessage outputMessage )
        throws IOException, HttpMessageNotWritableException{

    OutputStreamWriter writer = new OutputStreamWriter( outputMessage.getBody(), getCharset( outputMessage.getHeaders() ) );

    try{
        if( this.prefixJson ){
            writer.append( "{} && " );
        }
        Type typeOfSrc = getType();
        if( typeOfSrc != null ){
            this.gson.toJson( o, typeOfSrc, writer );
        }
        else{
            this.gson.toJson( o, writer );
        }
        writer.close();
    }
    catch( JsonIOException ex ){
        throw new HttpMessageNotWritableException( "Could not write JSON: " + ex.getMessage(), ex );
    }
}
项目:appverse-server    文件:CustomMappingJacksonHttpMessageConverter.java   
@Override
protected void writeInternal(Object o, HttpOutputMessage outputMessage)
        throws IOException, HttpMessageNotWritableException {
    JsonEncoding encoding = getEncoding(outputMessage.getHeaders()
            .getContentType());
    JsonGenerator jsonGenerator = this.objectMapper.getJsonFactory()
            .createJsonGenerator(outputMessage.getBody(), encoding);
    if (this.prefixJson) {
        jsonGenerator.writeRaw("{} && ");
    }
    this.objectMapper.writeValue(jsonGenerator, o);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    JsonGenerator baosjsonGenerator = this.objectMapper.getJsonFactory()
            .createJsonGenerator(baos, encoding);
    this.objectMapper.writeValue(baosjsonGenerator, o);
    logger.debug("Middleware returns " + o.getClass().getName() + " "
            + baos.toString());
}
项目:TableAliasV60    文件:MappingJackson2JsonpHttpMessageConverter.java   
@Override
   protected void writeInternal(Object object, HttpOutputMessage outputMessage)
    throws IOException, HttpMessageNotWritableException {
JsonGenerator jsonGenerator = getJsonGenerator(outputMessage);

try {
    String callbackParam = getRequestParam(DEFAULT_CALLBACK_PARAMETER);

    if (callbackParam == null || callbackParam.isEmpty()) {
    callbackParam = DEFAULT_CALLBACK_PARAMETER;
    }

    jsonGenerator.writeRaw(callbackParam);
    jsonGenerator.writeRaw(" (");
    getObjectMapper().writeValue(jsonGenerator, object);
    jsonGenerator.writeRaw(");");
    jsonGenerator.flush();
} catch (JsonProcessingException ex) {
    throw new HttpMessageNotWritableException("Could not write JSON:"
        + ex.getMessage(), ex);
}
   }
项目:MongoDB    文件:FastJsonHttpMessageConverter.java   
@Override
protected void writeInternal(Object obj, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException {

    OutputStream out = outputMessage.getBody();
    byte[] bytes;

    if (charset == UTF8) {
        if (serializerFeature != null) {
            bytes = JSON.toJSONBytes(obj, serializerFeature);
        } else {
            bytes = JSON.toJSONBytes(obj, SerializerFeature.WriteDateUseDateFormat);
        }

    } else {
        String text;
        if (serializerFeature != null) {
            text = JSON.toJSONString(obj, serializerFeature);
        } else {
            text = JSON.toJSONString(obj, SerializerFeature.WriteDateUseDateFormat);
        }
        bytes = text.getBytes(charset);
    }

    out.write(bytes);
}
项目:hydra-java    文件:SirenMessageConverter.java   
@Override
protected void writeInternal(Object o, HttpOutputMessage outputMessage) throws IOException,
        HttpMessageNotWritableException {
    SirenEntity entity = new SirenEntity();
    sirenUtils.toSirenEntity(entity, o);

    JsonEncoding encoding = getJsonEncoding(outputMessage.getHeaders()
            .getContentType());
    JsonGenerator jsonGenerator = this.objectMapper.getFactory()
            .createGenerator(outputMessage.getBody(), encoding);

    // 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, entity);
    } catch (JsonProcessingException ex) {
        throw new HttpMessageNotWritableException("Could not write JSON: " + ex.getMessage(), ex);
    }
}
项目:hydra-java    文件: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);

    // 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);
    }
}
项目:jasper-springmvc    文件:MappingJackson2JsonpHttpMessageConverter.java   
@Override
protected void writeInternal( Object object, HttpOutputMessage outputMessage )
        throws IOException, HttpMessageNotWritableException {
    JsonGenerator jsonGenerator = getJsonGenerator(outputMessage);

    try {
        String callbackParam = getRequestParam(DEFAULT_CALLBACK_PARAMETER);

        //if the callback parameter doesn't exists, use the default one...
        if (Strings.isNullOrEmpty(callbackParam) ) {
            getObjectMapper().writeValue(jsonGenerator, object);
        } else {
            jsonGenerator.writeRaw(callbackParam);
            jsonGenerator.writeRaw(" (");
            getObjectMapper().writeValue(jsonGenerator, object);
            jsonGenerator.writeRaw(");");
        }
        jsonGenerator.flush();
    } catch (JsonProcessingException ex) {
        throw new HttpMessageNotWritableException("Could not write JSON:"  + ex.getMessage(), ex);
    }
}
项目:kansalaisaloite    文件:JsonpMessageConverter.java   
@Override
protected void writeInternal(JsonpObject<T> t, HttpOutputMessage outputMessage)
        throws IOException, HttpMessageNotWritableException {
    String callback = t.getCallback();
    if (JSONPCallbackValidator.isValidJSONPCallback(callback)) {
        OutputStream out = outputMessage.getBody();
        out.write(callback.getBytes(DEFAULT_CHARSET));
        out.write(OPEN_BRACKET);

        jsonConverter.write(t.getObject(), jsonMediaType, outputMessage);

        out.write(MESSAGE_END);
    } else {
        throw new IllegalArgumentException("\"" + callback + "\" is not a valid JS identifier.");
    }
}
项目:JsonResponse    文件:JsonResponseAwareJsonMessageConverter.java   
protected void writeJson(ResponseWrapper response, HttpOutputMessage outputMessage) throws IOException,
        HttpMessageNotWritableException {

    JsonEncoding encoding = getJsonEncoding(outputMessage.getHeaders().getContentType());

    ObjectMapper mapper = new ObjectMapper();

    // Add support for jackson mixins
    JsonMixin[] jsonMixins = response.getJsonResponse().mixins();
    for (JsonMixin jsonMixin : jsonMixins) {
        mapper.addMixInAnnotations(jsonMixin.target(), jsonMixin.mixin());
    }

    JsonGenerator jsonGenerator = mapper.getFactory().createGenerator(outputMessage.getBody(), encoding);
    try {
        mapper.writeValue(jsonGenerator, response.getOriginalResponse());
    } catch (IOException ex) {
        throw new HttpMessageNotWritableException("Could not write JSON: " + ex.getMessage(), ex);
    }
}
项目:JsonResponse    文件:JsonResponseAwareJsonMessageConverter.java   
protected void writeJson(ResponseWrapper response, HttpOutputMessage outputMessage)
        throws IOException, HttpMessageNotWritableException {

    JsonEncoding encoding = getJsonEncoding(outputMessage.getHeaders().getContentType());

    ObjectMapper mapper = new ObjectMapper();

    //Add support for jackson mixins
    JsonMixin[] jsonMixins = response.getJsonResponse().mixins();
    for(int i=0;i<jsonMixins.length;i++) {
        mapper.getSerializationConfig()
            .addMixInAnnotations(jsonMixins[i].target(), jsonMixins[i].mixin());
    }

    JsonGenerator jsonGenerator =
            mapper.getJsonFactory().createJsonGenerator(outputMessage.getBody(), encoding);
    try {
        mapper.writeValue(jsonGenerator, response.getOriginalResponse());
    }
    catch (IOException ex) {
        throw new HttpMessageNotWritableException("Could not write JSON: " + ex.getMessage(), ex);
    }
}
项目:class-guard    文件:MappingJackson2HttpMessageConverter.java   
@Override
protected void writeInternal(Object object, HttpOutputMessage outputMessage)
        throws IOException, HttpMessageNotWritableException {

    JsonEncoding encoding = getJsonEncoding(outputMessage.getHeaders().getContentType());
    JsonGenerator jsonGenerator =
            this.objectMapper.getJsonFactory().createJsonGenerator(outputMessage.getBody(), encoding);

    // 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 {
        if (this.jsonPrefix != null) {
            jsonGenerator.writeRaw(this.jsonPrefix);
        }
        this.objectMapper.writeValue(jsonGenerator, object);
    }
    catch (JsonProcessingException ex) {
        throw new HttpMessageNotWritableException("Could not write JSON: " + ex.getMessage(), ex);
    }
}
项目:class-guard    文件:MappingJacksonHttpMessageConverter.java   
@Override
protected void writeInternal(Object object, HttpOutputMessage outputMessage)
        throws IOException, HttpMessageNotWritableException {

    JsonEncoding encoding = getJsonEncoding(outputMessage.getHeaders().getContentType());
    JsonGenerator jsonGenerator =
            this.objectMapper.getJsonFactory().createJsonGenerator(outputMessage.getBody(), encoding);

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

    try {
        if (this.jsonPrefix != null) {
            jsonGenerator.writeRaw(this.jsonPrefix);
        }
        this.objectMapper.writeValue(jsonGenerator, object);
    }
    catch (JsonProcessingException ex) {
        throw new HttpMessageNotWritableException("Could not write JSON: " + ex.getMessage(), ex);
    }
}