Send additional attribute to remote portlet consuming with wsrp in liferay - liferay

When consuming a remote portlet with wsrp, it is possible to send additional attributes and have access to them in the remote portlet? When setting a custom attribute to the current request object in liferay this attribute isn't accessible in the remote portlet, because it's a totally different session. Is there any best practice to solve this? Or isn't this a use case when consuming remote portlets with wsrp?

Related

How to listen on a stateless POST request and set JSF managed bean properties

I have a Java-EE application that works with JSF (ManagedBean, ManagedProperty, ect ...) and Spring framework. I need to be able to retrieve data via a javascript form sent from an external website. I have opened the rights to authorize the CORS (Cross Origin or Cross Domain).
I would like to know what is the best way to grab an external form with JSF so that it is processed by my ManagedBean.
To make my question more explicit I made a diagram
==============
EDIT
The application works with JSF, I'm looking for a way to retrieve data (from a Javascript form on an external site) in a ManagedBean under JSF. I tried to retrieve this data by creating a Java-EE standard servlet and using the doPost ... methods of HttpServlet. But this solution does not work (this was the subject of my previous question on S.O). Several people told me that in a web application do not mix Java-EE standard and JSF, it is either Servlet or JSF. I made a diagram (above) explaining quickly what I am trying to do.
To recap: I would like to retrieve data from an external website (via a Javascript form) in the ManagedBean of my application.
==============
I've already tried with a standard Java-EE servlet but it's not the right way. Indeed, with a standard servlet I can recover the data from the form but I can not access the ManagedBean. I must therefore have abandoned this hypothesis.
I did not find a similar question about Stackoverflow, If necessary I can give more indications.
Thank you for your help.

Reading property file data from a servlet

I am working on a web application, in which I am reading some configuration data stored in xml file from a Servlet. I want the data read from this servlet available to all the requests coming to this servlet. So inside the init() method of this servlet I am initializing global variable , which will have content read from this xml file so that all the request coming to this servlet will have this data available and don't have to read from the xml file again and again.
My first question is, is this method is better way to share data among request coming only to this servlet. I don't want to share it across all the servlets.
The rule here is just locality: if that data is only used by one single servlet, it should be local to the servlet, meaning as per you proposal:
a member of the servlet class
loaded in the init method of the servlet
But (as your initial post asked), if that data can be updated by another servlet of the same web application, it make sense to move it one step up to a SerletContext attribute. That way:
it can still be initially loaded in the init method of the servlet
it can be changed at any time by any other component of the web application that knows the name of the attribute.
You can imagine plenty of other ways, by using for example custom events and using an observable pattern, or by mapping the servlet to a special (and private) URL that would signal that the xml file must be reloaded, but IMHO, a servlet context attribute is a clean and simple way to allow different servlet to exchange informations.
But beware, you will still need an extra synchronization mechanisme if your web application is intended to be served by more than one single server

How can I get Liferay user ID from a external servlet

I have a problem. I want to get Liferay user ID in a servlet that runs in another Tomcat, not in Tomcat on which Liferay runs. If both runs in same Tomcat, no problem, Liferay API works perfectly. But in this case, when I use 'UserLocalServiceUtil.decryptUserId' in order to decrypt user ID present in cookie, I get a 'BeanLocator is null' exception.
What can I do? Has this any solution?
You can consume Liferay's web services to get User details from Liferay from your servlet. You can choose from SOAP WebServices or JSON WebServices.
My recommendation in you scenario is to use JSON WebService - get-user-by-email-address method (like this: http://<host>:<port>/api/jsonws?signature=/user/get-user-by-email-address-2-companyId-emailAddress) to get User object, and get UserId from it.

Injecting blueprint OSGi service into JSF/PrimeFaces bean

I have a project built on top OSGi and Karaf server. For dependency injection we are using Aries Blueprint.
The main part of the project is a Apache Camel routes and integration things, but now I need to create some maintenance web interface.
So I give a try to JSF - PrimeFaces implementation. I was able to create some demo, which works in OSGi under Karaf, that's ok.
Now I'd like to know if it's possible to use Blueprint here, to reference some already existing OSGi services we have and inject the service into JSF Bean, so we can benefit from already written code.
Can you help me, please?
We solved this in the following way:
We created a listener that:
Creates a ServiceTracker that tracks the BlueprintContainer service attached to the same bundle
Puts the servicetracker into the ServletContext attributes
We created an ELResolver that uses this ServiceTracker and if there is a BlueprintContainer available it uses the getComponentInstance of that to get the value
The listener opens the servicetracer during application initialization and closes it during application destroy
Our listener class: https://source.everit.biz/svn/everit-util/trunk/core/src/main/java/org/everit/util/core/servlet/ServiceLoaderListener.java
Our EL resolver class: https://source.everit.biz/svn/everit-util/trunk/core/src/main/java/org/everit/util/core/el/OsgiELResolver.java
User/pass: guest/guest
After you registered your custom el-resolver all el-expressions will be evaluated in the way that id-s of component instances will be searched inside the blueprint container. In case you say that you have a bean-property in your faces-config.xml with the value #{myComponent} it will be searched inside the BlueprintContainer.

Run a method of setup of liferay portal

I have a hook where to add an organization and few custom field variables (Expando Variables) automatically to a liferay portal. How do I run that hook or a method in the hook during liferay setup or the first time I start a liferay portal? Does anyone have any links or codes for this?
Thanks
To reiterate your requirement you need to do some custom actions when Liferay server is started, so from what I understand you need a startup custom action hook.
This is nothing but a simple hook where you would override some porperties from portal.properties and provide a custom action class like MyCustomStartupAction or MyCustomGlobalAction in that property and implement it.
In the user-guide here is a list of some properties you can configure: Startup Events
This SO Answer gives more information about creating a hook with such properties.
When you deploy that Hook (war file) into your server and restart it, in the (bin) logs, you could see one log statement which says that your particular Hook is available for use. This means your Hook has been successfully deployed into your Liferay portal.
To run the Hook or invoke a particular method inside your Hook, you need to invoke the flow for which your Hook was written.
For eg., if you have written a hook for logout.events.post= and if you want to invoke this, then you need to logout from your portal.
In your case you have written a Hook for registration. So, you need to do registration. Remember your Hook method should have extended Action class.

Resources