Refine search
private static void replaceConverter( Class<? extends ConverterHelper> converterClass, ConverterHelper newConverter) { // TODO java 8-ify List<ConverterHelper> converters = Engine.getInstance().getRegisteredConverters(); for (ConverterHelper converter : converters) { if (converter.getClass().equals(converterClass)) { converters.remove(converter); break; } } converters.add(newConverter); }
/** * Returns the current context's logger. * * @return The current context's logger. */ public static Logger getCurrentLogger() { return (Context.getCurrent() != null) ? Context.getCurrent() .getLogger() : Engine.getLogger("org.restlet"); }
/** * Returns a class for a given qualified class name. * * @param className * The class name to lookup. * @return The class object. * @throws ClassNotFoundException */ protected Class<?> loadClass(String className) throws ClassNotFoundException { return Engine.loadClass(className); }
/** * Discovers the converter helpers and register the default helpers. * * @throws IOException */ private void discoverConverters() throws IOException { registerHelpers(DESCRIPTOR_CONVERTER_PATH, getRegisteredConverters(), null); registerDefaultConverters(); }
/** * Registers a new Restlet Engine. * * @param discoverPlugins * True if plug-ins should be automatically discovered. * @return The registered engine. */ public static synchronized Engine register(boolean discoverPlugins) { if (!logConfigured) { configureLog(); } Engine result = new Engine(discoverPlugins); instance = result; return result; }
/** * 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().warning( "Challenge scheme " + challengeResponse.getScheme() + " not supported by the Restlet engine."); } } return resourceRef; }
public static void main(String[] args) throws Exception { Engine.setLogLevel(Level.FINE); Server server = null; server = new Server(new Context(), Protocol.SIP, Integer.parseInt(args[0]), UacServerResource.class); } else { server = new Server(new Context(), Protocol.SIP, UacServerResource.class);
/** * 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().log( Level.FINE, "Unable get the variants of the " + ch + " converter helper.", e); } } } return result; }
final Class<?> targetClass = Engine.loadClass(targetClassName); .getClientDispatcher() .handle(new Request(Method.GET, targetDescriptor)); if (response.getStatus().isSuccess() .newInstance( getComponent().getContext() .createChildContext(), representation); if (target != null) { if ((uriPattern != null) && !defaultRoute) {
/** * 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); } }
.getResource("org/restlet/data/agent.properties"); if (userAgentPropertiesUrl != null) { BufferedReader reader; if (Context.getCurrent() != null) { Context.getCurrent() .getLogger() .warning( "Cannot read '"
this.loggerFacade = new LoggerFacade(); } else { this.classLoader = createClassLoader(); this.userClassLoader = null; "org.restlet.engine.log.LoggerFacade"); try { this.loggerFacade = (LoggerFacade) getClassLoader().loadClass( loggerFacadeClass).newInstance(); } catch (Exception e) { discoverConnectors(); discoverProtocols(); discoverAuthenticators(); discoverConverters(); } catch (IOException e) { Context.getCurrentLogger() .log(Level.WARNING, "An error occurred while discovering the engine helpers.",
/** * 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) { Context.getCurrentLogger() .severe("Unable to fully initialize the Restlet. No Restlet engine available."); throw new RuntimeException( "Unable to fully initialize the Restlet. No Restlet engine available."); } fireContextChanged(this, context); }
final Class<?> targetClass = Engine.loadClass(targetClassName); Context.class).newInstance( getComponent().getContext() .createChildContext()); } catch (NoSuchMethodException e) { getLogger() .newInstance(); target.setContext(getComponent().getContext() .createChildContext());
/** * 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()); getStatusService().setContext(childContext); this.clients.setContext(childContext); this.servers.setContext(childContext); } }
public static void process(String[] args) throws TranslationException { Engine.register(); String ulogin = null; String upwd = null; useSectionNamingPackageStrategy = true; } else if ("-V".equals(arg) || "--verbose".equals(arg)) { Engine.setLogLevel(Level.FINE); } else if ("--application-name".equals(arg)) { applicationName = getParameter(args, ++i); Engine.getLogger("").getHandlers()[0] .setFilter(record -> record.getLoggerName().startsWith("org.restlet.ext.platform"));
/** * Constructor. * * @param context * The context. * @param logService * The log service descriptor. */ public LogFilter(Context context, LogService logService) { super(context); this.logService = logService; if (logService != null) { if (logService.getLoggerName() != null) { this.logLogger = Engine.getLogger(logService.getLoggerName()); } else if ((context != null) && (context.getLogger().getParent() != null)) { this.logLogger = Engine.getLogger(context.getLogger() .getParent().getName() + "." + LogUtils.getBestClassName(logService.getClass())); } else { this.logLogger = Engine.getLogger(LogUtils .getBestClassName(logService.getClass())); } } }
/** * Starts the OSGi bundle by registering the engine with the bundle of the * Restlet API. * * @param context * The bundle context. */ public void start(BundleContext context) throws Exception { org.restlet.engine.Engine.register(false); // Discover helpers in installed bundles and start // the bundle if necessary for (final Bundle bundle : context.getBundles()) { registerHelpers(bundle); } // Listen to installed bundles context.addBundleListener(new BundleListener() { public void bundleChanged(BundleEvent event) { switch (event.getType()) { case BundleEvent.INSTALLED: registerHelpers(event.getBundle()); break; case BundleEvent.UNINSTALLED: break; } } }); Engine.getInstance().registerDefaultConnectors(); Engine.getInstance().registerDefaultAuthentications(); Engine.getInstance().registerDefaultConverters(); }