首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >spring XD:如何创建自定义http源

spring XD:如何创建自定义http源
EN

Stack Overflow用户
提问于 2016-05-06 16:46:02
回答 2查看 189关注 0票数 0

我需要实现跨源代码的自定义http源:*。

怎么做?Spring XD Doc

需要示例

EN

回答 2

Stack Overflow用户

发布于 2016-05-07 05:11:14

开发自定义源需要您具备spring集成的基本知识。不管怎样,这里有一个例子:

你需要写4个文件:

文件1:

crossoriginsource.xml

代码语言:javascript
运行
复制
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:int="http://www.springframework.org/schema/integration"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd
        http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-4.2.xsd">

    <context:component-scan base-package="com.yourbasepackage"></context:component-scan>
    <context:annotation-config></context:annotation-config>

    <!-- The name of the chaannel is output.(Mandatory to have the name as output) -->
    <int:channel id="output"></int:channel>

    <int:inbound-channel-adapter ref="crossOriginHttpCaller" method="makeHttpCall" channel="output"></int:inbound-channel-adapter>
</beans>

crossoriginsource.properties

代码语言:javascript
运行
复制
info.shortDescription = Gets data from cross origin sources.
options_class = com.yourbasepackage.CrossOriginSourceMetadata

CrossOriginSourceMetadata.java

代码语言:javascript
运行
复制
package com.yourbasepackage;

public class CrossOriginSourceMetadata {
    // All the module related configurable properties goes here
    // The properties values for which you would like to take then while defining a stream.
}

CrossOriginHttpCaller.java

代码语言:javascript
运行
复制
@Component
public class CrossOriginHttpCaller {
    public Message<String> makeHttpCall() {
        // your http calling logic goes here
    }
}

开发模块后,必须在特定的文件夹结构中对其进行维护

代码语言:javascript
运行
复制
crossoriginsource
    |
    |---config
    |       |--crossoriginsource.xml
    |       |--crossoriginsource.properties
    |
    |---lib
    |    |--jar containing CrossOriginHttpCaller.java and CrossOriginSourceMetadata.java
    |    |--all the other dependent jars for this module

在此结构中打包应用程序后,必须将其复制到xd/modules/source,并且必须定义类似以下内容的流

stream create --name "test" --definition "crossoriginsource | log" --deploy

希望这能有所帮助。

票数 1
EN

Stack Overflow用户

发布于 2016-05-10 16:46:00

需要实现MessageProducerSupport。

使用响应头:response.setHeader("Access-Control-Allow-Origin", "*");

例如: fork spring-xd-http-extension。

以NettyHttpInboundChannelAdapter为例。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37068026

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档