List of usage examples for org.springframework.http HttpHeaders getAccept
public List<MediaType> getAccept()
From source file:web.rufer.swisscom.sms.api.factory.HeaderFactoryTest.java
@Test public void createHeadersReturnsHeadersWithAcceptApplicationJson() { HttpHeaders headers = HeaderFactory.createHeaders(API_KEY); assertArrayEquals(Arrays.asList(MediaType.APPLICATION_JSON).toArray(), headers.getAccept().toArray()); }
From source file:com.orange.ngsi.client.NgsiClientTest.java
@Test public void getRequestHeadersWithoutUrl() { HttpHeaders httpHeaders = ngsiClient.getRequestHeaders(); assertEquals(MediaType.APPLICATION_XML, httpHeaders.getContentType()); assertTrue(httpHeaders.getAccept().contains(MediaType.APPLICATION_XML)); }
From source file:com.orange.ngsi.client.NgsiClientTest.java
@Test public void getRequestHeadersWithNullUrl() { HttpHeaders httpHeaders = ngsiClient.getRequestHeaders(null); assertEquals(MediaType.APPLICATION_XML, httpHeaders.getContentType()); assertTrue(httpHeaders.getAccept().contains(MediaType.APPLICATION_XML)); }
From source file:com.orange.ngsi.client.NgsiClientTest.java
@Test public void getRequestHeadersWithUrlXml() { // prepare mock when(protocolRegistry.supportXml(any())).thenReturn(true); when(protocolRegistry.supportV1Json(any())).thenReturn(false); HttpHeaders httpHeaders = ngsiClient.getRequestHeaders("localhost"); assertEquals(MediaType.APPLICATION_XML, httpHeaders.getContentType()); assertTrue(httpHeaders.getAccept().contains(MediaType.APPLICATION_XML)); }
From source file:com.orange.ngsi.client.NgsiClientTest.java
@Test public void getRequestHeadersWithUrlV1Json() { // prepare mock when(protocolRegistry.supportXml(any())).thenReturn(false); when(protocolRegistry.supportV1Json(any())).thenReturn(true); HttpHeaders httpHeaders = ngsiClient.getRequestHeaders("localhost"); assertEquals(MediaType.APPLICATION_JSON, httpHeaders.getContentType()); assertTrue(httpHeaders.getAccept().contains(MediaType.APPLICATION_JSON)); }
From source file:com.orange.ngsi.client.NgsiClientTest.java
@Test public void getRequestHeadersWithUrlV2Json() { // prepare mock when(protocolRegistry.supportXml(any())).thenReturn(false); when(protocolRegistry.supportV1Json(any())).thenReturn(false); HttpHeaders httpHeaders = ngsiClient.getRequestHeaders("localhost"); assertEquals(MediaType.APPLICATION_JSON, httpHeaders.getContentType()); assertTrue(httpHeaders.getAccept().contains(MediaType.APPLICATION_JSON)); }
From source file:com.monarchapis.driver.spring.rest.ApiErrorResponseEntityExceptionHandlerTest.java
@Test public void testHttpMediaTypeNotSupportedException() { List<MediaType> supportedMediaTypes = Lists.newArrayList(MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON); ResponseEntity<Object> response = // performTest(new HttpMediaTypeNotSupportedException(MediaType.TEXT_PLAIN, supportedMediaTypes), // 400, "mediaTypeNotSupported"); HttpHeaders headers = response.getHeaders(); assertEquals(1, headers.size());//from w w w .j a v a2 s. co m assertEquals(supportedMediaTypes, headers.getAccept()); supportedMediaTypes = Collections.emptyList(); response = // performTest(new HttpMediaTypeNotSupportedException(MediaType.TEXT_PLAIN, supportedMediaTypes), // 400, "mediaTypeNotSupported"); headers = response.getHeaders(); assertEquals(0, headers.size()); }
From source file:com.orange.cepheus.cep.EventSinkListenerTest.java
/** * Check that an updateContext is fired when a new event bean arrives *//* ww w. j a v a2 s . c om*/ @Test public void postMessageOnEventUpdate() { HttpHeaders httpHeaders = new HttpHeaders(); httpHeaders.setContentType(MediaType.APPLICATION_JSON); httpHeaders.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON)); when(statement.getText()).thenReturn("statement"); when(ngsiClient.getRequestHeaders(any())).thenReturn(httpHeaders); // Trigger event update List<ContextAttribute> attributes = new LinkedList<>(); attributes.add(new ContextAttribute("id", "string", "OUT1234")); attributes.add(new ContextAttribute("avgTemp", "double", 10.25)); attributes.add(new ContextAttribute("avgTemp_unit", "string", "celcius")); EventBean[] beans = { buildEventBean("TempSensorAvg", attributes) }; eventSinkListener.update(beans, null, statement, provider); // Capture updateContext when postUpdateContextRequest is called on updateContextRequest, ArgumentCaptor<UpdateContext> updateContextArg = ArgumentCaptor.forClass(UpdateContext.class); ArgumentCaptor<HttpHeaders> headersArg = ArgumentCaptor.forClass(HttpHeaders.class); verify(ngsiClient).updateContext(eq(broker.getUrl()), headersArg.capture(), updateContextArg.capture()); // Check updateContext is valid UpdateContext updateContext = updateContextArg.getValue(); assertEquals(UpdateAction.APPEND, updateContext.getUpdateAction()); assertEquals(1, updateContext.getContextElements().size()); // Check headers are valid HttpHeaders headers = headersArg.getValue(); assertEquals(MediaType.APPLICATION_JSON, headers.getContentType()); assertTrue(headers.getAccept().contains(MediaType.APPLICATION_JSON)); assertEquals("SN", headers.getFirst("Fiware-Service")); assertEquals("SP", headers.getFirst("Fiware-ServicePath")); assertEquals("AUTH_TOKEN", headers.getFirst("X-Auth-Token")); ContextElement contextElement = updateContext.getContextElements().get(0); assertEquals("OUT1234", contextElement.getEntityId().getId()); assertEquals("TempSensorAvg", contextElement.getEntityId().getType()); assertFalse(contextElement.getEntityId().getIsPattern()); assertEquals(1, contextElement.getContextAttributeList().size()); ContextAttribute attr = contextElement.getContextAttributeList().get(0); assertEquals("avgTemp", attr.getName()); assertEquals("double", attr.getType()); assertEquals(10.25, attr.getValue()); assertEquals(1, attr.getMetadata().size()); assertEquals("unit", attr.getMetadata().get(0).getName()); assertEquals("string", attr.getMetadata().get(0).getType()); assertEquals("celcius", attr.getMetadata().get(0).getValue()); }
From source file:org.cloudfoundry.identity.uaa.api.common.impl.UaaConnectionHelper.java
/** * Add the Authorization, Content-Type, and Accept headers to the request * /*from w ww . j a v a 2s .c om*/ * @param headers */ private void getHeaders(HttpHeaders headers) { OAuth2AccessToken token = getAccessToken(); headers.add("Authorization", token.getTokenType() + " " + token.getValue()); if (headers.getContentType() == null) { headers.setContentType(MediaType.APPLICATION_JSON); } if (headers.getAccept() == null || headers.getAccept().size() == 0) { headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON)); } }
From source file:org.springframework.cloud.stream.app.http.source.DefaultMixedCaseContentTypeHttpHeaderMapper.java
private Object getHttpHeader(HttpHeaders source, String name) { if (ACCEPT.equalsIgnoreCase(name)) { return source.getAccept(); } else if (ACCEPT_CHARSET.equalsIgnoreCase(name)) { return source.getAcceptCharset(); } else if (ALLOW.equalsIgnoreCase(name)) { return source.getAllow(); } else if (CACHE_CONTROL.equalsIgnoreCase(name)) { String cacheControl = source.getCacheControl(); return (StringUtils.hasText(cacheControl)) ? cacheControl : null; } else if (CONTENT_LENGTH.equalsIgnoreCase(name)) { long contentLength = source.getContentLength(); return (contentLength > -1) ? contentLength : null; } else if (CONTENT_TYPE.equalsIgnoreCase(name)) { return source.getContentType(); } else if (DATE.equalsIgnoreCase(name)) { long date = source.getDate(); return (date > -1) ? date : null; } else if (ETAG.equalsIgnoreCase(name)) { String eTag = source.getETag(); return (StringUtils.hasText(eTag)) ? eTag : null; } else if (EXPIRES.equalsIgnoreCase(name)) { try {/*from ww w. j av a 2s . c o m*/ long expires = source.getExpires(); return (expires > -1) ? expires : null; } catch (Exception e) { if (logger.isDebugEnabled()) { logger.debug(e.getMessage()); } // According to RFC 2616 return null; } } else if (IF_NONE_MATCH.equalsIgnoreCase(name)) { return source.getIfNoneMatch(); } else if (IF_MODIFIED_SINCE.equalsIgnoreCase(name)) { long modifiedSince = source.getIfModifiedSince(); return (modifiedSince > -1) ? modifiedSince : null; } else if (IF_UNMODIFIED_SINCE.equalsIgnoreCase(name)) { String unmodifiedSince = source.getFirst(IF_UNMODIFIED_SINCE); return unmodifiedSince != null ? this.getFirstDate(unmodifiedSince, IF_UNMODIFIED_SINCE) : null; } else if (LAST_MODIFIED.equalsIgnoreCase(name)) { long lastModified = source.getLastModified(); return (lastModified > -1) ? lastModified : null; } else if (LOCATION.equalsIgnoreCase(name)) { return source.getLocation(); } else if (PRAGMA.equalsIgnoreCase(name)) { String pragma = source.getPragma(); return (StringUtils.hasText(pragma)) ? pragma : null; } return source.get(name); }