Example usage for org.apache.http.message BasicHeader BasicHeader

List of usage examples for org.apache.http.message BasicHeader BasicHeader

Introduction

In this page you can find the example usage for org.apache.http.message BasicHeader BasicHeader.

Prototype

public BasicHeader(String str, String str2) 

Source Link

Usage

From source file:org.apereo.portal.soffit.connector.PortalRequestHeaderProvider.java

@Override
public Header createHeader(RenderRequest renderRequest, RenderResponse renderResponse) {

    // Username//from www  . j a  va  2  s. c  om
    final String username = getUsername(renderRequest);

    // Properties
    final Map<String, String> properties = new HashMap<>();
    final Enumeration<String> names = renderRequest.getPropertyNames();
    for (String propertyName = names.nextElement(); names
            .hasMoreElements(); propertyName = names.nextElement()) {
        properties.put(propertyName, renderRequest.getProperty(propertyName));
    }

    // Attributes
    final Map<String, List<String>> attributes = new HashMap<>();
    attributes.put(Attributes.NAMESPACE.getName(),
            Collections.singletonList(NAMESPACE_PREFIX + renderRequest.getWindowID()));
    attributes.put(Attributes.MODE.getName(),
            Collections.singletonList(renderRequest.getPortletMode().toString()));
    attributes.put(Attributes.WINDOW_STATE.getName(),
            Collections.singletonList(renderRequest.getWindowState().toString()));
    attributes.put(Attributes.PORTAL_INFO.getName(),
            Collections.singletonList(renderRequest.getPortalContext().getPortalInfo()));
    attributes.put(Attributes.SCHEME.getName(), Collections.singletonList(renderRequest.getScheme()));
    attributes.put(Attributes.SERVER_NAME.getName(), Collections.singletonList(renderRequest.getServerName()));
    attributes.put(Attributes.SERVER_PORT.getName(),
            Collections.singletonList(Integer.valueOf(renderRequest.getServerPort()).toString()));
    attributes.put(Attributes.SECURE.getName(),
            Collections.singletonList(Boolean.valueOf(renderRequest.isSecure()).toString()));

    // Parameters
    final Map<String, List<String>> parameters = new HashMap<>();
    for (Map.Entry<String, String[]> y : renderRequest.getParameterMap().entrySet()) {
        parameters.put(y.getKey(), Arrays.asList(y.getValue()));
    }

    // Preferences header
    final PortalRequest portalRequest = portalRequestService.createPortalRequest(properties, attributes,
            parameters, username, getExpiration(renderRequest));
    final Header rslt = new BasicHeader(Headers.PORTAL_REQUEST.getName(), portalRequest.getEncryptedToken());
    logger.debug("Produced the following PortalRequest header for username='{}':  {}", username, rslt);

    return rslt;
}

From source file:cn.edu.nju.software.gof.web.AbstractHttpEntity.java

/**
 * Specifies the Content-Type header, as a string.
 * The default implementation calls/*w  ww  .  j a  v a  2s. co m*/
 * {@link #setContentType(Header) setContentType(Header)}.
 *
 * @param ctString     the new Content-Type header, or
 *                     <code>null</code> to unset
 */
public void setContentType(final String ctString) {
    Header h = null;
    if (ctString != null) {
        h = new BasicHeader(HTTP.CONTENT_TYPE, ctString);
    }
    setContentType(h);
}

From source file:org.codehaus.httpcache4j.resolver.HTTPClientResponseResolverTest.java

@Test
public void testPUT() throws IOException {
    HTTPClientResponseResolver resolver = new TestableResolver();
    HttpResponse mockedResponse = mock(HttpResponse.class);
    when(mockedResponse.getAllHeaders()).thenReturn(new org.apache.http.Header[] {
            new BasicHeader("Date", HeaderUtils.toHttpDate("Date", new DateTime()).getValue()) });
    when(mockedResponse.getStatusLine()).thenReturn(new BasicStatusLine(new HttpVersion(1, 1), 200, "OK"));
    when(mockedResponse.getEntity()).thenReturn(null);
    when(client.execute(Mockito.<HttpUriRequest>anyObject())).thenReturn(mockedResponse);
    HTTPResponse response = resolver.resolve(new HTTPRequest(URI.create("http://www.vg.no"), HTTPMethod.PUT));
    assertNotNull("Response was null", response);
    assertEquals("Wrong header size", 1, response.getHeaders().size());
    assertFalse("Response did have payload", response.hasPayload());
}

From source file:org.sonatype.nexus.apachehttpclient.NexusConnectionKeepAliveStrategyTest.java

@Test
public void keepAliveServerValueIfLessWithMaxConnCount() {
    // server response says 3s
    // server wins
    final List<Header> headers = new ArrayList<Header>(1);
    headers.add(new BasicHeader("Keep-Alive", "timeout=3, max=100"));
    Mockito.when(httpResponse.headerIterator(Mockito.anyString()))
            .thenReturn(new BasicListHeaderIterator(headers, null));
    final long keepAlive = subject.getKeepAliveDuration(httpResponse, httpContext);
    MatcherAssert.assertThat(keepAlive, Matchers.is(3000l));
}

From source file:com.joyent.manta.client.MantaDirectoryListingIteratorTest.java

public void throwsAppropriateExceptionWhenListingObject() throws Exception {
    final String dirPath = "/user/stor/directory";
    final Header contentTypeHeader = new BasicHeader(CONTENT_TYPE,
            ContentType.APPLICATION_OCTET_STREAM.toString());

    when(responseEntity.getContentType()).thenReturn(contentTypeHeader);
    when(response.getFirstHeader(CONTENT_TYPE)).thenReturn(contentTypeHeader);
    when(response.getAllHeaders()).thenReturn(new Header[] { contentTypeHeader });

    // uncomment once it's okay to call next before hasNext
    Assert.expectThrows(MantaUnexpectedObjectTypeException.class,
            () -> new MantaDirectoryListingIterator(dirPath, httpHelper, MAX_RESULTS).next());

    Assert.expectThrows(MantaUnexpectedObjectTypeException.class,
            () -> new MantaDirectoryListingIterator(dirPath, httpHelper, MAX_RESULTS).hasNext());
}

From source file:org.soyatec.windowsazure.blob.internal.BlobConstraints.java

public IBlobConstraints isDestinationUnmodifiedSince(Timestamp time) {
    constraints.add(new BasicHeader(HeaderNames.IfUnmodifiedSince, formatTime(time)));
    return this;
}

From source file:org.elasticsearch.http.CorsRegexIT.java

public void testThatSendingNoOriginHeaderReturnsNoAccessControlHeader() throws IOException {
    Response response = getRestClient().performRequest("GET", "/",
            new BasicHeader("User-Agent", "Mozilla Bar"));
    assertThat(response.getStatusLine().getStatusCode(), is(200));
    assertThat(response.getHeader("Access-Control-Allow-Origin"), nullValue());
}

From source file:com.fine47.http.request.AbstractRequest.java

/**
 * Create a new request for the specified end-point URL along with the
 * specified content type and optionally an accompanying meta-data.
 *
 * @param url request URL/* w ww  .  j  ava  2  s  . c o  m*/
 * @param contentType request's content type
 * @param metaData optional meta-data to accompany the request
 */
protected AbstractRequest(String url, String contentType, M metaData) {
    super();

    this.url = url;
    this.metaData = metaData;
    this.contentType = contentType;

    // Add a header to signal that we can decode GZIP data.
    headers = new ArrayList();
    headers.add(new BasicHeader(AsyncHttpClient.HEADER_ACCEPT_ENCODING, AsyncHttpClient.ENCODING_GZIP));

    if (ActivityHttpClient.isDebugging()) {
        Log.d(ActivityHttpClient.LOG_TAG, "Request: " + this);
    }
}

From source file:org.apereo.portal.soffit.AuthorizationHeaderProvider.java

@Override
public Header createHeader(RenderRequest renderRequest, RenderResponse renderResponse) {

    // Username//w w w  .  ja  v  a2 s  .  c  om
    final String username = getUsername(renderRequest);

    // Attributes
    final Map<String, List<String>> attributes = new HashMap<>();
    final IPersonAttributes person = personAttributeDao.getPerson(username);
    if (person != null) {
        for (Entry<String, List<Object>> y : person.getAttributes().entrySet()) {
            final List<String> values = new ArrayList<>();
            for (Object value : y.getValue()) {
                if (value instanceof String) {
                    values.add((String) value);
                }
            }
            attributes.put(y.getKey(), values);
        }
    }
    logger.debug("Found the following user attributes for username='{}':  {}", username, attributes);

    // Groups
    final List<String> groups = new ArrayList<>();
    final IGroupMember groupMember = GroupService.getGroupMember(username, IPerson.class);
    if (groupMember != null) {
        Set<IEntityGroup> ancestors = groupMember.getAncestorGroups();
        for (IEntityGroup g : ancestors) {
            groups.add(g.getName());
        }
    }
    logger.debug("Found the following group affiliations for username='{}':  {}", username, groups);

    // Expiration of the Bearer token
    final PortletSession portletSession = renderRequest.getPortletSession();
    final Date expires = new Date(
            portletSession.getLastAccessedTime() + ((long) portletSession.getMaxInactiveInterval() * 1000L));

    // Authorization header
    final Bearer bearer = bearerService.createBearer(username, attributes, groups, expires);
    final Header rslt = new BasicHeader(Headers.AUTHORIZATION.getName(),
            Headers.BEARER_TOKEN_PREFIX + bearer.getEncryptedToken());
    logger.debug("Produced the following Authorization header for username='{}':  {}", username, rslt);

    return rslt;
}

From source file:com.okta.sdk.framework.JsonApiClient.java

@Override
protected void setContentTypeHeader(HttpUriRequest httpUriRequest) throws IOException {
    Header contentTypeHeader = new BasicHeader("Content-type", "application/json");
    httpUriRequest.setHeader(contentTypeHeader);
}