Merge branch 'master' of ssh://git.code.sf.net/p/hl7api/fhircode
Conflicts: hapi-fhir-base/src/main/java/ca/uhn/fhir/server/RestfulServer.java
This commit is contained in:
commit
a74766e620
|
@ -64,15 +64,12 @@
|
||||||
<version>4.2.3</version>
|
<version>4.2.3</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- Server -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>javax.servlet</groupId>
|
<groupId>javax.servlet</groupId>
|
||||||
<artifactId>javax.servlet-api</artifactId>
|
<artifactId>javax.servlet-api</artifactId>
|
||||||
<version>3.1.0</version>
|
<version>3.1.0</version>
|
||||||
</dependency>
|
<scope>provided</scope>
|
||||||
<dependency>
|
|
||||||
<groupId>log4j</groupId>
|
|
||||||
<artifactId>log4j</artifactId>
|
|
||||||
<version>1.2.17</version>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- Testing -->
|
<!-- Testing -->
|
||||||
|
|
|
@ -96,6 +96,10 @@ class ModelScanner {
|
||||||
ourLog.info("Done scanning FHIR library, found {} model entries", myClassToElementDefinitions.size());
|
ourLog.info("Done scanning FHIR library, found {} model entries", myClassToElementDefinitions.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ModelScanner(Class<ResourceWithExtensionsA> theClass) {
|
||||||
|
// TODO Auto-generated constructor stub
|
||||||
|
}
|
||||||
|
|
||||||
public RuntimeChildUndeclaredExtensionDefinition getRuntimeChildUndeclaredExtensionDefinition() {
|
public RuntimeChildUndeclaredExtensionDefinition getRuntimeChildUndeclaredExtensionDefinition() {
|
||||||
return myRuntimeChildUndeclaredExtensionDefinition;
|
return myRuntimeChildUndeclaredExtensionDefinition;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
package ca.uhn.fhir.rest.annotation;
|
||||||
|
|
||||||
|
import java.lang.annotation.ElementType;
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@Target(ElementType.METHOD)
|
||||||
|
public @interface Read {
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,22 @@
|
||||||
|
package ca.uhn.fhir.rest.client;
|
||||||
|
|
||||||
|
import java.lang.reflect.InvocationHandler;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
|
import org.apache.http.client.HttpClient;
|
||||||
|
|
||||||
|
public class ClientInvocationHandler implements InvocationHandler {
|
||||||
|
|
||||||
|
private HttpClient myClient;
|
||||||
|
|
||||||
|
public ClientInvocationHandler(HttpClient theClient) {
|
||||||
|
myClient = theClient;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object invoke(Object theProxy, Method theMethod, Object[] theArgs) throws Throwable {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,5 @@
|
||||||
|
package ca.uhn.fhir.rest.client;
|
||||||
|
|
||||||
|
class MethodBinding {
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,60 @@
|
||||||
|
package ca.uhn.fhir.rest.client;
|
||||||
|
|
||||||
|
import java.lang.reflect.InvocationHandler;
|
||||||
|
import java.lang.reflect.Proxy;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import org.apache.http.client.HttpClient;
|
||||||
|
import org.apache.http.impl.client.DefaultHttpClient;
|
||||||
|
import org.apache.http.impl.conn.PoolingClientConnectionManager;
|
||||||
|
import org.apache.http.impl.conn.SchemeRegistryFactory;
|
||||||
|
|
||||||
|
import ca.uhn.fhir.context.ConfigurationException;
|
||||||
|
import ca.uhn.fhir.context.FhirContext;
|
||||||
|
import ca.uhn.fhir.rest.client.api.IRestfulClient;
|
||||||
|
|
||||||
|
public class RestfulClientFactory {
|
||||||
|
|
||||||
|
private FhirContext myContext;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor
|
||||||
|
*
|
||||||
|
* @param theContext The context
|
||||||
|
*/
|
||||||
|
public RestfulClientFactory(FhirContext theContext) {
|
||||||
|
myContext = theContext;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new client instance
|
||||||
|
*
|
||||||
|
* @param theClientType The client type, which is an interface type to be instantiated
|
||||||
|
* @param theServerBase The URL of the base for the restful FHIR server to connect to
|
||||||
|
* @return A newly created client
|
||||||
|
* @throws ConfigurationException If the interface type is not an interface
|
||||||
|
*/
|
||||||
|
public <T extends IRestfulClient> T newClient(Class<T> theClientType, String theServerBase) {
|
||||||
|
if (!theClientType.isInterface()) {
|
||||||
|
throw new ConfigurationException(theClientType.getCanonicalName() + " is not an interface");
|
||||||
|
}
|
||||||
|
|
||||||
|
PoolingClientConnectionManager connectionManager = new PoolingClientConnectionManager(SchemeRegistryFactory.createDefault(), 5000, TimeUnit.MILLISECONDS);
|
||||||
|
HttpClient client = new DefaultHttpClient(connectionManager);
|
||||||
|
|
||||||
|
ClientInvocationHandler theInvocationHandler = new ClientInvocationHandler(client);
|
||||||
|
|
||||||
|
T proxy = instantiateProxy(theClientType, theInvocationHandler);
|
||||||
|
|
||||||
|
return proxy;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
private <T extends IRestfulClient> T instantiateProxy(Class<T> theClientType, InvocationHandler theInvocationHandler) {
|
||||||
|
T proxy = (T) Proxy.newProxyInstance(RestfulClientFactory.class.getClassLoader(), new Class[] {theClientType}, theInvocationHandler);
|
||||||
|
return proxy;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,5 @@
|
||||||
|
package ca.uhn.fhir.rest.client.api;
|
||||||
|
|
||||||
|
public interface IRestfulClient {
|
||||||
|
|
||||||
|
}
|
|
@ -41,9 +41,31 @@ public abstract class RestfulServer extends HttpServlet {
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
private Map<Class<? extends IResource>, IResourceProvider<?>> myTypeToProvider = new HashMap<Class<? extends IResource>, IResourceProvider<?>>();
|
||||||
|
|
||||||
private FhirContext myFhirContext;
|
private FhirContext myFhirContext;
|
||||||
|
|
||||||
private Map<Class<? extends IResource>, IResourceProvider<?>> myTypeToProvider = new HashMap<Class<? extends IResource>, IResourceProvider<?>>();
|
public abstract Collection<IResourceProvider<?>> getResourceProviders();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void init() throws ServletException {
|
||||||
|
try {
|
||||||
|
ourLog.info("Initializing HAPI FHIR restful server");
|
||||||
|
|
||||||
|
Collection<IResourceProvider<?>> resourceProvider = getResourceProviders();
|
||||||
|
for (IResourceProvider<?> nextProvider : resourceProvider) {
|
||||||
|
if (myTypeToProvider.containsKey(nextProvider.getResourceType())) {
|
||||||
|
throw new ServletException("Multiple providers for type: " + nextProvider.getResourceType().getCanonicalName());
|
||||||
|
}
|
||||||
|
myTypeToProvider.put(nextProvider.getResourceType(), nextProvider);
|
||||||
|
}
|
||||||
|
|
||||||
|
ourLog.info("Got {} resource providers",myTypeToProvider.size());
|
||||||
|
|
||||||
|
myFhirContext = new FhirContext(myTypeToProvider.keySet());
|
||||||
|
|
||||||
|
// findResourceMethods(nextProvider.getClass());
|
||||||
|
>>>>>>> b15504ab6af00727419d4888cd3a1c5215f5b5e3:hapi-fhir-base/src/main/java/ca/uhn/fhir/ws/RestfulServer.java
|
||||||
|
|
||||||
// map of request handler resources keyed by resource name
|
// map of request handler resources keyed by resource name
|
||||||
private Map<String, Resource> resources = new HashMap<String, Resource>();
|
private Map<String, Resource> resources = new HashMap<String, Resource>();
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
package ca.uhn.fhir.rest.client;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class ClientTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testClient() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue