Glassfish Log4j JNDI: Cannot find appender - web-services

I am using Glassfish and I created a JNDI custom resource called log4j that has these properties:
Name: log4j.appender.LOG Value: org.apache.log4j.RollingFileAppender
Name: log4j.appender.LOG.layout Value: org.apache.log4j.PatternLayout
Name: log4j.rootLogger Value: WARN, LOG
Name: log4j.appender.LOG.layout.conversionPattern Value: %d{MMM dd, yyyy HH:mm:ss} %p %m%n
Name: log4j.appender.LOG.File Value: ${com.sun.aas.instanceRoot}/logs/RestWebServices.log
Name: log4j.appender.LOG.MaxFileSize Value: 10MB
Name: log4j.appender.LOG.MaxBackupIndex Value: 10
The JNDI resource type is java.util.Properties and my spring application context contains these lines to find them:
<jee:jndi-lookup id="log4jJndi" jndi-name="log4j" resource-ref="true" />
<jee:jndi-lookup id="configurationsJndi" jndi-name="configurations" resource-ref="true" />
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="propertiesArray">
<list>
<ref bean="configurationsJndi"/>
<ref bean="log4jJndi"/>
</list>
</property>
</bean>
It works fine for my configurations JNDI resource but log4j gives me this error when starting Glassfish:
SEVERE: log4j:WARN No appenders could be found for logger (org.springframework.web.context.ContextLoader).
SEVERE: log4j:WARN Please initialize the log4j system properly.
SEVERE: log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
When debugging the root logger was not the one I set in the JNDI resource. I tried adding the spring Log4jConfigListener to resolve this but it did not work. The version of Glassfish I am using is 3.1.
Does anyone know why log4j is an issue?
Edit: Now I am try to use JNDI that has the file location to my log4j properties file and my Spring application context gets the value from JNDI. My problem is I keep getting this error all the time with log4j:
Exception while loading the app : java.lang.IllegalStateException:
ContainerBase.addChild: start: org.apache.catalina.LifecycleException:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'log4jJndi': Invocation of init method failed;
nested exception is javax.naming.CommunicationException: Communication exception for SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming} [Root exception is java.lang.IllegalAccessException: value cannot be null]|#]

Try the following see if that helps:
1- create a file call it log4j.properties and place it in /src/main/resources
2- Copy the following lines in that file:
# #Default log level
log4j.rootCategory=INFO, console
log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.console.layout=org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern=%-5p %d [%t] %c: %m%n
################################################
# #You can set custom log levels per-package here
################################################
# #Apache Commons tend to make a lot of noise which can clutter the log.
log4j.logger.org.apache=WARN
# #Shuts up some innocuous messages if using the JBPM transport
log4j.logger.org.hibernate.engine.StatefulPersistenceContext.ProxyWarnLog=ERROR
# #Reduce startup noise
log4j.logger.org.springframework.beans.factory=WARN
# #Your custom classes if you have one
log4j.logger.com.mycompany=DEBUG

Related

WSO2IS - Disable Embedded LDAP - deployment.toml

How can I disable Embedded Ldap on Identity Server 5.10.0 version? I'm checking conf/identity/embedded-ldap.xml and enable property is true.
<EmbeddedLDAP>
<Property name="enable">true</Property>
<Property name="port">${Ports.EmbeddedLDAP.LDAPServerPort}</Property>
<Property name="instanceId">default</Property>
.....
I couldn't find how I can disable. If I overwrite this file when docker starts it came back to true.
If you have <wso2is-5.10.0-home>/repository/resources/conf/templates/repository/conf/identity/embedded-ldap.xml.j2 file and it's enable property value under <EmbeddedLDAP> is templated as {{embedded_ldap.enable}} (shown below),
<EmbeddedLDAP>
<Property name="enable">{{embedded_ldap.enable}}</Property>
<Property name="port">${Ports.EmbeddedLDAP.LDAPServerPort}</Property>
<Property name="instanceId">default</Property>
.....
</EmbeddedLDAP>
you can use the following deployment.toml config
[embedded_ldap]
enable = false
If the <wso2is-5.10.0-home>/repository/resources/conf/templates/repository/conf/identity/embedded-ldap.xml.j2 file contains the EmbeddedLDAP config's enable property value as hardcoded to "true", you can change it to false and restat the server to change the config in embedded-ldap.xml.
<EmbeddedLDAP>
<Property name="enable">true</Property>
<Property name="port">${Ports.EmbeddedLDAP.LDAPServerPort}</Property>
<Property name="instanceId">default</Property>
.....
</EmbeddedLDAP>
If you don't have <wso2is-5.10.0-home>/repository/resources/conf/templates/repository/conf/identity/embedded-ldap.xml.j2 file, the property value changes in embedded-ldap.xml won't be replaced once the server is restarted.
In WSO2 Identity Server 5.10.0 the configurations are managed by a centralized toml file which is called as deployment.toml. We can add the following configuration to the deployment.toml file which is located in <IS_HOME>/repository/conf directory.
[embedded_ldap]
enable = false
In WSO2 Identity Server 5.10.0 version the file embedded-ldap.xml.j2 doesn't come inside
wso2is-5.10.0/repository/resources/conf/templates/repository/conf/identity so I needed to copy the file from this link: embedded-ldap.xml.j2 and put inside my configuration for docker container conf/is-as-km/repository/resources/conf/templates/repository/conf/identity
docker-compose.yml
...
volumes:
- ./conf/is-as-km:/home/wso2carbon/wso2-config-volume
ports:
- "9444:9443"
...
After that I put the property in deployment.toml:
[embedded_ldap]
enable = false
And everything worked as shown in docker log:
cup-is-as-km ... NFO {org.wso2.carbon.identity.oauth.uma...} - UMA Grant component activated successfully.
cup-is-as-km ... INFO {org.wso2.carbon.ldap.server.DirectoryActivator} - Embedded LDAP is disabled.
cup-is-as-km ... INFO {org.wso2.carbon.mex.internal.Of...} - Office365Support MexServiceComponent bundle activated successfully..
Based on the last answers and comments I reached the solution ;).

getting an exception on running sample of wso2cep

I am a beginner in wso2cep. I want to execute the first sample of WSO2 CEP documentation. I use windows10 as operating system. I type the following command but i getting following exeption in Console output:
c:\wso2cep-4.0.0\samples\producers\http>ant Durl=http://localhost:9763/endpoints/httpReceiver -Dsn=0001
Buildfile: c:\wso2cep-4.0.0\samples\producers\http\build.xml
init:
compile:
[javac] c:\wso2cep-4.0.0\samples\producers\http\build.xml:71: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to
false
for repeatable builds
[copy] Copying 1 file to c:\wso2cep-4.0.0\samples\producers\http\temp\classes
run:
[echo] Configure -Durl=xxxx and ( -DfilePath=xxxx or -Dsn='sample number')
optionally use -Dusername=xxxx -Dpassword=xxxx
[java] [main] INFO org.wso2.carbon.sample.http.Http - Starting WSO2 Http
Client
[java] Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException:4
[java] at org.wso2.carbon.sample.http.Http.main(Unknown Source)
[java] Java Result: 1
BUILD SUCCESSFUL
Total time: 3 seconds
I add this line: <property name="filePath" value=""""/> to the build.xml file but I still get above exception. My build.xml file become as following:
<property name="carbon.home" value="${basedir}"/>
<property name="lib" value="${carbon.home}/repository/lib"/>
<property name="tempdir" value="${carbon.home}/tmp/setup"/>
<property name="output.dir" value="${carbon.home}/tmp/wso2"/>
<property name="filePath" value=""""/>
Should i change "filePath" to another thing? Should i add this line to build.xml file or change other lines? Please help and explain to me.

How can i handle Apache Camel NoRouteToHostException exception?

i want to treat the case when connection with Camel HTTP component cannot be established
example:
<from uri="timer:tm?period=2000"/>
<to uri="https://URI"/>
when there is no connection i get this exception:
java.net.NoRouteToHostException: No route to host: connect
I want to handle this response and change it to an understandable message by the consumer. How can i do this ?
Camel provides a couple of very powerful error handling mechanisms with very useful redelivery and deadletter functionality. Those include:
Error Handlers: https://camel.apache.org/error-handler.html
Dead Letter Channels: https://camel.apache.org/dead-letter-channel.html
Try, Catch & Finally: https://camel.apache.org/try-catch-finally.html
Exception Clause: https://camel.apache.org/exception-clause.html
For your usecase, Exception Clause is the best fit. Redelivery would help you to retry the HTTP call and avoid failure due to a temporary downtime, e.g. a server restart:
<onException>
<exception>java.net.NoRouteToHostException</exception>
<!-- retry 3 times with a delay of 10 seconds -->
<redeliveryPolicy maximumRedeliveries="3" logStackTrace="true" redeliveryDelay="10000" />
<!-- only logs once redeliveries have failed -->
<to uri="log:classToLog?level=ERROR"/>
</onException>
You can handle exception using try..catch..finally.
http://camel.apache.org/try-catch-finally.html
Example in Spring DSL:
<route id="send_request">
<from uri="timer:tm?period=2000" />
<doTry>
<to uri="https://URI" />
<doCatch>
<exception>java.net.NoRouteToHostException</exception>
<handled>
<constant>true</constant>
</handled>
<log message="Some Message : ${exception.message}"
loggingLevel="WARN" />
</doCatch>
</doTry>

Mule ESB Accessing a SOAP WS Error

I am trying to access a simple SOAP web service which return the String (No input arguments). Here is the configuration XML.
<flow name="SOAPWSFlow1" doc:name="SOAPWSFlow1">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8084" doc:name="HTTP" />
<cxf:jaxws-client operation="getTestName" enableMuleSoapHeaders="true" doc:name="SOAP" clientClass="com.mart.catalog.BestMartCatalogService" port="BestMartCatalogPort"/>
</flow>
I get the following error when the code is executed. Appreciate any help to resolve this issue. Thanks!
ERROR 2013-12-08 20:22:49,021 [[soapws].connector.http.mule.default.receiver.02] org.mule.exception.DefaultMessagingExceptionStrategy:
********************************************************************************
Message : wrong number of arguments. Failed to route event via endpoint: org.mule.module.cxf.CxfOutboundMessageProcessor. Message payload is of type: String
Code : MULE_ERROR--2
--------------------------------------------------------------------------------
Exception stack is:
1. wrong number of arguments (java.lang.IllegalArgumentException)
sun.reflect.NativeMethodAccessorImpl:-2 (null)
2. wrong number of arguments. Failed to route event via endpoint: org.mule.module.cxf.CxfOutboundMessageProcessor. Message payload is of type: String (org.mule.api.transport.DispatchException)
org.mule.module.cxf.CxfOutboundMessageProcessor:150 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/transport/DispatchException.html)
--------------------------------------------------------------------------------
Root Exception stack trace:
java.lang.IllegalArgumentException: wrong number of arguments
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
+ 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)

Where is the Sitecore ASR database connection configured?

I'm trying to set up ASR up to email scheduled reports, but this is the error message I see in the log files.
Exception: ASR.Reports.Items.Exceptions.DatabaseNotFoundException
Message: Exception of type 'ASR.Reports.Items.Exceptions.DatabaseNotFoundException' was thrown.
Source: ASR.Reports
at ASR.Reports.Scanners.DatabaseScanner.get_Database()
at ASR.Reports.Items.QueryScanner.Scan()
at ASR.Interface.Report.Run(Object[] parameters)
at ASR.Commands.ScheduledExecution.runReport(Item item, Boolean force)
at ASR.Commands.ScheduledExecution.<>c__DisplayClass4.b__1(Item i)
at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()
at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
at ASR.Commands.ScheduledExecution.EmailReports(Item[] itemarray, CommandItem commandItem, ScheduleItem scheduleItem)
This doesn't make much sense since I'm able to generate reports through the admin interface.
In my ASR config
<setting name="ASR.ConfigurationDatabase" value="master"/>
In my Sitecore Analytics file
<scheduling>
<agent type="Sitecore.Analytics.Tasks.EmailReportsTask, Sitecore.Analytics" method="Run" interval="1:00:00">
DatabaseName>master
In my connection strings config, (which I know works because everything else is working)
<add name="master" connectionString="..." ... />
What am I missing?
ASR will use the ContentDatabase. When you run the report manually, you're running in the context of the "shell" site and it will default to master. When run as a scheduled task, the site will be "scheduler" which has no content database defined by default.
Try adding the following to a config file:
<?xml version="1.0"?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
<sites>
<site name="scheduler">
<patch:attribute name="content">master</patch:attribute>
</site>
</sitecore>
</configuration>
Openly wondering if this is an issue to address back with the ASR module.