generate seriallized jaxb objects - maven-jaxb2-plugin

I have read couple of post on how we can generate serilazed jaxb
objects i got the configuration
<jxb:bindings version="1.0"
xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
jxb:extensionBindingPrefixes="xjc">
<jxb:bindings schemaLocation="mirth.xsd" node="/xs:schema">
<jxb:globalBindings>
<xjc:superClass name="com.webreach.mirth.managers.types.MirthElement" />
<xjc:serializable />
</jxb:globalBindings>
</jxb:bindings>
</jxb:bindings>
As per my knowledge I cannot add this configuration in my POM.xml Can
anybody suggest me where i can add this configuration??

Indeed you cannot add this jxb:bindings element into your pom.xml file. In the pom.xml you can define the maven-jaxb2-plugin that can refer to the bindings.xml file. You can find some helpfull material here
JAXB Bindings to schemas in a JAR
http://mojo.codehaus.org/jaxb2-maven-plugin/index.html

Related

PhpStorm unable to resolve symbol 'doctrine.orm.entity_manager'

When I open the services.xml in PhpStorm with Symfony Plugin enabled, it's able to resolve all the services, I can Ctrl+Click and go the Service Definition , except doctrine.orm.entity_manager.
It says unable to resolve symbol 'doctrine.orm.entity_manager'
Here is the services.xml file
<?xml version="1.0" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<service id="example_manager" class="Vendor\XysBundle\Manager\ExampleManager">
<argument type="service" id="doctrine.orm.entity_manager" />
</service>
</services>
</container>
PhpStorm Details:
PhpStorm 2016.3.1
Build #PS-163.9735.1, built on December 6, 2016
JRE: 1.8.0_112-release-408-b2 amd64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
appDevDebugProjectContainer.xml file exists in the app/cache directory .
How can I get get this working ?
I have the same issue. If you open up the vendor\doctrine\doctrine-bundle\Resources\config\orm.xml file where doctrine services are defined, you can see, there is no service with the id "doctrine.orm.entity_manager" but only "doctrine.orm.entity_manager.abstract"
The definition looks like:
<service id="doctrine.orm.entity_manager.abstract" class="%doctrine.orm.entity_manager.class%" abstract="true" />
As you can see the abstract attribute is set to true. This means this service can serve as a parent of other services, and when you define child services with this abstract parent you don't have to define the method calls or the parameters injected into the constructor for example, instead these definitions will be inherited from the parent.
If you investigate a bit deeper you will find that %doctrine.orm.entity_manager.class% is defined in the same file as a parameter that actually references to the Doctrine Entity Manager:
<parameter key="doctrine.orm.entity_manager.class">Doctrine\ORM\EntityManager</parameter>
So I guess we should use doctrine.orm.entity_manager.abstract, however doctrine.orm.entity_manager is recognised as well, although I don't know how.
For further explanation of abstract service definitions have a look at this Symfony doc page: https://symfony.com/doc/current/service_container/parent_services.html

Thymeleaf - Strict HTML parsing issue

HTML5 allows some tags to be written more liberally i.e without corresponding END tags. e.g. input need not be closed </input>.However if choose template mode HTML5 in Thymeleaf the Thymeleaf engine complains about this and does not parse the HTML template. I want to override this default Strict tag checking behavior. i.e Thymeleaf should parse an HTML template with meta and input (AND ALIKE) tags WITHOUT THEIR RESP. CLOSING TAGS. Pl. guide.
It also complains when you have something like this
<a href="/home/pic/image.png" download="/path/to/file" data-gallery></a>
It throws an exception when it encounters the data-gallery throws "should be followed by '=' " which is kind of annoying as it takes the flexibility out of HTML5.
All you have to do is run Thymeleaf in "LEGACYHTML5" mode and it works like a charm. Thanks to this and this post, I found the solution and am documenting in SO so others do not have to go through the same trouble in finding this answer.
To set the legacy mode you can define the bean in your Spring XML file:
<!-- View TemplateResolver -->
<bean id="templateResolver" class="org.thymeleaf.templateresolver.ServletContextTemplateResolver">
<property name="templateMode" value="LEGACYHTML5"/>
<property name="cacheable" value="false"/>
</bean>
or add the properties to the application.properties file:
spring.thymeleaf.mode=LEGACYHTML5
spring.thymeleaf.cache=false
And in both cases you have to add the nekohtml jar to your project or, if you are running maven, you can add its dependency to your pom.xml
<dependency>
<groupId>net.sourceforge.nekohtml</groupId>
<artifactId>nekohtml</artifactId>
<version>1.9.21</version>
</dependency>
Gradle
'net.sourceforge.nekohtml:nekohtml:1.9.21'
Here is how you can do it in a neat way
Step 1: Add thymeleaf mode to your application.properties file.
resources/application.properties
spring.thymeleaf.mode=LEGACYHTML5
Step 2: Add nekohtml dependency to your pom.xml file.
pom.xml
<dependency>
<groupId>net.sourceforge.nekohtml</groupId>
<artifactId>nekohtml</artifactId>
</dependency>
Using LEGACYHTML5 worked for me as well.
Also it is necessary to add
<dependency>
<groupId>net.sourceforge.nekohtml</groupId>
<artifactId>nekohtml</artifactId>
</dependency>
to pom.xml as stated above. But there is one more step which might occur. After doing those two steps I was getting:
java.lang.NoClassDefFoundError: org/w3c/dom/ElementTraversal
To avoid this it is necessary to add
<dependency>
<groupId>xml-apis</groupId>
<artifactId>xml-apis</artifactId>
<version>1.4.01</version>
</dependency>
to pom.xml

CAstle Windsor: How to reference a second xml config file that is an embedded resource?

We have one xml configuration file that we use in production. We also have a little test app that has a couple of additional needs. What I'd like to do is create a second, testing-only xml config file that references the embedded production configuration file. Is there any way to do this?
I'm aware of the "include" element, but am not sure where in the file it is supposed to be placed--in the castle node? The components node?
I feel like the answer is here but I'm too dense to figure it out.
Thanks for any help you can provide.
UPDATE
This is how our production config file is set up:
<?xml version="1.0" encoding="utf-8"?>
<OurCompany>
<Framework>
<castle>
<installers>
<!-- some installers-->
<installers>
<components>
<!--some components-->
<components>
<castle>
<Framework>
<OurCompany>
My most recent attempt at a non-production config file looks like this:
<?xml version="1.0" encoding="utf-8"?>
<OurCompany>
<Framework>
<castle>
<include uri="assembly://AssemblyContainingEmbeddedXml/MyEmbeddedConfig.xml" />
<components>
<!--components I only want registered with container when running in non-production environment-->
<components>
<castle>
<Framework>
<OurCompany>
The exception I get reads:
Configuration parser encountered Framework, but it was expecting to find installers, facilities or components. There might be either a typo on or you might have forgotten to nest it properly.
(In the actual message, "Framework," "installers," "facilities," and "components" are enclosed in angle brackets.)
The bottom of the page you reference has an example of loading from an embedded resourced:
IResource resource = new AssemblyResource("assembly://Acme.Crm.Data/Configuration/services.xml");
container = new WindsorContainer(new XmlInterpreter(resource));

Quartz.net Setup Throwing Error: "onfiguration parser encountered <job>"

I have a Asp.net C# MVC 3 application implementing the Sharp Architecture. I have been trying to get Quartz.net to setup and work nicely with Castle Windsor for a few days without any luck. Based on what I know, I have setup everything correctly, but continue to have issues.
In my Global.cs file, creating my Container and trying to register quartz jobs:
var container = new WindsorContainer(new XmlInterpreter("quartz_jobs.xml"));
container.AddFacility("quartznet", new QuartzFacility());
In my quartz_jobs.xml file I have the following contents:
<?xml version="1.0" encoding="utf-8" ?>
<quartz xmlns="http://quartznet.sourceforge.net/JobSchedulingData"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
version="1.0"
overwrite-existing-jobs="true">
<job>
<job-detail>
<name>DeleteLoansWithoutClientsJob</name>
<job-type>EasyOptions.Web.Mvc.Code.Jobs.DeleteLoansWithoutClientsJob, EasyOptions.Web.Mvc</job-type>
<durable>true</durable>
</job-detail>
<trigger>
<cron>
<name>DeleteLoansWithoutClientsJobTrigger</name>
<group>MyJobs</group>
<description>A description</description>
<job-name>DeleteLoansWithoutClientsJob</job-name>
<job-group>MyJobs</job-group>
<cron-expression>0 0/1 * * * ?</cron-expression>
</cron>
</trigger>
</job>
Problem is, you're pointing Windsor to the Quartz.NET config file.
There are two separate configurations: Windsor's and Quartz.NET's. Windsor is usually configured with code nowadays (i.e. fluent config), though it still supports XML configuration. However the Quartz.NET facility doesn't currently support code config, you have to use Windsor's XML config (at least for this, other components/facilities may still be configured via code). Then there's Quartz.NET, usually configured via an external quartz_jobs.xml file.
I recommend using the Quartz.NET facility sample app as reference. In particular, here's the sample Windsor config and the sample Quartz.NET config.
EDIT: if Quartz.NET says it can't find quartz_jobs.xml in a web application you need to include the web root in the configuration path: "~/quartz_jobs.xml" (instead of plain "quartz_jobs.xml")
I've written a blog post on how to integrate Quartz.NET with an IoC container. My example code uses Castle Windsor.
The blog post can be found here: http://thecodesaysitall.blogspot.com/2012/02/integrate-quartznet-with-your-favourite.html

Matching namespaces on marshalling / unmarshalling in JAXB

Matching namespaces on marshalling / unmarshalling in JAXB
I use JAXB to marshall / unmarshall XML. If I marshall an XML file like this:
<om:RequestCreateEvent xmlns:om="http://ossj.org/xml/OrderManagement/v1-0" xmlns:v1="http://ossj.org/xml/Common/v1-5" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:v11="http://ossj.org/xml/Common-CBECore/v1-5" xmlns:v12="http://ossj.org/xml/Common-CBEBi/v1-5">
<om:event>
<v1:applicationDN>System/JSR264/ApplicationType/OrderManagement/Application/1-0;1-0-2;ReferenceImplementation/</v1:applicationDN>
<v1:eventTime>2008-11-12T07:39:34.896+01:00</v1:eventTime>
<om:requestValue xmlns:v1="http://ossj.org/xml/om/ri/omimpl/v1-0" xsi:type="v1:ProductOrderImplValue">
<v13:key xmlns:v1="http://ossj.org/xml/OrderManagement/v1-0" xmlns:v13="http://ossj.org/xml/Common/v1-5" xsi:type="v1:ProductOrderKey">
<v13:type>http://ossj.org/xml/om/ri/omimpl/v1-0#ProductOrderImplValue</v13:type>
<v13:primaryKey>12</v13:primaryKey>
</v13:key>
<v1:requestState>open.not_running.not_started</v1:requestState>
<v12:description xsi:nil="true"/>
</om:requestValue>
</om:event>
</om:RequestCreateEvent>
and then subsequently try to unmarshall it, I get this:
<ns4:RequestCreateEvent xmlns="http://ossj.org/xml/Common/v1-5" xmlns:ns2="http://ossj.org/xml/Common-CBECore/v1-5" xmlns:ns3="http://ossj.org/xml/Common-CBEBi/v1-5" xmlns:ns4="http://ossj.org/xml/OrderManagement/v1-0" xmlns:ns5="http://ossj.org/xml/om/ri/omimpl/v1-0" xmlns:ns6="http://ossj.org/xml/Common-CBEDatatypes/v1-5" xmlns:ns7="http://ossj.org/xml/Common-CBELocation/v1-5" xmlns:ns8="http://ossj.org/xml/Common-CBEResource/v1-5" xmlns:ns9="http://ossj.org/xml/Common-CBEService/v1-5" xmlns:ns10="http://ossj.org/xml/Common-CBEProduct/v1-5" xmlns:ns11="http://ossj.org/xml/Common-CBEProductOffering/v1-5" xmlns:ns12="http://ossj.org/xml/Common-CBEParty/v1-5">
<ns4:event>
<applicationDN>System/JSR264/ApplicationType/OrderManagement/Application/1-0;1-0-2;ReferenceImplementation/</applicationDN>
<eventTime>
2008-11-12T07:39:34.896+01:00</eventTime>
<ns4:requestValue xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ns5:ProductOrderImplValue">
<key xsi:type="ns4:ProductOrderKey">
<type>
http://ossj.org/xml/om/ri/omimpl/v1-0#ProductOrderImplValue</type>
<primaryKey/>
</key>
<ns5:requestState>open.not_running.not_started</ns5:requestState>
<ns3:description xsi:nil="true"/>
</ns4:requestValue>
</ns4:event>
</ns4:RequestCreateEvent>
I need to ensure that the prefixes used in the namespaces when I marshall the jaxb generated pojo to create the XML file match those used when
I unmarshall the same file.
Possibly there is a solution in using a NamespaceContext when I do the marshalling. However I cannot hard-code the prefixes and their uris in an implementation
of NamespaceContext because I do not have this information available to me(I use lots of schemas etc). So if I were to try and use a NamespaceContext I would need to be able to
get the prefixes and their uris from the JAXB unmarshaller which I cant seem to get.
So if anyone has any suggestions on a NamespaceContext solution or indeed some other approach I would appreciate it.
After a quick look at your XML documents that appear to be namespace qualified the same but use different prefixes. Different JAXB implementations provide different mechanisms for controlling the prefixes used, but will involve interaction on your part:
JAXB RI/Metro JAXB
The JAXB RI/Metro offer an extension called the NamespacePrefixMapper:
http://jaxb.java.net/guide/Changing_prefixes.html
EclipseLink JAXB (MOXy)
MOXy (I'm the tech lead) will use the prefixes specified in the #XmlSchema annotation. In the example below the atom prefix will be used for the http://www.w3.org/2005/Atom namespace URI.
javax.xml.bind.annotation.XmlSchema(
xmlns = {
#javax.xml.bind.annotation.XmlNs(prefix = "atom", namespaceURI = "http://www.w3.org/2005/Atom")
})
package org.example.domain;
How to customize namespace prefixes on Jersey(JAX-WS) (related question)