Configure jbpm (version 7.28.0) server start with Mssql - sql-server-2005

I am using jbpm version 7.28.0. I need to configure it with Mssql, except connecting to the default database H2. I'm following DB_Configuration_Note and edited \standalone\configuration\standalone.xml <datasources> element as below;
<subsystem xmlns="urn:jboss:domain:datasources:5.0">
<datasources>
<datasource jndi-name="java:jboss/datasources/ExampleDS" pool-name="ExampleDS" enabled="true" use-java-context="true">
<connection-url>jdbc:mssql:mem:test.DB_CLOSE_DELAY=-1.DB_CLOSE_ON_EXIT=FALSE</connection-url>
<driver>mssql</driver>
<security>
<user-name>jbpm</user-name>
<password>Jbpm#123</password>
</security>
</datasource>
<xa-datasource jndi-name="java:jboss/datasources/jBPMDS" pool-name="jBPMXADS" enabled="true">
<xa-datasource-property name="URL">jdbc:mssql:file:${jboss.server.data.dir}/jbpm-db;MVCC=TRUE</xa-datasource-property>
<xa-datasource-class>com.microsoft.sqlserver.jdbc.SQLServerDataSource</xa-datasource-class>
<driver>mssql</driver>
<security>
<user-name>jbpm</user-name>
<password>Jbpm#123</password>
</security>
</xa-datasource>
<drivers>
<driver name="h2" module="com.h2database.h2">
<xa-datasource-class>com.microsoft.sqlserver.jdbc.SQLServerDataSource</xa-datasource-class>
</driver>
</drivers>
</datasources>
</subsystem>
But I'm getting following error.
16:16:35,776 ERROR [org.jboss.as.controller.management-operation]
(Controller Boot Thread) WFLYCTL0013: Operation ("add") failed -
address: ([
("subsystem" => "datasources"),
("data-source" => "ExampleDS") ]) - failure description: {
"WFLYCTL0412: Required services that are not installed:" => ["jboss.jdbc-driver.mssql"],
"WFLYCTL0180: Services with missing/unavailable dependencies" => [
"jboss.driver-demander.java:jboss/datasources/ExampleDS is missing [jboss.jdbc-driver.mssql]",
"org.wildfly.data-source.ExampleDS is missing [jboss.jdbc-driver.mssql]"
] }
I'm not sure the configuration I have done is correct. How to resolve this and connect JBPM with MSSQL?

Both datasources are using 'mssql' driver. But this driver is not available. I will recommend to create two different drivers for H2 database and mssql database.

ExampleDS of H2 database includes some samples of process.
javax.xml.bind.api is needed.
I wrote jbpm-sqlserver-config.cli for jbpm(7.54.0).
Try like this below.(jdk11,sqlserver2012 above)
jbpm-sqlserver-config.cli
embed-server --server-config=standalone.xml
try
module add --name=com.microsoft.sqlserver --resources=drivers/mssql-jdbc-9.2.1.jre11.jar --dependencies=javax.api,javax.transaction.api,javax.xml.bind.api
catch
echo "SQLServer module exists"
end-try
if (outcome != success) of /subsystem=datasources/jdbc-driver=sqlserver:read-resource
/subsystem=datasources/jdbc-driver=sqlserver:add(driver-name=sqlserver,driver-module-name=com.microsoft.sqlserver,driver-xa-datasource-class-name=com.microsoft.sqlserver.jdbc.SQLServerXADataSource)
end-if
if (outcome == success) of /subsystem=datasources/xa-data-source=jBPMXADS:read-resource
/subsystem=datasources/xa-data-source=jBPMXADS:remove
end-if
xa-data-source add --name=jBPMXADS --jndi-name="java:/MSSQLXADS" --driver-name=sqlserver --user-name=jbpm --password=jbpm --xa-datasource-class=com.microsoft.sqlserver.jdbc.SQLServerXADataSource --xa-datasource-properties=[ServerName=10.255.255.88, PortNumber=1433, DatabaseName=jbpm] --background-validation=false --valid-connection-checker-class-name=org.jboss.jca.adapters.jdbc.extensions.mssql.MSSQLValidConnectionChecker
if (outcome != success) of /system-property=org.kie.server.persistence.ds:read-resource
/system-property=org.kie.server.persistence.ds:add(value="java:/MSSQLXADS")
else
/system-property=org.kie.server.persistence.ds:write-attribute(name=value,value="java:/MSSQLXADS")
end-if
if (outcome != success) of /system-property=org.kie.server.persistence.dialect:read-resource
/system-property=org.kie.server.persistence.dialect:add(value="org.hibernate.dialect.SQLServer2012Dialect")
else
/system-property=org.kie.server.persistence.dialect:write-attribute(name=value,value="org.hibernate.dialect.SQLServer2012Dialect")
end-if
if (outcome != success) of /system-property=org.kie.server.id:read-resource
/system-property=org.kie.server.id:add(value="sample-server")
else
/system-property=org.kie.server.id:write-attribute(name=value,value="sample-server")
end-if
if (outcome != success) of /system-property=org.kie.server.controller:read-resource
/system-property=org.kie.server.controller:add(value="http://localhost:8080/business-central/rest/controller")
else
/system-property=org.kie.server.controller:write-attribute(name=value,value="http://localhost:8080/business-central/rest/controller")
end-if
if (outcome != success) of /system-property=org.kie.server.location:read-resource
/system-property=org.kie.server.location:add(value="http://localhost:8080/kie-server/services/rest/server")
else
/system-property=org.kie.server.location:write-attribute(name=value,value="http://localhost:8080/kie-server/services/rest/server")
end-if
if (outcome != success) of /system-property=org.jbpm.casemgmt.showcase.url:read-resource
/system-property=org.jbpm.casemgmt.showcase.url:add(value="/jbpm-casemgmt")
else
/system-property=org.jbpm.casemgmt.showcase.url:write-attribute(name=value,value="/jbpm-casemgmt")
end-if
stop-embedded-server
./jboss-cli.sh --file=jbpm-sqlserver-config.cli
You must create jbpm database on your sqlserver and give proper access right.
Read carefully "Understanding XA transactions" on ms web site.

Related

Infinispan local cache error: Unable to invoke method public void org.infinispan.globalstate.impl.GlobalConfigurationManagerImpl.start()

I have upgraded a Spring boot service to Infinispan 9.4.16.Final from 5.2.20.Final. The service has two XML files. I used the conversion script to convert them. Both have local-cache entries and no other types of caches. One was left with empty transport element by the conversion tool.
When we deploy and run these services, we often see this warning at startup:
org.infinispan.manager.EmbeddedCacheManagerStartupException: org.infinispan.commons.CacheException: Unable to invoke method public void org.infinispan.globalstate.impl.GlobalConfigurationManagerImpl.start() on object of type GlobalConfigurationManagerImpl
The above is the first warning/error we see. There is no stack trace. Why would it be calling GlobalConfigurationManagerImpl when we're only using local cache?
A few lines later in the log, then I see many The cache has been stopped and invocations are not allowed! errors. The last error we see is as follows. The service fails to start up successfully.
Caused by: org.infinispan.commons.CacheException: Initial state transfer timed out for cache org.infinispan.CONFIG on <server_name>
Why are these errors/warnings happening on startup? Is there a problem in the config files? I've searched online and have not found a solution.
~~More Info~~~
Here is one of the two XML config files:
<infinispan
xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation = "urn:infinispan:config:9.4 http://www.infinispan.org/schemas/infinispan-config-9.4.xsd"
xmlns = "urn:infinispan:config:9.4">
<threads/>
<cache-container name = "TestCenterServiceCache">
<!-- The conversion tool added this empty "transport" element. It was not present in our old config file -->
<transport/>
<jmx domain = "org.infinispan.TestCenterServiceCache"/>
<local-cache name = "authorizedLocations">
<expiration lifespan = "3600000"/>
</local-cache>
<!--caching for 24 hours: 3,600,000 milliseconds/hr x 24 hours -->
<local-cache name = "proximitySearchConfiguration">
<expiration lifespan = "86400000"/>
</local-cache>
</cache-container>
</infinispan>
The above is instantiated via applicationContext.xml. The first warning (GlobalConfigurationManagerImpl.start()) is referencing these beans.
<bean id="infinispanCacheManager"
class="org.infinispan.spring.embedded.support.InfinispanEmbeddedCacheManagerFactoryBean"
p:configurationFileLocation="classpath:testCenterServices-cache-config.xml" />
<bean id="cacheManager"
class="org.infinispan.spring.embedded.provider.SpringEmbeddedCacheManager">
<constructor-arg ref="infinispanCacheManager" />
</bean>
Here is the second XML config file:
<?xml version="1.0" ?>
<infinispan
xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation = "urn:infinispan:config:9.4 http://www.infinispan.org/schemas/infinispan-config-9.4.xsd"
xmlns = "urn:infinispan:config:9.4">
<threads />
<cache-container name="AtlasServicesCacheManager">
<local-cache name="allLocaleCache" />
<local-cache name="localeCacheByID" />
<local-cache name="countryByCode" />
<local-cache name="allActiveCountries" />
<local-cache name="allCountries" />
<local-cache name="allStatesForCountryCode" />
<local-cache name="allActiveStatesForCountryCode" />
<local-cache name="stateForCountryCodeStateCode" />
</cache-container>
</infinispan>
The above is instantiated via java code.
#Bean(name="atlasServicesCacheManager")
public CacheManager makeCacheManager() throws IOException {
return new SpringEmbeddedCacheManager(new DefaultCacheManager("atlas-cache-config.xml"));
}
I don't know if it's meaningful, but only after the upgrade, we log messages that include "JGroups", such as Unable to use any JGroups configuration mechanisms provided in properties {}. Using default JGroups configuration!.
The service instances are running on Windows Server 2012 R2 Standard (Windows 8).
To fix this, remove the empty <transport /> element for local caches.
Adding that empty element seems to be a defect in the config-converter. With the empty transport element in place, it seems that Infinispan is partially configured for cluster synchronization. For details on the underlying issue, see bug report: https://issues.redhat.com/browse/ISPN-11854.

how to connect apache ignite by redis's interface

i want connect apache ignite from nodejs by redis's interface
in ignite config, i add bellow xml defintion in config-default.xml:
<property name="connectorConfiguration">
<bean class="org.apache.ignite.configuration.ConnectorConfiguration">
<property name="host" value="localhost"/>
<property name="port" value="6379"/>
</bean>
</property>
and run ignite.bat (testing platform in win7 64bit)
console message seeming running fine:
[15:59:09] To start Console Management & Monitoring run ignitevisorcmd.{sh|bat}
[15:59:09]
[15:59:09] Ignite node started OK (id=b58f9f35)
[15:59:09] Topology snapshot [ver=1, servers=1, clients=0, CPUs=4, heap=1.0GB]
when test a nodejs code such as:
var redis = require("redis");
var client = redis.createClient({detect_buffers: true});
client.get("test", function (err, reply) {
if(err == null){
console.log('reply:'+reply);
}
else{
console.log('error:'+err);
}
});
client.quit();
got a error message in nodejs
vents.js:183
throw er; // Unhandled 'error' event
^
AbortError: Ready check failed: Stream connection ended and command aborted. It might have been processed.
at RedisClient.flush_and_error (d:\APP\nodejs\mcanserver\node_modules\redis\index.js:362:23)
at RedisClient.connection_gone (d:\APP\nodejs\mcanserver\node_modules\redis\index.js:597:14)
at Socket.<anonymous> (d:\APP\nodejs\mcanserver\node_modules\redis\index.js:293:14)
at Object.onceWrapper (events.js:313:30)
at emitNone (events.js:111:20)
at Socket.emit (events.js:208:7)
at endReadableNT (_stream_readable.js:1064:12)
at _combinedTickCallback (internal/process/next_tick.js:138:11)
at process._tickCallback (internal/process/next_tick.js:180:9)
Waiting for the debugger to disconnect...
AbortError
and errors in ignite console:
[16:08:59,809][SEVERE][grid-nio-worker-tcp-rest-0-#36][GridTcpRestProtocol] Fail
ed to process selector key [ses=GridSelectorNioSessionImpl [worker=ByteBufferNio
ClientWorker [readBuf=java.nio.HeapByteBuffer[pos=14 lim=14 cap=8192], super=Abs
tractNioClientWorker [idx=0, bytesRcvd=0, bytesSent=0, bytesRcvd0=0, bytesSent0=
0, select=true, super=GridWorker [name=grid-nio-worker-tcp-rest-0, igniteInstanc
eName=null, finished=false, hashCode=1424564915, interrupted=false, runner=grid-
nio-worker-tcp-rest-0-#36]]], writeBuf=null, readBuf=null, inRecovery=null, outR
ecovery=null, super=GridNioSessionImpl [locAddr=/127.0.0.1:6379, rmtAddr=/127.0.
0.1:18970, createTime=1527667738762, closeTime=0, bytesSent=0, bytesRcvd=14, byt
esSent0=0, bytesRcvd0=14, sndSchedTime=1527667738762, lastSndTime=1527667738762,
lastRcvTime=1527667738762, readsPaused=false, filterChain=FilterChain[filters=[
GridNioCodecFilter [parser=GridTcpRestParser [jdkMarshaller=JdkMarshaller [], ro
uterClient=false], directMode=false]], accepted=true]]]
java.lang.IllegalArgumentException: No enum constant org.apache.ignite.internal.
processors.rest.protocols.tcp.redis.GridRedisCommand.INFO
at java.lang.Enum.valueOf(Unknown Source)
at org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRe
disCommand.valueOf(GridRedisCommand.java:26)
at org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRe
disMessage.command(GridRedisMessage.java:124)
at org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRe
disNioListener.onMessage(GridRedisNioListener.java:132)
at org.apache.ignite.internal.processors.rest.protocols.tcp.GridTcpRestN
ioListener.onMessage(GridTcpRestNioListener.java:193)
at org.apache.ignite.internal.processors.rest.protocols.tcp.GridTcpRestN
ioListener.onMessage(GridTcpRestNioListener.java:94)
at org.apache.ignite.internal.util.nio.GridNioFilterChain$TailFilter.onM
essageReceived(GridNioFilterChain.java:279)
at org.apache.ignite.internal.util.nio.GridNioFilterAdapter.proceedMessa
geReceived(GridNioFilterAdapter.java:109)
i need help to known what's happen? and how to fixed this error, thanks.
I'm afraid that your client uses a command INFO which isn't implemented by Apache Ignite. Is it possible to try alternative client or maybe a memcached client? Note that the latter has binary and text forms, only one of which is supported.
just ran into the same issue with node.js redis client.. indeed, INFO operation is not supported by Apache Ignite, and node redis client uses it to check if Redis is ready to serve queries.. a workaround is to turn it off:
redis.createClient({no_ready_check: true});

Spring xd issue with http-client

I have spring xd module with rabbitmq as a transport. My module has http source http client processor which calls a rest url http://x.y.z/test
stream create --name cycletest4 --definition "http | http-client --url='''https://x.y.z/test''' --httpMethod=GET | log"
http post --data '{ "messageAttribute": { "channelType" : "EML", "contentKey" : "20020", "messageFormat" : "1", "contentSubscriber" : "dmttts", "languageCode" : "en-ca" }, "substitutionKeyValueData" : { "SvcgLOBCd": "CA", "User": "user", "phone": "yyyy, "accountLast": "tttt", "userName": "LP", "Company": "bbbb", "firstName": "Ryan" } }'
Now when my rest client throws any exception like 404 or connection time out exception and the message is going back the rabbit queue between http|http-client
My understanding was only connection time out exception will be put back queue and any other exception or 200 will move the message to next component it is http-client| log.But when i tried it all exception were put back the queue between http|http-client.
Now my usecase was i want to retry all socket time /connection time out exception .any other system exception 50x errors I want to write to log or file sink?How can I achieve this.Basically depending on exception I want to route retry and non retry exception.
Only 2xx results will go to the log.
4xx and 5xx are considered errors.
You will need a custom http-client module to trap the exceptions you consider 'ok' and forward them to the output channel. Something like...
<int:service-activator input-channel="input" ref="gw" />
<int:gateway request-channel="toHttp" error-channel="errors" />
<int:chain input-channel="errors" output-channel="output">
<!-- examine payload.cause (http status code etc) and decide whether
to throw an exception or return the status code for sending to output -->
</int:chain>
We tried implementing as suggested above. It is now filtering the 4XX errors and sending the payload to the next module. However the messages are stuck unacknowledged in the internal rabbit mq. The acknowledgement is not happening in case of 2XX also after the change. Before the changes the 2XX acknowledgement was happening fine. The 5XX retry continue to happen just fine. Please let us know how to overcome this.
Here is the context xml
<service-activator input-channel="inputX" ref="gw" />
<gateway id="gw" default-request-channel="toHttp" error-channel="errors" />
<beans:bean id="responseInterceptor" class="com.batch.httpclient.ResponseInterceptor">
</beans:bean>
<chain input-channel="errors" output-channel="output">
<transformer ref="responseInterceptor" />
</chain>
<int-http:outbound-gateway id='batch-http' header-mapper="headerMapper"
request-channel='toHttp' url-expression="${url}" http-method="${httpMethod}"
expected-response-type='java.lang.String' charset='${charset}'
reply-timeout='${replyTimeout}' reply-channel='output'>
</int-http:outbound-gateway>
<beans:bean id="headerMapper" class="org.springframework.integration.http.support.DefaultHttpHeaderMapper"
factory-method="outboundMapper">
<beans:property name="outboundHeaderNames" value="*"/>
<beans:property name="userDefinedHeaderPrefix" value=""/>
</beans:bean>
<channel id="output" />
<channel id="input" />
<channel id="inputX" />
<channel id="toHttp" />
And the Java code for ResponseInterceptor looks like this -
public Message<String> transform(ErrorMessage errorMessage) {
if(null != errorMessage && null != errorMessage.getPayload() && null != errorMessage.getPayload().getCause()
&& null != errorMessage.getPayload().getCause().getMessage()){
String rootCause = errorMessage.getPayload().getCause().getMessage();
//check if the error message contains 400 or 404 http code.
if(rootCause.contains("400") || rootCause.contains("404")){
return MessageBuilder.withPayload(errorMessage.getPayload().getCause().getMessage())
.copyHeaders(errorMessage.getHeaders())
.removeHeader("errorChannel")
.removeHeader("replyChannel")
.setReplyChannelName("output").setErrorChannelName(null).build();
}
}
return null;
}
}

Unable to connect Spring AMQP / Rabbit MQ : org.springframework.amqp.AmqpConnectException: java.net.ConnectException: Connection refused: connect

I am new to Spring AMQP / Rabbit MQ.
Am using a Spring AMQP / Rabbit MQ in my project. I am facing following error after running a tomcat:
org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer
- Consumer raised exception, processing can restart if the connection factory supports it.
Exception summary: org.springframework.amqp.AmqpConnectException:
java.net.ConnectException: Connection refused: connect
Below is the configuration file :
spring-amqp.xml
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:rabbit="http://www.springframework.org/schema/rabbit"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/rabbit http://www.springframework.org/schema/rabbit/spring-rabbit.xsd">
<rabbit:connection-factory id="connectionFactory" host="127.0.0.1"/>
<rabbit:admin connection-factory="connectionFactory"/>
<rabbit:template connection-factory="connectionFactory" id="rabbitTemplate" channel-transacted="true"/>
<rabbit:queue name="proposalQueue" />
<rabbit:listener-container connection-factory="connectionFactory">
<rabbit:listener ref="listener" queue-names="proposalQueue"/>
</rabbit:listener-container>
<bean id="rabbitMQTransactionManager" class="org.springframework.amqp.rabbit.transaction.RabbitTransactionManager">
<property name="connectionFactory" ref="connectionFactory"/>
</bean>
<rabbit:direct-exchange name="myExchange">
<rabbit:bindings>
<rabbit:binding queue="proposalQueue" key="userMesssage" />
</rabbit:bindings>
</rabbit:direct-exchange>
<bean id="listener" class="com.xxx.xxxx.rabbitmq.QueueServer"/>
</beans>
QueueServer.java
#Override
public void onMessage(Message message) {
Map<String, Object> result = new HashMap<>();
MessageProperties props = message.getMessageProperties();
BasicProperties replyProps = new BasicProperties.Builder().correlationId(new String(message.getMessageProperties().getCorrelationId())).build();
String inputParameterStr = new String(message.getBody());
try {
Map<String,Object> inputParameters = (Map<String, Object>) Utility.StringToObject(inputParameterStr, "java.util.Map");
result = service.createQueue(inputParameters);
} catch (ClassNotFoundException e) {
logger.error("Error :::: "+getClass()+proposalID, e);
result.put(Constants.FAILURE, e.getMessage());
} catch (Exception e) {
logger.error("Error :::: "+getClass()+proposalID, e);
result.put(Constants.FAILURE, e.getMessage());
}
}
Please help to resolve.
java.net.ConnectException: Connection refused: connect
That simply means that RabbitMQ is not running on localhost (127.0.0.1) on the standard port (5672).
Did you download and install/run RabbitMQ? It is not like ActiveMQ - it can't run embedded in a java application.
Check the host and port value
In application.properties
spring.rabbitmq.host=localhost
spring.rabbitmq.port=5672
spring.rabbitmq.username=guest
spring.rabbitmq.password=guest
See RabbitMQ site is running on port 15672 whereas in code using amqp protocol.
There's one more aspect to the problem.
By default, the RabbitMQ is accessible to the local machine only. If you want to access it from some other machine, you generally create one entry in "rabbitmq.config" file. Location of this file varies from OS to OS. In Linux, you can find this at: "/etc/rabbitmq/rabbitmq.config" and in Windows machine, you can find it at: "C:\Program Files\RabbitMQ Server\rabbitmq_server-3.6.9\etc\rabbitmq.config".
There's a possibility that you don't find this file at the mentioned location. This is an optional file and you need not to worry if it is missing even. You can create your own. This entry is something like:
[{rabbit, [{tcp_listeners, [{"<IP_OF_MACHINE>", 5672}]},{loopback_users, []}]}].
With this, you can access the server from any remote machine.
If after this you get the server inaccessible you can modify the entry to:
[{rabbit, [{tcp_listeners, [{"0.0.0.0", 5672}]},{loopback_users, []}]}].
You will definitely get the server connected to any client as well as through management console (if plugin enabled)
i'm confronted the same problem (when using docker). Above answers didn't help me. I switched to a different version rabbitmq.
was:
rabbitmq:3.9.14-management-alpine
now:
rabbitmq:3.9.8-management-alpine
In order to access the RabbitMQ remote , you need to allow inbound TCP traffic on ports 4369, 25672, 5671, 5672, 15672, 61613, 61614, 1883, and 8883.
sudo firewall-cmd --zone=public --permanent --add-port=4369/tcp --add-port=25672/tcp --add-port=5671-5672/tcp --add-port=15672/tcp --add-port=61613-61614/tcp --add-port=1883/tcp --add-port=8883/tcp
sudo firewall-cmd --reload

sl4j/logback under weblogic

I'm trying to configure sl4j/logback under Weblogic12.
I deploy ear file, which has war file, which has WEB-INF\classes\logback.xml
Here is the config:
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<root level="debug">
<appender-ref ref="STDOUT" />
</root>
</configuration>
My code to log :
private static final Logger logger = LoggerFactory.getLogger(FrontEndServlet.class);
//......
logger.info("info test");
logger.debug("debug test");
logger.error("error test");
What I see in the standart output is :
ьрщ 14, 2012 5:09:29 PM .....FrontEndServlet doPost
INFO: info test
ьрщ 14, 2012 5:09:29 PM .....FrontEndServlet doPost
SEVERE: error test
So, it looks like config file is not picked up.
What am I doing wrong?
The problem is discussed here in detail: https://stagingthinking.wordpress.com/2012/06/02/annoying-slf4j-problem-in-weblogic-server-12c/
The exact package you need to put to the prefer-application-packages mechanism is org.slf4j, like this:
<?xml version='1.0' encoding='UTF-8'?>
<weblogic-application>
<prefer-application-packages>
<package-name>org.slf4j</package-name>
</prefer-application-packages>
</weblogic-application>
Note: Also this question is already answered, I want to add that you should also add prefer-application-resources.
Answer: Add a file called META-INF/weblogic-application.xml to your ear, containing both prefer-application-packages and prefer-application-resources!
<?xml version="1.0" encoding="UTF-8"?>
<weblogic-application
xmlns="http://xmlns.oracle.com/weblogic/weblogic-application"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.oracle.com/weblogic/weblogic-application http://xmlns.oracle.com/weblogic/weblogic-application/1.5/weblogic-application.xsd"
version="6">
<!-- http://www.torsten-horn.de/techdocs/jee-oracleweblogic.htm -->
<prefer-application-packages>
<package-name>org.slf4j.*</package-name>
</prefer-application-packages>
<!-- if not using prefer-application-resources you will get a warning like this: -->
<!-- Class path contains multiple SLF4J bindings -->
<!-- SLF4J: Found binding in [jar:file:/C:/wls1211/modules/org.slf4j.jdk14_1.6.1.0.jar!/org/slf4j/impl/StaticLoggerBinder.class] -->
<prefer-application-resources>
<resource-name>org/slf4j/impl/StaticLoggerBinder.class</resource-name>
</prefer-application-resources>
</weblogic-application>
The problem was - sl4j did not pick up logback and used Weblogic's slf4j-jdk logging instead. Can be fixed with Weblogic's config weblogic-application.xml, option prefer-application-packages
Alternatively or if you have problems with more than just slf4j, you could use
<wls:container-descriptor>
<wls:prefer-web-inf-classes>true</wls:prefer-web-inf-classes>
</wls:container-descriptor>
Instead of
<prefer-application-packages>
<package-name>org.slf4j.*</package-name>
</prefer-application-packages>
Source: Oracle
Environment: Weblogic 12.2.1
Logging Framework : Slf4j and Logback
Requirement : Log to a file of my choosing (per application) as well as Weblogic server logs
Using the <prefer-application-packages/> or <prefer-web-inf-classes> in weblogic.xml did not satisfy the requirement. In my testing, using one or the other tags (you can't use both) will result in the application logback.xml to be picked up and logging will go to the file defined in logback.xml. However, the typical STDOUT defintion using logback's ConsoleAppender will not log to the server logs.
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
Removing the following from weblogic.xml
<wls:prefer-application-packages>
<wls:package-name>org.slf4j.*</wls:package-name>
</wls:prefer-application-packages>
will result in using the bundled SLF4j binding, which in Weblogic 12.2.1, is Java Util logging. In this case, log statements will go to the server logs and not to the file definition in the application level logback.xml. In my research, it appears at one time, some version of Weblogic 12 allowed the internal SLF4j to be bound to Log4j but was removed in one of the minor releases. This was my case; I did not have the option of enabling Log4j as the primary logging Framework in Weblogic through the Admin console. I am fairly sure this wouldn't have helped me, but I did want to note it because several documents I read indicated this would be available.
After much research and fighting configuration with weblogic.xml, configuration of POM (exclusions etc) and trying to use different bindings and bridges, I was unable to achieve the logging configuration that I wanted. It appears that Weblogic's slf4j is bound to Java utility logging, for better or worse. If you choose your own implementation of slf4j and binding (in my case Logback), there is no way that I could find to route those messages to Weblogic server logs through configuration. There can only be one binding in slf4j, and although many frameworks can be routed to that one binding, (I found this diagram useful) Weblogic 12.2.1 only employs Java util logging binding, there is no way to (at the application configuration level) to wire Weblogic to use the Logback binding that you provide to log to its server logs. There might be some way to use log4j and bridges to accomplish this, but for me that's entirely too much bloat and configuration to accomplish a simple logging task.
Giving up on trying to conquer this by configuration, I decided to simply write my own logback appender that translates a logging event into a JUL logging event. I replaced the standard STDOUT definition seen in many Logback examples with my own implementation of Logback's AppenderBase. At this point I can now log using per application logging configuration and also log to the Weblogic Server log.
Relevant POM Dependencies:
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-api -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.25</version>
</dependency>
<!-- https://mvnrepository.com/artifact/ch.qos.logback/logback-classic -->
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.3</version>
</dependency>
<!-- https://mvnrepository.com/artifact/ch.qos.logback/logback-core -->
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>1.2.3</version>
</dependency>
weblogic.xml (Note here that Hibernate comes with JbossLogging which will bridge to slf4j automatically)
<?xml version="1.0" encoding="UTF-8"?>
<weblogic-web-app xmlns="http://xmlns.oracle.com/weblogic/weblogic-web-app"
xmlns:wls="http://xmlns.oracle.com/weblogic/weblogic-web-app"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.oracle.com/weblogic/weblogic-web-app http://xmlns.oracle.com/weblogic/weblogic-web-app/2.0/weblogic-web-app.xsd">
<jsp-descriptor>
<keepgenerated>true</keepgenerated>
<debug>true</debug>
</jsp-descriptor>
<context-root>YourContextRoot</context-root>
<wls:container-descriptor>
<wls:prefer-application-packages>
<wls:package-name>ch.qos.logback.*</wls:package-name>
<wls:package-name>org.jboss.logging.*</wls:package-name>
<wls:package-name>org.slf4j.*</wls:package-name>
</wls:prefer-application-packages>
<wls:prefer-application-resources>
<wls:resource-name>org/slf4j/impl/StaticLoggerBinder.class</wls:resource-name>
</wls:prefer-application-resources>
</wls:container-descriptor>
Logback AppenderBase implementation
import java.util.logging.Logger;
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.AppenderBase;
public class WeblogicAppender extends AppenderBase<ILoggingEvent> {
private final Logger logger = Logger.getLogger(WeblogicAppender.class.getName());
ILoggingEvent event = null;
#Override
protected void append(ILoggingEvent event) {
this.event = event;
logger.log(getJULLevel(), event.getFormattedMessage());
}
private java.util.logging.Level getJULLevel() {
if (this.event == null) {
return java.util.logging.Level.SEVERE;
} else if (this.event.getLevel() == ch.qos.logback.classic.Level.ALL) {
return java.util.logging.Level.ALL;
} else if (this.event.getLevel() == ch.qos.logback.classic.Level.DEBUG) {
return java.util.logging.Level.FINE;
} else if (this.event.getLevel() == ch.qos.logback.classic.Level.ERROR) {
return java.util.logging.Level.SEVERE;
} else if (this.event.getLevel() == ch.qos.logback.classic.Level.INFO) {
return java.util.logging.Level.INFO;
} else if (this.event.getLevel() == ch.qos.logback.classic.Level.TRACE) {
return java.util.logging.Level.FINEST;
} else if (this.event.getLevel() == ch.qos.logback.classic.Level.WARN) {
return java.util.logging.Level.WARNING;
} else if (this.event.getLevel() == ch.qos.logback.classic.Level.OFF) {
return java.util.logging.Level.OFF;
} else {
return java.util.logging.Level.INFO;
}
}
}
Logback.xml configuration
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appender name="STDOUT" class="com.your.package.WeblogicAppender">
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger: LineNumber:%L - %message%n</pattern>
</encoder>
</appender>
<appender name="FILE"
class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>yourlog.log
</file>
<rollingPolicy
class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>yourlog.%d{yyyy-MM-dd}.%i.log
</fileNamePattern>
<maxFileSize>25MB</maxFileSize>
<maxHistory>60</maxHistory>
<totalSizeCap>10GB</totalSizeCap>
</rollingPolicy>
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger: LineNumber:%L - %message%n</pattern>
</encoder>
</appender>
<root level="TRACE">
<appender-ref ref="STDOUT" />
<appender-ref ref="FILE" />
</root>
</configuration>
Hopefully I can save others some of the pain that I went through trying to get this working the way I wanted.