@BeforeClass
  public static void beforeClass() throws Exception {
    ourPort = PortUtil.findFreePort();
    ourServer = new Server(ourPort);

    DummyPatientResourceProvider patientProvider = new DummyPatientResourceProvider();

    ServletHandler proxyHandler = new ServletHandler();
    ourServlet = new RestfulServer();
    ourServlet.getFhirContext().setNarrativeGenerator(new DefaultThymeleafNarrativeGenerator());
    ourServlet.setPagingProvider(new FifoMemoryPagingProvider(10).setDefaultPageSize(10));

    ourServlet.setResourceProviders(patientProvider, new DummyObservationResourceProvider());
    ServletHolder servletHolder = new ServletHolder(ourServlet);
    proxyHandler.addServletWithMapping(servletHolder, "/*");
    ourServer.setHandler(proxyHandler);
    ourServer.start();

    PoolingHttpClientConnectionManager connectionManager =
        new PoolingHttpClientConnectionManager(5000, TimeUnit.MILLISECONDS);
    HttpClientBuilder builder = HttpClientBuilder.create();
    builder.setConnectionManager(connectionManager);
    ourClient = builder.build();

    ourDefaultAddressStrategy = ourServlet.getServerAddressStrategy();
  }
  @BeforeClass
  public static void beforeClass() throws Exception {
    ourPort = PortUtil.findFreePort();
    ourServer = new Server(ourPort);

    PatientProvider patientProvider = new PatientProvider();

    ourReportProvider = new DiagnosticReportProvider();

    ServletHandler proxyHandler = new ServletHandler();
    RestfulServer servlet = new RestfulServer(ourCtx);
    servlet.setResourceProviders(
        patientProvider,
        ourReportProvider,
        new ObservationProvider(),
        new OrganizationResourceProvider());
    ServletHolder servletHolder = new ServletHolder(servlet);
    proxyHandler.addServletWithMapping(servletHolder, "/*");
    ourServer.setHandler(proxyHandler);
    ourServer.start();

    PoolingHttpClientConnectionManager connectionManager =
        new PoolingHttpClientConnectionManager(5000, TimeUnit.MILLISECONDS);
    HttpClientBuilder builder = HttpClientBuilder.create();
    builder.setConnectionManager(connectionManager);
    ourClient = builder.build();
  }
  @Test
  public void testApacheProxyAddressStrategy() throws Exception {

    ourServlet.setServerAddressStrategy(ApacheProxyAddressStrategy.forHttp());
    HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient");
    HttpResponse status = ourClient.execute(httpGet);
    String responseContent = IOUtils.toString(status.getEntity().getContent());
    IOUtils.closeQuietly(status.getEntity().getContent());
    ourLog.info(responseContent);
    assertEquals(200, status.getStatusLine().getStatusCode());
    assertThat(responseContent, containsString("<family value=\"FAMILY\""));
    assertThat(
        responseContent,
        containsString("<fullUrl value=\"http://localhost:" + ourPort + "/Patient/1\"/>"));

    ourServlet.setServerAddressStrategy(new ApacheProxyAddressStrategy(false));
    httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient");
    httpGet.addHeader("x-forwarded-host", "foo.com");
    status = ourClient.execute(httpGet);
    responseContent = IOUtils.toString(status.getEntity().getContent());
    IOUtils.closeQuietly(status.getEntity().getContent());
    ourLog.info(responseContent);
    assertEquals(200, status.getStatusLine().getStatusCode());
    assertThat(responseContent, containsString("<family value=\"FAMILY\""));
    assertThat(responseContent, containsString("<fullUrl value=\"http://foo.com/Patient/1\"/>"));

    ourServlet.setServerAddressStrategy(ApacheProxyAddressStrategy.forHttps());
    httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient");
    httpGet.addHeader("x-forwarded-host", "foo.com");
    status = ourClient.execute(httpGet);
    responseContent = IOUtils.toString(status.getEntity().getContent());
    IOUtils.closeQuietly(status.getEntity().getContent());
    ourLog.info(responseContent);
    assertEquals(200, status.getStatusLine().getStatusCode());
    assertThat(responseContent, containsString("<family value=\"FAMILY\""));
    assertThat(responseContent, containsString("<fullUrl value=\"https://foo.com/Patient/1\"/>"));

    ourServlet.setServerAddressStrategy(new ApacheProxyAddressStrategy(false));
    httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient");
    httpGet.addHeader("x-forwarded-host", "foo.com");
    httpGet.addHeader("x-forwarded-proto", "https");
    status = ourClient.execute(httpGet);
    responseContent = IOUtils.toString(status.getEntity().getContent());
    IOUtils.closeQuietly(status.getEntity().getContent());
    ourLog.info(responseContent);
    assertEquals(200, status.getStatusLine().getStatusCode());
    assertThat(responseContent, containsString("<family value=\"FAMILY\""));
    assertThat(responseContent, containsString("<fullUrl value=\"https://foo.com/Patient/1\"/>"));
  }
Example #4
0
  @BeforeClass
  public static void beforeClass() throws Exception {
    ourPort = PortUtil.findFreePort();
    ourServer = new Server(ourPort);
    ourCtx = new FhirContext(Patient.class);

    ourProvider = new DummyProvider();

    ServletHandler proxyHandler = new ServletHandler();
    RestfulServer servlet = new RestfulServer(ourCtx);
    servlet.setPlainProviders(ourProvider);
    ServletHolder servletHolder = new ServletHolder(servlet);
    proxyHandler.addServletWithMapping(servletHolder, "/*");
    ourServer.setHandler(proxyHandler);
    ourServer.start();

    PoolingHttpClientConnectionManager connectionManager =
        new PoolingHttpClientConnectionManager(5000, TimeUnit.MILLISECONDS);
    HttpClientBuilder builder = HttpClientBuilder.create();
    builder.setConnectionManager(connectionManager);
    ourClient = builder.build();
  }
  @BeforeClass
  public static void beforeClass() throws Exception {
    ourPort = PortUtil.findFreePort();
    ourServer = new Server(ourPort);

    DummyPatientResourceProvider patientProvider = new DummyPatientResourceProvider();

    ServletHandler proxyHandler = new ServletHandler();
    ourServlet = new RestfulServer(ourCtx);
    ourServlet.setPagingProvider(new FifoMemoryPagingProvider(10));

    ourServlet.setResourceProviders(patientProvider);
    ServletHolder servletHolder = new ServletHolder(ourServlet);
    proxyHandler.addServletWithMapping(servletHolder, "/*");
    ourServer.setHandler(proxyHandler);
    ourServer.start();

    PoolingHttpClientConnectionManager connectionManager =
        new PoolingHttpClientConnectionManager(5000, TimeUnit.MILLISECONDS);
    HttpClientBuilder builder = HttpClientBuilder.create();
    builder.setConnectionManager(connectionManager);
    ourClient = builder.build();
  }
  @BeforeClass
  public static void beforeClass() throws Exception {

    ourCtx = FhirContext.forDstu2();
    ourPort = PortUtil.findFreePort();
    ourServer = new Server(ourPort);

    DummyPatientResourceProvider patientProvider = new DummyPatientResourceProvider();

    ServletHandler proxyHandler = new ServletHandler();
    RestfulServer servlet = new RestfulServer(ourCtx);
    servlet.setResourceProviders(patientProvider, new DummyDiagnosticReportResourceProvider());
    servlet.setBundleInclusionRule(BundleInclusionRule.BASED_ON_RESOURCE_PRESENCE);
    ServletHolder servletHolder = new ServletHolder(servlet);
    proxyHandler.addServletWithMapping(servletHolder, "/*");
    ourServer.setHandler(proxyHandler);
    ourServer.start();

    PoolingHttpClientConnectionManager connectionManager =
        new PoolingHttpClientConnectionManager(5000, TimeUnit.MILLISECONDS);
    HttpClientBuilder builder = HttpClientBuilder.create();
    builder.setConnectionManager(connectionManager);
    ourClient = builder.build();
  }
  @Test
  public void testIncomingRequestAddressStrategy() throws Exception {
    ourServlet.setServerAddressStrategy(new IncomingRequestAddressStrategy());

    HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient");
    HttpResponse status = ourClient.execute(httpGet);
    String responseContent = IOUtils.toString(status.getEntity().getContent());
    IOUtils.closeQuietly(status.getEntity().getContent());
    ourLog.info(responseContent);
    assertEquals(200, status.getStatusLine().getStatusCode());
    assertThat(responseContent, containsString("<family value=\"FAMILY\""));
    assertThat(
        responseContent,
        containsString("<fullUrl value=\"http://localhost:" + ourPort + "/Patient/1\"/>"));
  }
 @Before
 public void before() {
   ourServlet.setServerAddressStrategy(ourDefaultAddressStrategy);
   ourLastIncludes = null;
   ourLastAndList = null;
 }
  /** #149 */
  @Test
  public void testReturnLinksWithAddressStrategy() throws Exception {
    ourServlet.setServerAddressStrategy(
        new HardcodedServerAddressStrategy("https://blah.com/base"));

    HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?_query=findWithLinks");

    CloseableHttpResponse status = ourClient.execute(httpGet);
    String responseContent = IOUtils.toString(status.getEntity().getContent());
    IOUtils.closeQuietly(status.getEntity().getContent());
    assertEquals(200, status.getStatusLine().getStatusCode());
    Bundle bundle = ourCtx.newXmlParser().parseBundle(responseContent);

    ourLog.info(responseContent);

    assertEquals(10, bundle.getEntries().size());
    assertEquals("https://blah.com/base", bundle.getLinkBase().getValue());
    assertEquals(
        "https://blah.com/base/Patient?_query=findWithLinks", bundle.getLinkSelf().getValue());

    Patient p = bundle.getResources(Patient.class).get(0);
    assertEquals("AAANamed", p.getIdentifierFirstRep().getValue().getValue());
    assertEquals("http://foo/Patient?_id=1", bundle.getEntries().get(0).getLinkSearch().getValue());
    assertEquals(
        "https://blah.com/base/Patient/99881",
        bundle.getEntries().get(0).getLinkAlternate().getValue());
    assertEquals("http://foo/Patient?_id=1", ResourceMetadataKeyEnum.LINK_SEARCH.get(p));
    assertEquals(
        "https://blah.com/base/Patient/99881", ResourceMetadataKeyEnum.LINK_ALTERNATE.get(p));

    String linkNext = bundle.getLinkNext().getValue();
    ourLog.info(linkNext);
    assertThat(linkNext, startsWith("https://blah.com/base?_getpages="));

    /*
     * Load the second page
     */
    String urlPart = linkNext.substring(linkNext.indexOf('?'));
    String link = "http://localhost:" + ourPort + urlPart;
    httpGet = new HttpGet(link);

    status = ourClient.execute(httpGet);
    responseContent = IOUtils.toString(status.getEntity().getContent());
    IOUtils.closeQuietly(status.getEntity().getContent());
    assertEquals(200, status.getStatusLine().getStatusCode());
    bundle = ourCtx.newXmlParser().parseBundle(responseContent);

    ourLog.info(responseContent);

    assertEquals(10, bundle.getEntries().size());
    assertEquals("https://blah.com/base", bundle.getLinkBase().getValue());
    assertEquals(linkNext, bundle.getLinkSelf().getValue());

    p = bundle.getResources(Patient.class).get(0);
    assertEquals("AAANamed", p.getIdentifierFirstRep().getValue().getValue());
    assertEquals(
        "http://foo/Patient?_id=11", bundle.getEntries().get(0).getLinkSearch().getValue());
    assertEquals(
        "https://blah.com/base/Patient/998811",
        bundle.getEntries().get(0).getLinkAlternate().getValue());
    assertEquals("http://foo/Patient?_id=11", ResourceMetadataKeyEnum.LINK_SEARCH.get(p));
    assertEquals(
        "https://blah.com/base/Patient/998811", ResourceMetadataKeyEnum.LINK_ALTERNATE.get(p));
  }