@ GET @ Path ( "/{path:.*}/" ) public Response getResource ( @ PathParam ( "path" ) String mavenPath , final @ Context UriInfo uriInfo , final @ QueryParam ( "view" ) String view , final @ QueryParam ( "gadget" ) String gadget ) { String resourcePath = mavenRoot + mavenPath ; // JCR resource String shaResourcePath = mavenPath . endsWith ( ".sha1" ) ? mavenRoot + mavenPath : mavenRoot + mavenPath + ".sha1" ; mavenPath = uriInfo . getBaseUriBuilder ( ) . path ( getClass ( ) ) . path ( mavenPath ) . build ( ) . toString ( ) ; Session ses = null ; try { // JCR resource SessionProvider sp = sessionProviderService . getSessionProvider ( null ) ; if ( sp == null ) throw new RepositoryException ( "Access to JCR Repository denied. SessionProvider is null." ) ; ses = sp . getSession ( workspace , repositoryService . getRepository ( repository ) ) ; ExtendedNode node = ( ExtendedNode ) ses . getRootNode ( ) . getNode ( resourcePath ) ; if ( isFile ( node ) ) { if ( view != null && view . equalsIgnoreCase ( "true" ) ) { ExtendedNode shaNode = null ; try { shaNode = ( ExtendedNode ) ses . getRootNode ( ) . getNode ( shaResourcePath ) ; } catch ( RepositoryException e ) { // no .sh1 file found if ( LOG . isTraceEnabled ( ) ) { LOG . trace ( "An exception occurred: " + e . getMessage ( ) ) ; } } return getArtifactInfo ( node , mavenPath , gadget , shaNode ) ; } else { return downloadArtifact ( node ) ; } } else { return browseRepository ( node , mavenPath , gadget ) ; } } catch ( PathNotFoundException e ) { if ( LOG . isDebugEnabled ( ) ) LOG . debug ( e . getLocalizedMessage ( ) , e ) ; return Response . status ( Response . Status . NOT_FOUND ) . build ( ) ; } catch ( AccessDeniedException e ) { if ( LOG . isDebugEnabled ( ) ) LOG . debug ( e . getLocalizedMessage ( ) , e ) ; if ( ses == null || ses . getUserID ( ) . equals ( IdentityConstants . ANONIM ) ) return Response . status ( Response . Status . UNAUTHORIZED ) . header ( ExtHttpHeaders . WWW_AUTHENTICATE , "Basic realm=\"" + realmName + "\"" ) . build ( ) ; else return Response . status ( Response . Status . FORBIDDEN ) . build ( ) ; } catch ( Exception e ) { LOG . error ( "Failed get maven artifact" , e ) ; throw new WebApplicationException ( e ) ; } finally { if ( ses != null ) ses . logout ( ) ; } }
Return Response with Maven artifact if it is file or HTML page for browsing if requested URL is folder .