前言

最近公司要开发个接口,要用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. [apue] 神奇的 Solaris pipe

    说到 pipe 大家可能都不陌生,经典的pipe调用配合fork进行父子进程通讯,简直就是Unix程序的标配. 然而Solaris上的pipe却和Solaris一样是个奇葩(虽然Solaris前途黯淡 ...

  2. 设计模式之美学习(九):业务开发常用的基于贫血模型的MVC架构违背OOP吗?

    我们都知道,很多业务系统都是基于 MVC 三层架构来开发的.实际上,更确切点讲,这是一种基于贫血模型的 MVC 三层架构开发模式. 虽然这种开发模式已经成为标准的 Web 项目的开发模式,但它却违反了 ...

  3. gulp 自动化构建html项目--自动刷新

    使用gulp自动化构建项目是前端学习的重要部分,gulp依赖于node.js.首选电脑要配置node和npm. 查看node版本号 node --version 查看npm 版本 npm --vers ...

  4. [ch03-02] 交叉熵损失函数

    系列博客,原文在笔者所维护的github上:https://aka.ms/beginnerAI, 点击star加星不要吝啬,星越多笔者越努力. 3.2 交叉熵损失函数 交叉熵(Cross Entrop ...

  5. day20190904一号店网页HTML+CSS

    1.知识要理一理.梳理.当天讲了什么内容?当天我学习到了什么内容?看懂.所有的学习型从模仿开始.1.看懂代码,看懂思路,学思路,多问自己问题,为什么要这么写?下一步为什么要这么写?因 果.2.多练多敲 ...

  6. Python下定义输出日志

    # 话不多说,直接看代码,,, # -*- coding:UTF-8 -*- # python version: 2.7.15 #脚本名, 日志名,日志路径 import os import sys ...

  7. 程序员的进阶课-架构师之路(9)-平衡二叉树(AVL树)

    版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明. 本文链接:https://blog.csdn.net/m0_37609579/article/de ...

  8. 最小化安装CentOS 7 系统

    目录 CentOS 程序准备 开始安装系统 创建虚拟机 安装系统 CentOS 运维最常接触的系统就是CentOS系统,无论是版本 6 还是版本 7 而且在安装系统时,讲究最小化安装系统,之后当需要什 ...

  9. 转:浅谈Spring的PropertyPlaceholderConfigurer

    大型项目中,我们往往会对我们的系统的配置信息进行统一管理,一般做法是将配置信息配置与一个cfg.properties的文件中,然后在我们系统初始化的时候,系统自动读取cfg.properties配置文 ...

  10. Java语法进阶13-文件、IO流

    File File是文件和目录路径名的抽象表示形式,即File类是文件或目录的路径,而不是文件本身,因此File类不能直接访问文件内容本身,如果需要访问文件内容本身,则需要使用输入/输出流. File ...