Posts Tagged ‘XSD’
(long tweet) This page calls for XML namespace declared with prefix body but no taglibrary exists for that namespace.
Case
On creating a new JSF 2 page, I get the following warning when the page is displayed:
Warning: This page calls for XML namespace declared with prefix body but no taglibrary exists for that namespace.
Fix
In the XHTML page, replace the HTML 4 headers:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html>...</html>
with XHTML headers:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html"> ...</html>
Why “contract first” approach won’t work with CXF or SpringWS for Axis-generated WSDLs
Case
My previous subject was the following: considering a WSDL that was generated by Axis 2, develop a webservice with CXF and/or SpringWS in “contract first” (ie the contract seen as an API is given, Java code comes afterwards) approach.
It cannot work easyly, unless you are ready to spend time, money and energy in creating adapters and adding layers in your application architecture.
CXF
With CXF, the first step is to generate Java code with the wsdl2java embeded in Maven CXF plugin. The output is explicit:
Failed to execute goal org.apache.cxf:cxf-codegen-plugin:2.6.1:#wsdl2java on project PocEjb3: Rpc/encoded wsdls are not supported with #CXF
(cf my tweet)
RPC vs Encoded
Actually, the SOAP envelope has two ways to transport the message: RPC and Document. More detail is available here: Which style of WSDL should I use?
Axis 2 generates RPC/encoded webservice ; this method is deprecated, CXF does not support it.
Spring WS
I then tried to use Spring WS. I thought “Spring WS is only contract-first, it should work”. The first pitfall I fell on was that SpringWS bases on XSD files, not on actual WSDL. For instance, if you follow SpringWS tutorial, you will find such a block:
<sws:dynamic-wsdl id="holiday" portTypeName="HumanResource" locationUri="/holidayService/" targetNamespace="http://mycompany.com/hr/definitions"> <sws:xsd location="/WEB-INF/hr.xsd"/> </sws:dynamic-wsdl>
To workaround, you can specify use tag, such as:
<sws:static-wsdl id="precomputed-holiday" location="/WEB-INF/precomputed-holiday.wsdl"/>
Anyway, the next issue appears: SpringWS expects to deal with document
webservices, ie blocks like:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sch="http://mycompany.com/hr/schemas"> <soapenv:Header/> <soapenv:Body> <sch:HolidayRequest> <!--You may enter the following 2 items in any order--> <sch:Holiday> <sch:StartDate>?</sch:StartDate> <sch:EndDate>?</sch:EndDate> </sch:Holiday> <sch:Employee> <sch:Number>?</sch:Number> <sch:FirstName>?</sch:FirstName> <sch:LastName>?</sch:LastName> </sch:Employee> </sch:HolidayRequest> </soapenv:Body> </soapenv:Envelope>>
whereas Axis-generated WSDL look like:
<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:int="http://interfaces.api.lalou.jonathan"> <soapenv:Header/> <soapenv:Body> <int:sayHello soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/> </soapenv:Body> </soapenv:Envelope>
In other words, I have just fallen on the exact same issue as with CXF: SpringWS cannot support RPC/encoded
WSDLs.
Spring / Mule / CheckExclusiveAttributesException: The attributes of Element … do not match the exclusive groups …
Case
I have the following block in my Mule config file:
<servlet:inbound-endpoint path="authenticationService" address="http://localhost:1234">
. Even though this block matches XSD constraints, it is illegal from a functionnal point of view.
I get the following stacktrace:
Offending resource: mule-config.xml; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from class path resource [lalou/jonathan/mule-config.xml]; nested exception is org.mule.config.spring.parsers.processors.CheckExclusiveAttributes$CheckExclusiveAttributesException: The attributes of Element servlet:inbound-endpoint{address=http://localhost:1234, name=.authenticationService:inbound.157:inbound-endpoint.158, path=authenticationService} do not match the exclusive groups [address] [ref] [path]
Explanation and Fix
The exception is meaningful: for the tag <servlet:inbound-endpoint
>, only one among the three following attributes is needed: path, ref and address.
To fix the issue, keep only the relevant attribute.
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!
Useful XSD
Following the post on widely used DTDs, here is a list of some XSD (aka XML Schemas):
File | XSD |
---|---|
Maven pom.xml |
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> |
weblogic.xml |
<weblogic-web-app xmlns="http://www.bea.com/ns/weblogic/weblogic-web-app" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.bea.com/ns/weblogic/weblogic-web-app http://www.bea.com/ns/weblogic/weblogic-web-app/1.0/weblogic-web-app.xsd"> |
Maven assembly.xml |
<assembly xmlns="http://maven.apache.org/xsd/1.1.0/assembly" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/xsd/assembly-1.1.2.xsd http://maven.apache.org/xsd/1.1.2/assembly"> |
web.xml |
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> |
EhCache |
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> |