当前位置: 首页>>代码示例>>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;未经允许,请勿转载。