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


Java Response類代碼示例

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


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

示例1: createInboundRoot

import org.restlet.Response; //導入依賴的package包/類
@Override
public Restlet createInboundRoot() {
	Router baseRouter = new Router(context);
	baseRouter.setDefaultMatchingMode(Template.MODE_STARTS_WITH);
	for (RestletRoutable rr : restlets) {
		baseRouter.attach(rr.basePath(), rr.getRestlet(context));
	}

	Filter slashFilter = new Filter() {            
		@Override
		protected int beforeHandle(Request request, Response response) {
			Reference ref = request.getResourceRef();
			String originalPath = ref.getPath();
			if (originalPath.contains("//"))
			{
				String newPath = originalPath.replaceAll("/+", "/");
				ref.setPath(newPath);
			}
			return Filter.CONTINUE;
		}

	};
	slashFilter.setNext(baseRouter);

	return slashFilter;
}
 
開發者ID:xuraylei,項目名稱:fresco_floodlight,代碼行數:27,代碼來源:RestApiServer.java

示例2: authorize

import org.restlet.Response; //導入依賴的package包/類
@Override
protected boolean authorize(Request request, Response response) {
	if (request.getMethod() == Method.OPTIONS) return true;

	if (request.getAttributes().get("account") != null) return true;
	
	String accessToken = request.getHeaders().getFirstValue(HttpHeaders.AUTHORIZATION);
	if (accessToken == null) return true;
	
	try {
		accessToken.replace("OAuth ", "");
		AccountBean acc = mAccounts.getAccountFromToken(accessToken);
	    if (acc != null) {
	    	request.getAttributes().put("account", acc);
	    	return true;
	    }
	} catch (Exception e) {
		Main.LOGGER.log(Level.WARNING, "Error while handling OAuth authentification", e);
		return false;
	}
    
	return false;
}
 
開發者ID:FightForSub,項目名稱:FFS-Api,代碼行數:24,代碼來源:AuthAggregator.java

示例3: verify

import org.restlet.Response; //導入依賴的package包/類
@Override
public int verify(Request request, Response response) {
	if (request.getMethod() == Method.OPTIONS) return RESULT_VALID;

	if (request.getAttributes().get("account") != null) return RESULT_VALID;
	
	String accessToken = request.getHeaders().getFirstValue(HttpHeaders.AUTHORIZATION);
	if (accessToken == null) return RESULT_MISSING;
	
	try {
		accessToken.replace("OAuth ", "");
		AccountBean acc = mAccounts.getAccountFromToken(accessToken);
	    if (acc != null) {
	    	request.getAttributes().put("account", acc);
	    	return RESULT_VALID;
	    }
	} catch (Exception e) {
		Main.LOGGER.log(Level.WARNING, "Error while handling OAuth authentification", e);
		return RESULT_INVALID;
	}
    
	return RESULT_INVALID;
}
 
開發者ID:FightForSub,項目名稱:FFS-Api,代碼行數:24,代碼來源:OAuthVerifier.java

示例4: createInboundRoot

import org.restlet.Response; //導入依賴的package包/類
@Override
public Restlet createInboundRoot() {
    Router baseRouter = new Router(context);
    baseRouter.setDefaultMatchingMode(Template.MODE_STARTS_WITH);
    for (RestletRoutable rr : restlets) {
        baseRouter.attach(rr.basePath(), rr.getRestlet(context));
    }

    Filter slashFilter = new Filter() {            
        @Override
        protected int beforeHandle(Request request, Response response) {
            Reference ref = request.getResourceRef();
            String originalPath = ref.getPath();
            if (originalPath.contains("//"))
            {
                String newPath = originalPath.replaceAll("/+", "/");
                ref.setPath(newPath);
            }
            return Filter.CONTINUE;
        }

    };
    slashFilter.setNext(baseRouter);
    
    return slashFilter;
}
 
開發者ID:JianqingJiang,項目名稱:QoS-floodlight,代碼行數:27,代碼來源:RestApiServer.java

示例5: testRestletProducer2

import org.restlet.Response; //導入依賴的package包/類
@Test
public void testRestletProducer2() throws Exception {
    final Map<String, Object> headers = new HashMap<String, Object>();
    headers.put("id", 123);
    headers.put("beverage.beer", "Carlsberg");

    Exchange out = template.request("direct:start", new Processor() {
        @Override
        public void process(Exchange exchange) throws Exception {
            exchange.getIn().setHeaders(headers);
        }
    });
    assertNotNull(out);
    assertEquals("text/xml", out.getOut().getHeader(Exchange.CONTENT_TYPE));
    assertEquals(200, out.getOut().getHeader(Exchange.HTTP_RESPONSE_CODE));
    assertEquals("<response>Beer is Good</response>", out.getOut().getBody(String.class));

    // the restlet response should be accessible if needed
    Response response = out.getOut().getHeader(RestletConstants.RESTLET_RESPONSE, Response.class);
    assertNotNull(response);
    assertEquals(200, response.getStatus().getCode());
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:23,代碼來源:RestletRequestAndResponseAPITest.java

示例6: shouldShowCommandForm

import org.restlet.Response; //導入依賴的package包/類
private boolean shouldShowCommandForm( Method interactionMethod )
{
    // Show form on GET/HEAD
    if( Request.getCurrent().getMethod().isSafe() )
    {
        return true;
    }

    if( interactionMethod.getParameterTypes().length > 0 )
    {
        return !( interactionMethod.getParameterTypes()[ 0 ].equals( Response.class ) || Request.getCurrent()
            .getEntity()
            .isAvailable() || Request.getCurrent().getEntityAsText() != null || Request.getCurrent()
                                                                                    .getResourceRef()
                                                                                    .getQuery() != null );
    }

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

示例7: createTextHtmlRepresentation

import org.restlet.Response; //導入依賴的package包/類
private Representation createTextHtmlRepresentation( final Object result, final Response response )
{
    return new WriterRepresentation( MediaType.TEXT_HTML )
                {
                    @Override
                    public void write( Writer writer )
                        throws IOException
                    {
                        Map<String, Object> context = new HashMap<>();
                        context.put( "request", response.getRequest() );
                        context.put( "response", response );
                        context.put( "result", result );
                        try
                        {
                            cfg.getTemplate( "links.htm" ).process( context, writer );
                        }
                        catch( TemplateException e )
                        {
                            throw new IOException( e );
                        }
                    }
                };
}
 
開發者ID:apache,項目名稱:polygene-java,代碼行數:24,代碼來源:LinksResponseWriter.java

示例8: createAtomRepresentation

import org.restlet.Response; //導入依賴的package包/類
private Representation createAtomRepresentation( final Object result, final Response response )
{
    return new WriterRepresentation( MediaType.APPLICATION_ATOM )
    {
        @Override
        public void write( Writer writer )
            throws IOException
        {
            Map<String, Object> context = new HashMap<>();
            context.put( "request", response.getRequest() );
            context.put( "response", response );
            context.put( "result", result );
            try
            {
                cfg.getTemplate( "links.atom" ).process( context, writer );
            }
            catch( TemplateException e )
            {
                throw new IOException( e );
            }
        }
    };
}
 
開發者ID:apache,項目名稱:polygene-java,代碼行數:24,代碼來源:LinksResponseWriter.java

示例9: onResource

import org.restlet.Response; //導入依賴的package包/類
public <T> ContextResourceClient onResource( final ResultHandler<T> handler)
{
    resourceHandler = new ResponseHandler()
    {
        @Override
        public HandlerCommand handleResponse( Response response, ContextResourceClient client )
        {
            final Class<T> resultType = (Class<T>) Classes.RAW_CLASS.apply(( (ParameterizedType) handler.getClass().getGenericInterfaces()[ 0 ] ).getActualTypeArguments()[0]);
            T result = contextResourceFactory.readResponse( response, resultType );

            if (result instanceof Resource)
            {
                resource = (Resource) result;
            }

            return handler.handleResult( result, client );
        }
    };
    return this;
}
 
開發者ID:apache,項目名稱:polygene-java,代碼行數:21,代碼來源:ContextResourceClient.java

示例10: onQuery

import org.restlet.Response; //導入依賴的package包/類
public <T> ContextResourceClient onQuery( String relation, final ResultHandler<T> handler
)
{
    final Class<T> resultType = (Class<T>) Classes.RAW_CLASS.apply(( (ParameterizedType) handler.getClass().getGenericInterfaces()[ 0 ] ).getActualTypeArguments()[0]);

    queryHandlers.put( relation,  new ResponseHandler()
    {
        @Override
        public HandlerCommand handleResponse( Response response, ContextResourceClient client )
        {
            T result = contextResourceFactory.readResponse( response, resultType );
            return handler.handleResult( result, client );
        }
    });

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

示例11: onProcessingError

import org.restlet.Response; //導入依賴的package包/類
public <T> ContextResourceClient onProcessingError( String relation, final ResultHandler<T> handler)
{
    final Class<T> resultType = (Class<T>) Classes.RAW_CLASS.apply(( (ParameterizedType) handler.getClass().getGenericInterfaces()[ 0 ] ).getActualTypeArguments()[0]);

    processingErrorHandlers.put( relation,  new ResponseHandler()
    {
        @Override
        public HandlerCommand handleResponse( Response response, ContextResourceClient client )
        {
            T result = contextResourceFactory.readResponse( response, resultType );
            return handler.handleResult( result, client );
        }
    });

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

示例12: create

import org.restlet.Response; //導入依賴的package包/類
@Override
public T create( Class<T> entityType, Request request, Response response, Context context )
{
    final Map<String, Object> attributes = request.getAttributes();
    String id = (String) attributes.get( "id" );

    ValueBuilder<T> builder = vbf.newValueBuilderWithState(
        resourceType,
        descriptor -> findValue( attributes, descriptor ),
        descriptor -> null,
        descriptor -> null,
        descriptor -> null
    );
    //noinspection unchecked
    ServerResource.Parameters<T> params = builder.prototypeFor( ServerResource.Parameters.class );
    params.id().set( id );
    params.entityType().set( entityType );
    params.context().set( this.context );
    params.request().set( request );
    params.router().set( router );
    params.response().set( response );
    return builder.newInstance();
}
 
開發者ID:apache,項目名稱:polygene-java,代碼行數:24,代碼來源:DefaultResourceFactoryImpl.java

示例13: administration

import org.restlet.Response; //導入依賴的package包/類
@SubResource
public void administration()
{
    ChallengeResponse challenge = Request.getCurrent().getChallengeResponse();
    if( challenge == null )
    {
        Response.getCurrent()
            .setChallengeRequests( Collections.singletonList( new ChallengeRequest( ChallengeScheme.HTTP_BASIC, "Forum" ) ) );
        throw new ResourceException( Status.CLIENT_ERROR_UNAUTHORIZED );
    }

    User user = select( Users.class, Users.USERS_ID ).userNamed( challenge.getIdentifier() );
    if( user == null || !user.isCorrectPassword( new String( challenge.getSecret() ) ) )
    {
        throw new ResourceException( Status.CLIENT_ERROR_UNAUTHORIZED );
    }

    current().select( user );

    subResource( AdministrationResource.class );
}
 
開發者ID:apache,項目名稱:polygene-java,代碼行數:22,代碼來源:RootResource.java

示例14: handle

import org.restlet.Response; //導入依賴的package包/類
@Override
public void handle( Request request, Response response )
{
	// RIAP ignores hide
	if( request.getProtocol() != Protocol.RIAP )
	{
		String remainingPart = request.getResourceRef().getRemainingPart();
		for( Template hiddenUriTemplate : hiddenUriTemplates )
		{
			if( hiddenUriTemplate.match( remainingPart ) != -1 )
			{
				response.setStatus( Status.CLIENT_ERROR_NOT_FOUND );
				return;
			}
		}
	}

	super.handle( request, response );
}
 
開發者ID:tliron,項目名稱:prudence,代碼行數:20,代碼來源:PrudenceRouter.java

示例15: run

import org.restlet.Response; //導入依賴的package包/類
public void run()
{
	if( delay > 0 )
	{
		try
		{
			Thread.sleep( delay );
		}
		catch( InterruptedException e )
		{
			// Restore interrupt status
			Thread.currentThread().interrupt();
			return;
		}
	}

	Response response = resource.getResponse();
	response.setEntity( this );
	response.setStatus( Status.SUCCESS_OK );
	response.commit();
}
 
開發者ID:tliron,項目名稱:prudence,代碼行數:22,代碼來源:GeneratedTextDeferredRepresentation.java


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