JBoss 4.0 中使用web service

zz/2024/5/21 21:37:26

大致过程

1. 安装Jboss
2. 将webservice endpoint当成servlet
3. 写一个远端的interface
4. 在eclipse中配置一个external tool:wscompile
4. 写一个config.xml, 然后用JWSDP的JAXRPC中的wscompile生成mapping.xml和wsdl
5. 必须存在4个文件:web.xml,webservices.xml,mapping.xml和.wsdl
6. webservices 中的port name 要和.wsdl中的一致
7. 使用lomboz或jbossIDE deploy

详细实例:

1. create a class

package service;


public class Hello {
 public boolean helloDancy(String hello){
  System.out.println(hello);
  return true;
 }

}

2. create corresponding remote interface

package remote;

import java.rmi.Remote;
import java.rmi.RemoteException;

public interface HelloRemote extends Remote {
 public boolean helloDancy(String hello) throws RemoteException;
}

3. create web.xml in WEB-INF folder

<?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">
 <servlet>
  <servlet-name>helloServlet</servlet-name>
  <servlet-class>service.Hello</servlet-class>
 </servlet>
 <servlet-mapping>
  <servlet-name>helloServlet</servlet-name>
  <url-pattern>/hello</url-pattern>
 </servlet-mapping>
</web-app>

4. create config.xml 

<?xml version="1.0" encoding="UTF-8"?>
<configuration xmlns="http://java.sun.com/xml/ns/jax-rpc/ri/config">
 <service name="helloservice"
  targetNamespace="/hello"
  typeNamespace="/hello/types"
        packageName="service">
  <interface name="remote.HelloRemote" />
 </service>
</configuration>

5. create folder wsdl in WEB-INF/ and run wscompile from jaxrpc folder in sun's jwsdp1.5 package

  wscompile -cp output/classes -gen:server -f:documentliteral -mapping jaxrpc-mapping.xml -keep config.xml

-keep: keep the generated source file

6. After executing wscompile.bat, a mapping.xml and helloservice.wsdl are generated

7. create webservice.xml

<?xml version="1.0" encoding="UTF-8"?>

<webservices 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://www.ibm.com/webservices/xsd/j2ee_web_services_1_1.xsd" version="1.1">
 
 <webservice-description>
  <webservice-description-name>hello world</webservice-description-name>
  <wsdl-file>WEB-INF/wsdl/helloservice.wsdl</wsdl-file>
        <jaxrpc-mapping-file>WEB-INF/mapping.xml</jaxrpc-mapping-file>
        <port-component>
            <port-component-name>hello-dancy</port-component-name>
            <wsdl-port>HelloRemotePort</wsdl-port>
            <service-endpoint-interface>remote.HelloRemote</service-endpoint-interface>
            <service-impl-bean>
                <servlet-link>helloServlet</servlet-link>
            </service-impl-bean>
        </port-component>
 </webservice-description>
</webservices>

8. create hello.war and deploy it to jboss4.0.1

9. create test client

public void testHelloDancy() {
  try{
   String urlstr   = "http://w20251-01:8080/hellows/hello?wsdl";
        
         java.net.URL url =  new java.net.URL(urlstr);

         String ns        = "/hello";
         QName  qname     = new QName(ns, "Helloservice");
         QName  port      = new QName(ns, "HelloRemotePort");
         QName  operation = new QName(ns, "helloDancy");

         Service service = new Service();
         Call call    = (Call)service.createCall();

            call.setTargetEndpointAddress( url );
            call.setOperationName( operation );
            call.addParameter( "String_1", XMLType.XSD_BASE64, ParameterMode.IN);
           
            call.setReturnType( XMLType.XSD_BOOLEAN);
         Boolean ret = (Boolean)call.invoke(new Object[]{"hello, Dancy".getBytes()});

  } catch(Exception e){
   e.printStackTrace();
  }
  
  
 }

10. set the classpath to lead to jars in axis's lib folder

11. customized object which involve byte[] as the input parameter
  client code:
 
   public void testHelloDancy() {
  try{
   String urlstr   = "http://w20251-01:8080/hellows/hello?wsdl";
        
         java.net.URL url =  new java.net.URL(urlstr);

         String ns        = "/hello";
         QName  qname     = new QName(ns, "Helloservice");
         QName  port      = new QName(ns, "HelloRemotePort");
         QName  operation = new QName(ns, "helloDancy");

         Service service = new Service();
         Call call    = (Call)service.createCall();
         QName    qn      = new QName( "/hello/types", "Dto" ); //refer to .wsdd
         call.registerTypeMapping(service.Dto.class, qn,
                       new org.apache.axis.encoding.ser.BeanSerializerFactory(service.Dto.class, qn),       
                       new org.apache.axis.encoding.ser.BeanDeserializerFactory(service.Dto.class, qn));       

            call.setTargetEndpointAddress( url );
            call.setOperationName( operation );
            call.addParameter( "arg0", qn, ParameterMode.IN);
           
            call.setReturnType( XMLType.XSD_BOOLEAN);
            service.Dto dto = new Dto();
            dto.setParam("hello, Dancy".getBytes());
         Boolean ret = (Boolean)call.invoke(new Object[]{dto});

  } catch(Exception e){
   e.printStackTrace();
  }



http://www.ngui.cc/zz/2700302.html

相关文章

CMPP相关参数说明

MsgFmt&#xff1a;0:ASCII串; 3:短信写卡操作; 4:二进制信息; 8:UCS2编码; 15:含GB汉字。。。。。。 status回复内容说明&#xff1a;8字节&#xff1a;message ID7字节&#xff1a;状态报告DELIVRD--成功&#xff0c;UNDELIV--失败10字节&#xff1a;消息submit时间&…

ME860安装安卓电子市场(android market)

安装过程&#xff1a; 我的国行ME860没有预装电子市场&#xff0c;有些国外的好软件无法装入我的手机&#xff0c;很痛苦&#xff0c;终于花了一些时间&#xff0c;成功安装电子市场。这里大致总结一下安装要点&#xff0c;1. 必须先安装Google service framework 2. 电子市场…

使用Java还是PHP构建网站(原文http://www.coderanch.com/t/569239/java/java/Java-PHP-Building-Websites)

PHP的好处&#xff1a; ----- API简单&#xff1a;PHP的API比java更直观&#xff0c;开发效率更高 Simpler API: PHPs API is much more intuitive than java. Takes less time to get productive with PHP than with Java PHP was not a resource hog: This is more rele…

tars-php 改造 invoke 支持多个tcp请求

现在“微服务”越来越少流行&#xff0c; 公司内部很多接口原来是CGI&#xff0c; 或者直接读DB&#xff0c;都改成用微服务接口&#xff0c; 不用CGI接口&#xff0c;其实挻好的&#xff0c;不好暴露接口到公网&#xff0c;网络延时也少&#xff0c;不需要做鉴权&#xff0c;直…

golang []map[string][string] , 先按大小,再按键名排序

type IpSortItem struct {Value int json:"value"Name string json:"name" } // 先按数量排序&#xff0c;再按名称排序 func sortIPView(rspData []map[string]string) []*IpSortItem {var totalList []intdataList : make(map[int][]string)for _, …

Java eclipse 设置代码折叠

1 windows->perferences->General->Editors->Structured Text Editors 选中Enable folding 效果 2 windows->perferences->Java->Editors->Folding 效果

javac 命令找不到

环境配置出错 仔细的查看每一个配置 复制黏贴的还是出现错误 在自己的电脑中生成的时候错误 仔细查看对比就可以了 使用命令也可以 set java_homeC:\Program Files\Java\jdk1.6.0_26 安装JDK的根目录 set classpath%JAVA_HOME%\lib\tools.jar;%JAVA_HOME%\lib\dt.jar; …

thinkPHP安装与配置

使用Git安装thinkPHP: 1 git clone https://gitee.com/liu21st/thinkphp5.git tp5 &#xff1b; clone thinkPHP的基础框架 &#xff0c;tp5为文件名字。 2 切换到tp5目录下在命令行中使用 3 git clone https://gitee.com/liu21st/framework.git thinkphp 4 git checko…

多线程同步I/O和单线程异步I/O

多线程同步I/O和单线程异步I/O 2014-08-24 同步I/O与异步I/O 线程在执行中如果遇到磁盘读写或网络通信&#xff08;统称IO操作&#xff09;&#xff0c;通常要耗费较长的时间&#xff0c;这时OS会剥夺此线程的CPU控制权&#xff0c;使其暂停执行&#xff0c;同时将资源让给其…

nodejs 调试技巧

1&#xff0c; 命令行调试 run 执行脚本,在第一行暂停 restart 重新执行脚本 cont, c 继续执行,直到遇到下一个断点 next, n 单步执行 step, s 单步执行并进入函数 out, o 从函数中步出 setBreakpoint(), sb() 在当前行设置断点 setBreakpoint(‘f()’), sb(...) 在函数f的第一…