javaee / metro

Metro has been contributed to Eclipse Foundation. Please use the link below to find the latest project
https://github.com/eclipse-ee4j/metro-jax-ws
Other
10 stars 1 forks source link

Metro 2.3 / WCF. Nested class variables with same name as class return null from service endpoint. #28

Open glassfishrobot opened 10 years ago

glassfishrobot commented 10 years ago

Summary

MetroHello WebService

This is a simple jax-ws bottom-up WebService implementation that produces a bug in Metro 2.3.

The issue occurs when a WCF consumer class receives an object from the endpoint that contains a nested class instance whose name matches that of the class: it comes back null.

**MetroHello.java**package com.michaelt.ws;

import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.jws.soap.SOAPBinding.Style;

@WebService
@SOAPBinding(style = Style.RPC)
public interface MetroHello {

    @WebMethod Hello getNewHello();

    @WebMethod Hello sayHelloWorld(Hello hello);

}

When sayHelloWorld method below sends the Hello object back to WCF consumer, its "world" member variable is null.

**MetroHelloImpl.java**package com.michaelt.ws;

import javax.jws.WebService;

@WebService(endpointInterface="com.michaelt.ws.MetroHello")
public class MetroHelloImpl implements MetroHello {

    @Override
    public Hello getNewHello() {
        return new Hello();
    }

    @Override
    public Hello sayHelloWorld(Hello pHello) {
        pHello.world.message = "Hello World";
        return pHello;
    }

}

The problem arises when there is a nested class instance whose name matches the class like the example of "World world" below.

**Hello.java**package com.michaelt.ws;

import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement
public class Hello {

    // The endpoint will always return this as null     public World world = new World();

}

When "world" is renamed to anything else, it does not return null.

**World.java**package com.michaelt.ws;

import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement
public class World {

    public String message;

}

Cause

Metro 2.3 vs. Metro 2.0.1

In this scenario, the cause of the problem can be found in the .xsd's generated by Metro. This issue doesn't exist in older Metro versions, and it has to do with the xml definition of the nested class being referenced in version 2.3. Notice the difference inside the body of the tag between the two versions.

**Metro 2.3**<xs:schema version="1.0" targetNamespace="http://ws.michaelt.com/">
    <xs:element name="hello" type="tns:hello"/>
    <xs:element name="world" type="tns:world"/>
    <xs:complexType name="hello">
        <xs:sequence>
            <xs:element ref="tns:world" minOccurs="0"/>
        </xs:sequence>
    </xs:complexType>
    <xs:complexType name="world">
        <xs:sequence>
            <xs:element name="message" type="xs:string" minOccurs="0"/>
        </xs:sequence>
    </xs:complexType>
</xs:schema>

The ref attribute in 2.3 is possibly confused by member variable "world"?

**Metro 2.0.1**<xs:schema version="1.0" targetNamespace="http://ws.michaelt.com/">
    <xs:element name="hello" type="tns:hello"/>
    <xs:element name="world" type="tns:world"/>
    <xs:complexType name="hello">
        <xs:sequence>
            <xs:element name="world" type="tns:world" minOccurs="0"/>
        </xs:sequence>
    </xs:complexType>
    <xs:complexType name="world">
        <xs:sequence>
            <xs:element name="message" type="xs:string" minOccurs="0"/>
        </xs:sequence>
    </xs:complexType>
</xs:schema>

Environment

Windows 8.1 Pro, Java 1.7.0, Metro 2.3

Affected Versions

[2.3]

glassfishrobot commented 10 years ago

Reported by mtostenson

glassfishrobot commented 10 years ago

snowtoad2 said: Is this issue tracking site active? Has anyone been able to review this specific issue?

glassfishrobot commented 10 years ago

Was assigned to snajper

glassfishrobot commented 7 years ago

This issue was imported from java.net JIRA METRO-28