How to config logging in Apache Ignite, sfl4j or log4j - spring-boot

I created spring-boot app with Apache Ignite and want to config logging on server and client side. I followed instructions https://apacheignite.readme.io/docs/logging but i got some issues with logging.
For Slf4j
<property name="gridLogger">
<bean class="org.apache.ignite.logger.slf4j.Slf4jLogger"/>
</property>
on server side if I set GNITE_QUIET=false i get
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
Ok, I added libs in $IGNITE_HOME/libs/ignite-slf4j/ slf4j-log4j12 and log4j
log4j:WARN No appenders could be found for logger (org.apache.ignite.internal.util.typedef.G).
log4j:WARN Please initialize the log4j system properly.
I tried to set -Dlog4j.configurationFile=config/log4j.xml, but it doesn't help.
On server side I managed to set up logging with
<property name="gridLogger">
<bean class="org.apache.ignite.logger.log4j.Log4JLogger">
<constructor-arg type="java.lang.String" value="log4j.xml"/>
</bean>
</property>
but in spring-boot ms I got
Caused by: class org.apache.ignite.IgniteCheckedException: Log4j configuration path was not found: config/log4j.xml
It works if I set absolute path
<constructor-arg type="java.lang.String" value="/home/username/work/ignite/config/log4j.xml"/>
but that's not what I need. How do I need to config logs in server/client side correctly?

According your first error, do you use maven? If yes, did you try to include following dependencies to your POM-file?
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.25</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.25</version>
<scope>test</scope>
</dependency>
"Log4j configuration path was not found" is probably thrown because you placed your config to the folder which is not part of your project. If you don't want to use full path just move it to "resources" folder of the project.

Related

java.lang.NoClassDefFoundError: org/apache/cxf/jaxrs/model/doc/DocumentationProvider

I am trying to integrate swagger. I am following steps as given here. application context and pom.xml is configured same.
when restarting tomcat getting this error.
2018-04-30 14:01:33 ERROR ContextLoader:351 - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'productAPIServer': Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: org/apache/cxf/jaxrs/model/doc/DocumentationProvider
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1583)
I have included
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-rs-service-description-swagger</artifactId>
<version>3.1.7</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-rs-service-description</artifactId>
<version>3.1.7</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-core</artifactId>
<version>3.1.7</version>
</dependency>
Changes in context xml file:
<bean id="jacksonJsonProviderFasterxml" class="com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider" />
<bean id="swagger2Feature" class="org.apache.cxf.jaxrs.swagger.Swagger2Feature">
<property name="basePath" value="/staticdata-web-service"/>
<property name="license" value=""/>
<property name="licenseUrl" value=""/>
<property name="title" value="Static data web service"/>
</bean>
Added feature
<jaxrs:features>
<ref bean="swagger2Feature" />
</jaxrs:features>
You have a version mismatch. When you search on Maven for that class, you'll find that the package of the DocumentationProvider has changed from version 3.0.x to 3.1.x
org/apache/cxf/jaxrs/model/doc/DocumentationProvider
to
org/apache/cxf/jaxrs/model/wadl/DocumentationProvider
It's hard to tell where the mismatch is located without having insight into your entire build and package dependencies. But you may want to run
mvn dependency:tree -Dverbose
in your project folder to see which package versions come into question for raising your ClassNotFoundException.
use below dependency in your maven project to solve your issue,
<!-- https://mvnrepository.com/artifact/org.apache.cxf/cxf-rt-rs-json-basic -->
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-rs-json-basic</artifactId>
<version>3.4.3</version>
<scope>provided</scope>
</dependency>

java.lang.NoClassDefFoundError:org/apache/commons/fileupload/FileItemFactoryin Spring MVC

I am trying to build a simple Spring MVC Web App with the functionality of file uploading.I got following error:
java.lang.NoClassDefFoundError: org/apache/commons/fileupload/FileItemFactory
After a quick search,all answers pointed to the missing of dependencies,but it seems not to be true in my case:
I have included the following code in pom.xml:
<dependencies>
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.3.1</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>
</dependencies>
with commons.io-2.4.jar and commons.fileupload-1.3.1.jar added into lib folder.
One interesting thing I found was that whenever I deleted the code:
<bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="maxUploadSize">
<value>10000000</value>
</property>
<property name="maxInMemorySize">
<value>10000000</value>
</property>
</bean>
the web app works fine(of course I removed the form for file uploading as well. )
If you visit the Maven Central Repository and enter the search term:
fc:org.apache.commons.fileupload.FileItemFactory
then every released artifact available containing that class will be listed.
You will find commons-upload 1.3.1 in that list.
Therefore you need to double check your deployment to ensure that jar is present.
Tip: Use fc: to locate jars in Maven Central that contain a specific class.
try to update your jar version, for Example:
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>2.0.0-SNAPSHOT</version>
</dependency>
We cann't find versions upper 1.3 on Apache and mvnrepository.com , but you can try this : https://repository.jboss.org/commons-fileupload/commons-fileupload/2.0.0-SNAPSHOT/
In fact, I encountered the same problem and now working fine with version 2.0 under SpringMVC framework.

WebSphere Spring Apache CXF SOAP WebService Client timeout not working

I need to configure a SOAP WebService client with certain timeout values for connection attempts and service invocations.
The WS client is a jar dependency generated using the WSDL with Maven cxf-codegen-plugin. I use this client jar in my web app as a maven dependency and invoke the service operations.
So my webapp pom contains:
<dependency>
<groupId>my.web.service</groupId>
<artifactId>web-service-client-jar</artifactId>
<version>x.x.x</version>
</dependency>
along with the Apache CXF dependencies:
<!-- CXF dependencies -->
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
<version>${cxf.version}</version>
</dependency>
And I have defined below spring configuration to setup timeouts which does not work..
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:http-conf="http://cxf.apache.org/transports/http/configuration"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://cxf.apache.org/transports/http/configuration http://cxf.apache.org/schemas/configuration/http-conf.xsd http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd">
<http-conf:conduit name="*.http-conduit">
<http-conf:client ConnectionTimeout="20000" ReceiveTimeout="10000" />
</http-conf:conduit>
<cxf:bus>
<cxf:outInterceptors>
<ref bean="fileuploadlogOutbound" />
</cxf:outInterceptors>
</cxf:bus>
<!-- Outbound Message Logging -->
<bean id="fileuploadlogOutbound" class="test.logging.MyLoggingOutInterceptor">
<property name="prettyLogging" value="true" />
</bean>
But to my confusion, the outInterceptors defined for pretty logging works fine. Hence, I doubt if my configuration has any errors or not. FYI I'm trying to get this working in WebSphere 8.5 environment.
This is how I instantiate the WS Client in spring:
<jaxws:client id="documentUploadServiceJaxwsClient"
serviceClass="org.tempuri.IDocumentUploadService" address="#serviceEndpointString" >
<jaxws:binding>
<soap:soapBinding version="1.2" mtomEnabled="true" />
</jaxws:binding>
</jaxws:client>
Is there any steps missing in Spring config or do I need to look into WebSphere 8.5 specific configuration which will enforce HTTP/SOAP connection & response timeouts?
I figured out that my CXF configuration mentioned above works fine but the WAS environment where the application deployed is actually overriding any config you define at the application level. Hence, I followed this link to copy and define custom HTTP Transport policy where you can set values for below timeouts.
Read timeout
Write timeout
Connection timeout

getting error java.lang.NoClassDefFoundError: org/hibernate/validator/resourceloading/ResourceBundleLocator

I have a spring project in which i am using a validator like the following:
<beans:bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource"
p:basenames="WEB-INF/i18n/messages,WEB-INF/i18n/application"
p:fallbackToSystemLocale="false" />
<beans:bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean">
<beans:property name="validationMessageSource" ref="messageSource" />
</beans:bean>
<annotation-driven validator="validator" />
<resources location="/, classpath:/META-INF/web-resources/" mapping="/resources/**" />
When i run the project i get the following BeanCreationException:
org.springframework.beans.factory.BeanCreationException: Error creating bean with
name 'validator' defined in ServletContext resource [/WEB-INF/spring/appServlet
/servlet-context.xml]: Error setting property values; nested exception is
org.springframework.beans.PropertyBatchUpdateException; nested
PropertyAccessExceptions (1) are:
PropertyAccessException 1: org.springframework.beans.MethodInvocationException:
Property 'validationMessageSource' threw exception; nested exception is
java.lang.NoClassDefFoundError: org/hibernate/validator/resourceloading/ResourceBundleLocator
Here is my snippet of POM:
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>1.3.2.RELEASE</version>
</dependency>
<!-- Hibernate entity manager with JPA 2 support. -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>4.3.0.Beta2</version>
</dependency>
<!-- Hibernate’s implementation of JSR-303. -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>4.2.0.Final</version>
</dependency>
<!-- The JSR-303 Bean Validation API library. -->
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.0.0.GA</version>
</dependency>
Why i am getting this error?
Thanks
Your dependencies are OK. Based on the provided information the error should not appear.
So I suggest you to check your IDE and whether the hibernate-validator dependency is really on classpath. If you are using Eclipse with M2E, try to update your project:
Project (right click on project) > Maven > Update Project....
This might be a broken backwards compatibility issue: https://jira.springsource.org/browse/SPR-10466
I had a similar problem using hibernate 5.2.10.Final and hibernate-validator 6.0.2.Final (that package version doesn't seem to be in sync with the others). Turns out, hibernate-validator's groupId was changed from org.hibernate to org.hibernate.validator. Once I made that change, the error went away, however I am using Dropwizard and noticed that there may be a version conflict somewhere, so that's something to keep an eye on.
I also had this exact same problem, tried all sorts of combinations of JAR versions, different bean definitions, even customised class implementations. Turns out, I just had to clean the project and restart Eclipse. Problem solved, and lesson learnt!
Check your dependency
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>4.2.8.Final</version>
</dependency>
Is must be at the same version of your other Hibernate dependencies.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
Just use following dependency, it will fix your issue as this dependency provides basic validation from get go similar to hibernate.

Embedded ActiveMQ in Embedded Glassfish (using maven-embedded-glassfish-plugin)

Im trying to run a ActiveMQ glassfish embedded using the maven-embedded-glassfish-plugin.
I have separately completed below tutorials, so I know the basics.
The goal is to have a setup that builds in one click and avoids 3pp libraries in svn.
1 http://www.hascode.com/2011/09/java-ee-6-development-using-the-maven-embedded-glassfish-plugin/
2 http://javadude.wordpress.com/2011/07/21/glassfish-v3-1-running-embedded-activemq-for-jms-part-1/
Project setup for #2 is used as startpoint from now and I will try to merge the steps from #1
I've setup a glassfish-resources.xml hoping it will do the configuration tutorial 1 did from the glassfish admin-console.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE resources PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Resource Definitions//EN" "http://glassfish.org/dtds/glassfish-resources_1_5.dtd">
<resources>
<resource-adapter-config resource-adapter-name="activemq-rar-5.6.0" thread-pool-ids="thread-pool-1">
<property name="ServerUrl" value="vm://localhost:61616"></property>
<property name="BrokerXmlConfig" value="broker:(tcp://0.0.0.0:61616)"></property>
</resource-adapter-config>
<connector-resource enabled="true" jndi-name="amqres"
object-type="user" pool-name="amqpool">
</connector-resource>
<connector-connection-pool
connection-definition-name="javax.jms.ConnectionFactory"
fail-all-connections="false" idle-timeout-in-seconds="300"
is-connection-validation-required="false" max-pool-size="32"
max-wait-time-in-millis="60000" name="amqpool" pool-resize-quantity="2"
resource-adapter-name="activemq-rar-5.6.0" steady-pool-size="2" />
<admin-object-resource res-adapter="activemq-rar-5.6.0"
res-type="javax.jms.Queue" jndi-name="amqmsg"></admin-object-resource>
</resources>
additions to pom.xml
<dependencies>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-rar</artifactId>
<version>5.6.0</version>
<type>rar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-core</artifactId>
<version>5.6.0</version>
<scope>compile</scope>
</dependency>
</dependencies>
Q1: How is glassfish-resources.xml loaded? Should i use maven admin command or place it in some META-INF?
edit: looks like it goes in web-inf if war and meta-inf if ejb-jar
Q2: Not entirely sure what is the next step. #1 has me copy activemq and log4j libraries to GLASSFISH_HOME/glassfish/lib so far I only added the dependency in the pom.xml, what is the equivalent here?
Q3: The Rar needs to be deployed as well. How can multiple applications be deployed?

Resources