前言

最近公司要开发个接口,要用webservices接口实现,而且使用的是axis1.4框架,webservices和axis这两个东西我之前都没接触过,而且axis1.4这个框架06年就不再维护了,没办法,客户就是上帝。上网查了一圈,基本都是spring整合axis的,而公司用的是springboot,比较头疼,在此记录下搭建过程。

一、引入依赖

 <dependency>
<groupId>org.apache.axis</groupId>
<artifactId>axis</artifactId>
<version>1.4</version>
</dependency> <dependency>
<groupId>axis</groupId>
<artifactId>axis-jaxrpc</artifactId>
<version>1.4</version>
</dependency> <dependency>
<groupId>commons-discovery</groupId>
<artifactId>commons-discovery</artifactId>
<version>0.2</version>
</dependency>
<dependency>
<groupId>wsdl4j</groupId>
<artifactId>wsdl4j</artifactId>
<version>1.6.3</version>
</dependency>

二、写个接口以及实现类

接口:

 public interface HelloService {
public String sayHello(String info); }

实现类:

 public class HelloServiceImpl implements HelloService {
public String sayHello(String info) {
return "sayHello:"+info;
}
}

三、创建资源文件server-config.wsdd

 <?xml version="1.0" encoding="UTF-8"?>
<deployment xmlns="http://xml.apache.org/axis/wsdd/"
xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">
<handler type="java:org.apache.axis.handlers.http.URLMapper"
name="URLMapper" /> <!--要告诉别人的接口名-->
<service name="HelloServiceImpl" provider="java:RPC">
<!--这个是 实现类-->
<parameter name="className" value="com.codefish.javalab.ws.server.HelloServiceImpl" />
<!--这是是暴露的方法名 比如可以值暴露一个-->
<parameter name="allowedMethods" value="sayHello" />
<!--这是是暴露的方法名 也可以用* 表示暴露全部的public方法-->
<!--<parameter name="allowedMethods" value="*" />-->
</service> <transport name="http">
<requestFlow>
<handler type="URLMapper" />
</requestFlow>
</transport> </deployment>

四、添加servlet过滤规则

新建com.example.servlet.WebServlet,继承AxisServlet。

     package com.example.servlet;
import org.apache.axis.transport.http.AxisServlet;
@javax.servlet.annotation.WebServlet(
urlPatterns = "/services/*",
loadOnStartup = 1,
name = "AxisServlet"
)
public class WebServlet extends AxisServlet { }

五、重写Axis的配置工厂信息

因为我想要以jar包形式发布,所以需要重写EngineConfigurationFactory类,否则会访问不到。新建org.apache.axis.configuration.EngineConfigurationFactoryServlet,继承EngineConfigurationFactoryDefault。更改的是getServerEngineConfig(ServletConfig cfg)方法。(注意:该类需要放在org.apache.axis.configuration包下,我尝试放在其他路径下无效,如有大神知道,还望告知

 /*
* Copyright 2002-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/ package org.apache.axis.configuration; import org.apache.axis.AxisProperties;
import org.apache.axis.ConfigurationException;
import org.apache.axis.EngineConfiguration;
import org.apache.axis.EngineConfigurationFactory;
import org.apache.axis.components.logger.LogFactory;
import org.apache.axis.server.AxisServer;
import org.apache.axis.utils.ClassUtils;
import org.apache.axis.utils.Messages;
import org.apache.commons.logging.Log; import javax.servlet.ServletConfig;
import java.io.InputStream; /**
* This is a default implementation of ServletEngineConfigurationFactory.
* It is user-overrideable by a system property without affecting
* the caller. If you decide to override it, use delegation if
* you want to inherit the behaviour of this class as using
* class extension will result in tight loops. That is, your
* class should implement EngineConfigurationFactory and keep
* an instance of this class in a member field and delegate
* methods to that instance when the default behaviour is
* required.
*
* @author Richard A. Sitze
* @author Davanum Srinivas (dims@apache.org)
*/
public class EngineConfigurationFactoryServlet
extends EngineConfigurationFactoryDefault {
protected static Log log =
LogFactory.getLog(EngineConfigurationFactoryServlet.class.getName()); private ServletConfig cfg; /**
* Creates and returns a new EngineConfigurationFactory.
* If a factory cannot be created, return 'null'.
* <p>
* The factory may return non-NULL only if:
* - it knows what to do with the param (param instanceof ServletContext)
* - it can find it's configuration information
*
* @see EngineConfigurationFactoryFinder
*/
public static EngineConfigurationFactory newFactory(Object param) {
/**
* Default, let this one go through if we find a ServletContext.
*
* The REAL reason we are not trying to make any
* decision here is because it's impossible
* (without refactoring FileProvider) to determine
* if a *.wsdd file is present or not until the configuration
* is bound to an engine.
*
* FileProvider/EngineConfiguration pretend to be independent,
* but they are tightly bound to an engine instance...
*/
return (param instanceof ServletConfig)
? new EngineConfigurationFactoryServlet((ServletConfig) param)
: null;
} /**
* Create the default engine configuration and detect whether the user
* has overridden this with their own.
*/
protected EngineConfigurationFactoryServlet(ServletConfig conf) {
super();
this.cfg = conf;
} /**
* Get a default server engine configuration.
*
* @return a server EngineConfiguration
*/
public EngineConfiguration getServerEngineConfig() {
return getServerEngineConfig(cfg);
} /**
* Get a default server engine configuration in a servlet environment.
*
* @param cfg a ServletContext
* @return a server EngineConfiguration
*/
private static EngineConfiguration getServerEngineConfig(ServletConfig cfg) { // Respect the system property setting for a different config file
String configFile = cfg.getInitParameter(OPTION_SERVER_CONFIG_FILE);
if (configFile == null)
configFile =
AxisProperties.getProperty(OPTION_SERVER_CONFIG_FILE);
if (configFile == null) {
configFile = SERVER_CONFIG_FILE;
} /**
* Flow can be confusing. Here is the logic:
* 1) Make all attempts to open resource IF it exists
* - If it exists as a file, open as file (r/w)
* - If not a file, it may still be accessable as a stream (r)
* (env will handle security checks).
* 2) If it doesn't exist, allow it to be opened/created
*
* Now, the way this is done below is:
* a) If the file does NOT exist, attempt to open as a stream (r)
* b) Open named file (opens existing file, creates if not avail).
*/ /*
* Use the WEB-INF directory
* (so the config files can't get snooped by a browser)
*/
String appWebInfPath = "/WEB-INF";
//由于部署方式变更为jar部署,此处不可以使用改方式获取路径
// ServletContext ctx = cfg.getServletContext();
// String realWebInfPath = ctx.getRealPath(appWebInfPath); FileProvider config = null;
String realWebInfPath = EngineConfigurationFactoryServlet.class.getResource(appWebInfPath).getPath(); /**
* If path/file doesn't exist, it may still be accessible
* as a resource-stream (i.e. it may be packaged in a JAR
* or WAR file).
*/
InputStream iss = ClassUtils.getResourceAsStream(EngineConfigurationFactoryServlet.class, appWebInfPath+"/" + SERVER_CONFIG_FILE);
if (iss != null) {
// FileProvider assumes responsibility for 'is':
// do NOT call is.close().
config = new FileProvider(iss);
} if (config == null) {
log.error(Messages.getMessage("servletEngineWebInfError03", ""));
} /**
* Couldn't get data OR file does exist.
* If we have a path, then attempt to either open
* the existing file, or create an (empty) file.
*/
if (config == null && realWebInfPath != null) {
try {
config = new FileProvider(realWebInfPath, configFile);
} catch (ConfigurationException e) {
log.error(Messages.getMessage("servletEngineWebInfError00"), e);
}
} /**
* Fall back to config file packaged with AxisEngine
*/
if (config == null) {
log.warn(Messages.getMessage("servletEngineWebInfWarn00"));
try {
InputStream is =
ClassUtils.getResourceAsStream(AxisServer.class,
SERVER_CONFIG_FILE);
config = new FileProvider(is); } catch (Exception e) {
log.error(Messages.getMessage("servletEngineWebInfError02"), e);
}
} return config;
}
}

六、配置Application

添加注解 @ServletComponentScan

@SpringBootApplication
@ServletComponentScan //扫描自定义的WebFilter和WebListener,否则无法扫描到
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}

启动程序,访问http://localhost:8080/services,会将server-config.wsdd里面的接口发布出来,此时客户端可以调用接口。

springboot整合axis1.4搭建服务端的更多相关文章

  1. CAS 5.1.x 的搭建和使用(一)—— 通过Overlay搭建服务端

    CAS单点登录系列: CAS 5.1.x 的搭建和使用(一)—— 通过Overlay搭建服务端 CAS5.1.x 的搭建和使用(二)—— 通过Overlay搭建服务端-其它配置说明 CAS5.1.x ...

  2. CAS 5.1.x 的搭建和使用(二)—— 通过Overlay搭建服务端-其它配置说明

    CAS单点登录系列: CAS 5.1.x 的搭建和使用(一)—— 通过Overlay搭建服务端 CAS5.1.x 的搭建和使用(二)—— 通过Overlay搭建服务端-其它配置说明 CAS5.1.x ...

  3. 使用Apache MINA框架搭建服务端

    使用MINA框架搭建服务端步骤: 1.定义一个启动服务的类MinaServer,并实现接口ServletContextListener 2.定义一个处理业务逻辑的类MinaServerHandler, ...

  4. SpringBoot整合阿里短信服务

    导读 由于最近手头上需要做个Message Gateway,涉及到:邮件(点我直达).短信.公众号(点我直达)等推送功能,网上学习下,整理下来以备以后使用. 步骤 点我直达 登录短信服务控制台 点我直 ...

  5. 【Java分享客栈】SpringBoot整合WebSocket+Stomp搭建群聊项目

    前言 前两周经常有大学生小伙伴私信给我,问我可否有偿提供毕设帮助,我说暂时没有这个打算,因为工作实在太忙,现阶段无法投入到这样的领域内,其中有两个小伙伴又问到我websocket该怎么使用,想给自己的 ...

  6. dubbo学习实践(4)之Springboot整合Dubbo及Hystrix服务熔断降级

    1. springboot整合dubbo 在provider端,添加maven引入,修改pom.xml文件 引入springboot,版本:2.3.2.RELEASE,dubbo(org.apache ...

  7. 用“MEAN”技术栈开发web应用(二)express搭建服务端框架

    上一篇我们讲了如何使用angular搭建起项目的前端框架,前端抽象出一个service层来向后端发送请求,后端则返回相应的json数据.本篇我们来介绍一下,如何在nodejs环境下利用express来 ...

  8. c#搭建服务端 准备工作(1)

    思路 搭建服务器主要为了接收客户端所传来的数据,在学习过程中,整体的搭建逻辑大体分为以下几个步骤: 1.启动线程监听服务端口 2.监听客户端链接并进行处理 3.接收客户端传入的消息 4.向客户端回传( ...

  9. axis1 创建service服务端 , axis1 客户端

    axis1 服务端配置 1.首先建立一个项目 axisTest 不需多说 2.在lib下放入需要的jar包  点击下载 :axis所需的jar包下载 3.然后需要在web.xml里面加入: <s ...

随机推荐

  1. python_08

    一.作业 ''' 主页: 图标地址.下载次数.大小.详情页地址 详情页: 游戏名.好评率.评论数.小编点评.下载地址.简介.网友评论.1-5张截图链接地址. https://www.wandoujia ...

  2. scrapy抓取豆瓣电影相关数据

    1. 任务分析及说明 目标网站:https://movie.douban.com/tag/#/ 抓取豆瓣电影上,中国大陆地区,相关电影数据约1000条:数据包括:电影名称.导演.主演.评分.电影类型. ...

  3. SQL语句实用技巧1

    --显示行号 select *, ROW_NUMBER() OVER(Order by TYPENAME ) AS RowNumber from ( select distinct TYPENAME ...

  4. JavaScript实战实例剖析——(激励倒计时日历)

    如今JavaScript在前端开发中的地位越来越高,掌握JavaScript的深度往往能决定你职业道路深远,这次通过制作 带着倒计时功能的激励日历的小实例,进一步细致的掌握JavaScript的语法与 ...

  5. [ASP.NET Core 3框架揭秘] 配置[2]:读取配置数据[下篇]

    [接上篇]提到“配置”二字,我想绝大部分.NET开发人员脑海中会立即浮现出两个特殊文件的身影,那就是我们再熟悉不过的app.config和web.config,多年以来我们已经习惯了将结构化的配置定义 ...

  6. nginx重启后,反向代理失败之问题排查记录

    问题与排查过程 本地开发环境的服务器,部署了nginx,nginx上对静态的web前端页面进行了http 80端口代理:然后呢,因为一些原因,服务器重启了,重启服务器后,我去把nginx启动起来,但是 ...

  7. python 3 mro

    __mro__ 1.只有在python2中才分新式类和经典类,python3中统一都是新式类 2.在python2中,没有显式的继承object类的类,以及该类的子类,都是经典类 3.在python2 ...

  8. 手机端web(iPad)页面自适应js

    有关编写手机页面(ipad页面)自适应的方法有很多,比如:bootstrap,rem等等.下面分享给大家一个js控制viewPort视区自适应缩放的方法(我给它命名为phone.js): 将phone ...

  9. css重置样式

    <style> html, body, div, span, applet, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, ...

  10. shell 脚本运行 hive sql

    #!/b START=$(date +%s); datebegin=`date -d "$1" "+%Y%m%d"` dateend=`date -d &quo ...