axis-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michel Etienne <michel.etie...@dryade.net>
Subject Re: [AXIS2 1.4.1 - Xmlbeans] validating an input parameter with anyType in it
Date Thu, 03 Sep 2009 14:47:08 GMT
Hello

Since I had no answer yet, I repost my question .
Does anybody have an idea ?
Thanks

Best regards
Michel Etienne


Michel Etienne a écrit :
> Hello,
> I have a problem when I try to validate an input parameter with an 
> AnyType member
>
> I use Xmlbeans and I get this error on the server side (I made a 
> sample program to show the problem)
>
> 2009-07-06 16:23:16,109 [HttpConnection-8080-1]  
> WARN                    Server - >> Invalid object 
> demo.dryade.soap.impl.RequestDocumentImpl
> >> error: cvc-elt.4.2: Invalid xsi:type qname: 'typ:SpecificType' in 
> element RequestPart
> 2009-07-06 16:23:16,125 [HttpConnection-8080-1]  
> WARN                    Server - Invalid content =
> <soap:Request xmlns:soap="http://soap.dryade.demo" 
> xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
>  <RequestPart>
>    <typ:element6 xmlns:typ="http://types.dryade.demo">1</typ:element6>
>    <typ:element7 xmlns:typ="http://types.dryade.demo">test</typ:element7>
>    <typ:element8 xsi:type="typ:SpecificType" 
> xmlns:typ="http://types.dryade.demo" 
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
>      <typ:element4>true</typ:element4>
>      <typ:element5>any test</typ:element5>
>    </typ:element8>
>  </RequestPart>
> </soap:Request>
>
> if the server produce an output with the same AnyType , it validate 
> correctly :
> in an input-output transaction
>
> 2009-07-06 16:23:16,125 [HttpConnection-8080-1]  INFO Server - >> 
> Valid object demo.dryade.soap.impl.RequestResponseDocumentImpl
>
> in an ouput-only transaction
>
> 2009-07-06 16:23:16,250 [HttpConnection-8080-2]  INFO Server - >> 
> Valid object demo.dryade.soap.impl.NotifyDocumentImpl
>
> on the client side, the structures are always valid.
>
> I send you the entire code I used for this exemple; it is made with 
> AXIS2 1.4.1 on Windows XP platform with Java 1.6
>
> (I can send the entire project archive if necessary)
>
> Thanks for help
>
> Best regards
> Michel Etienne
>
-------------------------------------------------------------------------------------------------------------------------
> Server source :
>
> package demo.server;
>
> import org.apache.log4j.Logger;
>
> import java.util.ArrayList;
>
> import javax.xml.namespace.QName;
>
> import org.apache.xmlbeans.SchemaType;
> import org.apache.xmlbeans.XmlBeans;
> import org.apache.xmlbeans.XmlObject;
> import org.apache.xmlbeans.XmlOptions;
> import org.apache.xmlbeans.XmlValidationError;
> import org.apache.xmlbeans.impl.common.QNameHelper;
>
> import demo.dryade.soap.DemoServicesSkeletonInterface;
> import demo.dryade.soap.NotifyDocument;
> import demo.dryade.soap.RequestDocument;
> import demo.dryade.soap.RequestResponseDocument;
> import demo.dryade.soap.RequestResponseDocument.RequestResponse;
> import demo.dryade.types.ComplexType1;
> import demo.dryade.types.SpecificType;
>
> public class Server implements DemoServicesSkeletonInterface
> {
> /**
> * Logger for this class
> */
> private static final Logger logger = Logger.getLogger(Server.class);
>
> public static boolean checkXmlSchema(XmlObject object)
> {
> if (object == null)
> {
> logger.warn("validation null object");
> return false;
> }
> ArrayList<XmlValidationError> validationErrors = new 
> ArrayList<XmlValidationError>();
> XmlOptions validationOptions = new XmlOptions();
> validationOptions.setErrorListener(validationErrors);
>
> boolean validation = object.validate(validationOptions);
> if (!validation)
> {
> StringBuffer errorTxt = new StringBuffer(">> Invalid object 
> "+object.getClass().getName());
> for (XmlValidationError error : validationErrors)
> {
> errorTxt.append("\n >> ");
> errorTxt.append(error.toString());
> }
> logger.warn(errorTxt);
> logger.warn("Invalid content = \n"+object.toString());
>
> }
> else
> {
> logger.info(">> Valid object "+object.getClass().getName());
> }
> return validation;
> }
>
>
>
> @Override
> public RequestResponseDocument Request(RequestDocument request)
> {
> checkXmlSchema(request);
>
> RequestResponseDocument response = 
> RequestResponseDocument.Factory.newInstance();
> RequestResponse reqResponse = response.addNewRequestResponse();
>
> ComplexType1 part = reqResponse.addNewResponsePart();
>
> part.addElement1(12);
> part.setElement2("test");
>
> SpecificType elt3 = SpecificType.Factory.newInstance();
> elt3.setElement4(true);
> elt3.setElement5("any test");
> part.setElement3(elt3);
>
> checkXmlSchema(response);
>
> return response;
> }
>
>
>
> @Override
> public void Notify(NotifyDocument notify)
> {
> checkXmlSchema(notify);
> }
>
> }
>
-------------------------------------------------------------------------------------------------------------------------


>
> Client Source :
>
> package demo.client;
>
>
> import java.math.BigInteger;
> import java.util.ArrayList;
>
> import org.apache.log4j.Logger;
> import org.apache.xmlbeans.XmlObject;
> import org.apache.xmlbeans.XmlOptions;
> import org.apache.xmlbeans.XmlValidationError;
>
> import demo.dryade.soap.DemoServices;
> import demo.dryade.soap.DemoServicesStub;
> import demo.dryade.soap.NotifyDocument;
> import demo.dryade.soap.RequestDocument;
> import demo.dryade.soap.RequestResponseDocument;
> import demo.dryade.soap.NotifyDocument.Notify;
> import demo.dryade.soap.RequestDocument.Request;
> import demo.dryade.types.ComplexType1;
> import demo.dryade.types.ComplexType2;
> import demo.dryade.types.SpecificType;
>
> /**
> * @author michel
> *
> */
> public class Client
> {
> /**
> * Logger for this class
> */
> private static final Logger logger = Logger.getLogger(Client.class);
>
> public static boolean checkXmlSchema(XmlObject object)
> {
> if (object == null)
> {
> logger.warn("validation null object");
> return false;
> }
> ArrayList<XmlValidationError> validationErrors = new 
> ArrayList<XmlValidationError>();
> XmlOptions validationOptions = new XmlOptions();
> validationOptions.setErrorListener(validationErrors);
>
> boolean validation = object.validate(validationOptions);
> if (!validation)
> {
> StringBuffer errorTxt = new StringBuffer(">> Invalid object 
> "+object.getClass().getName());
> for (XmlValidationError error : validationErrors)
> {
> errorTxt.append("\n >> ");
> errorTxt.append(error.toString());
> }
> logger.warn(errorTxt);
> logger.debug("Invalid content = \n"+object.toString());
>
> }
> else
> {
> logger.info(">> Valid object "+object.getClass().getName());
> }
> return validation;
> }
>
>
> /**
> * @param args
> */
> public static void main(String[] args)
> {
> try
> {
>
> String endPointReference = 
> "http://localhost:8080/axis2/services/demoServices";
> DemoServices service = new DemoServicesStub(endPointReference);
> RequestDocument request = RequestDocument.Factory.newInstance();
> Request req = request.addNewRequest();
> ComplexType2 part2 = req.addNewRequestPart();
> part2.setElement6(BigInteger.ONE);
> part2.setElement7("test");
> SpecificType elt8 = SpecificType.Factory.newInstance();
> elt8.setElement4(true);
> elt8.setElement5("any test");
> part2.setElement8(elt8);
>
> checkXmlSchema(request);
>
> RequestResponseDocument response = service.Request(request);
>
> checkXmlSchema(response);
>
> NotifyDocument notify = NotifyDocument.Factory.newInstance();
> Notify not = notify.addNewNotify();
> ComplexType1 part1 = not.addNewNotifyPart();
> part1.addElement1(12);
> part1.setElement2("test");
>
> SpecificType elt3 = SpecificType.Factory.newInstance();
> elt3.setElement4(true);
> elt3.setElement5("any test");
> part1.setElement3(elt3);
>
> checkXmlSchema(notify);
>
> service.Notify(notify);
>
> }
> catch (Exception e)
> {
> logger.error(e.getMessage(),e);
> }
>
>
>
> }
>
> }
>
-------------------------------------------------------------------------------------------------------------------------


>
> WSDL :
> <?xml version="1.0" encoding="UTF-8"?>
> <definitions xmlns="http://schemas.xmlsoap.org/wsdl/"
> xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
> xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
> xmlns:xsd="http://www.w3.org/2001/XMLSchema"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns:soap-enc="http://schemas.xmlsoap.org/soap/encoding/"
> xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"
> xmlns:demoWS="http://soap.dryade.demo"
> xmlns:demo="http://types.dryade.demo"
> targetNamespace="http://soap.dryade.demo">
> <import namespace="http://types.dryade.demo" location="schema.xsd"/>
> <message name="RequestMessage">
> <part name="RequestPart" type="demo:ComplexType2"/>
> </message>
> <message name="ResponseMessage">
> <part name="ResponsePart" type="demo:ComplexType1"/>
> </message>
> <message name="NotifyMessage">
> <part name="NotifyPart" type="demo:ComplexType1"/>
> </message>
> <portType name="SOAP-Port">
> <operation name="Request">
> <input message="demoWS:RequestMessage"/>
> <output message="demoWS:ResponseMessage"/>
> </operation>
> <operation name="Notify">
> <input message="demoWS:NotifyMessage"/>
> </operation>
> </portType>
> <binding name="demoSOAPBinding" type="demoWS:SOAP-Port">
> <soap:binding style="rpc" 
> transport="http://schemas.xmlsoap.org/soap/http"/>
> <!-- ==== Test services ===== -->
> <operation name="Request">
> <soap:operation soapAction="Request"/>
> <input>
> <soap:body use="literal" namespace="http://soap.dryade.demo"/>
> </input>
> <output>
> <soap:body use="literal" namespace="http://soap.dryade.demo"/>
> </output>
> </operation>
> <operation name="Notify">
> <soap:operation soapAction="Notify"/>
> <input>
> <soap:body use="literal" namespace="soap.dryade.demo"/>
> </input>
> </operation>
> </binding>
> <service name="demoServices">
> <port name="demoWSPort" binding="demoWS:demoSOAPBinding">
> <soap:address location="http://www.demo.net"/>
> </port>
> </service>
> </definitions>
>
> -------------------------------------------------------------------------------------------------------------------------
>
> XSD :
>
> <?xml version="1.0" encoding="UTF-8"?>
> <xs:schema xmlns:demo="http://types.dryade.demo"
> xmlns:xs="http://www.w3.org/2001/XMLSchema"
> targetNamespace="http://types.dryade.demo"
> elementFormDefault="qualified" attributeFormDefault="unqualified" 
> version="1.0" id="demo">
> <xs:complexType name="SpecificType">
> <xs:sequence>
> <xs:element name="element4" type="xs:boolean"/>
> <xs:element name="element5" type="xs:string" minOccurs="0"/>
> </xs:sequence>
> </xs:complexType>
> <xs:complexType name="ComplexType1">
> <xs:sequence>
> <xs:element name="element1" type="xs:int" minOccurs="1" 
> maxOccurs="unbounded"/>
> <xs:element name="element2" type="xs:string" />
> <xs:element name="element3" type="xs:anyType" minOccurs="0" 
> maxOccurs="1"/>
> </xs:sequence>
> </xs:complexType>
> <xs:complexType name="ComplexType2">
> <xs:sequence>
> <xs:element name="element6" type="xs:integer"/>
> <xs:element name="element7" type="xs:string"/>
> <xs:element name="element8" type="xs:anyType" minOccurs="0" 
> maxOccurs="1"/>
> </xs:sequence>
> </xs:complexType>
> </xs:schema>
>
> -------------------------------------------------------------------------------------------------------------------------
>
> ANT build file used to generate XmlBeans classes :
> <project name="demo" basedir="." default="generate_server">
> <property environment="env"/>
> <property name="axis2.home" value="${env.AXIS2_HOME}"/>
> <property name="src.dir" value="demo/src"/>
> <property name="buildserver.dir" value="demo/buildserver"/>
> <property name="buildclient.dir" value="demo/buildclient"/>
> <property name="distserver.dir" value="demo/distserver"/>
> <property name="distclient.dir" value="demo/distclient"/>
> <property name="lib.dir" value="demo/lib"/>
> <property name="project.package" value="demo"/>
> <!-- chemins pour la generation des wsdl -->
> <property name="server.dir" value="demo/wsdl_server"/>
> <property name="client.dir" value="demo/wsdl_client"/>
> <property name="server.wsdl" value="demo/wsdl/sample.wsdl"/>
>
> <path id="axis2.classpath">
> <fileset dir="${axis2.home}/lib">
> <include name="*.jar"/>
> </fileset>
> </path>
>
> <path id="server.classpath">
> <fileset dir="${axis2.home}/lib">
> <include name="*.jar"/>
> </fileset>
> <fileset dir="${lib.dir}">
> <include name="*.jar"/>
> </fileset>
> <pathelement location="${buildserver.dir}/classes"/>
> </path>
>
>
> <path id="client.classpath">
> <fileset dir="${lib.dir}/axis2">
> <include name="*.jar"/>
> </fileset>
> <fileset dir="${lib.dir}/log4j">
> <include name="*.jar"/>
> </fileset>
> <fileset dir="${distclient.dir}">
> <include name="*.jar"/>
> </fileset>
> <pathelement location="${client.dir}/resources"/>
> <pathelement location="${basedir}"/>
> </path>
>
>
> <target name="compile_server_axis">
> <mkdir dir="${buildserver.dir}"/>
> <mkdir dir="${buildserver.dir}/classes"/>
> <!--compilation des classes AXIS -->
> <javac debug="on"
> fork="true"
> memorymaximumsize="512m"
> destdir="${buildserver.dir}/classes"
> srcdir="${server.dir}/src"
> classpathref="axis2.classpath"/>
> </target>
>
>
> <target name="compile_client_axis">
> <mkdir dir="${buildclient.dir}"/>
> <mkdir dir="${buildclient.dir}/classes"/>
> <!--compilation des classes AXIS -->
> <javac debug="on"
> fork="true"
> memorymaximumsize="512m"
> destdir="${buildclient.dir}/classes"
> srcdir="${client.dir}/src"
> classpathref="axis2.classpath"/>
> </target>
>
>
> <target name="compile_server" depends="compile_server_axis">
> <!--compilation des classes métier-->
> <javac debug="on"
> fork="true"
> destdir="${buildserver.dir}/classes"
> srcdir="${src.dir}"
> includes="${project.package}/server/**"
> classpathref="server.classpath"/>
> </target>
>
>
> <target name="compile_client" depends="compile_client_axis">
> <mkdir dir="${distclient.dir}"/>
> <!--compilation des classes métier-->
> <javac debug="on"
> fork="true"
> destdir="${buildclient.dir}/classes"
> srcdir="${src.dir}"
> includes="${project.package}/client/**"
> classpathref="client.classpath"/>
> </target>
>
>
> <target name="generate_all" depends="generate_server,generate_client"/>
>
> <target name="generate_client" depends="compile_client">
> <mkdir dir="${distclient.dir}"/>
> <delete file="${distclient.dir}/client.jar"/>
> <jar destfile="${distclient.dir}/client.jar">
> <fileset dir="${buildclient.dir}/classes"/>
> <fileset dir="${client.dir}/resources">
> <include name="**/*"/>
> </fileset>
> </jar>
> </target>
>
>
> <target name="generate_server" depends="compile_server">
> <mkdir dir="${distserver.dir}"/>
> <!--aar them up -->
> <copy toDir="${buildserver.dir}/classes" failonerror="false">
> <fileset dir="${server.dir}/resources">
> <include name="**/*"/>
> </fileset>
> </copy>
> <copy toDir="${buildserver.dir}/classes" failonerror="false">
> <fileset dir="${basedir}/demo/resources/server">
> <include name="**/*.xml"/>
> </fileset>
> </copy>
> <delete file="${buildserver.dir}/classes/services.xml"/>
> <delete file="${distserver.dir}/DemoService.aar"/>
> <jar destfile="${distserver.dir}/DemoService.aar">
> <fileset dir="${buildserver.dir}/classes"/>
> <fileset dir="${lib.dir}/log4j">
> <include name="*.jar"/>
> </fileset>
> </jar>
> </target>
>
> <target name="install_server" depends="generate_server">
> <copy file="${distserver.dir}/DemoService.aar" 
> toDir="${axis2.home}/repository/services/"/>
> </target>
>
> <target name="install" depends="install_server"/>
>
> <target name="clean_all" depends="clean_server,clean_client"/>
>
> <target name="clean_server">
> <delete dir="${buildserver.dir}/classes"/>
> <delete dir="${distserver.dir}"/>
> </target>
>
> <target name="clean_client">
> <delete dir="${buildclient.dir}/classes"/>
> <delete dir="${distclient.dir}"/>
> <delete file="sh/client.sh"/>
> </target>
>
> <target name="all" 
> depends="generate_axis_classes,clean_all,generate_all,install"/>
>
> <target name="generate_axis_classes" depends="generate_axis_server"/>
>
> <target name="generate_axis_server" depends="clean_axis_server">
> <mkdir dir="${server.dir}"/>
> <java classname="org.apache.axis2.wsdl.WSDL2Java">
> <classpath refid="axis2.classpath"/>
> <arg value="-d"/>
> <arg value="xmlbeans"/>
> <arg value="-uri"/>
> <arg file="${server.wsdl}"/>
> <arg value="-ss"/>
> <arg value="-ssi"/>
> <arg value="-sd"/>
> <arg value="-sp"/>
> <arg value="-t"/>
> <arg value="-o"/>
> <arg file="${server.dir}"/>
> </java>
> <mkdir dir="${client.dir}"/>
> <java classname="org.apache.axis2.wsdl.WSDL2Java">
> <classpath refid="axis2.classpath"/>
> <arg value="-d"/>
> <arg value="xmlbeans"/>
> <arg value="-uri"/>
> <arg file="${server.wsdl}"/>
> <arg value="-u"/>
> <arg value="-t"/>
> <arg value="-sp"/>
> <arg value="-o"/>
> <arg file="${client.dir}"/>
> </java>
> </target>
>
>
> <target name="clean_axis_classes" depends="clean_axis_server"/>
>
> <target name="clean_axis_server">
> <delete dir="${server.dir}"/>
> <delete dir="${client.dir}"/>
> </target>
>
>
> </project>
>
>
>
> -------------------------------------------------------------------------------------------------------------------------
>
>
>
>
>
>
> ------------------------------------------------------------------------
>
>
> Ce message entrant est certifié sans virus connu.
> Analyse effectuée par AVG - www.avg.fr 
> Version: 8.5.386 / Base de données virale: 270.13.6/2221 - Date: 07/06/09 17:54:00
>
>   


Mime
View raw message