public Response sendMessage( Method method, RepositoryBaseResource resource, String id ) throws IOException { XStreamRepresentation representation = new XStreamRepresentation( xstream, "", mediaType ); String idPart = ( method == Method.POST ) ? "" : "/" + id; String serviceURI = "service/local/repositories" + idPart; RepositoryResourceResponse repoResponseRequest = new RepositoryResourceResponse(); repoResponseRequest.setData( resource ); // now set the payload representation.setPayload( repoResponseRequest ); LOG.debug( "sendMessage: " + representation.getText() ); return RequestFacade.sendMessage( serviceURI, method, representation ); }
private void saveRepository(RepositoryResource repository, String repositoryName) throws IOException { String serviceURI = "service/local/repositories/" + repositoryName; RepositoryResourceResponse repositoryResponse = new RepositoryResourceResponse(); XStreamRepresentation representation = new XStreamRepresentation(xstream, "", MediaType.APPLICATION_XML); repositoryResponse.setData(repository); representation.setPayload(repositoryResponse); RequestFacade.doPutForStatus(serviceURI, representation, isSuccessful()); }
/** * IMPORTANT: Make sure to release the Response in a finally block when you are done with it. */ public Response sendMessage(Method method, RepositoryBaseResource resource, String id) throws IOException { if (resource != null && resource.getProviderRole() == null) { if ("virtual".equals(resource.getRepoType())) { resource.setProviderRole(ShadowRepository.class.getName()); } else { resource.setProviderRole(Repository.class.getName()); } } XStreamRepresentation representation = new XStreamRepresentation(xstream, "", mediaType); String idPart = (method == Method.POST) ? "" : "/" + id; String serviceURI = SERVICE_PART + idPart; RepositoryResourceResponse repoResponseRequest = new RepositoryResourceResponse(); repoResponseRequest.setData(resource); // now set the payload representation.setPayload(repoResponseRequest); LOG.debug("sendMessage: " + representation.getText()); return nexusRestClient.sendMessage(serviceURI, method, representation); }
/** * IMPORTANT: Make sure to release the Response in a finally block when you are done with it. */ public Response sendMessage( Method method, RepositoryBaseResource resource, String id ) throws IOException { if ( resource != null && resource.getProviderRole() == null ) { if ( "virtual".equals( resource.getRepoType() ) ) { resource.setProviderRole( ShadowRepository.class.getName() ); } else { resource.setProviderRole( Repository.class.getName() ); } } XStreamRepresentation representation = new XStreamRepresentation( xstream, "", mediaType ); String idPart = ( method == Method.POST ) ? "" : "/" + id; String serviceURI = SERVICE_PART + idPart; RepositoryResourceResponse repoResponseRequest = new RepositoryResourceResponse(); repoResponseRequest.setData( resource ); // now set the payload representation.setPayload( repoResponseRequest ); LOG.debug( "sendMessage: " + representation.getText() ); return nexusRestClient.sendMessage( serviceURI, method, representation ); }
public RepositoryBaseResource createRepository( RepositoryBaseResource repo ) throws NexusConnectionException, NexusClientException { RepositoryResourceResponse repoResponseRequest = new RepositoryResourceResponse(); repoResponseRequest.setData( repo ); Object tempObj = this.getClientHelper().create( REPO_SERVICE, null, repoResponseRequest ); // Hack around NEXUS-540 if ( tempObj == null ) { return this.getRepository( repo.getId() ); } // type check the object so we can have a meaninful error if needed this.checkType( tempObj, RepositoryResourceResponse.class ); RepositoryResourceResponse repoResponse = (RepositoryResourceResponse) tempObj; return repoResponse.getData(); }
private void saveRepository( RepositoryResource repository, String repositoryName ) throws IOException { String serviceURI = "service/local/repositories/" + repositoryName; RepositoryResourceResponse repositoryResponse = new RepositoryResourceResponse(); XStreamRepresentation representation = new XStreamRepresentation( xstream, "", MediaType.APPLICATION_XML ); repositoryResponse.setData( repository ); representation.setPayload( repositoryResponse ); Status status = RequestFacade.sendMessage( serviceURI, Method.PUT, representation ).getStatus(); Assert.assertEquals( Status.SUCCESS_OK.getCode(), status.getCode() ); }
protected RepositoryResourceResponse getRepositoryResourceResponse(Request request, String repoId) throws ResourceException { RepositoryResourceResponse result = new RepositoryResourceResponse(); try { RepositoryBaseResource resource = null; Repository repository = getRepositoryRegistry().getRepository(repoId); if (repository.getRepositoryKind().isFacetAvailable(GroupRepository.class)) { // it is a group, not a repo throw new ResourceException(Status.CLIENT_ERROR_NOT_FOUND, "Repository Not Found"); } resource = getRepositoryRestModel(request, repository); result.setData(resource); } catch (NoSuchRepositoryAccessException e) { getLogger().warn("Repository access denied, id=" + repoId); throw new ResourceException(Status.CLIENT_ERROR_FORBIDDEN, "Access Denied to Repository"); } catch (NoSuchRepositoryException e) { getLogger().warn("Repository not found, id=" + repoId); throw new ResourceException(Status.CLIENT_ERROR_NOT_FOUND, "Repository Not Found"); } return result; }
public RepositoryBaseResource updateRepository( RepositoryBaseResource repo ) throws NexusConnectionException, NexusClientException { RepositoryResourceResponse repoResponseRequest = new RepositoryResourceResponse(); repoResponseRequest.setData( repo ); Object tempObj = this.getClientHelper().update( REPO_SERVICE, repo.getId(), repoResponseRequest ); // Hack around NEXUS-540 if ( tempObj == null ) { return this.getRepository( repo.getId() ); } // type check the object so we can have a meaninful error if needed this.checkType( tempObj, RepositoryResourceResponse.class ); RepositoryResourceResponse repoResponse = (RepositoryResourceResponse) tempObj; return repoResponse.getData(); }
result.setData(repoRes);
result.setData( repoRes );
S doCreate() { final RepositoryResourceResponse request = new RepositoryResourceResponse(); request.setData( settings() ); try { return (S) getNexusClient() .serviceResource( uri() ) .post( RepositoryResourceResponse.class, request ) .getData(); } catch ( UniformInterfaceException e ) { throw getNexusClient().convert( e ); } catch ( ClientHandlerException e ) { throw getNexusClient().convert( e ); } }
S doUpdate() { final RepositoryResourceResponse request = new RepositoryResourceResponse(); request.setData( settings() ); try { return (S) getNexusClient() .serviceResource( uri() + "/" + id() ) .put( RepositoryResourceResponse.class, request ) .getData(); } catch ( UniformInterfaceException e ) { throw getNexusClient().convert( e ); } catch ( ClientHandlerException e ) { throw getNexusClient().convert( e ); } }
protected RepositoryResourceResponse getRepositoryResourceResponse( Request request, String repoId ) throws ResourceException { RepositoryResourceResponse result = new RepositoryResourceResponse(); try { RepositoryBaseResource resource = null; Repository repository = getRepositoryRegistry().getRepository( repoId ); if ( repository.getRepositoryKind().isFacetAvailable( GroupRepository.class ) ) { // it is a group, not a repo throw new ResourceException( Status.CLIENT_ERROR_NOT_FOUND, "Repository Not Found" ); } resource = getRepositoryRestModel( request, repository ); result.setData( resource ); } catch ( NoSuchRepositoryAccessException e ) { getLogger().warn( "Repository access denied, id=" + repoId ); throw new ResourceException( Status.CLIENT_ERROR_FORBIDDEN, "Access Denied to Repository" ); } catch ( NoSuchRepositoryException e ) { getLogger().warn( "Repository not found, id=" + repoId ); throw new ResourceException( Status.CLIENT_ERROR_NOT_FOUND, "Repository Not Found" ); } return result; }