cxf-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Grzegorz Grzybek (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (CXF-5208) Anonymous types in an exception aren't generated in WSDL
Date Thu, 26 Sep 2013 12:22:03 GMT

    [ https://issues.apache.org/jira/browse/CXF-5208?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13778702#comment-13778702
] 

Grzegorz Grzybek commented on CXF-5208:
---------------------------------------

In {{org.apache.cxf.jaxb.JAXBSchemaInitializer.addElement(XmlSchema, XmlSchemaSequence, JAXBBeanInfo,
QName, boolean)}} a new XSD Element is constructed when generating {{MyException}} type in
{{org.apache.cxf.jaxb.JAXBSchemaInitializer.buildExceptionType(MessagePartInfo, Class<?>)}}.

{{str}} field is successfully added to the sequence particle of new Exception type, but for
{{myAnonObj}} property the following code returns instead of adding new element to the sequence:
{code:java}
el.setName(name.getLocalPart());
Iterator<QName> itr = beanInfo.getTypeNames().iterator();
if (!itr.hasNext()) {
   return;
}
QName typeName = itr.next();
el.setSchemaTypeName(typeName);
{code}

{{com.redhat.samples.ws.MyAnonType}} just *don't* have XML Type name.

What you have to do is to follow chapters 2.5 and 3.7 of JAX-WS 2 specifiction and instead
of:

{code:java}
@SuppressWarnings("serial")
public class MyException extends Exception {

  private String     str;
  private MyAnonType myAnonObj;
...
{code}

you have to create:
{code:java}
@WebFault
public class MyException extends Exception {
  private MyExceptionBean bean;

  public MyException(String message, MyExceptionBean bean) {
    super(message);
    this.bean = bean;
  }

  public MyException(String message, MyExceptionBean bean, Throwable cause) {
    super(message, cause);
    this.bean = bean;
  }

  public MyExceptionBean getFaultInfo() {
    return this.bean;
  }
}
{code}

and one additional type:
{code:java}
@XmlType(name = "MyException")
public class MyExceptionBean {

  private String     str;
  private MyAnonType myAnonObj;

  public String getStr() {
    return str;
  }

  public void setStr(String str) {
    this.str = str;
  }

  public MyAnonType getMyAnonObj() {
    return myAnonObj;
  }

  public void setMyAnonObj(MyAnonType myAnonObj) {
    this.myAnonObj = myAnonObj;
  }

}

{code}

{{MyAnonType}} still have {{@XmlType(name = "")}}

So instead of such WSDL:

{code:xml}
<xs:complexType name="MyException">
  <xs:sequence>
    <xs:element minOccurs="0" name="str" type="xs:string" />
  </xs:sequence>
</xs:complexType>
<xs:element name="MyException" nillable="true" type="tns:MyException" />
{code}

you get:

{code:xml}
<xs:complexType name="MyException">
  <xs:sequence>
    <xs:element minOccurs="0" name="myAnonObj">
      <xs:complexType>
        <xs:sequence>
          <xs:element minOccurs="0" name="value" type="xs:string" />
        </xs:sequence>
      </xs:complexType>
    </xs:element>
    <xs:element minOccurs="0" name="str" type="xs:string" />
  </xs:sequence>
</xs:complexType>
<xs:element name="MyException" nillable="true" type="tns:MyException" />
{code}


                
> Anonymous types in an exception aren't generated in WSDL
> --------------------------------------------------------
>
>                 Key: CXF-5208
>                 URL: https://issues.apache.org/jira/browse/CXF-5208
>             Project: CXF
>          Issue Type: Bug
>          Components: JAXB Databinding, Tooling
>    Affects Versions: 2.7.6
>            Reporter: Tadayoshi Sato
>         Attachments: exception-anontype.zip
>
>
> Anonymous types (annotated with {{@XmlType(name = "")}}) in an exception class aren't
generated at all in WSDL.
> Web service classes:
> {code:java}
> @WebService
> public class GreetingService {
>   @WebMethod
>   public void hello() throws MyException {}
>   ...
> {code}
> {code:java}
> public class MyException extends Exception {
>   private String     str;
>   private MyAnonType myAnonObj;
>   public String getStr() { return str; }
>   public void setStr(String str) { this.str = str; }
>   public MyAnonType getMyAnonObj() { return myAnonObj; }
>   public void setMyAnonObj(MyAnonType myAnonObj) { this.myAnonObj = myAnonObj; }
>   ...
> {code}
> {code:java}
> @XmlType(name = "")
> public class MyAnonType { ...
> {code}
> Generated WSDL:
> {code:xml}
>   <wsdl:types>
> <xs:schema ...>
>   ...
>   <xs:complexType name="MyException">
>     <xs:sequence>
>       <xs:element name="str" nillable="true" type="xs:string"/>
>     </xs:sequence>
>   </xs:complexType>
> {code}
> Note that the same type ({{MyAnonType}}) is generated in WSDL if the {{@XmlType(name
= "")}} annotation is removed.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Mime
View raw message