use of com.enonic.xp.portal.PortalRequest in project xp by enonic.
the class LocalizeFunctionTest method not_in_request_context.
@Test
public void not_in_request_context() {
final PortalRequest savedPortalRequest = PortalRequestAccessor.get();
PortalRequestAccessor.set(null);
try {
Mockito.when(localeService.getBundle(Mockito.eq(ApplicationKey.from("com.enonic.myapp")), Mockito.eq(new Locale("en", "US")))).thenReturn(messageBundle);
Mockito.when(messageBundle.localize(Mockito.eq("myPhrase"), ArgumentMatchers.<String>any())).thenReturn("localizedString");
final Object result = execute("i18n.localize", "_key=myPhrase", "_locale=en-US ", "_application=com.enonic.myapp", "a=5", "b=2");
assertEquals("localizedString", result);
} finally {
PortalRequestAccessor.set(savedPortalRequest);
}
}
use of com.enonic.xp.portal.PortalRequest in project xp by enonic.
the class LocalizeParamsTest method setUp.
@BeforeEach
public void setUp() throws Exception {
request = new PortalRequest();
request.setSite(Site.create().name(ContentName.from("test")).parentPath(ContentPath.ROOT).language(DEFAULT_LOCALE).build());
PortalRequestAccessor.set(request);
}
use of com.enonic.xp.portal.PortalRequest in project xp by enonic.
the class MultipartHandler method initialize.
@Override
public void initialize(final BeanContext context) {
final PortalRequest request = context.getBinding(PortalRequest.class).get();
final MultipartService service = context.getService(MultipartService.class).get();
this.form = service.parse(request.getRawRequest());
}
use of com.enonic.xp.portal.PortalRequest in project xp by enonic.
the class FilterNextFunctionWrapper method apply.
@Override
public Object apply(final Object scriptRequestObject) {
if (functionWasCalled) {
throw scriptError("Filter 'next' function was called multiple times", null);
}
functionWasCalled = true;
ScriptValue scriptRequestParam = scriptService.toScriptValue(this.script, scriptRequestObject);
try {
final PortalRequest portalRequest = new PortalRequestSerializer(request, scriptRequestParam).serialize();
final WebResponse newResponse = webHandlerChain.handle(portalRequest, response);
final PortalResponseMapper response = new PortalResponseMapper((PortalResponse) newResponse);
return scriptService.toNativeObject(this.script, response);
} catch (ResourceProblemException | WebException e) {
throw e;
} catch (Exception e) {
throw scriptError("Error executing filter script: " + script, e);
}
}
use of com.enonic.xp.portal.PortalRequest in project xp by enonic.
the class ServiceHandler method doHandle.
@Override
protected PortalResponse doHandle(final WebRequest webRequest, final WebResponse webResponse, final WebHandlerChain webHandlerChain) throws Exception {
final String restPath = findRestPath(webRequest);
final Matcher matcher = PATTERN.matcher(restPath);
if (!matcher.find()) {
throw WebException.notFound("Not a valid service url pattern");
}
final PortalRequest portalRequest = webRequest instanceof PortalRequest ? (PortalRequest) webRequest : new PortalRequest(webRequest);
portalRequest.setContextPath(findPreRestPath(portalRequest) + "/" + matcher.group(0));
final ServiceHandlerWorker worker = new ServiceHandlerWorker(portalRequest);
worker.applicationKey = ApplicationKey.from(matcher.group(1));
worker.name = matcher.group(2);
worker.contentResolver = new ContentResolver(this.contentService);
worker.resourceService = this.resourceService;
worker.serviceDescriptorService = this.serviceDescriptorService;
worker.controllerScriptFactory = this.controllerScriptFactory;
return worker.execute();
}
Aggregations