骆驼 CXF 请求/响应
我在基于 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最简单的方法是 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 asapplication/x-www-form-urlencoded
.