Uploaded image for project: 'JBoss Web Services'
  1. JBoss Web Services
  2. JBWS-3690

XMLJavaTypeAdapter not working in Exception Classes

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major Major
    • jbossws-cxf-4.2.2
    • jbossws-cxf-4.2
    • jbossws-cxf
    • None

      @XMLJavaTypeAdapter usage in Exception Classes does not work when mapping to a class not in the JAXB Context.

      MyEJB.java
      @Stateless
      @WebService
      public class MyEJB {
      
          public void launcheMyException() throws MyException {
              return;
          }
      }
      
      MyException.java
      @XmlAccessorType(XmlAccessType.FIELD)
      public class MyException extends Exception {
      
       @XmlJavaTypeAdapter(Cl1ToCl2Adapter.class)
          MyClass1 obj1;
      
          @XmlJavaTypeAdapter(NoArgObjAdapter.class)
          NoArgObj obj2;
      
          public MyClass1 getObj1() {
      		return obj1;
      	}
          
          public void setObj1(MyClass1 obj1) {
      		this.obj1 = obj1;
      	}
      
      	public NoArgObj getObj2() {
              return obj2;
          }
      
          public void setObj2(NoArgObj obj2) {
              this.obj2 = obj2;
          }
      }
      
      Cl1ToCl2Adapter.java
      public class Cl1ToCl2Adapter extends XmlAdapter<MyClass2,MyClass1> {
      
          @Override
      	public MyClass2 marshal(MyClass1 v) throws Exception {
      		return new MyClass2();
      	}
      
      	@Override
      	public MyClass1 unmarshal(MyClass2 v) throws Exception {
      		MyClass1 mc1 = new MyClass1(v.getS2());
      		return mc1;
      	}
      
      
      }
      

      This is what the resulting WSDL contains. Obj2 is mapped fine to a String, but MyClass1 is not and should have the MyClass2 mapping here.

      <xs:complexType name="MyException">
      <xs:sequence>
      <xs:element name="str" nillable="true" type="xs:string"/>
      <xs:element name="obj2" nillable="true" type="xs:string"/>
      </xs:sequence>
      </xs:complexType>
      

      If you add the same adapter to a non Exception class it works just fine.

      This is NOT a duplicate of JBWS-3552 as I believe in that use case only known JAXB types were tested (HashMap, Strings etc). This issue is when you are using custom classes that need to be mapped.

        1. cxf5219.diff
          2 kB
        2. cxfTest.jar
          8 kB

            [JBWS-3690] XMLJavaTypeAdapter not working in Exception Classes

            mark yarborough <myarboro@redhat.com> changed the Status of bug 999893 from VERIFIED to CLOSED

            RH Bugzilla Integration added a comment - mark yarborough <myarboro@redhat.com> changed the Status of bug 999893 from VERIFIED to CLOSED

            Petr Sakař <psakar@redhat.com> changed the Status of bug 999893 from ON_QA to VERIFIED

            RH Bugzilla Integration added a comment - Petr Sakař <psakar@redhat.com> changed the Status of bug 999893 from ON_QA to VERIFIED

            Petr Sakař <psakar@redhat.com> made a comment on bug 999893

            Verify using attachment from comment#9
            EAP 6.2.0.ER7 passed
            EAP 6.2.0.ER6 failed

            RH Bugzilla Integration added a comment - Petr Sakař <psakar@redhat.com> made a comment on bug 999893 Verify using attachment from comment#9 EAP 6.2.0.ER7 passed EAP 6.2.0.ER6 failed

            Petr Sakař <psakar@redhat.com> made a comment on bug 999893

            mvn verify -Djboss.home=/home/development/jbossqe/JBEAP-6.2.0.ER6/build/jboss-eap-6.2

            RH Bugzilla Integration added a comment - Petr Sakař <psakar@redhat.com> made a comment on bug 999893 mvn verify -Djboss.home=/home/development/jbossqe/JBEAP-6.2.0.ER6/build/jboss-eap-6.2

            Paul Gier <pgier@redhat.com> changed the Status of bug 999893 from MODIFIED to ON_QA

            RH Bugzilla Integration added a comment - Paul Gier <pgier@redhat.com> changed the Status of bug 999893 from MODIFIED to ON_QA

            Brian Stansberry <brian.stansberry@redhat.com> changed the Status of bug 999893 from ASSIGNED to MODIFIED

            RH Bugzilla Integration added a comment - Brian Stansberry <brian.stansberry@redhat.com> changed the Status of bug 999893 from ASSIGNED to MODIFIED

            Alessio Soldano <asoldano@redhat.com> changed the Status of bug 999893 from NEW to ASSIGNED

            RH Bugzilla Integration added a comment - Alessio Soldano <asoldano@redhat.com> changed the Status of bug 999893 from NEW to ASSIGNED

            Rostislav Svoboda <rsvoboda@redhat.com> made a comment on bug 999893

            Alessio, thanks for clarification. I didn't check the pom for cxf version.

            RH Bugzilla Integration added a comment - Rostislav Svoboda <rsvoboda@redhat.com> made a comment on bug 999893 Alessio, thanks for clarification. I didn't check the pom for cxf version.

            Alessio Soldano <asoldano@redhat.com> made a comment on bug 999893

            Rostislav, JBossWS 4.2.1.Final was released without Apache CXF upgrade to 2.7.7.

            RH Bugzilla Integration added a comment - Alessio Soldano <asoldano@redhat.com> made a comment on bug 999893 Rostislav, JBossWS 4.2.1.Final was released without Apache CXF upgrade to 2.7.7.

            Rostislav Svoboda <rsvoboda@redhat.com> made a comment on bug 999893

            Should be fixed in CXF 2.7.7 / JBossWS CXF 4.2.1

            RH Bugzilla Integration added a comment - Rostislav Svoboda <rsvoboda@redhat.com> made a comment on bug 999893 Should be fixed in CXF 2.7.7 / JBossWS CXF 4.2.1

            Mustafa Musaji <mmusaji@redhat.com> made a comment on bug 999893

            Platform BZ for https://issues.jboss.org/browse/JBWS-3690

            Given the interface:
            @javax.jws.WebService
            public interface WsIntfc {
            public void test() throws MyException;
            }

            And exception class:
            public class MyException extends Exception {
            private MyClass1 adapted = null;

            @XmlJavaTypeAdapter(Cl1ToCl2Adapter.class)
            public MyClass1 getAdapted()

            { return this.adapted; }

            public void setAdapted(MyClass1 adapted)

            { this.adapted = adapted; }

            }

            Along with:
            public class Cl1ToCl2Adapter extends XmlAdapter<MyClass2, MyClass1> {
            @Override
            public MyClass1 unmarshal(MyClass2 v) throws Exception

            { MyClass1 mc1 = new MyClass1(); mc1.setName(v.getFile()); return mc1; }

            @Override
            public MyClass2 marshal(MyClass1 v) throws Exception

            { MyClass2 mc2 = new MyClass2(); mc2.setFile(v.getName()); return mc2; }

            }

            public class MyClass1 {
            private String name = null;

            public String getName()

            { return this.name; }

            public void setName(String name)

            { this.name = name; }

            }

            public class MyClass2 {
            private String file = null;

            public String getFile()

            { return this.file; }

            public void setFile(String file)

            { this.file = file; }

            }

            I get the following schema output:

            <xs:complexType name="myClass1">
            <xs:sequence>
            <xs:element minOccurs="0" name="name" type="xs:string"/>
            </xs:sequence>
            </xs:complexType>
            <xs:complexType name="MyException">
            <xs:sequence/>
            </xs:complexType>

            I should expect myClass2 defined in the schema and referenced by MyException.

            RH Bugzilla Integration added a comment - Mustafa Musaji <mmusaji@redhat.com> made a comment on bug 999893 Platform BZ for https://issues.jboss.org/browse/JBWS-3690 Given the interface: @javax.jws.WebService public interface WsIntfc { public void test() throws MyException; } And exception class: public class MyException extends Exception { private MyClass1 adapted = null; @XmlJavaTypeAdapter(Cl1ToCl2Adapter.class) public MyClass1 getAdapted() { return this.adapted; } public void setAdapted(MyClass1 adapted) { this.adapted = adapted; } } Along with: public class Cl1ToCl2Adapter extends XmlAdapter<MyClass2, MyClass1> { @Override public MyClass1 unmarshal(MyClass2 v) throws Exception { MyClass1 mc1 = new MyClass1(); mc1.setName(v.getFile()); return mc1; } @Override public MyClass2 marshal(MyClass1 v) throws Exception { MyClass2 mc2 = new MyClass2(); mc2.setFile(v.getName()); return mc2; } } public class MyClass1 { private String name = null; public String getName() { return this.name; } public void setName(String name) { this.name = name; } } public class MyClass2 { private String file = null; public String getFile() { return this.file; } public void setFile(String file) { this.file = file; } } I get the following schema output: <xs:complexType name="myClass1"> <xs:sequence> <xs:element minOccurs="0" name="name" type="xs:string"/> </xs:sequence> </xs:complexType> <xs:complexType name="MyException"> <xs:sequence/> </xs:complexType> I should expect myClass2 defined in the schema and referenced by MyException.

              rhn-support-mus Mustafa Musaji
              rhn-support-mus Mustafa Musaji
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Created:
                Updated:
                Resolved: