前言

最近公司要开发个接口,要用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. vue3.0wactch监听

    <template> <div> <input v-model="count" /> </div> </template> ...

  2. 20191017-7 alpha week 2/2 Scrum立会报告+燃尽图 06

    此作业要求参见https://edu.cnblogs.com/campus/nenu/2019fall/homework/9803 一.小组情况 队名:扛把子 组长:迟俊文 组员:宋晓丽 梁梦瑶 韩昊 ...

  3. pwnable.kr第二天

    3.bof 这题就是简单的数组越界覆盖,直接用gdb 调试出偏移就ok from pwn import * context.log_level='debug' payload='A'*52+p32(0 ...

  4. IDEA导入MySQL的jdbc驱动,并操作数据库

    将MySQL的jdbc驱动,导入IDEA的方式,虽然也能连接并且操作数据库,但并不推荐这种方式,推荐使用Maven工程的方式:https://www.cnblogs.com/dadian/p/1193 ...

  5. ASP.NET Core +Highchart+ajax绘制动态柱状图

    一.项目介绍利用前端Highchart,以及ajax向后台获取数据,绘制动态柱状图.hightchart其他实例可查看官网文档.[Highchart](https://www.highcharts.c ...

  6. 以传参的方式执行shell(模板)

    以传参的方式执行shell(模板) #!bin/bash # USE: Template # author : xiaowei # -- # state : -name 选项必选,,, -v -m 选 ...

  7. Mac下PHP连接MySQL报错"No such file or directory"的解决办法

    首先做个简短的介绍. [说明1]MAC下MYSQL的安装路径: /usr/local/mysql-5.1.63-osx10.6-x86_64 数据库的数据文件在该目录的data文件夹中: 命令文件在b ...

  8. Chapter 07-Basic statistics(Part4 t-tests&&nonparametric tests of group difference)

    一. t-tests 这一部分我们使用分布在MASS包中的UScrime数据集.它是关于美国47个州在1960年时,关于惩罚制度对犯罪率的影响. Prob:监禁(坐牢)的概率: U1:14到24岁的城 ...

  9. c语言l博客作业09

    问题 答案 这个作业属于那个课程 C语言程序设计II 这个作业要求在哪里 https://edu.cnblogs.com/campus/zswxy/CST2019-2/homework/8655 我在 ...

  10. Nuget Server的搭建及实践之旅

    一. 背景 在做的一个项目使用的是Asp.Net MVC,由于缺少规范与约束,团队成员在使用类库各自为政,时常出现路径和版本不一致的问题.在一个同事建议下,开始尝试使用Nuget 管理项目或公司使用的 ...