Another mail that, by accident, didn't make the user list.

Simon

---------- Forwarded message ----------
From: Simon Laws <[EMAIL PROTECTED]>
Date: Jul 25, 2007 6:22 PM
Subject: Re: servlet TuscanyServlet threw exception
To: Nishant Joshi <[EMAIL PROTECTED]>



On 7/25/07, Simon Laws <[EMAIL PROTECTED]> wrote:



On 7/25/07, Nishant Joshi < [EMAIL PROTECTED]> wrote:
>
>  Hi Simon,
>
> I have used target servlet as Tuscany servlet which is actually get some
> URI path from me and get me some servlet,
>
> But if u see the complete Process of How it get URI from us and get
> servlet back to us it looks there is one map in WebAppServletHost called
> servles it is the creating problem for me, You can download source code of
> Tuscany from
>
> http://cwiki.apache.org/TUSCANY/sca-java-releases.html
>
>
>
> Mine problem now is How to register servlet and call one function
> addServletMapping() from WebAppServletHost.java file
>
>
>
> thanks
>
>
>
> Nishant Joshi
>
>
>
> This message and the information contained herein is proprietary and 
confidential and subject to the Amdocs policy statement,
> you may review at
>
> http://www.amdocs.com/email_disclaimer.asp
>
>
Ok, I think we need to take a step back and walk through what you are
trying to do. From the previous posts I have imagined that you were trying
to

1/ run SCA as part of a web app (and that you have got that working)
2/ add some web services to that web app

Let me know if you are trying to do something else.

Assuming this is the case lets talk about 1/ first. There is an example of
how to do this in samples/calculator-webapp. If you look at the
Calculator.composite file for this application you see

<composite xmlns="http://www.osoa.org/xmlns/sca/1.0
"
           targetNamespace="
http://sample";
           xmlns:sample="http://sample";
           name="Calculator">


    <component name="CalculatorServiceComponent">

                <implementation.java class="calculator.CalculatorServiceImpl"/>
        <reference name="addService" target="AddServiceComponent"></reference>

        <reference name="subtractService" 
target="SubtractServiceComponent"></reference>

        <reference name="multiplyService" 
target="MultiplyServiceComponent"></reference>

        <reference name="divideService" 
target="DivideServiceComponent"></reference>

    </component>

    <component name="AddServiceComponent">
        <
implementation.java class="calculator.AddServiceImpl"/>
    </component>

    <component name="SubtractServiceComponent">

        <implementation.java class="calculator.SubtractServiceImpl
"/>
    </component>

    <component name="MultiplyServiceComponent">
        <implementation.java
 class="calculator.MultiplyServiceImpl"/>
    </component>


    <component name="DivideServiceComponent">
        <implementation.java class="calculator.DivideServiceImpl
"/>
    </component>

</composite>

Now there is no mention here of servlets or that this application is
running in a webapp. If you look at the
calculator-webapp\src\main\webapp\calc.jsp file you see

<%@ page import="org.apache.tuscany.sca.host.embedded.SCADomain"%>
<%@ page import="calculator.CalculatorService" %>

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
   SCADomain scaDomain = (SCADomain) application.getAttribute("
org.apache.tuscany.sca.SCADomain");
   CalculatorService calculatorService = scaDomain.getService(
CalculatorService.class, "CalculatorServiceComponent");
%>
<html>
<head><title>Calculator sample</title></head>

<body>
<table>
    <tr>
        <th>Expression</th><th>Result</th>
    </tr>
    <tr>
        <td>2 + 3</td><td><%= calculatorService.add(2, 3) %></td>
    </tr>
    <tr>
        <td>3 - 2</td><td><%= calculatorService.subtract(3, 2) %></td>
    </tr>
    <tr>
        <td>3 * 2</td><td><%= calculatorService.multiply(3, 2) %></td>
    </tr>
    <tr>
        <td>3 / 2</td><td><%= calculatorService.divide(3, 2) %></td>
    </tr>
</table>
</body>
</html>

The web.xml file itself uses the TuscanyContextListener to start the SCA
runtime (SCADomain) and register it in the servlet context so that the JSP
can access it.

<web-app>

  <display-name>Tuscany Calculator Web Service Sample</display-name>

  <listener>
    
<listener-class>org.apache.tuscany.sca.webapp.TuscanyContextListener</listener-class>

  </listener>

  <welcome-file-list id="WelcomeFileList">
    <welcome-file>calc.jsp</welcome-file>
  </welcome-file-list>

</web-app>

In case 2/. If you want to expose some of the SCA components as web
services then you need to describe the appropriate bindings in the composite
file, for example, here, I have changed the calculator SCA application to
expose the AddServiceComponent as a web service. I have to provide the WSDL
for this service but the runtime should be able to work out how to register
the underlying Axis servlet so that the web services run.

<composite xmlns="http://www.osoa.org/xmlns/sca/1.0";
           targetNamespace=" http://sample";
           xmlns:sample=" http://sample";
           name="Calculator">

    <component name="CalculatorServiceComponent">
        <implementation.java class="calculator.CalculatorServiceImpl "/>
        <reference name="addService" >
           <interface.java interface="calculator.AddService" />
           < binding.ws wsdlElement="
http://calculator#wsdl.port(AddService/AddSoapPort)<http://calculator#wsdl.port%28AddService/AddSoapPort%29>"/>

        </reference>
        <reference name="subtractService"
target="SubtractServiceComponent"></reference>
        <reference name="multiplyService"
target="MultiplyServiceComponent"></reference>
        <reference name="divideService"
target="DivideServiceComponent"></reference>
    </component>

    <component name="AddServiceComponent">
        <implementation.java class="calculator.AddServiceImpl"/>
        <service name="AddService">
            <interface.java interface="calculator.AddService" />
            <binding.ws wsdlElement="
http://calculator#wsdl.port(AddService/AddSoapPort)<http://calculator#wsdl.port%28AddService/AddSoapPort%29>
"/>
        </service>
    </component>

    <component name="SubtractServiceComponent">
        <implementation.java class="calculator.SubtractServiceImpl"/>
    </component>

    <component name="MultiplyServiceComponent">
        <implementation.java class="calculator.MultiplyServiceImpl "/>
    </component>

    <component name="DivideServiceComponent">
        <implementation.java class="calculator.DivideServiceImpl"/>
    </component>

    <component name="ExtensionPointRegistryInspectorComponent">
        <implementation.java class="
org.apache.tuscany.sca.tools.registryinspector.inspector.ExtensionPointRegistryInspectorImpl"/>
    </component>

</composite>

I'm in the middle of trying this out to make sure that it does run :-).
Let me know if these two points are an accurate reflection of what you are
trying to achieve. In particular I'm interested to know why you ask " How
to register servlet and call one function addServletMapping() from
WebAppServletHost.java file" as this function should be hidden unless of
course you are writing some new host integration.

Regards

Simon


Ok, so an update on what I have found. I built the calculator-webapp
sample but with the modified .composite file I included in my previous post.
The WSDL service description was as follows.

   <wsdl:service name="AddService">
       <wsdl:port binding="tns:AddSoapBinding" name="AddSoapPort">
           <wsdlsoap:address
location="http://localhost:8080/sample-calculator-webapp/services/AddService
"/>
       </wsdl:port>
   </wsdl:service>

I updated the web.xml from the original sample to include the TuscanyServlet
mapping

<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web
Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd";>
<web-app>

 <display-name>Tuscany Calculator Web Service Sample</display-name>

 <listener>
   <listener-class>org.apache.tuscany.sca.webapp.TuscanyContextListener
</listener-class>
 </listener>

 <servlet>
   <servlet-name>TuscanyServlet</servlet-name>
   <servlet-class>org.apache.tuscany.sca.webapp.TuscanyServlet</servlet-class>

 </servlet>

 <servlet-mapping>
   <servlet-name>TuscanyServlet</servlet-name>
   <url-pattern>/services/*</url-pattern>
 </servlet-mapping>

 <welcome-file-list id="WelcomeFileList">
   <welcome-file>calc.jsp</welcome-file>
 </welcome-file-list>

</web-app>

So I was expecting the JSP line

<td>2 + 3</td><td><%= calculatorService.add (2, 3) %></td>

To make a local call to the calculatorService which in turn would make a web
service call to the addService at
http://localhost:8080/sample-calculator-webapp/services/AddService
.
The addService should have been registered at
http://localhost:8080/sample-calculator-webapp/services/AddService via the
TuscanyServlet registered with Tomcat and hence all should  have been well.

As you may have guessed by now it didn't work. The problem is in the
TuscanyServlet as it only currently checks path info against the registered
servlets and our axis servlet (serving the AddService web service) has been
registered against the full url
http://localhost:8080/sample-calculator-webapp/services/AddService.

So I put a fix into TuscanyServlet as follows;

       String path = ((HttpServletRequest)req).getPathInfo();
       Servlet servlet = servletHost.getServlet(path);
       if (servlet == null) {
            throw new IllegalStateException("No servlet registered for
path: " + path);
       }

Becomes

       String path = ((HttpServletRequest)req).getPathInfo();
       Servlet servlet = servletHost.getServlet(path);
       if (servlet == null) {
           path = ((HttpServletRequest)req).getRequestURI();
           servlet = servletHost.getServlet(path);

           if (servlet == null) {
               throw new IllegalStateException("No servlet registered for
path: " + path);
           }
       }

And this does the trick. I suspect that the reason it is the way it is now
as you are not expected to specify a full URL when you are deploying your
app into a web app hosting environment but it would seem sensible to allow
it to be specified. You may specify the wrong URL but then it just won't
match again.

I'll also check in my new sample that demonstrates web services from within
web apps.

The alternative to doing all of this is to just run your application with
the internal Jetty or Tomcat servers and this will start up a service
automatically to expose webservices but this is not ideal in an environment
where you want to control the servlet container more closely.

Simon

Reply via email to