SOAP UI访问REST服务出现500错误的问题

同步发表在:http://www.xeclipse.com/?p=1366

 

创建了一个简单的REST Web Service,使用Java代码访问完全OK,但是用SOAP UI就一直出现500的错误,简单的Google一下,发现了问题。小结一下。

错误的截图:

具体:

<html>
   <head>
      <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
      <title>Error 500 Could not resolve view with name 'employees' in servlet with name 'rest'</title>
   </head>
   <body>
      <h2>HTTP ERROR 500</h2>
      <p>
         Problem accessing /service/employees. Reason:
         <pre>Could not resolve view with name 'employees' in servlet with name 'rest'</pre>
      </p>
      <h3>Caused by:</h3>
      <pre>javax.servlet.ServletException: Could not resolve view with name 'employees' in servlet with name 'rest'
 

REST的地址为:http://localhost:8082/service/employees, 使用浏览器可以正常访问,显示

<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>Employees</title>
</head>
<body>
<table border=1>
	<thead><tr>
		<th>ID</th>
		<th>Name</th>
		<th>Email</th>
	</tr></thead>

	<tr>
		<td>1</td>
		<td>Huang Yi Ming</td>
		<td>huangyim@cn.ibm.com</td>
	</tr>

	<tr>
		<td>2</td>
		<td>Wu Dong Fei</td>
		<td>wudongf@cn.ibm.com</td>
	</tr>

</table>
</body>
</html>
 

说明REST 服务OK,使用SOAP UI等工具就有问题了,这里有个东西需要注意:

Accept必须设置,默认为“*/*;”

比如:

当然,如果你的REST服务制定需要某种Accept,就需要设置为其他了:

@RequestMapping(method=RequestMethod.GET, value="/emps", headers="Accept=application/xml, application/json")
	public @ResponseBody EmployeeList getAllEmp() {
 

这里就可以设置为

Accept = application/xml 或者 applicaiton/json

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值