骆驼 CXF 请求/响应

发布于 2025-01-03 18:30:40 字数 1568 浏览 2 评论 0原文

我在基于 cxf/camel 构建自己的网络服务时遇到问题。

我的网络服务应该执行如下操作:

我在 DomainA 上,从该域将 POST 数据发送到我的网络服务 (CXF)

我的 CXF 代码是:

@Path("/")
@ProduceMime({ "application/json" })
public class SSO {

    @POST
    @Path("/user")
    @ProduceMime({ "application/json" })
    public String user(@FormParam("id") String token) {


    }

}

我的 CXF 代码接收我的 id 变量。

现在我想将此变量发送到其他网址 http://localhost:8080/myWebSite 并等待来自该网址的响应,并在获得响应后将其发送到 DomainA

我的beans.xml 是:

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:osgi="http://www.springframework.org/schema/osgi"
    xmlns:jaxrs="http://cxf.apache.org/jaxrs"
    xsi:schemaLocation="
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
    http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd
    http://www.springframework.org/schema/osgi http://www.springframework.org/schema/osgi/spring-osgi.xsd">

    <import resource="classpath:META-INF/cxf/cxf.xml" />
    <import resource="classpath:META-INF/cxf/osgi/cxf-extension-osgi.xml" />

    <bean id="cxfSSO" class="com.esb.cxf.SSO" />
    <jaxrs:server id="sso" address="/sso">
        <jaxrs:serviceBeans>
            <ref bean="cxfSSO" />
        </jaxrs:serviceBeans>
    </jaxrs:server>

</beans>

i have problem with build my own webservice based on cxf/camel.

My webservice should do something like this:

I am on DomainA from which i send POST data to my webservice (CXF)

my CXF code is:

@Path("/")
@ProduceMime({ "application/json" })
public class SSO {

    @POST
    @Path("/user")
    @ProduceMime({ "application/json" })
    public String user(@FormParam("id") String token) {


    }

}

My CXF code receive my id variable.

Now i want to send this variable to other url http://localhost:8080/myWebSite and wait for response from the url and after get the response send it to DomainA

my beans.xml is:

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:osgi="http://www.springframework.org/schema/osgi"
    xmlns:jaxrs="http://cxf.apache.org/jaxrs"
    xsi:schemaLocation="
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
    http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd
    http://www.springframework.org/schema/osgi http://www.springframework.org/schema/osgi/spring-osgi.xsd">

    <import resource="classpath:META-INF/cxf/cxf.xml" />
    <import resource="classpath:META-INF/cxf/osgi/cxf-extension-osgi.xml" />

    <bean id="cxfSSO" class="com.esb.cxf.SSO" />
    <jaxrs:server id="sso" address="/sso">
        <jaxrs:serviceBeans>
            <ref bean="cxfSSO" />
        </jaxrs:serviceBeans>
    </jaxrs:server>

</beans>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

孤蝉 2025-01-10 18:30:40

最简单的方法是 Spring RestTemplate,因为这隐藏了您原本必须处理的大量复杂性。

Spring 文档 描述了基础知识,但请注意,您需要将请求构建为 MultiValueMap ,以便将其发送到服务application/x-www-form-urlencoded

The easiest way is going to be a Spring RestTemplate, as this hides a huge amount of the complexity that you'd otherwise have to deal with.

The Spring documentation describes the basics, but be aware that you'll want to build the request as a MultiValueMap<String, String> so that it will be sent to the service as application/x-www-form-urlencoded.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文