1:当使用 cxf 发布服务时,要求返回值类型为xml,或者json等

    @Path("/searchProductByText")
@GET
@Produces({"application/xml", "application/json"})
JSONObject productSearch(@QueryParam("text") String text);

但是 cxf不支持解析  JSONObject 等对象

进行访问时将会返回    No message body writer has been found for class com.alibaba.fastjson.JSONObject, ContentType: */*

2:解决方法,定义一个pojo,里面包含 JSONObject  引用。将返回的JSONObject包含在 自定义的 POJO中,使用注解将pojo定义为能被解析为xml形式等。

package com.search.pojo;

import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.annotation.JsonInclude; import javax.xml.bind.annotation.XmlRootElement; //@JsonInclude(JsonInclude.Include.NON_NULL)//不包含有null值的字段,即字段值为null的转换为json字符串时会被省略
@XmlRootElement(name="MyJSONObject")
public class MyJSONObject {
JSONObject jsonObject; public JSONObject getJsonObject() {
return jsonObject;
} public void setJsonObject(JSONObject jsonObject) {
this.jsonObject = jsonObject;
}
}

3:在实现类中,返回对象变为 pojo

       MyJSONObject myJSONObject=new MyJSONObject();
myJSONObject.setJsonObject(jsonObject);
return myJSONObject;

4:接口 方法 返回 也变为 pojo

    @Path("/searchProductByText")
@GET
@Produces({"application/xml", "application/json"})
MyJSONObject productSearch(@QueryParam("text") String text);

5  可以返回值了。

6:前端接到响应体中的xml,可以转化为json

            httpResponse = httpUtil.HttpGet(requestParamMap, url);
HttpEntity entity = httpResponse.getEntity();
String s = EntityUtils.toString(entity);
//将返回的xml字符串形式转化为json格式
org.json.JSONObject xmlJSONObj = XML.toJSONObject(s);
jsonObject = (JSONObject) JSON.parse(xmlJSONObj.toString());

No message body writer has been found for class com.alibaba.fastjson.JSONObject, ContentType: */*的更多相关文章

  1. webservice接口问题:Payload: No message body writer has been found for class domain, ContentType: application/xml

    当在使用cxf-rs的webservice的时候,有时候在传输数据,会发生这种错误 错误代码: Response-Code: 500 Content-Type: text/plain Headers: ...

  2. cxf maven 依赖 No message body writer foud.. contenttype:application/json

    最近使用cxf发布rest服务时遇到了如题的异常,最后发现是缺少依赖的问题.ps:我并没有使用spring cxf基本运行需要如下依赖 1 <dependency> <groupId ...

  3. SpringBoot之KindEditor文件上传

    后端核心代码如下: package com.blog.springboot.controller; import java.io.BufferedOutputStream; import java.i ...

  4. java 微信开发的工具类WeChatUtils

    import com.alibaba.fastjson.JSONObject;import com.bhudy.entity.BhudyPlugin;import com.bhudy.service. ...

  5. 【学习】014 深入理解Http协议

    Http协议入门 什么是http协议 http协议: 对浏览器客户端 和  服务器端 之间数据传输的格式规范 查看http协议的工具 1)使用火狐的firebug插件(右键->firebug-& ...

  6. Dubbo入门到精通学习笔记(八):ActiveMQ的安装与使用(单节点)、Redis的安装与使用(单节点)、FastDFS分布式文件系统的安装与使用(单节点)

    文章目录 ActiveMQ的安装与使用(单节点) 安装(单节点) 使用 目录结构 edu-common-parent edu-demo-mqproducer edu-demo-mqconsumer 测 ...

  7. hive数据仓库入门到实战及面试

    第一章.hive入门 一.hive入门手册 1.什么是数据仓库 1.1数据仓库概念 对历史数据变化的统计,从而支撑企业的决策.比如:某个商品最近一个月的销量,预判下个月应该销售多少,从而补充多少货源. ...

  8. J2EE项目开发中常用到的公共方法

    在项目IDCM中涉及到多种工单,包括有:服务器|网络设备上下架工单.服务器|网络设备重启工单.服务器光纤网线更换工单.网络设备撤线布线工单.服务器|网络设备替换工单.服务器|网络设备RMA工单.通用原 ...

  9. HttpClient相关

    HTTPClient的主页是http://jakarta.apache.org/commons/httpclient/,你可以在这里得到关于HttpClient更加详细的信息 HttpClient入门 ...

随机推荐

  1. Form表单验证神器: BootstrapValidator

    前言:做Web开发的我们,表单验证是再常见不过的需求了.友好的错误提示能增加用户体验.博主搜索bootstrap表单验证,搜到的结果大部分都是文中的主题:bootstrapvalidator.今天就来 ...

  2. MegaCli 使用

    安装: wget ftp://rpmfind.net/linux/Mandriva/devel/cooker/x86_64/media/non-free/release/megacli-8.02.21 ...

  3. 《转》Python学习(16)-python异常

    转自 http://www.cnblogs.com/BeginMan/p/3171445.html 一.什么是错误,什么是异常,它们两者区别 这里解释如下:个人觉得很通俗易懂 错误是指在执行代码过程中 ...

  4. javascript解析器原理

    浏览器在读取HTML文件的时候,只有当遇到<script>标签的时候,才会唤醒所谓的“JavaScript解析器”开始工作. JavaScript解析器工作步骤 1. “找一些东西”: v ...

  5. [原]git的使用(一)---建立本地仓库、add和commit、status和git diff、版本回退使用git reset

    在window下已经安装了git的环境 1.建立本地仓库 mkdir   test     #建立test目录 cd   test        #进入目录 git  init           # ...

  6. Oracle SQL Developer保持数据库连接的方法

    一.概述 从navicat切到pl/sql developer,但是发现个bug,因为本地客户端pl/sql developer的字符集 和数据库服务器的字符集不一致,导致一个很奇葩的东西. 本来我有 ...

  7. 生产环境的gitlab大版本升级思路(从7.x升级到8.x)

    之前在生产环境部署的gitlab是7.x版本的,提供给公司内部的员工来使用,大概有350个用户左右,gitlab从8.x版本之后内置了CI和CD的集成,所以就考虑到升级版本的问题 通过参考和总结git ...

  8. was cached in the local repository, resolution will not be reattempted until the update interval of localhost-repository has elapsed or updates are forced

    ailed to collect dependencies at com.eshore:common:jar:0.0.1-SNAPSHOT: Failed to read artifact descr ...

  9. python中列表排序,字典排序,列表中的字典排序

    #-*- encoding=utf-8 -*- # python3代码 import operator 一. 按字典值排序(默认为升序) x = {1:2, 3:4, 4:3, 2:1, 0:0} 1 ...

  10. logstash实战filter插件之grok(收集apache日志)

    有些日志(比如apache)不像nginx那样支持json可以使用grok插件 grok利用正则表达式就行匹配拆分 预定义的位置在 /opt/logstash/vendor/bundle/jruby/ ...