@滄海一夢
@西夏一品堂
请教两位一个问题
正在学习camel 研究了网上的demo,自己写了一个提交post请求 然后一个service类里面有一个addXXX方法,参数是一个post提交表单对应的pojo,但是在这个addXXX方法里面获取到的pojo的实例不为空,但是get属性的时候发现属性值为null
试试这样做吧,我试过了,没有问题。
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:camel="http://camel.apache.org/schema/spring" xmlns:cxf="http://camel.apache.org/schema/cxf" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd"> <cxf:cxfEndpoint id="userserviceEndpoint" address="http://127.0.0.1:6069/cxf/userservice" serviceClass="com.osc.cxf.UserService" /> <bean id="userServiceProcessor" class="com.osc.cxf.UserServiceProcessor" /> <camelContext xmlns="http://camel.apache.org/schema/spring"> <route> <from uri="cxf:bean:userserviceEndpoint" /> <bean ref="userServiceProcessor" method="addUser" /> </route> </camelContext> </beans>
注意schema,我用的是spring,你改成blueprint
karaf 控制台打印截图 如下
可以看到 user对象不为空 但是里面的两个属性值为null,
不知道是怎么回事,困扰了好几天了
发布以后 在浏览器输入 http://localhost:8181/cxf
可以看到一个restful的webservice已经部署了
点击 http://localhost:8181/cxf/userservice?_wadl显示如下
用火狐的httpRequest 工具访问如下
我的应用是运行在karaf里面的 打包发布以后 状态都没问题 如下图
粘贴主要代码
pojo类
@XmlRootElement(name = "User") public class User { private String id; private String name; public String getId() { return id; } public void setId(String id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } }
service类
@POST @Path("/adduser") @Consumes({ "application/xml", "application/json" }) public OutputOfUserService addUser(User User){ return null; }
processor 类
public OutputOfUserService addUser(User user) { System.out.println(user); System.out.println("@@"+user.getId()); System.out.println("@@"+user.getName()); OutputOfUserService output = new OutputOfUserService(); output.setCode("0000"); output.setDesc("success"); return output; }
blueprint.xml
<cxf:rsServer id="userserviceEndpoint" address="/userservice" serviceClass="com.mesys.fuse.user.UserService" /> <bean id="userServiceProcessor" class="com.mesys.fuse.user.UserServiceProcessor" /> <camelContext xmlns="http://camel.apache.org/schema/blueprint"> <route id="cxfrs"> <from uri="cxfrs:bean:userserviceEndpoint" /> <bean ref="userServiceProcessor" method="addUser" /> <to uri="log:output" /> <marshal> <json prettyPrint="true" library="Jackson" /> </marshal> </route> </camelContext>
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
暂无简介
文章 0 评论 0
接受
发布评论
评论(5)
试试这样做吧,我试过了,没有问题。
注意schema,我用的是spring,你改成blueprint
karaf 控制台打印截图 如下
可以看到 user对象不为空 但是里面的两个属性值为null,
不知道是怎么回事,困扰了好几天了
发布以后 在浏览器输入 http://localhost:8181/cxf
可以看到一个restful的webservice已经部署了
点击 http://localhost:8181/cxf/userservice?_wadl显示如下
用火狐的httpRequest 工具访问如下
我的应用是运行在karaf里面的 打包发布以后 状态都没问题 如下图
粘贴主要代码
pojo类
service类
processor 类
blueprint.xml