Skip to content

Commit

Permalink
Close the response
Browse files Browse the repository at this point in the history
  • Loading branch information
sswguo committed Mar 7, 2024
1 parent d09cd7c commit b3b2881
Showing 1 changed file with 56 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,12 @@ private ArtifactStore doGetArtifactStore(String trackingId, final URL url )
try
{
response = repositoryService.getStore(PackageTypeConstants.PKG_TYPE_GENERIC_HTTP, "group", groupName);

if ( response != null && response.getStatus() == HttpStatus.SC_OK )
{
group = (Group)response.readEntity(ArtifactStore.class);
cache.put(groupName, group, 15, TimeUnit.MINUTES);
}
}
catch ( WebApplicationException e )
{
Expand All @@ -178,11 +184,14 @@ private ArtifactStore doGetArtifactStore(String trackingId, final URL url )
throw new IndyProxyException("Get artifact store error.", e);
}
}
if ( response != null && response.getStatus() == HttpStatus.SC_OK )
finally
{
group = (Group)response.readEntity(ArtifactStore.class);
cache.put(groupName, group, 15, TimeUnit.MINUTES);
if ( response != null )
{
response.close();
}
}

return group;
}
else
Expand All @@ -194,6 +203,19 @@ private ArtifactStore doGetArtifactStore(String trackingId, final URL url )
try
{
response = repositoryService.getRemoteByUrl(PackageTypeConstants.PKG_TYPE_GENERIC_HTTP, "remote", baseUrl);

if ( response != null && response.getStatus() == HttpStatus.SC_OK )
{
StoreListingDTO<RemoteRepository> dto = response.readEntity(StoreListingDTO.class);
for( RemoteRepository remoteRepository : dto.getItems() )
{
if ( remoteRepository.getMetadata( TRACKING_ID ) == null )
{
remote = remoteRepository;
break;
}
}
}
}
catch ( WebApplicationException e )
{
Expand All @@ -211,19 +233,15 @@ private ArtifactStore doGetArtifactStore(String trackingId, final URL url )
throw new IndyProxyException("Get artifact store error.", e);
}
}

if ( response != null && response.getStatus() == HttpStatus.SC_OK )
finally
{
StoreListingDTO<RemoteRepository> dto = response.readEntity(StoreListingDTO.class);
for( RemoteRepository remoteRepository : dto.getItems() )
if ( response != null )
{
if ( remoteRepository.getMetadata( TRACKING_ID ) == null )
{
remote = remoteRepository;
break;
}
response.close();
}
}


return remote;
}
}
Expand Down Expand Up @@ -359,32 +377,43 @@ private String getRemoteRepositoryName( URL url ) throws IndyProxyException
try
{
response = repositoryService.getRemoteByUrl(GENERIC_PKG_KEY, "remote", baseUrl);

if ( response != null && response.getStatus() == HttpStatus.SC_OK )
{
StoreListingDTO<RemoteRepository> dto = response.readEntity(StoreListingDTO.class);
Predicate<ArtifactStore> filter = ((RepoCreator)repoCreator).getNameFilter( name );
List<String> l = dto.getItems().stream()
.filter( filter )
.map( repository -> repository.getName() )
.collect( Collectors.toList() );
if ( l.isEmpty() )
{
return name;
}
return ((RepoCreator)repoCreator).getNextName( l );
}
else
{
return name;
}
}
catch ( WebApplicationException e )
{
if ( e.getResponse().getStatus() == HttpStatus.SC_NOT_FOUND )
{
return name;
}
}

if ( response != null && response.getStatus() == HttpStatus.SC_OK )
{
StoreListingDTO<RemoteRepository> dto = response.readEntity(StoreListingDTO.class);
Predicate<ArtifactStore> filter = ((RepoCreator)repoCreator).getNameFilter( name );
List<String> l = dto.getItems().stream()
.filter( filter )
.map( repository -> repository.getName() )
.collect( Collectors.toList() );
if ( l.isEmpty() )
else
{
return name;
throw new IndyProxyException("Get remote repository error.", e);
}
return ((RepoCreator)repoCreator).getNextName( l );
}
else
finally
{
return name;
if ( response != null )
{
response.close();
}
}
}

Expand Down

0 comments on commit b3b2881

Please sign in to comment.