當前位置: 首頁>>代碼示例>>Java>>正文


Java ResourceException類代碼示例

本文整理匯總了Java中org.restlet.resource.ResourceException的典型用法代碼示例。如果您正苦於以下問題:Java ResourceException類的具體用法?Java ResourceException怎麽用?Java ResourceException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ResourceException類屬於org.restlet.resource包,在下文中一共展示了ResourceException類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getFilesHttp

import org.restlet.resource.ResourceException; //導入依賴的package包/類
/**
 * Helper method that will call the Rest server via localhost only at
 * http://localhost:$monitor.port/files/count/$status
 * 
 * @param status may be null or not
 * @return
 * @throws ResourceException
 * @throws IOException
 */
private long getFilesHttp(FileTrackingStatus.STATUS status) throws ResourceException, IOException {

	int clientPort = configuration.getInt(AgentProperties.MONITORING_PORT,
			8040);

	LOG.info("Connecting client to " + clientPort);

	String querySuffix = (status == null ) ? "/files/count" : "/files/count/" + status.toString().toUpperCase(); 
	ClientResource clientResource = new ClientResource("http://localhost:"
			+ clientPort + querySuffix);

	StringWriter writer = new StringWriter();
	Long count = 0L;
	
	try {
		clientResource.get(MediaType.APPLICATION_JSON).write(writer);
		count = Long.valueOf(writer.toString());
	} finally {
		clientResource.release();
	}

	return count;
}
 
開發者ID:gerritjvv,項目名稱:bigstreams,代碼行數:33,代碼來源:CountCommand.java

示例2: getFilesHttp

import org.restlet.resource.ResourceException; //導入依賴的package包/類
/**
 * Helper method that will call the Rest server via localhost only at
 * 
 * @param querySuffix
 * @return
 * @throws ResourceException
 * @throws IOException
 */
private long getFilesHttp(String querySuffix) throws ResourceException,
		IOException {

	int clientPort = configuration.getInt(
			CoordinationProperties.PROP.COORDINATION_PORT.toString(),
			(Integer) CoordinationProperties.PROP.COORDINATION_PORT
					.getDefaultValue());

	LOG.info("Connecting client to " + clientPort);

	ClientResource clientResource = new ClientResource("http://localhost:"
			+ clientPort + querySuffix);

	StringWriter writer = new StringWriter();

	try {
		clientResource.get(MediaType.APPLICATION_JSON).write(writer);
	} finally {
		clientResource.release();
	}

	return Long.valueOf(writer.toString());
}
 
開發者ID:gerritjvv,項目名稱:bigstreams,代碼行數:32,代碼來源:CountCommand.java

示例3: put

import org.restlet.resource.ResourceException; //導入依賴的package包/類
@Override
public Representation put(Representation entity) throws ResourceException {
    if (!this.directory.isModifiable()) {
        setStatus(Status.CLIENT_ERROR_METHOD_NOT_ALLOWED, "The directory is not modifiable.");
        return null;
    }

    // Transfer of PUT calls is only allowed if the readOnly flag is not set.
    Request contextRequest = new Request(Method.PUT, this.targetUri);

    // Add support of partial PUT calls.
    contextRequest.getRanges().addAll(getRanges());
    contextRequest.setEntity(entity);
    Response contextResponse = new Response(contextRequest);
    contextRequest.setResourceRef(this.targetUri);
    getClientDispatcher().handle(contextRequest, contextResponse);
    setStatus(contextResponse.getStatus());

    return null;
}
 
開發者ID:restlet,項目名稱:restlet-framework,代碼行數:21,代碼來源:DirectoryServerResource.java

示例4: doGet

import org.restlet.resource.ResourceException; //導入依賴的package包/類
@Override
public void doGet(BaseSolrResource endpoint, String childId) {
  
  // filter results by /schema or /config
  String path = ManagedEndpoint.resolveResourceId(endpoint.getRequest());
  Matcher resourceIdMatcher = resourceIdRegex.matcher(path);
  if (!resourceIdMatcher.matches()) {
    // extremely unlikely but didn't want to squelch it either
    throw new ResourceException(Status.SERVER_ERROR_NOT_IMPLEMENTED, path);
  }
  
  String filter = resourceIdMatcher.group(1);
        
  List<Map<String,String>> regList = new ArrayList<>();
  for (ManagedResourceRegistration reg : restManager.registry.getRegistered()) {
    if (!reg.resourceId.startsWith(filter))
      continue; // doesn't match filter
    
    if (RestManagerManagedResource.class.isAssignableFrom(reg.implClass))
      continue; // internal, no need to expose to outside
    
    regList.add(reg.getInfo());          
  }
  
  endpoint.getSolrResponse().add("managedResources", regList);      
}
 
開發者ID:europeana,項目名稱:search,代碼行數:27,代碼來源:RestManager.java

示例5: checkRequest

import org.restlet.resource.ResourceException; //導入依賴的package包/類
void checkRequest()
    throws ResourceException
{
    // Check command rules
    Instant unmodifiedSince = request.getConditions().getUnmodifiedSince().toInstant();
    EntityState state = spi.entityStateOf( entity );
    Instant lastModifiedSeconds = state.lastModified().with(ChronoField.NANO_OF_SECOND, 0 );
    if( unmodifiedSince != null )
    {
        if( lastModifiedSeconds.isAfter( unmodifiedSince ) )
        {
            throw new ResourceException( Status.CLIENT_ERROR_CONFLICT );
        }
    }

    // Check query rules
    Instant modifiedSince = request.getConditions().getModifiedSince().toInstant();
    if( modifiedSince != null )
    {
        if( !lastModifiedSeconds.isAfter( modifiedSince ) )
        {
            throw new ResourceException( Status.REDIRECTION_NOT_MODIFIED );
        }
    }
}
 
開發者ID:apache,項目名稱:polygene-java,代碼行數:26,代碼來源:ResourceValidity.java

示例6: delete

import org.restlet.resource.ResourceException; //導入依賴的package包/類
@Override
protected Representation delete( Variant variant )
    throws ResourceException
{
    Usecase usecase = UsecaseBuilder.newUsecase( "Remove entity" );
    EntityStoreUnitOfWork uow = entityStore.newUnitOfWork( module, usecase, SystemTime.now() );
    try
    {
        EntityReference reference = EntityReference.create( identity );
        uow.entityStateOf( module, reference ).remove();
        uow.applyChanges().commit();
        getResponse().setStatus( Status.SUCCESS_NO_CONTENT );
    }
    catch( EntityNotFoundException e )
    {
        uow.discard();
        getResponse().setStatus( Status.CLIENT_ERROR_NOT_FOUND );
    }

    return new EmptyRepresentation();
}
 
開發者ID:apache,項目名稱:polygene-java,代碼行數:22,代碼來源:EntityResource.java

示例7: representRdfXml

import org.restlet.resource.ResourceException; //導入依賴的package包/類
private Representation representRdfXml( final EntityState entity )
    throws ResourceException
{
    Representation representation = new WriterRepresentation( MediaType.APPLICATION_RDF_XML )
    {
        @Override
        public void write( Writer writer )
            throws IOException
        {
            try
            {
                Iterable<Statement> statements = entitySerializer.serialize( entity );
                new RdfXmlSerializer().serialize( statements, writer );
            }
            catch( RDFHandlerException e )
            {
                throw new IOException( e );
            }
        }
    };
    representation.setCharacterSet( CharacterSet.UTF_8 );
    return representation;
}
 
開發者ID:apache,項目名稱:polygene-java,代碼行數:24,代碼來源:EntityResource.java

示例8: get

import org.restlet.resource.ResourceException; //導入依賴的package包/類
@Override
protected Representation get( Variant variant )
    throws ResourceException
{
    // Generate the right representation according to its media type.
    if( MediaType.APPLICATION_JSON.equals( variant.getMediaType() ) )
    {
        return representJson();
    }
    else if( MediaType.APPLICATION_RDF_XML.equals( variant.getMediaType() ) )
    {
        return representRdf();
    }
    else if( MediaType.TEXT_HTML.equals( variant.getMediaType() ) )
    {
        return representHtml();
    }
    else if( MediaType.APPLICATION_ATOM.equals( variant.getMediaType() ) )
    {
        return representAtom();
    }

    throw new ResourceException( Status.CLIENT_ERROR_NOT_FOUND );
}
 
開發者ID:apache,項目名稱:polygene-java,代碼行數:25,代碼來源:EntitiesResource.java

示例9: representJson

import org.restlet.resource.ResourceException; //導入依賴的package包/類
private Representation representJson()
    throws ResourceException
{
    try
    {
        final Iterable<EntityReference> query = entityFinder.findEntities( EntityComposite.class, null, null, null, null, Collections.emptyMap() )
                                                            .collect( toList() );
        return new OutputRepresentation( MediaType.APPLICATION_JSON )
        {
            @Override
            public void write( OutputStream outputStream )
                throws IOException
            {
                stateSerialization.serialize( new OutputStreamWriter( outputStream ), query );
            }
        };
    }
    catch( Exception e )
    {
        throw new ResourceException( e );
    }
}
 
開發者ID:apache,項目名稱:polygene-java,代碼行數:23,代碼來源:EntitiesResource.java

示例10: post

import org.restlet.resource.ResourceException; //導入依賴的package包/類
@Override
protected Representation post( Representation entity, Variant variant )
    throws ResourceException
{
    try
    {
        /*
         * InputStream in = entity.getStream(); ObjectInputStream oin = new ObjectInputStream( in ); String reference
         * = oin.readUTF(); Usecase usecase = (Usecase) oin.readUnshared(); MetaInfo unitofwork = (MetaInfo)
         * oin.readUnshared(); Iterable<UnitOfWorkEvent> events = (Iterable<UnitOfWorkEvent>) oin.readUnshared();
         *
         * // Store state try { entityStore.apply( reference, events, usecase, unitofwork ).commit(); } catch(
         * ConcurrentEntityStateModificationException e ) { throw new ResourceException(
         * Status.CLIENT_ERROR_CONFLICT ); }
         */
    }
    catch( Exception e )
    {
        throw new ResourceException( e );
    }

    return new EmptyRepresentation();
}
 
開發者ID:apache,項目名稱:polygene-java,代碼行數:24,代碼來源:EntitiesResource.java

示例11: get

import org.restlet.resource.ResourceException; //導入依賴的package包/類
@Override
public Representation get( Variant variant )
    throws ResourceException
{
    if( variant.getMediaType().equals( MediaType.APPLICATION_RDF_XML ) )
    {
        return new RdfXmlOutputRepresentation();
    }
    else if( variant.getMediaType().equals( MediaType.APPLICATION_RDF_TRIG ) )
    {
        return new RdfTrigOutputRepresentation( MediaType.APPLICATION_RDF_TRIG );
    }
    else if( variant.getMediaType().equals( MediaType.TEXT_PLAIN ) )
    {
        return new RdfTrigOutputRepresentation( MediaType.TEXT_PLAIN );
    }

    return null;
}
 
開發者ID:apache,項目名稱:polygene-java,代碼行數:20,代碼來源:IndexResource.java

示例12: writeRequest

import org.restlet.resource.ResourceException; //導入依賴的package包/類
@Override
public boolean writeRequest(Object requestObject, Request request) throws ResourceException
{
   if (requestObject instanceof Form)
   {
      // Form as query parameters
      if (request.getMethod().equals(Method.GET))
         request.getResourceRef().setQuery(((Form)requestObject).getQueryString());
      else
         request.setEntity(((Form)requestObject).getWebRepresentation(CharacterSet.UTF_8));

      return true;
   }

   return false;
}
 
開發者ID:apache,項目名稱:polygene-java,代碼行數:17,代碼來源:FormRequestWriter.java

示例13: readResponse

import org.restlet.resource.ResourceException; //導入依賴的package包/類
@Override
public Object readResponse( Response response, Class<?> resultType ) throws ResourceException
{
    if( MediaType.APPLICATION_JSON.equals( response.getEntity().getMediaType() ) )
    {
        if( resultType.equals( String.class ) || Number.class.isAssignableFrom( resultType ) )
        {
            try
            {
                return jsonDeserializer.deserialize( module, resultType, response.getEntityAsText() );
            }
            catch( Exception e )
            {
                throw new ResourceException( e );
            }
        }
    }
    return null;
}
 
開發者ID:apache,項目名稱:polygene-java,代碼行數:20,代碼來源:DefaultResponseReader.java

示例14: writeRequest

import org.restlet.resource.ResourceException; //導入依賴的package包/類
@Override
public boolean writeRequest(Object requestObject, Request request) throws ResourceException
{
   if (requestObject == null)
   {
      if (!Method.GET.equals(request.getMethod()))
         request.setEntity(new EmptyRepresentation());

      return true;
   }

   if (requestObject instanceof Representation)
   {
      request.setEntity((Representation) requestObject);
      return true;
   }

   for (RequestWriter requestWriter : requestWriters)
   {
      if (requestWriter.writeRequest(requestObject, request))
         return true;
   }

   return false;
}
 
開發者ID:apache,項目名稱:polygene-java,代碼行數:26,代碼來源:RequestWriterDelegator.java

示例15: getRestManager

import org.restlet.resource.ResourceException; //導入依賴的package包/類
/**
 * Locates the RestManager using ThreadLocal SolrRequestInfo.
 */
public static RestManager getRestManager(SolrRequestInfo solrRequestInfo) {
  if (solrRequestInfo == null)
    throw new ResourceException(Status.SERVER_ERROR_INTERNAL, 
        "No SolrRequestInfo in this Thread!");

  SolrQueryRequest req = solrRequestInfo.getReq();
  RestManager restManager = 
      (req != null) ? req.getCore().getRestManager() : null;
  
  if (restManager == null)
    throw new ResourceException(Status.SERVER_ERROR_INTERNAL, 
        "No RestManager found!");
  
  return restManager;
}
 
開發者ID:europeana,項目名稱:search,代碼行數:19,代碼來源:RestManager.java


注:本文中的org.restlet.resource.ResourceException類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。