weblogic部署axis2实现的webservice服务的web工程(非打war包)

首先声明哈借鉴了别人的贡献,再稍微详细点做个记录。
下面步骤的前提是你的weblogic是得是部署好的哈,可以登录console直接部署的。
1.创建一个web工程(非maven,因为maven的web项目目录级别比较乱,没调试通)
在这里插入图片描述在这里插入图片描述在这里插入图片描述这样我们就有一个web工程了

2.在这里插入图片描述到官网上下载axis2的包
官网:http://axis.apache.org/axis2/java/core/
下载后进行解压得到war包
在这里插入图片描述解压开war包
在这里插入图片描述
a.将axis2-web粘到工程WebContent下
b.将解压开的war包里WEB-INF/里面的lib的包,粘到工程中的WebContent/WEB-INF/lib下
c.将解压开的war包里WEB-INF/里面modules,conf文件夹粘到工程中的WebContent/WEB-INF下
在这里插入图片描述
d.在如上图的目录下创建services目录以及如下一直到services.xml文件

services.xml文件内容为:

<?xml version="1.0" encoding="UTF-8"?>
<service name="Testservice">  <!-- 指定服务名,随便定义 -->
    <description>测试axis2webservices</description><!-- 服务的作用说明,可写可不写 -->
     <!-- 指定要发布的类路径 -->
    <parameter name="ServiceClass">  <!-- 自定义    name-->
           axis2.WebserviceDemo     <!-- 写的类路径 -->
    </parameter>  
   <!-- 类里面的方法,有其他方法就在写个operation标签 -->
    <operation name="sayHello">  <!-- 类里面的方法名 -->
        <messageReceiver class="org.apache.axis2.rpc.receivers.RPCMessageReceiver" />  
    </operation>   
</service>

e.web.xml文件内容
注意下面的param-value,按照weblogic在服务器的对应位置进行修改

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
  <display-name>webservice</display-name><!-- 项目名,创建项目时候自动生成的 -->
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
  
  
    <servlet>
        <servlet-name>AxisServlet</servlet-name>
        <servlet-class>org.apache.axis2.transport.http.AxisServlet</servlet-class>
        <!--下面配置是支持Axis2在Weblogic可发布服务,value指的是域下对应Web项目包WEB-INF下,其实就是找到拷贝过去的那三个文件夹-->
        <init-param>
            <param-name>axis2.repository.path</param-name>
            <param-value>/home/weblogic/Oracle/Middleware/Oracle_Home/user_projects/domains/base_domain/servers/AdminServer/tmp/_WL_user/webservice/byjuto/war/WEB-INF</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>AxisServlet</servlet-name>
        <url-pattern>/services/*</url-pattern>
    </servlet-mapping>
  
  
  
</web-app>

f.weblogic.xml内容

<?xml version="1.0" encoding="UTF-8"?>
<wls:weblogic-web-app xmlns:wls="http://www.bea.com/ns/weblogic/weblogic-web-app" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd http://www.bea.com/ns/weblogic/weblogic-web-app http://www.bea.com/ns/weblogic/weblogic-web-app/1.0/weblogic-web-app.xsd">
    <wls:weblogic-version>10.3.0</wls:weblogic-version>
    <wls:context-root>E7-Planning</wls:context-root>
    <wls:container-descriptor>
        <wls:servlet-reload-check-secs>-1</wls:servlet-reload-check-secs>
        <wls:resource-reload-check-secs>-1</wls:resource-reload-check-secs>
        <wls:prefer-web-inf-classes>true</wls:prefer-web-inf-classes>
    </wls:container-descriptor>
    <wls:session-descriptor>
        <wls:cookie-name>JSESSIONID1</wls:cookie-name>
        <wls:encode-session-id-in-query-params>true</wls:encode-session-id-in-query-params>
    </wls:session-descriptor>
</wls:weblogic-web-app>

所有的配置文件就这些了,具体的结构如下

在这里插入图片描述
然后开始填代码

package axis2;


public class WebserviceDemo {
	 public String  sayHello(String name){  
	        return "hello " + name;  
	    }  

	

}

这个是提供webservice服务的实现类,注意接口里面的方法要是public的,然后把services.xml文件中对应的内容修改一下。然后就可以将工程打成war包进行部署了,具体打包以及weblogic部署步骤就不详细记录了,可自行百度。

部署完成之后,在页面上进行访问在这里插入图片描述看到上面的接口信息就证明接口是打开的。
具体的url格式如下:
ip:端口/weblogic.xml文件中的context-root值/services/services.xml文件的service name值?wsdl

接口确认打开之后就可以自行编写客户端进行测试。

package axis2;



import javax.xml.namespace.QName;


import org.apache.axis2.AxisFault;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.rpc.client.RPCServiceClient;

public class TextClient {
	 public static void main(String[] args) {
		    
	        try {
	            //本机tomcat端口默认为8081,参数是wsdl网址的一部分
	      
	            EndpointReference targetEPR = new EndpointReference("http://127.0.0.1:7001/E7-Planning/services/Testservice");
	        	RPCServiceClient sender = new RPCServiceClient();  
	            Options options = sender.getOptions();  
	            options.setTimeOutInMilliSeconds(2*20000L);//超时时间20s  
	            options.setTo(targetEPR);  
	            /**
	             * 参数:
	             * 1:在网页上执行 wsdl后xs:schema标签的targetNamespace路径
	             * <xs:schema  targetNamespace="http://test.axiswevservice.com">
	             * 2:<xs:element name="test"> ======这个标签中name的值
	             * 
	             */
	            QName qname = new QName("http://axis2", "sayHello"); 
	            String str = "客户端调用成功";  //方法的入参
	            Object[] param = new Object[]{str};  
	            Class<?>[] types = new Class[]{String.class};  //这是针对返值类型的  
	            /** 
	             * RPCServiceClient类的invokeBlocking方法调用了WebService中的方法。 
	             * invokeBlocking方法有三个参数 
	             * 第一个参数的类型是QName对象,表示要调用的方法名; 
	             * 第二个参数表示要调用的WebService方法的参数值,参数类型为Object[]; 
	             * 第三个参数表示WebService方法的返回值类型的Class对象,参数类型为Class[]。 
	             *  
	             * 当方法没有参数时,invokeBlocking方法的第二个参数值不能是null,而要使用new Object[]{}。 
	             */  
	            Object[] response1 = sender.invokeBlocking(qname, param, types);  
	            System.out.println(response1[0]);
	        } catch (AxisFault e) {
	            // TODO Auto-generated catch block
	            e.printStackTrace();
	        }
	        
	    }

}

在这里插入图片描述成功啦!

在网上综合了好几版内容才在weblogic上调通,送给大家不用谢( ̄▽ ̄)~*

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值