use of com.enonic.xp.app.ApplicationKey in project xp by enonic.
the class ServiceHandlerWorker method execute.
@Override
public PortalResponse execute() throws Exception {
// Retrieves the ServiceDescriptor
final DescriptorKey descriptorKey = DescriptorKey.from(applicationKey, name);
final ServiceDescriptor serviceDescriptor = serviceDescriptorService.getByKey(descriptorKey);
if (serviceDescriptor == null) {
throw WebException.notFound(String.format("Service [%s] not found", descriptorKey));
}
// Checks if the access to ServiceDescriptor is allowed
final PrincipalKeys principals = ContextAccessor.current().getAuthInfo().getPrincipals();
if (!serviceDescriptor.isAccessAllowed(principals)) {
throw WebException.forbidden(String.format("You don't have permission to access [%s]", descriptorKey));
}
final ContentResolverResult resolvedContent = contentResolver.resolve(request);
final Site site = resolvedContent.getNearestSite();
// Checks if the application is set on the current site
if (site != null) {
final PropertyTree siteConfig = site.getSiteConfig(applicationKey);
if (siteConfig == null) {
throw WebException.forbidden(String.format("Service [%s] forbidden for this site", descriptorKey));
}
}
// Checks if the application is set on the current application
final ApplicationKey baseApplicationKey = getBaseApplicationKey();
if (baseApplicationKey != null && !baseApplicationKey.equals(applicationKey)) {
throw WebException.forbidden(String.format("Service [%s] forbidden for this application", descriptorKey));
}
// Prepares the request
this.request.setApplicationKey(applicationKey);
this.request.setContent(resolvedContent.getContent());
this.request.setSite(site);
// Executes the service
final ControllerScript controllerScript = getScript();
final PortalResponse portalResponse = controllerScript.execute(this.request);
final WebSocketConfig webSocketConfig = portalResponse.getWebSocket();
final WebSocketContext webSocketContext = this.request.getWebSocketContext();
if ((webSocketContext != null) && (webSocketConfig != null)) {
final WebSocketEndpoint webSocketEndpoint = newWebSocketEndpoint(webSocketConfig);
webSocketContext.apply(webSocketEndpoint);
}
return portalResponse;
}
use of com.enonic.xp.app.ApplicationKey in project xp by enonic.
the class MacroInstruction method evaluate.
@Override
public PortalResponse evaluate(final PortalRequest portalRequest, final String instruction) {
if (!Instruction.isInstruction(instruction, "MACRO")) {
return null;
}
// parse instruction
final Instruction macroInstruction;
try {
macroInstruction = new InstructionParser().parse(instruction);
} catch (RenderException e) {
return null;
}
final String macroName = macroInstruction.attribute(MACRO_NAME);
if (macroName == null) {
return null;
}
// resolve macro processor
final Site site = portalRequest.getSite();
if (site == null) {
throw new RenderException("Macro controller script could not be resolved, context site could not be found.");
}
final MacroDescriptor macroDescriptor = resolveMacroDescriptor(site.getSiteConfigs(), macroName);
if (macroDescriptor == null) {
final String editModeMacro = toMacroInstruction(macroInstruction);
return PortalResponse.create().body(editModeMacro).build();
}
final MacroProcessor macroProcessor = resolveMacroProcessor(macroDescriptor);
if (macroProcessor == null) {
throw new RenderException("Macro controller not found: " + macroName);
}
// execute macro
final MacroContext context = createContext(macroInstruction, macroDescriptor, portalRequest);
final ApplicationKey previousAppKey = portalRequest.getApplicationKey();
try {
portalRequest.setApplicationKey(macroDescriptor.getKey().getApplicationKey());
return macroProcessor.process(context);
} finally {
portalRequest.setApplicationKey(previousAppKey);
}
}
use of com.enonic.xp.app.ApplicationKey in project xp by enonic.
the class ApplicationServiceImpl method doInstallLocalApplication.
private Application doInstallLocalApplication(final ByteSource byteSource) {
final ApplicationKey applicationKey = getApplicationKey(byteSource);
final Application application = installOrUpdateApplication(byteSource, applicationKey, true, false);
LOG.info("Local application [{}] installed successfully", applicationKey);
doStartApplication(applicationKey, false, false);
return application;
}
use of com.enonic.xp.app.ApplicationKey in project xp by enonic.
the class ApplicationServiceImplTest method configuration_comes_last.
@Test
public void configuration_comes_last() throws Exception {
final ApplicationKey key = ApplicationKey.from("myapp");
final Bundle bundle = deployAppBundle("myapp");
applicationRegistry.installApplication(bundle);
final Application app = service.getInstalledApplication(key);
applicationRegistry.configureApplication(bundle, ConfigBuilder.create().add("a", "b").build());
assertEquals(ConfigBuilder.create().add("a", "b").build(), app.getConfig());
}
use of com.enonic.xp.app.ApplicationKey in project xp by enonic.
the class ApplicationServiceImplTest method stop_application.
@Test
public void stop_application() throws Exception {
final Bundle bundle = deployAppBundle("app1");
applicationRegistry.installApplication(bundle);
bundle.start();
assertEquals(Bundle.ACTIVE, bundle.getState());
final ApplicationKey applicationKey = ApplicationKey.from("app1");
this.service.stopApplication(applicationKey, true);
assertEquals(Bundle.RESOLVED, bundle.getState());
verify(this.eventPublisher, times(1)).publish(Mockito.argThat(new ApplicationEventMatcher(ApplicationClusterEvents.stop(applicationKey))));
verify(this.eventPublisher, times(1)).publish(Mockito.argThat(new ApplicationEventMatcher(ApplicationClusterEvents.stopped(applicationKey))));
}
Aggregations