I have service that handles a response from an external validation server, and I need to get this response and pass it to my java class. Is that possible? How can I achieve that?
I need my request object from javascript to be converted to a HttpRequest object in java.
You can access the current request from Java code using PortalRequestAccessor:
package foo;
import com.enonic.xp.portal.PortalRequestAccessor;
public class MyClass {
public void doSomething() {
HttpServletRequest request = PortalRequestAccessor.get().getRawRequest();
// do something with request
}
}
For this to work you have to call your Java class from the controller receiving the request, as you would call Java code in a library.
exports.get = function (req) {
var bean = __.newBean('foo.MyClass');
bean.doSomething();
}
That will not work within a controller request. The Java code in that class is using the HttpServletResponse to redirect, it cannot work within the context of a XP request.
It’s probably easier to just implement it in Java.