阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

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

136次阅读
没有评论

共计 4144 个字符,预计需要花费 11 分钟才能阅读完成。

先说下遇到的问题,在 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 下, 访问该站点可以看到发布的服务,结果如下右图

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

2、services.xml 配置文件内容如下

<?xml version="1.0" encoding="UTF-8" ?>
<service name="tongweiws">
    <description>
        publish webservice
    </description>
    <messageReceivers>
        <messageReceiver mep="http://www.w3.org/ns/wsdl/in-out"
                         class="org.apache.axis2.rpc.receivers.RPCMessageReceiver" />
        <messageReceiver mep="http://www.w3.org/ns/wsdl/in-only"
                         class="org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver" />
    </messageReceivers>
    <!-- 不使用 Spring 注解 -->
    <!--<parameter name="ServiceClass">com.epoch.planning.projects.tongwei.SyncUser</parameter>-->
    
    <!-- 使用 Spring 注解,@Component 注解的类,beanName 如果不指定,默认是类名首字母小写 -->
    <parameter name="SpringBeanName">syncUser</parameter>
    <parameter name="ServiceObjectSupplier">org.apache.axis2.extensions.spring.receivers.SpringServletContextObjectSupplier</parameter>
</service>

3、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>

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 方式请求服务时,客户端报错如下

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

然后在 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>

本文永久更新链接地址 :http://www.linuxidc.com/Linux/2017-12/149204.htm

正文完
星哥说事-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2022-01-21发表,共计4144字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中