當前位置: 首頁>>代碼示例>>Java>>正文


Java HttpOutputMessage.getBody方法代碼示例

本文整理匯總了Java中org.springframework.http.HttpOutputMessage.getBody方法的典型用法代碼示例。如果您正苦於以下問題:Java HttpOutputMessage.getBody方法的具體用法?Java HttpOutputMessage.getBody怎麽用?Java HttpOutputMessage.getBody使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.springframework.http.HttpOutputMessage的用法示例。


在下文中一共展示了HttpOutputMessage.getBody方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: writeInternal

import org.springframework.http.HttpOutputMessage; //導入方法依賴的package包/類
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);
  }
}
 
開發者ID:Huawei,項目名稱:Server_Management_Common_eSightApi,代碼行數:19,代碼來源:GsonHttpMessageConverter.java

示例2: handleHttpEntityResponse

import org.springframework.http.HttpOutputMessage; //導入方法依賴的package包/類
public void handleHttpEntityResponse(HttpEntity<?> responseEntity, ServletWebRequest webRequest) throws Exception {
    if (responseEntity == null) {
        return;
    }

    HttpInputMessage inputMessage = createHttpInputMessage(webRequest);
    HttpOutputMessage outputMessage = createHttpOutputMessage(webRequest);
    if (responseEntity instanceof ResponseEntity && outputMessage instanceof ServerHttpResponse) {
        ((ServerHttpResponse) outputMessage).setStatusCode(((ResponseEntity<?>) responseEntity).getStatusCode());
    }

    HttpHeaders entityHeaders = responseEntity.getHeaders();
    if (!entityHeaders.isEmpty()) {
        outputMessage.getHeaders().putAll(entityHeaders);
    }

    Object body = responseEntity.getBody();
    if (body != null) {
        writeWithMessageConverters(body, inputMessage, outputMessage);
    }
    else {
        outputMessage.getBody();
    }
}
 
開發者ID:PatternFM,項目名稱:tokamak,代碼行數:25,代碼來源:RestExceptionRenderer.java

示例3: writeInternal

import org.springframework.http.HttpOutputMessage; //導入方法依賴的package包/類
@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);
    }
}
 
開發者ID:FlowCI,項目名稱:flow-platform,代碼行數:22,代碼來源:RawGsonMessageConverter.java

示例4: writeInternal

import org.springframework.http.HttpOutputMessage; //導入方法依賴的package包/類
@Override
protected void writeInternal(CSVHttpResponse response, HttpOutputMessage output) throws IOException {
    final Charset charset = getCharset(response);

    output.getHeaders().setContentType(createMediaType(charset));
    output.getHeaders().set("Content-Disposition", "attachment; filename=\"" + response.getFilename() + "\"");

    try (final OutputStreamWriter outputStreamWriter = new OutputStreamWriter(output.getBody(), charset);
         final CSVWriter writer = new CSVWriter(outputStreamWriter, ';')) {

        if (response.getHeaderRow() != null) {
            writer.writeNext(response.getHeaderRow());
        }

        writer.writeAll(response.getRows());
        writer.flush();
    }
}
 
開發者ID:suomenriistakeskus,項目名稱:oma-riista-web,代碼行數:19,代碼來源:CSVMessageConverter.java

示例5: handleHttpEntityResponse

import org.springframework.http.HttpOutputMessage; //導入方法依賴的package包/類
private void handleHttpEntityResponse(HttpEntity<?> responseEntity, ServletWebRequest webRequest) throws Exception {
	if (responseEntity == null) {
		return;
	}
	HttpInputMessage inputMessage = createHttpInputMessage(webRequest);
	HttpOutputMessage outputMessage = createHttpOutputMessage(webRequest);
	if (responseEntity instanceof ResponseEntity && outputMessage instanceof ServerHttpResponse) {
		((ServerHttpResponse) outputMessage).setStatusCode(((ResponseEntity<?>) responseEntity).getStatusCode());
	}
	HttpHeaders entityHeaders = responseEntity.getHeaders();
	if (!entityHeaders.isEmpty()) {
		outputMessage.getHeaders().putAll(entityHeaders);
	}
	Object body = responseEntity.getBody();
	if (body != null) {
		writeWithMessageConverters(body, inputMessage, outputMessage);
	}
	else {
		// flush headers
		outputMessage.getBody();
	}
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:23,代碼來源:AnnotationMethodHandlerAdapter.java

示例6: writeInternal

import org.springframework.http.HttpOutputMessage; //導入方法依賴的package包/類
@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);
	}
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:23,代碼來源:GsonHttpMessageConverter.java

示例7: writeInternal

import org.springframework.http.HttpOutputMessage; //導入方法依賴的package包/類
@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);
	}
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:25,代碼來源:AbstractWireFeedHttpMessageConverter.java

示例8: write

import org.springframework.http.HttpOutputMessage; //導入方法依賴的package包/類
@Override
public void write(final GenericEntity entity, final MediaType contentType, final HttpOutputMessage outputMessage)
		throws IOException {
	final HierarchicalStreamWriter writer = new CompactWriter(new OutputStreamWriter(outputMessage.getBody()));
	writer.startNode("Entity");
	writer.addAttribute("Type", entity.getType());
	writer.startNode("Fields");
	for (final Field field : entity.getFields()) {
		writer.startNode("Field");
		writer.addAttribute("Name", field.getName());
		if (field.getValues().size() == 0) {
			writer.startNode("Value");
			writer.endNode();
		} else {
			for (final String value : field.getValues()) {
				writer.startNode("Value");
				writer.setValue(value);
				writer.endNode();
			}
		}
		writer.endNode();
	}
	writer.endNode();
	writer.endNode();

}
 
開發者ID:stevensimmons,項目名稱:restalm,代碼行數:27,代碼來源:EntityMarshaller.java

示例9: writeInternal

import org.springframework.http.HttpOutputMessage; //導入方法依賴的package包/類
@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();
}
 
開發者ID:DTL-FAIRData,項目名稱:FAIRDataPoint,代碼行數:17,代碼來源:CatalogMetadataConverter.java

示例10: writeInternal

import org.springframework.http.HttpOutputMessage; //導入方法依賴的package包/類
@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();
}
 
開發者ID:DTL-FAIRData,項目名稱:FAIRDataPoint,代碼行數:17,代碼來源:DatasetMetadataConverter.java

示例11: writeInternal

import org.springframework.http.HttpOutputMessage; //導入方法依賴的package包/類
@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();
}
 
開發者ID:DTL-FAIRData,項目名稱:FAIRDataPoint,代碼行數:18,代碼來源:DistributionMetadataConverter.java

示例12: writeInternal

import org.springframework.http.HttpOutputMessage; //導入方法依賴的package包/類
@Override
protected void writeInternal(Object o, HttpOutputMessage outputMessage)
        throws IOException, HttpMessageNotWritableException {
    String jsonString = JSON.toJSONString(o, serializerFeature);
    OutputStream out = outputMessage.getBody();
    out.write(jsonString.getBytes(DEFAULT_CHARSET));
    out.flush();
}
 
開發者ID:MasonQAQ,項目名稱:WeatherSystem,代碼行數:9,代碼來源:FastJsonMessageConverter.java

示例13: writeInternal

import org.springframework.http.HttpOutputMessage; //導入方法依賴的package包/類
@Override
protected void writeInternal(T t, HttpOutputMessage outputMessage)
		throws IOException, HttpMessageNotWritableException {
	try {
		Result result = new StreamResult(outputMessage.getBody());
		transform(t, result);
	}
	catch (TransformerException ex) {
		throw new HttpMessageNotWritableException("Could not transform [" + t + "] to output message", ex);
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:12,代碼來源:SourceHttpMessageConverter.java

示例14: writeInternal

import org.springframework.http.HttpOutputMessage; //導入方法依賴的package包/類
@Override
protected void writeInternal(Object obj, Type type, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException {
    OutputStream out = outputMessage.getBody();
    byte[] bytes = converter(obj).getBytes(charset);
    out.write(bytes);
    out.flush();
}
 
開發者ID:hs-web,項目名稱:hsweb-framework,代碼行數:8,代碼來源:FastJsonGenericHttpMessageConverter.java

示例15: writeInternal

import org.springframework.http.HttpOutputMessage; //導入方法依賴的package包/類
@Override
protected void writeInternal(Object obj, HttpOutputMessage outputMessage) throws IOException,
        HttpMessageNotWritableException {
    OutputStream out = outputMessage.getBody();
    byte[] bytes = converter(obj).getBytes(charset);
    out.write(bytes);
    out.flush();
}
 
開發者ID:hs-web,項目名稱:hsweb-framework,代碼行數:9,代碼來源:FastJsonHttpMessageConverter.java


注:本文中的org.springframework.http.HttpOutputMessage.getBody方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。