You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by co...@apache.org on 2008/04/17 02:31:00 UTC

[CONF] Apache Tuscany: Build your first Web Services with Tuscany (page edited)

Build your first Web Services with Tuscany (TUSCANY) edited by Luciano Resende
      Page: http://cwiki.apache.org/confluence/display/TUSCANY/Build+your+first+Web+Services+with+Tuscany
   Changes: http://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=82971&originalVersion=1&revisedVersion=2






Content:
---------------------------------------------------------------------

h1. Build your first Web Services with Tuscany

This guide will give you step by step instructions on how to build your first web services.
The first part, we will learn how we can add the Tuscany Runtime to Eclipse IDE.
The second part, will show how easy is to create a webservices using Apache Tuscany.

{include:Tools - Install Tuscany Eclipse Plugins 1.1}

h2. Create your Service Business Logic

h2. Create a Java Project

In this step you create a Java Project in Eclipse to hold the composite service application.
Click on the *{_}New Java Project{_}* button !new_java_project.png!  in the toolbar to launch the project creation dialog.
Next you enter "ws" as the *{_}Project name{_}*, and for *{_}Project Layout{_}* select *{_}Create separate{_}*
*{_}folders for sources and class files._*
!new_java_project_dlg.png!
 
!project_layout.png!
 
Hit the *{_}Next{_}* button, and on the following page go to the *{_}Libraries{_}* tab. Use the *{_}Add Library..._*
button on the right to add the *Tuscany Library* library to the project.
 
!new_java_project_lib.png!
 
 
Hit the *{_}Finish{_}* button to complete the *{_}New Java Project{_}* dialog to create the "store" java project. 
 
!new_java_project_folder.png!
 
 

h2. Construct Services

First you create the "helloworld" package folders into which later in this step you place service implementations.
Select the "ws" project and click on the *{_}New Java Package{_}* button !new_java_pkg_btn.png! in the toolbar to launch
the package creation dialog.

Next you enter "helloworld" as the package *{_}Name{_}*, and press the *{_}Finish{_}* button to complete the
dialog.
!new_java_pkg_dlg.png!
 

h3. _HelloWorld_

In this step you create the HelloWorld service interface and implementation.
Select the "helloworld" package. Next you click on the dropdown arrow next to the *{_}New Java Class{_}*
button  !class_btn.png!  and select the *{_}New Java Interface{_}*   !interface_btn.png! option from the dropdown list. In the dialog
enter "HelloWorld" as the *{_}Name{_}* of the interface and select the Finish button to complete the dialog.
The Java editor will open on the new created Java interface. Replace the content of the editor by
*{_}copy-paste{_}* of the following Java interface code snippet.
{code}
package helloworld;
import org.osoa.sca.annotations.Remotable;
@Remotable
public interface HelloWorld {
    String sayHello(String name);
}
{code}
Select the "helloworld" package again. Select the *{_}New Java Class{_}* button !class_btn.png! . In the dialog enter
"HelloWorldImpl" as the *{_}Name{_}* of the class, add "Catalog" as the interface this class implements, and
then select *{_}Finish{_}* to complete the dialog.

The Java editor will open on the new created Java class. Replace the content of the editor by
*{_}copy-paste{_}* of the following Java class code snippet.
{code}
package helloworld;
public class HelloWorldImpl implements HelloWorld {
	public String sayHello(String name) {
		return "Hello " + name;
	}
}
{code}
After completing these steps the content of the "ws" project will look as follows.
!store_project.png!
 
*Note:* CatalogImpl is red x'ed because it makes use of the CurrencyConverter interface that we
have not implemented yet.
 

h2. Compose Services

Now that you have all the required service implementations you compose them together to provide
the store composite service. The composition is stored in a .composite file.

Select the "src" folder of the "ws" project. *{_}Right click{_}* to get the context menu, select *{_}New{_}*, and
then *{_}File{_}*. In the *{_}New File{_}* dialog enter "helloworld.composite" for the *{_}File name{_}*, and then select *{_}Finish{_}*
to complete the dialog.

The Text editor will open on the new created composite file. Replace the content of the editor by
*{_}copy-paste{_}* of the following composite snippet.
{code}
<?xml version="1.0" encoding="UTF-8"?>
<composite	xmlns="http://www.osoa.org/xmlns/sca/1.0"
			xmlns:t="http://tuscany.apache.org/xmlns/sca/1.0"
			xmlns:c="http://helloworld"
			name="helloworld">


	<component name="HelloWorldComponent">
		<implementation.java class="helloworld.HelloWorldImpl"/>
		<service name="HelloWorld">
			<binding.ws uri="http://localhost:8080/HelloWorld"/>
		</service>
	</component>
</composite>
{code}
After completing these steps the content of the "store" project will look as follows.

!store_project_4.jpg!
&nbsp;

Congratulations you completed your 1st composite service applications, now its time to take it into
action.

h2. Use Services

In this step you launch and use the ws composite service application you created.

First select the "helloworld.composite" file, in your "ws" project. *{_}Right click{_}* to get the
context menu, select *{_}Run As{_}*, and then *{_}Tuscany{_}*. The Tuscany runtime will start up adding
the helloworld composition to its domain and will make the helloworld web service live.

The Eclipse console will show the following messages.

&nbsp;!eclipse_console.png!

&nbsp;Next Launch your Web browser and enter the following address:

[http://localhost:8080/HelloWorld?wsdl]&nbsp;

You should now have your web service live, and the url should give you back a generated wsdl for the service.

{code}
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions targetNamespace="http://helloworld" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:ns0="http://helloworld" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:ns1="http://org.apache.axis2/xsd" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
  <wsdl:types>
    <xs:schema attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://helloworld" xmlns:ns="http://helloworld">
         <xs:element name="sayHello">
            <xs:complexType>
               <xs:sequence>
                  <xs:element minOccurs="0" name="param0" nillable="true" type="xs:string"/>
               </xs:sequence>
            </xs:complexType>

         </xs:element>
         <xs:element name="sayHelloResponse">
            <xs:complexType>
               <xs:sequence>
                  <xs:element minOccurs="0" name="return" nillable="true" type="xs:string"/>
               </xs:sequence>
            </xs:complexType>
         </xs:element>
      </xs:schema>

  </wsdl:types>
  <wsdl:message name="sayHelloRequest">
    <wsdl:part name="parameters" element="ns0:sayHello">
    </wsdl:part>
  </wsdl:message>
  <wsdl:message name="sayHelloResponse">
    <wsdl:part name="parameters" element="ns0:sayHelloResponse">
    </wsdl:part>
  </wsdl:message>

  <wsdl:portType name="HelloWorldPortType">
    <wsdl:operation name="sayHello">
      <wsdl:input message="ns0:sayHelloRequest" wsaw:Action="urn:sayHello">
    </wsdl:input>
      <wsdl:output message="ns0:sayHelloResponse" wsaw:Action="urn:sayHelloResponse">
    </wsdl:output>
    </wsdl:operation>
  </wsdl:portType>
  <wsdl:binding name="HelloWorldHttpBinding" type="ns0:HelloWorldPortType">

    <http:binding verb="POST"/>
    <wsdl:operation name="sayHello">
      <http:operation location="HelloWorld/sayHello"/>
      <wsdl:input>
        <mime:content part="sayHello" type="text/xml"/>
      </wsdl:input>
      <wsdl:output>
        <mime:content part="sayHello" type="text/xml"/>
      </wsdl:output>

    </wsdl:operation>
  </wsdl:binding>
  <wsdl:binding name="HelloWorldSOAP11Binding" type="ns0:HelloWorldPortType">
    <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
    <wsdl:operation name="sayHello">
      <soap:operation soapAction="urn:sayHello" style="document"/>
      <wsdl:input>
        <soap:body use="literal"/>
      </wsdl:input>

      <wsdl:output>
        <soap:body use="literal"/>
      </wsdl:output>
    </wsdl:operation>
  </wsdl:binding>
  <wsdl:service name="HelloWorld">
    <wsdl:port name="HelloWorldSOAP11port_http" binding="ns0:HelloWorldSOAP11Binding">
      <soap:address location="http://192.168.209.1:8080/HelloWorld"/>
    </wsdl:port>

    <wsdl:port name="HelloWorldHttpport" binding="ns0:HelloWorldHttpBinding">
      <http:address location="http://192.168.209.1:8080/HelloWorld"/>
    </wsdl:port>
  </wsdl:service>
</wsdl:definitions>
{code}


---------------------------------------------------------------------
CONFLUENCE INFORMATION
This message is automatically generated by Confluence

Unsubscribe or edit your notifications preferences
   http://cwiki.apache.org/confluence/users/viewnotifications.action

If you think it was sent incorrectly contact one of the administrators
   http://cwiki.apache.org/confluence/administrators.action

If you want more information on Confluence, or have a bug to report see
   http://www.atlassian.com/software/confluence



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