Can not validate XML - java

I am trying to create a camel route in spring boot. I get the following error.
Caused by: org.xml.sax.SAXParseException: s4s-elt-character: Non-whitespace characters are not allowed in schema elements other than 'xs:appinfo' and 'xs:documentation'. Saw '301 Moved Permanently'.
My applicationContext.xml looks like this.
<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.0.0"
xmlns:jaxws="http://cxf.apache.org/blueprint/jaxws"
xmlns:cxf="http://cxf.apache.org/blueprint/core"
xmlns:camel="http://camel.apache.org/schema/blueprint"
xmlns:camelcxf="http://camel.apache.org/schema/blueprint/cxf"
xmlns:http-conf="http://cxf.apache.org/transports/http/configuration"
xsi:schemaLocation="http://cxf.apache.org/transports/http/configuration
http://cxf.apache.org/schemas/configuration/http-conf.xsd
http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
http://camel.apache.org/schema/cxf http://camel.apache.org/schema/cxf/camel-cxf.xsd
http://cxf.apache.org/blueprint/jaxws http://cxf.apache.org/schemas/blueprint/jaxws.xsd
http://cxf.apache.org/blueprint/core http://cxf.apache.org/schemas/blueprint/core.xsd"
default-activation="lazy">
<!-- CXF SERVER -->
<camelcxf:rsServer id="productRestController"
address="http://0.0.0.0:8080/product"
serviceClass="com.born.oktopus.product.controller.ProductRestController"
loggingFeatureEnabled="true" loggingSizeLimit="20" >
<!-- <cxf:schemaLocations> <value>classpath:/schemas/productDataList.xsd</value>
</cxf:schemaLocations> <camelcxf:providers> <ref component-id="jaxbProviderXsi"
/> </camelcxf:providers> -->
</camelcxf:rsServer>
<!-- ERP BEANS -->
<bean id="loggingOutInterceptor"
class="org.apache.cxf.interceptor.LoggingOutInterceptor" >
<property name="prettyLogging" value="true" />
</bean>
</blueprint>

It sounds like you are trying to validate a transformation file with an XML file instead of an XSD as the applicationContext.xml appears correct.
You need to show us the JAVA code where you are parsing with SAX, but I would guess you either have a typo of some kind or you are thinking you are parsing the XSD file, but you reference the XML file.

Related

How do I load a Camel Property into a Bean?

I have been reading the following page on Camel properties: http://camel.apache.org/using-propertyplaceholder.html and also reading the book "Camel In Action".
I found Chapter 6 of "Camel In Action" very helpful in defining Camel properties, and I can load the following three properties from my config.properties:
config.timeout=10000
config.numSamples=1000
config.defaultViz=a
When I run my Java code I'm able to see the following three values inside my camel route in my applicationContext.xml, as shown in the thread#0 messages below:
14669 [Camel (HelloWorldContext) thread #0 - timer://hello.world.request.timer] INFO route1 - printing values read from config.properties file
14669 [Camel (HelloWorldContext) thread #0 - timer://hello.world.request.timer] INFO route1 - config.timeout= 10000
14669 [Camel (HelloWorldContext) thread #0 - timer://hello.world.request.timer] INFO route1 - config.numSamples= 1000
14670 [Camel (HelloWorldContext) thread #0 - timer://hello.world.request.timer] INFO route1 - config.defaultViz= a
However, when I try to pass the variable {{config.defaultViz}} to a String called defaultViz in my SensorGenerator Java class, and print that string I get "{{config.defaultViz}}" on the console instead of the value contained within {{config.defaultViz}}.
In other words, here's what I see on the screen:
Returning List
defaultViz= {{config.defaultViz}}
But I really want to see this on the screen:
Returning List
defaultViz=a
So what am I doing wrong in my applicationContext.xml?
UPDATED: The issue was that I needed to add a Bridge between Spring and Camel as outlined in the link I referenced above.
Here's my UPDATED applicationContext.xml with the bridge:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:camel="http://camel.apache.org/schema/spring"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<bean
class="org.springframework.context.annotation.CommonAnnotationBeanPostProcessor" />
<context:component-scan base-package="com.data.world2" />
<context:annotation-config />
<camel:camelContext id="HelloWorldContext">
<!-- Add Jackson library to render Java Map into JSON -->
<camel:dataFormats>
<camel:json id="jack" library="Jackson"/>
</camel:dataFormats>
<camel:route>
<!-- sends a request to the hello world JMS queue every 10 seconds -->
<camel:from
uri="timer://hello.world.request.timer?fixedRate=true&period={{config.timeout}}" />
<camel:to uri="log:hello.world.request?level=INFO&showAll=true" />
<camel:bean ref="helloWorld" />
<!-- now print out the map in JSON format -->
<camel:marshal ref ="jack"/>
<camel:convertBodyTo type="java.lang.String" />
<camel:log message="${body}"/>
<!-- print out values read from config.properties file -->
<camel:log message="printing values read from config.properties file"/>
<camel:log message="config.timeout= {{config.timeout}}"/>
<camel:log message="config.numSamples= {{config.numSamples}}"/>
<camel:log message="config.defaultViz= {{config.defaultViz}}"/>
<!-- now log the message -->
<camel:to uri="log:hello.world.response?level=INFO&showAll=true" />
</camel:route>
</camel:camelContext>
<!-- creates a java.util.Properties instance with values loaded from the supplied location -->
<util:properties id="sensorProperties" location="classpath:/sensor.properties"/>
<!-- pass in sensor.properties and defaultViz from config.properties -->
<bean class="com.data.world2.SensorGenerator">
<property name="sourceProperties" ref="sensorProperties" />
<property name="defaultViz" value="${config.defaultViz}"/>
</bean>
<!-- declare a Spring bean to use the Camel Properties component in Spring XML -->
<bean id="properties"
class="org.apache.camel.component.properties.PropertiesComponent">
<property name="location" value="classpath:config.properties"/>
</bean>
<!-- bridge spring property placeholder with Camel -->
<!-- you must NOT use the <context:property-placeholder at the same time, only this bridge bean -->
<bean id="bridgePropertyPlaceholder" class="org.apache.camel.spring.spi.BridgePropertyPlaceholderConfigurer">
<property name="location" value="classpath:config.properties"/>
</bean>
</beans>
I found this question that is similar but not quite the same: Injecting property into bean
The {{}} notation just works inside the routes (ie inside the XML camel contexts). To use it in the bean I think you need to define the property placeholder bridge that camel provides but in your bean use the ${} notation. The explanation of how to use that bridge is in the link you have provided.

Spring Framework: The document type declaration for root element type "beans" must end with '>'

This is my spring.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans SYSTEM "http://www.springframework.org/dtd/spring-beans-2.0.dtd" PUBLIC "-//SPRING//DTD BEAN 2.0//EN">
<beans>
<bean id="data" class="com.blah.tests.DataProviderClass" />
<bean id="wdcm" class="com.blah.tests.WebDriverCustomMethods"/>
</beans>
When I run my application test, this is the error I get:
Caused by: org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException:
Line 2 in XML document from class path resource [spring.xml] is invalid; nested exception is org.xml.sax.SAXParseException;
lineNumber: 2; columnNumber: 82; The document type declaration for root element type "beans" must end with '>'.
Im using Spring 3.0.7
Try this...
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd" >
<bean id="data" class="com.blah.tests.DataProviderClass" />
<bean id="wdcm" class="com.blah.tests.WebDriverCustomMethods"/>
</beans>
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
<!-- <bean/> definitions here -->
</beans>
Actually the DTD style is still fully supported:
http://static.springsource.org/spring/docs/3.0.x/reference/xsd-config.html
DTD support?
Authoring Spring configuration files using the older DTD style is still fully supported.
Nothing will break if you forego the use of the new XML Schema-based approach to authoring >Spring XML configuration files. All that you lose out on is the opportunity to have more >succinct and clearer configuration. Regardless of whether the XML configuration is DTD- or >Schema-based, in the end it all boils down to the same object model in the container (namely >one or more BeanDefinition instances).
according to your issue, this is maybe caused by the network, did you try to open http://www.springframework.org/dtd/spring-beans-2.0.dtd directly in the browser?(I think you will get error when you open http://www.springframework.org/dtd/spring-beans-2.0.dtd directly in the browser.)

Loading an xml file only once in spring

In spring, how would I go about loading an XML file once such that I can reference the file in my controller actions and not have to load it up again and again.
Create a bean whose sole purpose is to read your XML file and has the desired accessor methods, and inject it into your controller.
In Spring , all beans are initialized as Singleton unless specified . You could inject the properties from your XML file as follows
The xml file format for the properties is as below.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
<properties>
<entry key="key1">Value 1</entry>
<entry key="key2">Value 2</entry>
</properties>
you can use
<context:property-placeholder
location="classpath:/com/myProject/spring_prop.xml" />
<bean id="bean" class="org.MyBean">
<property name="key1" value="${key1}" />
</bean>
Or read the XML files in an #PostConstruct method via a bean as #Jens has mentioned .

Spring Webflow 2.3.0 Samples unstartable... No Idea how to fix

I'm currently evaluating Spring (with a focus on WebFlow) for future projects. After reading lots of docs and articles (most of which didn't help much) I downloaded the current release of Spring WebFlow (2.3.0 at the time of writing) and tried to get the samples running. Apart from solvable, yet frustrating, dependency- and classpath-issues, I hit the first roadblock with the config-files distributed with the samples. First of all, the webflow-config.xml of the booking-mvc-sample isn't even valid.
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:webflow="http://www.springframework.org/schema/webflow-config"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/webflow-config
http://www.springframework.org/schema/webflow-config/spring-webflow-config.xsd">
<!-- Executes flows: the entry point into the Spring Web Flow system -->
<webflow:flow-executor id="flowExecutor">
<webflow:flow-execution-listeners>
<webflow:listener ref="securityFlowExecutionListener" />
</webflow:flow-execution-listeners>
</webflow:flow-executor>
<!-- The registry of executable flow definitions -->
<webflow:flow-registry id="flowRegistry" flow-builder-services="flowBuilderServices" base-path="/WEB-INF">
<webflow:flow-location-pattern value="/**/*-flow.xml" />
</webflow:flow-registry>
<!-- Plugs in a custom creator for Web Flow views -->
<webflow:flow-builder-services id="flowBuilderServices" view-factory-creator="mvcViewFactoryCreator"
development="true" validator="validator" />
<!-- Configures Web Flow to use Tiles to create views for rendering; Tiles allows for applying consistent layouts to your views -->
<bean id="mvcViewFactoryCreator" class="org.springframework.webflow.mvc.builder.MvcViewFactoryCreator">
<property name="viewResolvers" ref="tilesViewResolver"/>
<property name="useSpringBeanBinding" value="true" />
</bean>
<!-- Installs a listener to apply Spring Security authorities -->
<bean id="securityFlowExecutionListener" class="org.springframework.webflow.security.SecurityFlowExecutionListener" />
<!-- Bootstraps JSR-303 validation and exposes it through Spring's Validator interface -->
<bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean"/>
</beans>
cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'webflow:flow-executor'.
cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'webflow:flow-registry'.
cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'webflow:flow-builder-services'.
Changing http://www.springframework.org/schema/webflow-config/spring-webflow-config.xsd to http://www.springframework.org/schema/webflow-config/spring-webflow-config-2.3.xsd removes the validation errors from Eclipse but the SAXParser still complains at startup.
Is there any way around it? Can someone help me out with a working config or point to a working tutorial (either a correct one if it's the samples fault or one that shown me how to setup SWF correctly if I'm doing it wrong)?
Right now I'm not far from dumping SWF from our list of possible frameworks as "not running out of the box" and - looking at the userbase and prevalence of Spring, this is somehow hard to believe.
Thanks a lot.

Spring and JMS Integration Configuration file error

I keep having this error when I'm trying to integrate Spring JMS into my current project. It's driving me up the wall and I'm not entirely sure how to fix it as I'm new to Spring.
The prefix "jms" for element "jms:listener-container" is not bound.
The code in question is this,
<jms:listener-container container-type="default" connection-factory="connectionFactory" acknowledge="auto">
<jms:listener destination="TESTQUEUE" ref="simpleMessageListener" method="onMessage" />
</jms:listener-container>
I'm pretty sure it has to do with the jms: namespace but I don't know how to fix it as before my program was complaining about the p: namespace so I had to change it to property name="some value" reference="someReference"
Make sure you have the jms namespace in your context file:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jms="http://www.springframework.org/schema/jms"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/jms http://www.springframework.org/schema/jms/spring-jms-3.0.xsd">
<!-- <bean/> definitions here -->
</beans>
See http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/jms.html for details.

Categories

Resources