当资源上无法进行DELETE(但不涉及用户权限)时,我的问题是关于HTTP状态代码的非常通用的问题.
我们在一种资源上有一个RESTful API.
该DELETE方法被授权的资源,但有些条件下的资源不能被删除下(如果有绑定到该资源数据).
在这种情况下,返回客户端的正确HTTP状态代码是什么?
以下是我收集的一些可能性以及为什么它在我的案例中似乎不合适:
更新:无法通过REST API更改阻止资源被删除的数据绑定.但是,资源可以通过其他方式"释放",因为数据所来自的数据库也可以被其他应用程序访问,这些应用程序可能会更改资源的状态(DB中的SQL DELETE总是可以这样做).
如果我们只是创建一个引用变量或为原始数据类型或引用数据类型声明一个变量而不用以下任何值进行初始化,那么内存中会发生什么?
int x;
Employee emp;
Run Code Online (Sandbox Code Playgroud)
那么两种情况下记忆中到底发生了什么?
是否在此阶段分配了任何内存,或者它是指向任何随机位置还是指向null或指向垃圾值?
与第二种情况一样,如果我们使用带有new运算符的构造函数或使用任何其他方法创建对象,则只会在内存中创建空间.
Employee emp = new Employee();
Run Code Online (Sandbox Code Playgroud) 我正在尝试实现涉及HashMap的XML映射.这是我的用例:我想得到这个:
<userParameters>
<KEY_1>VALUE_1</KEY_1>
<KEY_2>VALUE_2</KEY_2>
<KEY_3>VALUE_3</KEY_3>
</userParameters>
Run Code Online (Sandbox Code Playgroud)
我的UserParameters类看起来像这样:
@XmlRootElement
public class UserParameters {
private final Map<QName, String> params = new HashMap<>();
@XmlAnyElement
public Map<QName, String> getParams() {
return params;
}
}
Run Code Online (Sandbox Code Playgroud)
编组时出现以下错误:
Caused by: javax.xml.bind.JAXBException: class java.util.HashMap nor any of its super class is known to this context.
at com.sun.xml.bind.v2.runtime.JAXBContextImpl.getBeanInfo(JAXBContextImpl.java:593)
at com.sun.xml.bind.v2.runtime.property.SingleReferenceNodeProperty.serializeBody(SingleReferenceNodeProperty.java:109)
... 54 more
Run Code Online (Sandbox Code Playgroud)
它工作正常,@XmlAnyAttribute我得到:<userParameters KEY_1="VALUE_1" ... />
从我看到的答案来看,似乎我必须自己制作,XmlAdapter但对于这种简单而常见的需求感觉有些过分.
---更新---
我在这里找到了一个很有前途的解决方案:JAXB HashMap是不可映射的
唯一不方便的是它似乎搞乱了名称空间.
这是我的新UserParameters类:
@XmlAnyElement
public List<JAXBElement> getParams() {
return params;
}
public void …Run Code Online (Sandbox Code Playgroud) 我的应用程序正在使用 spring-ws 的 WebServiceTemplate 调用外部 Soap WS,我在测试中使用 MockWebServiceServer 进行模拟。
它可以很好地根据请求有效负载模拟响应。
但是现在我想测试调用了哪个 SOAP 操作。它应该在请求的“SOAPAction”HTTP 标头中定义。
我正在使用 Spring-WS 2.1.4。
有谁知道是否可以测试它以及如何测试?
这是我的测试课:
public class MyWebServiceTest {
@Autowired
private WebServiceTemplate webServiceTemplate;
private MockWebServiceServer mockServer;
@Before
public void createServer() throws Exception {
mockServer = MockWebServiceServer.createServer(webServiceTemplate);
}
@Test
public void callStambiaWithExistingFileShouldSuccess() throws IOException {
Resource requestPayload = new ClassPathResource("request-payload.xml");
Resource responseSoapEnvelope = new ClassPathResource("success-response-soap-envoloppe.xml");
mockServer.expect(payload(requestPayload)).andRespond(withSoapEnvelope(responseSoapEnvelope));
//init job
//myService call the webservice via WebServiceTemplate
myService.executeJob(job);
mockServer.verify();
//some asserts
}
}
Run Code Online (Sandbox Code Playgroud)
所以我要测试的是调用的soap动作。所以我想在我的测试课上做这样的事情:
mockServer.expect(....withSoapAction("calledSoapAction")).andRespond(...
Run Code Online (Sandbox Code Playgroud)