PostRequest.java
1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* javax.jcr.ItemExistsException
* org.apache.sling.api.SlingHttpServletRequest
* org.apache.sling.api.resource.Resource
* org.apache.sling.servlets.post.Modification
* org.apache.sling.servlets.post.PostResponse
*/
package com.adobe.granite.rest.impl.servlet;
import com.adobe.granite.rest.RequestException;
import com.adobe.granite.rest.impl.servlet.ModifyingRequest;
import java.util.List;
import javax.jcr.ItemExistsException;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.servlets.post.Modification;
import org.apache.sling.servlets.post.PostResponse;
public class PostRequest
extends ModifyingRequest {
@Override
protected void doHandle(SlingHttpServletRequest request, PostResponse response, List<Modification> changes) throws UnsupportedOperationException, RequestException, Exception {
try {
Resource createdResource = this.createOrModifyResource(request, changes);
changes.add(Modification.onCreated((String)createdResource.getPath()));
response.setLocation(this.externalizePath(request, createdResource.getPath()));
response.setCreateRequest(true);
}
catch (Exception e) {
if (e.getCause() instanceof ItemExistsException) {
throw new RequestException(409, "Resource " + (Object)request.getResource() + " already exist.");
}
throw e;
}
}
}