Search
Calendar
November 2017
S M T W T F S
« Sep    
 1234
567891011
12131415161718
19202122232425
2627282930  
Your widget title
Archives

Posts Tagged ‘XML’

PostHeaderIcon Spring: Failed to read schema document

Case

I try to deploy a Mule ESB configuration, using this XML:

<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xmlns:pattern="http://www.mulesoft.org/schema/mule/pattern"
 xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core
 http://www.mulesoft.org/schema/mule/core/3.1/mule.xsd
 http://www.mulesoft.org/schema/mule/pattern
 http://www.mulesoft.org/schema/mule/pattern/3.1/mule-pattern.xsd
 ">
 <pattern:simple-service name="authenticationService"
 address="http://localhost:1234/authenticationService"
 component-class="lalou.jonathan.esb.components.AuthenticationComponent"
 type="direct" />
</mule>

I get the following error:

Ignored XML validation warning
org.xml.sax.SAXParseException: schema_reference.4: Failed to read schema document 'http://www.mulesoft.org/schema/mule/pattern/3.1/mule-pattern.xsd'

Extended Stacktrace

2011-11-22 16:10:25,375 WARN  xml.XmlBeanDefinitionReader         - Ignored XML validation warning
org.xml.sax.SAXParseException: schema_reference.4: Failed to read schema document 'http://www.mulesoft.org/schema/mule/pattern/3.1/mule-pattern.xsd', because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not <xsd:schema>.
 at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:195)
 at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.warning(ErrorHandlerWrapper.java:96)
 at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:380)

Notice that Mule ESB files are similar to classic Spring files. Of course, I first checked the pointed XSD was actually reachable.
Anyway, this error should be raised when your application, for any reason -firewall, proxies, network interruption-, cannot access the remote site where the XSD is hosted.

Fix

  • Copy the XSD to a local folder
  • Create a file spring.schemas
  • Make it available in the classpath in META-INF.
  • Add the following line
  • http\://www.mulesoft.org/schema/mule/pattern/3.1/mule-pattern.xsd=WEB-INF/classes/mule-pattern.xsd

    The pattern is: missing resource (beware of escaping colon) = path in classpath of the local XSD

  • Rebuild, pack and run!

PostHeaderIcon Useful DTD

DTDs are useful when your XML editor take them in account: detecting errors, suggestions, complete statements… For instance, I save much time with IntelliJ IDEA automatic completion ; unlike, Eclipse amazingly does not implement this feature.

Here is a list of some widely used DTDs:

File DTD
weblogic-application.xml
<!DOCTYPE weblogic-application PUBLIC "-//BEA Systems, Inc.//DTD WebLogic Application 7.0.0//EN" "http://www.oracle.com/technology/weblogic/weblogic-application/1.1/weblogic-application.xsd">
weblogic-application.xml
<!DOCTYPE weblogic-application PUBLIC "-//BEA Systems, Inc.//DTD WebLogic Application 7.0.0//EN" "http://www.oracle.com/technology/weblogic/weblogic-application/1.1/weblogic-application.xsd">
web.xml
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "http://java.sun.com/dtd/web-app_2_3.dtd" >
*.hbm.xml
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
GWT modules
<!DOCTYPE module SYSTEM "http://google-web-toolkit.googlecode.com/svn/trunk/distro-source/core/src/gwt-module.dtd">
GWT UI
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
Tangosol / Oracle Coherence
<!DOCTYPE coherence SYSTEM "coherence.dtd">
Log4J
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">

Tangosol and Log4J DTDs are included within their distribution JARs: you have to extract them or to give their path to IntelliJ IDEA.

PostHeaderIcon Dynamic serviceUrl with Spring’s HttpInvokerProxyFactoryBean

Abstract

How to set dynamically the URL used by a HttpInvokerProxyFactoryBean in a Spring-deployed WAR?

Detailed Case

I have to deploy a GWT/GXT application, calling two distant services:
a remote EJB
a service accessed through Spring Remoting

Here is the Spring configuration file I firstly used:

  <util:properties id="jndiProperties" location="classpath:jndi.properties"/>
	<jee:remote-slsb id="myRemoteEJBService" jndi-name="ejb.remote.myRemoteService"
		business-interface="lalou.jonathan.myRemoteEJBService"
		environment-ref="jndiProperties" cache-home="false"
		lookup-home-on-startup="false" refresh-home-on-connect-failure="true" />

	<bean id="mySpringRemoteService"
		class="org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean">
		<property name="serviceInterface"
			value="lalou.jonathan.services.mySpringRemoteService" />
		<property name="serviceUrl" value="${spring.remote.service.url}"/>
	</bean>

Unhappily, even though the remote EJB is retrieved (which proves that the jndi file is available in the classpath and rightly loaded), the Spring Remote service is not. I had to write the URL in hard in the configuration file… This is not very efficient when you work in a large team, with different production and testings environments!

This is the log when myRemoteEJBService bean is loaded:

2010-08-17 16:05:42,937 DEBUG support.DefaultListableBeanFactory  - Creating shared instance of singleton bean 'myRemoteEJBService'
2010-08-17 16:05:42,937 DEBUG support.DefaultListableBeanFactory  - Creating instance of bean 'myRemoteEJBService'
2010-08-17 16:05:42,937 DEBUG support.DefaultListableBeanFactory  - Eagerly caching bean 'myRemoteEJBService' to allow for resolving potential circular references
2010-08-17 16:05:42,937 DEBUG support.DefaultListableBeanFactory  - Returning cached instance of singleton bean 'jndiProperties'
2010-08-17 16:05:42,937 DEBUG support.DefaultListableBeanFactory  - Invoking afterPropertiesSet() on bean with name 'myRemoteEJBService'
2010-08-17 16:05:42,937 DEBUG framework.JdkDynamicAopProxy        - Creating JDK dynamic proxy: target source is EmptyTargetSource: no target class, static
2010-08-17 16:05:42,953 DEBUG support.DefaultListableBeanFactory  - Finished creating instance of bean 'myRemoteEJBService'

That is the log when mySpringRemoteService is loaded:

2010-08-17 16:05:42,968 DEBUG support.DefaultListableBeanFactory  - Creating shared instance of singleton bean 'mySpringRemoteService'
2010-08-17 16:05:42,968 DEBUG support.DefaultListableBeanFactory  - Creating instance of bean 'mySpringRemoteService'
2010-08-17 16:05:42,984 DEBUG support.DefaultListableBeanFactory  - Eagerly caching bean 'mySpringRemoteService' to allow for resolving potential circular references
2010-08-17 16:05:43,234 DEBUG support.DefaultListableBeanFactory  - Invoking afterPropertiesSet() on bean with name 'mySpringRemoteService'
2010-08-17 16:05:43,250 DEBUG framework.JdkDynamicAopProxy        - Creating JDK dynamic proxy: target source is EmptyTargetSource: no target class, static
2010-08-17 16:05:43,250 DEBUG support.DefaultListableBeanFactory  - Finished creating instance of bean 'mySpringRemoteService'

You can notice that no mention to jndiProperties appears. Here is the key of the problem: jndiProperties is considered as a bean among others, which cannot be accessed easyly from the HttpInvokerProxyFactoryBean.

Fix

To fix the issue, you have to add an actual property holder in Spring XML configuration file, ie after:

<util:properties id="jndiProperties" location="classpath:jndi.properties"/>

add an instanciation of PropertyPlaceholderConfigurer:

<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="location" value="classpath:jndi.properties"/>
    </bean>

PostHeaderIcon Unable to validate using XSD: Your JAXP provider does not support XML Schema

Here is the stacktrace that happened this morning:

Unable to validate using XSD: Your JAXP provider org.apache.crimson.jaxp.DocumentBuilderFactoryImpl@e6a73d does not support XML Schema. Are you running on Java 1.4 or below with Apache Crimson? Upgrade to Apache Xerces (or Java 1.5) for full XSD support.

To solve it, I had to remove the j2ee-X.X.jar from my project.xml Maven config file.

PostHeaderIcon Java, SAX, XML: About special characters encoding

Unlike what most people think, characters such as &eacute are not part of XML specification! And SAX follows rigorously this spec…

Read the rest of this entry »