- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我正在尝试手动返回带有自定义错误消息的 HTTP 4xx 或 5xx。它对 GET 非常有效,但对 PUT 和 POST 返回空内容。预先感谢任何可以建议如何让 PUT 和 POST 工作的人!
这些是我对网络服务的调用:GET/webapp/orders/A.json
- 返回 HTTP 500 和错误消息作为内容PUT/webapp/orders/A.json
- 返回 HTTP 500 和 content-length=0
getModel()
在这两个实例中都被调用,消息只是没有返回到 Chrome 进行 PUT。
这是产生错误的示例代码:
订单 Controller
package com.test.controller;
import org.apache.struts2.rest.DefaultHttpHeaders;
import org.apache.struts2.rest.HttpHeaders;
import org.apache.struts2.convention.annotation.Namespace;
import com.opensymphony.xwork2.ModelDriven;
@Namespace("/rest")
public class OrdersController implements ModelDriven<Object> {
// GET /orders/A
public HttpHeaders show() {
return new DefaultHttpHeaders().withStatus(500);
}
// PUT /orders/A
public HttpHeaders update() {
return new DefaultHttpHeaders().withStatus(500);
}
public void setId(String id) {
// Nothing
}
public Object getModel() {
return new String("{ \"message\": \"An error occurred.\"}");
}
}
结构
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
<constant name="struts.convention.action.suffix" value="Controller"/>
<constant name="struts.convention.action.mapAllMatches" value="true"/>
<constant name="struts.convention.default.parent.package" value="rest-default"/>
<constant name="struts.convention.package.locators" value="controller"/>
</struts>
网络
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="starter" version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>Orders</display-name>
<filter>
<filter-name>action2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>action2</filter-name>
<url-pattern>/rest/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
</web-app>
AngularJS 测试工具
var orderApp = angular.module('orderApp', []);
orderApp.run(function($http) {
$http.get("rest/orders/A.json");
$http.put("rest/orders/A.json", {"orderId":"A"} );
});
环境:Struts2 (2.3.16.3), Rest-Plugin, Convention, Java7, Tomcat7, Maven
最佳答案
添加<constant name="struts.rest.content.restrictToGET" value="false"/>
到struts.xml就解决了问题。感谢@ontk 的 this回答另一个问题。感谢所有试图帮助我的人。
关于java - Struts2-Rest : Manual HTTP 5xx doesn't return content,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26456325/
关闭。这个问题需要更多 focused .它目前不接受答案。 想要改进这个问题吗? 更新问题,使其只关注一个问题 editing this post . 关闭 5 年前。 Improve this q
我们如何手动启动滑动 Jquery 事件(例如用于点击事件的 $('div').click(); )? $('div').live('swipeleft'); 无法执行此操作。 最佳答案 根据您正在使
我想做一个std::function像可以处理存储多个重载的对象。 语法有点像这样:my_function . 或者,更明确地说: template struct type_list {}; temp
1. macvlan 简介 在 macvlan 出现之前,我们只能为一块以太网卡添加多个 ip 地址,却不能添加多个 mac 地址,因为 mac 地址正是通过其全球唯一性来标识一块以太网卡的,即便
我只想在 shell(或 perl)脚本中获取 MAN 页面的特定部分并打印它。 例如:仅 MAN 页面的 SYNOPSIS 部分 有没有标准的方法来做到这一点? 问候, 阿南丹 最佳答案 据我所知,
我正在使用以下代码为 Woocommerce 创建一个新的自定义订单状态。我遇到的问题是,在管理员中,状态显示为无样式。如何以类似于“处理”的方式设置自定义状态的样式? /* Adding a new
我希望在 MOSS 2007 中创建一个“在线手册”站点模板,以便创建多个站点,这些站点将保存有关一系列主题的静态信息。 我应该使用什么网站模板,我目前正在考虑发布网站,但 Wiki 可能有用? 我应
简单来说,我在客户的整个网站上使用外部 PHP 脚本来实现各种目的,例如获取搜索结果、更新内容等。 我将这些脚本保存在一个目录中: www.domain.com/scripts/scriptname0
在具有 Spring MVC 和 Spring Security 的 Web 应用程序中。 有没有办法手动设置 UserPrincipal? 我需要通过我的 web 应用程序的管理部分切换到另一个用户
我发现我可以使用migrations.RunSQL('some sql')为django项目中的postgres数据库设置列的默认值。 我目前正在通过添加列,makemigrations,然后删除列,
我的 web 应用程序(Spring3 + Hibernate3)始终使用使用 @Transactional 注释的服务类以及以下配置: 现在...我正在使用
我们是否可以手动登录用户并创建一个 TWTRSession 以便继续与 TwitterKit 一起使用?我已经尝试过: NSDictionary *twSessionInfo = [self.acco
我有这个功能: int cipher_file(char *file_path, uint8_t *key, int key_size){ FILE *file; size_t rea
仅当单击按钮 #collapse_init 时,我才能根据 active bool 变量将按钮上的文本更改为“全部显示”或“全部隐藏” 当我手动隐藏/折叠选项卡(一个接一个)时,按钮上的文本没有改变,
我正在尝试从 OpenCV 中重现 projectPoints() 方法的行为。 下面两张图中,红/绿/蓝轴是用OpenCV的方法得到的,而洋红/黄/青轴是用我自己的方法得到的: 图片1 图片2 用我
鉴于 LISP 显然可以用“LISP 微型手册”的“10 条规则”来表达 [1] [2] (这是真的吗?),是否有类似简洁的Scheme描述? 最佳答案 这里麦卡锡的“10 条规则”本质上是操作语义的
手动,我的意思是代码好像我需要迎合,就好像对象不是我期望的那样。 例如,我正在使用中继器。作为其中的一部分,我正在操纵 DataSource 属性。为此,我必须先检查以下内容: this.DataSo
这个问题在这里已经有了答案: Spring Data JPA Update @Query not updating? (5 个答案) 关闭 2 年前。 社区在 去年 审查了是否重新打开这个问题并将其
我真的是 Spring 的新手我正在使用 JSF+Hibernate+Spring 开发一个简单的 JEE 应用程序我在尝试更新 DAO 上的值时遇到了一些问题我确定问题与 Spring 配置 xml
我想对在Web应用程序中在服务器和客户端之间来回传输的数据进行加密。我会使用SSL,但是需要证书和专用IP地址。获得证书没有问题,但专用IP需要我升级到企业托管计划,该计划是在Web主机上每月支付20
我是一名优秀的程序员,十分优秀!