You are viewing a plain text version of this content. The canonical link for it is here.
Posted to muse-user@ws.apache.org by Nelson Kotowski <nk...@gmail.com> on 2008/01/17 02:12:38 UTC

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.

RE: Different Return Type - SimpleResourceClient.java

Posted by Ch...@swisscom.com.
Hi Nelson,

I'm not sure but I you could be creating alot of work for yourself.
http://www.nabble.com/Creating-a-Serializer-for-JiBX-altered-classes-td1
4327762.html is a similar issue.  There is an overview below to get you
started.

You should use the tools that muse provides to generate a proxy class
for your client
(http://ws.apache.org/muse/docs/2.2.0/tutorial/03-wsdl2java.html#Section
4), it will derive from SimpleResourceClient or
org.apache.muse.ws.notification.remote.NotificationProducerClient if you
are using notifications.  In the generated code you can specify complex
return types.  EndpointReferences aren't automatically provided though,
so you use code like:

	GeneratedResourceProxy resource = new GeneratedResourceProxy(
targetEPR, sourceEPR );

	EndpointReference epr = new EndpointReference(
resource.getPropertyOrCallOperationThatReturnsAnEpr() );

	getPropertyOrCallOperationThatReturnsAnEpr() in this case
returns an Element from the generated proxy.

To add complicated return types (here ResourcePartResponse is a custom
type) to your proxy you can use serializers like this:

	public ResourcePartResponse retrieveResourcePart(String uri,
long start, long length)
        throws SoapFault
    {
        Object[] params = new Object[3];

        params[0] = uri;
        params[1] = new Long(start);
        params[2] = new Long(length);

        ProxyHandler handler = getHandler("retrieveResourcePart");
        return (ResourcePartResponse) rpSer.fromXML(
(Element)invoke(handler, params) );
    }

rpSer is a org.apache.muse.core.serializer.Serializer, that can also
then be used inside of your capabilities by muse in muse.xml:

<custom-serializer>
	
<java-serializable-type>com.swisscom.sif.esb.service.resourceTransfer.Re
sourcePartResponse</java-serializable-type>
 
<java-serializer-class>com.swisscom.sif.esb.service.resourceTransfer.Res
ourcePartResponseSerializer</java-serializer-class>
</custom-serializer>

where the ResourcePartResponse is a custom type that you can add to your
generated interfaces.

cheers,
Chris

-----Original Message-----
From: Nelson Kotowski [mailto:nkotowski@gmail.com] 
Sent: Thursday, January 17, 2008 2:13 AM
To: muse-user@ws.apache.org
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: muse-user-unsubscribe@ws.apache.org
For additional commands, e-mail: muse-user-help@ws.apache.org


RE: Different Return Type - SimpleResourceClient.java

Posted by le...@bt.com.
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:nkotowski@gmail.com] 
Sent: 17 January 2008 01:13
To: muse-user@ws.apache.org
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: muse-user-unsubscribe@ws.apache.org
For additional commands, e-mail: muse-user-help@ws.apache.org