Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Sonatype Nexus (TM) Open Source Version Copyright (c) 2007-2012 Sonatype, Inc. All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions. This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0, which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html. Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the Eclipse Foundation. All other trademarks are the property of their respective owners.
 
 package org.sonatype.nexus.rest.repotargets;
 
 
 import  javax.ws.rs.Consumes;
 import  javax.ws.rs.GET;
 import  javax.ws.rs.POST;
 import  javax.ws.rs.Path;
 import  javax.ws.rs.Produces;
 
 import  org.codehaus.enunciate.contract.jaxrs.ResourceMethodSignature;
 import  org.restlet.Context;
 import  org.restlet.data.Request;
 import  org.restlet.data.Response;
 import  org.restlet.data.Status;
 import  org.restlet.resource.ResourceException;
 import  org.restlet.resource.Variant;

Author(s):
tstevens
 
 @Component( role = PlexusResource.class, hint = "RepositoryTargetListPlexusResource" )
 @Produces( { "application/xml""application/json" } )
 @Consumes( { "application/xml""application/json" } )
 {
     public static final String RESOURCE_URI = "/repo_targets";
     
     {
         this.setModifiabletrue );
     }
 
     @Override
     public Object getPayloadInstance()
     {
         return new RepositoryTargetResourceResponse();
     }
 
     @Override
     public String getResourceUri()
     {
         return ;
     }
 
     @Override
     {
         return new PathProtectionDescriptorgetResourceUri(), "authcBasic,perms[nexus:targets]" );
     }

    
Get the list of configuration repository targets.
 
     @Override
     @GET
     @ResourceMethodSignature( output = RepositoryTargetListResourceResponse.class )
     public Object get( Context context, Request request, Response response, Variant variant )
         throws ResourceException
     {
 
         Collection<Targettargets = getTargetRegistry().getRepositoryTargets();
 
         RepositoryTargetListResource res = null;
 
         for ( Target target : targets )
         {
             res = new RepositoryTargetListResource();
 
             res.setIdtarget.getId() );
 
            res.setNametarget.getName() );
            res.setContentClasstarget.getContentClass().getId() );
            res.setResourceURIthis.createChildReferencerequestthistarget.getId() ).toString() );
            result.addDatares );
        }
        return result;
    }

    
Add a new repository target to nexus.
    @Override
    @POST
    @ResourceMethodSignature( input = RepositoryTargetResourceResponse.class, output = RepositoryTargetResourceResponse.class )
    public Object post( Context context, Request request, Response responseObject payload )
        throws ResourceException
    {
        RepositoryTargetResourceResponse resourceResponse = null;
        if ( result != null )
        {
            RepositoryTargetResource resource = result.getData();
            if ( validatetrueresource ) )
            {
                try
                {
                    // create
                    Target target = getRestToNexusResourceresource );
                    
                    getTargetRegistry().addRepositoryTargettarget );
                    
                    getNexusConfiguration().saveConfiguration();
                    
                    // response
                    resourceResponse = new RepositoryTargetResourceResponse();
                    resourceResponse.setDataresult.getData() );
                }
                catch ( ConfigurationException e )
                {
                    // build an exception and throws it
                    handleConfigurationExceptione );
                }
                catch ( PatternSyntaxException e )
                {
                    // TODO: fix because this happens before we validate, we need to fix the validation.
                    ErrorResponse errorResponse = getNexusErrorResponse"*"e.getMessage() );
                    throw new PlexusResourceException( Status.CLIENT_ERROR_BAD_REQUEST, "Configuration error."errorResponse );
                }
                catch ( IOException e )
                {
                    getLogger().warn"Got IOException during creation of repository target!"e );
                    throw new ResourceException(
                        Status.SERVER_ERROR_INTERNAL,
                        "Got IOException during creation of repository target!" );
                }
            }
        }
        return resourceResponse;
    }
New to GrepCode? Check out our FAQ X