Posts

Showing posts with the label osgi

Liferay Blacklist Configuration

Image
 How to Remove a Bundle from the Blacklist in Liferay 7 Overview This article will explain how to remove a bundle from the Liferay’s Blacklist with the settings in the Control Panel. Preface Liferay may add your bundle into a “black list” if you, for example, uninstall your bundle in the Apps Manager: In this case any subsequent deploys will not actually deploy your bundle, and you’ll see something like this in logs: 2021-03-23 07:49:58.854 INFO  [com.liferay.portal.kernel.deploy.auto.AutoDeployScanner][AutoDeployDir:261] Processing journal.edit.article.hook-1.0.2.jar 2021-03-23 07:51:09.765 INFO  [fileinstall-/opt/liferay/osgi/modules][BundleBlacklist:188] Stopping blacklisted bundle journal.edit.article.hook_1.0.2  To make your bundle available again - you need to remove it from the blacklist. Configuration To remove the bundle from the blacklist, you need: Go to Control Panel -> Configuration -> System Settings; Click on “Module Container” in “Platform” sect...

HttpClient and Liferay 7 OSGi modules

 HttpClient and Liferay 7 OSGi modules Overview Apache HttpClient is a popular library, which simplifies interaction with remote HTTP server or API. But, as with any third-party library, it’s tricky to make it work inside Liferay’s OSGi world. This article explains how to do it. Configuration build.gradle: compileOnly group : "org.apache.httpcomponents" , name : "httpclient" , version : "4.5.11" compileOnly group : "org.apache.httpcomponents" , name : "httpcore" , version : "4.4.13" bnd.bnd: Bundle-Name : LifeDev HttpClient Sample Bundle-SymbolicName : com.lifedev.httpclient.sample Bundle-Version : 1.0.0 Export-Package : com.lifedev.httpclient.sample.constants -includeresource : \   lib/httpclient.jar=httpclient-4.5.11.jar;lib :=true,\   lib/httpcore.jar=httpcore-4.4.13.jar;lib :=true,\    lib/commons-codec.jar=commons-codec-1.13.jar;lib:=true Note: “-includeresource” part is important here. Otherwise, you may get errors like:...

Configurable Scheduled Task (Cronjob) in Liferay DXP

Configurable Scheduled Task  Overview This article will explain and give you an example of configurable scheduled task. It may be enabled or disabled on-the-fly, cronjob expression for the task may be also changed dynamically. Example This is an example of scheduled task, which uses custom OSGi configuration: ______________________________________________________________________________ import com.liferay.portal.kernel.log.Log; import com.liferay.portal.kernel.log.LogFactoryUtil; import com.liferay.portal.kernel.messaging.BaseMessageListener; import com.liferay.portal.kernel.messaging.DestinationNames; import com.liferay.portal.kernel.messaging.Message; import com.liferay.portal.kernel.scheduler.*; import org.osgi.service.component.annotations.*; import java.util.Date; import java.util.Map; @Component( configurationPid = MyConfigurationKeys.MY_CONFIGURATION_ID, //todo 1: - set configuration ID immediate = true, property = { }, ...

Override OSGi Component Properties

Image
Override OSGi Component Properties Overview You may need to change some properties for Liferay's OSGi  @Component  in order to customize the built-in behavior, but you don't want to override the whole component. Fortunately, there is an easy way to achieve this. This article will explain how to do this. Sample scenario Let's say, you want to add the "Notifications" portlet to a user profile page. But when you try do this - you can't find this portlet among the available ones: When you check the sources - you'll find out, that "Notifications" portlet is hidden: Obviously, you just need to change the display category. But this is the internal Lifeay code, which you can't just modify. Fortunately, all those properties are easy customizable. Here are the required steps: Create a  [Component-Classname].config  class in  [Liferay]/osgi/configs  folder; Add properties you need to override inside the created file; Restart Lifer...

Resolving "internal" dependencies

Image
Resolving "internal" dependencies in your OSGi modules Overview Sometimes you may need to reference some class from "internal" package of Liferay's OSGi bundle. But classes under "internal" package are not exposed by Liferay bundles, and thus, can't be used by default. You can include dependency on that module, for example: compileOnly group: "com.liferay", name: "com.liferay.asset.publisher.web", version: "3.0.43" and you'll be able to compile/assemble/deploy your OSGi JAR, but you'll get a runtime error during deployment, like: org.osgi.framework.BundleException: Could not resolve module: com.lifedev.asset.publisher.portlet.filter [1105]_ Unresolved requirement: Import-Package: com.liferay.asset.publisher.web.internal.util _ [Sanitized] at org.eclipse.osgi.container.Module.start(Module.java:444) at org.eclipse.osgi.internal.framework.EquinoxBundle.start(EquinoxBundle.java:428) saying that pa...

Fix Gradle workspace for OSGi configuration modules

If you are using Gradle workspace for Liferay 7.2 and developing a module with OSGi configuration, for example: @ExtendedObjectClassDefinition ( category = ConfigurationKeys. CATEGORY_KEY , scope = ExtendedObjectClassDefinition .Scope. COMPANY ) @Meta.OCD ( id = ConfigurationKeys. REST_CONFIGURATION , localization = "content/Language" , name = "rest-configuration" ) public interface RestConfiguration {     @Meta.AD ( deflt = "https://lifedev.com/api/v1" , name = "rest-endpoint" )     public String restEndpoint();     @Meta.AD ( deflt = "0 * * ? * *" , name = "cronjob-expression" )     public String cronjobExpression(); } , you may notice that your configuration does not appear in Control Panel, even if code/configuration seems to be correct. The issue may be related to gradle plugins workspace version. Check "com.liferay.gradle.plugins.workspace" property in settin gs. gradle file....