JWorld@TW the best professional Java site in Taiwan
      註冊 | 登入 | 全文檢索 | 排行榜  

» JWorld@TW » Java Application Framework » Spring  

按列印兼容模式列印這個話題 列印話題    把這個話題寄給朋友 寄給朋友    訂閱主題
reply to topicthreaded modego to previous topicgo to next topic
己加入精華區
by caterpillar at 2006-08-14 21:06
本主題所含的標籤
無標籤
作者 Spring and Axis 學習筆記 [精華]
gamerqq





發文: 17
積分: 1
於 2006-04-21 16:05 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
Step1:
  web server:tomcat
  jar: axis,spring 相關 jar 檔
Step2:建立 class
真正服務的class
1
2
3
4
5
6
7
8
9
10
11
  package axisspring;
  public interface  BusinessLogic {
      public String doSomeWork(String work);
  }
  public class BusinessLogicImpl  implements BusinessLogic  {
    public BusinessLogicImpl() {
    }
    public String doSomeWork(String work) {
        return "The work " +work+ " is done.";
    }
  }

服務窗口
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
  package axisspring.soap;
  public interface WebService  extends java.rmi.Remote  {
      public String doSomeWork(String work) throws java.rmi.RemoteException;
  }
  public class WebServiceImpl  extends ServletEndpointSupport implements WebService {
    public WebServiceImpl() {
    }
    private BusinessLogic logic;
    protected final void onInit() {
        this.logic = (BusinessLogicImpl)getWebApplicationContext().getBean("bizLogic");
    }
    public String doSomeWork(String work) throws java.rmi.RemoteException {
        return logic.doSomeWork(work);
    }
  }

Step 3: 設定相關檔案

server-config.wsdd 目的讓 web app 啟動時,自動增加 web services
(不知到該怎麼自動產生該檔案)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<?xml version="1.0" encoding="utf-8"?>
<deployment xmlns="http://xml.apache.org/axis/wsdd/"
    xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">
    <handler name="LocalResponder" type="java:org.apache.axis.transport.local.LocalResponder"/>
    <handler name="URLMapper" type="java:org.apache.axis.handlers.http.URLMapper"/>
    <handler name="Authenticate" type="java:org.apache.axis.handlers.SimpleAuthenticationHandler"/>
    <service name="webservice" provider="java:RPC" style="rpc" use="encoded">
        <parameter name="wsdlTargetNamespace" value="urn:soap.axisspring"/>
        <parameter name="className" value="axisspring.soap.WebServiceImpl"/>
        <parameter name="allowedMethods" value="*"/>
    </service>
    <transport name="http">
        <requestFlow>
            <handler type="URLMapper"/>
            <handler type="java:org.apache.axis.handlers.http.HTTPAuthHandler"/>
        </requestFlow>
        <parameter name="qs:list" value="org.apache.axis.transport.http.QSListHandler"/>
        <parameter name="qs:wsdl" value="org.apache.axis.transport.http.QSWSDLHandler"/>
        <parameter name="qs.list" value="org.apache.axis.transport.http.QSListHandler"/>
        <parameter name="qs.method" value="org.apache.axis.transport.http.QSMethodHandler"/>
        <parameter name="qs:method" value="org.apache.axis.transport.http.QSMethodHandler"/>
        <parameter name="qs.wsdl" value="org.apache.axis.transport.http.QSWSDLHandler"/>
    </transport>
    <transport name="local">
        <responseFlow>
            <handler type="LocalResponder"/>
        </responseFlow>
    </transport>
</deployment>


applicationContext.xml
1
2
3
4
5
6
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
    "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
    <bean id="bizLogic" class="axisspring.BusinessLogicImpl" />
</beans>


web.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/applicationContext.xml</param-value>
    </context-param>
    <listener>
    <listener-class>org.apache.axis.transport.http.AxisHTTPSessionListener</listener-class>
    </listener>  
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    <servlet>
        <description>Apache-Axis Servlet</description>
        <servlet-name>AxisServlet</servlet-name>
        <servlet-class>org.apache.axis.transport.http.AxisServlet</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>AxisServlet</servlet-name>
        <url-pattern>/soap/*</url-pattern>
    </servlet-mapping>
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>
    <mime-mapping>
        <extension>wsdl</extension>
        <mime-type>text/xml</mime-type>
    </mime-mapping>
    <mime-mapping>
        <extension>xsd</extension>
        <mime-type>text/xml</mime-type>
    </mime-mapping>
    <welcome-file-list>
        <welcome-file>
            index.jsp
        </welcome-file>
    </welcome-file-list>
</web-app>


Stpe 4:
  開啟 http://localhost/yourwebapp/soap
  應該就可以看到 web services 列表

參考資源
http://javaboutique.internet.com/tutorials/axisspring/

ps:剛開始學,觀念還不是很清楚,請見諒


gamerqq edited on 2006-04-21 16:24
reply to postreply to post
» JWorld@TW »  Java Application Framework » Spring

reply to topicthreaded modego to previous topicgo to next topic
  已讀文章
  新的文章
  被刪除的文章
Jump to the top of page

JWorld@TW 本站商標資訊

Powered by Powerful JuteForum® Version Jute 1.5.8