Package org.restlet

Examples of org.restlet.Component


    LOG.info("helixAdminWebApp starting");
    if (_component == null) {
      _zkClient =
          new ZkClient(_zkServerAddress, ZkClient.DEFAULT_SESSION_TIMEOUT,
              ZkClient.DEFAULT_CONNECTION_TIMEOUT, new ZNRecordSerializer());
      _component = new Component();
      _component.getServers().add(Protocol.HTTP, _helixAdminPort);
      Context applicationContext = _component.getContext().createChildContext();
      applicationContext.getAttributes()
          .put(RestAdminApplication.ZKSERVERADDRESS, _zkServerAddress);
      applicationContext.getAttributes().put(RestAdminApplication.PORT, "" + _helixAdminPort);
View Full Code Here


  void startServer() {
    LOG.info("zkDataTransferServer starting on Port " + _localWebservicePort + " zkAddress "
        + _zkAddress);

    _component = new Component();

    _component.getServers().add(Protocol.HTTP, _localWebservicePort);
    Context applicationContext = _component.getContext().createChildContext();
    applicationContext.getAttributes().put(SERVER, this);
    applicationContext.getAttributes().put(PORT, "" + _localWebservicePort);
View Full Code Here

    private Boolean pipeliningConnections;
    private Integer threadMaxIdleTimeMs;
    private Boolean useForwardedForHeader;

    public RestletComponent() {
        this(new Component());
    }
View Full Code Here

     *
     * @return The Restlet-Component to use.
     */
    @Override
    public Component createComponent() {
        Component component = null;
        final String componentBeanName = getInitParameter(
                Component_BEAN_PARAM_NAME, null);

        // Not mentionned in the Spring javadocs, but getBean surely fails if
        // the argument is null.
View Full Code Here

     *
     * @return The newly created Component or null if unable to create.
     */
    @SuppressWarnings("unchecked")
    protected Component createComponent() {
        Component component = null;

        // Look for the Component XML configuration file.
        ServletWarClient client = new ServletWarClient(new Context(),
                getServletContext());
        Response response = client.get("war:///WEB-INF/restlet.xml");
        if (response.getStatus().isSuccess() && response.isEntityAvailable()) {
            component = new Component(response.getEntity());
        }

        // Look for the component class name specified in the web.xml file.
        if (component == null) {
            // Try to instantiate a new target component
            // First, find the component class name
            final String componentClassName = getInitParameter(COMPONENT_KEY,
                    null);

            // Load the component class using the given class name
            if (componentClassName != null) {
                try {
                    final Class<?> targetClass = loadClass(componentClassName);

                    // Create a new instance of the component class by
                    // invoking the constructor with the Context parameter.
                    component = (Component) targetClass.newInstance();
                } catch (ClassNotFoundException e) {
                    log(
                            "[Noelios Restlet Engine] - The ServerServlet couldn't find the target class. Please check that your classpath includes "
                                    + componentClassName, e);
                } catch (InstantiationException e) {
                    log(
                            "[Noelios Restlet Engine] - The ServerServlet couldn't instantiate the target class. Please check this class has an empty constructor "
                                    + componentClassName, e);
                } catch (IllegalAccessException e) {
                    log(
                            "[Noelios Restlet Engine] - The ServerServlet couldn't instantiate the target class. Please check that you have to proper access rights to "
                                    + componentClassName, e);
                }
            }
        }

        // Create the default Component
        if (component == null) {
            component = new Component();

            // The status service is disabled by default.
            component.getStatusService().setEnabled(false);

            // Define the list of supported client protocols.
            final String clientProtocolsString = getInitParameter(CLIENTS_KEY,
                    null);
            if (clientProtocolsString != null) {
                final String[] clientProtocols = clientProtocolsString
                        .split(" ");
                for (final String clientProtocol : clientProtocols) {
                    component.getClients()
                            .add(Protocol.valueOf(clientProtocol));
                }
            }
        }

        // Complete the configuration of the Component
        // Add the WAR client
        component.getClients().add(
                createWarClient(component.getContext(), getServletConfig()));

        // Copy all the servlet parameters into the context
        final ComponentContext componentContext = (ComponentContext) component
                .getContext();
        String initParam;

        // Copy all the Servlet container initialization parameters
        final javax.servlet.ServletConfig servletConfig = getServletConfig();
View Full Code Here

     *            The HTTP Servlet request.
     * @return The new HTTP server handling calls.
     */
    protected HttpServerHelper createServer(HttpServletRequest request) {
        HttpServerHelper result = null;
        final Component component = getComponent();

        if (component != null) {
            // First, let's create a pseudo server
            final Server server = new Server(component.getContext()
                    .createChildContext(), (List<Protocol>) null, request
                    .getLocalAddr(), request.getLocalPort(), component);
            result = new HttpServerHelper(server);

            // Attach the hosted application(s) to the right path
            final String uriPattern = request.getContextPath()
                    + request.getServletPath();

            if (isDefaultComponent()) {
                if (this.application != null) {
                    log("[Noelios Restlet Engine] - Attaching application: "
                            + this.application + " to URI: " + uriPattern);
                    component.getDefaultHost().attach(uriPattern,
                            this.application);
                }
            } else {
                // According to the mode, configure correctly the component.
                final String autoWire = getInitParameter(AUTO_WIRE_KEY,
                        AUTO_WIRE_KEY_DEFAULT);
                if (AUTO_WIRE_KEY_DEFAULT.equalsIgnoreCase(autoWire)) {
                    // Translate all defined routes as much as possible
                    // with the context path only or the full servlet path.

                    // 1- get the offset
                    boolean addContextPath = false;
                    boolean addFullServletPath = false;

                    if (component.getDefaultHost().getRoutes().isEmpty()) {
                        // Case where the default host has a default route (with
                        // an empty pattern).
                        addFullServletPath = component.getDefaultHost()
                                .getDefaultRoute() != null;
                    } else {
                        for (final Route route : component.getDefaultHost()
                                .getRoutes()) {
                            if (route.getTemplate().getPattern() == null) {
                                addFullServletPath = true;
                                continue;
                            }

                            if (!route.getTemplate().getPattern().startsWith(
                                    uriPattern)) {
                                if (!route.getTemplate().getPattern()
                                        .startsWith(request.getServletPath())) {
                                    addFullServletPath = true;
                                } else {
                                    addContextPath = true;
                                    break;
                                }
                            }
                        }
                    }
                    if (!addContextPath) {
                        for (final VirtualHost virtualHost : component
                                .getHosts()) {
                            if (virtualHost.getRoutes().isEmpty()) {
                                // Case where the default host has a default
                                // route (with an empty pattern).
                                addFullServletPath = virtualHost
                                        .getDefaultRoute() != null;
                            } else {
                                for (final Route route : virtualHost
                                        .getRoutes()) {
                                    if (route.getTemplate().getPattern() == null) {
                                        addFullServletPath = true;
                                        continue;
                                    }

                                    if (!route.getTemplate().getPattern()
                                            .startsWith(uriPattern)) {
                                        if (!route
                                                .getTemplate()
                                                .getPattern()
                                                .startsWith(
                                                        request
                                                                .getServletPath())) {
                                            addFullServletPath = true;
                                        } else {
                                            addContextPath = true;
                                            break;
                                        }
                                    }
                                }
                            }
                            if (addContextPath) {
                                break;
                            }
                        }
                    }

                    // 2- Translate all routes.
                    if (addContextPath || addFullServletPath) {
                        String offsetPath = null;

                        if (addContextPath) {
                            offsetPath = request.getContextPath();
                        } else {
                            offsetPath = uriPattern;
                        }

                        // Shift the default route (if any) of the default host
                        Route defaultRoute = component.getDefaultHost()
                                .getDefaultRoute();
                        if (defaultRoute != null) {
                            defaultRoute.getTemplate().setPattern(
                                    offsetPath
                                            + defaultRoute.getTemplate()
                                                    .getPattern());
                            log("[Noelios Restlet Engine] - Attaching restlet: "
                                    + defaultRoute.getNext()
                                    + " to URI: "
                                    + offsetPath
                                    + defaultRoute.getTemplate().getPattern());
                        }

                        // Shift the routes of the default host
                        for (final Route route : component.getDefaultHost()
                                .getRoutes()) {
                            log("[Noelios Restlet Engine] - Attaching restlet: "
                                    + route.getNext()
                                    + " to URI: "
                                    + offsetPath
                                    + route.getTemplate().getPattern());
                            route.getTemplate().setPattern(
                                    offsetPath
                                            + route.getTemplate().getPattern());
                        }
                        for (final VirtualHost virtualHost : component
                                .getHosts()) {
                            // Shift the default route (if any) of the virtual
                            // host
                            defaultRoute = virtualHost.getDefaultRoute();
                            if (defaultRoute != null) {
View Full Code Here

     *
     * @return The component.
     */
    @SuppressWarnings("null")
    public Component getComponent() {
        Component result = this.component;

        if (result == null) {
            synchronized (ServerServlet.class) {
                if (result == null) {
                    // Find the attribute name to use to store the component
View Full Code Here

    /**
     * Tests the cookies parsing.
     */
    public void testRedirect() throws Exception {
        // Create components
        final Component clientComponent = new Component();
        final Component proxyComponent = new Component();
        final Component originComponent = new Component();

        // Create the client connectors
        clientComponent.getClients().add(Protocol.HTTP);
        proxyComponent.getClients().add(Protocol.HTTP);

        // Create the proxy Restlet
        final String target = "http://localhost:" + (TEST_PORT + 1) + "{rr}";
        final Redirector proxy = new Redirector(proxyComponent.getContext()
                .createChildContext(), target, Redirector.MODE_SERVER_OUTBOUND);

        // Create a new Restlet that will display some path information.
        final Restlet trace = new Restlet(originComponent.getContext()
                .createChildContext()) {
            @Override
            public void handle(Request request, Response response) {
                // Print the requested URI path
                final String message = "Resource URI:  "
                        + request.getResourceRef() + '\n' + "Base URI:      "
                        + request.getResourceRef().getBaseRef() + '\n'
                        + "Remaining part: "
                        + request.getResourceRef().getRemainingPart() + '\n'
                        + "Method name:   " + request.getMethod() + '\n';
                response.setEntity(new StringRepresentation(message,
                        MediaType.TEXT_PLAIN));
            }
        };

        // Set the component roots
        proxyComponent.getDefaultHost().attach("", proxy);
        originComponent.getDefaultHost().attach("", trace);

        // Create the server connectors
        proxyComponent.getServers().add(Protocol.HTTP, TEST_PORT);
        originComponent.getServers().add(Protocol.HTTP, TEST_PORT + 1);

        // Now, let's start the components!
        originComponent.start();
        proxyComponent.start();
        clientComponent.start();

        // Tests
        final Context context = clientComponent.getContext();
        String uri = "http://localhost:" + TEST_PORT + "/?foo=bar";
        testCall(context, Method.GET, uri);
        testCall(context, Method.DELETE, uri);

        uri = "http://localhost:" + TEST_PORT
                + "/abcd/efgh/ijkl?foo=bar&foo=beer";
        testCall(context, Method.GET, uri);
        testCall(context, Method.DELETE, uri);

        uri = "http://localhost:" + TEST_PORT
                + "/v1/client/kwse/CnJlNUQV9%252BNNqbUf7Lhs2BYEK2Y%253D"
                + "/user/johnm/uVGYTDK4kK4zsu96VHGeTCzfwso%253D/";
        testCall(context, Method.GET, uri);

        // Stop the components
        clientComponent.stop();
        originComponent.stop();
        proxyComponent.stop();
    }
View Full Code Here

    private Client client;

    protected void setUp() throws Exception {
        super.setUp();
        c = new Component();
        c.getServers().add(Protocol.HTTP, 8111);
        c.getDefaultHost().attach(new TestApplication());
        c.start();

        client = new Client(Protocol.HTTP);
View Full Code Here

    private Client client;

    protected void setUp() throws Exception {
        super.setUp();
        c = new Component();
        c.getServers().add(Protocol.HTTP, 8111);
        c.getDefaultHost().attach(new TestApplication());
        c.start();
        client = new Client(Protocol.HTTP);
    }
View Full Code Here

TOP

Related Classes of org.restlet.Component

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.