# HG changeset patch # User Sebastien Jodogne # Date 1547583104 -3600 # Node ID 8296f0f75716818db663877e0dab5286c23cf14b # Parent c0d7aee8c3f864d6150177bad6524fff99ef4806# Parent 58ea4ef84c924533eeb1f8dd27fa11140eb9f692 integration mainline->db-changes diff -r c0d7aee8c3f8 -r 8296f0f75716 Core/HttpClient.cpp --- a/Core/HttpClient.cpp Tue Jan 15 21:09:33 2019 +0100 +++ b/Core/HttpClient.cpp Tue Jan 15 21:11:44 2019 +0100 @@ -62,8 +62,8 @@ } else { - LOG(INFO) << "Error code " << static_cast(code) - << " in libcurl: " << curl_easy_strerror(code); + LOG(ERROR) << "Error code " << static_cast(code) + << " in libcurl: " << curl_easy_strerror(code); *status = 0; return code; } @@ -697,8 +697,8 @@ else { answerBody.clear(); - LOG(INFO) << "Error in HTTP request, received HTTP status " << status - << " (" << EnumerationToString(lastStatus_) << ")"; + LOG(ERROR) << "Error in HTTP request, received HTTP status " << status + << " (" << EnumerationToString(lastStatus_) << ")"; } return success; diff -r c0d7aee8c3f8 -r 8296f0f75716 Resources/Testing/Issue32/Cpp/CMakeLists.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Resources/Testing/Issue32/Cpp/CMakeLists.txt Tue Jan 15 21:11:44 2019 +0100 @@ -0,0 +1,20 @@ +cmake_minimum_required(VERSION 2.8) + +project(Orthanc) + +set(ORTHANC_ROOT ${CMAKE_SOURCE_DIR}/../../../../Resources/CMake) + +include(${ORTHANC_ROOT}/OrthancFrameworkParameters.cmake) +set(ENABLE_WEB_CLIENT ON) +include(${ORTHANC_ROOT}/OrthancFrameworkConfiguration.cmake) + +add_definitions( + -DORTHANC_ENABLE_LOGGING_PLUGIN=OFF + ) + +include_directories(${ORTHANC_ROOT}) + +add_executable(Sample + main.cpp + ${ORTHANC_CORE_SOURCES} + ) \ No newline at end of file diff -r c0d7aee8c3f8 -r 8296f0f75716 Resources/Testing/Issue32/Cpp/main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Resources/Testing/Issue32/Cpp/main.cpp Tue Jan 15 21:11:44 2019 +0100 @@ -0,0 +1,86 @@ +#include +#include +#include +#include + +#include +#include + +static void Worker(bool *done) +{ + LOG(WARNING) << "One thread has started"; + + Orthanc::HttpClient client; + //client.SetUrl("http://localhost:8042/studies"); + //client.SetUrl("http://localhost:8042/tools/default-encoding"); + client.SetUrl("http://localhost:8042/system"); + //client.SetUrl("http://localhost:8042/"); + //client.SetCredentials("orthanc", "orthanc"); + client.SetRedirectionFollowed(false); + + while (!(*done)) + { + try + { +#if 0 + Json::Value v; + if (!client.Apply(v) || + v.type() != Json::objectValue) + { + printf("ERROR\n"); + } +#else + std::string s; + if (!client.Apply(s) || + s.empty()) + { + printf("ERROR\n"); + } +#endif + } + catch (Orthanc::OrthancException& e) + { + printf("EXCEPTION: %s", e.What()); + } + } + + LOG(WARNING) << "One thread has stopped"; +} + +int main() +{ + Orthanc::Logging::Initialize(); + //Orthanc::Logging::EnableInfoLevel(true); + Orthanc::HttpClient::GlobalInitialize(); + + { + bool done = false; + + std::vector threads; + + for (size_t i = 0; i < 100; i++) + { + threads.push_back(new boost::thread(Worker, &done)); + } + + LOG(WARNING) << "STARTED"; + Orthanc::SystemToolbox::ServerBarrier(); + LOG(WARNING) << "STOPPING"; + + done = true; + + for (size_t i = 0; i < threads.size(); i++) + { + if (threads[i]->joinable()) + { + threads[i]->join(); + } + + delete threads[i]; + } + } + + Orthanc::HttpClient::GlobalFinalize(); + printf("OK\n"); + return 0; +} diff -r c0d7aee8c3f8 -r 8296f0f75716 Resources/Testing/Issue32/Java/README.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Resources/Testing/Issue32/Java/README.txt Tue Jan 15 21:11:44 2019 +0100 @@ -0,0 +1,2 @@ +$ sudo apt-get install maven +$ mvn test diff -r c0d7aee8c3f8 -r 8296f0f75716 Resources/Testing/Issue32/Java/pom.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Resources/Testing/Issue32/Java/pom.xml Tue Jan 15 21:11:44 2019 +0100 @@ -0,0 +1,35 @@ + + + + 4.0.0 + + io.osimis + issue32 + 1.0-SNAPSHOT + + issue32 + + http://www.example.com + + + UTF-8 + 1.8 + 1.8 + + + + + org.apache.httpcomponents + httpclient + 4.5.3 + + + + junit + junit + 4.11 + test + + + diff -r c0d7aee8c3f8 -r 8296f0f75716 Resources/Testing/Issue32/Java/src/test/java/io/osimis/AppTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Resources/Testing/Issue32/Java/src/test/java/io/osimis/AppTest.java Tue Jan 15 21:11:44 2019 +0100 @@ -0,0 +1,61 @@ +package io.osimis; + +import java.io.IOException; +import org.apache.http.HttpEntity; +import org.apache.http.client.HttpRequestRetryHandler; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.client.methods.HttpRequestBase; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; +import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; +import org.apache.http.util.EntityUtils; + +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +public class AppTest +{ + @Test + public void testKeepAlive() + { + PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager(); + + CloseableHttpClient client = HttpClients + .custom() + .setConnectionManager(cm) + .setRetryHandler((HttpRequestRetryHandler) (exception, executionCount, context) -> { + System.out.println("ERROR"); + assertTrue(false); + return false; + }).build(); + + HttpRequestBase request = new HttpGet("http://localhost:8042/system"); + + // The following call works + //HttpRequestBase request = new HttpGet("https://api.ipify.org?format=json"); + + for (int i = 0; i < 5; i++) { + System.out.println("================================"); + try (CloseableHttpResponse httpResponse = client.execute(request)) { + String responseContent = null; + + HttpEntity entity = httpResponse.getEntity(); + if (entity != null) { + responseContent = EntityUtils.toString(entity); + } + + System.out.println(httpResponse.getStatusLine().getStatusCode()); + System.out.println(responseContent); + + EntityUtils.consume(entity); + httpResponse.close(); + } catch (IOException e) { + System.out.println("Request error " + e); + } + } + + assertTrue(true); + } +}