Starting client implementation
This commit is contained in:
parent
ce17e82f9d
commit
b15504ab6a
|
@ -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 -->
|
||||||
|
|
|
@ -92,6 +92,10 @@ class ModelScanner {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 {
|
||||||
|
|
||||||
|
}
|
|
@ -40,6 +40,8 @@ public abstract class RestfulServer extends HttpServlet {
|
||||||
|
|
||||||
private Map<Class<? extends IResource>, IResourceProvider<?>> myTypeToProvider = new HashMap<Class<? extends IResource>, IResourceProvider<?>>();
|
private Map<Class<? extends IResource>, IResourceProvider<?>> myTypeToProvider = new HashMap<Class<? extends IResource>, IResourceProvider<?>>();
|
||||||
|
|
||||||
|
private FhirContext myFhirContext;
|
||||||
|
|
||||||
public abstract Collection<IResourceProvider<?>> getResourceProviders();
|
public abstract Collection<IResourceProvider<?>> getResourceProviders();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -59,7 +61,7 @@ public abstract class RestfulServer extends HttpServlet {
|
||||||
|
|
||||||
myFhirContext = new FhirContext(myTypeToProvider.keySet());
|
myFhirContext = new FhirContext(myTypeToProvider.keySet());
|
||||||
|
|
||||||
findResourceMethods(nextProvider.getClass());
|
// findResourceMethods(nextProvider.getClass());
|
||||||
|
|
||||||
|
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
|
|
|
@ -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