To return an EndpointReference you need to do a bit more dancing :)

2 things need to be done:

1) Change the return response in your schema declaration in the wsdl
<xsd:element name="createResponse">
                                <xsd:complexType>
                                        <xsd:sequence>
                                                <xsd:element
ref="wsa:EndpointReference" />
                                        </xsd:sequence>
                                </xsd:complexType>
                        </xsd:element>
2) after using wsdl2java you need to edit the following files (assuming
your wsdl is called Factory.wsdl):
<Factory.java>
Change the create operation return Element to EndpointReference (import
org.apache.muse.ws.addressing.EndpointReference; needs to be added as
well)

<FactoryProxy.java>
//add this method to get the EPR from the xml
        public class EndpointReferenceSerializer extends
        XmlSerializableSerializer 
        {
                public Class<?> getSerializableType()
                {
                        return EndpointReference.class;
                }

                public Object fromXML(Element xml)
                {
                        EndpointReference epr = null;
                        try{
                       epr = new EndpointReference(xml);
                        }catch (Throwable error){
                                error.printStackTrace();
                        }
                        return epr;
                }
        }
/Change from Element to EndpointReference
    public EndpointReference create(int matchId)
        throws SoapFault
    {
//add the following 2 lines to use the EndpointReferenceSerializer above
        SerializerRegistry reg = SerializerRegistry.getInstance();
                reg.registerSerializer(EndpointReference.class, new
EndpointReferenceSerializer());
                
        Object[] params = new Object[1];

        params[0] = new Integer(matchId);

        ProxyHandler handler = getHandler("create");
        return (EndpointReference)invoke(handler, params);
    }

// in this you need to change the Element.class to
EndpointReference.class, // but you need to change the one that relates
to your create methode
// count what number your create methode is from the top of the file,
then
// change that Element.class in the array below
private static final Class<?>[] _RETURN_TYPES = {
        EndpointReference.class, Element.class, Element.class,
Element.class
    };

<IMyCapability.java>
// Change the return Element to EndpointReference
public EndpointReference create() throws Exception;

<MyCapability.java>
Change the return Element to EndpointReference
public EndpointReference create() throws Exception    {
        // add your business logic
                return epr;
    }

This worked for me.

/Lenni

-----Original Message-----
From: Nelson Kotowski [mailto:[EMAIL PROTECTED] 
Sent: 17 January 2008 01:13
To: [email protected]
Subject: Different Return Type - SimpleResourceClient.java

Hello everyone,

I have a little doubt. I would like to know how to return a
EndpointReference type in a method inside SimpleResourceClient.java,
from
the wsrf example.

Something like this works fine...

public String mycapability() throws SoapFault
 {
   Element body =
XmlUtils.createElement(mycapability.CAPABILITY_OP_QNAME);
   Element response = invoke(mycapability.CAPABILITY_OP_URI, body);
   return XmlUtils.extractText(response);
}

But if I want to return a different type, like the EndpointReference,
has
anyone ever had a similar experience? If so, how did you manage to
return
"non-primitive" types?

Best regards,
Nelson P Kotowski Filho.

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to