From ff40a4c1e31801ae9432331abec0c9fb5bff1324 Mon Sep 17 00:00:00 2001 From: jamesagnew Date: Thu, 27 Feb 2014 13:21:47 -0500 Subject: [PATCH] Upgrading HTTP client version for unit tests --- hapi-fhir-base/.classpath | 147 ++++++++++-------- .../.settings/org.eclipse.jdt.core.prefs | 13 +- hapi-fhir-base/pom.xml | 21 +++ .../src/main/java/ca/uhn/fhir/ws/Service.java | 40 +++-- .../java/ca/uhn/fhir/ws/ResourceTest.java | 39 +++-- 5 files changed, 160 insertions(+), 100 deletions(-) diff --git a/hapi-fhir-base/.classpath b/hapi-fhir-base/.classpath index 9d5aecc687e..24308671dc5 100644 --- a/hapi-fhir-base/.classpath +++ b/hapi-fhir-base/.classpath @@ -1,64 +1,85 @@ + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/hapi-fhir-base/.settings/org.eclipse.jdt.core.prefs b/hapi-fhir-base/.settings/org.eclipse.jdt.core.prefs index b03bfe1c855..35679dd2fb5 100644 --- a/hapi-fhir-base/.settings/org.eclipse.jdt.core.prefs +++ b/hapi-fhir-base/.settings/org.eclipse.jdt.core.prefs @@ -5,9 +5,15 @@ org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonN org.eclipse.jdt.core.compiler.annotation.nonnullbydefault=org.eclipse.jdt.annotation.NonNullByDefault org.eclipse.jdt.core.compiler.annotation.nullable=org.eclipse.jdt.annotation.Nullable org.eclipse.jdt.core.compiler.annotation.nullanalysis=enabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 -org.eclipse.jdt.core.compiler.compliance=1.6 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.7 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error org.eclipse.jdt.core.compiler.problem.autoboxing=ignore org.eclipse.jdt.core.compiler.problem.comparingIdentical=warning org.eclipse.jdt.core.compiler.problem.deadCode=warning @@ -16,6 +22,7 @@ org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=disabled org.eclipse.jdt.core.compiler.problem.discouragedReference=warning org.eclipse.jdt.core.compiler.problem.emptyStatement=warning +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error org.eclipse.jdt.core.compiler.problem.explicitlyClosedAutoCloseable=ignore org.eclipse.jdt.core.compiler.problem.fallthroughCase=warning org.eclipse.jdt.core.compiler.problem.fatalOptionalError=disabled @@ -89,4 +96,4 @@ org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning org.eclipse.jdt.core.compiler.problem.unusedTypeParameter=warning org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning -org.eclipse.jdt.core.compiler.source=1.6 +org.eclipse.jdt.core.compiler.source=1.7 diff --git a/hapi-fhir-base/pom.xml b/hapi-fhir-base/pom.xml index be185fce7ec..699f4c0cf71 100644 --- a/hapi-fhir-base/pom.xml +++ b/hapi-fhir-base/pom.xml @@ -57,6 +57,14 @@ true + + + org.apache.httpcomponents + httpclient + 4.2.3 + + + junit @@ -76,6 +84,19 @@ 1.5 test + + org.eclipse.jetty + jetty-servlets + 9.1.1.v20140108 + test + + + org.eclipse.jetty + jetty-servlet + 9.1.1.v20140108 + test + + diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/ws/Service.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/ws/Service.java index 9f358bfb297..b146836f9ea 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/ws/Service.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/ws/Service.java @@ -1,14 +1,15 @@ package ca.uhn.fhir.ws; -import ca.uhn.fhir.context.FhirContext; -import ca.uhn.fhir.model.dstu.resource.Observation; -import ca.uhn.fhir.parser.XmlParser; -import ca.uhn.fhir.ws.exceptions.MethodNotFoundException; -import ca.uhn.fhir.ws.operations.DELETE; -import ca.uhn.fhir.ws.operations.GET; -import ca.uhn.fhir.ws.operations.POST; -import ca.uhn.fhir.ws.operations.PUT; -import org.apache.log4j.Logger; +import java.io.File; +import java.io.IOException; +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; +import java.net.URL; +import java.util.ArrayList; +import java.util.Enumeration; +import java.util.HashMap; +import java.util.List; +import java.util.Map; import javax.naming.Context; import javax.naming.InitialContext; @@ -17,16 +18,21 @@ import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import java.io.File; -import java.io.IOException; -import java.lang.reflect.Method; -import java.lang.reflect.Modifier; -import java.net.URL; -import java.util.*; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import ca.uhn.fhir.context.FhirContext; +import ca.uhn.fhir.parser.XmlParser; +import ca.uhn.fhir.ws.exceptions.MethodNotFoundException; +import ca.uhn.fhir.ws.operations.DELETE; +import ca.uhn.fhir.ws.operations.GET; +import ca.uhn.fhir.ws.operations.POST; +import ca.uhn.fhir.ws.operations.PUT; public class Service extends HttpServlet { - private static final Logger log = Logger.getLogger(Service.class); + private static final Logger log = LoggerFactory.getLogger(Service.class); private static final String handlerPackage = "ca.uhn.rest.handlers"; //map of request handler resources keyed by resource name @@ -53,7 +59,7 @@ public class Service extends HttpServlet { log.debug("Looking up:: " + name); handlerPackage = (String) env.lookup(name); } catch (NamingException ne) { - log.debug(ne); + log.debug("NamingException", ne); } if (handlerPackage != null) { log.debug("Found:: " + name); diff --git a/hapi-fhir-base/src/test/java/ca/uhn/fhir/ws/ResourceTest.java b/hapi-fhir-base/src/test/java/ca/uhn/fhir/ws/ResourceTest.java index e42ff720cad..d32f78fd457 100644 --- a/hapi-fhir-base/src/test/java/ca/uhn/fhir/ws/ResourceTest.java +++ b/hapi-fhir-base/src/test/java/ca/uhn/fhir/ws/ResourceTest.java @@ -1,21 +1,26 @@ package ca.uhn.fhir.ws; -import junit.framework.TestCase; -import org.apache.commons.httpclient.HttpClient; -import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager; -import org.apache.commons.httpclient.methods.PostMethod; -import org.apache.commons.httpclient.methods.StringRequestEntity; -import org.eclipse.jetty.server.Server; -import org.eclipse.jetty.servlet.ServletHandler; -import org.eclipse.jetty.servlet.ServletHolder; -import org.junit.Before; -import org.junit.Test; - import java.lang.reflect.Method; import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Set; +import java.util.concurrent.TimeUnit; + +import junit.framework.TestCase; + +import org.apache.http.HttpResponse; +import org.apache.http.client.HttpClient; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.entity.StringEntity; +import org.apache.http.impl.client.DefaultHttpClient; +import org.apache.http.impl.conn.PoolingClientConnectionManager; +import org.apache.http.impl.conn.SchemeRegistryFactory; +import org.eclipse.jetty.server.Server; +import org.eclipse.jetty.servlet.ServletHandler; +import org.eclipse.jetty.servlet.ServletHolder; +import org.junit.Before; +import org.junit.Test; /** * Created by dsotnikov on 2/25/2014. @@ -52,13 +57,13 @@ public class ResourceTest extends TestCase { server.setHandler(proxyHandler); server.start(); - MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager(); - HttpClient client = new HttpClient(connectionManager); + PoolingClientConnectionManager connectionManager = new PoolingClientConnectionManager(SchemeRegistryFactory.createDefault(), 5000, TimeUnit.MILLISECONDS); + HttpClient client = new DefaultHttpClient(connectionManager); + - - PostMethod httpPost = new PostMethod("http://localhost:3000/foo/bar?bar=123&more=params"); - httpPost.setRequestEntity(new StringRequestEntity("test", "application/json", "UTF-8")); - int status = client.executeMethod(httpPost); + HttpPost httpPost = new HttpPost("http://localhost:3000/foo/bar?bar=123&more=params"); + httpPost.setEntity(new StringEntity("test", "application/json", "UTF-8")); + HttpResponse status = client.execute(httpPost); System.out.println(status); // server.join();