This commit is contained in:
Francesco Chicchiriccò 2014-04-16 13:13:18 +02:00
commit 03e5462c07
10 changed files with 239 additions and 78 deletions

View File

@ -114,6 +114,8 @@ public abstract class AbstractServices {
private static final Pattern REQUEST_PATTERN = Pattern.compile("(.*) (http://.*) HTTP/.*"); private static final Pattern REQUEST_PATTERN = Pattern.compile("(.*) (http://.*) HTTP/.*");
private static final Pattern BATCH_REQUEST_REF_PATTERN = Pattern.compile("(.*) ([$].*) HTTP/.*");
private static final String BOUNDARY = "batch_243234_25424_ef_892u748"; private static final String BOUNDARY = "batch_243234_25424_ef_892u748";
protected final ODataServiceVersion version; protected final ODataServiceVersion version;
@ -161,6 +163,7 @@ public abstract class AbstractServices {
} }
return xml.createResponse( return xml.createResponse(
null,
FSManager.instance(version).readFile(Constants.get(version, ConstantKey.SERVICES), acceptType), FSManager.instance(version).readFile(Constants.get(version, ConstantKey.SERVICES), acceptType),
null, acceptType); null, acceptType);
} catch (Exception e) { } catch (Exception e) {
@ -182,7 +185,7 @@ public abstract class AbstractServices {
protected Response getMetadata(final String filename) { protected Response getMetadata(final String filename) {
try { try {
return xml.createResponse(FSManager.instance(version).readFile(filename, Accept.XML), null, Accept.XML); return xml.createResponse(null, FSManager.instance(version).readFile(filename, Accept.XML), null, Accept.XML);
} catch (Exception e) { } catch (Exception e) {
return xml.createFaultResponse(Accept.XML.toString(version), e); return xml.createFaultResponse(Accept.XML.toString(version), e);
} }
@ -201,22 +204,29 @@ public abstract class AbstractServices {
} }
private Response bodyPartRequest(final MimeBodyPart body) throws Exception { private Response bodyPartRequest(final MimeBodyPart body) throws Exception {
return bodyPartRequest(body, Collections.<String, String>emptyMap());
}
private Response bodyPartRequest(final MimeBodyPart body, final Map<String, String> references) throws Exception {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
final Enumeration<Header> en = (Enumeration<Header>) body.getAllHeaders(); final Enumeration<Header> en = (Enumeration<Header>) body.getAllHeaders();
Header header = en.nextElement(); Header header = en.nextElement();
final String request = header.getName() + ":" + header.getValue(); final String request =
header.getName() + (StringUtils.isNotBlank(header.getValue()) ? ":" + header.getValue() : "");
final Matcher matcher = REQUEST_PATTERN.matcher(request); final Matcher matcher = REQUEST_PATTERN.matcher(request);
final Matcher matcherRef = BATCH_REQUEST_REF_PATTERN.matcher(request);
final MultivaluedMap<String, String> headers = new MultivaluedHashMap<String, String>();
while (en.hasMoreElements()) {
header = en.nextElement();
headers.putSingle(header.getName(), header.getValue());
}
if (matcher.find()) { if (matcher.find()) {
final MultivaluedMap<String, String> headers = new MultivaluedHashMap<String, String>();
while (en.hasMoreElements()) {
header = en.nextElement();
headers.putSingle(header.getName(), header.getValue());
}
String method = matcher.group(1); String method = matcher.group(1);
if ("PATCH".equals(method) || "MERGE".equals(method)) { if ("PATCH".equals(method) || "MERGE".equals(method)) {
headers.putSingle("X-HTTP-METHOD", method); headers.putSingle("X-HTTP-METHOD", method);
@ -226,7 +236,19 @@ public abstract class AbstractServices {
final String url = matcher.group(2); final String url = matcher.group(2);
final WebClient client = WebClient.create(url); final WebClient client = WebClient.create(url);
client.headers(headers);
return client.invoke(method, body.getDataHandler().getInputStream());
} else if (matcherRef.find()) {
String method = matcherRef.group(1);
if ("PATCH".equals(method) || "MERGE".equals(method)) {
headers.putSingle("X-HTTP-METHOD", method);
method = "POST";
}
final String url = matcherRef.group(2);
final WebClient client = WebClient.create(references.get(url));
client.headers(headers); client.headers(headers);
return client.invoke(method, body.getDataHandler().getInputStream()); return client.invoke(method, body.getDataHandler().getInputStream());
@ -246,6 +268,8 @@ public abstract class AbstractServices {
final Object content = obj.getDataHandler().getContent(); final Object content = obj.getDataHandler().getContent();
if (content instanceof MimeMultipart) { if (content instanceof MimeMultipart) {
final Map<String, String> references = new HashMap<String, String>();
final String cboundary = "changeset_" + UUID.randomUUID().toString(); final String cboundary = "changeset_" + UUID.randomUUID().toString();
bos.write(("Content-Type: multipart/mixed;boundary=" + cboundary).getBytes()); bos.write(("Content-Type: multipart/mixed;boundary=" + cboundary).getBytes());
bos.write(Constants.CRLF); bos.write(Constants.CRLF);
@ -259,12 +283,13 @@ public abstract class AbstractServices {
lastContebtID = part.getContentID(); lastContebtID = part.getContentID();
addChangesetItemIntro(chbos, lastContebtID, cboundary); addChangesetItemIntro(chbos, lastContebtID, cboundary);
res = bodyPartRequest(new MimeBodyPart(part.getInputStream())); res = bodyPartRequest(new MimeBodyPart(part.getInputStream()), references);
if (res.getStatus() > 400) { if (res.getStatus() >= 400) {
throw new Exception("Failure processing changeset"); throw new Exception("Failure processing changeset");
} }
addSingleBatchResponse(res, lastContebtID, chbos); addSingleBatchResponse(res, lastContebtID, chbos);
references.put("$" + lastContebtID, res.getHeaderString("Location"));
} }
bos.write(chbos.toByteArray()); bos.write(chbos.toByteArray());
IOUtils.closeQuietly(chbos); IOUtils.closeQuietly(chbos);
@ -290,7 +315,7 @@ public abstract class AbstractServices {
res = bodyPartRequest(new MimeBodyPart(obj.getDataHandler().getInputStream())); res = bodyPartRequest(new MimeBodyPart(obj.getDataHandler().getInputStream()));
if (res.getStatus() > 400) { if (res.getStatus() >= 400) {
throw new Exception("Failure processing changeset"); throw new Exception("Failure processing changeset");
} }
@ -384,6 +409,7 @@ public abstract class AbstractServices {
@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON}) @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON})
@Consumes({MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON}) @Consumes({MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON})
public Response mergeEntity( public Response mergeEntity(
@Context UriInfo uriInfo,
@HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) String accept, @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) String accept,
@HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) String contentType, @HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) String contentType,
@HeaderParam("Prefer") @DefaultValue(StringUtils.EMPTY) String prefer, @HeaderParam("Prefer") @DefaultValue(StringUtils.EMPTY) String prefer,
@ -392,7 +418,7 @@ public abstract class AbstractServices {
@PathParam("entityId") String entityId, @PathParam("entityId") String entityId,
final String changes) { final String changes) {
return patchEntity(accept, contentType, prefer, ifMatch, entitySetName, entityId, changes); return patchEntity(uriInfo, accept, contentType, prefer, ifMatch, entitySetName, entityId, changes);
} }
@PATCH @PATCH
@ -400,6 +426,7 @@ public abstract class AbstractServices {
@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON}) @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON})
@Consumes({MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON}) @Consumes({MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON})
public Response patchEntity( public Response patchEntity(
@Context UriInfo uriInfo,
@HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) String accept, @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) String accept,
@HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) String contentType, @HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) String contentType,
@HeaderParam("Prefer") @DefaultValue(StringUtils.EMPTY) String prefer, @HeaderParam("Prefer") @DefaultValue(StringUtils.EMPTY) String prefer,
@ -442,11 +469,16 @@ public abstract class AbstractServices {
final Response response; final Response response;
if ("return-content".equalsIgnoreCase(prefer)) { if ("return-content".equalsIgnoreCase(prefer)) {
response = xml.createResponse( response = xml.createResponse(
uriInfo.getRequestUri().toASCIIString(),
util.readEntity(entitySetName, entityId, acceptType).getValue(), util.readEntity(entitySetName, entityId, acceptType).getValue(),
null, acceptType, Response.Status.OK); null, acceptType, Response.Status.OK);
} else { } else {
res.close(); res.close();
response = xml.createResponse(null, null, acceptType, Response.Status.NO_CONTENT); response = xml.createResponse(
uriInfo.getRequestUri().toASCIIString(),
null,
null,
acceptType, Response.Status.NO_CONTENT);
} }
if (StringUtils.isNotBlank(prefer)) { if (StringUtils.isNotBlank(prefer)) {
@ -464,6 +496,7 @@ public abstract class AbstractServices {
@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON}) @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON})
@Consumes({MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON}) @Consumes({MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON})
public Response replaceEntity( public Response replaceEntity(
@Context UriInfo uriInfo,
@HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) String accept, @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) String accept,
@HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) String contentType, @HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) String contentType,
@HeaderParam("Prefer") @DefaultValue(StringUtils.EMPTY) String prefer, @HeaderParam("Prefer") @DefaultValue(StringUtils.EMPTY) String prefer,
@ -504,11 +537,19 @@ public abstract class AbstractServices {
final Response response; final Response response;
if ("return-content".equalsIgnoreCase(prefer)) { if ("return-content".equalsIgnoreCase(prefer)) {
response = xml.createResponse( response = xml.createResponse(
uriInfo.getRequestUri().toASCIIString(),
getUtilities(acceptType).readEntity(entitySetName, entityId, acceptType).getValue(), getUtilities(acceptType).readEntity(entitySetName, entityId, acceptType).getValue(),
null, acceptType, Response.Status.OK); null,
acceptType,
Response.Status.OK);
} else { } else {
res.close(); res.close();
response = xml.createResponse(null, null, acceptType, Response.Status.NO_CONTENT); response = xml.createResponse(
uriInfo.getRequestUri().toASCIIString(),
null,
null,
acceptType,
Response.Status.NO_CONTENT);
} }
if (StringUtils.isNotBlank(prefer)) { if (StringUtils.isNotBlank(prefer)) {
@ -526,6 +567,7 @@ public abstract class AbstractServices {
@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON}) @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON})
@Consumes({MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_OCTET_STREAM}) @Consumes({MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_OCTET_STREAM})
public Response postNewEntity( public Response postNewEntity(
@Context UriInfo uriInfo,
@HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) String accept, @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) String accept,
@HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) String contentType, @HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) String contentType,
@HeaderParam("Prefer") @DefaultValue(StringUtils.EMPTY) String prefer, @HeaderParam("Prefer") @DefaultValue(StringUtils.EMPTY) String prefer,
@ -591,7 +633,7 @@ public abstract class AbstractServices {
} else { } else {
final Container<JSONEntryImpl> jcontainer = final Container<JSONEntryImpl> jcontainer =
mapper.readValue(IOUtils.toInputStream(entity), new TypeReference<JSONEntryImpl>() { mapper.readValue(IOUtils.toInputStream(entity), new TypeReference<JSONEntryImpl>() {
}); });
entry = (new DataBinder(version)). entry = (new DataBinder(version)).
getAtomEntry(jcontainer.getObject()); getAtomEntry(jcontainer.getObject());
@ -620,12 +662,23 @@ public abstract class AbstractServices {
FSManager.instance(version).putInMemory( FSManager.instance(version).putInMemory(
cres, path + File.separatorChar + Constants.get(version, ConstantKey.ENTITY)); cres, path + File.separatorChar + Constants.get(version, ConstantKey.ENTITY));
final String location = uriInfo.getRequestUri().toASCIIString() + "(" + entityKey + ")";
final Response response; final Response response;
if ("return-no-content".equalsIgnoreCase(prefer)) { if ("return-no-content".equalsIgnoreCase(prefer)) {
response = utils.createResponse(null, null, acceptType, Response.Status.NO_CONTENT); response = utils.createResponse(
location,
null,
null,
acceptType,
Response.Status.NO_CONTENT);
} else { } else {
response = utils.createResponse(utils.readEntity(entitySetName, entityKey, acceptType).getValue(), response = utils.createResponse(
null, acceptType, Response.Status.CREATED); location,
utils.readEntity(entitySetName, entityKey, acceptType).getValue(),
null,
acceptType,
Response.Status.CREATED);
} }
if (StringUtils.isNotBlank(prefer)) { if (StringUtils.isNotBlank(prefer)) {
@ -664,15 +717,15 @@ public abstract class AbstractServices {
replaceAll("\"Salary\":[0-9]*,", "\"Salary\":0,"). replaceAll("\"Salary\":[0-9]*,", "\"Salary\":0,").
replaceAll("\"Title\":\".*\"", "\"Title\":\"[Sacked]\""). replaceAll("\"Title\":\".*\"", "\"Title\":\"[Sacked]\"").
replaceAll("\\<d:Salary m:type=\"Edm.Int32\"\\>.*\\</d:Salary\\>", replaceAll("\\<d:Salary m:type=\"Edm.Int32\"\\>.*\\</d:Salary\\>",
"<d:Salary m:type=\"Edm.Int32\">0</d:Salary>"). "<d:Salary m:type=\"Edm.Int32\">0</d:Salary>").
replaceAll("\\<d:Title\\>.*\\</d:Title\\>", "<d:Title>[Sacked]</d:Title>"); replaceAll("\\<d:Title\\>.*\\</d:Title\\>", "<d:Title>[Sacked]</d:Title>");
final FSManager fsManager = FSManager.instance(version); final FSManager fsManager = FSManager.instance(version);
fsManager.putInMemory(IOUtils.toInputStream(newContent, "UTF-8"), fsManager.putInMemory(IOUtils.toInputStream(newContent, "UTF-8"),
fsManager.getAbsolutePath(Commons.getEntityBasePath("Person", entityId) + Constants.get(version, fsManager.getAbsolutePath(Commons.getEntityBasePath("Person", entityId) + Constants.get(version,
ConstantKey.ENTITY), utils.getKey())); ConstantKey.ENTITY), utils.getKey()));
return utils.getValue().createResponse(null, null, utils.getKey(), Response.Status.NO_CONTENT); return utils.getValue().createResponse(null, null, null, utils.getKey(), Response.Status.NO_CONTENT);
} catch (Exception e) { } catch (Exception e) {
return xml.createFaultResponse(accept, e); return xml.createFaultResponse(accept, e);
} }
@ -722,15 +775,15 @@ public abstract class AbstractServices {
final Long newSalary = Long.valueOf(salaryMatcher.group(1)) + n; final Long newSalary = Long.valueOf(salaryMatcher.group(1)) + n;
newContent = newContent. newContent = newContent.
replaceAll("\"Salary\":" + salaryMatcher.group(1) + ",", replaceAll("\"Salary\":" + salaryMatcher.group(1) + ",",
"\"Salary\":" + newSalary + ","). "\"Salary\":" + newSalary + ",").
replaceAll("\\<d:Salary m:type=\"Edm.Int32\"\\>" + salaryMatcher.group(1) + "</d:Salary\\>", replaceAll("\\<d:Salary m:type=\"Edm.Int32\"\\>" + salaryMatcher.group(1) + "</d:Salary\\>",
"<d:Salary m:type=\"Edm.Int32\">" + newSalary + "</d:Salary>"); "<d:Salary m:type=\"Edm.Int32\">" + newSalary + "</d:Salary>");
} }
FSManager.instance(version).putInMemory(IOUtils.toInputStream(newContent, "UTF-8"), FSManager.instance(version).putInMemory(IOUtils.toInputStream(newContent, "UTF-8"),
FSManager.instance(version).getAbsolutePath(path.toString(), acceptType)); FSManager.instance(version).getAbsolutePath(path.toString(), acceptType));
return xml.createResponse(null, null, acceptType, Response.Status.NO_CONTENT); return xml.createResponse(null, null, null, acceptType, Response.Status.NO_CONTENT);
} catch (Exception e) { } catch (Exception e) {
return xml.createFaultResponse(accept, e); return xml.createFaultResponse(accept, e);
} }
@ -767,7 +820,7 @@ public abstract class AbstractServices {
: Constants.get(version, ConstantKey.FEED)); : Constants.get(version, ConstantKey.FEED));
final InputStream feed = FSManager.instance(version).readFile(path.toString(), acceptType); final InputStream feed = FSManager.instance(version).readFile(path.toString(), acceptType);
return xml.createResponse(feed, Commons.getETag(basePath, version), acceptType); return xml.createResponse(null, feed, Commons.getETag(basePath, version), acceptType);
} catch (Exception e) { } catch (Exception e) {
return xml.createFaultResponse(accept, e); return xml.createFaultResponse(accept, e);
} }
@ -788,6 +841,7 @@ public abstract class AbstractServices {
@GET @GET
@Path("/{name}") @Path("/{name}")
public Response getEntitySet( public Response getEntitySet(
@Context UriInfo uriInfo,
@HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) String accept, @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) String accept,
@PathParam("name") String name, @PathParam("name") String name,
@QueryParam("$format") @DefaultValue(StringUtils.EMPTY) String format, @QueryParam("$format") @DefaultValue(StringUtils.EMPTY) String format,
@ -804,10 +858,11 @@ public abstract class AbstractServices {
acceptType = Accept.parse(accept, version); acceptType = Accept.parse(accept, version);
} }
final String location = uriInfo.getRequestUri().toASCIIString();
try { try {
// search for function ... // search for function ...
final InputStream func = FSManager.instance(version).readFile(name, acceptType); final InputStream func = FSManager.instance(version).readFile(name, acceptType);
return xml.createResponse(func, null, acceptType); return xml.createResponse(location, func, null, acceptType);
} catch (NotFoundException e) { } catch (NotFoundException e) {
if (acceptType == Accept.XML || acceptType == Accept.TEXT) { if (acceptType == Accept.XML || acceptType == Accept.TEXT) {
throw new UnsupportedMediaTypeException("Unsupported media type"); throw new UnsupportedMediaTypeException("Unsupported media type");
@ -856,11 +911,14 @@ public abstract class AbstractServices {
mapper.writeValue( mapper.writeValue(
writer, new JsonFeedContainer<JSONFeedImpl>(container.getContextURL(), container.getMetadataETag(), writer, new JsonFeedContainer<JSONFeedImpl>(container.getContextURL(), container.getMetadataETag(),
new DataBinder(version).getJsonFeed(container.getObject()))); new DataBinder(version).getJsonFeed(container.getObject())));
} }
return xml.createResponse(new ByteArrayInputStream(content.toByteArray()), return xml.createResponse(
Commons.getETag(basePath, version), acceptType); location,
new ByteArrayInputStream(content.toByteArray()),
Commons.getETag(basePath, version),
acceptType);
} }
} catch (Exception e) { } catch (Exception e) {
return xml.createFaultResponse(accept, e); return xml.createFaultResponse(accept, e);
@ -880,6 +938,7 @@ public abstract class AbstractServices {
@GET @GET
@Path("/Person({entityId})") @Path("/Person({entityId})")
public Response getEntity( public Response getEntity(
@Context UriInfo uriInfo,
@HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) final String accept, @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) final String accept,
@PathParam("entityId") final String entityId, @PathParam("entityId") final String entityId,
@QueryParam("$format") @DefaultValue(StringUtils.EMPTY) final String format) { @QueryParam("$format") @DefaultValue(StringUtils.EMPTY) final String format) {
@ -901,7 +960,10 @@ public abstract class AbstractServices {
} }
return utils.getValue().createResponse( return utils.getValue().createResponse(
entity, Commons.getETag(entityInfo.getKey(), version), utils.getKey()); uriInfo.getRequestUri().toASCIIString(),
entity,
Commons.getETag(entityInfo.getKey(), version),
utils.getKey());
} catch (Exception e) { } catch (Exception e) {
LOG.error("Error retrieving entity", e); LOG.error("Error retrieving entity", e);
return xml.createFaultResponse(accept, e); return xml.createFaultResponse(accept, e);
@ -922,6 +984,7 @@ public abstract class AbstractServices {
@GET @GET
@Path("/{entitySetName}({entityId})") @Path("/{entitySetName}({entityId})")
public Response getEntity( public Response getEntity(
@Context UriInfo uriInfo,
@HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) String accept, @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) String accept,
@PathParam("entitySetName") String entitySetName, @PathParam("entitySetName") String entitySetName,
@PathParam("entityId") String entityId, @PathParam("entityId") String entityId,
@ -929,10 +992,12 @@ public abstract class AbstractServices {
@QueryParam("$expand") @DefaultValue(StringUtils.EMPTY) String expand, @QueryParam("$expand") @DefaultValue(StringUtils.EMPTY) String expand,
@QueryParam("$select") @DefaultValue(StringUtils.EMPTY) String select) { @QueryParam("$select") @DefaultValue(StringUtils.EMPTY) String select) {
return getEntityInternal(accept, entitySetName, entityId, format, expand, select, false); return getEntityInternal(
uriInfo.getRequestUri().toASCIIString(), accept, entitySetName, entityId, format, expand, select, false);
} }
protected Response getEntityInternal( protected Response getEntityInternal(
final String location,
final String accept, final String accept,
final String entitySetName, final String entitySetName,
final String entityId, final String entityId,
@ -1038,11 +1103,14 @@ public abstract class AbstractServices {
final ObjectMapper mapper = Commons.getJsonMapper(version); final ObjectMapper mapper = Commons.getJsonMapper(version);
mapper.writeValue( mapper.writeValue(
writer, new JsonEntryContainer<JSONEntryImpl>(container.getContextURL(), container.getMetadataETag(), writer, new JsonEntryContainer<JSONEntryImpl>(container.getContextURL(), container.getMetadataETag(),
(new DataBinder(version)).getJsonEntry((AtomEntryImpl) container.getObject()))); (new DataBinder(version)).getJsonEntry((AtomEntryImpl) container.getObject())));
} }
return xml.createResponse(new ByteArrayInputStream(content.toByteArray()), return xml.createResponse(
Commons.getETag(entityInfo.getKey(), version), utils.getKey()); location,
new ByteArrayInputStream(content.toByteArray()),
Commons.getETag(entityInfo.getKey(), version),
utils.getKey());
} catch (Exception e) { } catch (Exception e) {
LOG.error("Error retrieving entity", e); LOG.error("Error retrieving entity", e);
@ -1053,6 +1121,7 @@ public abstract class AbstractServices {
@GET @GET
@Path("/{entitySetName}({entityId})/$value") @Path("/{entitySetName}({entityId})/$value")
public Response getMediaEntity( public Response getMediaEntity(
@Context UriInfo uriInfo,
@HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) String accept, @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) String accept,
@PathParam("entitySetName") String entitySetName, @PathParam("entitySetName") String entitySetName,
@PathParam("entityId") String entityId) { @PathParam("entityId") String entityId) {
@ -1064,7 +1133,11 @@ public abstract class AbstractServices {
final AbstractUtilities utils = getUtilities(null); final AbstractUtilities utils = getUtilities(null);
final Map.Entry<String, InputStream> entityInfo = utils.readMediaEntity(entitySetName, entityId); final Map.Entry<String, InputStream> entityInfo = utils.readMediaEntity(entitySetName, entityId);
return utils.createResponse(entityInfo.getValue(), Commons.getETag(entityInfo.getKey(), version), null); return utils.createResponse(
uriInfo.getRequestUri().toASCIIString(),
entityInfo.getValue(),
Commons.getETag(entityInfo.getKey(), version),
null);
} catch (Exception e) { } catch (Exception e) {
LOG.error("Error retrieving entity", e); LOG.error("Error retrieving entity", e);
@ -1084,7 +1157,7 @@ public abstract class AbstractServices {
FSManager.instance(version).deleteFile(basePath + Constants.get(version, ConstantKey.ENTITY)); FSManager.instance(version).deleteFile(basePath + Constants.get(version, ConstantKey.ENTITY));
return xml.createResponse(null, null, null, Response.Status.NO_CONTENT); return xml.createResponse(null, null, null, null, Response.Status.NO_CONTENT);
} catch (Exception e) { } catch (Exception e) {
return xml.createFaultResponse(Accept.XML.toString(version), e); return xml.createFaultResponse(Accept.XML.toString(version), e);
} }
@ -1122,10 +1195,10 @@ public abstract class AbstractServices {
final Response response; final Response response;
if ("return-content".equalsIgnoreCase(prefer)) { if ("return-content".equalsIgnoreCase(prefer)) {
response = xml.createResponse(changed, null, acceptType, Response.Status.OK); response = xml.createResponse(null, changed, null, acceptType, Response.Status.OK);
} else { } else {
changed.close(); changed.close();
response = xml.createResponse(null, null, acceptType, Response.Status.NO_CONTENT); response = xml.createResponse(null, null, null, acceptType, Response.Status.NO_CONTENT);
} }
if (StringUtils.isNotBlank(prefer)) { if (StringUtils.isNotBlank(prefer)) {
@ -1167,10 +1240,10 @@ public abstract class AbstractServices {
final Response response; final Response response;
if ("return-content".equalsIgnoreCase(prefer)) { if ("return-content".equalsIgnoreCase(prefer)) {
response = xml.createResponse(changed, null, acceptType, Response.Status.OK); response = xml.createResponse(null, changed, null, acceptType, Response.Status.OK);
} else { } else {
changed.close(); changed.close();
response = xml.createResponse(null, null, acceptType, Response.Status.NO_CONTENT); response = xml.createResponse(null, null, null, acceptType, Response.Status.NO_CONTENT);
} }
if (StringUtils.isNotBlank(prefer)) { if (StringUtils.isNotBlank(prefer)) {
@ -1261,6 +1334,7 @@ public abstract class AbstractServices {
@Consumes({MediaType.WILDCARD, MediaType.APPLICATION_OCTET_STREAM}) @Consumes({MediaType.WILDCARD, MediaType.APPLICATION_OCTET_STREAM})
@Path("/{entitySetName}({entityId})/$value") @Path("/{entitySetName}({entityId})/$value")
public Response replaceMediaEntity( public Response replaceMediaEntity(
@Context UriInfo uriInfo,
@HeaderParam("Prefer") @DefaultValue(StringUtils.EMPTY) String prefer, @HeaderParam("Prefer") @DefaultValue(StringUtils.EMPTY) String prefer,
@PathParam("entitySetName") String entitySetName, @PathParam("entitySetName") String entitySetName,
@PathParam("entityId") String entityId, @PathParam("entityId") String entityId,
@ -1272,12 +1346,14 @@ public abstract class AbstractServices {
InputStream res = utils.putMediaInMemory(entitySetName, entityId, IOUtils.toInputStream(value)); InputStream res = utils.putMediaInMemory(entitySetName, entityId, IOUtils.toInputStream(value));
final String location = uriInfo.getRequestUri().toASCIIString().replace("/$value", "");
final Response response; final Response response;
if ("return-content".equalsIgnoreCase(prefer)) { if ("return-content".equalsIgnoreCase(prefer)) {
response = xml.createResponse(res, null, null, Response.Status.OK); response = xml.createResponse(location, res, null, null, Response.Status.OK);
} else { } else {
res.close(); res.close();
response = xml.createResponse(null, null, null, Response.Status.NO_CONTENT); response = xml.createResponse(location, null, null, null, Response.Status.NO_CONTENT);
} }
if (StringUtils.isNotBlank(prefer)) { if (StringUtils.isNotBlank(prefer)) {
@ -1333,10 +1409,10 @@ public abstract class AbstractServices {
final Response response; final Response response;
if ("return-content".equalsIgnoreCase(prefer)) { if ("return-content".equalsIgnoreCase(prefer)) {
response = xml.createResponse(res, null, null, Response.Status.OK); response = xml.createResponse(null, res, null, null, Response.Status.OK);
} else { } else {
res.close(); res.close();
response = xml.createResponse(null, null, null, Response.Status.NO_CONTENT); response = xml.createResponse(null, null, null, null, Response.Status.NO_CONTENT);
} }
if (StringUtils.isNotBlank(prefer)) { if (StringUtils.isNotBlank(prefer)) {
@ -1462,7 +1538,7 @@ public abstract class AbstractServices {
final AbstractUtilities utils = getUtilities(null); final AbstractUtilities utils = getUtilities(null);
final Map.Entry<String, InputStream> entityInfo = utils.readMediaEntity(entitySetName, entityId, path); final Map.Entry<String, InputStream> entityInfo = utils.readMediaEntity(entitySetName, entityId, path);
return utils.createResponse(entityInfo.getValue(), Commons.getETag(entityInfo.getKey(), version), null); return utils.createResponse(null, entityInfo.getValue(), Commons.getETag(entityInfo.getKey(), version), null);
} }
private Response navigateEntity( private Response navigateEntity(
@ -1511,7 +1587,7 @@ public abstract class AbstractServices {
} }
} }
final String basePath = Commons.getEntityBasePath(entitySetName, entityId); final String basePath = Commons.getEntityBasePath(entitySetName, entityId);
return xml.createResponse(stream, Commons.getETag(basePath, version), acceptType); return xml.createResponse(null, stream, Commons.getETag(basePath, version), acceptType);
} }
private Response navigateProperty( private Response navigateProperty(
@ -1544,7 +1620,7 @@ public abstract class AbstractServices {
stream = utils.getProperty(entitySetName, entityId, pathElements, edmType); stream = utils.getProperty(entitySetName, entityId, pathElements, edmType);
} }
return xml.createResponse(stream, Commons.getETag(basePath, version), acceptType); return xml.createResponse(null, stream, Commons.getETag(basePath, version), acceptType);
} }
/** /**

View File

@ -32,8 +32,10 @@ import javax.ws.rs.Path;
import javax.ws.rs.PathParam; import javax.ws.rs.PathParam;
import javax.ws.rs.Produces; import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam; import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.olingo.fit.methods.MERGE; import org.apache.olingo.fit.methods.MERGE;
@ -79,6 +81,7 @@ public class V3KeyAsSegment {
@GET @GET
@Path("/{entitySetName}/{entityId}") @Path("/{entitySetName}/{entityId}")
public Response getEntity( public Response getEntity(
@Context UriInfo uriInfo,
@HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) String accept, @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) String accept,
@PathParam("entitySetName") String entitySetName, @PathParam("entitySetName") String entitySetName,
@PathParam("entityId") String entityId, @PathParam("entityId") String entityId,
@ -86,7 +89,7 @@ public class V3KeyAsSegment {
@QueryParam("$expand") @DefaultValue(StringUtils.EMPTY) String expand, @QueryParam("$expand") @DefaultValue(StringUtils.EMPTY) String expand,
@QueryParam("$select") @DefaultValue(StringUtils.EMPTY) String select) { @QueryParam("$select") @DefaultValue(StringUtils.EMPTY) String select) {
return replaceServiceName(services.getEntityInternal( return replaceServiceName(services.getEntityInternal(uriInfo.getRequestUri().toASCIIString(),
accept, entitySetName, entityId, format, expand, select, true)); accept, entitySetName, entityId, format, expand, select, true));
} }
@ -104,6 +107,7 @@ public class V3KeyAsSegment {
@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON}) @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON})
@Consumes({MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON}) @Consumes({MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON})
public Response mergeEntity( public Response mergeEntity(
@Context UriInfo uriInfo,
@HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) String accept, @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) String accept,
@HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) String contentType, @HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) String contentType,
@HeaderParam("Prefer") @DefaultValue(StringUtils.EMPTY) String prefer, @HeaderParam("Prefer") @DefaultValue(StringUtils.EMPTY) String prefer,
@ -113,7 +117,7 @@ public class V3KeyAsSegment {
final String changes) { final String changes) {
return replaceServiceName( return replaceServiceName(
services.patchEntity(accept, contentType, prefer, ifMatch, entitySetName, entityId, changes)); services.patchEntity(uriInfo, accept, contentType, prefer, ifMatch, entitySetName, entityId, changes));
} }
@PATCH @PATCH
@ -121,6 +125,7 @@ public class V3KeyAsSegment {
@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON}) @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON})
@Consumes({MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON}) @Consumes({MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON})
public Response patchEntity( public Response patchEntity(
@Context UriInfo uriInfo,
@HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) String accept, @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) String accept,
@HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) String contentType, @HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) String contentType,
@HeaderParam("Prefer") @DefaultValue(StringUtils.EMPTY) String prefer, @HeaderParam("Prefer") @DefaultValue(StringUtils.EMPTY) String prefer,
@ -130,7 +135,7 @@ public class V3KeyAsSegment {
final String changes) { final String changes) {
return replaceServiceName( return replaceServiceName(
services.patchEntity(accept, contentType, prefer, ifMatch, entitySetName, entityId, changes)); services.patchEntity(uriInfo, accept, contentType, prefer, ifMatch, entitySetName, entityId, changes));
} }
@PUT @PUT
@ -138,6 +143,7 @@ public class V3KeyAsSegment {
@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON}) @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON})
@Consumes({MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON}) @Consumes({MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON})
public Response putNewEntity( public Response putNewEntity(
@Context UriInfo uriInfo,
@HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) String accept, @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) String accept,
@HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) String contentType, @HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) String contentType,
@HeaderParam("Prefer") @DefaultValue(StringUtils.EMPTY) String prefer, @HeaderParam("Prefer") @DefaultValue(StringUtils.EMPTY) String prefer,
@ -146,7 +152,7 @@ public class V3KeyAsSegment {
final String entity) { final String entity) {
return replaceServiceName( return replaceServiceName(
services.replaceEntity(accept, contentType, prefer, entitySetName, entityId, entity)); services.replaceEntity(uriInfo, accept, contentType, prefer, entitySetName, entityId, entity));
} }
@POST @POST
@ -154,12 +160,13 @@ public class V3KeyAsSegment {
@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON}) @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON})
@Consumes({MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_OCTET_STREAM}) @Consumes({MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_OCTET_STREAM})
public Response postNewEntity( public Response postNewEntity(
@Context UriInfo uriInfo,
@HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) String accept, @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) String accept,
@HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) String contentType, @HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) String contentType,
@HeaderParam("Prefer") @DefaultValue(StringUtils.EMPTY) String prefer, @HeaderParam("Prefer") @DefaultValue(StringUtils.EMPTY) String prefer,
@PathParam("entitySetName") String entitySetName, @PathParam("entitySetName") String entitySetName,
final String entity) { final String entity) {
return replaceServiceName(services.postNewEntity(accept, contentType, prefer, entitySetName, entity)); return replaceServiceName(services.postNewEntity(uriInfo, accept, contentType, prefer, entitySetName, entity));
} }
} }

View File

@ -33,8 +33,10 @@ import javax.ws.rs.Path;
import javax.ws.rs.PathParam; import javax.ws.rs.PathParam;
import javax.ws.rs.Produces; import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam; import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion; import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
@ -110,6 +112,7 @@ public class V3OpenType {
@GET @GET
@Path("/{entitySetName}({entityId})") @Path("/{entitySetName}({entityId})")
public Response getEntity( public Response getEntity(
@Context UriInfo uriInfo,
@HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) String accept, @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) String accept,
@PathParam("entitySetName") String entitySetName, @PathParam("entitySetName") String entitySetName,
@PathParam("entityId") String entityId, @PathParam("entityId") String entityId,
@ -118,7 +121,8 @@ public class V3OpenType {
@QueryParam("$select") @DefaultValue(StringUtils.EMPTY) String select) { @QueryParam("$select") @DefaultValue(StringUtils.EMPTY) String select) {
final Matcher matcher = GUID.matcher(entityId); final Matcher matcher = GUID.matcher(entityId);
return replaceServiceName(services.getEntityInternal(accept, entitySetName, return replaceServiceName(services.getEntityInternal(
uriInfo.getRequestUri().toASCIIString(), accept, entitySetName,
matcher.matches() ? matcher.group(1) : entityId, format, expand, select, false)); matcher.matches() ? matcher.group(1) : entityId, format, expand, select, false));
} }
@ -127,13 +131,14 @@ public class V3OpenType {
@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON}) @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON})
@Consumes({MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_OCTET_STREAM}) @Consumes({MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_OCTET_STREAM})
public Response postNewEntity( public Response postNewEntity(
@Context UriInfo uriInfo,
@HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) String accept, @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) String accept,
@HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) String contentType, @HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) String contentType,
@HeaderParam("Prefer") @DefaultValue(StringUtils.EMPTY) String prefer, @HeaderParam("Prefer") @DefaultValue(StringUtils.EMPTY) String prefer,
@PathParam("entitySetName") final String entitySetName, @PathParam("entitySetName") final String entitySetName,
final String entity) { final String entity) {
return replaceServiceName(services.postNewEntity(accept, contentType, prefer, entitySetName, entity)); return replaceServiceName(services.postNewEntity(uriInfo, accept, contentType, prefer, entitySetName, entity));
} }
@DELETE @DELETE

View File

@ -319,5 +319,4 @@ public class V3Services extends AbstractServices {
return xml.createFaultResponse(accept, e); return xml.createFaultResponse(accept, e);
} }
} }
} }

View File

@ -31,8 +31,10 @@ import javax.ws.rs.Path;
import javax.ws.rs.PathParam; import javax.ws.rs.PathParam;
import javax.ws.rs.Produces; import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam; import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion; import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
@ -54,9 +56,8 @@ public class V4OpenType {
public V4OpenType() throws Exception { public V4OpenType() throws Exception {
this.openMetadata = new Metadata(FSManager.instance(ODataServiceVersion.V40). this.openMetadata = new Metadata(FSManager.instance(ODataServiceVersion.V40).
readFile("openType" + StringUtils.capitalize(Constants.get(ODataServiceVersion.V40, ConstantKey.METADATA)), readFile("openType" + StringUtils.capitalize(Constants.get(ODataServiceVersion.V40, ConstantKey.METADATA)),
Accept.XML)); Accept.XML));
this.services = new V4Services() { this.services = new V4Services() {
@Override @Override
protected Metadata getMetadataObj() { protected Metadata getMetadataObj() {
return openMetadata; return openMetadata;
@ -106,6 +107,7 @@ public class V4OpenType {
@GET @GET
@Path("/{entitySetName}({entityId})") @Path("/{entitySetName}({entityId})")
public Response getEntity( public Response getEntity(
@Context UriInfo uriInfo,
@HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) String accept, @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) String accept,
@PathParam("entitySetName") String entitySetName, @PathParam("entitySetName") String entitySetName,
@PathParam("entityId") String entityId, @PathParam("entityId") String entityId,
@ -114,7 +116,8 @@ public class V4OpenType {
@QueryParam("$select") @DefaultValue(StringUtils.EMPTY) String select) { @QueryParam("$select") @DefaultValue(StringUtils.EMPTY) String select) {
return replaceServiceName( return replaceServiceName(
services.getEntityInternal(accept, entitySetName, entityId, format, expand, select, false)); services.getEntityInternal(
uriInfo.getRequestUri().toASCIIString(), accept, entitySetName, entityId, format, expand, select, false));
} }
@POST @POST
@ -122,13 +125,14 @@ public class V4OpenType {
@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON}) @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON})
@Consumes({MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_OCTET_STREAM}) @Consumes({MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_OCTET_STREAM})
public Response postNewEntity( public Response postNewEntity(
@Context UriInfo uriInfo,
@HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) String accept, @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) String accept,
@HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) String contentType, @HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) String contentType,
@HeaderParam("Prefer") @DefaultValue(StringUtils.EMPTY) String prefer, @HeaderParam("Prefer") @DefaultValue(StringUtils.EMPTY) String prefer,
@PathParam("entitySetName") final String entitySetName, @PathParam("entitySetName") final String entitySetName,
final String entity) { final String entity) {
return replaceServiceName(services.postNewEntity(accept, contentType, prefer, entitySetName, entity)); return replaceServiceName(services.postNewEntity(uriInfo, accept, contentType, prefer, entitySetName, entity));
} }
@DELETE @DELETE

View File

@ -31,6 +31,7 @@ import javax.ws.rs.Path;
import javax.ws.rs.PathParam; import javax.ws.rs.PathParam;
import javax.ws.rs.QueryParam; import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;
import org.apache.commons.codec.binary.Base64; import org.apache.commons.codec.binary.Base64;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
@ -97,7 +98,7 @@ public class V4Services extends AbstractServices {
return utils.getValue().createResponse( return utils.getValue().createResponse(
FSManager.instance(version).readFile(Constants.get(version, ConstantKey.REF) FSManager.instance(version).readFile(Constants.get(version, ConstantKey.REF)
+ File.separatorChar + filename, utils.getKey()), + File.separatorChar + filename, utils.getKey()),
null, null,
utils.getKey()); utils.getKey());
} catch (Exception e) { } catch (Exception e) {
@ -108,6 +109,7 @@ public class V4Services extends AbstractServices {
@Override @Override
public Response patchEntity( public Response patchEntity(
final UriInfo uriInfo,
final String accept, final String accept,
final String contentType, final String contentType,
final String prefer, final String prefer,
@ -117,14 +119,16 @@ public class V4Services extends AbstractServices {
final String changes) { final String changes) {
final Response response = final Response response =
getEntityInternal(accept, entitySetName, entityId, accept, StringUtils.EMPTY, StringUtils.EMPTY, false); getEntityInternal(uriInfo.getRequestUri().toASCIIString(),
accept, entitySetName, entityId, accept, StringUtils.EMPTY, StringUtils.EMPTY, false);
return response.getStatus() >= 400 return response.getStatus() >= 400
? postNewEntity(accept, contentType, prefer, entitySetName, changes) ? postNewEntity(uriInfo, accept, contentType, prefer, entitySetName, changes)
: super.patchEntity(accept, contentType, prefer, ifMatch, entitySetName, entityId, changes); : super.patchEntity(uriInfo, accept, contentType, prefer, ifMatch, entitySetName, entityId, changes);
} }
@Override @Override
public Response replaceEntity( public Response replaceEntity(
final UriInfo uriInfo,
final String accept, final String accept,
final String contentType, final String contentType,
final String prefer, final String prefer,
@ -133,10 +137,11 @@ public class V4Services extends AbstractServices {
final String entity) { final String entity) {
try { try {
getEntityInternal(accept, entitySetName, entityId, accept, StringUtils.EMPTY, StringUtils.EMPTY, false); getEntityInternal(uriInfo.getRequestUri().toASCIIString(),
return super.replaceEntity(accept, contentType, prefer, entitySetName, entityId, entity); accept, entitySetName, entityId, accept, StringUtils.EMPTY, StringUtils.EMPTY, false);
return super.replaceEntity(uriInfo, accept, contentType, prefer, entitySetName, entityId, entity);
} catch (NotFoundException e) { } catch (NotFoundException e) {
return postNewEntity(accept, contentType, prefer, entitySetName, entityId); return postNewEntity(uriInfo, accept, contentType, prefer, entitySetName, entityId);
} }
} }
@ -225,7 +230,7 @@ public class V4Services extends AbstractServices {
final Container<JSONEntryImpl> jsonContainer = mapper.readValue(IOUtils.toInputStream(changes), final Container<JSONEntryImpl> jsonContainer = mapper.readValue(IOUtils.toInputStream(changes),
new TypeReference<JSONEntryImpl>() { new TypeReference<JSONEntryImpl>() {
}); });
jsonContainer.getObject().setType(typeInfo.getFullQualifiedName().toString()); jsonContainer.getObject().setType(typeInfo.getFullQualifiedName().toString());
entryChanges = dataBinder.getAtomEntry(jsonContainer.getObject()); entryChanges = dataBinder.getAtomEntry(jsonContainer.getObject());
} }
@ -246,5 +251,4 @@ public class V4Services extends AbstractServices {
return xml.createFaultResponse(accept, e); return xml.createFaultResponse(accept, e);
} }
} }
} }

View File

@ -365,7 +365,7 @@ public abstract class AbstractUtilities {
fsManager.putInMemory( fsManager.putInMemory(
IOUtils.toInputStream(entity), fsManager.getAbsolutePath(path + Constants.get(version, ConstantKey.ENTITY), IOUtils.toInputStream(entity), fsManager.getAbsolutePath(path + Constants.get(version, ConstantKey.ENTITY),
Accept.JSON_FULLMETA)); Accept.JSON_FULLMETA));
// ----------------------------------------- // -----------------------------------------
return readEntity(entitySetName, entityKey, getDefaultFormat()).getValue(); return readEntity(entitySetName, entityKey, getDefaultFormat()).getValue();
@ -410,8 +410,12 @@ public abstract class AbstractUtilities {
} }
public Response createResponse( public Response createResponse(
final InputStream entity, final String etag, final Accept accept) { final String location, final InputStream entity, final String etag, final Accept accept) {
return createResponse(entity, etag, accept, null); return createResponse(location, entity, etag, accept, null);
}
public Response createResponse(final InputStream entity, final String etag, final Accept accept) {
return createResponse(null, entity, etag, accept, null);
} }
public Response createBatchResponse(final InputStream stream, final String boundary) { public Response createBatchResponse(final InputStream stream, final String boundary) {
@ -421,7 +425,18 @@ public abstract class AbstractUtilities {
} }
public Response createResponse( public Response createResponse(
final InputStream entity, final String etag, final Accept accept, final Response.Status status) { final InputStream entity,
final String etag,
final Accept accept,
final Response.Status status) {
return createResponse(null, entity, etag, accept, status);
}
public Response createResponse(
final String location,
final InputStream entity,
final String etag,
final Accept accept,
final Response.Status status) {
final Response.ResponseBuilder builder = Response.ok(); final Response.ResponseBuilder builder = Response.ok();
if (version.compareTo(ODataServiceVersion.V30) <= 0) { if (version.compareTo(ODataServiceVersion.V30) <= 0) {
@ -466,6 +481,10 @@ public abstract class AbstractUtilities {
builder.header("Content-Length", contentLength); builder.header("Content-Length", contentLength);
builder.header("Content-Type", (accept == null ? "*/*" : accept.toString(version)) + contentTypeEncoding); builder.header("Content-Type", (accept == null ? "*/*" : accept.toString(version)) + contentTypeEncoding);
if (StringUtils.isNotBlank(location)) {
builder.header("Location", location);
}
return builder.build(); return builder.build();
} }

View File

@ -0,0 +1,11 @@
{
"odata.metadata": "http://localhost:${cargo.servlet.port}/StaticService/V30/Static.svc/$metadata#CustomerInfo/@Element",
"odata.type": "Microsoft.Test.OData.Services.AstoriaDefaultService.CustomerInfo",
"odata.id": "http://localhost:${cargo.servlet.port}/StaticService/V30/Static.svc/CustomerInfo(17)",
"odata.editLink": "CustomerInfo(17)",
"odata.mediaEditLink": "CustomerInfo(17)/$value",
"odata.mediaReadLink": "CustomerInfo(17)/$value",
"odata.mediaContentType": "*/*",
"CustomerInfoId": 17,
"Information": "び黑ポ畚ぜマチンハ歹黑zクヲネボァたグヲ黑ソЯ歹ぴせポzゼ弌ぞせぜゼ亜Яクあソ亜ゼそせ珱ァタひグゼ縷яぁゾ黑マミ裹暦ポя"
}

View File

@ -0,0 +1,37 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<entry xml:base="http://localhost:${cargo.servlet.port}/StaticService/V30/Static.svc/" xmlns="http://www.w3.org/2005/Atom" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
<id>http://localhost:${cargo.servlet.port}/StaticService/V30/Static.svc/CustomerInfo(17)</id>
<category term="Microsoft.Test.OData.Services.AstoriaDefaultService.CustomerInfo" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />
<link rel="edit" title="CustomerInfo" href="CustomerInfo(17)" />
<title />
<updated>2014-03-04T09:52:15Z</updated>
<author>
<name />
</author>
<link rel="edit-media" title="CustomerInfo" href="CustomerInfo(17)/$value" />
<content type="*/*" src="CustomerInfo(17)/$value" />
<m:properties>
<d:CustomerInfoId m:type="Edm.Int32">17</d:CustomerInfoId>
<d:Information>び黑ポ畚ぜマチンハ歹黑zクヲネボァたグヲ黑ソЯ歹ぴせポzゼ弌ぞせぜゼ亜Яクあソ亜ゼそせ珱ァタひグゼ縷яぁゾ黑マミ裹暦ポя</d:Information>
</m:properties>
</entry>

View File

@ -151,7 +151,6 @@ public class BatchTestITCase extends AbstractTestITCase {
} }
@Test @Test
@Ignore
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void changesetWithReference() throws EdmPrimitiveTypeException { public void changesetWithReference() throws EdmPrimitiveTypeException {
// create your request // create your request
@ -161,7 +160,7 @@ public class BatchTestITCase extends AbstractTestITCase {
final ODataChangeset changeset = streamManager.addChangeset(); final ODataChangeset changeset = streamManager.addChangeset();
ODataEntity customer = getSampleCustomerProfile(20, "sample customer", false); ODataEntity customer = getSampleCustomerProfile(20, "sample customer", false);
URIBuilder uriBuilder = client.getURIBuilder(testAuthServiceRootURL).appendEntitySetSegment("Customer"); URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL).appendEntitySetSegment("Customer");
// add create request // add create request
final ODataEntityCreateRequest<ODataEntity> createReq = final ODataEntityCreateRequest<ODataEntity> createReq =
@ -176,10 +175,10 @@ public class BatchTestITCase extends AbstractTestITCase {
final ODataEntity customerChanges = client.getObjectFactory().newEntity(customer.getTypeName()); final ODataEntity customerChanges = client.getObjectFactory().newEntity(customer.getTypeName());
customerChanges.addLink(client.getObjectFactory().newEntityNavigationLink( customerChanges.addLink(client.getObjectFactory().newEntityNavigationLink(
"Info", "Info",
client.getURIBuilder(testAuthServiceRootURL).appendEntitySetSegment("CustomerInfo"). client.getURIBuilder(testStaticServiceRootURL).appendEntitySetSegment("CustomerInfo").
appendKeySegment(17).build())); appendKeySegment(17).build()));
final ODataEntityUpdateRequest updateReq = client.getCUDRequestFactory().getEntityUpdateRequest( final ODataEntityUpdateRequest<ODataEntity> updateReq = client.getCUDRequestFactory().getEntityUpdateRequest(
URI.create("$" + createRequestRef), UpdateType.PATCH, customerChanges); URI.create("$" + createRequestRef), UpdateType.PATCH, customerChanges);
changeset.addRequest(updateReq); changeset.addRequest(updateReq);