本文整理汇总了Java中org.restlet.engine.Engine类的典型用法代码示例。如果您正苦于以下问题:Java Engine类的具体用法?Java Engine怎么用?Java Engine使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Engine类属于org.restlet.engine包,在下文中一共展示了Engine类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: Server
import org.restlet.engine.Engine; //导入依赖的package包/类
/**
* Constructor.
*
* @param context
* The context.
* @param protocols
* The connector protocols.
* @param address
* The optional listening IP address (useful if multiple IP
* addresses available). You can also use a domain name as an
* alias for the IP address to listen to.
* @param port
* The listening port.
* @param next
* The next Restlet.
* @param helperClass
* Optional helper class name.
*/
public Server(Context context, List<Protocol> protocols, String address,
int port, Restlet next, String helperClass) {
super(context, protocols);
this.address = address;
this.port = port;
this.next = next;
if (Engine.getInstance() != null) {
this.helper = Engine.getInstance().createHelper(this, helperClass);
} else {
this.helper = null;
}
if (context != null && this.helper != null) {
context.getAttributes().put("org.restlet.engine.helper",
this.helper);
}
}
示例2: Component
import org.restlet.engine.Engine; //导入依赖的package包/类
/**
* Constructor.
*/
public Component() {
super();
this.hosts = new CopyOnWriteArrayList<VirtualHost>();
this.clients = new ClientList(null);
this.servers = new ServerList(null, this);
this.realms = new CopyOnWriteArrayList<Realm>();
this.services = new ServiceList(getContext());
if (Engine.getInstance() != null) {
// To be done before setting the helper...
this.services.add(new org.restlet.service.TaskService());
this.helper = new ComponentHelper(this);
Context childContext = getContext().createChildContext();
this.defaultHost = new VirtualHost(childContext);
this.internalRouter = new InternalRouter(childContext);
this.services.add(new LogService());
getLogService().setContext(childContext);
this.services.add(new StatusService());
this.clients.setContext(childContext);
this.servers.setContext(childContext);
}
}
示例3: getBestHelper
import org.restlet.engine.Engine; //导入依赖的package包/类
/**
* Returns the best converter helper matching the given parameters.
*
* @param source
* The object to convert to a representation.
* @param target
* The target representation variant.
* @param resource
* The optional parent resource.
* @return The matched converter helper or null.
*/
public static ConverterHelper getBestHelper(Object source, Variant target,
Resource resource) {
ConverterHelper result = null;
float bestScore = -1.0F;
float currentScore;
for (ConverterHelper ch : Engine.getInstance()
.getRegisteredConverters()) {
if (ch != null) {
try {
currentScore = ch.score(source, target, resource);
if (currentScore > bestScore) {
bestScore = currentScore;
result = ch;
}
} catch (Exception e) {
Context.getCurrentLogger().error("Unable get the score of the " + ch
+ " converter helper.", e);
}
}
}
return result;
}
示例4: getVariants
import org.restlet.engine.Engine; //导入依赖的package包/类
/**
* Returns the list of variants that can be converted from a given object
* class.
*
* @param sourceClass
* The source class.
* @param targetVariant
* The expected representation metadata.
* @return The list of variants that can be converted.
*/
public static List<VariantInfo> getVariants(Class<?> sourceClass,
Variant targetVariant) {
List<VariantInfo> result = null;
for (ConverterHelper ch : Engine.getInstance()
.getRegisteredConverters()) {
if (ch != null) {
try {
result = ch.addVariants(sourceClass, targetVariant, result);
} catch (IOException e) {
Context.getCurrentLogger().debug(
"Unable get the variants of the " + ch + " converter helper.", e);
}
}
}
return result;
}
示例5: parseRequest
import org.restlet.engine.Engine; //导入依赖的package包/类
/**
* Parses an authenticate header into a list of challenge request. The
* header is {@link HeaderConstants#HEADER_WWW_AUTHENTICATE}.
*
* @param header
* The HTTP header value to parse.
* @param httpHeaders
* The current response HTTP headers.
* @return The list of parsed challenge request.
*/
public static List<ChallengeRequest> parseRequest(Response response,
String header, Series<Header> httpHeaders) {
List<ChallengeRequest> result = new ArrayList<ChallengeRequest>();
if (header != null) {
result = new ChallengeRequestReader(header).readValues();
for (ChallengeRequest cr : result) {
// Give a chance to the authenticator helper to do further
// parsing
AuthenticatorHelper helper = Engine.getInstance().findHelper(
cr.getScheme(), true, false);
if (helper != null) {
helper.parseRequest(cr, response, httpHeaders);
} else {
Context.getCurrentLogger().warn(
"Couldn't find any helper support the "
+ cr.getScheme() + " challenge scheme.");
}
}
}
return result;
}
示例6: updateReference
import org.restlet.engine.Engine; //导入依赖的package包/类
/**
* Optionally updates the request with a challenge response before sending
* it. This is sometimes useful for authentication schemes that aren't based
* on the Authorization header but instead on URI query parameters or other
* headers. By default it returns the resource URI reference unchanged.
*
* @param resourceRef
* The resource URI reference to update.
* @param challengeResponse
* The challenge response provided.
* @param request
* The request to update.
* @return The original URI reference if unchanged or a new one if updated.
*/
public static Reference updateReference(Reference resourceRef,
ChallengeResponse challengeResponse, Request request) {
if (challengeResponse != null && challengeResponse.getRawValue() == null) {
AuthenticatorHelper helper = Engine.getInstance().findHelper(
challengeResponse.getScheme(), true, false);
if (helper != null) {
resourceRef = helper.updateReference(resourceRef,
challengeResponse, request);
} else {
Context.getCurrentLogger().warn(
"Challenge scheme " + challengeResponse.getScheme()
+ " not supported by the Restlet engine.");
}
}
return resourceRef;
}
示例7: registerHelpers
import org.restlet.engine.Engine; //导入依赖的package包/类
/**
* Registers the helpers for a given bundle.
*
* @param bundle
* The bundle to inspect.
*/
private void registerHelpers(Bundle bundle) {
// Register server helpers
registerHelper(bundle, Engine.getInstance().getRegisteredServers(),
Server.class, Engine.DESCRIPTOR_SERVER_PATH);
// Register client helpers
registerHelper(bundle, Engine.getInstance().getRegisteredClients(),
Client.class, Engine.DESCRIPTOR_CLIENT_PATH);
// Register authentication helpers
registerHelper(bundle, Engine.getInstance()
.getRegisteredAuthenticators(), null,
Engine.DESCRIPTOR_AUTHENTICATOR_PATH);
// Register converter helpers
registerHelper(bundle, Engine.getInstance().getRegisteredConverters(),
null, Engine.DESCRIPTOR_CONVERTER_PATH);
}
示例8: Client
import org.restlet.engine.Engine; //导入依赖的package包/类
/**
* Constructor.
*
* @param context
* The context.
* @param protocols
* The connector protocols.
* @param helperClass
* Optional helper class name.
*/
public Client(Context context, List<Protocol> protocols, String helperClass) {
super(context, protocols);
if ((protocols != null) && !protocols.isEmpty()) {
if (Engine.getInstance() != null) {
this.helper = Engine.getInstance().createHelper(this,
helperClass);
} else {
this.helper = null;
}
} else {
this.helper = null;
}
if (context != null && this.helper != null) {
context.getAttributes().put("org.restlet.engine.helper",
this.helper);
}
}
示例9: getObjectClasses
import org.restlet.engine.Engine; //导入依赖的package包/类
/**
* Returns the list of object classes that can be converted from a given
* variant.
*
* @param source
* The source variant.
* @return The list of object class that can be converted.
*/
public List<Class<?>> getObjectClasses(Variant source) {
List<Class<?>> result = null;
List<Class<?>> helperObjectClasses = null;
for (ConverterHelper ch : Engine.getInstance()
.getRegisteredConverters()) {
helperObjectClasses = ch.getObjectClasses(source);
if (helperObjectClasses != null) {
if (result == null) {
result = new ArrayList<Class<?>>();
}
result.addAll(helperObjectClasses);
}
}
return result;
}
示例10: Restlet
import org.restlet.engine.Engine; //导入依赖的package包/类
/**
* Constructor with the Restlet's context which can be the parent's
* application context, but shouldn't be the parent Component's context for
* security reasons.
*
* @see Context#createChildContext()
*
* @param context
* The context of the Restlet.
*
*/
public Restlet(Context context) {
this.context = context;
this.started = false;
this.name = toString();
this.description = null;
this.author = null;
this.owner = null;
this.finderClass = null;
if (Engine.getInstance() == null) {
String message = "Unable to fully initialize the Restlet. No Restlet engine available.";
Context.getCurrentLogger().error(message);
throw new RuntimeException(message);
}
fireContextChanged(this, context);
}
示例11: getLogger
import org.restlet.engine.Engine; //导入依赖的package包/类
/**
* Returns the context's logger.
*
* @return The context's logger.
*/
public Logger getLogger() {
Logger result = null;
Context context = getContext();
if (context == null) {
context = Context.getCurrent();
}
if (context != null) {
result = context.getLogger();
}
if (result == null) {
result = Engine.getLogger(this, "org.restlet");
}
return result;
}
示例12: replaceConverter
import org.restlet.engine.Engine; //导入依赖的package包/类
/**
* 移除给定类的第一个注册的converter后,使用Restlet引擎注册一个converter类
* 参考:http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2716118
*/
static void replaceConverter(Class<? extends ConverterHelper> converterClass, ConverterHelper newConverter) {
ConverterHelper oldConverter = null;
List<ConverterHelper> converters = Engine.getInstance().getRegisteredConverters();
for (ConverterHelper converter : converters) {
if (converter.getClass().equals(converterClass)) {
converters.remove(converter);
oldConverter = converter;
break;
}
}
converters.add(newConverter);
if (oldConverter == null) {
System.err.println("Added Converter to Restlet Engine: " + newConverter.getClass().getName());
} else {
System.err.println("Replaced Converter " + oldConverter.getClass().getName() + " with "
+ newConverter.getClass().getName() + " in Restlet Engine");
}
}
示例13: doConfigureConverter
import org.restlet.engine.Engine; //导入依赖的package包/类
protected void doConfigureConverter() {
resourceRegister.addClass(DataSourceResponse.class, "datasourceResponse");
resourceRegister.addClass(FormResponse.class, "formResponse");
resourceRegister.addClass(ErrorFormResponse.class, "message");
resourceRegister.addClass(FieldMessage.class, "field");
Engine engine = Engine.getInstance();
List<ConverterHelper> converters = engine.getRegisteredConverters();
for (ConverterHelper converterHelper : converters) {
if (converterHelper instanceof IObjectRegistering) {
IObjectRegistering registring = (IObjectRegistering) converterHelper;
try {
registring.registerObjects(resourceRegister);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
}
示例14: main
import org.restlet.engine.Engine; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
Component component = new Component();
component.getClients().add(Protocol.FILE);
//TODO: To test with the restlet 2.1 Maybe the maxTotalConnections could be avoided
// see: http://restlet-discuss.1400322.n2.nabble.com/rejectedExecution-td4513620.html
//component.getServers().add(Protocol.HTTP, SERVER_PORT);
Server server = new Server(Protocol.HTTP, 8111);
component.getServers().add(server);
server.getContext().getParameters().add("maxTotalConnections", "50");
//end TODO
Engine.getInstance().getRegisteredServers().clear();
Engine.getInstance().getRegisteredServers().add(new HttpServerHelper(server));
component.getClients().add(Protocol.FILE);
component.getDefaultHost().attach(new FreedomRestServer());
component.start();
}
示例15: replaceConverter
import org.restlet.engine.Engine; //导入依赖的package包/类
private static void replaceConverter(
Class<? extends ConverterHelper> converterClass,
ConverterHelper newConverter) {
List<ConverterHelper> converters = Engine.getInstance().getRegisteredConverters();
for (ConverterHelper converter : converters) {
if (converter.getClass().equals(converterClass)) {
converters.remove(converter);
break;
}
}
converters.add(newConverter);
}