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);
}
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);
}
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();
}
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())));
}
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);
}
}
}
}
Aggregations