`
salever
  • 浏览: 250316 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

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

    博客分类:
  • Web
阅读更多

同步发表在: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

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics