Updates to our URL structure
diff --git a/JPA-RS/org.eclipse.persistence.jpars.test/.classpath b/JPA-RS/org.eclipse.persistence.jpars.test/.classpath
index 123d314..6c6870c 100644
--- a/JPA-RS/org.eclipse.persistence.jpars.test/.classpath
+++ b/JPA-RS/org.eclipse.persistence.jpars.test/.classpath
@@ -4,5 +4,6 @@
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
<classpathentry combineaccessrules="false" kind="src" path="/org.eclipse.persistence.jpars"/>
+ <classpathentry kind="con" path="org.eclipse.jst.server.core.container/com.sun.enterprise.jst.server.runtimeTarget/GlassFish 3.1.2"/>
<classpathentry kind="output" path="classes"/>
</classpath>
diff --git a/JPA-RS/org.eclipse.persistence.jpars.test/src/org/eclipse/persistence/jpars/test/service/TestService.java b/JPA-RS/org.eclipse.persistence.jpars.test/src/org/eclipse/persistence/jpars/test/service/TestService.java
index 6505121..aded45b 100644
--- a/JPA-RS/org.eclipse.persistence.jpars.test/src/org/eclipse/persistence/jpars/test/service/TestService.java
+++ b/JPA-RS/org.eclipse.persistence.jpars.test/src/org/eclipse/persistence/jpars/test/service/TestService.java
@@ -353,7 +353,7 @@
public void testMetadataQuery(){
Service service = new Service();
service.setPersistenceFactory(factory);
- StreamingOutput output = (StreamingOutput)service.getContexts(generateHTTPHeader(MediaType.APPLICATION_JSON_TYPE, MediaType.APPLICATION_JSON)).getEntity();
+ StreamingOutput output = (StreamingOutput)service.getContexts(generateHTTPHeader(MediaType.APPLICATION_JSON_TYPE, MediaType.APPLICATION_JSON), new TestURIInfo()).getEntity();
String result = stringifyResults(output);
assertTrue("auction was not in the results", result.contains("auction"));
assertTrue("phonebook was not in the results", result.contains("phonebook"));
@@ -367,6 +367,46 @@
}
+ @Test
+ public void testDelete(){
+ Service service = new Service();
+ service.setPersistenceFactory(factory);
+ PersistenceContext context = factory.getPersistenceContext("auction");
+
+ DynamicEntity entity1 = (DynamicEntity)context.newEntity("Auction");
+ entity1.set("name", "Computer1");
+ context.create(null, entity1);
+
+ TestURIInfo ui = new TestURIInfo();
+ service.delete("auction", "Auction", entity1.get("id").toString(), generateHTTPHeader(MediaType.APPLICATION_JSON_TYPE, MediaType.APPLICATION_JSON), ui);
+
+ entity1 = (DynamicEntity)context.find("Auction", entity1.get("id"));
+
+ assertTrue("Entity was not deleted.", entity1 == null);
+
+ }
+
+ @Test
+ public void testWriteQuery(){
+ Service service = new Service();
+ service.setPersistenceFactory(factory);
+ PersistenceContext context = factory.getPersistenceContext("auction");
+
+ DynamicEntity entity = (DynamicEntity)context.newEntity("User");
+ entity.set("name", "Bob");
+ context.create(null, entity);
+
+ TestURIInfo ui = new TestURIInfo();
+ ui.addMatrixParameter("name", "Robert");
+ ui.addMatrixParameter("id", entity.get("id").toString());
+
+ service.namedQueryUpdate("auction", "User.updateName", generateHTTPHeader(MediaType.APPLICATION_JSON_TYPE, MediaType.APPLICATION_JSON), ui);
+
+ entity = (DynamicEntity)context.find("User", entity.get("id"));
+
+ assertTrue("Entity was not updated.", entity.get("name").equals("Robert"));
+ }
+
public static String stringifyResults(StreamingOutput output){
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
try{
diff --git a/JPA-RS/org.eclipse.persistence.jpars.test/src/xmldocs/auction-orm.xml b/JPA-RS/org.eclipse.persistence.jpars.test/src/xmldocs/auction-orm.xml
index 1390bc5..c59c4de 100644
--- a/JPA-RS/org.eclipse.persistence.jpars.test/src/xmldocs/auction-orm.xml
+++ b/JPA-RS/org.eclipse.persistence.jpars.test/src/xmldocs/auction-orm.xml
@@ -40,6 +40,10 @@
<named-query name="User.all">
<query>SELECT u from User u</query>
</named-query>
+
+ <named-query name="User.updateName">
+ <query>UPDATE User u SET u.name = :name WHERE u.id = :id</query>
+ </named-query>
<entity class="User" access="VIRTUAL">
<table name="AUCTION_USER" />
diff --git a/JPA-RS/org.eclipse.persistence.jpars/dist/jpars.jar b/JPA-RS/org.eclipse.persistence.jpars/dist/jpars.jar
new file mode 100644
index 0000000..bcb85f2
--- /dev/null
+++ b/JPA-RS/org.eclipse.persistence.jpars/dist/jpars.jar
Binary files differ
diff --git a/JPA-RS/org.eclipse.persistence.jpars/src/org/eclipse/persistence/jpa/rs/PersistenceContext.java b/JPA-RS/org.eclipse.persistence.jpars/src/org/eclipse/persistence/jpa/rs/PersistenceContext.java
index 5e76cae..d61b6c4 100644
--- a/JPA-RS/org.eclipse.persistence.jpars/src/org/eclipse/persistence/jpa/rs/PersistenceContext.java
+++ b/JPA-RS/org.eclipse.persistence.jpars/src/org/eclipse/persistence/jpa/rs/PersistenceContext.java
@@ -28,6 +28,7 @@
import java.util.Map;
import java.util.Set;
+import javax.management.RuntimeErrorException;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Query;
@@ -39,6 +40,8 @@
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamWriter;
import javax.xml.transform.stream.StreamSource;
import org.eclipse.persistence.config.PersistenceUnitProperties;
@@ -380,6 +383,20 @@
return descriptor;
}
+ public ClassDescriptor getDescriptorForClass(Class clazz){
+ Server session = JpaHelper.getServerSession(getEmf());
+ ClassDescriptor descriptor = session.getDescriptor(clazz);
+ if (descriptor == null){
+ for (Object ajaxBSession:((JAXBContext)getJAXBContext()).getXMLContext().getSessions() ){
+ descriptor = ((Session)ajaxBSession).getClassDescriptor(clazz);
+ if (descriptor != null){
+ break;
+ }
+ }
+ }
+ return descriptor;
+ }
+
public EntityManagerFactory getEmf() {
return emf;
}
@@ -594,10 +611,11 @@
return element.getValue();
}
- public void marshallEntity(Object object, MediaType mediaType, OutputStream output) throws JAXBException {
+ public void marshallEntity(Object object, MediaType mediaType, OutputStream output) throws JAXBException {
Marshaller marshaller = getJAXBContext().createMarshaller();
marshaller.setProperty(MEDIA_TYPE, mediaType.toString());
marshaller.setProperty(org.eclipse.persistence.jaxb.JAXBContext.JSON_INCLUDE_ROOT, false);
+System.out.println("--- marshallEntity - " + object + " baseURI" + getBaseURI());
marshaller.setAdapter(new LinkAdapter(getBaseURI().toString(), this));
marshaller.setListener(new Marshaller.Listener() {
@Override
@@ -611,7 +629,28 @@
}
}
});
- marshaller.marshal(object, output);
+
+ if (mediaType == MediaType.APPLICATION_XML_TYPE && object instanceof List){
+ marshaller.setProperty(Marshaller.JAXB_FRAGMENT, true);
+ XMLOutputFactory outputFactory = XMLOutputFactory.newFactory();
+ XMLStreamWriter writer = null;
+ try{
+ writer = outputFactory.createXMLStreamWriter(output);
+ writer.writeStartDocument();
+ writer.writeStartElement("List");
+ for (Object o: (List<Object>)object){
+ marshaller.marshal(o, writer);
+ }
+ writer.writeEndDocument();
+ } catch (Exception e){
+ e.printStackTrace();
+ throw new RuntimeException(e);
+ }
+
+ } else {
+
+ marshaller.marshal(object, output);
+ }
}
}
diff --git a/JPA-RS/org.eclipse.persistence.jpars/src/org/eclipse/persistence/jpa/rs/Service.java b/JPA-RS/org.eclipse.persistence.jpars/src/org/eclipse/persistence/jpa/rs/Service.java
index 87c349d..730ab6d 100644
--- a/JPA-RS/org.eclipse.persistence.jpars/src/org/eclipse/persistence/jpa/rs/Service.java
+++ b/JPA-RS/org.eclipse.persistence.jpars/src/org/eclipse/persistence/jpa/rs/Service.java
@@ -17,6 +17,7 @@
import java.io.InputStream;
import java.net.URI;
import java.net.URL;
+import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
@@ -53,6 +54,7 @@
import org.eclipse.persistence.config.PersistenceUnitProperties;
import org.eclipse.persistence.descriptors.ClassDescriptor;
import org.eclipse.persistence.dynamic.DynamicClassLoader;
+import org.eclipse.persistence.dynamic.DynamicEntity;
import org.eclipse.persistence.internal.queries.MapContainerPolicy;
import org.eclipse.persistence.jpa.JpaHelper;
import org.eclipse.persistence.jpa.rs.metadata.DatabaseMetadataStore;
@@ -61,6 +63,7 @@
import org.eclipse.persistence.mappings.CollectionMapping;
import org.eclipse.persistence.mappings.DatabaseMapping;
import org.eclipse.persistence.mappings.ForeignReferenceMapping;
+import org.eclipse.persistence.queries.DatabaseQuery;
import com.sun.jersey.core.spi.factory.ResponseBuilderImpl;
@@ -112,14 +115,18 @@
@GET
@Path("/")
@Consumes({ MediaType.WILDCARD})
- public Response getContexts(@Context HttpHeaders hh) {
+ public Response getContexts(@Context HttpHeaders hh, @Context UriInfo uriInfo) {
ResponseBuilder rb = new ResponseBuilderImpl();
Set<String> contexts = factory.getPersistenceContextNames();
StringBuffer buffer = new StringBuffer();
buffer.append("[");
Iterator<String> contextIterator = contexts.iterator();
while (contextIterator.hasNext()){
- buffer.append("\"" + contextIterator.next() + "\"");
+ String context = contextIterator.next();
+ buffer.append("{");
+ buffer.append("\"name\": \"" + context + "\", ");
+ buffer.append("\"link\": \"" + uriInfo.getBaseUri() + context + "/metadata\"");
+ buffer.append("} ");
if (contextIterator.hasNext()){
buffer.append(", ");
}
@@ -155,6 +162,7 @@
rb.status(Status.NOT_FOUND);
}
if (persistenceContext != null){
+ System.out.println("--- Setting baseURI for " + persistenceUnit + " to " + uriInfo.getBaseUri());
persistenceContext.setBaseURI(uriInfo.getBaseUri());
rb.status(Status.CREATED);
}
@@ -163,7 +171,7 @@
}
@GET
- @Path("{context}")
+ @Path("{context}/metadata")
@Consumes({ MediaType.WILDCARD})
@Produces({MediaType.APPLICATION_JSON})
public Response getTypes(@PathParam("context") String persistenceUnit, @Context HttpHeaders hh, @Context UriInfo uriInfo) {
@@ -174,17 +182,24 @@
} else {
Map<Class, ClassDescriptor> descriptors = JpaHelper.getServerSession(app.getEmf()).getDescriptors();
StringBuffer buffer = new StringBuffer();
-
+ buffer.append("{");
+ buffer.append("\"persistence-unit-name\": \"" + persistenceUnit + "\", ");
+ buffer.append("\"types\": ");
buffer.append("[");
Iterator<Class> contextIterator = descriptors.keySet().iterator();
while (contextIterator.hasNext()){
ClassDescriptor descriptor = descriptors.get(contextIterator.next());
- appendDescriptor(buffer, descriptor);
+ buffer.append("{");
+ buffer.append("\"descriptor\": \"" + descriptor.getAlias() + "\", ");
+ buffer.append("\"link\": \"" + uriInfo.getBaseUri() + persistenceUnit + "/metadata/entity/" + descriptor.getAlias() + "\"");
+ buffer.append("}");
+ // appendDescriptor(buffer, descriptor);
if (contextIterator.hasNext()){
buffer.append(", ");
}
}
buffer.append("]");
+ buffer.append("}");
rb.status(Status.OK);
rb.entity(new StreamingOutputMarshaller(null , buffer.toString(), hh.getAcceptableMediaTypes()));
}
@@ -216,10 +231,52 @@
}
@GET
- @Path("{context}/entity/{type}")
- public Response find(@PathParam("context") String persistenceUnit, @PathParam("type") String type, @Context HttpHeaders hh, @Context UriInfo ui) {
+ @Path("{context}/metadata/entity/{descriptorAlias}")
+ @Consumes({ MediaType.WILDCARD})
+ @Produces({MediaType.APPLICATION_JSON})
+ public Response getDescriptorMetadata(@PathParam("context") String persistenceUnit, @PathParam("descriptorAlias") String descriptorAlias, @Context HttpHeaders hh, @Context UriInfo uriInfo) {
+ ResponseBuilder rb = new ResponseBuilderImpl();
+ PersistenceContext app = get(persistenceUnit, uriInfo.getBaseUri());
+ if (app == null){
+ rb.status(Status.NOT_FOUND);
+ } else {
+ ClassDescriptor descriptor = JpaHelper.getServerSession(app.getEmf()).getDescriptorForAlias(descriptorAlias);
+ if (descriptor == null){
+ rb.status(Status.NOT_FOUND);
+ } else {
+ StringBuffer buffer = new StringBuffer();
+ appendDescriptor(app, buffer, persistenceUnit, descriptor, uriInfo.getBaseUri().toString());
+ rb.status(Status.OK);
+ rb.entity(new StreamingOutputMarshaller(null , buffer.toString(), hh.getAcceptableMediaTypes()));
+ }
+ }
+ return rb.build();
+ }
+
+ @GET
+ @Path("{context}/metadata/query/")
+ @Consumes({ MediaType.WILDCARD})
+ @Produces({MediaType.APPLICATION_JSON})
+ public Response getDescriptorMetadata(@PathParam("context") String persistenceUnit, @Context HttpHeaders hh, @Context UriInfo uriInfo) {
+ ResponseBuilder rb = new ResponseBuilderImpl();
+ PersistenceContext app = get(persistenceUnit, uriInfo.getBaseUri());
+ if (app == null){
+ rb.status(Status.NOT_FOUND);
+ } else {
+ StringBuffer buffer = new StringBuffer();
+ appendQueries(buffer, app, null);
+ rb.status(Status.OK);
+ rb.entity(new StreamingOutputMarshaller(null , buffer.toString(), hh.getAcceptableMediaTypes()));
+
+ }
+ return rb.build();
+ }
+
+ @GET
+ @Path("{context}/entity/{type}/{key}")
+ public Response find(@PathParam("context") String persistenceUnit, @PathParam("type") String type, @PathParam("key") String key, @Context HttpHeaders hh, @Context UriInfo ui) {
PersistenceContext app = get(persistenceUnit, ui.getBaseUri());
- Object id = IdHelper.buildId(app, type, ui.getQueryParameters());
+ Object id = IdHelper.buildId(app, type, key);
Object entity = app.find(getTenantId(hh), type, id);
ResponseBuilder rb = new ResponseBuilderImpl();
@@ -267,12 +324,12 @@
}
@DELETE
- @Path("{context}/entity/{type}")
- public Response delete(@PathParam("context") String persistenceUnit, @PathParam("type") String type, @Context HttpHeaders hh, @Context UriInfo ui) {
+ @Path("{context}/entity/{type}/{key}")
+ public Response delete(@PathParam("context") String persistenceUnit, @PathParam("type") String type, @PathParam("key") String key, @Context HttpHeaders hh, @Context UriInfo ui) {
ResponseBuilder rb = new ResponseBuilderImpl();
PersistenceContext app = get(persistenceUnit, ui.getBaseUri());
String tenantId = getTenantId(hh);
- Object id = IdHelper.buildId(app, type, ui.getQueryParameters());
+ Object id = IdHelper.buildId(app, type, key);
app.delete(tenantId, type, id);
rb.status(Status.OK);
return rb.build();
@@ -315,10 +372,14 @@
return new StreamingOutputMarshaller(app, result, hh.getAcceptableMediaTypes());
}
- protected void appendDescriptor(StringBuffer buffer, ClassDescriptor descriptor){
+ protected void appendDescriptor(PersistenceContext app, StringBuffer buffer, String persistenceUnit, ClassDescriptor descriptor, String baseUri){
buffer.append("{\"name\": ");
buffer.append("\"" + descriptor.getAlias() + "\"");
buffer.append(", \"type\":\"" + descriptor.getJavaClassName() + "\"");
+ buffer.append(", \"find\":\"GET " + baseUri + persistenceUnit + "/entity/" + descriptor.getAlias() + "/<primaryKey>\"");
+ buffer.append(", \"persist\":\"PUT " + baseUri + persistenceUnit + "/entity/" + descriptor.getAlias() + " payload: <entity>\"");
+ buffer.append(", \"update\":\"POST " + baseUri + persistenceUnit + "/entity/" + descriptor.getAlias() + " payload: <entity>\"");
+ buffer.append(", \"delete\":\"DELETE " + baseUri + persistenceUnit + "/entity/" + descriptor.getAlias() + "/<primaryKey>\"");
if (!descriptor.getMappings().isEmpty()){
buffer.append(", \"attributes\":[");
Iterator<DatabaseMapping> mappingIterator = descriptor.getMappings().iterator();
@@ -331,6 +392,9 @@
}
buffer.append("]");
}
+ buffer.append(", \"queries\": ");
+ appendQueries(buffer, app, descriptor.getJavaClassName());
+
buffer.append("}");
}
@@ -355,6 +419,39 @@
buffer.append("}");
}
+ protected void appendQueries(StringBuffer buffer, PersistenceContext app, String javaClassName){
+ Map<String, List<DatabaseQuery>> queries = JpaHelper.getServerSession(app.getEmf()).getQueries();
+ List<DatabaseQuery> returnQueries = new ArrayList<DatabaseQuery>();
+ for (String key: queries.keySet()){
+ List<DatabaseQuery> keyQueries = queries.get(key);
+ Iterator<DatabaseQuery> queryIterator = keyQueries.iterator();
+ while (queryIterator.hasNext()){
+ DatabaseQuery query= queryIterator.next();
+ if (javaClassName == null || query.getReferenceClassName().equals(javaClassName)){
+ returnQueries.add(query);
+ }
+ }
+ }
+ buffer.append("[");
+ Iterator<DatabaseQuery> queryIterator = returnQueries.iterator();
+ while(queryIterator.hasNext()){
+ buffer.append("{");
+ DatabaseQuery query= queryIterator.next();
+ buffer.append("\"query-name\": \"" + query.getName() + "\", ");
+ String referenceClass = query.getReferenceClassName() == null ? "" : query.getReferenceClassName();
+ buffer.append("\"reference-type\": \"" + referenceClass + "\", ");
+ String jpql = query.getJPQLString() == null? "" : query.getJPQLString();
+ buffer.append("\"jpql\": \"" + jpql + "\"");
+ System.out.println(query);
+ buffer.append("}");
+ if (queryIterator.hasNext()){
+ buffer.append(", ");
+ }
+ }
+
+ buffer.append("]");
+ }
+
@PreDestroy
public void close() {
factory.close();
diff --git a/JPA-RS/org.eclipse.persistence.jpars/src/org/eclipse/persistence/jpa/rs/util/IdHelper.java b/JPA-RS/org.eclipse.persistence.jpars/src/org/eclipse/persistence/jpa/rs/util/IdHelper.java
index 267172a..aee6125 100644
--- a/JPA-RS/org.eclipse.persistence.jpars/src/org/eclipse/persistence/jpa/rs/util/IdHelper.java
+++ b/JPA-RS/org.eclipse.persistence.jpars/src/org/eclipse/persistence/jpa/rs/util/IdHelper.java
@@ -12,7 +12,11 @@
******************************************************************************/
package org.eclipse.persistence.jpa.rs.util;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
import java.util.List;
+import java.util.StringTokenizer;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.MultivaluedMap;
@@ -37,17 +41,24 @@
*/
public class IdHelper {
- public static Object buildId(PersistenceContext app, String entityName,MultivaluedMap<String, String> multivaluedMap) {
+ public static Object buildId(PersistenceContext app, String entityName, String idString) {
Server session = JpaHelper.getServerSession(app.getEmf());
ClassDescriptor descriptor = null;
descriptor = app.getDescriptor(entityName);
List<DatabaseMapping> pkMappings = descriptor.getObjectBuilder().getPrimaryKeyMappings();
-
+ List<SortableKey> pkIndices = new ArrayList<SortableKey>();
+ int index = 0;
+ for (DatabaseMapping mapping: pkMappings){
+ pkIndices.add(new SortableKey(mapping, index));
+ index++;
+ }
+ Collections.sort(pkIndices);
+
// Handle composite key in map
int[] elementIndex = new int[pkMappings.size()];
Object[] keyElements = new Object[pkMappings.size()];
- for (int index = 0; index < pkMappings.size(); index++) {
+ /* for (int index = 0; index < pkMappings.size(); index++) {
DatabaseMapping mapping = pkMappings.get(index);
elementIndex[index] = index;
List<String> idValues = multivaluedMap.get(mapping.getAttributeName());
@@ -58,6 +69,19 @@
idValue = session.getPlatform().getConversionManager().convertObject(idValue, mapping.getAttributeClassification());
keyElements[index] = idValue;
+ }*/
+ StringTokenizer tokenizer = new StringTokenizer(idString, "+");
+ int tokens = tokenizer.countTokens();
+ if (tokens != pkMappings.size()){
+ throw new RuntimeException("Failed, incorrect number of keys values");
+ }
+ index = 0;
+ Iterator<SortableKey> iterator = pkIndices.iterator();
+ while (tokenizer.hasMoreTokens()){
+ SortableKey key = iterator.next();
+ Object idValue = session.getPlatform().getConversionManager().convertObject(tokenizer.nextToken(), key.getMapping().getAttributeClassification());
+ keyElements[key.getIndex()] = idValue;
+ index++;
}
if (descriptor.hasCMPPolicy()) {
@@ -70,4 +94,28 @@
}
return keyElements;
}
+
+ private static class SortableKey implements Comparable<SortableKey>{
+
+ private DatabaseMapping mapping;
+ private int index;
+
+ public SortableKey(DatabaseMapping mapping, int index){
+ this.mapping = mapping;
+ this.index = index;
+ }
+
+ public int compareTo(SortableKey o){
+ return mapping.getAttributeName().compareTo(o.getMapping().getAttributeName());
+ }
+
+ public DatabaseMapping getMapping(){
+ return mapping;
+ }
+
+ public int getIndex(){
+ return index;
+ }
+
+ }
}
diff --git a/JPA-RS/org.eclipse.persistence.jpars/src/org/eclipse/persistence/jpa/rs/util/LinkAdapter.java b/JPA-RS/org.eclipse.persistence.jpars/src/org/eclipse/persistence/jpa/rs/util/LinkAdapter.java
index 15a6891..ca0c484 100644
--- a/JPA-RS/org.eclipse.persistence.jpars/src/org/eclipse/persistence/jpa/rs/util/LinkAdapter.java
+++ b/JPA-RS/org.eclipse.persistence.jpars/src/org/eclipse/persistence/jpa/rs/util/LinkAdapter.java
@@ -64,7 +64,7 @@
}
String fixedString = v.replace("\\/", "/");
int lastSlash = fixedString.lastIndexOf('/');
- String entityType = fixedString.substring((baseURI + context.getName() + "/" ).length(), lastSlash);
+ String entityType = fixedString.substring((baseURI + context.getName() + "/entity/" ).length(), lastSlash);
String entityId = fixedString.substring(lastSlash + 1);
ClassDescriptor descriptor = context.getDescriptor(entityType);
DatabaseMapping idMapping = getIdMapping(descriptor);
@@ -81,6 +81,7 @@
}
}
Object id = ConversionManager.getDefaultManager().convertObject(entityId, idType);
+
return constructObjectForId(entityType, idField, id);
}
@@ -108,16 +109,12 @@
return null;
}
DynamicEntityImpl de = (DynamicEntityImpl) v;
- System.out.println("---- Trying to marshall " + de);
- System.out.println("---- Trying to marshall type " + de.getType());
- System.out.println("---- Trying to marshall type name " + de.getType().getName());
- System.out.println("---- Trying to marshall descriptor " + context.getDescriptor(de.getType().getName()));
DatabaseMapping idMapping = getIdMapping(context.getDescriptor(de.getType().getName()));
if (idMapping == null){
return "";
}
Object id = de.get(idMapping.getAttributeName());
- String href = baseURI + context.getName() + "/" + v.getClass().getSimpleName() + "/"
+ String href = baseURI + context.getName() + "/entity/" + v.getClass().getSimpleName() + "/"
+ id;
return href;
}
diff --git a/JPA-RS/org.eclipse.persistence.jpars/src/org/eclipse/persistence/jpa/rs/util/StreamingOutputMarshaller.java b/JPA-RS/org.eclipse.persistence.jpars/src/org/eclipse/persistence/jpa/rs/util/StreamingOutputMarshaller.java
index 7814185..819ce26 100644
--- a/JPA-RS/org.eclipse.persistence.jpars/src/org/eclipse/persistence/jpa/rs/util/StreamingOutputMarshaller.java
+++ b/JPA-RS/org.eclipse.persistence.jpars/src/org/eclipse/persistence/jpa/rs/util/StreamingOutputMarshaller.java
@@ -59,14 +59,7 @@
public void write(OutputStream output) throws IOException, WebApplicationException {
long millis = System.currentTimeMillis();
- System.out.println("StreamingOutputMarshaller About to write ");
- if (this.context != null && this.context.getJAXBContext() != null && this.result != null && !this.mediaType.equals(MediaType.WILDCARD_TYPE)) {
- try {
- context.marshallEntity(result, mediaType, output);
- } catch (JAXBException e) {
- throw new RuntimeException("JAXB Failure to marshal: " + this.result, e);
- }
- } else if (result instanceof byte[]){
+ if (result instanceof byte[]){
output.write((byte[])result);
} else if (result instanceof String){
OutputStreamWriter writer = new OutputStreamWriter(output);
@@ -74,6 +67,18 @@
writer.flush();
writer.close();
} else {
+ if (this.context != null && this.context.getJAXBContext() != null && this.result != null ) {
+ try {
+ context.marshallEntity(result, mediaType, output);
+ System.out.println("SteamingOutputMarshaller done write. time: " + (System.currentTimeMillis() - millis));
+ return;
+ } catch (JAXBException e) {
+ // TODO: proper warning message
+ e.printStackTrace();
+ System.out.println("WARNING, could not marshall entity, serializing. " + e.toString());
+ }
+ }
+ // could not marshall, try serializing
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(result);