Search in sources :

Example 6 with Application

use of org.apache.wicket.Application in project wicket by apache.

the class WebSocketPushBroadcaster method broadcast.

/**
 * Processes the given message in the page and session identified by the given Web Socket connection.
 * The message is sent as an event to the Page and components of the session allowing the components
 * to be updated.
 *
 * This method can be invoked from any thread, even a non-wicket thread. By default all processing
 * is done in the caller thread. Use
 * {@link WebSocketSettings#setWebSocketPushMessageExecutor(org.apache.wicket.protocol.ws.concurrent.Executor)}
 * to move processing to background threads.
 *
 * If the given connection is no longer open then the broadcast is silently ignored.
 *
 * @param connection
 *			The Web Socket connection that identifies the page and session
 * @param message
 *			The push message event
 */
public void broadcast(ConnectedMessage connection, IWebSocketPushMessage message) {
    Args.notNull(connection, "connection");
    Args.notNull(message, "message");
    Application application = connection.getApplication();
    String sessionId = connection.getSessionId();
    IKey key = connection.getKey();
    IWebSocketConnection wsConnection = registry.getConnection(application, sessionId, key);
    if (wsConnection == null) {
        return;
    }
    process(application, singletonList(wsConnection), message);
}
Also used : IKey(org.apache.wicket.protocol.ws.api.registry.IKey) Application(org.apache.wicket.Application)

Example 7 with Application

use of org.apache.wicket.Application in project wicket by apache.

the class AjaxRequestHandler method respond.

/**
 * @see org.apache.wicket.core.request.handler.IPageRequestHandler#respond(org.apache.wicket.request.IRequestCycle)
 */
@Override
public final void respond(final IRequestCycle requestCycle) {
    final RequestCycle rc = (RequestCycle) requestCycle;
    final WebResponse response = (WebResponse) requestCycle.getResponse();
    if (shouldRedirectToPage(requestCycle)) {
        // the page itself has been added to the request target, we simply issue a redirect
        // back to the page
        IRequestHandler handler = new RenderPageRequestHandler(new PageProvider(page));
        final String url = rc.urlFor(handler).toString();
        response.sendRedirect(url);
        return;
    }
    respondersFrozen = true;
    for (ITargetRespondListener listener : respondListeners) {
        listener.onTargetRespond(this);
    }
    final Application app = page.getApplication();
    page.send(app, Broadcast.BREADTH, this);
    // Determine encoding
    final String encoding = app.getRequestCycleSettings().getResponseRequestEncoding();
    // Set content type based on markup type for page
    update.setContentType(response, encoding);
    // Make sure it is not cached by a client
    response.disableCaching();
    final StringResponse bodyResponse = new StringResponse();
    update.writeTo(bodyResponse, encoding);
    CharSequence filteredResponse = invokeResponseFilters(bodyResponse);
    response.write(filteredResponse);
}
Also used : WebResponse(org.apache.wicket.request.http.WebResponse) IRequestHandler(org.apache.wicket.request.IRequestHandler) RenderPageRequestHandler(org.apache.wicket.core.request.handler.RenderPageRequestHandler) RequestCycle(org.apache.wicket.request.cycle.RequestCycle) IRequestCycle(org.apache.wicket.request.IRequestCycle) PageProvider(org.apache.wicket.core.request.handler.PageProvider) StringResponse(org.apache.wicket.response.StringResponse) Application(org.apache.wicket.Application)

Example 8 with Application

use of org.apache.wicket.Application in project wicket by apache.

the class AbstractClassResolver method getResources.

@Override
public Iterator<URL> getResources(final String name) {
    Set<URL> resultSet = new TreeSet<>(new UrlExternalFormComparator());
    try {
        // Try the classloader for the wicket jar/bundle
        Enumeration<URL> resources = Application.class.getClassLoader().getResources(name);
        loadResources(resources, resultSet);
        // Try the classloader for the user's application jar/bundle
        resources = Application.get().getClass().getClassLoader().getResources(name);
        loadResources(resources, resultSet);
        // Try the context class loader
        resources = getClassLoader().getResources(name);
        loadResources(resources, resultSet);
    } catch (Exception e) {
        throw new WicketRuntimeException(e);
    }
    return resultSet.iterator();
}
Also used : UrlExternalFormComparator(org.apache.wicket.util.collections.UrlExternalFormComparator) TreeSet(java.util.TreeSet) WicketRuntimeException(org.apache.wicket.WicketRuntimeException) Application(org.apache.wicket.Application) URL(java.net.URL) WicketRuntimeException(org.apache.wicket.WicketRuntimeException)

Example 9 with Application

use of org.apache.wicket.Application in project wicket-orientdb by OrienteerBAP.

the class OrientDbWebApplication method init.

@Override
protected void init() {
    super.init();
    Orient.instance().registerThreadDatabaseFactory(new DefaultODatabaseThreadLocalFactory(this));
    Orient.instance().addDbLifecycleListener(new ODatabaseLifecycleListener() {

        private ORecordHook createHook(Class<? extends ORecordHook> clazz, ODatabaseInternal iDatabase) {
            if (!(iDatabase instanceof ODatabaseDocument))
                return null;
            try {
                return (ORecordHook) clazz.getConstructor(ODatabaseDocument.class).newInstance(iDatabase);
            } catch (Exception e) {
                try {
                    return (ORecordHook) clazz.newInstance();
                } catch (Exception e1) {
                    throw new IllegalStateException("Can't initialize hook " + clazz.getName(), e);
                }
            }
        }

        @Override
        public void onOpen(ODatabaseInternal iDatabase) {
            registerHooks(iDatabase);
        }

        @Override
        public void onCreate(ODatabaseInternal iDatabase) {
            registerHooks(iDatabase);
            // Fix for "feature" appeared in OrientDB 2.1.1
            // Issue: https://github.com/orientechnologies/orientdb/issues/4906
            fixOrientDBRights(iDatabase);
        }

        public void registerHooks(ODatabaseInternal iDatabase) {
            Set<ORecordHook> hooks = iDatabase.getHooks().keySet();
            List<Class<? extends ORecordHook>> hooksToRegister = new ArrayList<Class<? extends ORecordHook>>(getOrientDbSettings().getORecordHooks());
            for (ORecordHook hook : hooks) {
                if (hooksToRegister.contains(hook.getClass()))
                    hooksToRegister.remove(hook.getClass());
            }
            for (Class<? extends ORecordHook> oRecordHookClass : hooksToRegister) {
                ORecordHook hook = createHook(oRecordHookClass, iDatabase);
                if (hook != null) {
                    if (hook instanceof IHookPosition) {
                        iDatabase.registerHook(hook, ((IHookPosition) hook).getPosition());
                    } else {
                        iDatabase.registerHook(hook);
                    }
                }
            }
        }

        @Override
        public void onClose(ODatabaseInternal iDatabase) {
        /*NOP*/
        }

        @Override
        public void onDrop(ODatabaseInternal iDatabase) {
        /*NOP*/
        }

        public PRIORITY getPriority() {
            return PRIORITY.REGULAR;
        }

        @Override
        public void onCreateClass(ODatabaseInternal iDatabase, OClass iClass) {
        /*NOP*/
        }

        @Override
        public void onDropClass(ODatabaseInternal iDatabase, OClass iClass) {
        /*NOP*/
        }

        @Override
        public void onLocalNodeConfigurationRequest(ODocument arg0) {
        /*NOP*/
        }
    });
    getRequestCycleListeners().add(newTransactionRequestCycleListener());
    getRequestCycleListeners().add(new OrientDefaultExceptionsHandlingListener());
    getSecuritySettings().setAuthorizationStrategy(new WicketOrientDbAuthorizationStrategy(this));
    getApplicationListeners().add(new IApplicationListener() {

        @Override
        public void onAfterInitialized(Application application) {
            Orient.instance().startup();
            Orient.instance().removeShutdownHook();
        }

        @Override
        public void onBeforeDestroyed(Application application) {
            Orient.instance().shutdown();
        }
    });
    getAjaxRequestTargetListeners().add(new FixFormEncTypeListener());
    // workaround to support changing system users passwords in web interface
    getOrientDbSettings().getORecordHooks().add(OUserCatchPasswordHook.class);
    PropertyResolver.setLocator(this, new ODocumentPropertyLocator(new PropertyResolver.CachingPropertyLocator(new PropertyResolver.DefaultPropertyLocator())));
}
Also used : Set(java.util.Set) ODocumentPropertyLocator(ru.ydn.wicket.wicketorientdb.utils.ODocumentPropertyLocator) IHookPosition(ru.ydn.wicket.wicketorientdb.components.IHookPosition) PropertyResolver(org.apache.wicket.core.util.lang.PropertyResolver) FixFormEncTypeListener(ru.ydn.wicket.wicketorientdb.utils.FixFormEncTypeListener) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) ArrayList(java.util.ArrayList) List(java.util.List) ODatabaseLifecycleListener(com.orientechnologies.orient.core.db.ODatabaseLifecycleListener) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) ORecordHook(com.orientechnologies.orient.core.hook.ORecordHook) InvocationTargetException(java.lang.reflect.InvocationTargetException) ODatabaseInternal(com.orientechnologies.orient.core.db.ODatabaseInternal) ODatabaseDocument(com.orientechnologies.orient.core.db.document.ODatabaseDocument) WicketOrientDbAuthorizationStrategy(ru.ydn.wicket.wicketorientdb.security.WicketOrientDbAuthorizationStrategy) IApplicationListener(org.apache.wicket.IApplicationListener) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) AuthenticatedWebApplication(org.apache.wicket.authroles.authentication.AuthenticatedWebApplication) Application(org.apache.wicket.Application) WebApplication(org.apache.wicket.protocol.http.WebApplication)

Example 10 with Application

use of org.apache.wicket.Application in project wicket by apache.

the class PackageTextTemplate method load.

/**
 * Loads the template if it is not loaded yet
 */
private void load() {
    if (buffer.length() == 0) {
        String path = Packages.absolutePath(scope, fileName);
        Application app = Application.get();
        // first try default class loading locator to find the resource
        IResourceStream stream = app.getResourceSettings().getResourceStreamLocator().locate(scope, path, getStyle(), getVariation(), getLocale(), null, false);
        if (stream == null) {
            // if the default locator didn't find the resource then fallback
            stream = new ResourceStreamLocator().locate(scope, path, getStyle(), getVariation(), getLocale(), null, false);
        }
        if (stream == null) {
            throw new IllegalArgumentException("resource " + fileName + " not found for scope " + scope + " (path = " + path + ")");
        }
        setLastModified(stream.lastModifiedTime());
        try {
            if (encoding != null) {
                buffer.append(Streams.readString(stream.getInputStream(), encoding));
            } else {
                buffer.append(Streams.readString(stream.getInputStream()));
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        } catch (ResourceStreamNotFoundException e) {
            throw new RuntimeException(e);
        } finally {
            try {
                stream.close();
            } catch (IOException e) {
                log.error(e.getMessage(), e);
            }
        }
    }
}
Also used : IResourceStream(org.apache.wicket.util.resource.IResourceStream) ResourceStreamLocator(org.apache.wicket.core.util.resource.locator.ResourceStreamLocator) IOException(java.io.IOException) ResourceStreamNotFoundException(org.apache.wicket.util.resource.ResourceStreamNotFoundException) Application(org.apache.wicket.Application)

Aggregations

Application (org.apache.wicket.Application)21 WicketRuntimeException (org.apache.wicket.WicketRuntimeException)5 WebApplication (org.apache.wicket.protocol.http.WebApplication)5 IOException (java.io.IOException)4 RequestCycle (org.apache.wicket.request.cycle.RequestCycle)4 MockApplication (org.apache.wicket.mock.MockApplication)3 MockHttpServletRequest (org.apache.wicket.protocol.http.mock.MockHttpServletRequest)3 FilterChain (javax.servlet.FilterChain)2 ServletException (javax.servlet.ServletException)2 ServletRequest (javax.servlet.ServletRequest)2 ServletResponse (javax.servlet.ServletResponse)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 HttpSession (javax.servlet.http.HttpSession)2 IApplication (org.apache.openmeetings.IApplication)2 Page (org.apache.wicket.Page)2 WebSocketSettings (org.apache.wicket.protocol.ws.WebSocketSettings)2 IKey (org.apache.wicket.protocol.ws.api.registry.IKey)2 IRequestHandler (org.apache.wicket.request.IRequestHandler)2 WebResponse (org.apache.wicket.request.http.WebResponse)2