Joomla - How to install custom logger class - class

To meet my needs, I have created a custom logger class which extends JLogLoggerFormattedtext.
The file is located in the /libraries/joomla/log/logger directory.
This way I can use it like any other logger class and it works fine :
JLog::addLogger(
array(
'logger' => 'formattedtextsmt',
'text_file' => 'my_comp_site.log.php',
),
[..]
);
But now, I d'like to make it part either from a component I developed or a dedicated library so that it can be installed properly from the admin UI.
How can I do to make my logger class available for addLogger when it is not located in the joomla/log/logger directory ?

Related

How can I load a vendor class as a Service in Symfony 4?

I'm using the jwt firebase class in a project, it's path in vendor is:
vendor\firebase\php-jwt\src\jwt
I'm trying to define the class as a service to be able to inject in another class, but I'm not able to do it.
I'm to do this in the service.yml file:
#services.yaml
services:
Firebase:
class: '../vendor\firebase\php-jwt\JWT'
An this is the class I have created:
<?php
namespace App\Helpers;
use Firebase\JWT\JWT;
use Symfony\Component\HttpKernel\KernelInterface;
class simpleJwt
{
private $encrypt = 'RS256';
function __construct(KernelInterface $kernel, JWT $JWT )
{
$this->rootDir = $kernel->getProjectDir();
$this->jwt = $JWT;
}
}
When I try to load it I get this error:
Cannot autowire service "App\Helpers\simpleJwt": argument "$JWT" of method "__construct()" references class "Firebase\JWT\JWT" but no such service exists.
Thanks
Just add full namespace in config.yaml
services:
Firebase\JWT\JWT:
You can also provide to your service constructor requirements, using arguments:
services:
Namespace\Domain\ServiceName:
arguments:
- '#Another\Namespace\Class'
- '#service.name'
- '%parameter%'
More details and features in the official documentation :
Service Container (Symfony Docs)
Note you'll access your service through AutoWiring and that you won't access to it directly through the container, cause service public argument is set to false by default (public: true is not recommended according to Symfony documentation).
Try adding ‘autowire: true’ in your services.yaml, right under ‘class: ../vendor\firebase\php-jwt\JWT’
It could be that the bundle you are trying to import might not be compatible with Symfony’s autowire. Be sure to use the latest version of the bundle (newer versions might be compatible). In case you’re already using the lastest version, you might need to create an alias for that bundle in your services.yaml so you can use it later on your classes. You can use bin/console debug:container to check what services are available and manually create an alias for the service you need. It happens that autowire is commonly turned off in most of the vendor bundles.

Osgi REST API service using ECF and bndtools is not accessible

I'm currently trying to expose restful webservice using OSGI remote services, but it seems that i'm missing something from ECF tutorial.
below the details here is the impl class:
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import org.example.api.HelloWorldService;
import org.osgi.service.component.annotations.Component;
#Path("/helloworld")
#Component(property = { "service.exported.interfaces=HTTP",
"service.exported.configs=ecf.jaxrs.jersey.server",
"ecf.jaxrs.jersey.server.alias=/jersey" })
public class HelloWorldResource implements HelloWorldService {
#GET
#Produces("text/plain")
public String getMessage() {
// Return some textual content
return "Hello World";
}}
I followed this link to know how things can be together but i wasn't able to get HTTP 200 ok message based on the jax-rs path annotation
https://wiki.eclipse.org/Tutorial:_Using_REST_and_OSGi_Standards_for_Micro_Services
Please note that all bundle are resolved correctly.
I've created a bndtools4 bndrun for something like your hello jaxrs service. First, you need to create a new workspace using the ECF bndtools.workspace template. Just follow the instructions here:
https://wiki.eclipse.org/Bndtools_Support_for_Remote_Services_Development
for creating a workspace from the ECF bndtools.workspace template. Just today I've added the JaxRS bundles to this workspace template.
Then I created an org.example.api project with this interface
package org.example.api;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
#Path("/helloworld")
public interface HelloWorldService {
#GET
#Path("/hello")
#Produces("text/plain")
String getMessage();
}
Note that it differs slightly from yours because it has a #PATH annotation for the getMessage() method.
Then in another project...named org.example.impl there is this class:
package org.example.impl;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import org.example.api.HelloWorldService;
import org.osgi.service.component.annotations.Component;
#Path("/helloworld")
#Component(property = { "service.exported.interfaces=*",
"service.intents=jaxrs" })
public class HelloWorldResource implements HelloWorldService {
#GET
#Path("/hello")
#Produces("text/plain")
public String getMessage() {
// Return some textual content
return "Hello World";
}}
The jaxrs annotations are the same as with the interface (as they should be). There are fewer
And here's the bndrun (which I've called jettyserver.bndrun):
-runrequires: \
bnd.identity;id='org.eclipse.ecf.provider.jersey.server',\
osgi.identity;filter:='(&(osgi.identity=javax.validation.api)(version>=1.1.0))',\
osgi.identity;filter:='(&(osgi.identity=org.apache.felix.gogo.command)(version>=1.0.2))',\
osgi.identity;filter:='(&(osgi.identity=org.apache.felix.gogo.runtime)(version>=1.0.10))',\
osgi.identity;filter:='(&(osgi.identity=org.slf4j.api)(version>=1.7.2))',\
bnd.identity;version='latest';id='org.example.impl',\
bnd.identity;id='org.apache.felix.gogo.command',\
bnd.identity;id='org.apache.felix.gogo.runtime',\
bnd.identity;id='org.apache.felix.gogo.shell',\
bnd.identity;id='org.eclipse.ecf.osgi.services.remoteserviceadmin.console',\
bnd.identity;id='org.apache.felix.scr',\
bnd.identity;id='org.eclipse.ecf.osgi.services.distribution',\
bnd.identity;id='org.eclipse.ecf.provider.jersey.client'
-runfw: org.apache.felix.framework;version='[5.6.10,5.6.10]'
-runee: JavaSE-1.8
-runbundles: \
com.fasterxml.jackson.core.jackson-annotations;version='[2.9.2,2.9.3)',\
com.fasterxml.jackson.core.jackson-core;version='[2.9.2,2.9.3)',\
com.fasterxml.jackson.core.jackson-databind;version='[2.9.2,2.9.3)',\
com.fasterxml.jackson.jaxrs.jackson-jaxrs-base;version='[2.9.2,2.9.3)',\
com.fasterxml.jackson.jaxrs.jackson-jaxrs-json-provider;version='[2.9.2,2.9.3)',\
javax.annotation;version='[1.2.0,1.2.1)',\
javax.inject;version='[1.0.0,1.0.1)',\
javax.persistence;version='[2.2.0,2.2.1)',\
javax.validation.api;version='[1.1.0,1.1.1)',\
javax.ws.rs;version='[2.0.1,2.0.2)',\
org.aopalliance;version='[1.0.0,1.0.1)',\
org.apache.felix.configadmin;version='[1.8.16,1.8.17)',\
org.apache.felix.eventadmin;version='[1.4.10,1.4.11)',\
org.apache.felix.gogo.command;version='[1.0.2,1.0.3)',\
org.apache.felix.gogo.runtime;version='[1.0.10,1.0.11)',\
org.apache.felix.http.jetty;version='[3.4.8,3.4.9)',\
org.apache.felix.http.servlet-api;version='[1.1.2,1.1.3)',\
org.apache.felix.scr;version='[2.0.14,2.0.15)',\
org.eclipse.core.jobs;version='[3.9.3,3.9.4)',\
org.eclipse.ecf;version='[3.9.0,3.9.1)',\
org.eclipse.ecf.discovery;version='[5.0.300,5.0.301)',\
org.eclipse.ecf.identity;version='[3.9.0,3.9.1)',\
org.eclipse.ecf.osgi.services.remoteserviceadmin;version='[4.6.800,4.6.801)',\
org.eclipse.ecf.osgi.services.remoteserviceadmin.proxy;version='[1.0.100,1.0.101)',\
org.eclipse.ecf.provider.jaxrs;version='[1.3.0,1.3.1)',\
org.eclipse.ecf.provider.jaxrs.server;version='[1.4.0,1.4.1)',\
org.eclipse.ecf.provider.jersey.server;version='[1.3.0,1.3.1)',\
org.eclipse.ecf.remoteservice;version='[8.13.0,8.13.1)',\
org.eclipse.ecf.remoteservice.asyncproxy;version='[2.1.0,2.1.1)',\
org.eclipse.equinox.common;version='[3.9.0,3.9.1)',\
org.eclipse.equinox.concurrent;version='[1.1.0,1.1.1)',\
org.eclipse.equinox.supplement;version='[1.7.0,1.7.1)',\
org.eclipse.osgi.services.remoteserviceadmin;version='[1.6.200,1.6.201)',\
org.glassfish.hk2.api;version='[2.5.0,2.5.1)',\
org.glassfish.hk2.osgi-resource-locator;version='[2.5.0,2.5.1)',\
org.glassfish.hk2.utils;version='[2.5.0,2.5.1)',\
org.glassfish.jersey.bundles.repackaged.jersey-guava;version='[2.22.1,2.22.2)',\
org.glassfish.jersey.containers.servlet.core;version='[2.22.1,2.22.2)',\
org.glassfish.jersey.core.jersey-common;version='[2.22.1,2.22.2)',\
org.glassfish.jersey.core.jersey-server;version='[2.22.1,2.22.2)',\
org.glassfish.jersey.ext.entityfiltering;version='[2.22.1,2.22.2)',\
org.glassfish.jersey.media.jersey-media-json-jackson;version='[2.22.1,2.22.2)',\
org.slf4j.api;version='[1.7.2,1.7.3)',\
org.example.api;version=snapshot,\
org.example.impl;version=snapshot,\
org.apache.felix.gogo.shell;version='[1.0.0,1.0.1)',\
org.eclipse.ecf.console;version='[1.1.0,1.1.1)',\
org.eclipse.ecf.osgi.services.remoteserviceadmin.console;version='[1.0.0,1.0.1)',\
org.eclipse.ecf.osgi.services.distribution;version='[2.1.200,2.1.201)',\
javassist;version='[3.13.0,3.13.1)',\
org.eclipse.ecf.provider.jaxrs.client;version='[1.3.0,1.3.1)',\
org.eclipse.ecf.provider.jersey.client;version='[1.3.0,1.3.1)',\
org.glassfish.hk2.locator;version='[2.5.0,2.5.1)',\
org.glassfish.jersey.core.jersey-client;version='[2.22.1,2.22.2)'
With your permission, I would like to add bndtools project templates for both jaxrs hello api and impl projects to the ECF bndtools.workspace repo, along with a jersey and cxf bndrun server and client templates (once I complete them). I'll create the bndruns and test over the next few days.
The exported interfaces property should not be "HTTP". Instead it must be an interface fqname or Star. So try this:
"service.exported.interfaces=*"
If you are not using already, please update to ECF 3.14.0. Further, after 3.14.0/Photon (last few weeks) there have been significant changes to the JaxRS providers to support OSGi R7 Async Remote Services so please make sure you have the latest from JaxRSProviders as well. The required remote service properties have changed based upon the R7 changes. Please see the service properties of the hello examples and this short tutorial for running the hello example on Karaf:
https://wiki.eclipse.org/Tutorial:_JaxRS_Remote_Services_on_Karaf
In short, it's no longer necessary to specify ecf.jaxrs.jersey.server.alias but there are other (newly standardize) properties to set.
I would like to create a bndtools4 JaxRS run descriptor template, and I think this would make it significantly easier for you. I suspect your problem might be that do not have all necessary jersey bundles, as jersey has quite a number of dependencies...all of which have to be present to successfully export a remote service. For ref, here's the setup info for using the project and bndrun templates that are currently there:
https://wiki.eclipse.org/Bndtools_Support_for_Remote_Services_Development
I will create a bndtools4 bndrun template for the CXF and Jersey distribution providers, but have not had enough time since the JaxRSProvider changes. If you would like to express your desire for bndrun template and/or help with contributions, please open an issue at https://github.com/ECF/JaxRSProviders/issues and that will help track.
In the mean time, the examples list of bundles is in the product files here:
https://github.com/ECF/JaxRSProviders/tree/master/examples/com.mycorp.examples.student.remoteservice.host/launch
For info:
I've added project templates for JaxRS API, Impl, Consumer projects (based upon the HelloWorldService) and I've added bndrun templates for Jersey server and client, as well as CXF server and client.
See https://github.com/ECF/JaxRSProviders/issues/6

Importing domain classes from GORM-standalone module into Grails

I have 2 pieces of my puzzle:
1) a no-Grails project named core-module with standalone GORM:
dependencies {
compile 'org.grails:grails-datastore-gorm-mongodb:6.0.4.RELEASE'
compile 'org.grails:grails-validation:3.2.3'
}
and domain classes like:
import grails.gorm.annotation.Entity
#Entity
class Module {
String id
String tags
}
the GORM-ing is initialized by
Map config = new Yaml().load this.class.getResource( '/application.yml' ).text
new MongoDatastore( config, Module, UserAccount )
and the domain classes are working as they would in a Grails app.
2) a Grails 3.2.3 app:
dependencies {
// default grails dependencies
compile project( ':core-module' )
compile 'org.grails.plugins:mongodb:6.0.4'
compile 'org.grails.plugins:spring-security-core:3.1.1'
// etc
}
the GORM is initialized so:
def config = config.grails.mongodb
log.info "using $config"
new MongoDatastore( config, Module, UserAccount )
and it prints out this into the log file:
g.app.init.com.mozaiq.Application - using [host:localhost, port:27017, databaseName:theDB, username:theUN, pooled:true, mongoOptions:[connectionsPerHost:100, autoConnectRetry:true, connectTimeout:3000]]
The problem is, that the property grailsApplication.domainClasses is empty, and even though the Module.collection is not-null, the Module.count() return 0 despite the collection being not empty.
Also in my mongo-client I see that upon app start a new database test is created with an empty collection, named by one of my domain classes. If I insert some documents into it, the .count() returns 0 and the CRUD list remains empty.
Grails only scans packages in the application by default for performance reasons. Override limitScanningToApplication() to return false in your Application class and define the packages you wish to scan by overriding packageNames() in your Application class.
Grails will then automatically discover the Mongo GORM classes

Yii2 Module setup in advanced template

I have created a module in frontend folder path is frontend/modules/module-name/Module.php. I am getting ReflectionException error as Class app\modules\module-name\Module does not exist. In frontend/config/main.php i have added this configuration
'modules' => [
'module-name' => [
'class' => 'app\modules\module-name\Module'
]
Can anyone help why i am getting this ReflectionException error
You said that you are using an advanced template, folder path is frontend/modules/module-name/Module.php, but you are requiring app\modules\module-name\Module class. It looks like a namespace from basic application template.
In case of advanced template, make sure that Module.php file is in frontend/modules/module-name folder, has a namespace frontend\modules\module-name and you are requiring frontend\modules\module-name\Module class.

Determine web app path

I am using Spring Tool Suite (really eclipse). I just created a new springMVC project and created a simple controller. There was a problem with how STS created the project so I had to manually fix the groupID and artifactID in the pom. The problem I am currently having is I can't seem to hit my tomcat server (published and launched by STS). I have checked the directory structure in tomcat where it gets published and everything seems to be fine but I get 404's when I try and hit the controller. The tomcat logs look as if nothing has even tried to connect to it. They also show that my controller has been mapped:
2013-10-14 09:09:17.763] INFO o.s.w.s.m.m.a.RequestMappingHandlerMapping - Mapped "{[/Login],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.String com.verisk.underwriting.ims.web.IMSController.test()
This is what my controller looks like:
#Controller
#RequestMapping("Login")
public class IMSController
{
#RequestMapping(value = "", method = RequestMethod.GET)
#ResponseBody
public String test()
{
return "SUCCESS";
}
}
The app is called ims, so I should be able to hit this controller with this request:
http://localhost/ims/Login
It is configured with a java config (AppConfig.java):
#Configuration
#EnableWebMvc
#ComponentScan(basePackages = "com.some.package.ims.web")
public class AppConfig extends WebMvcConfigurerAdapter
{
#Override
public void addResourceHandlers(ResourceHandlerRegistry registry)
{
registry.addResourceHandler("/resources/**").addResourceLocations("/resources/");
}
}
Is there a config file that specifies the base path for the app?
Have a look at the .metadata directory of our workspace. It has a .plugins folder, that constains the org.eclipse.wst.server.core directory, and there is one (or more) tmp0 diectory. That contains a wtpwebapps directory. This contains the deployed webapps with the name that is used -- for example MyApp.
<Workspace>\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\MyApp
Then your Login page is located at
http://localhost[:8080]/MyApp/Login
http://localhost/ims/Login will hit port 80 ; by default tomcat runs on port 8080. So unless you have changed tomcat's HTTP port to 80 you need to use localhost:8080
If the port is good then check that your application context path is really ims, by default it is the exact name of the generated WAR file. If you use WTP, eclipse "servers" view will show it under the server instance.
If the context path is good then check the configured URL mapping in your web.xml descriptor. Make sure you are not missing a prefix in the URL for REST/MVC servlet URL aggregation. In your case it looks like you should use .../resources/Login because your configured your resources to be under the /resources/** pattern.