Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FHIRClient.getWebTarget(String baseURL) throws NPE #2450

Closed
csandersdev opened this issue Jun 1, 2021 · 5 comments
Closed

FHIRClient.getWebTarget(String baseURL) throws NPE #2450

csandersdev opened this issue Jun 1, 2021 · 5 comments
Assignees
Labels
bug Something isn't working

Comments

@csandersdev
Copy link
Contributor

Describe the bug
Using the following code, the client generates a NullPointerException.

public class ClientTest {
	@Test
	public void testGetWebTargetBaseUrl() throws Exception {
		String baseURL = "http://hapi.fhir.org/baseR4";
		
		Properties properties = new Properties();
		properties.put(FHIRClient.PROPNAME_BASE_URL, baseURL);
		FHIRClient client = FHIRClientFactory.getClient( properties );
		client.getWebTarget( baseURL + "/Patient?_page=2" ).request("application/json").get();
	}
}

Environment
4.8.2

To Reproduce
Steps to reproduce the behavior:

  1. Execute the code as shown above.

Expected behavior
The code executes normally, passing all configurations specified in the initial properties collection to the URL specified in the getWebTarget(String) method (e.g. basic authentication, tenant header, keystore, truststore, etc.).

Additional context
I came across this while trying to write code that will follow the links in the Bundle resource returned from search query. As a workaround, I've so far been about to use getWebTarget().path(fullUrl) and that seems to work.

@csandersdev csandersdev added the bug Something isn't working label Jun 1, 2021
@prb112 prb112 self-assigned this Jun 1, 2021
@prb112 prb112 added this to the Sprint 2021-08 milestone Jun 1, 2021
@prb112
Copy link
Contributor

prb112 commented Jun 2, 2021

getClient is our typical entrrypoint. I'll add a check for this code path.

prb112 added a commit that referenced this issue Jun 2, 2021
Signed-off-by: Paul Bastide <pbastide@us.ibm.com>
@JohnTimm
Copy link
Collaborator

JohnTimm commented Jun 2, 2021

@csandersdev please attach the stacktrace if you have it handy.

@csandersdev
Copy link
Contributor Author

@prb112 getClient is only available on the impl class and is protected. I think it would be useful to expose outward if folks are ok with that.

@JohnTimm The NPE is because it is trying to use keystore properties that are null in my configuration. The getWebTarget() method without params uses getClient() which checks for nulls. The getWebTarget(String) and getWebTargetUsingBasicAuth(String,String,String) methods don't use getClient() and are not null-safe.

java.lang.NullPointerException
	at javax.ws.rs.client.ClientBuilder.keyStore(ClientBuilder.java:185)
	at com.ibm.fhir.client.impl.FHIRClientImpl.getWebTarget(FHIRClientImpl.java:820)
	at com.ibm.fhir.cql.engine.rest.ClientTest.testGetWebTargetBaseUrl(ClientTest.java:20)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
	at org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63)
	at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
	at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
	at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:89)
	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:41)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:542)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:770)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:464)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:210)

prb112 added a commit that referenced this issue Jun 2, 2021
- Code Review with John
	- Changed construction to be in constructor instead of in getClient()
	- Added/updated test.oauth2.properties to read from special file
instead of custom injection
	- Refactored to remove unused getBasicAuth

Signed-off-by: Paul Bastide <pbastide@us.ibm.com>
prb112 added a commit that referenced this issue Jun 3, 2021
FHIRClient.getWebTarget(String baseURL) throws NPE #2450
@lmsurpre
Copy link
Member

lmsurpre commented Jun 3, 2021

@CoreySandersOH this is now in main and slated for 4.8.3. Mind helping to confirm that these changes adequately address the issue?

@csandersdev
Copy link
Contributor Author

LGTM

@lmsurpre lmsurpre closed this as completed Jun 3, 2021
tbieste pushed a commit that referenced this issue Jun 9, 2021
Signed-off-by: Paul Bastide <pbastide@us.ibm.com>
tbieste pushed a commit that referenced this issue Jun 9, 2021
- Code Review with John
	- Changed construction to be in constructor instead of in getClient()
	- Added/updated test.oauth2.properties to read from special file
instead of custom injection
	- Refactored to remove unused getBasicAuth

Signed-off-by: Paul Bastide <pbastide@us.ibm.com>
tbieste pushed a commit that referenced this issue Jun 9, 2021
FHIRClient.getWebTarget(String baseURL) throws NPE #2450
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants