当前位置: 首页>>代码示例>>Java>>正文


Java BearerTokenAuthInterceptor类代码示例

本文整理汇总了Java中ca.uhn.fhir.rest.client.interceptor.BearerTokenAuthInterceptor的典型用法代码示例。如果您正苦于以下问题:Java BearerTokenAuthInterceptor类的具体用法?Java BearerTokenAuthInterceptor怎么用?Java BearerTokenAuthInterceptor使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


BearerTokenAuthInterceptor类属于ca.uhn.fhir.rest.client.interceptor包,在下文中一共展示了BearerTokenAuthInterceptor类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createSecurityBearer

import ca.uhn.fhir.rest.client.interceptor.BearerTokenAuthInterceptor; //导入依赖的package包/类
@SuppressWarnings("unused")
public void createSecurityBearer() {
   // START SNIPPET: securityBearer
   // Create a context and get the client factory so it can be configured
   FhirContext ctx = new FhirContext();
   IRestfulClientFactory clientFactory = ctx.getRestfulClientFactory();

   // In reality the token would have come from an authorization server 
   String token = "3w03fj.r3r3t"; 
   
   BearerTokenAuthInterceptor authInterceptor = new BearerTokenAuthInterceptor(token);

   // Register the interceptor with your client (either style)
   IPatientClient annotationClient = ctx.newRestfulClient(IPatientClient.class, "http://localhost:9999/fhir");
   annotationClient.registerInterceptor(authInterceptor);

   IGenericClient genericClient = ctx.newRestfulGenericClient("http://localhost:9999/fhir");
   annotationClient.registerInterceptor(authInterceptor);
   // END SNIPPET: securityBearer
}
 
开发者ID:gajen0981,项目名称:FHIR-Server,代码行数:21,代码来源:ClientExamples.java

示例2: testRequest

import ca.uhn.fhir.rest.client.interceptor.BearerTokenAuthInterceptor; //导入依赖的package包/类
@Test
public void testRequest() throws Exception {
	String msg = crerateMsg();

	ArgumentCaptor<HttpUriRequest> capt = ArgumentCaptor.forClass(HttpUriRequest.class);
	when(myHttpClient.execute(capt.capture())).thenReturn(myHttpResponse);
	when(myHttpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 200, "OK"));
	Header[] headers = new Header[] {};

	when(myHttpResponse.getAllHeaders()).thenReturn(headers);
	when(myHttpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_XML + "; charset=UTF-8"));
	when(myHttpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(msg), Charset.forName("UTF-8")));

	ITestClient client = ourCtx.newRestfulClient(ITestClient.class, "http://foo");
	client.registerInterceptor(new BearerTokenAuthInterceptor("mytoken"));
	client.getPatientById(new IdDt("111"));

	HttpUriRequest req = capt.getValue();
	assertEquals("Bearer mytoken", req.getFirstHeader("Authorization").getValue());
}
 
开发者ID:gajen0981,项目名称:FHIR-Server,代码行数:21,代码来源:BearerTokenAuthInterceptorTest.java

示例3: testRequest

import ca.uhn.fhir.rest.client.interceptor.BearerTokenAuthInterceptor; //导入依赖的package包/类
@Test
public void testRequest() throws Exception {
	String msg = crerateMsg();

	ArgumentCaptor<HttpUriRequest> capt = ArgumentCaptor.forClass(HttpUriRequest.class);
	when(myHttpClient.execute(capt.capture())).thenReturn(myHttpResponse);
	when(myHttpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 200, "OK"));
	Header[] headers = new Header[] {};

	when(myHttpResponse.getAllHeaders()).thenReturn(headers);
	when(myHttpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_XML + "; charset=UTF-8"));
	when(myHttpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(msg), Charset.forName("UTF-8")));

	ITestClient client = ourCtx.newRestfulClient(ITestClient.class, "http://foo");
	client.registerInterceptor(new BearerTokenAuthInterceptor("mytoken"));
	client.getPatientById(new IdType("111"));

	HttpUriRequest req = capt.getValue();
	assertEquals("Bearer mytoken", req.getFirstHeader("Authorization").getValue());
}
 
开发者ID:jamesagnew,项目名称:hapi-fhir,代码行数:21,代码来源:BearerTokenAuthInterceptorTest.java

示例4: newClient

import ca.uhn.fhir.rest.client.interceptor.BearerTokenAuthInterceptor; //导入依赖的package包/类
@Override
public IGenericClient newClient(FhirContext theFhirContext, HttpServletRequest theRequest, String theServerBaseUrl) {
	// Create a client
	IGenericClient client = theFhirContext.newRestfulGenericClient(theServerBaseUrl);

	String apiKey = theRequest.getParameter("apiKey");
	if (isNotBlank(apiKey)) {
		client.registerInterceptor(new BearerTokenAuthInterceptor(apiKey));
	}

	return client;
}
 
开发者ID:jamesagnew,项目名称:hapi-fhir,代码行数:13,代码来源:BearerTokenClientFactory.java

示例5: main

import ca.uhn.fhir.rest.client.interceptor.BearerTokenAuthInterceptor; //导入依赖的package包/类
public static void main(String[] args) {
	
	FhirContext ctx = FhirContext.forDstu2();
	IGenericClient client = ctx.newRestfulGenericClient("http://54.165.58.158:8081/FHIRServer/fhir");
	client.registerInterceptor(new BearerTokenAuthInterceptor("AN3uCTC5B"));
	client.registerInterceptor(new LoggingInterceptor(true));
	Bundle result = client.search().forResource(Patient.class).where(Patient.NAME.matches().value("Alice")).returnBundle(Bundle.class).execute();
	
	System.out.println(result.getEntry().size());
	
}
 
开发者ID:jamesagnew,项目名称:hapi-fhir,代码行数:12,代码来源:BundleTypeDstu2Test.java

示例6: run

import ca.uhn.fhir.rest.client.interceptor.BearerTokenAuthInterceptor; //导入依赖的package包/类
@Override
public void run(CommandLine theCommandLine) throws Exception {
	FhirContext ctx = getSpecVersionContext(theCommandLine);

	String targetServer = theCommandLine.getOptionValue("t");
	if (isBlank(targetServer)) {
		throw new ParseException("No target server (-t) specified");
	} else if (targetServer.startsWith("http") == false && targetServer.startsWith("file") == false) {
		throw new ParseException("Invalid target server specified, must begin with 'http' or 'file'");
	}

	String termUrl = theCommandLine.getOptionValue("u");
	if (isBlank(termUrl)) {
		throw new ParseException("No URL provided");
	}
	
	String[] datafile = theCommandLine.getOptionValues("d");
	if (datafile == null || datafile.length == 0) {
		throw new ParseException("No data file provided");
	}
	
	String bearerToken = theCommandLine.getOptionValue("b");

	IGenericClient client = super.newClient(ctx, targetServer);
	IBaseParameters inputParameters;
	if (ctx.getVersion().getVersion() == FhirVersionEnum.DSTU3) {
		Parameters p = new Parameters();
		p.addParameter().setName("url").setValue(new UriType(termUrl));
		for (String next : datafile) {
			p.addParameter().setName("localfile").setValue(new StringType(next));
		}
		inputParameters = p;
	} else {
		throw new ParseException("This command does not support FHIR version " + ctx.getVersion().getVersion());
	}

	if (isNotBlank(bearerToken)) {
		client.registerInterceptor(new BearerTokenAuthInterceptor(bearerToken));
	}

	if (theCommandLine.hasOption('v')) {
		client.registerInterceptor(new LoggingInterceptor(true));
	}
	
	ourLog.info("Beginning upload - This may take a while...");
	IBaseParameters response = client
		.operation()
		.onServer()
		.named("upload-external-code-system")
		.withParameters(inputParameters)
		.execute();

	ourLog.info("Upload complete!");
	ourLog.info("Response:\n{}", ctx.newXmlParser().setPrettyPrint(true).encodeResourceToString(response));
}
 
开发者ID:jamesagnew,项目名称:hapi-fhir,代码行数:56,代码来源:UploadTerminologyCommand.java


注:本文中的ca.uhn.fhir.rest.client.interceptor.BearerTokenAuthInterceptor类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。