ca.uhn.fhir.rest.server.interceptor.ResponseHighlighterInterceptor Java Examples

The following examples show how to use ca.uhn.fhir.rest.server.interceptor.ResponseHighlighterInterceptor. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ExampleRestfulServlet.java    From fhirstarters with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * This method is called automatically when the
 * servlet is initializing.
 */
@Override
public void initialize() {
	/*
	 * Two resource providers are defined. Each one handles a specific
	 * type of resource.
	 */
	List<IResourceProvider> providers = new ArrayList<IResourceProvider>();
	providers.add(new PatientResourceProvider());
	providers.add(new OrganizationResourceProvider());
	setResourceProviders(providers);
	
	/*
	 * Use a narrative generator. This is a completely optional step, 
	 * but can be useful as it causes HAPI to generate narratives for
	 * resources which don't otherwise have one.
	 */
	INarrativeGenerator narrativeGen = new DefaultThymeleafNarrativeGenerator();
	getFhirContext().setNarrativeGenerator(narrativeGen);

	/*
	 * Use nice coloured HTML when a browser is used to request the content
	 */
	registerInterceptor(new ResponseHighlighterInterceptor());
	
}
 
Example #2
Source File: Example02_SimpleRestfulServer.java    From fhirstarters with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
protected void initialize() throws ServletException {
	// Create a context for the appropriate version
	setFhirContext(FhirContext.forR4());
	
	// Register resource providers
	registerProvider(new Example01_PatientResourceProvider());
	
	// Format the responses in nice HTML
	registerInterceptor(new ResponseHighlighterInterceptor());
}
 
Example #3
Source File: JpaRestfulServerR4.java    From careconnect-reference-implementation with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
protected void initialize() throws ServletException {
    super.initialize();
    TimeZone.setDefault(TimeZone.getTimeZone("UTC"));

    // Get the spring context from the web container (it's declared in web.xml)
    FhirVersionEnum fhirVersion = FhirVersionEnum.R4;
    setFhirContext(new FhirContext(fhirVersion));
    String serverBase = HapiProperties.getServerAddress();
    if (serverBase != null && !serverBase.isEmpty()) {
        setServerAddressStrategy(new HardcodedServerAddressStrategy(serverBase));
    }

    if (applicationContext == null ) log.info("Context is null");

    AutowireCapableBeanFactory autowireCapableBeanFactory = applicationContext.getAutowireCapableBeanFactory();
    autowireCapableBeanFactory.autowireBean(this);

    List<IResourceProvider> permissionlist = new ArrayList<>();
    Class<?> classType = null;
    try {
        classType = Class.forName("uk.nhs.careconnect.ccri.fhirserver.r4.provider.ObservationDefinitionProvider");
        log.info("class methods " + classType.getMethods()[4].getName() );
    } catch (ClassNotFoundException  e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (Exception ex) {
        log.error(ex.getMessage());
    }

    permissionlist.add((IResourceProvider) applicationContext.getBean(classType));
    setResourceProviders(permissionlist);

    // Replace built in conformance provider (CapabilityStatement)
    setServerConformanceProvider(new CareConnectServerConformanceR4Provider());

    setServerName(HapiProperties.getServerName());
    setServerVersion(HapiProperties.getSoftwareVersion());
    setImplementationDescription(HapiProperties.getSoftwareImplementationDesc());


    ServerInterceptor loggingInterceptor = new ServerInterceptor(log);
    registerInterceptor(loggingInterceptor);




    CorsConfiguration config = new CorsConfiguration();
    config.addAllowedHeader("x-fhir-starter");
    config.addAllowedHeader("Origin");
    config.addAllowedHeader("Accept");
    config.addAllowedHeader("X-Requested-With");
    config.addAllowedHeader("Content-Type");

    config.addAllowedOrigin("*");

    config.addExposedHeader("Location");
    config.addExposedHeader("Content-Location");
    config.setAllowedMethods(Arrays.asList("GET", "POST", "PUT", "DELETE", "OPTIONS", "PATCH"));

    // Create the interceptor and register it
    CorsInterceptor interceptor = new CorsInterceptor(config);
    registerInterceptor(interceptor);

    ServerInterceptor gatewayInterceptor = new ServerInterceptor(log);
    if (HapiProperties.getSecurityOauth()) {
        registerInterceptor(new OAuth2Interceptor());  // Add OAuth2 Security Filter
    }
    registerInterceptor(gatewayInterceptor);

    FifoMemoryPagingProvider pp = new FifoMemoryPagingProvider(10);
    pp.setDefaultPageSize(10);
    pp.setMaximumPageSize(100);
    setPagingProvider(pp);

    setDefaultPrettyPrint(true);
    setDefaultResponseEncoding(EncodingEnum.JSON);

    ctx = getFhirContext();


    registerInterceptor( new ResponseHighlighterInterceptor());

    // Remove as believe due to issues on docker ctx.setNarrativeGenerator(new DefaultThymeleafNarrativeGenerator());
}
 
Example #4
Source File: FhirServerConfig.java    From cqf-ruler with Apache License 2.0 4 votes vote down vote up
/**
 * This interceptor adds some pretty syntax highlighting in responses when a browser is detected
 */
@Bean(autowire = Autowire.BY_TYPE)
public ResponseHighlighterInterceptor responseHighlighterInterceptor() {
    return new ResponseHighlighterInterceptor();
}