/** * Adds the given method of the given component as a * dynamic handler for a specific pattern. Other informations * are taken from the annotation. * * @param component the component * @param method the name of the method that implements the handler * @param pattern the pattern */ public static void add(ComponentType component, String method, String pattern) { add(component, method, pattern, null); }
@Override public int priority(Annotation annotation) { return ((RequestHandler) annotation).priority(); }
@Override public HandlerScope scope(ComponentType component, Method method, ChannelReplacements channelReplacements) { RequestHandler annotation = method.getAnnotation(RequestHandler.class); if (annotation.dynamic()) { return null; } return new Scope(component, method, (RequestHandler) annotation, channelReplacements, null); }
/** * Handles a `GET` request. * * @param event the event * @param channel the channel * @throws ParseException the parse exception * @throws IOException Signals that an I/O exception has occurred. */ @RequestHandler(dynamic = true) public void onGet(Request.In.Get event, IOSubchannel channel) throws ParseException, IOException { int prefixSegs = resourcePattern.matches(event.requestUri()); if (prefixSegs < 0) { return; } if (contentDirectory == null) { getFromUri(event, channel, prefixSegs); } else { getFromFileSystem(event, channel, prefixSegs); } }
if (hda == null || !RequestHandler.class.isAssignableFrom(annoType) || !((RequestHandler) annotation).dynamic()) { continue; Scope scope = new Scope(component, m, (RequestHandler) annotation, Collections.emptyMap(), pattern); Components.manager(component) .addHandler(m, scope, priority == null ? ((RequestHandler) annotation).priority() : priority); return;
if (annotation.events()[0] != NoEvent.class) { handledEventTypes .addAll(Arrays.asList(annotation.events())); if (annotation.channels()[0] != NoChannel.class) { for (Class<?> c : annotation.channels()) { if (c == Self.class) { if (!(component instanceof Channel)) { if (!annotation.patterns()[0].equals("")) { for (String p : annotation.patterns()) { handledPatterns.add(new ResourcePattern(p));
/** * Adds the given method of the given component as a * dynamic handler for a specific pattern with the specified * priority. Other informations are taken from the annotation. * * @param component the component * @param method the name of the method that implements the handler * @param pattern the pattern * @param priority the priority */ public static void add(ComponentType component, String method, String pattern, int priority) { add(component, method, pattern, Integer.valueOf(priority)); }
@RequestHandler(priority = 990, dynamic = true) public void onRequest(Request.In event) { @SuppressWarnings("PMD.AccessorClassGeneration")
/** * Creates a new language selector component with its channel set * to the given channel and the scope to the given scope. * * @param componentChannel the component channel * @param scope the scope */ @SuppressWarnings("PMD.AvoidLiteralsInIfCondition") public LanguageSelector(Channel componentChannel, String scope) { super(componentChannel); if ("/".equals(scope) || !scope.endsWith("/")) { path = scope; } else { path = scope.substring(0, scope.length() - 1); } String pattern; if ("/".equals(path)) { pattern = "/**"; } else { pattern = path + "," + path + "/**"; } RequestHandler.Evaluator.add(this, "onRequest", pattern); }
@RequestHandler(dynamic = true) public void onRequest(Request.In event) { if (event.associated(Session.class).isPresent()) {
/** * Creates a new session manager using the given channel and path. * The manager handles only requests that match the given pattern. * The handler is registered with the given priority. * * This constructor can be used if special handling of top level * requests is needed. * * @param componentChannel the component channel * @param pattern the path part of a {@link ResourcePattern} * @param priority the priority * @param path the path */ public SessionManager(Channel componentChannel, String pattern, int priority, String path) { super(componentChannel); this.path = path; RequestHandler.Evaluator.add(this, "onRequest", pattern, priority); MBeanView.addManager(this); }
@RequestHandler(dynamic = true) public void onGet(GetRequest event, IOSubchannel channel) throws InterruptedException, IOException, ParseException {
this.contentRoot = contentRoot; RequestHandler.Evaluator.add(this, "onGet", resourcePattern);
/** * Redirects `GET` requests without trailing slash. * * @param event the event * @param channel the channel * @throws InterruptedException the interrupted exception * @throws IOException Signals that an I/O exception has occurred. * @throws ParseException the parse exception */ @RequestHandler(dynamic = true) @SuppressWarnings("PMD.EmptyCatchBlock") public void onGetRedirect(Request.In.Get event, IOSubchannel channel) throws InterruptedException, IOException, ParseException { HttpResponse response = event.httpRequest().response().get(); response.setStatus(HttpStatus.MOVED_PERMANENTLY) .setContentType("text", "plain", UTF_8) .setField(HttpField.LOCATION, prefix); channel.respond(new Response(response)); try { channel.respond(Output.from(prefix.toString() .getBytes(UTF_8), true)); } catch (UnsupportedEncodingException e) { // Supported by definition } event.setResult(true); event.stop(); }
/** * Redirects `GET` requests without trailing slash. * * @param event the event * @param channel the channel * @throws InterruptedException the interrupted exception * @throws IOException Signals that an I/O exception has occurred. * @throws ParseException the parse exception */ @RequestHandler(dynamic = true) @SuppressWarnings("PMD.EmptyCatchBlock") public void onGetRedirect(GetRequest event, IOSubchannel channel) throws InterruptedException, IOException, ParseException { HttpResponse response = event.httpRequest().response().get(); response.setStatus(HttpStatus.MOVED_PERMANENTLY) .setContentType("text", "plain", UTF_8) .setField(HttpField.LOCATION, portal.prefix()); channel.respond(new Response(response)); try { channel.respond(Output.from(portal.prefix().toString() .getBytes(UTF_8), true)); } catch (UnsupportedEncodingException e) { // Supported by definition } event.setResult(true); event.stop(); }
@RequestHandler(dynamic = true) public void onGet(Request.In.Get event, IOSubchannel channel) throws InterruptedException, IOException, ParseException {