facebook

Unable to create JAXBContext – XMLBeans, complexType params

  1. MyEclipse Archived
  2.  > 
  3. Web Services
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #287306 Reply

    bsumn
    Member

    When creating a Web Service using beans created from XMLBeans as parameters to/from the service. When creating the Web Service (bottom up) in the Web Service Project if I select ‘Generate WSDL in Project” it results in a pop-up error “Unable to create JAXBContext.” Not selecting to create the WSDL does not produce the error. If I choose simple String parameters as the input/output to the service I can create the WSDL. So, I am unable to create a web service that uses complex types and have the WSDL generated. I am using MyEclipse 6.5.

    The following example describes the problem I am having.
    1. Create a ‘Web Service Project’ ie. File / New / Web Service Project – click Next
    2. Set the Project Name to: TestService
    Leave remaining options as already set. Should be JAX-WS and Java EE 5.0.
    Click Finish.
    3. In the TestService project add a package directory under ‘src’ named test.
    4. In the TestService project add a folder called ‘schema’.
    5. In the schema directory add the test.xsd schema in the following manner with the
    following contents.
    File / New / Other / MyEclipse / XML / XML Schema – name the file ‘test’

    <?xml version=”1.0″ encoding=”UTF-8″?>
    <xs:schema
    attributeFormDefault=”unqualified”
    elementFormDefault=”qualified”
    xmlns:xs=”http://www.w3.org/2001/XMLSchema”&gt;
    <xs:element name=”Car” type=”Nissan”/>
    <xs:complexType name=”Nissan”>
    <xs:sequence>
    <xs:element name=”Color” type=”xs:string”/>
    <xs:element name=”Doors” type=”xs:string”/>
    </xs:sequence>
    </xs:complexType>
    </xs:schema>

    6. In the schema directory create a test.xsdconfig file in the following manner. Add the
    following contents to it.
    File / New / File – name it test.xsdconfig

    <?xml version=”1.0″ encoding=”UTF-8″?>
    <xb:config xmlns:xb=”http://xml.apache.org/xmlbeans/2004/02/xbean/config”&gt;
    <xb:namespace uri=”##any”>
    <!– add the class files to a package. –>
    <xb:package>model</xb:package>
    </xb:namespace>
    </xb:config>

    7. Download XMLBeans from the Apache web site and unzip the files in the directory
    indicated by the <property> statement in the build.xml file or change the property
    statement to match where you put them.
    I used version 2.4.0 in this example from:
    http://mirrors.isc.org/pub/apache/xmlbeans/binaries/

    8. In the TestService project create a build.xml file in the following manner with the
    following contents.
    File / New / Other/ MyEclipse / XML / XML (Basic Templates)
    Name the file build.xml.

    Build.xml file contents are:

    <?xml version=”1.0″ encoding=”UTF-8″?>
    <project name=”TestXMLBean” default=”xmlbean”>
    <property name=”xmlbeanPath” value=”D:\xmlbeans-2.4.0\lib”/>
    <property name=”src.schema.dir” value=”schema”/>
    <property name=”src.java.dir” value=”src”/>
    <!– The Apache XMLBeans task used to compile the schema file(s) into java beans –>
    <taskdef name=”xmlbean” classname=”org.apache.xmlbeans.impl.tool.XMLBean”
    classpath=”${xmlbeanPath}/xbean.jar”/>
    <target name=”xmlbean”>
    <xmlbean
    classpath=”${xmlbeanPath}/xbean.jar:
    ${xmlbeanPath}/jsr173_1.0_api.jar:
    ${xmlbeanPath}/xmlbeans-qname.jar”
    classgendir=”WebRoot/WEB-INF/classes”
    srcgendir=”${src.java.dir}”
    javasource=”1.5″
    verbose=”true”
    excludes=””
    debug=”on”
    debuglevel=”lines, vars, source”>
    <fileset dir=”${src.schema.dir}”>
    <include name=”test.xsd”/>
    <include name=”test.xsdconfig”/>
    </fileset>
    </xmlbean>
    </target>
    </project>

    9. In MyEclipse right-click on the build.xml file and select ‘Run As / Ant Build’. The top ‘Ant
    Build’ selection.
    If everything runs you should see a ‘BUILD SUCCESSFUL’ message in your Console
    tab.

    10. You will need to add the XMLBean .jars to your project via. Project / Properties / Add
    External Jars to get rid of the red error flags in the project. Then.
    File / Save All
    File / Refresh
    Project / Build All – Unless you have Project / Build Automatically selected.

    11. In your src directory you should now have two more sub-directories called model
    and model.impl. The following .java file should be visible:

    model/CarDocument.java
    model/Nissan.java
    model/impl/CarDocumentImpl.java
    model/impl/NissanImpl.java

    12. Now create the .java file that will be used to build the web service from.
    In the src/test directory create a new java class in the following manner with the
    following contents.
    File / New / Class
    Set its Name value to CarService and click Finish.
    Set its contents as follows:

    package test;

    import javax.jws.*;
    import model.*;

    public class CarService {

    @WebMethod()
    @WebResult(name=”MyResult”)
    public Nissan processRequest(@WebParam(name=”inNissan”)Nissan objectIn) {

    Nissan objectOut = Nissan.Factory.newInstance();
    objectOut.setColor(“red”);
    objectOut.setDoors(“two”);

    return objectOut;
    }
    }

    13. Add the following Libraries to the project in the following manner:
    Project / Properties / Libraries (tab)
    Select: Add Library / MyEclipse Libraries -> Next button
    Check the boxes for:
    JAX-WS 2.1 Runtime Libraries
    JAX-WS 2.1 API Libraries
    Click Finish and OK to close out the screens and these two libraries will be added to
    the project.

    14. Try to create the web service in the following manner:
    File / New / Other / MyEclipse / Web Services / Web Service
    Make sure you have the TestService project selected to create your Web
    Service inside of.
    Make sure of the following selectons:
    Framework: JAX-WS
    Strategy: Create web service from Java bean.
    Click the Next button.

    15. In the next screen click the Browse button. IIn the screen that comes up start typing
    the name of the CarService.java file and it should appear in the listing that
    automatically starts being displayed to you. Select the CarService.java file.

    You are returned to the previous screen which has now become populated with the
    selection you just made. Check the checkbox for ‘Generate WSDL in project”,
    leave all the other settings as they are and then click the Finish button.

    The error message pop-up I am receiving is:
    An internal error occurred during: “Generating JAX-WS Web Services”.
    Unable to create JAXB-Context.

    This error does not occur if I do not select the WSDL checkbox. Which of course means
    that I don’t get a WSDL.

    #287311 Reply

    bsumn
    Member

    Well after some more playing around and searching it appears that the solution to the above problem is “don’t use XMLBeans!”. Finding out the location of the MyEclipse .log file from another post was pretty helpful. The log file is in your workspace/.metadata directory and is rotated with the current one being .log. Mine showed me that what the pop-up was really reporting to me was that the beans being created by XMLBeans don’t have a zero argument constructor for JAXB to use. Which explains why simple String values worked, java.lang.String has a zero argument constructor. Ignore the impl class in the error, I was trying every concievable thing to get this to work before finding the log file.

    !ENTRY org.eclipse.core.jobs 4 2 2008-07-20 00:36:12.642
    !MESSAGE An internal error occurred during: “Generating JAX-WS Web Services”.
    !STACK 0
    javax.xml.ws.WebServiceException: Unable to create JAXBContext
    at com.sun.xml.ws.model.AbstractSEIModelImpl.createJAXBContext(AbstractSEIModelImpl.java:158)
    at com.sun.xml.ws.model.AbstractSEIModelImpl.postProcess(AbstractSEIModelImpl.java:87)
    at com.sun.xml.ws.model.RuntimeModeler.buildRuntimeModel(RuntimeModeler.java:262)
    at com.sun.tools.ws.wscompile.WsgenTool.buildModel(WsgenTool.java:225)
    at com.sun.tools.ws.wscompile.WsgenTool.run(WsgenTool.java:124)
    at com.genuitec.eclipse.ws.jaxws.JaxWSBUJob.wsGen(JaxWSBUJob.java:224)
    at com.genuitec.eclipse.ws.jaxws.JaxWSBUJob.run(JaxWSBUJob.java:124)
    at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)
    Caused by: java.security.PrivilegedActionException: com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 4 counts of IllegalAnnotationExceptions
    model.impl.NissanImpl does not have a no-arg default constructor.
    this problem is related to the following location:
    at model.impl.NissanImpl
    at private model.impl.NissanImpl test.jaxws.ProcessRequest.arg0
    at test.jaxws.ProcessRequest
    org.apache.xmlbeans.impl.values.XmlComplexContentImpl does not have a no-arg default constructor.
    this problem is related to the following location:
    at org.apache.xmlbeans.impl.values.XmlComplexContentImpl
    at model.impl.NissanImpl
    at private model.impl.NissanImpl test.jaxws.ProcessRequest.arg0
    at test.jaxws.ProcessRequest
    etc. and so on.

    Instead I used the xjc schema compiler that comes bundled with java1.6
    In my case: C:\Sun\SDK\jdk\bin\xjc.exe with the following command. -> xjc -d . -p model -verbose test.xsd
    This created the java beans with the default constructors that the WebService wizard liked.
    So for the time being I just deleted the files that XMLBeans created and copied these over to the WEBROOT\WEB-INF\classes directory.
    By the way, why isn’t MyEclipse showing me that directory in the project Package Explorer. I have to go into Windows Explorer to see it.

    A couple of small tweaks to the example service .java file were needed for the new classes.

    package test;

    import javax.jws.*;
    import model.*;

    public class CarService {

    @WebMethod()
    @WebResult(name=”MyResult”)

    public Nissan processRequest(@WebParam(name=”objectIn”)Nissan objectIn) {

    Nissan objectOut1 = new Nissan();
    objectOut1.setColor(“green”);
    objectOut1.setDoors(“two”);

    return objectOut1;
    }
    }

    After using the the ‘Axis2 Service Archiver’ wizard to create the Axis2 .aar service file I deployed that to Axis and was able to
    use the MyEclipse ‘Web Services Explorer’ to connect to the WSDL and run the service. It ran as expected and allowed me to
    send the NIssan object and receive one back. It doesn’t actually do anthing with what is being sent but then this was only trying to
    get the most basic of processes to go with something other than simple objects.

    I originally went down the XMLBeans path as what I am working on was originally written for WebLogic and now need to go on
    both WebLogic and Axis. The WebLogic jwsc ant task to create web services doesn’t choke on the XMLBeans created files. So,
    now I’m not quite sure about what to do for both platforms. Two different methods is not what I would have hoped for.

Viewing 2 posts - 1 through 2 (of 2 total)
Reply To: Unable to create JAXBContext – XMLBeans, complexType params

You must be logged in to post in the forum log in