use of org.apache.http.params.HttpParams in project undertow by undertow-io.
the class FileHandlerSymlinksTestCase method testExplicitAccessSymlinkGrantedUsingSpecificFiltersWithDirectoryListingEnabled.
@Test
public void testExplicitAccessSymlinkGrantedUsingSpecificFiltersWithDirectoryListingEnabled() throws IOException, URISyntaxException {
HttpParams params = new SyncBasicHttpParams();
DefaultHttpClient.setDefaultHttpParams(params);
HttpConnectionParams.setSoTimeout(params, 300000);
TestHttpClient client = new TestHttpClient(params);
Path rootPath = Paths.get(getClass().getResource("page.html").toURI()).getParent();
Path newSymlink = rootPath.resolve("newSymlink");
try {
DefaultServer.setRootHandler(new PathHandler().addPrefixPath("/path", new ResourceHandler(new PathResourceManager(newSymlink, 10485760, true, rootPath.toAbsolutePath().toString().concat("/newDir"))).setDirectoryListingEnabled(false).addWelcomeFiles("page.html")));
/**
* This request should return a 200 code as rootPath + "/newDir" is used in the safePaths
*/
HttpGet get = new HttpGet(DefaultServer.getDefaultServerURL() + "/path/innerSymlink/.");
HttpResponse result = client.execute(get);
Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
final String response = HttpClientUtils.readResponse(result);
Header[] headers = result.getHeaders("Content-Type");
Assert.assertEquals("text/html", headers[0].getValue());
Assert.assertTrue(response, response.contains("A web page"));
} finally {
client.getConnectionManager().shutdown();
}
}
use of org.apache.http.params.HttpParams in project voldemort by voldemort.
the class RemoteStoreComparisonTest method main.
public static void main(String[] args) throws Exception {
if (args.length != 2)
Utils.croak("USAGE: java " + RemoteStoreComparisonTest.class.getName() + " numRequests numThreads [useNio]");
int numRequests = Integer.parseInt(args[0]);
int numThreads = Integer.parseInt(args[1]);
boolean useNio = args.length > 2 ? args[2].equals("true") : false;
/** * In memory test ** */
final Store<byte[], byte[], byte[]> memStore = new InMemoryStorageEngine<byte[], byte[], byte[]>("test");
PerformanceTest memWriteTest = new PerformanceTest() {
@Override
public void doOperation(int i) {
byte[] key = String.valueOf(i).getBytes();
memStore.put(key, new Versioned<byte[]>(key), null);
}
};
System.out.println("###########################################");
System.out.println("Performing memory write test.");
memWriteTest.run(numRequests, numThreads);
memWriteTest.printStats();
System.out.println();
PerformanceTest memReadTest = new PerformanceTest() {
@Override
public void doOperation(int i) {
try {
memStore.get(String.valueOf(i).getBytes(), null);
} catch (Exception e) {
System.out.println("Failure on i = " + i);
e.printStackTrace();
}
}
};
System.out.println("Performing memory read test.");
memReadTest.run(numRequests, numThreads);
memReadTest.printStats();
System.out.println();
System.out.println();
/** * Do Socket tests ** */
String storeName = "test";
StoreRepository repository = new StoreRepository();
repository.addLocalStore(new InMemoryStorageEngine<ByteArray, byte[], byte[]>(storeName));
SocketStoreFactory storeFactory = new ClientRequestExecutorPool(10, 1000, 1000, 32 * 1024);
final Store<ByteArray, byte[], byte[]> socketStore = storeFactory.create(storeName, "localhost", 6666, RequestFormatType.VOLDEMORT_V1, RequestRoutingType.NORMAL);
RequestHandlerFactory factory = ServerTestUtils.getSocketRequestHandlerFactory(repository);
AbstractSocketService socketService = ServerTestUtils.getSocketService(useNio, factory, 6666, 50, 50, 1000);
socketService.start();
PerformanceTest socketWriteTest = new PerformanceTest() {
@Override
public void doOperation(int i) {
byte[] bytes = String.valueOf(i).getBytes();
ByteArray key = new ByteArray(bytes);
socketStore.put(key, new Versioned<byte[]>(bytes), null);
}
};
System.out.println("###########################################");
System.out.println("Performing socket write test.");
socketWriteTest.run(numRequests, numThreads);
socketWriteTest.printStats();
System.out.println();
PerformanceTest socketReadTest = new PerformanceTest() {
@Override
public void doOperation(int i) {
try {
socketStore.get(TestUtils.toByteArray(String.valueOf(i)), null);
} catch (Exception e) {
System.out.println("Failure on i = " + i);
e.printStackTrace();
}
}
};
System.out.println("Performing socket read test.");
socketReadTest.run(numRequests, 1);
socketReadTest.printStats();
System.out.println();
System.out.println();
socketStore.close();
storeFactory.close();
socketService.stop();
/** * Do HTTP tests ** */
repository.addLocalStore(new InMemoryStorageEngine<ByteArray, byte[], byte[]>(storeName));
HttpService httpService = new HttpService(null, null, repository, RequestFormatType.VOLDEMORT_V0, numThreads, 8080);
httpService.start();
ThreadSafeClientConnManager connectionManager = new ThreadSafeClientConnManager(SchemeRegistryFactory.createDefault(), 10000, TimeUnit.MILLISECONDS);
DefaultHttpClient httpClient = new DefaultHttpClient(connectionManager);
HttpParams clientParams = httpClient.getParams();
httpClient.setHttpRequestRetryHandler(new DefaultHttpRequestRetryHandler(0, false));
HttpClientParams.setCookiePolicy(clientParams, CookiePolicy.IGNORE_COOKIES);
HttpProtocolParams.setUserAgent(clientParams, "test-agent");
HttpProtocolParams.setVersion(clientParams, HttpVersion.HTTP_1_1);
HttpConnectionParams.setConnectionTimeout(clientParams, 10000);
connectionManager.setMaxTotal(numThreads);
connectionManager.setDefaultMaxPerRoute(numThreads);
HttpConnectionParams.setStaleCheckingEnabled(clientParams, false);
final HttpStore httpStore = new HttpStore("test", "localhost", 8080, httpClient, new RequestFormatFactory().getRequestFormat(RequestFormatType.VOLDEMORT_V0), false);
Thread.sleep(400);
PerformanceTest httpWriteTest = new PerformanceTest() {
@Override
public void doOperation(int i) {
byte[] key = String.valueOf(i).getBytes();
httpStore.put(new ByteArray(key), new Versioned<byte[]>(key), null);
}
};
System.out.println("###########################################");
System.out.println("Performing HTTP write test.");
httpWriteTest.run(numRequests, numThreads);
httpWriteTest.printStats();
System.out.println();
PerformanceTest httpReadTest = new PerformanceTest() {
@Override
public void doOperation(int i) {
httpStore.get(new ByteArray(String.valueOf(i).getBytes()), null);
}
};
System.out.println("Performing HTTP read test.");
httpReadTest.run(numRequests, numThreads);
httpReadTest.printStats();
httpService.stop();
VoldemortIOUtils.closeQuietly(httpClient);
}
use of org.apache.http.params.HttpParams in project playn by threerings.
the class AndroidHttpClient method newInstance.
/**
* Create a new HttpClient with reasonable defaults (which you can update).
*
* @param userAgent to report in your HTTP requests.
* @return AndroidHttpClient for you to use for all your requests.
*/
public static AndroidHttpClient newInstance(String userAgent) {
HttpParams params = new BasicHttpParams();
// Turn off stale checking. Our connections break all the time anyway,
// and it's not worth it to pay the penalty of checking every time.
HttpConnectionParams.setStaleCheckingEnabled(params, false);
// Default connection and socket timeout of 20 seconds. Tweak to taste.
HttpConnectionParams.setConnectionTimeout(params, 20 * 1000);
HttpConnectionParams.setSoTimeout(params, 20 * 1000);
HttpConnectionParams.setSocketBufferSize(params, 8192);
// Don't handle redirects -- return them to the caller. Our code
// often wants to re-POST after a redirect, which we must do ourselves.
HttpClientParams.setRedirecting(params, false);
// Set the specified user agent and register standard protocols.
HttpProtocolParams.setUserAgent(params, userAgent);
SchemeRegistry schemeRegistry = new SchemeRegistry();
schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
schemeRegistry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));
ClientConnectionManager manager = new ThreadSafeClientConnManager(params, schemeRegistry);
// parameters without the funny call-a-static-method dance.
return new AndroidHttpClient(manager, params);
}
use of org.apache.http.params.HttpParams in project perun by CESNET.
the class AbstractPublicationSystemStrategy method execute.
@Override
public HttpResponse execute(HttpUriRequest request) throws CabinetException {
final HttpParams httpParams = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(httpParams, 300000);
HttpConnectionParams.setSoTimeout(httpParams, 300000);
HttpClient httpClient = new DefaultHttpClient(httpParams);
HttpResponse response = null;
try {
log.debug("Attempting to execute HTTP request...");
response = httpClient.execute(request);
log.debug("HTTP request executed.");
} catch (IOException ioe) {
log.error("Failed to execute HTTP request.");
throw new CabinetException(ErrorCodes.HTTP_IO_EXCEPTION, ioe);
}
return response;
}
use of org.apache.http.params.HttpParams in project xUtils by wyouflf.
the class HttpUtils method configTimeout.
public HttpUtils configTimeout(int timeout) {
final HttpParams httpParams = this.httpClient.getParams();
ConnManagerParams.setTimeout(httpParams, timeout);
HttpConnectionParams.setConnectionTimeout(httpParams, timeout);
return this;
}
Aggregations