forked from Commonjava/indy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Proxy Site cache support and API resource
- Loading branch information
Showing
5 changed files
with
186 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
core/src/main/java/org/commonjava/indy/core/inject/MemoryProxySitesCache.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package org.commonjava.indy.core.inject; | ||
|
||
import org.commonjava.maven.galley.spi.proxy.ProxySitesCache; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
import javax.enterprise.inject.Alternative; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
@ApplicationScoped | ||
@Alternative | ||
public class MemoryProxySitesCache | ||
implements ProxySitesCache | ||
{ | ||
|
||
protected Set<String> proxySitesCache = new HashSet<>(); | ||
|
||
@Override | ||
public Set<String> getProxySites() | ||
{ | ||
return proxySitesCache; | ||
} | ||
|
||
@Override | ||
public boolean isProxySite( String site ) | ||
{ | ||
return proxySitesCache.contains( site ); | ||
} | ||
|
||
@Override | ||
public void saveProxySite( String site ) | ||
{ | ||
proxySitesCache.add( site ); | ||
} | ||
|
||
@Override | ||
public void deleteProxySite( String site ) | ||
{ | ||
proxySitesCache.remove( site ); | ||
} | ||
|
||
@Override | ||
public void deleteAllProxySites() | ||
{ | ||
proxySitesCache.clear(); | ||
} | ||
} |
86 changes: 86 additions & 0 deletions
86
core/src/main/java/org/commonjava/indy/core/jaxrs/ProxySiteAccessResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package org.commonjava.indy.core.jaxrs; | ||
|
||
import io.swagger.annotations.Api; | ||
import io.swagger.annotations.ApiOperation; | ||
import io.swagger.annotations.ApiResponse; | ||
import io.swagger.annotations.ApiResponses; | ||
import org.commonjava.indy.bind.jaxrs.IndyResources; | ||
import org.commonjava.indy.bind.jaxrs.util.REST; | ||
import org.commonjava.indy.core.inject.CoreProvider; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
import javax.inject.Inject; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.ws.rs.DELETE; | ||
import javax.ws.rs.GET; | ||
import javax.ws.rs.PUT; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.PathParam; | ||
import javax.ws.rs.Produces; | ||
import javax.ws.rs.core.Context; | ||
import javax.ws.rs.core.Response; | ||
import javax.ws.rs.core.StreamingOutput; | ||
import javax.ws.rs.core.UriInfo; | ||
import java.util.Set; | ||
|
||
@Api( value = "Proxy Site Cache Access and Storage" ) | ||
@Path( "/api/proxysite" ) | ||
@ApplicationScoped | ||
@REST | ||
public class ProxySiteAccessResource | ||
implements IndyResources | ||
{ | ||
protected final Logger logger = LoggerFactory.getLogger( getClass() ); | ||
|
||
@Inject | ||
CoreProvider provider; | ||
|
||
@ApiOperation( "Retrieve All Proxy Sites." ) | ||
@ApiResponses( { @ApiResponse( code = 404, message = "Site is not available" ), | ||
@ApiResponse( code = 200, response = StreamingOutput.class, message = "Site stream" ), } ) | ||
@Produces( "application/json" ) | ||
@Path( "/all" ) | ||
@GET | ||
public Response doGet( @Context final UriInfo uriInfo, @Context final HttpServletRequest request ) | ||
{ | ||
Set<String> cache = provider.getProxySites(); | ||
logger.info( "Proxy Site Cache list: {}", cache ); | ||
return ( cache == null || cache.isEmpty() ) ? | ||
Response.status( Response.Status.NOT_FOUND ).build() : | ||
Response.ok( cache ).build(); | ||
} | ||
|
||
@ApiOperation( "Store Proxy Site." ) | ||
@ApiResponses( { @ApiResponse( code = 201, message = "Site was stored successfully" ) } ) | ||
@PUT | ||
@Path( "/{site}" ) | ||
public Response doCreate( @PathParam( "site" ) final String site, @Context final HttpServletRequest request, | ||
@Context final UriInfo uriInfo ) | ||
{ | ||
provider.saveProxySite( site ); | ||
return Response.created( uriInfo.getRequestUri() ).build(); | ||
} | ||
|
||
@ApiOperation( "Delete Proxy Site." ) | ||
@ApiResponse( code = 200, message = "Delete complete." ) | ||
@Path( "/{site}" ) | ||
@DELETE | ||
public Response doDelete( @PathParam( "site" ) final String site ) | ||
{ | ||
provider.deleteProxySite( site ); | ||
return Response.ok().build(); | ||
} | ||
|
||
@ApiOperation( "Delete All Proxy Sites." ) | ||
@ApiResponse( code = 200, message = "Delete complete." ) | ||
@Path( "/all" ) | ||
@DELETE | ||
public Response doDeleteAll() | ||
{ | ||
provider.deleteAllProxySites(); | ||
return Response.ok().build(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters