Search in sources :

Example 6 with HttpHeaders

use of org.springframework.http.HttpHeaders in project spring-boot-admin by codecentric.

the class LetsChatNotifierTest method expectedMessage.

private HttpEntity<?> expectedMessage(String message) {
    HttpHeaders httpHeaders = new HttpHeaders();
    httpHeaders.setContentType(MediaType.APPLICATION_JSON);
    String auth = Base64Utils.encodeToString(String.format("%s:%s", token, user).getBytes());
    httpHeaders.add(HttpHeaders.AUTHORIZATION, String.format("Basic %s", auth));
    Map<String, Object> messageJson = new HashMap<>();
    messageJson.put("text", message);
    return new HttpEntity<>(messageJson, httpHeaders);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) HttpEntity(org.springframework.http.HttpEntity) HashMap(java.util.HashMap)

Example 7 with HttpHeaders

use of org.springframework.http.HttpHeaders in project spring-boot-admin by codecentric.

the class HipchatNotifier method createHipChatNotification.

protected HttpEntity<Map<String, Object>> createHipChatNotification(ClientApplicationEvent event) {
    Map<String, Object> body = new HashMap<>();
    body.put("color", getColor(event));
    body.put("message", getMessage(event));
    body.put("notify", getNotify());
    body.put("message_format", "html");
    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_JSON);
    return new HttpEntity<>(body, headers);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) HttpEntity(org.springframework.http.HttpEntity) HashMap(java.util.HashMap)

Example 8 with HttpHeaders

use of org.springframework.http.HttpHeaders in project fastjson by alibaba.

the class FastJsonHttpMessageConverter method write.

/*
     * @see org.springframework.http.converter.GenericHttpMessageConverter#write(java.lang.Object, java.lang.reflect.Type, org.springframework.http.MediaType, org.springframework.http.HttpOutputMessage)
     */
public //
void write(//
Object t, //
Type type, //
MediaType contentType, //
HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException {
    HttpHeaders headers = outputMessage.getHeaders();
    if (headers.getContentType() == null) {
        if (contentType == null || contentType.isWildcardType() || contentType.isWildcardSubtype()) {
            contentType = getDefaultContentType(t);
        }
        if (contentType != null) {
            headers.setContentType(contentType);
        }
    }
    if (headers.getContentLength() == -1) {
        Long contentLength = getContentLength(t, headers.getContentType());
        if (contentLength != null) {
            headers.setContentLength(contentLength);
        }
    }
    writeInternal(t, outputMessage);
    outputMessage.getBody().flush();
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders)

Example 9 with HttpHeaders

use of org.springframework.http.HttpHeaders in project fastjson by alibaba.

the class FastJsonHttpMessageConverter4 method writeInternal.

@Override
protected //
void writeInternal(//
Object obj, //
Type type, //
HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException {
    HttpHeaders headers = outputMessage.getHeaders();
    ByteArrayOutputStream outnew = new ByteArrayOutputStream();
    int len = //
    JSON.writeJSONString(//
    outnew, //
    fastJsonConfig.getCharset(), //
    obj, //
    fastJsonConfig.getSerializeConfig(), //
    fastJsonConfig.getSerializeFilters(), //
    fastJsonConfig.getDateFormat(), //
    JSON.DEFAULT_GENERATE_FEATURE, fastJsonConfig.getSerializerFeatures());
    if (fastJsonConfig.isWriteContentLength()) {
        headers.setContentLength(len);
    }
    OutputStream out = outputMessage.getBody();
    outnew.writeTo(out);
    outnew.close();
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 10 with HttpHeaders

use of org.springframework.http.HttpHeaders in project fastjson by alibaba.

the class FastJsonpHttpMessageConverter4 method writeInternal.

@Override
protected void writeInternal(Object obj, Type type, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException {
    HttpHeaders headers = outputMessage.getHeaders();
    ByteArrayOutputStream outnew = new ByteArrayOutputStream();
    int len = writePrefix(outnew, obj);
    Object value = obj;
    if (obj instanceof MappingFastJsonValue) {
        MappingFastJsonValue container = (MappingFastJsonValue) obj;
        value = container.getValue();
    }
    len += //
    JSON.writeJSONString(//
    outnew, //
    fastJsonConfig.getCharset(), //
    value, //
    fastJsonConfig.getSerializeConfig(), //
    fastJsonConfig.getSerializeFilters(), //
    fastJsonConfig.getDateFormat(), //
    JSON.DEFAULT_GENERATE_FEATURE, fastJsonConfig.getSerializerFeatures());
    len += writeSuffix(outnew, obj);
    if (fastJsonConfig.isWriteContentLength()) {
        headers.setContentLength(len);
    }
    OutputStream out = outputMessage.getBody();
    outnew.writeTo(out);
    outnew.close();
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Aggregations

HttpHeaders (org.springframework.http.HttpHeaders)425 Test (org.junit.Test)205 ResponseEntity (org.springframework.http.ResponseEntity)63 HttpEntity (org.springframework.http.HttpEntity)62 URI (java.net.URI)52 MediaType (org.springframework.http.MediaType)50 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)42 ByteArrayInputStream (java.io.ByteArrayInputStream)30 HttpStatus (org.springframework.http.HttpStatus)30 LinkedMultiValueMap (org.springframework.util.LinkedMultiValueMap)30 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)30 IOException (java.io.IOException)21 Map (java.util.Map)21 ArrayList (java.util.ArrayList)19 List (java.util.List)18 ClientHttpResponse (org.springframework.http.client.ClientHttpResponse)18 MultiValueMap (org.springframework.util.MultiValueMap)18 HttpInputMessage (org.springframework.http.HttpInputMessage)17 TestRestTemplate (org.springframework.boot.test.web.client.TestRestTemplate)15 HttpOutputMessage (org.springframework.http.HttpOutputMessage)14