Skip to content

Commit

Permalink
Fix #4511 : Handle closure of instances of org.jboss.resteasy.client.…
Browse files Browse the repository at this point in the history
…jaxrs.ResteasyClient
  • Loading branch information
vrindanayak committed Jun 4, 2024
1 parent 4a27d81 commit 96fea4c
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -170,20 +170,21 @@ public Outcome export(ExportContext ctx) throws Exception {
}

String url = destWebApp.getServiceURL().append("/workitems").toString();
ResteasyClient client = accessTokenRequestor.resteasyClientBuilder(url, destWebApp).build();
WebTarget target = client.target(url);
Invocation.Builder request = target.request();
String token = authorization(destWebApp);
if (token != null)
request.header("Authorization", token);
try (ResteasyClient client = accessTokenRequestor.resteasyClientBuilder(url, destWebApp).build()) {
WebTarget target = client.target(url);
Invocation.Builder request = target.request();
String token = authorization(destWebApp);
if (token != null)
request.header("Authorization", token);

ApplicationEntity ae = device.getApplicationEntity(descriptor.getAETitle(), true);
ApplicationEntity ae = device.getApplicationEntity(descriptor.getAETitle(), true);

Attributes upsInfo = queryService.createUPSInfo(
ae, ctx.getStudyInstanceUID(), ctx.getSeriesInstanceUID(), ctx.getSopInstanceUID(), descriptor);
Attributes upsInfo = queryService.createUPSInfo(
ae, ctx.getStudyInstanceUID(), ctx.getSeriesInstanceUID(), ctx.getSopInstanceUID(), descriptor);

return outcome(request.post(EntityType.valueOf(mediaType(destWebApp.getProperties().get("content-type")))
.entity(upsAttrs(upsInfo))));
return outcome(request.post(EntityType.valueOf(mediaType(destWebApp.getProperties().get("content-type")))
.entity(upsAttrs(upsInfo))));
}
}

public String getInputReadinessState() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -365,13 +365,14 @@ String getTargetURL() {
Invocation.Builder openConnection(Object[] params, AccessTokenRequestor accessTokenRequestor)
throws Exception {
targetURL = format.format(params);
ResteasyClient client = accessTokenRequestor.resteasyClientBuilder(targetURL, queryRetrieveWebApp).build();
WebTarget target = client.target(targetURL);
Invocation.Builder request = target.request();
headerFields.forEach((k,v) -> request.header(k.toString(), v));
if (token != null)
request.header("Authorization", "Bearer " + token);
return request;
try (ResteasyClient client = accessTokenRequestor.resteasyClientBuilder(targetURL, queryRetrieveWebApp).build()) {
WebTarget target = client.target(targetURL);
Invocation.Builder request = target.request();
headerFields.forEach((k,v) -> request.header(k.toString(), v));
if (token != null)
request.header("Authorization", "Bearer " + token);
return request;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -105,21 +105,22 @@ private Attributes query(PDQServiceContext ctx, WebApplication webApp) throws PD
String authorization;
try {
String url = webApp.getServiceURL().toString();
ResteasyClient client = accessTokenRequestor.resteasyClientBuilder(url, webApp).build();
ResteasyWebTarget target = client.target(url);
target = setQueryParameters(target, ctx);
Invocation.Builder request = target.request();
setHeaders(request);
if ((authorization = authorization(webApp)) != null)
request.header("Authorization", authorization);
LOG.info("Request invoked is : {}", target.getUri());
Response response = request.get();
if (response.getStatus() != Response.Status.OK.getStatusCode())
return null;

return SAXTransformer.transform(response,
descriptor.getProperties().getOrDefault("XSLStylesheetURI", FHIR_PAT_2_DCM_XSL),
null);
try (ResteasyClient client = accessTokenRequestor.resteasyClientBuilder(url, webApp).build()) {
ResteasyWebTarget target = client.target(url);
target = setQueryParameters(target, ctx);
Invocation.Builder request = target.request();
setHeaders(request);
if ((authorization = authorization(webApp)) != null)
request.header("Authorization", authorization);
LOG.info("Request invoked is : {}", target.getUri());
Response response = request.get();
if (response.getStatus() != Response.Status.OK.getStatusCode())
return null;

return SAXTransformer.transform(response,
descriptor.getProperties().getOrDefault("XSLStylesheetURI", FHIR_PAT_2_DCM_XSL),
null);
}
} catch (Exception e) {
LOG.info("Exception caught on querying FHIR Supplier {}", webApp);
ctx.setException(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,21 +169,22 @@ private String targetURI(RSOperation rsOp,

private Response toResponse(
String method, String uri, WebApplication webApp, byte[] content, String authorization) throws Exception {
ResteasyClient client = accessTokenRequestor.resteasyClientBuilder(uri, webApp).build();
WebTarget target = client.target(uri);
Invocation.Builder request = target.request();
if (authorization != null)
request.header("Authorization", authorization);
try (ResteasyClient client = accessTokenRequestor.resteasyClientBuilder(uri, webApp).build()) {
WebTarget target = client.target(uri);
Invocation.Builder request = target.request();
if (authorization != null)
request.header("Authorization", authorization);

LOG.info("Restful Service Forward : {} {}", method, uri);
LOG.info("Restful Service Forward : {} {}", method, uri);

return method.equals("POST")
? content != null
? request.post(Entity.json(content))
: request.post(Entity.json(""))
: method.equals("PUT")
? request.put(Entity.json(content))
: request.delete();
return method.equals("POST")
? content != null
? request.post(Entity.json(content))
: request.post(Entity.json(""))
: method.equals("PUT")
? request.put(Entity.json(content))
: request.delete();
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,21 +91,22 @@ public StowTask newStowTask(RetrieveContext ctx) throws DicomServiceException {
WebApplication webApp = ctx.getDestinationWebApp();
Map<String, String> props = webApp.getProperties();
String url = webApp.getServiceURL().append("/studies").toString();
ResteasyClient client = accessTokenRequestor.resteasyClientBuilder(url, webApp).build();
ResteasyWebTarget target = client.target(url)
.setChunked(Boolean.parseBoolean(props.get("chunked")));
String authorization = webApp.getKeycloakClientID() != null
? "Bearer " + accessTokenRequestor.getAccessToken2(webApp).getToken()
: props.containsKey("bearer-token")
? "Bearer " + props.get("bearer-token")
: props.containsKey("basic-auth")
? "Basic " + encodeBase64(props.get("basic-auth").getBytes(StandardCharsets.UTF_8))
: null;
return new StowTaskImpl(ctx, retrieveStart, retrieveEnd,
target,
authorization,
uidsOf(props.get("transfer-syntax")),
props.containsKey("concurrency") ? Integer.parseInt(props.get("concurrency")) : 1);
try (ResteasyClient client = accessTokenRequestor.resteasyClientBuilder(url, webApp).build()) {
ResteasyWebTarget target = client.target(url)
.setChunked(Boolean.parseBoolean(props.get("chunked")));
String authorization = webApp.getKeycloakClientID() != null
? "Bearer " + accessTokenRequestor.getAccessToken2(webApp).getToken()
: props.containsKey("bearer-token")
? "Bearer " + props.get("bearer-token")
: props.containsKey("basic-auth")
? "Basic " + encodeBase64(props.get("basic-auth").getBytes(StandardCharsets.UTF_8))
: null;
return new StowTaskImpl(ctx, retrieveStart, retrieveEnd,
target,
authorization,
uidsOf(props.get("transfer-syntax")),
props.containsKey("concurrency") ? Integer.parseInt(props.get("concurrency")) : 1);
}
} catch (Exception e) {
LOG.info("Failed to build STOW request: ", e);
DicomServiceException dse = new DicomServiceException(Status.UnableToPerformSubOperations, e);
Expand Down

0 comments on commit 96fea4c

Please sign in to comment.