You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@chemistry.apache.org by dc...@apache.org on 2010/04/22 18:28:00 UTC
svn commit: r936938 [3/29] - in
/incubator/chemistry/opencmis/trunk/chemistry-opencmis-server:
chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/
chemistry-opencmis-server-bindings/src/main/java/org/apache/chemi...
Modified: incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/CmisAtomPubServlet.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/CmisAtomPubServlet.java?rev=936938&r1=936937&r2=936938&view=diff
==============================================================================
--- incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/CmisAtomPubServlet.java (original)
+++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/CmisAtomPubServlet.java Thu Apr 22 16:27:57 2010
@@ -57,264 +57,264 @@ import org.apache.commons.logging.LogFac
*/
public class CmisAtomPubServlet extends HttpServlet {
- private static final long serialVersionUID = 1L;
+ private static final long serialVersionUID = 1L;
- private static final String PARAM_CALL_CONTEXT_HANDLER = "callContextHandler";
+ private static final String PARAM_CALL_CONTEXT_HANDLER = "callContextHandler";
- private static final String METHOD_GET = "GET";
- private static final String METHOD_POST = "POST";
- private static final String METHOD_PUT = "PUT";
- private static final String METHOD_DELETE = "DELETE";
-
- private static final Log LOG = LogFactory.getLog(CmisAtomPubServlet.class.getName());
-
- private Dispatcher fDispatcher;
- private CallContextHandler fCallContextHandler;
-
- @Override
- public void init(ServletConfig config) throws ServletException {
- super.init(config);
-
- // initialize the call context handler
- fCallContextHandler = null;
- String callContextHandlerClass = config.getInitParameter(PARAM_CALL_CONTEXT_HANDLER);
- if (callContextHandlerClass != null) {
- try {
- fCallContextHandler = (CallContextHandler) Class.forName(callContextHandlerClass).newInstance();
- } catch (Exception e) {
- throw new ServletException("Could not load call context handler: " + e, e);
- }
- }
-
- // initialize the dispatcher
- fDispatcher = new Dispatcher();
-
- try {
- fDispatcher
- .addResource(AtomPubUtils.RESOURCE_TYPES, METHOD_GET, RepositoryService.class, "getTypeChildren");
- fDispatcher.addResource(AtomPubUtils.RESOURCE_TYPESDESC, METHOD_GET, RepositoryService.class,
- "getTypeDescendants");
- fDispatcher.addResource(AtomPubUtils.RESOURCE_TYPE, METHOD_GET, RepositoryService.class,
- "getTypeDefinition");
- fDispatcher.addResource(AtomPubUtils.RESOURCE_CHILDREN, METHOD_GET, NavigationService.class, "getChildren");
- fDispatcher.addResource(AtomPubUtils.RESOURCE_DESCENDANTS, METHOD_GET, NavigationService.class,
- "getDescendants");
- fDispatcher.addResource(AtomPubUtils.RESOURCE_FOLDERTREE, METHOD_GET, NavigationService.class,
- "getFolderTree");
- fDispatcher.addResource(AtomPubUtils.RESOURCE_PARENTS, METHOD_GET, NavigationService.class,
- "getObjectParents");
- fDispatcher.addResource(AtomPubUtils.RESOURCE_CHECKEDOUT, METHOD_GET, NavigationService.class,
- "getCheckedOutDocs");
- fDispatcher.addResource(AtomPubUtils.RESOURCE_ENTRY, METHOD_GET, ObjectService.class, "getObject");
- fDispatcher.addResource(AtomPubUtils.RESOURCE_OBJECTBYID, METHOD_GET, ObjectService.class, "getObject");
- fDispatcher.addResource(AtomPubUtils.RESOURCE_OBJECTBYPATH, METHOD_GET, ObjectService.class,
- "getObjectByPath");
- fDispatcher.addResource(AtomPubUtils.RESOURCE_ALLOWABLEACIONS, METHOD_GET, ObjectService.class,
- "getAllowableActions");
- fDispatcher.addResource(AtomPubUtils.RESOURCE_CONTENT, METHOD_GET, ObjectService.class, "getContentStream");
- fDispatcher.addResource(AtomPubUtils.RESOURCE_CONTENT, METHOD_PUT, ObjectService.class, "setContentStream");
- fDispatcher.addResource(AtomPubUtils.RESOURCE_CONTENT, METHOD_DELETE, ObjectService.class,
- "deleteContentStream");
- fDispatcher.addResource(AtomPubUtils.RESOURCE_CHILDREN, METHOD_POST, ObjectService.class, "create");
- fDispatcher.addResource(AtomPubUtils.RESOURCE_RELATIONSHIPS, METHOD_POST, ObjectService.class,
- "createRelationship");
- fDispatcher.addResource(AtomPubUtils.RESOURCE_ENTRY, METHOD_PUT, ObjectService.class, "updateProperties");
- fDispatcher.addResource(AtomPubUtils.RESOURCE_ENTRY, METHOD_DELETE, ObjectService.class, "deleteObject");
- fDispatcher
- .addResource(AtomPubUtils.RESOURCE_DESCENDANTS, METHOD_DELETE, ObjectService.class, "deleteTree");
- fDispatcher.addResource(AtomPubUtils.RESOURCE_CHECKEDOUT, METHOD_POST, VersioningService.class, "checkOut");
- fDispatcher.addResource(AtomPubUtils.RESOURCE_VERSIONS, METHOD_GET, VersioningService.class,
- "getAllVersions");
- fDispatcher.addResource(AtomPubUtils.RESOURCE_VERSIONS, METHOD_DELETE, VersioningService.class,
- "deleteAllVersions");
- fDispatcher.addResource(AtomPubUtils.RESOURCE_QUERY, METHOD_GET, DiscoveryService.class, "query");
- fDispatcher.addResource(AtomPubUtils.RESOURCE_QUERY, METHOD_POST, DiscoveryService.class, "query");
- fDispatcher.addResource(AtomPubUtils.RESOURCE_CHANGES, METHOD_GET, DiscoveryService.class,
- "getContentChanges");
- fDispatcher.addResource(AtomPubUtils.RESOURCE_RELATIONSHIPS, METHOD_GET, RelationshipService.class,
- "getObjectRelationships");
- fDispatcher.addResource(AtomPubUtils.RESOURCE_UNFILED, METHOD_POST, MultiFilingService.class,
- "removeObjectFromFolder");
- fDispatcher.addResource(AtomPubUtils.RESOURCE_ACL, METHOD_GET, AclService.class, "getAcl");
- fDispatcher.addResource(AtomPubUtils.RESOURCE_ACL, METHOD_PUT, AclService.class, "applyAcl");
- fDispatcher.addResource(AtomPubUtils.RESOURCE_POLICIES, METHOD_GET, PolicyService.class,
- "getAppliedPolicies");
- fDispatcher.addResource(AtomPubUtils.RESOURCE_POLICIES, METHOD_POST, PolicyService.class, "applyPolicy");
- fDispatcher.addResource(AtomPubUtils.RESOURCE_POLICIES, METHOD_DELETE, PolicyService.class, "removePolicy");
- } catch (NoSuchMethodException e) {
- LOG.error("Cannot initialize dispatcher!", e);
- }
- }
-
- @Override
- protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException,
- IOException {
-
- // create a context object, dispatch and handle exceptions
- CallContext context = null;
- try {
- context = createContext(request);
- dispatch(context, request, response);
- } catch (Exception e) {
- if (e instanceof CmisPermissionDeniedException) {
- if ((context == null) || (context.getUsername() == null)) {
- response.setHeader("WWW-Authenticate", "Basic realm=\"CMIS\"");
- response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Authorization Required");
- } else {
- response.sendError(getErrorCode((CmisPermissionDeniedException) e), e.getMessage());
- }
- } else if (e instanceof CmisRuntimeException) {
- LOG.error(e.getMessage(), e);
- response.sendError(getErrorCode((CmisRuntimeException) e), e.getMessage());
- } else if (e instanceof CmisBaseException) {
- response.sendError(getErrorCode((CmisBaseException) e), e.getMessage());
- } else {
- LOG.error(e.getMessage(), e);
- response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage());
- }
- }
-
- // we are done.
- response.flushBuffer();
- }
-
- /**
- * Dispatches to feed, entry or whatever.
- */
- private void dispatch(CallContext context, HttpServletRequest request, HttpServletResponse response)
- throws Exception {
-
- // get services factory
- AbstractServicesFactory servicesFactory = (AbstractServicesFactory) getServletContext().getAttribute(
- CmisRepositoryContextListener.SERVICES_FACTORY);
-
- // analyze the path
- String[] pathFragments = splitPath(request);
-
- if (pathFragments.length < 2) {
- // root -> service document
- RepositoryService.getRepositories(context, servicesFactory, request, response);
- return;
- }
-
- String method = request.getMethod();
- String repositoryId = pathFragments[0];
- String resource = pathFragments[1];
-
- // dispatch
- boolean methodFound = fDispatcher.dispatch(resource, method, context, servicesFactory, repositoryId, request,
- response);
-
- // if the dispatcher couldn't find a matching method, return an error
- // message
- if (!methodFound) {
- response.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "Unknown operation");
- }
- }
-
- /**
- * Decodes basic auth and creates a {@link CallContext} object.
- */
- protected CallContext createContext(HttpServletRequest request) {
- String[] pathFragments = splitPath(request);
-
- String repositoryId = null;
- if (pathFragments.length > 0) {
- repositoryId = pathFragments[0];
- }
-
- CallContextImpl context = new CallContextImpl(CallContext.BINDING_ATOMPUB, repositoryId, true);
-
- // call call text handler
- if (fCallContextHandler != null) {
- Map<String, String> callContextMap = fCallContextHandler.getCallContextMap(request);
- if (callContextMap != null) {
- for (Map.Entry<String, String> e : callContextMap.entrySet()) {
- context.put(e.getKey(), e.getValue());
- }
- }
- }
-
- // decode range
- String rangeHeader = request.getHeader("Range");
- if (rangeHeader != null) {
- rangeHeader = rangeHeader.trim();
- BigInteger offset = null;
- BigInteger length = null;
-
- int eq = rangeHeader.indexOf('=');
- int ds = rangeHeader.indexOf('-');
- if ((eq > 0) && (ds > eq)) {
- String offsetStr = rangeHeader.substring(eq + 1, ds).trim();
- if (offsetStr.length() > 0) {
- offset = new BigInteger(offsetStr);
- }
-
- if (ds < rangeHeader.length()) {
- String lengthStr = rangeHeader.substring(ds + 1).trim();
- if (lengthStr.length() > 0) {
- if (offset == null) {
- length = new BigInteger(lengthStr);
- } else {
- length = (new BigInteger(lengthStr)).subtract(offset);
- }
- }
-
- if (offset != null) {
- context.put(CallContext.OFFSET, offset.toString());
- }
- if (length != null) {
- context.put(CallContext.LENGTH, length.toString());
- }
- }
- }
- }
-
- return context;
- }
-
- /**
- * Splits the path into its fragments.
- */
- private String[] splitPath(HttpServletRequest request) {
- String p = request.getPathInfo();
- if (p == null) {
- return new String[0];
- }
-
- return p.substring(1).split("/");
- }
-
- /**
- * Translates an exception in an appropriate HTTP error code.
- */
- private int getErrorCode(CmisBaseException ex) {
- if (ex instanceof CmisConstraintException) {
- return 409;
- } else if (ex instanceof CmisContentAlreadyExistsException) {
- return 409;
- } else if (ex instanceof CmisFilterNotValidException) {
- return 400;
- } else if (ex instanceof CmisInvalidArgumentException) {
- return 400;
- } else if (ex instanceof CmisNameConstraintViolationException) {
- return 409;
- } else if (ex instanceof CmisNotSupportedException) {
- return 405;
- } else if (ex instanceof CmisObjectNotFoundException) {
- return 404;
- } else if (ex instanceof CmisPermissionDeniedException) {
- return 403;
- } else if (ex instanceof CmisStorageException) {
- return 500;
- } else if (ex instanceof CmisStreamNotSupportedException) {
- return 403;
- } else if (ex instanceof CmisUpdateConflictException) {
- return 409;
- } else if (ex instanceof CmisVersioningException) {
- return 409;
- }
+ private static final String METHOD_GET = "GET";
+ private static final String METHOD_POST = "POST";
+ private static final String METHOD_PUT = "PUT";
+ private static final String METHOD_DELETE = "DELETE";
+
+ private static final Log LOG = LogFactory.getLog(CmisAtomPubServlet.class.getName());
+
+ private Dispatcher fDispatcher;
+ private CallContextHandler fCallContextHandler;
+
+ @Override
+ public void init(ServletConfig config) throws ServletException {
+ super.init(config);
+
+ // initialize the call context handler
+ fCallContextHandler = null;
+ String callContextHandlerClass = config.getInitParameter(PARAM_CALL_CONTEXT_HANDLER);
+ if (callContextHandlerClass != null) {
+ try {
+ fCallContextHandler = (CallContextHandler) Class.forName(callContextHandlerClass).newInstance();
+ } catch (Exception e) {
+ throw new ServletException("Could not load call context handler: " + e, e);
+ }
+ }
+
+ // initialize the dispatcher
+ fDispatcher = new Dispatcher();
+
+ try {
+ fDispatcher
+ .addResource(AtomPubUtils.RESOURCE_TYPES, METHOD_GET, RepositoryService.class, "getTypeChildren");
+ fDispatcher.addResource(AtomPubUtils.RESOURCE_TYPESDESC, METHOD_GET, RepositoryService.class,
+ "getTypeDescendants");
+ fDispatcher.addResource(AtomPubUtils.RESOURCE_TYPE, METHOD_GET, RepositoryService.class,
+ "getTypeDefinition");
+ fDispatcher.addResource(AtomPubUtils.RESOURCE_CHILDREN, METHOD_GET, NavigationService.class, "getChildren");
+ fDispatcher.addResource(AtomPubUtils.RESOURCE_DESCENDANTS, METHOD_GET, NavigationService.class,
+ "getDescendants");
+ fDispatcher.addResource(AtomPubUtils.RESOURCE_FOLDERTREE, METHOD_GET, NavigationService.class,
+ "getFolderTree");
+ fDispatcher.addResource(AtomPubUtils.RESOURCE_PARENTS, METHOD_GET, NavigationService.class,
+ "getObjectParents");
+ fDispatcher.addResource(AtomPubUtils.RESOURCE_CHECKEDOUT, METHOD_GET, NavigationService.class,
+ "getCheckedOutDocs");
+ fDispatcher.addResource(AtomPubUtils.RESOURCE_ENTRY, METHOD_GET, ObjectService.class, "getObject");
+ fDispatcher.addResource(AtomPubUtils.RESOURCE_OBJECTBYID, METHOD_GET, ObjectService.class, "getObject");
+ fDispatcher.addResource(AtomPubUtils.RESOURCE_OBJECTBYPATH, METHOD_GET, ObjectService.class,
+ "getObjectByPath");
+ fDispatcher.addResource(AtomPubUtils.RESOURCE_ALLOWABLEACIONS, METHOD_GET, ObjectService.class,
+ "getAllowableActions");
+ fDispatcher.addResource(AtomPubUtils.RESOURCE_CONTENT, METHOD_GET, ObjectService.class, "getContentStream");
+ fDispatcher.addResource(AtomPubUtils.RESOURCE_CONTENT, METHOD_PUT, ObjectService.class, "setContentStream");
+ fDispatcher.addResource(AtomPubUtils.RESOURCE_CONTENT, METHOD_DELETE, ObjectService.class,
+ "deleteContentStream");
+ fDispatcher.addResource(AtomPubUtils.RESOURCE_CHILDREN, METHOD_POST, ObjectService.class, "create");
+ fDispatcher.addResource(AtomPubUtils.RESOURCE_RELATIONSHIPS, METHOD_POST, ObjectService.class,
+ "createRelationship");
+ fDispatcher.addResource(AtomPubUtils.RESOURCE_ENTRY, METHOD_PUT, ObjectService.class, "updateProperties");
+ fDispatcher.addResource(AtomPubUtils.RESOURCE_ENTRY, METHOD_DELETE, ObjectService.class, "deleteObject");
+ fDispatcher
+ .addResource(AtomPubUtils.RESOURCE_DESCENDANTS, METHOD_DELETE, ObjectService.class, "deleteTree");
+ fDispatcher.addResource(AtomPubUtils.RESOURCE_CHECKEDOUT, METHOD_POST, VersioningService.class, "checkOut");
+ fDispatcher.addResource(AtomPubUtils.RESOURCE_VERSIONS, METHOD_GET, VersioningService.class,
+ "getAllVersions");
+ fDispatcher.addResource(AtomPubUtils.RESOURCE_VERSIONS, METHOD_DELETE, VersioningService.class,
+ "deleteAllVersions");
+ fDispatcher.addResource(AtomPubUtils.RESOURCE_QUERY, METHOD_GET, DiscoveryService.class, "query");
+ fDispatcher.addResource(AtomPubUtils.RESOURCE_QUERY, METHOD_POST, DiscoveryService.class, "query");
+ fDispatcher.addResource(AtomPubUtils.RESOURCE_CHANGES, METHOD_GET, DiscoveryService.class,
+ "getContentChanges");
+ fDispatcher.addResource(AtomPubUtils.RESOURCE_RELATIONSHIPS, METHOD_GET, RelationshipService.class,
+ "getObjectRelationships");
+ fDispatcher.addResource(AtomPubUtils.RESOURCE_UNFILED, METHOD_POST, MultiFilingService.class,
+ "removeObjectFromFolder");
+ fDispatcher.addResource(AtomPubUtils.RESOURCE_ACL, METHOD_GET, AclService.class, "getAcl");
+ fDispatcher.addResource(AtomPubUtils.RESOURCE_ACL, METHOD_PUT, AclService.class, "applyAcl");
+ fDispatcher.addResource(AtomPubUtils.RESOURCE_POLICIES, METHOD_GET, PolicyService.class,
+ "getAppliedPolicies");
+ fDispatcher.addResource(AtomPubUtils.RESOURCE_POLICIES, METHOD_POST, PolicyService.class, "applyPolicy");
+ fDispatcher.addResource(AtomPubUtils.RESOURCE_POLICIES, METHOD_DELETE, PolicyService.class, "removePolicy");
+ } catch (NoSuchMethodException e) {
+ LOG.error("Cannot initialize dispatcher!", e);
+ }
+ }
+
+ @Override
+ protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException,
+ IOException {
+
+ // create a context object, dispatch and handle exceptions
+ CallContext context = null;
+ try {
+ context = createContext(request);
+ dispatch(context, request, response);
+ } catch (Exception e) {
+ if (e instanceof CmisPermissionDeniedException) {
+ if ((context == null) || (context.getUsername() == null)) {
+ response.setHeader("WWW-Authenticate", "Basic realm=\"CMIS\"");
+ response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Authorization Required");
+ } else {
+ response.sendError(getErrorCode((CmisPermissionDeniedException) e), e.getMessage());
+ }
+ } else if (e instanceof CmisRuntimeException) {
+ LOG.error(e.getMessage(), e);
+ response.sendError(getErrorCode((CmisRuntimeException) e), e.getMessage());
+ } else if (e instanceof CmisBaseException) {
+ response.sendError(getErrorCode((CmisBaseException) e), e.getMessage());
+ } else {
+ LOG.error(e.getMessage(), e);
+ response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage());
+ }
+ }
+
+ // we are done.
+ response.flushBuffer();
+ }
+
+ /**
+ * Dispatches to feed, entry or whatever.
+ */
+ private void dispatch(CallContext context, HttpServletRequest request, HttpServletResponse response)
+ throws Exception {
+
+ // get services factory
+ AbstractServicesFactory servicesFactory = (AbstractServicesFactory) getServletContext().getAttribute(
+ CmisRepositoryContextListener.SERVICES_FACTORY);
+
+ // analyze the path
+ String[] pathFragments = splitPath(request);
+
+ if (pathFragments.length < 2) {
+ // root -> service document
+ RepositoryService.getRepositories(context, servicesFactory, request, response);
+ return;
+ }
+
+ String method = request.getMethod();
+ String repositoryId = pathFragments[0];
+ String resource = pathFragments[1];
+
+ // dispatch
+ boolean methodFound = fDispatcher.dispatch(resource, method, context, servicesFactory, repositoryId, request,
+ response);
+
+ // if the dispatcher couldn't find a matching method, return an error
+ // message
+ if (!methodFound) {
+ response.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "Unknown operation");
+ }
+ }
+
+ /**
+ * Decodes basic auth and creates a {@link CallContext} object.
+ */
+ protected CallContext createContext(HttpServletRequest request) {
+ String[] pathFragments = splitPath(request);
+
+ String repositoryId = null;
+ if (pathFragments.length > 0) {
+ repositoryId = pathFragments[0];
+ }
+
+ CallContextImpl context = new CallContextImpl(CallContext.BINDING_ATOMPUB, repositoryId, true);
+
+ // call call text handler
+ if (fCallContextHandler != null) {
+ Map<String, String> callContextMap = fCallContextHandler.getCallContextMap(request);
+ if (callContextMap != null) {
+ for (Map.Entry<String, String> e : callContextMap.entrySet()) {
+ context.put(e.getKey(), e.getValue());
+ }
+ }
+ }
+
+ // decode range
+ String rangeHeader = request.getHeader("Range");
+ if (rangeHeader != null) {
+ rangeHeader = rangeHeader.trim();
+ BigInteger offset = null;
+ BigInteger length = null;
+
+ int eq = rangeHeader.indexOf('=');
+ int ds = rangeHeader.indexOf('-');
+ if ((eq > 0) && (ds > eq)) {
+ String offsetStr = rangeHeader.substring(eq + 1, ds).trim();
+ if (offsetStr.length() > 0) {
+ offset = new BigInteger(offsetStr);
+ }
+
+ if (ds < rangeHeader.length()) {
+ String lengthStr = rangeHeader.substring(ds + 1).trim();
+ if (lengthStr.length() > 0) {
+ if (offset == null) {
+ length = new BigInteger(lengthStr);
+ } else {
+ length = (new BigInteger(lengthStr)).subtract(offset);
+ }
+ }
+
+ if (offset != null) {
+ context.put(CallContext.OFFSET, offset.toString());
+ }
+ if (length != null) {
+ context.put(CallContext.LENGTH, length.toString());
+ }
+ }
+ }
+ }
+
+ return context;
+ }
+
+ /**
+ * Splits the path into its fragments.
+ */
+ private String[] splitPath(HttpServletRequest request) {
+ String p = request.getPathInfo();
+ if (p == null) {
+ return new String[0];
+ }
+
+ return p.substring(1).split("/");
+ }
+
+ /**
+ * Translates an exception in an appropriate HTTP error code.
+ */
+ private int getErrorCode(CmisBaseException ex) {
+ if (ex instanceof CmisConstraintException) {
+ return 409;
+ } else if (ex instanceof CmisContentAlreadyExistsException) {
+ return 409;
+ } else if (ex instanceof CmisFilterNotValidException) {
+ return 400;
+ } else if (ex instanceof CmisInvalidArgumentException) {
+ return 400;
+ } else if (ex instanceof CmisNameConstraintViolationException) {
+ return 409;
+ } else if (ex instanceof CmisNotSupportedException) {
+ return 405;
+ } else if (ex instanceof CmisObjectNotFoundException) {
+ return 404;
+ } else if (ex instanceof CmisPermissionDeniedException) {
+ return 403;
+ } else if (ex instanceof CmisStorageException) {
+ return 500;
+ } else if (ex instanceof CmisStreamNotSupportedException) {
+ return 403;
+ } else if (ex instanceof CmisUpdateConflictException) {
+ return 409;
+ } else if (ex instanceof CmisVersioningException) {
+ return 409;
+ }
- return 500;
- }
+ return 500;
+ }
}
Modified: incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/DiscoveryService.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/DiscoveryService.java?rev=936938&r1=936937&r2=936938&view=diff
==============================================================================
--- incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/DiscoveryService.java (original)
+++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/DiscoveryService.java Thu Apr 22 16:27:57 2010
@@ -62,220 +62,220 @@ import org.apache.chemistry.opencmis.ser
*/
public class DiscoveryService {
- private static final String METHOD_GET = "GET";
- private static final String METHOD_POST = "POST";
+ private static final String METHOD_GET = "GET";
+ private static final String METHOD_POST = "POST";
- /**
- * Query.
- */
- public static void query(CallContext context, AbstractServicesFactory factory, String repositoryId,
- HttpServletRequest request, HttpServletResponse response) throws Exception {
- CmisDiscoveryService service = factory.getDiscoveryService();
-
- // get parameters
- String statement = null;
- Boolean searchAllVersions = null;
- Boolean includeAllowableActions = null;
- IncludeRelationships includeRelationships = null;
- String renditionFilter = null;
- BigInteger maxItems = null;
- BigInteger skipCount = null;
-
- int statusCode = 0;
-
- if (METHOD_POST.equals(request.getMethod())) {
- // POST -> read from stream
- Object queryRequest = null;
- try {
- Unmarshaller u = JaxBHelper.createUnmarshaller();
- queryRequest = u.unmarshal(request.getInputStream());
- } catch (Exception e) {
- throw new CmisInvalidArgumentException("Invalid query request: " + e, e);
- }
-
- if (!(queryRequest instanceof JAXBElement<?>)) {
- throw new CmisInvalidArgumentException("Not a query document!");
- }
-
- if (!(((JAXBElement<?>) queryRequest).getValue() instanceof CmisQueryType)) {
- throw new CmisInvalidArgumentException("Not a query document!");
- }
-
- CmisQueryType queryType = (CmisQueryType) ((JAXBElement<?>) queryRequest).getValue();
-
- statement = queryType.getStatement();
- searchAllVersions = queryType.isSearchAllVersions();
- includeAllowableActions = queryType.isIncludeAllowableActions();
- includeRelationships = convert(IncludeRelationships.class, queryType.getIncludeRelationships());
- renditionFilter = queryType.getRenditionFilter();
- maxItems = queryType.getMaxItems();
- skipCount = queryType.getSkipCount();
-
- statusCode = HttpServletResponse.SC_CREATED;
- } else if (METHOD_GET.equals(request.getMethod())) {
- // GET -> parameters
- statement = getStringParameter(request, Constants.PARAM_Q);
- searchAllVersions = getBooleanParameter(request, Constants.PARAM_SEARCH_ALL_VERSIONS);
- includeAllowableActions = getBooleanParameter(request, Constants.PARAM_ALLOWABLE_ACTIONS);
- includeRelationships = getEnumParameter(request, Constants.PARAM_RELATIONSHIPS, IncludeRelationships.class);
- renditionFilter = null;
- maxItems = getBigIntegerParameter(request, Constants.PARAM_MAX_ITEMS);
- skipCount = getBigIntegerParameter(request, Constants.PARAM_SKIP_COUNT);
-
- statusCode = HttpServletResponse.SC_OK;
- } else {
- throw new CmisRuntimeException("Invalid HTTP method!");
- }
-
- // execute
- ObjectList results = service.query(context, repositoryId, statement, searchAllVersions,
- includeAllowableActions, includeRelationships, renditionFilter, maxItems, skipCount, null);
-
- if (results == null) {
- throw new CmisRuntimeException("Results are null!");
- }
-
- // set headers
- UrlBuilder baseUrl = compileBaseUrl(request, repositoryId);
-
- UrlBuilder pagingUrl = compileUrlBuilder(baseUrl, RESOURCE_QUERY, null);
- pagingUrl.addParameter(Constants.PARAM_Q, statement);
- pagingUrl.addParameter(Constants.PARAM_SEARCH_ALL_VERSIONS, searchAllVersions);
- pagingUrl.addParameter(Constants.PARAM_ALLOWABLE_ACTIONS, includeAllowableActions);
- pagingUrl.addParameter(Constants.PARAM_RELATIONSHIPS, includeRelationships);
-
- UrlBuilder location = new UrlBuilder(pagingUrl);
- location.addParameter(Constants.PARAM_MAX_ITEMS, maxItems);
- location.addParameter(Constants.PARAM_SKIP_COUNT, skipCount);
-
- response.setStatus(statusCode);
- response.setContentType(Constants.MEDIATYPE_FEED);
- response.setHeader("Content-Location", location.toString());
- response.setHeader("Location", location.toString());
-
- // write XML
- AtomFeed feed = new AtomFeed();
- feed.startDocument(response.getOutputStream());
- feed.startFeed(true);
-
- // write basic Atom feed elements
- GregorianCalendar now = new GregorianCalendar();
- feed.writeFeedElements("query", "", "Query", now, null, results.getNumItems());
-
- // write links
- feed.writeServiceLink(baseUrl.toString(), repositoryId);
-
- feed.writePagingLinks(pagingUrl, maxItems, skipCount, results.getNumItems(), results.hasMoreItems(),
- AtomPubUtils.PAGE_SIZE);
-
- if (results.getObjects() != null) {
- AtomEntry entry = new AtomEntry(feed.getWriter());
- int idCounter = 0;
- for (ObjectData result : results.getObjects()) {
- if (result == null) {
- continue;
- }
- idCounter++;
- writeQueryResultEntry(entry, result, "id-" + idCounter, now);
- }
- }
-
- // we are done
- feed.endFeed();
- feed.endDocument();
- }
-
- private static void writeQueryResultEntry(AtomEntry entry, ObjectData result, String id, GregorianCalendar now)
- throws Exception {
- CmisObjectType resultJaxb = convert(result);
- if (resultJaxb == null) {
- return;
- }
-
- // start
- entry.startEntry(false);
-
- // write Atom base tags
- entry.writeAuthor("");
- entry.writeId(entry.generateAtomId(id));
- entry.writePublished(now);
- entry.writeTitle("Query Result " + id);
- entry.writeUpdated(now);
-
- // write query result object
- JaxBHelper.marshal(JaxBHelper.CMIS_EXTRA_OBJECT_FACTORY.createObject(resultJaxb), entry.getWriter(), true);
-
- // we are done
- entry.endEntry();
- }
-
- /**
- * Get content changes.
- */
- public static void getContentChanges(CallContext context, AbstractServicesFactory factory, String repositoryId,
- HttpServletRequest request, HttpServletResponse response) throws Exception {
- CmisDiscoveryService service = factory.getDiscoveryService();
-
- // get parameters
- String changeLogToken = getStringParameter(request, Constants.PARAM_CHANGE_LOG_TOKEN);
- Boolean includeProperties = getBooleanParameter(request, Constants.PARAM_PROPERTIES);
- String filter = getStringParameter(request, Constants.PARAM_FILTER);
- Boolean includePolicyIds = getBooleanParameter(request, Constants.PARAM_POLICY_IDS);
- Boolean includeAcl = getBooleanParameter(request, Constants.PARAM_ACL);
- BigInteger maxItems = getBigIntegerParameter(request, Constants.PARAM_MAX_ITEMS);
-
- // execute
- ObjectInfoHolder objectInfoHolder = new ObjectInfoHolderImpl();
- Holder<String> changeLogTokenHolder = new Holder<String>(changeLogToken);
- ObjectList changes = service.getContentChanges(context, repositoryId, changeLogTokenHolder, includeProperties,
- filter, includePolicyIds, includeAcl, maxItems, null, objectInfoHolder);
-
- if (changes == null) {
- throw new CmisRuntimeException("Changes are null!");
- }
-
- // set headers
- response.setStatus(HttpServletResponse.SC_OK);
- response.setContentType(Constants.MEDIATYPE_FEED);
-
- // write XML
- AtomFeed feed = new AtomFeed();
- feed.startDocument(response.getOutputStream());
- feed.startFeed(true);
-
- // write basic Atom feed elements
- GregorianCalendar now = new GregorianCalendar();
- feed.writeFeedElements("contentChanges", "", "Content Change", now, null, changes.getNumItems());
-
- // write links
- UrlBuilder baseUrl = compileBaseUrl(request, repositoryId);
-
- feed.writeServiceLink(baseUrl.toString(), repositoryId);
-
- if (changeLogTokenHolder.getValue() != null) {
- UrlBuilder nextLink = compileUrlBuilder(baseUrl, RESOURCE_CHANGES, null);
- nextLink.addParameter(Constants.PARAM_CHANGE_LOG_TOKEN, changeLogTokenHolder.getValue());
- nextLink.addParameter(Constants.PARAM_PROPERTIES, includeProperties);
- nextLink.addParameter(Constants.PARAM_FILTER, filter);
- nextLink.addParameter(Constants.PARAM_POLICY_IDS, includePolicyIds);
- nextLink.addParameter(Constants.PARAM_ACL, includeAcl);
- nextLink.addParameter(Constants.PARAM_MAX_ITEMS, maxItems);
- feed.writeNextLink(nextLink.toString());
- }
-
- // write entries
- if (changes.getObjects() != null) {
- AtomEntry entry = new AtomEntry(feed.getWriter());
- for (ObjectData object : changes.getObjects()) {
- if (object == null) {
- continue;
- }
- writeObjectEntry(entry, object, objectInfoHolder, null, repositoryId, null, null, baseUrl, false);
- }
- }
-
- // we are done
- feed.endFeed();
- feed.endDocument();
- }
+ /**
+ * Query.
+ */
+ public static void query(CallContext context, AbstractServicesFactory factory, String repositoryId,
+ HttpServletRequest request, HttpServletResponse response) throws Exception {
+ CmisDiscoveryService service = factory.getDiscoveryService();
+
+ // get parameters
+ String statement = null;
+ Boolean searchAllVersions = null;
+ Boolean includeAllowableActions = null;
+ IncludeRelationships includeRelationships = null;
+ String renditionFilter = null;
+ BigInteger maxItems = null;
+ BigInteger skipCount = null;
+
+ int statusCode = 0;
+
+ if (METHOD_POST.equals(request.getMethod())) {
+ // POST -> read from stream
+ Object queryRequest = null;
+ try {
+ Unmarshaller u = JaxBHelper.createUnmarshaller();
+ queryRequest = u.unmarshal(request.getInputStream());
+ } catch (Exception e) {
+ throw new CmisInvalidArgumentException("Invalid query request: " + e, e);
+ }
+
+ if (!(queryRequest instanceof JAXBElement<?>)) {
+ throw new CmisInvalidArgumentException("Not a query document!");
+ }
+
+ if (!(((JAXBElement<?>) queryRequest).getValue() instanceof CmisQueryType)) {
+ throw new CmisInvalidArgumentException("Not a query document!");
+ }
+
+ CmisQueryType queryType = (CmisQueryType) ((JAXBElement<?>) queryRequest).getValue();
+
+ statement = queryType.getStatement();
+ searchAllVersions = queryType.isSearchAllVersions();
+ includeAllowableActions = queryType.isIncludeAllowableActions();
+ includeRelationships = convert(IncludeRelationships.class, queryType.getIncludeRelationships());
+ renditionFilter = queryType.getRenditionFilter();
+ maxItems = queryType.getMaxItems();
+ skipCount = queryType.getSkipCount();
+
+ statusCode = HttpServletResponse.SC_CREATED;
+ } else if (METHOD_GET.equals(request.getMethod())) {
+ // GET -> parameters
+ statement = getStringParameter(request, Constants.PARAM_Q);
+ searchAllVersions = getBooleanParameter(request, Constants.PARAM_SEARCH_ALL_VERSIONS);
+ includeAllowableActions = getBooleanParameter(request, Constants.PARAM_ALLOWABLE_ACTIONS);
+ includeRelationships = getEnumParameter(request, Constants.PARAM_RELATIONSHIPS, IncludeRelationships.class);
+ renditionFilter = null;
+ maxItems = getBigIntegerParameter(request, Constants.PARAM_MAX_ITEMS);
+ skipCount = getBigIntegerParameter(request, Constants.PARAM_SKIP_COUNT);
+
+ statusCode = HttpServletResponse.SC_OK;
+ } else {
+ throw new CmisRuntimeException("Invalid HTTP method!");
+ }
+
+ // execute
+ ObjectList results = service.query(context, repositoryId, statement, searchAllVersions,
+ includeAllowableActions, includeRelationships, renditionFilter, maxItems, skipCount, null);
+
+ if (results == null) {
+ throw new CmisRuntimeException("Results are null!");
+ }
+
+ // set headers
+ UrlBuilder baseUrl = compileBaseUrl(request, repositoryId);
+
+ UrlBuilder pagingUrl = compileUrlBuilder(baseUrl, RESOURCE_QUERY, null);
+ pagingUrl.addParameter(Constants.PARAM_Q, statement);
+ pagingUrl.addParameter(Constants.PARAM_SEARCH_ALL_VERSIONS, searchAllVersions);
+ pagingUrl.addParameter(Constants.PARAM_ALLOWABLE_ACTIONS, includeAllowableActions);
+ pagingUrl.addParameter(Constants.PARAM_RELATIONSHIPS, includeRelationships);
+
+ UrlBuilder location = new UrlBuilder(pagingUrl);
+ location.addParameter(Constants.PARAM_MAX_ITEMS, maxItems);
+ location.addParameter(Constants.PARAM_SKIP_COUNT, skipCount);
+
+ response.setStatus(statusCode);
+ response.setContentType(Constants.MEDIATYPE_FEED);
+ response.setHeader("Content-Location", location.toString());
+ response.setHeader("Location", location.toString());
+
+ // write XML
+ AtomFeed feed = new AtomFeed();
+ feed.startDocument(response.getOutputStream());
+ feed.startFeed(true);
+
+ // write basic Atom feed elements
+ GregorianCalendar now = new GregorianCalendar();
+ feed.writeFeedElements("query", "", "Query", now, null, results.getNumItems());
+
+ // write links
+ feed.writeServiceLink(baseUrl.toString(), repositoryId);
+
+ feed.writePagingLinks(pagingUrl, maxItems, skipCount, results.getNumItems(), results.hasMoreItems(),
+ AtomPubUtils.PAGE_SIZE);
+
+ if (results.getObjects() != null) {
+ AtomEntry entry = new AtomEntry(feed.getWriter());
+ int idCounter = 0;
+ for (ObjectData result : results.getObjects()) {
+ if (result == null) {
+ continue;
+ }
+ idCounter++;
+ writeQueryResultEntry(entry, result, "id-" + idCounter, now);
+ }
+ }
+
+ // we are done
+ feed.endFeed();
+ feed.endDocument();
+ }
+
+ private static void writeQueryResultEntry(AtomEntry entry, ObjectData result, String id, GregorianCalendar now)
+ throws Exception {
+ CmisObjectType resultJaxb = convert(result);
+ if (resultJaxb == null) {
+ return;
+ }
+
+ // start
+ entry.startEntry(false);
+
+ // write Atom base tags
+ entry.writeAuthor("");
+ entry.writeId(entry.generateAtomId(id));
+ entry.writePublished(now);
+ entry.writeTitle("Query Result " + id);
+ entry.writeUpdated(now);
+
+ // write query result object
+ JaxBHelper.marshal(JaxBHelper.CMIS_EXTRA_OBJECT_FACTORY.createObject(resultJaxb), entry.getWriter(), true);
+
+ // we are done
+ entry.endEntry();
+ }
+
+ /**
+ * Get content changes.
+ */
+ public static void getContentChanges(CallContext context, AbstractServicesFactory factory, String repositoryId,
+ HttpServletRequest request, HttpServletResponse response) throws Exception {
+ CmisDiscoveryService service = factory.getDiscoveryService();
+
+ // get parameters
+ String changeLogToken = getStringParameter(request, Constants.PARAM_CHANGE_LOG_TOKEN);
+ Boolean includeProperties = getBooleanParameter(request, Constants.PARAM_PROPERTIES);
+ String filter = getStringParameter(request, Constants.PARAM_FILTER);
+ Boolean includePolicyIds = getBooleanParameter(request, Constants.PARAM_POLICY_IDS);
+ Boolean includeAcl = getBooleanParameter(request, Constants.PARAM_ACL);
+ BigInteger maxItems = getBigIntegerParameter(request, Constants.PARAM_MAX_ITEMS);
+
+ // execute
+ ObjectInfoHolder objectInfoHolder = new ObjectInfoHolderImpl();
+ Holder<String> changeLogTokenHolder = new Holder<String>(changeLogToken);
+ ObjectList changes = service.getContentChanges(context, repositoryId, changeLogTokenHolder, includeProperties,
+ filter, includePolicyIds, includeAcl, maxItems, null, objectInfoHolder);
+
+ if (changes == null) {
+ throw new CmisRuntimeException("Changes are null!");
+ }
+
+ // set headers
+ response.setStatus(HttpServletResponse.SC_OK);
+ response.setContentType(Constants.MEDIATYPE_FEED);
+
+ // write XML
+ AtomFeed feed = new AtomFeed();
+ feed.startDocument(response.getOutputStream());
+ feed.startFeed(true);
+
+ // write basic Atom feed elements
+ GregorianCalendar now = new GregorianCalendar();
+ feed.writeFeedElements("contentChanges", "", "Content Change", now, null, changes.getNumItems());
+
+ // write links
+ UrlBuilder baseUrl = compileBaseUrl(request, repositoryId);
+
+ feed.writeServiceLink(baseUrl.toString(), repositoryId);
+
+ if (changeLogTokenHolder.getValue() != null) {
+ UrlBuilder nextLink = compileUrlBuilder(baseUrl, RESOURCE_CHANGES, null);
+ nextLink.addParameter(Constants.PARAM_CHANGE_LOG_TOKEN, changeLogTokenHolder.getValue());
+ nextLink.addParameter(Constants.PARAM_PROPERTIES, includeProperties);
+ nextLink.addParameter(Constants.PARAM_FILTER, filter);
+ nextLink.addParameter(Constants.PARAM_POLICY_IDS, includePolicyIds);
+ nextLink.addParameter(Constants.PARAM_ACL, includeAcl);
+ nextLink.addParameter(Constants.PARAM_MAX_ITEMS, maxItems);
+ feed.writeNextLink(nextLink.toString());
+ }
+
+ // write entries
+ if (changes.getObjects() != null) {
+ AtomEntry entry = new AtomEntry(feed.getWriter());
+ for (ObjectData object : changes.getObjects()) {
+ if (object == null) {
+ continue;
+ }
+ writeObjectEntry(entry, object, objectInfoHolder, null, repositoryId, null, null, baseUrl, false);
+ }
+ }
+
+ // we are done
+ feed.endFeed();
+ feed.endDocument();
+ }
}
Modified: incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/Dispatcher.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/Dispatcher.java?rev=936938&r1=936937&r2=936938&view=diff
==============================================================================
--- incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/Dispatcher.java (original)
+++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/Dispatcher.java Thu Apr 22 16:27:57 2010
@@ -41,64 +41,64 @@ import org.apache.commons.logging.LogFac
*/
public class Dispatcher {
- private static final Log LOG = LogFactory.getLog(Dispatcher.class.getName());
+ private static final Log LOG = LogFactory.getLog(Dispatcher.class.getName());
- private Map<String, Method> fMethodMap = new HashMap<String, Method>();
+ private Map<String, Method> fMethodMap = new HashMap<String, Method>();
- public Dispatcher() {
- }
+ public Dispatcher() {
+ }
- /**
- * Connects a resource and HTTP method with a class and a class method.
- */
- public synchronized void addResource(String resource, String httpMethod, Class<?> clazz, String classmethod)
- throws NoSuchMethodException {
-
- Method m = clazz.getMethod(classmethod, CallContext.class, AbstractServicesFactory.class, String.class,
- HttpServletRequest.class, HttpServletResponse.class);
-
- fMethodMap.put(getKey(resource, httpMethod), m);
- }
-
- /**
- * Find the appropriate method an call it.
- *
- * @return <code>true</code> if the method was found, <code>false</code>
- * otherwise.
- */
- public boolean dispatch(String resource, String httpMethod, CallContext context, AbstractServicesFactory factory,
- String repositoryId, HttpServletRequest request, HttpServletResponse response) {
-
- Method m = fMethodMap.get(getKey(resource, httpMethod));
- if (m == null) {
- return false;
- }
-
- if (LOG.isDebugEnabled()) {
- LOG.debug(repositoryId + " / " + resource + ", " + httpMethod + " -> " + m.getName());
- }
-
- try {
- m.invoke(null, context, factory, repositoryId, request, response);
- } catch (IllegalArgumentException e) {
- throw e;
- } catch (IllegalAccessException e) {
- throw new CmisRuntimeException("Internal error!", e);
- } catch (InvocationTargetException e) {
- if (e.getCause() instanceof CmisBaseException) {
- throw (CmisBaseException) e.getCause();
- } else {
- throw new CmisRuntimeException(e.getMessage(), e);
- }
- }
-
- return true;
- }
-
- /**
- * Generates a map key from a resource and an HTTP method.
- */
- private String getKey(String resource, String httpMethod) {
- return resource + "/" + httpMethod;
- }
+ /**
+ * Connects a resource and HTTP method with a class and a class method.
+ */
+ public synchronized void addResource(String resource, String httpMethod, Class<?> clazz, String classmethod)
+ throws NoSuchMethodException {
+
+ Method m = clazz.getMethod(classmethod, CallContext.class, AbstractServicesFactory.class, String.class,
+ HttpServletRequest.class, HttpServletResponse.class);
+
+ fMethodMap.put(getKey(resource, httpMethod), m);
+ }
+
+ /**
+ * Find the appropriate method an call it.
+ *
+ * @return <code>true</code> if the method was found, <code>false</code>
+ * otherwise.
+ */
+ public boolean dispatch(String resource, String httpMethod, CallContext context, AbstractServicesFactory factory,
+ String repositoryId, HttpServletRequest request, HttpServletResponse response) {
+
+ Method m = fMethodMap.get(getKey(resource, httpMethod));
+ if (m == null) {
+ return false;
+ }
+
+ if (LOG.isDebugEnabled()) {
+ LOG.debug(repositoryId + " / " + resource + ", " + httpMethod + " -> " + m.getName());
+ }
+
+ try {
+ m.invoke(null, context, factory, repositoryId, request, response);
+ } catch (IllegalArgumentException e) {
+ throw e;
+ } catch (IllegalAccessException e) {
+ throw new CmisRuntimeException("Internal error!", e);
+ } catch (InvocationTargetException e) {
+ if (e.getCause() instanceof CmisBaseException) {
+ throw (CmisBaseException) e.getCause();
+ } else {
+ throw new CmisRuntimeException(e.getMessage(), e);
+ }
+ }
+
+ return true;
+ }
+
+ /**
+ * Generates a map key from a resource and an HTTP method.
+ */
+ private String getKey(String resource, String httpMethod) {
+ return resource + "/" + httpMethod;
+ }
}
Modified: incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/MultiFilingService.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/MultiFilingService.java?rev=936938&r1=936937&r2=936938&view=diff
==============================================================================
--- incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/MultiFilingService.java (original)
+++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/MultiFilingService.java Thu Apr 22 16:27:57 2010
@@ -45,43 +45,43 @@ import org.apache.chemistry.opencmis.ser
*/
public class MultiFilingService {
- /**
- * Remove object from folder.
- */
- public static void removeObjectFromFolder(CallContext context, AbstractServicesFactory factory,
- String repositoryId, HttpServletRequest request, HttpServletResponse response) throws Exception {
- CmisMultiFilingService service = factory.getMultiFilingService();
-
- // get parameters
- String removeFrom = getStringParameter(request, Constants.PARAM_REMOVE_FROM);
-
- AtomEntryParser parser = new AtomEntryParser(request.getInputStream());
- String objectId = parser.getId();
-
- // execute
- ObjectInfoHolder objectInfoHolder = new ObjectInfoHolderImpl();
- ObjectData object = service.removeObjectFromFolder(context, repositoryId, objectId, removeFrom, null,
- objectInfoHolder);
-
- if (object == null) {
- throw new CmisRuntimeException("Object is null!");
- }
-
- if (object.getId() == null) {
- throw new CmisRuntimeException("Object Id is null!");
- }
-
- // set headers
- UrlBuilder baseUrl = compileBaseUrl(request, repositoryId);
-
- response.setStatus(HttpServletResponse.SC_CREATED);
- response.setContentType(Constants.MEDIATYPE_ENTRY);
- response.setHeader("Location", compileUrl(baseUrl, RESOURCE_ENTRY, object.getId()));
-
- // write XML
- AtomEntry entry = new AtomEntry();
- entry.startDocument(response.getOutputStream());
- writeObjectEntry(entry, object, objectInfoHolder, null, repositoryId, null, null, baseUrl, true);
- entry.endDocument();
- }
+ /**
+ * Remove object from folder.
+ */
+ public static void removeObjectFromFolder(CallContext context, AbstractServicesFactory factory,
+ String repositoryId, HttpServletRequest request, HttpServletResponse response) throws Exception {
+ CmisMultiFilingService service = factory.getMultiFilingService();
+
+ // get parameters
+ String removeFrom = getStringParameter(request, Constants.PARAM_REMOVE_FROM);
+
+ AtomEntryParser parser = new AtomEntryParser(request.getInputStream());
+ String objectId = parser.getId();
+
+ // execute
+ ObjectInfoHolder objectInfoHolder = new ObjectInfoHolderImpl();
+ ObjectData object = service.removeObjectFromFolder(context, repositoryId, objectId, removeFrom, null,
+ objectInfoHolder);
+
+ if (object == null) {
+ throw new CmisRuntimeException("Object is null!");
+ }
+
+ if (object.getId() == null) {
+ throw new CmisRuntimeException("Object Id is null!");
+ }
+
+ // set headers
+ UrlBuilder baseUrl = compileBaseUrl(request, repositoryId);
+
+ response.setStatus(HttpServletResponse.SC_CREATED);
+ response.setContentType(Constants.MEDIATYPE_ENTRY);
+ response.setHeader("Location", compileUrl(baseUrl, RESOURCE_ENTRY, object.getId()));
+
+ // write XML
+ AtomEntry entry = new AtomEntry();
+ entry.startDocument(response.getOutputStream());
+ writeObjectEntry(entry, object, objectInfoHolder, null, repositoryId, null, null, baseUrl, true);
+ entry.endDocument();
+ }
}