You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@abdera.apache.org by jm...@apache.org on 2007/10/13 01:21:51 UTC
svn commit: r584318 - in /incubator/abdera/java/trunk/server/src:
main/java/org/apache/abdera/protocol/server/
main/java/org/apache/abdera/protocol/server/content/
test/java/org/apache/abdera/server/protocol/server/content/
Author: jmsnell
Date: Fri Oct 12 16:21:49 2007
New Revision: 584318
URL: http://svn.apache.org/viewvc?rev=584318&view=rev
Log:
Commit https://issues.apache.org/jira/browse/ABDERA-73. There was one change to FOMEntry included in the patch that I omitted from this as it did not appear to be directly relevant.
Added:
incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/content/ResponseContextException.java
Modified:
incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/HttpResponse.java
incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/content/AbstractCollectionProvider.java
incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/content/AbstractWorkspaceProvider.java
incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/content/CollectionProvider.java
incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/content/SimpleWorkspaceInfo.java
incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/content/WorkspaceInfo.java
incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/content/WorkspaceProvider.java
incubator/abdera/java/trunk/server/src/test/java/org/apache/abdera/server/protocol/server/content/ContentProviderTest.java
incubator/abdera/java/trunk/server/src/test/java/org/apache/abdera/server/protocol/server/content/CustomerContentProvider.java
Modified: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/HttpResponse.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/HttpResponse.java?rev=584318&r1=584317&r2=584318&view=diff
==============================================================================
--- incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/HttpResponse.java (original)
+++ incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/HttpResponse.java Fri Oct 12 16:21:49 2007
@@ -1,3 +1,20 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements. 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. For additional information regarding
+* copyright in this work, please see the NOTICE file in the top level
+* directory of this distribution.
+*/
package org.apache.abdera.protocol.server;
import java.io.IOException;
Modified: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/content/AbstractCollectionProvider.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/content/AbstractCollectionProvider.java?rev=584318&r1=584317&r2=584318&view=diff
==============================================================================
--- incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/content/AbstractCollectionProvider.java (original)
+++ incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/content/AbstractCollectionProvider.java Fri Oct 12 16:21:49 2007
@@ -1,3 +1,20 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements. 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. For additional information regarding
+* copyright in this work, please see the NOTICE file in the top level
+* directory of this distribution.
+*/
package org.apache.abdera.protocol.server.content;
import java.io.IOException;
@@ -14,6 +31,7 @@
import org.apache.abdera.model.Document;
import org.apache.abdera.model.Entry;
import org.apache.abdera.model.Feed;
+import org.apache.abdera.model.Text;
import org.apache.abdera.parser.ParseException;
import org.apache.abdera.parser.Parser;
import org.apache.abdera.protocol.server.RequestContext;
@@ -25,10 +43,13 @@
import org.apache.abdera.protocol.server.impl.ProviderSupport;
import org.apache.abdera.util.EntityTag;
import org.apache.abdera.util.MimeTypeHelper;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
public abstract class AbstractCollectionProvider<T> extends ProviderSupport
implements CollectionProvider<T> {
-
+ private final static Log log = LogFactory.getLog(AbstractCollectionProvider.class);
+
private String baseMediaIri = "media/";
public ResponseContext createEntry(RequestContext request) {
@@ -53,9 +74,9 @@
return ctype != null && !MimeTypeHelper.isAtom(ctype) /*&& !MimeTypeHelper.isXml(ctype)*/;
}
- public abstract T createEntry(String title, String summary, Content content);
+ public abstract T createEntry(String title, String summary, Content content) throws ResponseContextException;
- public T createMediaEntry(MimeType mimeType, String slug, InputStream inputStream) {
+ public T createMediaEntry(MimeType mimeType, String slug, InputStream inputStream) throws ResponseContextException {
throw new UnsupportedOperationException();
}
@@ -63,8 +84,12 @@
String id = getEntryID(request);
if (id != null) {
- deleteEntry(id);
-
+ try {
+ deleteEntry(id);
+ } catch (ResponseContextException e) {
+ return createErrorResponse(e);
+ }
+
return new EmptyResponseContext(204);
} else {
// TODO: is this right?
@@ -72,15 +97,15 @@
}
}
- public abstract void deleteEntry(String resourceName);
+ public abstract void deleteEntry(String resourceName) throws ResponseContextException;
- public abstract String getAuthor();
+ public abstract String getAuthor() throws ResponseContextException;
public String getBaseMediaIri() {
return baseMediaIri;
}
- public abstract Object getContent(T entry);
+ public abstract Object getContent(T entry) throws ResponseContextException;
// GET, POST, PUT, DELETE
@@ -88,31 +113,35 @@
throw new UnsupportedOperationException();
}
- public abstract Iterable<T> getEntries();
+ public abstract Iterable<T> getEntries() throws ResponseContextException;
public ResponseContext getEntry(RequestContext request, IRI entryBaseIri) {
- Entry entry = getEntryFromCollectionProvider(entryBaseIri,
- request);
- if (entry != null) {
- Feed feed = createDocumentsFeed(request.getAbdera());
- entry.setSource(feed.getAsSource());
- Document<Entry> entry_doc = entry.getDocument();
- AbstractResponseContext rc = new BaseResponseContext<Document<Entry>>(entry_doc);
- rc.setEntityTag(calculateEntityTag(entry));
- return rc;
- } else {
- return new EmptyResponseContext(404);
+ try {
+ Entry entry = getEntryFromCollectionProvider(entryBaseIri,
+ request);
+ if (entry != null) {
+ Feed feed = createFeed(request.getAbdera());
+ entry.setSource(feed.getAsSource());
+ Document<Entry> entry_doc = entry.getDocument();
+ AbstractResponseContext rc = new BaseResponseContext<Document<Entry>>(entry_doc);
+ rc.setEntityTag(calculateEntityTag(entry));
+ return rc;
+ } else {
+ return new EmptyResponseContext(404);
+ }
+ } catch (ResponseContextException e) {
+ return createErrorResponse(e);
}
}
- public abstract T getEntry(String resourceName);
+ public abstract T getEntry(String resourceName) throws ResponseContextException;
- public abstract T getEntryFromId(String id);
+ public abstract T getEntryFromId(String id) throws ResponseContextException;
public ResponseContext getFeed(RequestContext request) {
Abdera abdera = request.getAbdera();
- Feed feed = createDocumentsFeed(abdera);
+ Feed feed = createFeed(abdera);
return getFeed(request, feed);
}
@@ -120,26 +149,60 @@
public ResponseContext getFeed(RequestContext request, Feed feed) {
feed.setUpdated(new Date());
- for (T entryObj : getEntries()) {
- Entry e = feed.addEntry();
+ IRI baseIri = resolveBase(request);
+ IRI entryIri = getEntryBaseFromFeedIRI(baseIri);
+
+ try {
+ Iterable<T> entries = getEntries();
+ if (entries != null) {
+ for (T entryObj : entries) {
+ Entry e = feed.addEntry();
+
+ addEntryDetails(request, e, entryIri, entryObj);
- addEntryDetails(request, e, resolveBase(request), entryObj);
- addContent(e, entryObj);
+ if (isMediaEntry(entryObj)) {
+ addMediaContent(entryIri, e, entryObj);
+ } else {
+ addContent(e, entryObj);
+ }
+ }
+ }
+
+ Document<Feed> document = feed.getDocument();
+ AbstractResponseContext rc = new BaseResponseContext<Document<Feed>>(document);
+ rc.setEntityTag(calculateEntityTag(document.getRoot()));
+ return rc;
+ } catch (ResponseContextException e) {
+ return createErrorResponse(e);
}
+
+ }
- Document<Feed> document = feed.getDocument();
- AbstractResponseContext rc = new BaseResponseContext<Document<Feed>>(document);
- rc.setEntityTag(calculateEntityTag(document.getRoot()));
- return rc;
+ /**
+ * Create a ResponseContext (or take it from the Exception) for an
+ * exception that occurred in the application.
+ * @param e
+ * @return
+ */
+ protected ResponseContext createErrorResponse(ResponseContextException e) {
+ if (log.isDebugEnabled()) {
+ log.debug("A ResponseException was thrown.", e);
+ } else if (e.getResponseContext() instanceof EmptyResponseContext
+ && ((EmptyResponseContext) e.getResponseContext()).getStatus() >= 500) {
+ log.warn("A ResponseException was thrown.", e);
+ }
+
+ return e.getResponseContext();
}
public abstract String getId();
+
/**
* Gets the UUID for the specified entry.
* @param entry
* @return
*/
- public abstract String getId(T entry);
+ public abstract String getId(T entry) throws ResponseContextException;
public ResponseContext getMedia(RequestContext request) {
try {
@@ -172,13 +235,13 @@
throw new UnsupportedOperationException();
}
- public abstract String getName(T entry);
+ public abstract String getName(T entry) throws ResponseContextException;
public abstract String getTitle();
- public abstract String getTitle(T entry);
+ public abstract String getTitle(T entry) throws ResponseContextException;
- public abstract Date getUpdated(T entry);
+ public abstract Date getUpdated(T entry) throws ResponseContextException;
public boolean isMediaEntry(T entry) {
return false;
@@ -190,9 +253,10 @@
public ResponseContext updateEntry(RequestContext request, IRI feedUri) {
Abdera abdera = request.getAbdera();
- Entry orig_entry = getEntryFromCollectionProvider(feedUri, request);
- if (orig_entry != null) {
- try {
+ try {
+ Entry orig_entry = getEntryFromCollectionProvider(feedUri, request);
+ if (orig_entry != null) {
+
MimeType contentType = request.getContentType();
if (contentType != null && !MimeTypeHelper.isAtom(contentType.toString()))
return new EmptyResponseContext(415);
@@ -212,28 +276,31 @@
// entryObjProvider.updateEntry(entry)
- Feed feed = createDocumentsFeed(abdera);
+ Feed feed = createFeed(abdera);
feed.insertEntry(entry);
feed.setUpdated(new Date());
return new EmptyResponseContext(204);
} else {
return new EmptyResponseContext(400);
}
- } catch (ParseException pe) {
- return new EmptyResponseContext(415);
- } catch (ClassCastException cce) {
- return new EmptyResponseContext(415);
- } catch (Exception e) {
- return new EmptyResponseContext(400);
+ } else {
+ return new EmptyResponseContext(404);
}
- } else {
- return new EmptyResponseContext(404);
+ } catch (ResponseContextException e) {
+ return createErrorResponse(e);
+ } catch (ParseException pe) {
+ return new EmptyResponseContext(415);
+ } catch (ClassCastException cce) {
+ return new EmptyResponseContext(415);
+ } catch (Exception e) {
+ return new EmptyResponseContext(400);
}
+
}
public abstract T updateEntry(T entry, Content content);
- protected void addContent(Entry e, T doc) {
+ protected void addContent(Entry e, T doc) throws ResponseContextException {
Object content = getContent(doc);
if (content instanceof Content) {
@@ -244,12 +311,20 @@
}
protected void addEntryDetails(RequestContext request, Entry e,
- IRI entryBaseIri, T entryObj) {
+ IRI entryBaseIri, T entryObj) throws ResponseContextException {
IRI entryIri = entryBaseIri.resolve(getName(entryObj));
- e.addLink(entryIri.toString(), "edit");
+ e.addLink(entryIri.toASCIIString(), "edit");
e.setId(getId(entryObj));
e.setTitle(getTitle(entryObj));
e.setUpdated(getUpdated(entryObj));
+ Text t = getSummary(entryObj);
+ if (t != null) {
+ e.setSummaryElement(t);
+ }
+ }
+
+ public Text getSummary(T entry) {
+ return null;
}
protected void addMediaContent(IRI entryBaseIri, Entry entry, T doc) {
@@ -258,7 +333,7 @@
mediaIri = entryBaseIri.resolve(mediaIri);
entry.setContent(mediaIri, getContentType(doc));
- entry.addLink(mediaIri.toString(), "edit-media");
+ entry.addLink(mediaIri.toASCIIString(), "edit-media");
}
protected EntityTag calculateEntityTag(Base base) {
@@ -273,7 +348,7 @@
}
return EntityTag.generate(id, modified);
}
- protected Feed createDocumentsFeed(Abdera abdera) {
+ protected Feed createFeed(Abdera abdera) {
Factory factory = abdera.getFactory();
Feed feed = factory.newFeed();
try {
@@ -308,6 +383,8 @@
return rc;
} catch (IOException e) {
return new EmptyResponseContext(500);
+ } catch (ResponseContextException e) {
+ return createErrorResponse(e);
}
}
@@ -320,31 +397,35 @@
entry.setUpdated(new Date());
- T entryObj = createEntry(entry.getTitle(), entry.getSummary(),
- entry.getContentElement());
- entry.getIdElement().setValue(getId(entryObj));
-
- IRI entryBaseUri = getEntryBaseFromFeedIRI(resolveBase(request));
+ try {
+ T entryObj = createEntry(entry.getTitle(), entry.getSummary(),
+ entry.getContentElement());
+ entry.getIdElement().setValue(getId(entryObj));
- IRI entryIri = entryBaseUri.resolve(getName(entryObj));
- entry.addLink(entryIri.toString(), "edit");
-
- BaseResponseContext<Entry> rc = new BaseResponseContext<Entry>(entry);
- rc.setLocation(entryIri.resolve(entry.getEditLinkResolvedHref()).toString());
- rc.setContentLocation(rc.getLocation().toString());
- rc.setEntityTag(calculateEntityTag(entry));
- rc.setStatus(201);
- return rc;
+ IRI entryBaseUri = getEntryBaseFromFeedIRI(resolveBase(request));
+
+ IRI entryIri = entryBaseUri.resolve(getName(entryObj));
+ entry.addLink(entryIri.toASCIIString(), "edit");
+
+ BaseResponseContext<Entry> rc = new BaseResponseContext<Entry>(entry);
+ rc.setLocation(entryIri.resolve(entry.getEditLinkResolvedHref()).toString());
+ rc.setContentLocation(rc.getLocation().toString());
+ rc.setEntityTag(calculateEntityTag(entry));
+ rc.setStatus(201);
+ return rc;
+ } catch (ResponseContextException e) {
+ return createErrorResponse(e);
+ }
} else {
return new EmptyResponseContext(400);
}
}
protected IRI getEntryBaseFromFeedIRI(IRI baseIri) {
- return new IRI(baseIri + "/");
+ return new IRI(baseIri.toASCIIString() + "/");
}
- protected Entry getEntryFromCollectionProvider(IRI feedIri, RequestContext request) {
+ protected Entry getEntryFromCollectionProvider(IRI feedIri, RequestContext request) throws ResponseContextException {
String id = getEntryID(request);
T entryObj = getEntry(id);
Modified: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/content/AbstractWorkspaceProvider.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/content/AbstractWorkspaceProvider.java?rev=584318&r1=584317&r2=584318&view=diff
==============================================================================
--- incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/content/AbstractWorkspaceProvider.java (original)
+++ incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/content/AbstractWorkspaceProvider.java Fri Oct 12 16:21:49 2007
@@ -1,10 +1,30 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements. 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. For additional information regarding
+* copyright in this work, please see the NOTICE file in the top level
+* directory of this distribution.
+*/
package org.apache.abdera.protocol.server.content;
+import java.io.UnsupportedEncodingException;
import java.util.Map;
import java.util.Set;
import org.apache.abdera.Abdera;
import org.apache.abdera.factory.Factory;
+import org.apache.abdera.i18n.iri.Constants;
+import org.apache.abdera.i18n.iri.Escaping;
import org.apache.abdera.i18n.iri.IRI;
import org.apache.abdera.model.Collection;
import org.apache.abdera.model.Document;
@@ -15,10 +35,14 @@
import org.apache.abdera.protocol.server.impl.AbstractProvider;
import org.apache.abdera.protocol.server.impl.AbstractResponseContext;
import org.apache.abdera.protocol.server.impl.BaseResponseContext;
+import org.apache.abdera.protocol.server.impl.EmptyResponseContext;
import org.apache.abdera.util.EntityTag;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
public abstract class AbstractWorkspaceProvider extends AbstractProvider {
-
+ private final static Log log = LogFactory.getLog(AbstractWorkspaceProvider.class);
+
private EntityTag service_etag = new EntityTag("simple");
protected AbstractWorkspaceProvider(int count) {
@@ -27,14 +51,22 @@
public ResponseContext getService(RequestContext request) {
Abdera abdera = request.getAbdera();
- Document<Service> service = getServicesDocument(abdera);
+ Document<Service> service = getServicesDocument(abdera, getEncoding(request));
AbstractResponseContext rc = new BaseResponseContext<Document<Service>>(service);
rc.setEntityTag(service_etag);
return rc;
}
+ private String getEncoding(RequestContext request) {
+ return "utf-8";
+ }
+
@SuppressWarnings("unchecked")
- private Document<Service> getServicesDocument(Abdera abdera) {
+ private Document<Service> getServicesDocument(Abdera abdera, String enc) {
+ if (enc == null) {
+ enc = "utf-8";
+ }
+
Factory factory = abdera.getFactory();
Service service = factory.newService();
for (WorkspaceInfo wp : getWorkspaces()) {
@@ -43,8 +75,17 @@
(Set<Map.Entry<String, CollectionProvider>>) (wp.getCollectionProviders().entrySet());
for (Map.Entry<String, CollectionProvider> entry : entrySet) {
CollectionProvider<?> cp = entry.getValue();
+
+ String id;
+ String workspaceKey;
+ try {
+ id = Escaping.encode(wp.getId(), enc, Constants.PATH);
+ workspaceKey = Escaping.encode(entry.getKey(), enc, Constants.PATH);
+ } catch (UnsupportedEncodingException e) {
+ throw new RuntimeException(e);
+ }
Collection collection = workspace.addCollection(cp.getTitle(),
- wp.getId() + "/" + entry.getKey());
+ id + "/" + workspaceKey);
collection.setAccept("entry");
// collection.addCategories().setFixed(false);
}
@@ -55,14 +96,18 @@
public abstract java.util.Collection<WorkspaceInfo> getWorkspaces();
public ResponseContext getFeed(RequestContext request) {
- CollectionProvider provider = getCollectionProvider(resolveBase(request), request);
-
- return provider.getFeed(request);
+ try {
+ CollectionProvider provider = getCollectionProvider(resolveBase(request), request);
+
+ return provider.getFeed(request);
+ } catch (ResponseContextException e) {
+ return createErrorResponse(e);
+ }
}
@SuppressWarnings("unchecked")
private <T> CollectionProvider<T> getCollectionProvider(IRI resolveBase,
- RequestContext request) {
+ RequestContext request) throws ResponseContextException {
String path = resolveBase.getPath();
String[] paths = path.split("/");
if (paths.length < 1) {
@@ -85,20 +130,44 @@
}
}
+ /**
+ * Create a ResponseContext (or take it from the Exception) for an
+ * exception that occurred in the application.
+ * @param e
+ * @return
+ */
+ protected ResponseContext createErrorResponse(ResponseContextException e) {
+ if (log.isDebugEnabled()) {
+ log.debug("A ResponseException was thrown.", e);
+ } else if (e.getResponseContext() instanceof EmptyResponseContext
+ && ((EmptyResponseContext) e.getResponseContext()).getStatus() >= 500) {
+ log.warn("A ResponseException was thrown.", e);
+ }
+
+ return e.getResponseContext();
+ }
protected abstract WorkspaceInfo<?> getWorkspaceInfo(String string);
public ResponseContext createEntry(RequestContext request) {
- CollectionProvider provider = getCollectionProvider(request.getUri(), request);
-
- return provider.createEntry(request);
+ try {
+ CollectionProvider provider = getCollectionProvider(request.getUri(), request);
+
+ return provider.createEntry(request);
+ } catch (ResponseContextException e) {
+ return createErrorResponse(e);
+ }
}
@Override
public ResponseContext getMedia(RequestContext request) {
- IRI entryBaseIri = resolveBase(request).resolve("../");
- CollectionProvider provider = getCollectionProvider(entryBaseIri, request);
-
- return provider.getMedia(request);
+ try {
+ IRI entryBaseIri = resolveBase(request).resolve("../");
+ CollectionProvider provider = getCollectionProvider(entryBaseIri, request);
+
+ return provider.getMedia(request);
+ } catch (ResponseContextException e) {
+ return createErrorResponse(e);
+ }
}
@@ -109,25 +178,37 @@
}
public ResponseContext deleteEntry(RequestContext request) {
- CollectionProvider<?> provider = getCollectionProvider(resolveBase(request).resolve("./"), request);
-
- return provider.deleteEntry(request);
+ try {
+ CollectionProvider<?> provider = getCollectionProvider(resolveBase(request).resolve("./"), request);
+
+ return provider.deleteEntry(request);
+ } catch (ResponseContextException e) {
+ return createErrorResponse(e);
+ }
}
public ResponseContext getEntry(RequestContext request) {
- IRI entryBaseIri = resolveBase(request).resolve("./");
- CollectionProvider provider = getCollectionProvider(entryBaseIri, request);
-
- return provider.getEntry(request, entryBaseIri);
+ try {
+ IRI entryBaseIri = resolveBase(request).resolve("./");
+ CollectionProvider provider = getCollectionProvider(entryBaseIri, request);
+
+ return provider.getEntry(request, entryBaseIri);
+ } catch (ResponseContextException e) {
+ return createErrorResponse(e);
+ }
}
@SuppressWarnings("unchecked")
public ResponseContext updateEntry(RequestContext request) {
- IRI entryBaseIri = resolveBase(request).resolve("./");
- CollectionProvider provider = getCollectionProvider(entryBaseIri, request);
-
- return provider.updateEntry(request, entryBaseIri);
+ try {
+ IRI entryBaseIri = resolveBase(request).resolve("./");
+ CollectionProvider provider = getCollectionProvider(entryBaseIri, request);
+
+ return provider.updateEntry(request, entryBaseIri);
+ } catch (ResponseContextException e) {
+ return createErrorResponse(e);
+ }
}
Modified: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/content/CollectionProvider.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/content/CollectionProvider.java?rev=584318&r1=584317&r2=584318&view=diff
==============================================================================
--- incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/content/CollectionProvider.java (original)
+++ incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/content/CollectionProvider.java Fri Oct 12 16:21:49 2007
@@ -1,3 +1,20 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements. 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. For additional information regarding
+* copyright in this work, please see the NOTICE file in the top level
+* directory of this distribution.
+*/
package org.apache.abdera.protocol.server.content;
import java.io.InputStream;
Added: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/content/ResponseContextException.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/content/ResponseContextException.java?rev=584318&view=auto
==============================================================================
--- incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/content/ResponseContextException.java (added)
+++ incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/content/ResponseContextException.java Fri Oct 12 16:21:49 2007
@@ -0,0 +1,47 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements. 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. For additional information regarding
+* copyright in this work, please see the NOTICE file in the top level
+* directory of this distribution.
+*/
+package org.apache.abdera.protocol.server.content;
+
+import org.apache.abdera.protocol.server.impl.AbstractResponseContext;
+import org.apache.abdera.protocol.server.impl.EmptyResponseContext;
+
+public class ResponseContextException extends Exception {
+ private AbstractResponseContext responseContext;
+
+ public ResponseContextException(AbstractResponseContext responseContext, Throwable t) {
+ super(t);
+ this.responseContext = responseContext;
+ }
+
+ public ResponseContextException(AbstractResponseContext responseContext) {
+ super();
+ this.responseContext = responseContext;
+ }
+
+ public ResponseContextException(int responseCode) {
+ this(new EmptyResponseContext(responseCode));
+ }
+
+ public ResponseContextException(int responseCode, Throwable t) {
+ this(new EmptyResponseContext(responseCode), t);
+ }
+
+ public AbstractResponseContext getResponseContext() {
+ return responseContext;
+ }
+}
Modified: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/content/SimpleWorkspaceInfo.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/content/SimpleWorkspaceInfo.java?rev=584318&r1=584317&r2=584318&view=diff
==============================================================================
--- incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/content/SimpleWorkspaceInfo.java (original)
+++ incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/content/SimpleWorkspaceInfo.java Fri Oct 12 16:21:49 2007
@@ -1,3 +1,20 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements. 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. For additional information regarding
+* copyright in this work, please see the NOTICE file in the top level
+* directory of this distribution.
+*/
package org.apache.abdera.protocol.server.content;
import java.util.Collection;
Modified: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/content/WorkspaceInfo.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/content/WorkspaceInfo.java?rev=584318&r1=584317&r2=584318&view=diff
==============================================================================
--- incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/content/WorkspaceInfo.java (original)
+++ incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/content/WorkspaceInfo.java Fri Oct 12 16:21:49 2007
@@ -1,3 +1,20 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements. 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. For additional information regarding
+* copyright in this work, please see the NOTICE file in the top level
+* directory of this distribution.
+*/
package org.apache.abdera.protocol.server.content;
import java.util.Map;
@@ -10,6 +27,6 @@
Map<String, CollectionProvider<T>> getCollectionProviders();
- CollectionProvider<T> getCollectionProvider(String id);
+ CollectionProvider<T> getCollectionProvider(String id) throws ResponseContextException;
}
Modified: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/content/WorkspaceProvider.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/content/WorkspaceProvider.java?rev=584318&r1=584317&r2=584318&view=diff
==============================================================================
--- incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/content/WorkspaceProvider.java (original)
+++ incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/content/WorkspaceProvider.java Fri Oct 12 16:21:49 2007
@@ -1,3 +1,20 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements. 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. For additional information regarding
+* copyright in this work, please see the NOTICE file in the top level
+* directory of this distribution.
+*/
package org.apache.abdera.protocol.server.content;
import java.util.Collection;
Modified: incubator/abdera/java/trunk/server/src/test/java/org/apache/abdera/server/protocol/server/content/ContentProviderTest.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/test/java/org/apache/abdera/server/protocol/server/content/ContentProviderTest.java?rev=584318&r1=584317&r2=584318&view=diff
==============================================================================
--- incubator/abdera/java/trunk/server/src/test/java/org/apache/abdera/server/protocol/server/content/ContentProviderTest.java (original)
+++ incubator/abdera/java/trunk/server/src/test/java/org/apache/abdera/server/protocol/server/content/ContentProviderTest.java Fri Oct 12 16:21:49 2007
@@ -113,6 +113,8 @@
org.apache.abdera.model.Document<Entry> entry_doc = res.getDocument();
entry = entry_doc.getRoot();
+ res = client.get(colUri + "/foobar");
+ assertEquals(404, res.getStatus());
}
private void prettyPrint(Abdera abdera, Base doc) throws IOException {
Modified: incubator/abdera/java/trunk/server/src/test/java/org/apache/abdera/server/protocol/server/content/CustomerContentProvider.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/test/java/org/apache/abdera/server/protocol/server/content/CustomerContentProvider.java?rev=584318&r1=584317&r2=584318&view=diff
==============================================================================
--- incubator/abdera/java/trunk/server/src/test/java/org/apache/abdera/server/protocol/server/content/CustomerContentProvider.java (original)
+++ incubator/abdera/java/trunk/server/src/test/java/org/apache/abdera/server/protocol/server/content/CustomerContentProvider.java Fri Oct 12 16:21:49 2007
@@ -12,6 +12,7 @@
import org.apache.abdera.model.Content;
import org.apache.abdera.model.Element;
import org.apache.abdera.protocol.server.content.AbstractCollectionProvider;
+import org.apache.abdera.protocol.server.content.ResponseContextException;
import sun.security.pkcs.ContentInfo;
public class CustomerContentProvider extends AbstractCollectionProvider<Customer> {
@@ -45,7 +46,7 @@
return customer;
}
- public void deleteEntry(String resourceName) {
+ public void deleteEntry(String resourceName) throws ResponseContextException {
Integer id = getIdFromResourceName(resourceName);
customers.remove(id);
}
@@ -67,15 +68,15 @@
return customers.values();
}
- public Customer getEntry(String resourceName) {
+ public Customer getEntry(String resourceName) throws ResponseContextException {
Integer id = getIdFromResourceName(resourceName);
return customers.get(id);
}
- private Integer getIdFromResourceName(String resourceName) {
+ private Integer getIdFromResourceName(String resourceName) throws ResponseContextException {
int idx = resourceName.indexOf("-");
if (idx == -1) {
- // TODO: exception handling for 404 Not found
+ throw new ResponseContextException(404);
}
Integer id = new Integer(resourceName.substring(0, idx));
return id;
Re: FOMEntry & IRI encoding [was Re: svn commit: r584318 - ..]
Posted by James M Snell <ja...@gmail.com>.
It was mainly just separating concerns a bit... I can apply this one
separately, I just didn't want to bundle it in with the rest of the
patch since they did not seem to be related.
- James
Dan Diephouse wrote:
> jmsnell@apache.org wrote:
>> Author: jmsnell
>> Date: Fri Oct 12 16:21:49 2007
>> New Revision: 584318
>>
>> URL: http://svn.apache.org/viewvc?rev=584318&view=rev
>> Log:
>> Commit https://issues.apache.org/jira/browse/ABDERA-73. There was one
>> change to FOMEntry included in the patch that I omitted from this as
>> it did not appear to be directly relevant.
>>
>>
> Hi James, thanks for applying my patch!
>
> Was there anything wrong with this change:
>
> Index: parser/src/main/java/org/apache/abdera/parser/stax/FOMEntry.java
> ===================================================================
> --- parser/src/main/java/org/apache/abdera/parser/stax/FOMEntry.java
> (revision 584433)
> +++ parser/src/main/java/org/apache/abdera/parser/stax/FOMEntry.java
> (working copy)
> @@ -313,7 +313,7 @@
> try {
> FOMFactory factory = (FOMFactory) this.factory;
> Content content = factory.newContent(new MimeType(mediatype));
> - content.setSrc(uri.toString());
> + content.setSrc(uri.toASCIIString());
> setContentElement(content);
> return content;
> } catch (javax.activation.MimeTypeParseException e) {
>
> My application doesn't work correctly without it because my IRI has
> spaces in it sometimes. Since we're converting it to a String for the
> <content> element we need to encode these characters.
>
> - Dan
>
Re: FOMEntry & IRI encoding [was Re: svn commit: r584318 - ..]
Posted by James M Snell <ja...@gmail.com>.
Can you post a test case to jira? I'll see if I can tweak IRI to
produce the right results.
- James
Dan Diephouse wrote:
> OK, thanks. Is there some type of temporary fix we could do? Like encode
> the toString() output manually in that method?
>
> - Dan
>
> James M Snell wrote:
>> Dan, after reviewing this further, I do not think this patch is a good
>> idea. Atom explicitly allows documents to contain IRI's, which means
>> applications using Abdera should not have to be forced to use the
>> converted URI form in the @src attribute. The correct fix would be to
>> make sure that the toString() method returns the appropriate results
>> instead of forcing the results to the ASCII URI form.
>>
>> - James
>>
>> Dan Diephouse wrote:
>>
>>> jmsnell@apache.org wrote:
>>>
>>>> Author: jmsnell
>>>> Date: Fri Oct 12 16:21:49 2007
>>>> New Revision: 584318
>>>>
>>>> URL: http://svn.apache.org/viewvc?rev=584318&view=rev
>>>> Log:
>>>> Commit https://issues.apache.org/jira/browse/ABDERA-73. There was one
>>>> change to FOMEntry included in the patch that I omitted from this as
>>>> it did not appear to be directly relevant.
>>>>
>>>>
>>> Hi James, thanks for applying my patch!
>>>
>>> Was there anything wrong with this change:
>>>
>>> Index: parser/src/main/java/org/apache/abdera/parser/stax/FOMEntry.java
>>> ===================================================================
>>> ---
>>> parser/src/main/java/org/apache/abdera/parser/stax/FOMEntry.java
>>> (revision 584433)
>>> +++
>>> parser/src/main/java/org/apache/abdera/parser/stax/FOMEntry.java
>>> (working copy)
>>> @@ -313,7 +313,7 @@
>>> try {
>>> FOMFactory factory = (FOMFactory) this.factory;
>>> Content content = factory.newContent(new MimeType(mediatype));
>>> - content.setSrc(uri.toString());
>>> + content.setSrc(uri.toASCIIString());
>>> setContentElement(content);
>>> return content;
>>> } catch (javax.activation.MimeTypeParseException e) {
>>>
>>> My application doesn't work correctly without it because my IRI has
>>> spaces in it sometimes. Since we're converting it to a String for the
>>> <content> element we need to encode these characters.
>>>
>>> - Dan
>>>
>>>
>
>
Re: FOMEntry & IRI encoding [was Re: svn commit: r584318 - ..]
Posted by Dan Diephouse <da...@mulesource.com>.
OK, thanks. Is there some type of temporary fix we could do? Like encode
the toString() output manually in that method?
- Dan
James M Snell wrote:
> Dan, after reviewing this further, I do not think this patch is a good
> idea. Atom explicitly allows documents to contain IRI's, which means
> applications using Abdera should not have to be forced to use the
> converted URI form in the @src attribute. The correct fix would be to
> make sure that the toString() method returns the appropriate results
> instead of forcing the results to the ASCII URI form.
>
> - James
>
> Dan Diephouse wrote:
>
>> jmsnell@apache.org wrote:
>>
>>> Author: jmsnell
>>> Date: Fri Oct 12 16:21:49 2007
>>> New Revision: 584318
>>>
>>> URL: http://svn.apache.org/viewvc?rev=584318&view=rev
>>> Log:
>>> Commit https://issues.apache.org/jira/browse/ABDERA-73. There was one
>>> change to FOMEntry included in the patch that I omitted from this as
>>> it did not appear to be directly relevant.
>>>
>>>
>>>
>> Hi James, thanks for applying my patch!
>>
>> Was there anything wrong with this change:
>>
>> Index: parser/src/main/java/org/apache/abdera/parser/stax/FOMEntry.java
>> ===================================================================
>> --- parser/src/main/java/org/apache/abdera/parser/stax/FOMEntry.java
>> (revision 584433)
>> +++ parser/src/main/java/org/apache/abdera/parser/stax/FOMEntry.java
>> (working copy)
>> @@ -313,7 +313,7 @@
>> try {
>> FOMFactory factory = (FOMFactory) this.factory;
>> Content content = factory.newContent(new MimeType(mediatype));
>> - content.setSrc(uri.toString());
>> + content.setSrc(uri.toASCIIString());
>> setContentElement(content);
>> return content;
>> } catch (javax.activation.MimeTypeParseException e) {
>>
>> My application doesn't work correctly without it because my IRI has
>> spaces in it sometimes. Since we're converting it to a String for the
>> <content> element we need to encode these characters.
>>
>> - Dan
>>
>>
--
Dan Diephouse
MuleSource
http://mulesource.com | http://netzooid.com/blog
Re: FOMEntry & IRI encoding [was Re: svn commit: r584318 - ..]
Posted by James M Snell <ja...@gmail.com>.
Dan, after reviewing this further, I do not think this patch is a good
idea. Atom explicitly allows documents to contain IRI's, which means
applications using Abdera should not have to be forced to use the
converted URI form in the @src attribute. The correct fix would be to
make sure that the toString() method returns the appropriate results
instead of forcing the results to the ASCII URI form.
- James
Dan Diephouse wrote:
> jmsnell@apache.org wrote:
>> Author: jmsnell
>> Date: Fri Oct 12 16:21:49 2007
>> New Revision: 584318
>>
>> URL: http://svn.apache.org/viewvc?rev=584318&view=rev
>> Log:
>> Commit https://issues.apache.org/jira/browse/ABDERA-73. There was one
>> change to FOMEntry included in the patch that I omitted from this as
>> it did not appear to be directly relevant.
>>
>>
> Hi James, thanks for applying my patch!
>
> Was there anything wrong with this change:
>
> Index: parser/src/main/java/org/apache/abdera/parser/stax/FOMEntry.java
> ===================================================================
> --- parser/src/main/java/org/apache/abdera/parser/stax/FOMEntry.java
> (revision 584433)
> +++ parser/src/main/java/org/apache/abdera/parser/stax/FOMEntry.java
> (working copy)
> @@ -313,7 +313,7 @@
> try {
> FOMFactory factory = (FOMFactory) this.factory;
> Content content = factory.newContent(new MimeType(mediatype));
> - content.setSrc(uri.toString());
> + content.setSrc(uri.toASCIIString());
> setContentElement(content);
> return content;
> } catch (javax.activation.MimeTypeParseException e) {
>
> My application doesn't work correctly without it because my IRI has
> spaces in it sometimes. Since we're converting it to a String for the
> <content> element we need to encode these characters.
>
> - Dan
>
FOMEntry & IRI encoding [was Re: svn commit: r584318 - ..]
Posted by Dan Diephouse <da...@mulesource.com>.
jmsnell@apache.org wrote:
> Author: jmsnell
> Date: Fri Oct 12 16:21:49 2007
> New Revision: 584318
>
> URL: http://svn.apache.org/viewvc?rev=584318&view=rev
> Log:
> Commit https://issues.apache.org/jira/browse/ABDERA-73. There was one change to FOMEntry included in the patch that I omitted from this as it did not appear to be directly relevant.
>
>
Hi James, thanks for applying my patch!
Was there anything wrong with this change:
Index: parser/src/main/java/org/apache/abdera/parser/stax/FOMEntry.java
===================================================================
--- parser/src/main/java/org/apache/abdera/parser/stax/FOMEntry.java
(revision 584433)
+++ parser/src/main/java/org/apache/abdera/parser/stax/FOMEntry.java
(working copy)
@@ -313,7 +313,7 @@
try {
FOMFactory factory = (FOMFactory) this.factory;
Content content = factory.newContent(new MimeType(mediatype));
- content.setSrc(uri.toString());
+ content.setSrc(uri.toASCIIString());
setContentElement(content);
return content;
} catch (javax.activation.MimeTypeParseException e) {
My application doesn't work correctly without it because my IRI has
spaces in it sometimes. Since we're converting it to a String for the
<content> element we need to encode these characters.
- Dan
--
Dan Diephouse
MuleSource
http://mulesource.com | http://netzooid.com/blog