error in persistence.xml - jndi

I am trying to deploy a simple EJB project onto Jboss 7.1.1. I have a separate installation of H2 database.
So I changed the standalone.xml as follows:
<subsystem xmlns="urn:jboss:domain:datasources:1.0">
<datasources>
<datasource jndi-name="java:jboss/datasources/ExampleDS" pool-name="ExampleDS" enabled="true" use-java-context="true">
<connection-url>jdbc:h2:tcp://localhost/~/test</connection-url>
<driver>h2</driver>
<security>
<user-name>sa</user-name>
<password>sa</password>
</security>
</datasource>
<drivers>
<driver name="h2" module="com.h2database.h2">
<xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class>
</driver>
</drivers>
</datasources>
</subsystem>
Now I have also edited the persistence.xml to match the names in the standalone.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="scube" transaction-type="JTA">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>com.sample.model.Property</class>
<jta-data-source>java:jboss/datasources/ExampleDS</jta-data-source>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect" />
<property name="hibernate.max_fetch_depth" value="3" />
<property name="hibernate.hbm2ddl.auto" value="update" />
<property name="hibernate.show_sql" value="true" />
</properties>
</persistence-unit>
</persistence>
Eclipse, points an error at line: java:jboss/datasources/ExampleDS
Error is as follows:
cvc-complex-type.2.4.a: Invalid content was found starting with element 'jta-data-source'. One of '{"http://java.sun.com/xml/ns/persistence":class, "http://java.sun.com/
xml/ns/persistence":exclude-unlisted-classes, "http://java.sun.com/xml/ns/persistence":shared-cache-mode, "http://java.sun.com/xml/ns/persistence":validation-mode,
"http://java.sun.com/xml/ns/persistence":properties}' is expected.
I searched for similar errors and all the resolutions said that either the order of xml elements were important, which I checked or the jndi name should match with standalone.xml, which does match.
Can someone help me with this?

The right order of XML elements (according to schema document) is:
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>java:jboss/datasources/ExampleDS</jta-data-source>
<class>com.sample.model.Property</class>

Related

Dotnet framework - Nlog configuration change using variable substitution in TFS cd pipeline

I have Nlog configuration in the web config file and I would like to change the file path in the CD pipeline in order to put some dynamic path based on the environment.
Right now the web.config file variable substitution (XML Variable Substitution option) does not support it.
What are the other ways this can be done? I really don't have a choice to go the Web.Config transformation approach.
Any guidance on this will really help.
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
autoReload="true"
throwExceptions="false"
internalLogLevel="Error" internalLogFile="c:\Logs\nlog-internal.log">
<targets name="nlogconfig" async="true">
<target xsi:type="File" name="name"
fileName="Path/${shortdate}.log"
archiveFileName="Path/${shortdate}.{###}.log"
layout="${longdate} ${uppercase:${level}} ${callsite:className=true:includeSourcePath=true:methodName=true:skipFrames=1:cleanNamesOfAnonymousDelegates=true} ${newline} ${message} ${newline} ${exception:innerFormat=ToString:maxInnerExceptionLevel=2:innerExceptionSeparator=newline:separator=newline:format=ToString,StackTrace}${newline}"
archiveAboveSize="8388608"
archiveNumbering="Rolling"
archiveEvery="Day"
concurrentWrites="true"
maxArchiveFiles="100" />
</targets>
<rules>
<logger name="*" minlevel="Debug" writeTo="name" />
</rules>
</nlog>
What are the other ways this can be done?
You could use the Replace Token task from Replace Tokens Extension.
Here are my steps, you could refer to them:
Nlog configuration:
<targets>
<target name="logfile" xsi:type="File" fileName="#{variable}#/#{shortdate}#.log />
<target name="logconsole" xsi:type="Console" />
</targets>
Replace Token task sample:
- task: replacetokens#3
inputs:
rootDirectory: 'Folder Path'
targetFiles: '**/*.config'
encoding: 'auto'
writeBOM: true
actionOnMissing: 'warn'
keepToken: false
tokenPrefix: '#{'
tokenSuffix: '}#'
useLegacyPattern: false
enableTelemetry: true
Variable:
Then the variables in Nlog configuration will be replaced.
Alternative solution is to deploy an environment-specific override-file next to the default NLog.config.
Example of environment-specific NLog.override.config:
<nlog>
<variable name="LogDirectory" value="D:/Path" />
</nlog>
Example of NLog.config:
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<variable name="LogDirectory" value="${basedir}" /> <!-- Default Value -->
<include file="NLog.override.config" ignoreErrors="true" /> <!-- Override Value -->
<targets async="true">
<target xsi:type="File" name="name" fileName="${LogDirectory}/${shortdate}.log" />
</targets>
<rules>
<logger name="*" minlevel="Debug" writeTo="name" />
</rules>
</nlog>
The deployment-package could include multiple nlog.override.config-files. One for each environment and just deploy the right one based on chosen environment.
See also: https://github.com/nlog/nlog/wiki/Configuration-file#include-files

WSO2 API Manager 2.0.0- Receive GET request and send POST to backend

I've created an RESTful API in wso2-am 2.0.0. But I'm face a problem and a would some help.
I have a resource wiht GET http method which receive an url param and I made a SOAP payload to send via POST to backend (backend is soap11).
For this, I used a custom 'in' sequence:
<?xml version="1.0" encoding="UTF-8"?>
<sequence name="JSONtoSOAP" trace="disable"
xmlns="http://ws.apache.org/ns/synapse">
<log description="Entrada" level="full" separator=",">
<property expression="get-property('uri.var.cpfCnpj')" name="cpfcnpj" />
<property name="trace"
value="IN LOG" />
</log>
<property name="HTTP_METHOD" value="POST" scope="axis2" type="STRING" />
<property name="messageType" scope="axis2" type="STRING"
value="application/soap+xml" />
<enrich>
<source type="inline">
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body />
</soap:Envelope>
</source>
<target action="replace" type="envelope" />
</enrich>
<payloadFactory media-type="xml">
<format>
<man:QueryCustomerDetailsRequestMessage
xmlns:man="http://www.algartelecom.com.br/SOA/Service/ManageCustomerInformationPortalClientesReqCS">
<man:documentNumber>$1</man:documentNumber>
<man:tagetCRM />
</man:QueryCustomerDetailsRequestMessage>
</format>
<args>
<arg evaluator="xml" expression="get-property('uri.var.cpfCnpj')" />
</args>
</payloadFactory>
<property name="REST_URL_POSTFIX" value="" scope="axis2" />
<header name="Action" scope="default" value="queryCustomerDetails" />
<log description="Saida" level="full" separator=",">
<property name="trace" value="DEBUG LOG" />
</log>
</sequence>
Until here, without problem.
But when I try to call the resource from any restClient (SOAPui for example or wso2-am store) result in Runtime exception, like this:
<?xml version='1.0' encoding='UTF-8'?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<am:fault xmlns:am="http://wso2.org/apimanager">
<am:code/>
<am:type>Status report</am:type>
<am:message>Runtime Error</am:message>
<am:description/>
</am:fault>
</soap:Body>
</soap:Envelope>
Note that code and description tags are empty, and when I checked the server's log I found:
[2016-09-30 16:53:44,603] INFO - LogMediator STATUS = Executing default 'fault' sequence, ERROR_CODE = null, ERROR_MESSAGE = null
This is the correct way to produces a restful API and call a SOAP backend?
Anybody knows about this issue? (I believe, this feature works on WSO2 ESB).
You can try the following:
In the publisher, set your endpoint type to HTTP/SOAP endpoint
In your sequence don't set the REST_URL_POSTFIX to "", but remove the property completely

maven-antrun-plugin generating emty ddl file

I would like to generate schema sql script with maven.
Here is my persistance file :
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0"
xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="mypersistance"
transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"></property>
<property name="hibernate.archive.autodetection" value="class"></property>
</properties>
<description>Persistance descriptor</description>
<class>test.sofiane.beans.Code</class>
</persistence-unit>
</persistence>
hibernate configuration file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory name="mySessionFactory">
<property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
<property name="hibernate.connection.password">root</property>
<property name="hibernate.connection.url">jdbc:postgresql://localhost:5432/test</property>
<property name="hibernate.connection.username">postgres</property>
<property name="hibernate.default_schema">public</property>
<property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.format_sql">true</property>
</session-factory>
</hibernate-configuration>
plugin in the pom
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<!-- Hibernatetool will generate everything before running tests -->
<phase>compile</phase>
<configuration>
<target>
<echo message="Ant target, through maven-antrun-plugin, started" />
<property name="maven_compile_classpath" refid="maven.compile.classpath" />
<property name="maven_test_classpath" refid="maven.test.classpath" />
<path id="hibernatetool.path">
<pathelement path="${maven_compile_classpath}" />
<pathelement path="${maven_test_classpath}" />
</path>
<taskdef name="hibernatetool" classname="org.hibernate.tool.ant.HibernateToolTask"
classpathref="hibernatetool.path" />
<property name="generatedByHibernate.outputDirectory"
value="${project.build.directory}/generated/hibernatetool" />
<mkdir dir="${generatedByHibernate.outputDirectory}" />
<hibernatetool destdir="${generatedByHibernate.outputDirectory}">
<classpath>
<path location="${project.build.directory}/classes/test/sofiane/beans" />
</classpath>
<configuration
configurationfile="${project.build.directory}/classes/hibernate.cfg.xml" />
<hbm2ddl export="true" drop="true" create="true"
outputfilename="helloworld.ddl" format="true" />
</hibernatetool>
<echo message="Ant target, through maven-antrun-plugin, terminated" />
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
The pom works fine and generate helloworld.ddl but empty unfortunately !
Any idea please ?
My first advice is that you should better use the hibernate3-maven-plugin instead of the maven-antrun-plugin because it includes everything that you need and is a lot more simple to use than all the configuration that you had to write with the maven-antrun-plugin (see here for more information about the hibernate3-maven-plugin).
And then, to fix your problem, I think that you can find the answer to your problem in this post and in the answer because it seems that all the elements given will lead you to make your configuration work good.
And don't forget to bind the run of the hibernate3-maven-plugin after the compile phase, on the process-classes phase for example (see Lifecycle Reference) and then just run mvn process-classes.

Not able to read environment variable in persistence.xml

I have a Maven3 project where I'm using the tomcat7-maven-plugin. I would like to set the path for the embedded database via an environment variable argument to the jvm.
Reading the variable with System.getenv("myDataDir") within a Java-Method returns the correct path.
But when I try to set the variable ${myDataDir} in my persistence.xml and then I start tomcat with "mvn tomcat:run" I get FileNotFoundExceptions because the variable is not replaced with the actual value (it says e.g. Cannot find path for ${myDataDir}\derby.log)
I don't know what's causing this - if it's the persistence provider (EclipseLink) that doesn't support this or if it's something else.
My persistence.xml looks like this:
<persistence xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd" version="2.0" xmlns="http://java.sun.com/xml/ns/persistence">
<persistence-unit name="myPersistence" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<properties>
<property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.EmbeddedDriver" />
<property name="javax.persistence.jdbc.url" value="jdbc:derby:${myDataDir}/DB;create=true;upgrade=true" />
<property name="javax.persistence.jdbc.user" value="admin" />
<property name="javax.persistence.jdbc.password" value="password" />
<property name="eclipselink.ddl-generation" value="create-tables" />
<property name="eclipselink.ddl-generation.output-mode" value="both" />
<property name="eclipselink.logging.level" value="SEVERE" />
<property name="eclipselink.logging.file" value="${myDataDir}/derby.log" />
<property name="eclipselink.application-location" value="${myDataDir}/dbScripts" />
</properties>
</persistence-unit>
</persistence>
EDIT:
I forgot to mention, that I'm in a Spring 3 Framework environment. According to the examples on the web, this should be capable of using environment variables in persistence.xml...
Using ${myDataDir} in a database URL is not valid, unless supported by your database, or unless you are translating the variable during your own build scripts.
What you can do is pass a properties map to Persistence.createEntityManagerFactory() that has the URL you want, that you must build at runtime in code.

ASP.NET MVC 2 + Common.Logging + NLog = Session_Start called for each request

After switching the logging library behind Common.Logging 2.1.1 from log4net to NLog 2.0 my ASP.NET MVC 2 application kept logging correctly, but it started calling the HttpApplication.Session_Start method for each request.
I'm trying to use NLog's File target with the following configuration files:
web.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<sectionGroup name="common">
<section
name="logging"
type="Common.Logging.ConfigurationSectionHandler, Common.Logging" />
</sectionGroup>
.
.
.
<configSections>
.
.
.
<common>
<logging>
<factoryAdapter type="Common.Logging.NLog.NLogLoggerFactoryAdapter, Common.Logging.NLog20">
<arg key="configType" value="FILE" />
<arg key="configFile" value="~/NLog.config" />
</factoryAdapter>
</logging>
</common>
</configuration>
NLog.config
<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<!--
See http://nlog-project.org/wiki/Configuration_file
for information on customizing logging rules and outputs.
-->
<targets async="true">
<target
name="f"
xsi:type="File"
fileName="${basedir}/bin/statistics/logs/${shortdate}.log"
layout="${longdate} ${uppercase:${level}} ${callsite} ${message}"/>
</targets>
<rules>
<logger name="*" minlevel="Trace" writeTo="f" />
</rules>
</nlog>
I have already tried the following:
Debugging the application. The ASP.NET_SessionId cookie is being sent to the server and the Session.SessionID property is not changing between requests.
Switching back to Common.Logging - log4net to verify that the problem is related to Common.Logging - NLog. It works.
Omitting the async="true" attribute in the targets node of the configuration file of NLog to disable the AsyncWrapper of NLog. It doesn't work.
Using other NLog targets, tried Debugger and Database. It works.
I need to hold to the File target and I'd like to use NLog.

Resources