handler name ="URLMapper" type ="java:org.apache.axis.handlers.http.URLMapper"/ > handler name ="Loc" />
0
  • 聊天消息
  • 系统消息
  • 评论与回复
登录后你可以
  • 下载海量资料
  • 学习在线课程
  • 观看技术视频
  • 写文章/发帖/加入社区
创作中心

完善资料让更多小伙伴认识你,还能领取20积分哦,立即完善>

3天内不再提示

如何成功迁移到Springboot工程

科技绿洲 来源:了不起 作者:了不起 2023-09-25 10:53 次阅读

最近在做一个老旧工程的迁移,其中一个服务端接口是使用 WebService 做的,而且用的是 Axis1.4 这种老的不能再老的框架。经过一番探索和研究,终于成功迁移到Springboot工程里,下面跟着我一步步操作。

Axis配置文件

Axis1.4 的入口配置文件是 server-config.wsdd,在 resources 中创建一个 WEB-INF 文件夹,将配置文件拷贝到其中。

图片

我们看一下配置文件的内容:

< ?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 name="URLMapper" type="java:org.apache.axis.handlers.http.URLMapper"/ >
    < handler name="LocalResponder" type="java:org.apache.axis.transport.local.LocalResponder"/ >

    < transport name="http" >
        < requestFlow >
            < handler type="URLMapper"/ >
        < /requestFlow >
    < /transport >

    < transport name="local" >
        < responseFlow >
            < handler type="LocalResponder"/ >
        < /responseFlow >
    < /transport >

    < !-- 示例接口 -- >
    < service name="DemoService" provider="java:RPC" >
        < parameter name="className" value="com.test.webservice.DemoService"/ >
        < parameter name="allowedMethods" value="*"/ >
    < /service >

< /deployment >

主要看最后一段:声明了一个示例接口:服务名为DemoService,映射的类为com.test.webservice.DemoService,方法名为*(通配符代表与类中的方法名一样)

接口类

简简单单的一个接口类:

package com.test.webservice;

import org.springframework.stereotype.Component;

@Component
public class DemoService {

    public String test() {
        return "这是一个Axis1.4接口。";
    }

}

我们如何把这个接口发布出去呢,接着往下看。

引入依赖

我这里用的是 gradle 构建的:

implementation('org.apache.axis:axis:1.4')
implementation('org.apache.axis:axis-jaxrpc:1.4')
implementation('axis:axis-wsdl4j:1.5.1')
implementation('commons-discovery:commons-discovery:0.5')

继承AxisServlet

创建一个Servlet类,继承AxisServlet:

package com.test.webservice.servlet;

import org.apache.axis.transport.http.AxisServlet;
import javax.servlet.annotation.WebServlet;

@WebServlet(
        urlPatterns = "/axis-services/*",
        loadOnStartup = 1,
        name = "AxisServlet"
)
public class MyAxisServlet extends AxisServlet {
}

注意,Axis默认的过滤 url 是/services/,而我这里将 urlPatterns 配置为/axis-services/,是因为工程中同时使用了 Cxf框架 ,如果使用默认配置,会与 Cxf 冲突。

重写Axis配置工厂

网上拷贝的配置工厂类:

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;


public class EngineConfigurationFactoryServlet extends EngineConfigurationFactoryDefault {
    protected static Log log = LogFactory.getLog(EngineConfigurationFactoryServlet.class.getName());
    private ServletConfig cfg;

    public static EngineConfigurationFactory newFactory(Object param) {
        return (param instanceof ServletConfig)
                ? new EngineConfigurationFactoryServlet((ServletConfig) param)
                : null;
    }

    protected EngineConfigurationFactoryServlet(ServletConfig conf) {
        super();
        this.cfg = conf;
    }

    @Override
    public EngineConfiguration getServerEngineConfig() {
        return getServerEngineConfig(cfg);
    }

    private static EngineConfiguration getServerEngineConfig(ServletConfig cfg) {
        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;
        }


        String appWebInfPath = "/WEB-INF";
        //由于部署方式变更为jar部署,此处不可以使用改方式获取路径
//        ServletContext ctx = cfg.getServletContext();
//        String realWebInfPath = ctx.getRealPath(appWebInfPath);

        FileProvider config = null;
        String realWebInfPath = EngineConfigurationFactoryServlet.class.getResource(appWebInfPath).getPath();

   
        InputStream iss = ClassUtils.getResourceAsStream(EngineConfigurationFactoryServlet.class, appWebInfPath + "/" + SERVER_CONFIG_FILE);
        if (iss != null) {
            config = new FileProvider(iss);
        }

        if (config == null) {
            log.error(Messages.getMessage("servletEngineWebInfError03", ""));
        }

        if (config == null && realWebInfPath != null) {
            try {
                config = new FileProvider(realWebInfPath, configFile);
            } catch (ConfigurationException e) {
                log.error(Messages.getMessage("servletEngineWebInfError00"), e);
            }
        }

        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;
    }
}

有两点需要注意:

  1. 这个配置类必须放在org.apache.axis.configuration包下,否则不生效,别问为什么,我也不知道...
  2. 代码中48行左右,String appWebInfPath = "/WEB-INF";指向的文件夹就是一开始创建的 WEB-INF

最后一步

在启动类加上注解 @ServletComponentScan

@SpringBootApplication
@ServletComponentScan
public class TestApplication {
    public static void main(String[] args) {
        SpringApplication.run(TestApplication.class, args);
    }
}

启动程序,访问 http://localhost:8080/axis-services,会显示已发布的 WebService 接口信息,示例接口地址为:http://localhost:8080/axis-services/DemoService?wsdl

声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉
  • 接口
    +关注

    关注

    33

    文章

    7639

    浏览量

    148495
  • 文件
    +关注

    关注

    1

    文章

    540

    浏览量

    24402
  • spring
    +关注

    关注

    0

    文章

    332

    浏览量

    14161
  • 服务端
    +关注

    关注

    0

    文章

    61

    浏览量

    6871
  • SpringBoot
    +关注

    关注

    0

    文章

    172

    浏览量

    106
收藏 人收藏

    评论

    相关推荐

    工程从CCS5.1迁移到CCS5.3下有什么注意事项

    如题,想请教一下专家,应用工程之前在CCS5.1开发的,编译器版本为7.3.1,bios版本为6.32.5.54,现在想将工程迁移到CCS5.3上,有什么注意事项?另外之前在CCS5.1下面
    发表于 06-21 08:29

    如何将Spartan 6迁移到Artix-7?

    我们有一个为XC6SLX25开发的设计,我们希望转移到Artix-7以节省电力。我们可以通过将设计迁移到Artix-7来实际期望节省电力吗?
    发表于 05-01 12:44

    EDK项目迁移到vivado的建议有哪些?

    大家好,我正在开发一个目前处于planAhead ISE的项目。我正在将该EDK项目迁移到vivado。当我尝试迁移IP时,我能够成功迁移我的一些IP,我收到了帖子附带的通知。请有人建
    发表于 05-06 10:31

    如何将CCSv3.3迁移到CCSv4?

    如何将CCSv3.3迁移到CCSv4
    发表于 02-25 07:15

    为什么KEIL4迁移到KEIL5的工程会发生报错的问题呢

    为什么KEIL4迁移到KEIL5的工程会发生报错的问题呢?如何去解决?
    发表于 12-20 07:49

    请问一下mysql怎么快速迁移到oceanBase啊?

    mysql怎么快速迁移到oceanBase啊
    发表于 05-30 17:04

    请问如何从codeaurora迁移到github?

    我注意到最近恩智浦存储库从 codeaurora 转移到了 github。我们如何在仍然使用 BSP31 的同时更改它,因为我们目前没有时间迁移到更新的 BSP 版本。在版本 31 的新 github repo 中,.xml 文件中仍然有 codeaurora 链接。
    发表于 04-07 06:35

    将codeaurora迁移到github后yocto构建失败了怎么解决?

    将 codeaurora 迁移到 github 后 yocto 构建失败
    发表于 04-21 08:12

    从电源架构迁移到ARM的应用说明

    本文档的目的是强调那些参与将软件应用程序从Power架构迁移到ARM平台的人员感兴趣的领域。 本文并不试图将一种体系结构提升到另一种体系结构之上,只是为了清楚地解释将现有软件应用程序从一种体系结构
    发表于 08-22 06:09

    如何在迁移到云的时候构建VoIP预算

    迁移到云通信时,重新评估预算以整合重叠的协作功能,淘汰硬件并转换到Opex模型
    的头像 发表于 05-29 16:18 2075次阅读

    如何从M2M迁移到IIoT

    随着工业自动化需求的增加,工业协议和M2M机器通信逐渐迁移到IIoT工业物联网。
    发表于 09-16 15:56 969次阅读

    云计算中迁移到和建设私有云

    对于互联网公司而言,迁移到云是一个明智的决定。它减少了总的成本支出,同时最大限度地提高了工作效率和生产率,本文将指出迁移到云或者建设私有云优缺点以及边界在哪里?
    的头像 发表于 04-02 09:16 2204次阅读

    组织如何有效地将业务迁移到云平台

    调研机构Gartner公司指出,如果不采取正确的策略,组织迁移到云平台将会导致成本增加、安全漏洞以及对云迁移结果的失望。
    的头像 发表于 01-03 14:32 1867次阅读

    如何将Hadoop迁移到云平台中?

    希望实现数据基础设施的现代化并将Hadoop迁移到云平台中吗?以下是组织在数据迁移之前需要问的五个问题:
    发表于 05-05 16:59 753次阅读

    AN5426_STM32CubeMX 5_4_0的中间组件工程迁移到STM32CubeMX 5_5_0

    AN5426_STM32CubeMX 5_4_0的中间组件工程迁移到STM32CubeMX 5_5_0
    发表于 11-21 08:11 0次下载
    AN5426_STM32CubeMX 5_4_0的中间组件<b class='flag-5'>工程</b><b class='flag-5'>迁移到</b>STM32CubeMX 5_5_0