您的位置:首页 > 运维架构 > Tomcat

Axis2发布服务,支持Tomcat和Weblogic的SSHWeb项目部署

2017-09-26 09:28 771 查看
先说下遇到的问题,在SSHWeb项目中使用JDK自带的jar发布WebService(Endpoint.publish),在tomcat下可以正常发布,但是在Weblogic报奇葩错误,如Struts2-core.xml解析出错,还有weblogic实例重名错误等;用了一天网上也找不到解决方案,就改为Axis2发布WebService,发现也会出问题,但是可以在网上找到解决办法

一、非Maven的Axis2方式

1、官网下载Axis2的war包,解压后将conf、lib、modules拷贝到Web项目webapp的WEB-INF下,然后再新建services文件-》webservices-》META-INF文件夹,META-INF下创建services.xml文件;将解压的axis2文件夹下axis2-web拷贝到webapp下,访问该站点可以看到发布的服务,结果如下右图

<?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>


weblogic.xml
4、web.xml相关配置如下

<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>D:\Oracle\Middleware\user_projects\domains\base_domain\servers\AdminServer\tmp\_WL_user\E7-Planning_war\j3vqe1\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>


5、services.xml中配置的对应类,使用spring就是@Component注解的类,不使用就是普通类

6、Struts2会拦截请求,报错,在struts.xml配置相关如下

<constant name="struts.action.excludePattern" value="/services.*"/>


7、访问http://localhost:8081/services/tongweiws?wsdl     tongweiws为service的name属性

8、客户端使用HttpURLConnection方式请求服务时,客户端报错如下



然后在AxisServlet的dopost方法处断点,查看此处的异常如下

The endpoint reference (EPR) for the Operation not found is http://192.168.0.97:8081/services/tongweiws and the WSA Action = null. If this EPR was previously reachable, please contact the server administrator.

说明客户端需要设置action,如下

connection.setRequestProperty("SOAPAction","urn:test");

二、maven的Axis2

<properties>
<axis2.version>1.7.6</axis2.version>
</properties>
<!--Axis2-->
<!--<dependency>-->
<!--<groupId>org.apache.axis2</groupId>-->
<!--<artifactId>axis2</artifactId>-->
<!--<version>${axis2.version}</version>-->
<!--</dependency>-->
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-spring</artifactId>
<version>${axis2.version}</version>
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-transport-http</artifactId>
<version>${axis2.version}</version>
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-transport-local</artifactId>
<version>${axis2.version}</version>
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-xmlbeans</artifactId>
<version>${axis2.version}</version>
</dependency>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: