現有銀行模擬系統(EJB 實現),需暴露為 SOAP/HTTP Web 服務,支援審計員監管。
java.rmi.Remote,拋 RemoteException)webservices.xml 部署描述符接口繼承 java.rmi.Remote,方法拋 RemoteException,參數/返回值為 JAX-RPC 相容類型(JavaBean + 原始類型)。
<configuration xmlns="https://java.sun.com/xml/ns/jax-rpc/ri/config">
<service name="BusinessLogic"
targetNamespace="https://ibm.com/samples/workdev/v1/wsdl"
typeNamespace="https://ibm.com/samples/workdev/v1/types"
packageName="com.ibm.workdev.v1.interfaces">
<interface name="com.ibm.workdev.v1.interfaces.BusinessLogicEndpoint"/>
</service>
</configuration>
wscompile -classpath ... -gen:server -f:documentliteral config.xml
long_2 → amount。complexType 並關聯到響應消息部件。<configuration xmlns="...">
<wsdl location="file:///BusinessLogic.wsdl" packageName="com.ibm.workdev.v1.interfaces"/>
</configuration>
wscompile -s src-gen -keep -mapping mapping.xml -classpath ... -gen:client -f:documentliteral config.xml
後處理:修正 wsdl-message-part-name(從 parameters 改為實際元素名),刪除 void 方法的 wsdl-return-value-mapping。
Servlet 實現類 BusinessLogicServiceServlet 調用 EJB。安全攔截器 WSSecurityServerHandler 實現 javax.xml.rpc.handler.Handler:
ThreadLocal,Servlet 取出建立 LoginContext,以認證主體身份 Subject.doAs 調用 EJB。<webservices xmlns="https://java.sun.com/xml/ns/j2ee" version="1.1">
<webservice-description>
<webservice-description-name>BusinessLogic</webservice-description-name>
<wsdl-file>WEB-INF/BusinessLogic.wsdl</wsdl-file>
<jaxrpc-mapping-file>WEB-INF/jaxrpc-mapping.xml</jaxrpc-mapping-file>
<port-component>
<port-component-name>BusinessLogicEndpointPort</port-component-name>
<wsdl-port xmlns:ns="...">ns:BusinessLogicEndpointPort</wsdl-port>
<service-endpoint-interface>com.ibm.workdev.v1.interfaces.BusinessLogicEndpoint</service-endpoint-interface>
<service-impl-bean><servlet-link>BusinessLogicServiceServlet</servlet-link></service-impl-bean>
<handler>
<handler-name>ServerSecurityHandler</handler-name>
<handler-class>com.ibm.workdev.v1.web.wssec.WSSecurityServerHandler</handler-class>
<soap-header xmlns:wssec="...">wssec:Security</soap-header>
</handler>
</port-component>
</webservice-description>
</webservices>
https://localhost:8080/workdev/service?WSDL。-gen:client)。web.xml 中聲明 <service-ref>,含 handler 鏈(客戶端加密/簽名)。new InitialContext().lookup("java:comp/env/service/BusinessLogicService")。Geronimo 依賴 J2EE 1.4 標準提供健壯 Web 服務支援。雖工具鏈尚待成熟,但手工掌握 wscompile、描述符配置、Handler 鏈開發,即可構建生產級服務。未來隨 WTP 完善 JSR 109 支援,開發效率將大幅提升。