List of usage examples for org.apache.http.message BasicHeader BasicHeader
public BasicHeader(String str, String str2)
From source file:com.epam.wilma.browsermob.transformer.HttpResponseTransformerTest.java
@BeforeMethod public void setUp() { MockitoAnnotations.initMocks(this); given(responseFactory.createNewWilmaHttpResponse(false)).willReturn(response); requestHeaders = new Header[1]; responseHeaders = new Header[1]; requestHeaders[0] = new BasicHeader("reqName", "reqValue"); responseHeaders[0] = new BasicHeader("respName", "respValue"); }
From source file:org.elasticsearch.example.realm.CustomRealmIT.java
public void testHttpAuthentication() throws Exception { Response response = getRestClient().performRequest("GET", "/", new BasicHeader(CustomRealm.USER_HEADER, CustomRealm.KNOWN_USER), new BasicHeader(CustomRealm.PW_HEADER, CustomRealm.KNOWN_PW.toString())); assertThat(response.getStatusLine().getStatusCode(), is(200)); }
From source file:org.georchestra.security.ImpersonateUserRequestHeaderProvider.java
@Override protected Collection<Header> getCustomRequestHeaders(HttpSession session, HttpServletRequest originalRequest) { if (originalRequest.getHeader(HeaderNames.IMP_USERNAME) != null) { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); if (authentication != null && trustedUsers != null && trustedUsers.contains(authentication.getName())) { List<Header> headers = new ArrayList<Header>(2); headers.add(new BasicHeader(HeaderNames.SEC_USERNAME, originalRequest.getHeader(HeaderNames.IMP_USERNAME))); headers.add(/* w w w.ja v a 2 s .c o m*/ new BasicHeader(HeaderNames.SEC_ROLES, originalRequest.getHeader(HeaderNames.IMP_ROLES))); return headers; } } return Collections.emptyList(); }
From source file:com.eTilbudsavis.etasdk.network.impl.HttpURLNetwork.java
public HttpResponse performNetworking(Request<?> request) throws ClientProtocolException, IOException { URL url = new URL(Utils.requestToUrlAndQueryString(request)); HttpURLConnection connection = openConnection(url, request); setHeaders(request, connection);//from ww w . ja v a2s.co m setRequestMethod(connection, request); int sc = connection.getResponseCode(); if (sc == -1) { throw new IOException("Connection returned invalid response code."); } ProtocolVersion pv = new ProtocolVersion("HTTP", 1, 1); String rm = connection.getResponseMessage(); BasicHttpResponse response = new BasicHttpResponse(pv, sc, rm); HttpEntity entity = getEntity(connection); response.setEntity(entity); for (Entry<String, List<String>> header : connection.getHeaderFields().entrySet()) { if (header.getKey() != null) { Header h = new BasicHeader(header.getKey(), header.getValue().get(0)); response.addHeader(h); } } return response; }
From source file:org.etk.common.net.ETKHttpClient.java
public HttpEntity execute(String targetURL) throws ClientProtocolException, IOException { HttpHost targetHost = new HttpHost("127.0.0.1", 8080, "http"); httpClient.getCredentialsProvider().setCredentials( new AuthScope(targetHost.getHostName(), targetHost.getPort()), new UsernamePasswordCredentials("demo", "gtn")); // Create AuthCache instance AuthCache authCache = new BasicAuthCache(); // Generate BASIC scheme object and add it to the local auth cache BasicScheme basicAuth = new BasicScheme(); authCache.put(targetHost, basicAuth); // Add AuthCache to the execution context BasicHttpContext localcontext = new BasicHttpContext(); localcontext.setAttribute(ClientContext.AUTH_CACHE, authCache); HttpGet httpget = new HttpGet(targetURL); Header header = new BasicHeader("Content-Type", "application/json"); httpget.setHeader(header);//from w w w . j a va 2s . c om HttpResponse response = httpClient.execute(targetHost, httpget, localcontext); DumpHttpResponse.dumpHeader(response); HttpEntity entity = response.getEntity(); if (entity != null) { entity = new BufferedHttpEntity(entity); } EntityUtils.consume(entity); return entity; }
From source file:org.apereo.portal.soffit.connector.PreferencesHeaderProvider.java
@Override public Header createHeader(RenderRequest renderRequest, RenderResponse renderResponse) { // Username/* w ww.j ava 2 s . c om*/ final String username = getUsername(renderRequest); // PreferencesMap final Map<String, List<String>> preferencesMap = new HashMap<>(); final PortletPreferences prefs = renderRequest.getPreferences(); for (Map.Entry<String, String[]> y : prefs.getMap().entrySet()) { final String name = y.getKey(); /* * We ignore (skip) preferences that exist for the benefit of the * SoffitConnectorController. */ if (name.startsWith(SoffitConnectorController.CONNECTOR_PREFERENCE_PREFIX)) { continue; } List<String> values = Arrays.asList(prefs.getValues(name, new String[0])); if (!values.isEmpty()) { preferencesMap.put(name, values); } } // Preferences header final Preferences preferences = preferencesService.createPreferences(preferencesMap, username, getExpiration(renderRequest)); final Header rslt = new BasicHeader(Headers.PREFERECES.getName(), preferences.getEncryptedToken()); logger.debug("Produced the following Preferences header for username='{}': {}", username, rslt); return rslt; }
From source file:com.huawei.ais.demo.TokenDemo.java
/** * ?Token? ??HTTPHeader???Token//from w w w . j av a 2 s.com * ???: X-Subject-Token * * @param username ?? * @param password ? * @param regionName ???? * @return ?Token * @throws URISyntaxException * @throws UnsupportedOperationException * @throws IOException */ private static String getToken(String username, String password, String regionName) throws URISyntaxException, UnsupportedOperationException, IOException { // 1.?Token?? String requestBody = requestBody(username, password, username, regionName); String url = "https://iam.cn-north-1.myhuaweicloud.com/v3/auth/tokens"; Header[] headers = new Header[] { new BasicHeader("Content-Type", ContentType.APPLICATION_JSON.toString()) }; StringEntity stringEntity = new StringEntity(requestBody, "utf-8"); // 2.IAM??, POST??Token value HttpResponse response = HttpClientUtils.post(url, headers, stringEntity); Header[] xst = response.getHeaders("X-Subject-Token"); return xst[0].getValue(); }
From source file:org.sonatype.nexus.httpclient.NexusRedirectStrategyTest.java
@Test public void doNotFollowRedirectsToDirIndex() throws ProtocolException { when(response.getStatusLine()).thenReturn(statusLine); final RedirectStrategy underTest = new NexusRedirectStrategy(); HttpContext httpContext;//ww w . j ava 2s.c o m // no location header request = new HttpGet("http://localhost/dir/fileA"); httpContext = new BasicHttpContext(); httpContext.setAttribute(NexusRedirectStrategy.CONTENT_RETRIEVAL_MARKER_KEY, Boolean.TRUE); when(statusLine.getStatusCode()).thenReturn(HttpStatus.SC_OK); assertThat(underTest.isRedirected(request, response, httpContext), is(false)); // redirect to file request = new HttpGet("http://localhost/dir/fileA"); httpContext = new BasicHttpContext(); httpContext.setAttribute(NexusRedirectStrategy.CONTENT_RETRIEVAL_MARKER_KEY, Boolean.TRUE); when(statusLine.getStatusCode()).thenReturn(HttpStatus.SC_MOVED_TEMPORARILY); when(response.getFirstHeader("location")) .thenReturn(new BasicHeader("location", "http://localhost/dir/fileB")); assertThat(underTest.isRedirected(request, response, httpContext), is(true)); // redirect to dir request = new HttpGet("http://localhost/dir"); httpContext = new BasicHttpContext(); httpContext.setAttribute(NexusRedirectStrategy.CONTENT_RETRIEVAL_MARKER_KEY, Boolean.TRUE); when(statusLine.getStatusCode()).thenReturn(HttpStatus.SC_MOVED_TEMPORARILY); when(response.getFirstHeader("location")).thenReturn(new BasicHeader("location", "http://localhost/dir/")); assertThat(underTest.isRedirected(request, response, httpContext), is(false)); }
From source file:fr.xebia.workshop.android.core.utils.ServerUtils.java
private static HttpRequestBase buildUserRegistationRequest(PlusClient plusClient) throws JSONException, UnsupportedEncodingException { HttpPost postRequest = new HttpPost(USER_REGISTRATION_URL); postRequest.setHeader(new BasicHeader(HTTP.CONTENT_TYPE, "application/json")); JSONObject regObject = new JSONObject(); regObject.put("email", plusClient.getAccountName()); Person currentPerson = plusClient.getCurrentPerson(); regObject.put("firstName", currentPerson.getName().getGivenName()); regObject.put("lastName", currentPerson.getName().getFamilyName()); postRequest.setEntity(new StringEntity(regObject.toString())); return postRequest; }
From source file:com.appdirect.sdk.feature.OrderValidationIsWiredUpIntegrationTest.java
private CloseableHttpClient createHttpClient() { return HttpClients.custom().setUserAgent("Apache-HttpClient/4.3.6 (java 1.5)") .setDefaultHeaders(asList(new BasicHeader(HttpHeaders.ACCEPT, "application/json, application/xml"), new BasicHeader(HttpHeaders.ACCEPT_ENCODING, "gzip, deflate"), new BasicHeader(HttpHeaders.CONTENT_TYPE, "application/x-www-form-urlencoded"))) .disableRedirectHandling().build(); }