本文整理匯總了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);
}
}
示例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();
}
}
示例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);
}
}
示例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();
}
}
示例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();
}
}
示例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);
}
}
示例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);
}
}
示例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();
}
示例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();
}
示例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();
}
示例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();
}
示例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();
}
示例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);
}
}
示例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();
}
示例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();
}