/** * Test parse with quoted text */ public void testParse3() throws Exception { String headerValue = "name=\"Doe, John\";version=1;max-age=600;secure;domain=.apache.org"; Header header = new Header("set-cookie", headerValue); CookieSpec cookiespec = new CookieSpecBase(); Cookie[] cookies = cookieParse(cookiespec, "www.apache.org", 80, "/", false, header); assertEquals(1, cookies.length); assertEquals("name", cookies[0].getName()); assertEquals("Doe, John", cookies[0].getValue()); assertEquals(null, cookies[0].getComment()); assertEquals(0, cookies[0].getVersion()); assertEquals(".apache.org", cookies[0].getDomain()); assertEquals("/", cookies[0].getPath()); assertTrue(cookies[0].getSecure()); }
@Override public List<TestResult> run() { List<TestResult> results = new ArrayList<TestResult>(); results.add(doSort("Sort users in ascending order in XML", new Header("Accept", "application/xml"), "ascending", "XML", "/Users", "userName")); results.add(doSort("Sort users in descending order in XML", new Header("Accept", "application/xml"), "descending", "XML", "/Users", "userName")); results.add(doSort("Sort groups in ascending order in XML", new Header("Accept", "application/xml"), "ascending", "XML", "/Groups", "displayName")); results.add(doSort("Sort groups in descending order in XML", new Header("Accept", "application/xml"), "descending", "XML", "/Groups", "displayName")); results.add(doSort("Sort users in ascending order in JSON", new Header("Accept", "application/json"), "ascending", "JSON", "/Users", "userName")); results.add(doSort("Sort users in descending order in JSON", new Header("Accept", "application/json"), "descending", "JSON", "/Users", "userName")); results.add(doSort("Sort groups in ascending order in JSON", new Header("Accept", "application/json"), "ascending", "JSON", "/Groups", "displayName")); results.add(doSort("Sort groups in descending order in JSON", new Header("Accept", "application/json"), "descending", "JSON", "/Groups", "displayName")); return results; }
public void testCustomAuthorizationHeader() throws Exception { UsernamePasswordCredentials creds = new UsernamePasswordCredentials("testuser", "testpass"); HttpRequestHandlerChain handlerchain = new HttpRequestHandlerChain(); handlerchain.appendHandler(new AuthRequestHandler(creds)); handlerchain.appendHandler(new HttpServiceHandler(new FeedbackService())); this.server.setRequestHandler(handlerchain); GetMethod httpget = new GetMethod("/test/"); String authResponse = "Basic " + EncodingUtil.getAsciiString( Base64.encodeBase64(EncodingUtil.getAsciiBytes("testuser:testpass"))); httpget.addRequestHeader(new Header("Authorization", authResponse)); try { this.client.executeMethod(httpget); } finally { httpget.releaseConnection(); } assertNotNull(httpget.getStatusLine()); assertEquals(HttpStatus.SC_OK, httpget.getStatusLine().getStatusCode()); }
public static SimpleResponse getResponse(int statusCode) { Integer code = new Integer(statusCode); SimpleResponse response = (SimpleResponse)responses.get(code); if (response == null) { response = new SimpleResponse(); response.setStatusLine(HttpVersion.HTTP_1_0, statusCode); response.setHeader(new Header("Content-Type", "text/plain; charset=US-ASCII")); String s = HttpStatus.getStatusText(statusCode); if (s == null) { s = "Error " + statusCode; } response.setBodyString(s); response.addHeader(new Header("Connection", "close")); response.addHeader(new Header("Content-Lenght", Integer.toString(s.length()))); responses.put(code, response); } return response; }
/** * Will write all response headers received in the method to the response. * One header, connection, is however omitted since we will only want the * client to keep his connection to the proxy not to the backing server. * * @param response * The response that will have headers written to it */ protected void setHeaders(HttpServletResponse response) { Header[] headers = method.getResponseHeaders(); for (int i = 0; i < headers.length; i++) { Header header = headers[i]; String name = header.getName(); boolean contentLength = name.equalsIgnoreCase("content-length"); boolean connection = name.equalsIgnoreCase("connection"); if (!contentLength && !connection) { response.addHeader(name, header.getValue()); } } setViaHeader(response); }
@Test public void testSingleCellGetPutBinary() throws IOException { final String path = "/" + TABLE + "/" + ROW_3 + "/" + COLUMN_1; final byte[] body = Bytes.toBytes(VALUE_3); Response response = client.put(path, Constants.MIMETYPE_BINARY, body); assertEquals(response.getCode(), 200); Thread.yield(); response = client.get(path, Constants.MIMETYPE_BINARY); assertEquals(response.getCode(), 200); assertEquals(Constants.MIMETYPE_BINARY, response.getHeader("content-type")); assertTrue(Bytes.equals(response.getBody(), body)); boolean foundTimestampHeader = false; for (Header header: response.getHeaders()) { if (header.getName().equals("X-Timestamp")) { foundTimestampHeader = true; break; } } assertTrue(foundTimestampHeader); response = deleteRow(TABLE, ROW_3); assertEquals(response.getCode(), 200); }
protected Document makeBlob(byte[] data){ Document document = XMLUtils.getDefaultDocumentBuilder().newDocument(); Element blob = document.createElement("blob"); document.appendChild(blob); Header[] heads = context.getResponseHeaders(); for (int i = 0; i < heads.length; i++) { if (HeaderName.ContentType.is(heads[i].getName()) || HeaderName.ContentLength.is(heads[i].getName()) ) { blob.setAttribute(heads[i].getName(), heads[i].getValue()); } } blob.setAttribute("Referer", ((HtmlConnector)context.getConnector()).getReferer()); blob.appendChild(document.createTextNode(Base64.encodeBase64String(data))); return document; }
@Override protected void appendToOutputDom(NodeList nodeList, Document outputDom) { Element doc = outputDom.getDocumentElement(); Element httpHeaders = outputDom.createElement(tagName); Element headerElement; Header header; int length = contextHeaders.length; for (int i = 0 ; i < length ; i++) { if (!isRequestedObjectRunning()) break; header = contextHeaders[i]; headerElement = outputDom.createElement("header"); headerElement.setAttribute("headerName", header.getName()); headerElement.setAttribute("headerValue", header.getValue()); httpHeaders.appendChild(headerElement); Engine.logBeans.trace("HttpHeader '" + headerElement.getAttribute("headerName") + " : " + headerElement.getAttribute("headerValue") + "' added to httpHeaders."); } doc.appendChild(httpHeaders); Engine.logBeans.trace("HttpHeaders added to result document."); }
/** * Return the header field key * @param keyPosition The key position * @return The header field key. * @see java.net.HttpURLConnection#getHeaderFieldKey(int) * @see org.apache.commons.httpclient.HttpMethod#getResponseHeaders() */ public String getHeaderFieldKey(int keyPosition) { LOG.trace("enter HttpURLConnection.getHeaderFieldKey(int)"); // Note: HttpClient does not consider the returned Status Line as // a response header. However, getHeaderFieldKey(0) is supposed to // return null. Hence the special case below ... if (keyPosition == 0) { return null; } // Note: HttpClient does not currently keep headers in the same order // that they are read from the HTTP server. Header[] headers = this.method.getResponseHeaders(); if (keyPosition < 0 || keyPosition > headers.length) { return null; } return headers[keyPosition - 1].getName(); }
public static String getPostResponseHeader(String url,String argJson,List<UHeader> headerList,String headerName){ String info = ""; try { HttpClient client = new HttpClient(); PostMethod method = new PostMethod(url); client.getParams().setContentCharset("UTF-8"); if(headerList.size()>0){ for(int i = 0;i<headerList.size();i++){ UHeader header = headerList.get(i); method.setRequestHeader(header.getHeaderTitle(),header.getHeaderValue()); } } method.getParams().setParameter( HttpMethodParams.HTTP_CONTENT_CHARSET, "UTF-8"); if(argJson != null && !argJson.trim().equals("")) { RequestEntity requestEntity = new StringRequestEntity(argJson,"application/json","UTF-8"); method.setRequestEntity(requestEntity); } method.releaseConnection(); Header h = method.getResponseHeader(headerName); info = h.getValue(); } catch (IOException e) { e.printStackTrace(); } return info; }
public void testParseSimple() throws Exception { Header header = new Header("Set-Cookie","cookie-name=cookie-value"); CookieSpec cookiespec = new CookieSpecBase(); Cookie[] parsed = cookieParse(cookiespec, "127.0.0.1", 80, "/path/path", false, header); assertEquals("Found 1 cookie.",1,parsed.length); assertEquals("Name","cookie-name",parsed[0].getName()); assertEquals("Value","cookie-value",parsed[0].getValue()); assertTrue("Comment",null == parsed[0].getComment()); assertTrue("ExpiryDate",null == parsed[0].getExpiryDate()); //assertTrue("isToBeDiscarded",parsed[0].isToBeDiscarded()); assertTrue("isPersistent",!parsed[0].isPersistent()); assertEquals("Domain","127.0.0.1",parsed[0].getDomain()); assertEquals("Path","/path",parsed[0].getPath()); assertTrue("Secure",!parsed[0].getSecure()); assertEquals("Version",0,parsed[0].getVersion()); }
public void testKeepCloverHappy() throws Exception { CookieSpec cookiespec = new IgnoreCookiesSpec(); cookiespec.parseAttribute(null, null); cookiespec.parse("host", 80, "/", false, (String)null); cookiespec.parse("host", 80, "/", false, (Header)null); cookiespec.validate("host", 80, "/", false, (Cookie)null); cookiespec.match("host", 80, "/", false, (Cookie)null); cookiespec.match("host", 80, "/", false, (Cookie [])null); cookiespec.domainMatch(null, null); cookiespec.pathMatch(null, null); cookiespec.match("host", 80, "/", false, (Cookie [])null); cookiespec.formatCookie(null); cookiespec.formatCookies(null); cookiespec.formatCookieHeader((Cookie)null); cookiespec.formatCookieHeader((Cookie [])null); }
public void testCookieVersionSupportHeader1() throws IOException { this.server.setHttpService(new CookieVer0Service()); this.client.getParams().setCookiePolicy(CookiePolicy.RFC_2965); GetMethod httpget1 = new GetMethod("/test/"); try { this.client.executeMethod(httpget1); } finally { httpget1.releaseConnection(); } GetMethod httpget2 = new GetMethod("/test/"); try { this.client.executeMethod(httpget2); } finally { httpget2.releaseConnection(); } Header cookiesupport = httpget2.getRequestHeader("Cookie2"); assertNotNull(cookiesupport); assertEquals("$Version=\"1\"", cookiesupport.getValue()); }
public void testParseNoValue() throws Exception { Header header = new Header("Set-Cookie","cookie-name="); CookieSpec cookiespec = new CookieSpecBase(); Cookie[] parsed = cookieParse(cookiespec, "127.0.0.1", 80, "/", false, header); assertEquals("Found 1 cookie.",1,parsed.length); assertEquals("Name","cookie-name",parsed[0].getName()); assertEquals("Value", "", parsed[0].getValue()); assertTrue("Comment",null == parsed[0].getComment()); assertTrue("ExpiryDate",null == parsed[0].getExpiryDate()); //assertTrue("isToBeDiscarded",parsed[0].isToBeDiscarded()); assertTrue("isPersistent",!parsed[0].isPersistent()); assertEquals("Domain","127.0.0.1",parsed[0].getDomain()); assertEquals("Path","/",parsed[0].getPath()); assertTrue("Secure",!parsed[0].getSecure()); assertEquals("Version",0,parsed[0].getVersion()); }
/** * <p> * This implementation will parse the <tt>Allow</tt> header to obtain * the set of methods supported by the resource identified by the Request-URI. * </p> * * @param state the {@link HttpState state} information associated with this method * @param conn the {@link HttpConnection connection} used to execute * this HTTP method * * @see #readResponse * @see #readResponseHeaders * @since 2.0 */ protected void processResponseHeaders(HttpState state, HttpConnection conn) { LOG.trace("enter OptionsMethod.processResponseHeaders(HttpState, HttpConnection)"); Header allowHeader = getResponseHeader("allow"); if (allowHeader != null) { String allowHeaderValue = allowHeader.getValue(); StringTokenizer tokenizer = new StringTokenizer(allowHeaderValue, ","); while (tokenizer.hasMoreElements()) { String methodAllowed = tokenizer.nextToken().trim().toUpperCase(); methodsAllowed.addElement(methodAllowed); } } }
/** * Returns the request's charset. The charset is parsed from the request entity's * content type, unless the content type header has been set manually. * * @see RequestEntity#getContentType() * * @since 3.0 */ public String getRequestCharSet() { if (getRequestHeader("Content-Type") == null) { // check the content type from request entity // We can't call getRequestEntity() since it will probably call // this method. if (this.requestEntity != null) { return getContentCharSet( new Header("Content-Type", requestEntity.getContentType())); } else { return super.getRequestCharSet(); } } else { return super.getRequestCharSet(); } }
void testScannerResultCodes() throws Exception { Header[] headers = new Header[3]; headers[0] = new Header("Content-Type", Constants.MIMETYPE_XML); headers[1] = new Header("Accept", Constants.MIMETYPE_JSON); headers[2] = new Header("Accept-Encoding", "gzip"); Response response = client.post("/" + TABLE + "/scanner", headers, "<Scanner/>".getBytes()); assertEquals(response.getCode(), 201); String scannerUrl = response.getLocation(); assertNotNull(scannerUrl); response = client.get(scannerUrl); assertEquals(response.getCode(), 200); response = client.get(scannerUrl); assertEquals(response.getCode(), 204); }
/** * Host minus domain may not contain any dots */ public void testParseWithIllegalDomain4() throws Exception { Header header = new Header("Set-Cookie", "cookie-name=cookie-value; domain=.c.com; version=1"); CookieSpec cookiespec = new RFC2109Spec(); try { Cookie[] parsed = cookieParse(cookiespec, "a.b.c.com", 80, "/", false, header); fail("MalformedCookieException should have been thrown"); } catch (MalformedCookieException e) { // expected } }
public void removeHeaders(final String s) { if (s == null) { return; } Header[] headers = this.headers.getHeaders(s); for (int i = 0; i < headers.length; i++) { this.headers.removeHeader(headers[i]); } }
public String getContentType() { for (Header hdr : headers) { if (HEADER_CONTENT_TYPE.equals( hdr.getName() )) { return hdr.getValue(); } } return null; }
public String getCharset() { String charset = DEFAULT_CONTENT_CHARSET; Header contenttype = this.headers.getFirstHeader("Content-Type"); if (contenttype != null) { HeaderElement values[] = contenttype.getElements(); if (values.length == 1) { NameValuePair param = values[0].getParameterByName("charset"); if (param != null) { charset = param.getValue(); } } } return charset; }
public void testParseWithNullPath() throws Exception { Header header = new Header("Set-Cookie", "cookie-name=cookie-value; domain=127.0.0.1; path=/; secure"); CookieSpec cookiespec = new NetscapeDraftSpec(); try { Cookie[] parsed = cookieParse(cookiespec, "127.0.0.1", 80, null, false, header); fail("IllegalArgumentException should have been thrown"); } catch (IllegalArgumentException e) { // expected } }
public void testParseWithNullHostAndPath() throws Exception { Header header = new Header("Set-Cookie", "cookie-name=cookie-value; domain=127.0.0.1; path=/; secure"); CookieSpec cookiespec = new CookieSpecBase(); try { Cookie[] parsed = cookieParse(cookiespec, null, 80, null, false, header); fail("IllegalArgumentException should have been thrown"); } catch (IllegalArgumentException e) { // expected } }
public void testParseMultipleSamePaths() throws Exception { Header header = new Header("Set-Cookie", "name1=value1;Version=1;Path=/commons,name1=value2;Version=1;Path=/commons"); CookieSpec cookiespec = new CookieSpecBase(); Cookie[] parsed = cookieParse(cookiespec, ".apache.org", 80, "/commons/httpclient", true, header); HttpState state = new HttpState(); state.addCookies(parsed); Cookie[] cookies = state.getCookies(); assertEquals("Found 1 cookies.",1,cookies.length); assertEquals("Name","name1",cookies[0].getName()); assertEquals("Value","value2",cookies[0].getValue()); }
/** * Test <tt>Domain</tt> validation. Cookie domain attribute must have a * leading dot. */ public void testValidateDomainLeadingDot() throws Exception { CookieSpec cookiespec = new RFC2965Spec(); Header header = new Header("Set-Cookie2", "name=value;Domain=domain.com;Version=1"); Cookie[] parsed = cookieParse(cookiespec, "www.domain.com", 80, "/", false, header); assertNotNull(parsed); assertEquals(1, parsed.length); Cookie2 cookie = (Cookie2) parsed[0]; assertEquals(".domain.com", cookie.getDomain()); }
public void testParseMaxageDefault() throws Exception { CookieSpec cookiespec = new RFC2965Spec(); // Max-age is OPTIONAL, defaults to session cookie Header header = new Header("Set-Cookie2", "name=value;Version=1"); Cookie[] parsed = cookiespec.parse("www.domain.com", 80, "/", false, header); assertNotNull(parsed); assertEquals(1, parsed.length); Cookie2 cookie = (Cookie2) parsed[0]; assertFalse(cookie.isPersistent()); }
public String getContentType() { Header contenttype = this.headers.getFirstHeader("Content-Type"); if (contenttype != null) { return contenttype.getValue(); } else { return "text/plain"; } }
/** * Send Request to the repository */ protected HttpMethod sendRemoteRequest(Request req) throws AuthenticationException, IOException { if (logger.isDebugEnabled()) { logger.debug(""); logger.debug("* Request: " + req.getMethod() + " " + req.getFullUri() + (req.getBody() == null ? "" : "\n" + new String(req.getBody(), "UTF-8"))); } HttpMethod method = createMethod(req); // execute method executeMethod(method); // Deal with redirect if(isRedirect(method)) { Header locationHeader = method.getResponseHeader("location"); if (locationHeader != null) { String redirectLocation = locationHeader.getValue(); method.setURI(new URI(redirectLocation, true)); httpClient.executeMethod(method); } } return method; }
public void testParseWithWrongDomain() throws Exception { Header header = new Header("Set-Cookie", "cookie-name=cookie-value; domain=127.0.0.1; version=1"); CookieSpec cookiespec = new CookieSpecBase(); try { Cookie[] parsed = cookieParse(cookiespec, "127.0.0.2", 80, "/", false, header); fail("HttpException exception should have been thrown"); } catch (HttpException e) { // expected } }
public void testPreemptiveAuthorizationTrueWithoutCreds() throws Exception { UsernamePasswordCredentials creds = new UsernamePasswordCredentials("testuser", "testpass"); HttpRequestHandlerChain handlerchain = new HttpRequestHandlerChain(); handlerchain.appendHandler(new AuthRequestHandler(creds)); handlerchain.appendHandler(new HttpServiceHandler(new FeedbackService())); HttpState state = new HttpState(); this.client.setState(state); this.client.getParams().setAuthenticationPreemptive(true); this.server.setRequestHandler(handlerchain); GetMethod httpget = new GetMethod("/test/"); try { this.client.executeMethod(httpget); } finally { httpget.releaseConnection(); } assertNotNull(httpget.getStatusLine()); assertEquals(HttpStatus.SC_UNAUTHORIZED, httpget.getStatusLine().getStatusCode()); Header auth = httpget.getRequestHeader("Authorization"); assertNull(auth); AuthState authstate = httpget.getHostAuthState(); assertNotNull(authstate.getAuthScheme()); assertTrue(authstate.getAuthScheme() instanceof BasicScheme); assertNotNull(authstate.getRealm()); assertTrue(authstate.isPreemptive()); }
/** * Decode cipher algorithm parameters from the HTTP method * * @param method HttpMethod * @return decoded algorithm parameters * @throws IOException */ protected AlgorithmParameters decodeAlgorithmParameters(HttpMethod method) throws IOException { Header header = method.getResponseHeader(HEADER_ALGORITHM_PARAMETERS); if(header != null) { byte[] algorithmParams = Base64.decode(header.getValue()); AlgorithmParameters algorithmParameters = encryptor.decodeAlgorithmParameters(algorithmParams); return algorithmParameters; } else { return null; } }
/** * Will create the method and execute it. After this the method is sent to a * ResponseHandler that is returned. * * @param httpRequest * Request we are receiving from the client * @param url * The location we are proxying to * @return A ResponseHandler that can be used to write the response * @throws MethodNotAllowedException * If the method specified by the request isn't handled * @throws IOException * When there is a problem with the streams * @throws HttpException * The httpclient can throw HttpExcetion when executing the * method */ ResponseHandler executeRequest(HttpServletRequest httpRequest, String url) throws MethodNotAllowedException, IOException, HttpException { RequestHandler requestHandler = RequestHandlerFactory .createRequestMethod(httpRequest.getMethod()); HttpMethod method = requestHandler.process(httpRequest, url); method.setFollowRedirects(false); /* * Why does method.validate() return true when the method has been * aborted? I mean, if validate returns true the API says that means * that the method is ready to be executed. TODO I don't like doing type * casting here, see above. */ if (!((HttpMethodBase) method).isAborted()) { httpClient.executeMethod(method); if (method.getStatusCode() == 405) { Header allow = method.getResponseHeader("allow"); String value = allow.getValue(); throw new MethodNotAllowedException( "Status code 405 from server", AllowedMethodHandler.processAllowHeader(value)); } } return ResponseHandlerFactory.createResponseHandler(method); }
public void testParseWithPathMismatch() throws Exception { Header header = new Header("Set-Cookie", "cookie-name=cookie-value; path=/path/path/path"); CookieSpec cookiespec = new CookieSpecBase(); try { Cookie[] parsed = cookieParse(cookiespec, "127.0.0.1", 80, "/path", false, header); fail("MalformedCookieException should have been thrown."); } catch (MalformedCookieException e) { // expected } }
protected String getContentType(final HttpMethod method) { final Header header = method.getResponseHeader("Content-Type"); if (header != null) { final String contentType = header.getValue(); if (contentType != null && !contentType.isEmpty()) { return contentType.toLowerCase(Locale.ENGLISH); } } return EMPTY; }
private void setBasicAuthorization(HttpMethod method, String userName, String password) { String userpass = userName + ":" + password; String basicAuth = "Basic " + javax.xml.bind.DatatypeConverter.printBase64Binary(userpass.getBytes()); method.addRequestHeader(new Header("Authorization", basicAuth)); }
public void testParseBlankPath() throws Exception { CookieSpec cookiespec = new RFC2965Spec(); Header header = new Header("Set-Cookie2", "name=value;Path=\" \";Version=1"); try { cookiespec.parse("www.domain.com", 80, "/", false, header); fail("MalformedCookieException should have been thrown"); } catch (MalformedCookieException ex) { // expected } }
/** * Test <tt>Domain</tt> validation when domain is not specified * in <tt>Set-Cookie2</tt> header. */ public void testValidateNoDomain() throws Exception { CookieSpec cookiespec = new RFC2965Spec(); Header header = new Header("Set-Cookie2", "name=value;Version=1"); Cookie[] parsed = cookieParse(cookiespec, "www.domain.com" /* request host */, 80, "/", false, header); assertNotNull(parsed); assertEquals(1, parsed.length); Cookie2 cookie = (Cookie2) parsed[0]; // cookie domain must string match request host assertEquals("www.domain.com", cookie.getDomain()); }
public void testParseNegativeMaxage() throws Exception { CookieSpec cookiespec = new RFC2965Spec(); Header header = new Header("Set-Cookie2", "name=value;Max-age=-3600;Version=1;"); try { cookiespec.parse("www.domain.com", 80, "/", false, header); fail("MalformedCookieException should have been thrown"); } catch (MalformedCookieException ex) { // expected } }
/** * Tests if malformatted expires attribute is parsed correctly. */ public void testCookieWithComma() throws Exception { Header header = new Header("Set-Cookie", "name=value; expires=\"Thu, 01-Jan-1970 00:00:00 GMT"); CookieSpec cookiespec = new CookieSpecBase(); try { Cookie[] cookies = cookiespec.parse("localhost", 80, "/", false, header); fail("MalformedCookieException should have been thrown"); } catch (MalformedCookieException expected) { } }
public void testBasicAuthenticationWithDefaultCreds() throws Exception { UsernamePasswordCredentials creds = new UsernamePasswordCredentials("testuser", "testpass"); HttpRequestHandlerChain handlerchain = new HttpRequestHandlerChain(); handlerchain.appendHandler(new AuthRequestHandler(creds)); handlerchain.appendHandler(new HttpServiceHandler(new FeedbackService())); HttpState state = new HttpState(); state.setCredentials(AuthScope.ANY, creds); this.client.setState(state); this.server.setRequestHandler(handlerchain); GetMethod httpget = new GetMethod("/test/"); try { this.client.executeMethod(httpget); } finally { httpget.releaseConnection(); } assertNotNull(httpget.getStatusLine()); assertEquals(HttpStatus.SC_OK, httpget.getStatusLine().getStatusCode()); Header auth = httpget.getRequestHeader("Authorization"); assertNotNull(auth); String expected = "Basic " + EncodingUtil.getAsciiString( Base64.encodeBase64(EncodingUtil.getAsciiBytes("testuser:testpass"))); assertEquals(expected, auth.getValue()); AuthState authstate = httpget.getHostAuthState(); assertNotNull(authstate.getAuthScheme()); assertTrue(authstate.getAuthScheme() instanceof BasicScheme); assertEquals("test", authstate.getRealm()); }