You are viewing a plain text version of this content. The canonical link for it is here.
Posted to muse-dev@ws.apache.org by José Antonio Sánchez <ge...@gmail.com> on 2006/11/10 15:57:47 UTC

How to create a factory service?

Hello, I need a service that, at the execution of a method, creates a
resource of type T end returns its end point but I don't know exactly
how to implement the factory service. In the wsdl I have defined a
Create method with the following messages:

.............
<xsd:element name="Create">
	<xsd:complexType>
		<xsd:sequence>
			<xsd:element name="Type" type="xsd:anyURI">
			</xsd:element>
		</xsd:sequence>
	</xsd:complexType>
	</xsd:element>
<xsd:element name="CreateResponse">
	<xsd:complexType>
		<xsd:sequence>
			<xsd:element name="Resource"
				type="wsa:EndpointReferenceType">
			</xsd:element>
		</xsd:sequence>
	</xsd:complexType>
</xsd:element>
.............................
<wsdl:message name="CreateRequest">
		<wsdl:part name="CreateRequest" element="tns:Create"></wsdl:part>
</wsdl:message>
<wsdl:message name="CreateResponse">
	<wsdl:part name="CreateResponse"
		element="tns:CreateResponse">
	</wsdl:part>
</wsdl:message>
...........................
But there are a couple of problems. As the two wsdls has to be in the
same project (the factory's capabilitys has to have access to the
Resource class to create it) I don't know how to create two
capabilities because the wsdl2java tool always creates
IMyCapability.java and MyCapability.java. Although I can create one
and then rename it (changing the muse.xml too) I wonder if there is a
way to tell the tool to create the capability with a given name.
The second problem is that in the code generated from the above wsdl,
the Create operation returns an Element type instead of an
EndPointReference type. I don't know if I'm doing it wrong or if it's
supposed to be that way (and in the client I have to cast Element to
EndPointReference).
-- 
Saludos.
José Antonio Sánchez

---------------------------------------------------------------------
To unsubscribe, e-mail: muse-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: muse-dev-help@ws.apache.org


Re: How to create a factory service?

Posted by Daniel Jemiolo <da...@us.ibm.com>.
Hi,

You're on the right track, here are a few suggestions to fix your issues:

1. Capabilities are distinguished by XML namespaces. To separate the two 
capabilities (the factory one and your others), simply put the message 
schemas under different namespaces - this will result in different package 
names. See this link for more details on capabilities-by-namespace:

 
http://ws.apache.org/muse/docs/2.0.0/manual/tools/wsdl2java.html#algorithm

2. Once you've done that, you can get wsdl2java to generate the 
package/class names you want by putting them in a skeleton muse.xml file. 
You don't even have to make the muse.xml file yourself - wsdl2java will 
generate a blank one for you with the right elements. See use case #3 
here:

 
http://ws.apache.org/muse/docs/2.0.0/manual/tools/wsdl2java.html#use_cases

3. Check out the MyFactoryImpl.java code and the muse.xml file in the 
'wsrf' sample. This project has one resource type ("WsResourc") whose 
creation is controlled by a factory resource type ("WsResourceFactory"). 
The factory capability in the WsResourceFactory resource creates new 
WsResources every seven seconds (in a separate thread). These instances 
are added to a service group resource, which is illustrated by reading the 
service group contents in the test client.

I believe this is similar to what you want to do, you just have to change 
*when* resources are created; the sample uses a timer, you want to use a 
web service operation. You can start by taking this sample code and 
modifying it so that instead of encapsulating the resource creation in a 
java.lang.Thread, it's encapsulated in the create(URI) method. That's all.

4. The Muse runtime will actually support your code if you return 
EndpointReference objects from your methods, but wsdl2java always 
generates DOM ELement for complex types it finds in your WSDL operations. 
You have two options here - both of these code fragments will work:


a. Keep the 'Element' return type and use code like this:


public Element create(String type)
{
    ResourceManager mgr = getEnvironment().getResourceManager();
    Resource resource = mgr.createResource(type);
    resource.initialize();

    EndpointReference epr = resource.getEndpointReference();
    mgr.addResource(epr, resource);

    return epr.toXML();  // convert to Element!
}


b. Change to 'EndpointReference' return type:

public EndpointReference create(String type)
{
    ResourceManager mgr = getEnvironment().getResourceManager();
    Resource resource = mgr.createResource(type);
    resource.initialize();

    EndpointReference epr = resource.getEndpointReference();
    mgr.addResource(epr, resource);

    return epr;
}


The latter works because EndpointReference implements Muse's 
XmlSerializable interface, so Muse knows how to convert it to XML before 
adding it to the SOAP response.

Also note that I have left exception handling as an exercise for the 
reader.  :)

Dan


"José Antonio Sánchez" <ge...@gmail.com> wrote on 11/10/2006 09:57:47 
AM:

> Hello, I need a service that, at the execution of a method, creates a
> resource of type T end returns its end point but I don't know exactly
> how to implement the factory service. In the wsdl I have defined a
> Create method with the following messages:
> 
> .............
> <xsd:element name="Create">
>    <xsd:complexType>
>       <xsd:sequence>
>          <xsd:element name="Type" type="xsd:anyURI">
>          </xsd:element>
>       </xsd:sequence>
>    </xsd:complexType>
>    </xsd:element>
> <xsd:element name="CreateResponse">
>    <xsd:complexType>
>       <xsd:sequence>
>          <xsd:element name="Resource"
>             type="wsa:EndpointReferenceType">
>          </xsd:element>
>       </xsd:sequence>
>    </xsd:complexType>
> </xsd:element>
> .............................
> <wsdl:message name="CreateRequest">
>       <wsdl:part name="CreateRequest" element="tns:Create"></wsdl:part>
> </wsdl:message>
> <wsdl:message name="CreateResponse">
>    <wsdl:part name="CreateResponse"
>       element="tns:CreateResponse">
>    </wsdl:part>
> </wsdl:message>
> ...........................
> But there are a couple of problems. As the two wsdls has to be in the
> same project (the factory's capabilitys has to have access to the
> Resource class to create it) I don't know how to create two
> capabilities because the wsdl2java tool always creates
> IMyCapability.java and MyCapability.java. Although I can create one
> and then rename it (changing the muse.xml too) I wonder if there is a
> way to tell the tool to create the capability with a given name.
> The second problem is that in the code generated from the above wsdl,
> the Create operation returns an Element type instead of an
> EndPointReference type. I don't know if I'm doing it wrong or if it's
> supposed to be that way (and in the client I have to cast Element to
> EndPointReference).
> -- 
> Saludos.
> José Antonio Sánchez
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: muse-dev-unsubscribe@ws.apache.org
> For additional commands, e-mail: muse-dev-help@ws.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: muse-user-unsubscribe@ws.apache.org
For additional commands, e-mail: muse-user-help@ws.apache.org


Re: How to create a factory service?

Posted by Daniel Jemiolo <da...@us.ibm.com>.
Hi,

You're on the right track, here are a few suggestions to fix your issues:

1. Capabilities are distinguished by XML namespaces. To separate the two 
capabilities (the factory one and your others), simply put the message 
schemas under different namespaces - this will result in different package 
names. See this link for more details on capabilities-by-namespace:

 
http://ws.apache.org/muse/docs/2.0.0/manual/tools/wsdl2java.html#algorithm

2. Once you've done that, you can get wsdl2java to generate the 
package/class names you want by putting them in a skeleton muse.xml file. 
You don't even have to make the muse.xml file yourself - wsdl2java will 
generate a blank one for you with the right elements. See use case #3 
here:

 
http://ws.apache.org/muse/docs/2.0.0/manual/tools/wsdl2java.html#use_cases

3. Check out the MyFactoryImpl.java code and the muse.xml file in the 
'wsrf' sample. This project has one resource type ("WsResourc") whose 
creation is controlled by a factory resource type ("WsResourceFactory"). 
The factory capability in the WsResourceFactory resource creates new 
WsResources every seven seconds (in a separate thread). These instances 
are added to a service group resource, which is illustrated by reading the 
service group contents in the test client.

I believe this is similar to what you want to do, you just have to change 
*when* resources are created; the sample uses a timer, you want to use a 
web service operation. You can start by taking this sample code and 
modifying it so that instead of encapsulating the resource creation in a 
java.lang.Thread, it's encapsulated in the create(URI) method. That's all.

4. The Muse runtime will actually support your code if you return 
EndpointReference objects from your methods, but wsdl2java always 
generates DOM ELement for complex types it finds in your WSDL operations. 
You have two options here - both of these code fragments will work:


a. Keep the 'Element' return type and use code like this:


public Element create(String type)
{
    ResourceManager mgr = getEnvironment().getResourceManager();
    Resource resource = mgr.createResource(type);
    resource.initialize();

    EndpointReference epr = resource.getEndpointReference();
    mgr.addResource(epr, resource);

    return epr.toXML();  // convert to Element!
}


b. Change to 'EndpointReference' return type:

public EndpointReference create(String type)
{
    ResourceManager mgr = getEnvironment().getResourceManager();
    Resource resource = mgr.createResource(type);
    resource.initialize();

    EndpointReference epr = resource.getEndpointReference();
    mgr.addResource(epr, resource);

    return epr;
}


The latter works because EndpointReference implements Muse's 
XmlSerializable interface, so Muse knows how to convert it to XML before 
adding it to the SOAP response.

Also note that I have left exception handling as an exercise for the 
reader.  :)

Dan


"José Antonio Sánchez" <ge...@gmail.com> wrote on 11/10/2006 09:57:47 
AM:

> Hello, I need a service that, at the execution of a method, creates a
> resource of type T end returns its end point but I don't know exactly
> how to implement the factory service. In the wsdl I have defined a
> Create method with the following messages:
> 
> .............
> <xsd:element name="Create">
>    <xsd:complexType>
>       <xsd:sequence>
>          <xsd:element name="Type" type="xsd:anyURI">
>          </xsd:element>
>       </xsd:sequence>
>    </xsd:complexType>
>    </xsd:element>
> <xsd:element name="CreateResponse">
>    <xsd:complexType>
>       <xsd:sequence>
>          <xsd:element name="Resource"
>             type="wsa:EndpointReferenceType">
>          </xsd:element>
>       </xsd:sequence>
>    </xsd:complexType>
> </xsd:element>
> .............................
> <wsdl:message name="CreateRequest">
>       <wsdl:part name="CreateRequest" element="tns:Create"></wsdl:part>
> </wsdl:message>
> <wsdl:message name="CreateResponse">
>    <wsdl:part name="CreateResponse"
>       element="tns:CreateResponse">
>    </wsdl:part>
> </wsdl:message>
> ...........................
> But there are a couple of problems. As the two wsdls has to be in the
> same project (the factory's capabilitys has to have access to the
> Resource class to create it) I don't know how to create two
> capabilities because the wsdl2java tool always creates
> IMyCapability.java and MyCapability.java. Although I can create one
> and then rename it (changing the muse.xml too) I wonder if there is a
> way to tell the tool to create the capability with a given name.
> The second problem is that in the code generated from the above wsdl,
> the Create operation returns an Element type instead of an
> EndPointReference type. I don't know if I'm doing it wrong or if it's
> supposed to be that way (and in the client I have to cast Element to
> EndPointReference).
> -- 
> Saludos.
> José Antonio Sánchez
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: muse-dev-unsubscribe@ws.apache.org
> For additional commands, e-mail: muse-dev-help@ws.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: muse-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: muse-dev-help@ws.apache.org