本文整理匯總了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;
}
示例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;
}
示例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;
}
示例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;
}
示例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());
}
示例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;
}
示例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 );
}
}
};
}
示例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 );
}
}
};
}
示例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;
}
示例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;
}
示例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;
}
示例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();
}
示例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 );
}
示例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 );
}
示例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();
}