You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@chemistry.apache.org by fm...@apache.org on 2013/05/11 23:19:48 UTC
svn commit: r1481420 [7/7] - in
/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src:
main/java/org/apache/chemistry/opencmis/server/impl/
main/java/org/apache/chemistry/opencmis/server/impl/atompub/
main/java/org/...
Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/RepositoryService.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/RepositoryService.java?rev=1481420&r1=1481419&r2=1481420&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/RepositoryService.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/RepositoryService.java Sat May 11 21:19:48 2013
@@ -26,10 +26,6 @@ import static org.apache.chemistry.openc
import static org.apache.chemistry.opencmis.commons.impl.Constants.PARAM_SKIP_COUNT;
import static org.apache.chemistry.opencmis.commons.impl.Constants.PARAM_TOKEN;
import static org.apache.chemistry.opencmis.commons.impl.Constants.PARAM_TYPE_ID;
-import static org.apache.chemistry.opencmis.server.impl.browser.BrowserBindingUtils.writeEmpty;
-import static org.apache.chemistry.opencmis.server.shared.HttpUtils.getBigIntegerParameter;
-import static org.apache.chemistry.opencmis.server.shared.HttpUtils.getBooleanParameter;
-import static org.apache.chemistry.opencmis.server.shared.HttpUtils.getStringParameter;
import java.math.BigInteger;
import java.net.URLDecoder;
@@ -57,215 +53,231 @@ import org.apache.chemistry.opencmis.com
/**
* Repository Service operations.
*/
-public final class RepositoryService {
-
- private RepositoryService() {
- }
+public class RepositoryService {
/**
* getRepositories.
*/
- public static void getRepositories(CallContext context, CmisService service, HttpServletRequest request,
- HttpServletResponse response) throws Exception {
- // execute
- List<RepositoryInfo> infoDataList = service.getRepositoryInfos(null);
-
- JSONObject result = new JSONObject();
- for (RepositoryInfo ri : infoDataList) {
- String repositoryUrl = BrowserBindingUtils.compileRepositoryUrl(request, ri.getId()).toString();
- String rootUrl = BrowserBindingUtils.compileRootUrl(request, ri.getId()).toString();
+ public static class GetRepositories extends AbstractBrowserServiceCall {
+ public void serve(CallContext context, CmisService service, String repositoryId, HttpServletRequest request,
+ HttpServletResponse response) throws Exception {
+ // execute
+ List<RepositoryInfo> infoDataList = service.getRepositoryInfos(null);
+
+ JSONObject result = new JSONObject();
+ for (RepositoryInfo ri : infoDataList) {
+ String repositoryUrl = compileRepositoryUrl(request, ri.getId()).toString();
+ String rootUrl = compileRootUrl(request, ri.getId()).toString();
- result.put(ri.getId(), JSONConverter.convert(ri, repositoryUrl, rootUrl));
- }
+ result.put(ri.getId(), JSONConverter.convert(ri, repositoryUrl, rootUrl));
+ }
- response.setStatus(HttpServletResponse.SC_OK);
- BrowserBindingUtils.writeJSON(result, request, response);
+ response.setStatus(HttpServletResponse.SC_OK);
+ writeJSON(result, request, response);
+ }
}
/**
* getRepositoryInfo.
*/
- public static void getRepositoryInfo(CallContext context, CmisService service, String repositoryId,
- HttpServletRequest request, HttpServletResponse response) throws Exception {
- // execute
- RepositoryInfo ri = service.getRepositoryInfo(repositoryId, null);
+ public static class GetRepositoryInfo extends AbstractBrowserServiceCall {
+ public void serve(CallContext context, CmisService service, String repositoryId, HttpServletRequest request,
+ HttpServletResponse response) throws Exception {
+ // execute
+ RepositoryInfo ri = service.getRepositoryInfo(repositoryId, null);
- String repositoryUrl = BrowserBindingUtils.compileRepositoryUrl(request, ri.getId()).toString();
- String rootUrl = BrowserBindingUtils.compileRootUrl(request, ri.getId()).toString();
+ String repositoryUrl = compileRepositoryUrl(request, ri.getId()).toString();
+ String rootUrl = compileRootUrl(request, ri.getId()).toString();
- JSONObject result = new JSONObject();
- result.put(ri.getId(), JSONConverter.convert(ri, repositoryUrl, rootUrl));
+ JSONObject result = new JSONObject();
+ result.put(ri.getId(), JSONConverter.convert(ri, repositoryUrl, rootUrl));
- response.setStatus(HttpServletResponse.SC_OK);
- BrowserBindingUtils.writeJSON(result, request, response);
+ response.setStatus(HttpServletResponse.SC_OK);
+ writeJSON(result, request, response);
+ }
}
/**
* getLastResult.
*/
- public static void getLastResult(CallContext context, CmisService service, String repositoryId,
- HttpServletRequest request, HttpServletResponse response) throws Exception {
-
- String token = getStringParameter(request, PARAM_TOKEN);
- String cookieName = BrowserBindingUtils.getCookieName(token);
- String cookieValue = null;
-
- if (request.getCookies() != null) {
- for (Cookie cookie : request.getCookies()) {
- if (cookieName.equals(cookie.getName())) {
- cookieValue = URLDecoder.decode(cookie.getValue(), "UTF-8");
- break;
+ public static class GetLastResult extends AbstractBrowserServiceCall {
+ public void serve(CallContext context, CmisService service, String repositoryId, HttpServletRequest request,
+ HttpServletResponse response) throws Exception {
+ String token = getStringParameter(request, PARAM_TOKEN);
+ String cookieName = getCookieName(token);
+ String cookieValue = null;
+
+ if (request.getCookies() != null) {
+ for (Cookie cookie : request.getCookies()) {
+ if (cookieName.equals(cookie.getName())) {
+ cookieValue = URLDecoder.decode(cookie.getValue(), "UTF-8");
+ break;
+ }
}
}
- }
- try {
- if (cookieValue == null) {
- cookieValue = BrowserBindingUtils.createCookieValue(0, null,
- CmisInvalidArgumentException.EXCEPTION_NAME, "Unknown transaction!");
- } else {
- JSONValue.parse(cookieValue);
- }
- } catch (Exception pe) {
- cookieValue = BrowserBindingUtils.createCookieValue(0, null, CmisRuntimeException.EXCEPTION_NAME,
- "Cookie pasring error!");
- }
+ try {
+ if (cookieValue == null) {
+ cookieValue = createCookieValue(0, null, CmisInvalidArgumentException.EXCEPTION_NAME,
+ "Unknown transaction!");
+ } else {
+ JSONValue.parse(cookieValue);
+ }
+ } catch (Exception pe) {
+ cookieValue = createCookieValue(0, null, CmisRuntimeException.EXCEPTION_NAME, "Cookie pasring error!");
+ }
- BrowserBindingUtils.deleteCookie(request, response, repositoryId, token);
+ deleteCookie(request, response, repositoryId, token);
- response.setStatus(HttpServletResponse.SC_OK);
- BrowserBindingUtils.writeJSON((JSONObject) JSONValue.parse(cookieValue), request, response);
+ response.setStatus(HttpServletResponse.SC_OK);
+ writeJSON((JSONObject) JSONValue.parse(cookieValue), request, response);
+ }
}
/**
* getTypeChildren.
*/
- public static void getTypeChildren(CallContext context, CmisService service, String repositoryId,
- HttpServletRequest request, HttpServletResponse response) throws Exception {
- // get parameters
- String typeId = getStringParameter(request, PARAM_TYPE_ID);
- boolean includePropertyDefinitions = getBooleanParameter(request, PARAM_PROPERTY_DEFINITIONS, false);
- BigInteger maxItems = getBigIntegerParameter(request, PARAM_MAX_ITEMS);
- BigInteger skipCount = getBigIntegerParameter(request, PARAM_SKIP_COUNT);
-
- // execute
- TypeDefinitionList typeList = service.getTypeChildren(repositoryId, typeId, includePropertyDefinitions,
- maxItems, skipCount, null);
- JSONObject jsonTypeList = JSONConverter.convert(typeList);
+ public static class GetTypeChildren extends AbstractBrowserServiceCall {
+ public void serve(CallContext context, CmisService service, String repositoryId, HttpServletRequest request,
+ HttpServletResponse response) throws Exception {
+ // get parameters
+ String typeId = getStringParameter(request, PARAM_TYPE_ID);
+ boolean includePropertyDefinitions = getBooleanParameter(request, PARAM_PROPERTY_DEFINITIONS, false);
+ BigInteger maxItems = getBigIntegerParameter(request, PARAM_MAX_ITEMS);
+ BigInteger skipCount = getBigIntegerParameter(request, PARAM_SKIP_COUNT);
+
+ // execute
+ TypeDefinitionList typeList = service.getTypeChildren(repositoryId, typeId, includePropertyDefinitions,
+ maxItems, skipCount, null);
+ JSONObject jsonTypeList = JSONConverter.convert(typeList);
- response.setStatus(HttpServletResponse.SC_OK);
- BrowserBindingUtils.writeJSON(jsonTypeList, request, response);
+ response.setStatus(HttpServletResponse.SC_OK);
+ writeJSON(jsonTypeList, request, response);
+ }
}
- public static void getTypeDescendants(CallContext context, CmisService service, String repositoryId,
- HttpServletRequest request, HttpServletResponse response) throws Exception {
- // get parameters
- String typeId = getStringParameter(request, PARAM_TYPE_ID);
- BigInteger depth = getBigIntegerParameter(request, PARAM_DEPTH);
- boolean includePropertyDefinitions = getBooleanParameter(request, PARAM_PROPERTY_DEFINITIONS, false);
+ public static class GetTypeDescendants extends AbstractBrowserServiceCall {
+ public void serve(CallContext context, CmisService service, String repositoryId, HttpServletRequest request,
+ HttpServletResponse response) throws Exception {
+ // get parameters
+ String typeId = getStringParameter(request, PARAM_TYPE_ID);
+ BigInteger depth = getBigIntegerParameter(request, PARAM_DEPTH);
+ boolean includePropertyDefinitions = getBooleanParameter(request, PARAM_PROPERTY_DEFINITIONS, false);
+
+ // execute
+ List<TypeDefinitionContainer> typeTree = service.getTypeDescendants(repositoryId, typeId, depth,
+ includePropertyDefinitions, null);
- // execute
- List<TypeDefinitionContainer> typeTree = service.getTypeDescendants(repositoryId, typeId, depth,
- includePropertyDefinitions, null);
+ if (typeTree == null) {
+ throw new CmisRuntimeException("Type tree is null!");
+ }
- if (typeTree == null) {
- throw new CmisRuntimeException("Type tree is null!");
- }
+ JSONArray jsonTypeTree = new JSONArray();
+ for (TypeDefinitionContainer container : typeTree) {
+ jsonTypeTree.add(JSONConverter.convert(container));
+ }
- JSONArray jsonTypeTree = new JSONArray();
- for (TypeDefinitionContainer container : typeTree) {
- jsonTypeTree.add(JSONConverter.convert(container));
+ response.setStatus(HttpServletResponse.SC_OK);
+ writeJSON(jsonTypeTree, request, response);
}
-
- response.setStatus(HttpServletResponse.SC_OK);
- BrowserBindingUtils.writeJSON(jsonTypeTree, request, response);
}
/**
* getTypeDefinition.
*/
- public static void getTypeDefinition(CallContext context, CmisService service, String repositoryId,
- HttpServletRequest request, HttpServletResponse response) throws Exception {
- // get parameters
- String typeId = getStringParameter(request, PARAM_TYPE_ID);
-
- // execute
- TypeDefinition type = service.getTypeDefinition(repositoryId, typeId, null);
- JSONObject jsonType = JSONConverter.convert(type);
+ public static class GetTypeDefinition extends AbstractBrowserServiceCall {
+ public void serve(CallContext context, CmisService service, String repositoryId, HttpServletRequest request,
+ HttpServletResponse response) throws Exception {
+ // get parameters
+ String typeId = getStringParameter(request, PARAM_TYPE_ID);
+
+ // execute
+ TypeDefinition type = service.getTypeDefinition(repositoryId, typeId, null);
+ JSONObject jsonType = JSONConverter.convert(type);
- response.setStatus(HttpServletResponse.SC_OK);
- BrowserBindingUtils.writeJSON(jsonType, request, response);
+ response.setStatus(HttpServletResponse.SC_OK);
+ writeJSON(jsonType, request, response);
+ }
}
/**
* createType.
*/
- public static void createType(CallContext context, CmisService service, String repositoryId,
- HttpServletRequest request, HttpServletResponse response) throws Exception {
- // get parameters
- String typeStr = getStringParameter(request, CONTROL_TYPE);
- if (typeStr == null) {
- throw new CmisInvalidArgumentException("Type definition missing!");
- }
-
- // convert type definition
- JSONParser parser = new JSONParser();
- Object typeJson = parser.parse(typeStr);
- if (!(typeJson instanceof Map)) {
- throw new CmisInvalidArgumentException("Invalid type definition!");
- }
-
- @SuppressWarnings("unchecked")
- TypeDefinition typeIn = JSONConverter.convertTypeDefinition((Map<String, Object>) typeJson);
-
- // execute
- TypeDefinition typeOut = service.createType(repositoryId, typeIn, null);
- JSONObject jsonType = JSONConverter.convert(typeOut);
+ public static class CreateType extends AbstractBrowserServiceCall {
+ public void serve(CallContext context, CmisService service, String repositoryId, HttpServletRequest request,
+ HttpServletResponse response) throws Exception {
+ // get parameters
+ String typeStr = getStringParameter(request, CONTROL_TYPE);
+ if (typeStr == null) {
+ throw new CmisInvalidArgumentException("Type definition missing!");
+ }
+
+ // convert type definition
+ JSONParser parser = new JSONParser();
+ Object typeJson = parser.parse(typeStr);
+ if (!(typeJson instanceof Map)) {
+ throw new CmisInvalidArgumentException("Invalid type definition!");
+ }
+
+ @SuppressWarnings("unchecked")
+ TypeDefinition typeIn = JSONConverter.convertTypeDefinition((Map<String, Object>) typeJson);
+
+ // execute
+ TypeDefinition typeOut = service.createType(repositoryId, typeIn, null);
+ JSONObject jsonType = JSONConverter.convert(typeOut);
+
+ // set headers
+ response.setStatus(HttpServletResponse.SC_CREATED);
+ response.setHeader("Location", compileTypeLocationUrl(request, repositoryId, typeOut.getId()));
- response.setStatus(HttpServletResponse.SC_OK);
- BrowserBindingUtils.writeJSON(jsonType, request, response);
+ writeJSON(jsonType, request, response);
+ }
}
/**
* updateType.
*/
- public static void updateType(CallContext context, CmisService service, String repositoryId,
- HttpServletRequest request, HttpServletResponse response) throws Exception {
- // get parameters
- String typeStr = getStringParameter(request, CONTROL_TYPE);
- if (typeStr == null) {
- throw new CmisInvalidArgumentException("Type definition missing!");
- }
-
- // convert type definition
- JSONParser parser = new JSONParser();
- Object typeJson = parser.parse(typeStr);
- if (!(typeJson instanceof Map)) {
- throw new CmisInvalidArgumentException("Invalid type definition!");
- }
-
- @SuppressWarnings("unchecked")
- TypeDefinition typeIn = JSONConverter.convertTypeDefinition((Map<String, Object>) typeJson);
-
- // execute
- TypeDefinition typeOut = service.updateType(repositoryId, typeIn, null);
- JSONObject jsonType = JSONConverter.convert(typeOut);
+ public static class UpdateType extends AbstractBrowserServiceCall {
+ public void serve(CallContext context, CmisService service, String repositoryId, HttpServletRequest request,
+ HttpServletResponse response) throws Exception {
+ // get parameters
+ String typeStr = getStringParameter(request, CONTROL_TYPE);
+ if (typeStr == null) {
+ throw new CmisInvalidArgumentException("Type definition missing!");
+ }
+
+ // convert type definition
+ JSONParser parser = new JSONParser();
+ Object typeJson = parser.parse(typeStr);
+ if (!(typeJson instanceof Map)) {
+ throw new CmisInvalidArgumentException("Invalid type definition!");
+ }
- response.setStatus(HttpServletResponse.SC_OK);
- BrowserBindingUtils.writeJSON(jsonType, request, response);
+ @SuppressWarnings("unchecked")
+ TypeDefinition typeIn = JSONConverter.convertTypeDefinition((Map<String, Object>) typeJson);
+
+ // execute
+ TypeDefinition typeOut = service.updateType(repositoryId, typeIn, null);
+ JSONObject jsonType = JSONConverter.convert(typeOut);
+
+ response.setStatus(HttpServletResponse.SC_OK);
+ writeJSON(jsonType, request, response);
+ }
}
/**
* deleteType.
*/
- public static void deleteType(CallContext context, CmisService service, String repositoryId,
- HttpServletRequest request, HttpServletResponse response) throws Exception {
- // get parameters
- String typeId = getStringParameter(request, CONTROL_TYPE_ID);
+ public static class DeleteType extends AbstractBrowserServiceCall {
+ public void serve(CallContext context, CmisService service, String repositoryId, HttpServletRequest request,
+ HttpServletResponse response) throws Exception {
+ // get parameters
+ String typeId = getStringParameter(request, CONTROL_TYPE_ID);
- service.deleteType(repositoryId, typeId, null);
+ service.deleteType(repositoryId, typeId, null);
- response.setStatus(HttpServletResponse.SC_OK);
- writeEmpty(request, response);
+ response.setStatus(HttpServletResponse.SC_OK);
+ writeEmpty(request, response);
+ }
}
}
Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/VersioningService.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/VersioningService.java?rev=1481420&r1=1481419&r2=1481420&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/VersioningService.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/VersioningService.java Sat May 11 21:19:48 2013
@@ -23,25 +23,6 @@ import static org.apache.chemistry.openc
import static org.apache.chemistry.opencmis.commons.impl.Constants.PARAM_FILTER;
import static org.apache.chemistry.opencmis.commons.impl.Constants.PARAM_MAJOR;
import static org.apache.chemistry.opencmis.commons.impl.Constants.PARAM_TOKEN;
-import static org.apache.chemistry.opencmis.server.impl.atompub.AtomPubUtils.RESOURCE_CONTENT;
-import static org.apache.chemistry.opencmis.server.impl.atompub.AtomPubUtils.compileBaseUrl;
-import static org.apache.chemistry.opencmis.server.impl.atompub.AtomPubUtils.compileUrl;
-import static org.apache.chemistry.opencmis.server.impl.browser.BrowserBindingUtils.CONTEXT_OBJECT_ID;
-import static org.apache.chemistry.opencmis.server.impl.browser.BrowserBindingUtils.CONTEXT_OBJECT_TYPE_ID;
-import static org.apache.chemistry.opencmis.server.impl.browser.BrowserBindingUtils.closeContentStream;
-import static org.apache.chemistry.opencmis.server.impl.browser.BrowserBindingUtils.createAddAcl;
-import static org.apache.chemistry.opencmis.server.impl.browser.BrowserBindingUtils.createContentStream;
-import static org.apache.chemistry.opencmis.server.impl.browser.BrowserBindingUtils.createCookieValue;
-import static org.apache.chemistry.opencmis.server.impl.browser.BrowserBindingUtils.createPolicies;
-import static org.apache.chemistry.opencmis.server.impl.browser.BrowserBindingUtils.createRemoveAcl;
-import static org.apache.chemistry.opencmis.server.impl.browser.BrowserBindingUtils.createUpdateProperties;
-import static org.apache.chemistry.opencmis.server.impl.browser.BrowserBindingUtils.getSimpleObject;
-import static org.apache.chemistry.opencmis.server.impl.browser.BrowserBindingUtils.setCookie;
-import static org.apache.chemistry.opencmis.server.impl.browser.BrowserBindingUtils.setStatus;
-import static org.apache.chemistry.opencmis.server.impl.browser.BrowserBindingUtils.writeEmpty;
-import static org.apache.chemistry.opencmis.server.impl.browser.BrowserBindingUtils.writeJSON;
-import static org.apache.chemistry.opencmis.server.shared.HttpUtils.getBooleanParameter;
-import static org.apache.chemistry.opencmis.server.shared.HttpUtils.getStringParameter;
import java.util.Collections;
import java.util.List;
@@ -64,135 +45,140 @@ import org.apache.chemistry.opencmis.com
/**
* Versioning Service operations.
*/
-public final class VersioningService {
-
- private VersioningService() {
- }
+public class VersioningService {
/**
* checkOut.
*/
- public static void checkOut(CallContext context, CmisService service, String repositoryId,
- HttpServletRequest request, HttpServletResponse response) throws Exception {
- // get parameters
- String objectId = (String) context.get(CONTEXT_OBJECT_ID);
- String token = getStringParameter(request, PARAM_TOKEN);
- boolean succinct = getBooleanParameter(request, Constants.CONTROL_SUCCINCT, false);
-
- // execute
- Holder<String> checkOutId = new Holder<String>(objectId);
- service.checkOut(repositoryId, checkOutId, null, null);
-
- ObjectData object = getSimpleObject(service, repositoryId, checkOutId.getValue());
- if (object == null) {
- throw new CmisRuntimeException("PWC is null!");
- }
-
- // return object
- TypeCache typeCache = new ServerTypeCacheImpl(repositoryId, service);
- JSONObject jsonObject = JSONConverter.convert(object, typeCache, JSONConverter.PropertyMode.OBJECT, succinct);
-
- // set headers
- String location = compileUrl(compileBaseUrl(request, repositoryId), RESOURCE_CONTENT, object.getId());
+ public static class CheckOut extends AbstractBrowserServiceCall {
+ public void serve(CallContext context, CmisService service, String repositoryId, HttpServletRequest request,
+ HttpServletResponse response) throws Exception {
+ // get parameters
+ String objectId = ((BrowserCallContextImpl) context).getObjectId();
+ String token = getStringParameter(request, PARAM_TOKEN);
+ boolean succinct = getBooleanParameter(request, Constants.CONTROL_SUCCINCT, false);
+
+ // execute
+ Holder<String> checkOutId = new Holder<String>(objectId);
+ service.checkOut(repositoryId, checkOutId, null, null);
+
+ ObjectData object = getSimpleObject(service, repositoryId, checkOutId.getValue());
+ if (object == null) {
+ throw new CmisRuntimeException("PWC is null!");
+ }
+
+ // return object
+ TypeCache typeCache = new ServerTypeCacheImpl(repositoryId, service);
+ JSONObject jsonObject = JSONConverter.convert(object, typeCache, JSONConverter.PropertyMode.OBJECT,
+ succinct);
+
+ // set headers
+ setStatus(request, response, HttpServletResponse.SC_CREATED);
+ response.setHeader("Location", compileObjectLocationUrl(request, repositoryId, object.getId()));
- setStatus(request, response, HttpServletResponse.SC_CREATED);
- response.setHeader("Location", location);
+ setCookie(request, response, repositoryId, token,
+ createCookieValue(HttpServletResponse.SC_CREATED, object.getId(), null, null));
- setCookie(request, response, repositoryId, token,
- createCookieValue(HttpServletResponse.SC_CREATED, object.getId(), null, null));
-
- writeJSON(jsonObject, request, response);
+ writeJSON(jsonObject, request, response);
+ }
}
/**
* checkOut.
*/
- public static void cancelCheckOut(CallContext context, CmisService service, String repositoryId,
- HttpServletRequest request, HttpServletResponse response) throws Exception {
- // get parameters
- String objectId = (String) context.get(CONTEXT_OBJECT_ID);
+ public static class CancelCheckOut extends AbstractBrowserServiceCall {
+ public void serve(CallContext context, CmisService service, String repositoryId, HttpServletRequest request,
+ HttpServletResponse response) throws Exception {
+ // get parameters
+ String objectId = ((BrowserCallContextImpl) context).getObjectId();
- // execute
- service.cancelCheckOut(repositoryId, objectId, null);
+ // execute
+ service.cancelCheckOut(repositoryId, objectId, null);
- response.setStatus(HttpServletResponse.SC_OK);
- writeEmpty(request, response);
+ response.setStatus(HttpServletResponse.SC_OK);
+ writeEmpty(request, response);
+ }
}
/**
* checkIn.
*/
- public static void checkIn(CallContext context, CmisService service, String repositoryId,
- HttpServletRequest request, HttpServletResponse response) throws Exception {
- // get parameters
- String objectId = (String) context.get(CONTEXT_OBJECT_ID);
- String typeId = (String) context.get(CONTEXT_OBJECT_TYPE_ID);
- Boolean major = getBooleanParameter(request, PARAM_MAJOR);
- String checkinComment = getStringParameter(request, PARAM_CHECKIN_COMMENT);
- String token = getStringParameter(request, PARAM_TOKEN);
- boolean succinct = getBooleanParameter(request, Constants.CONTROL_SUCCINCT, false);
-
- // execute
- ControlParser cp = new ControlParser(request);
- TypeCache typeCache = new ServerTypeCacheImpl(repositoryId, service);
- Holder<String> objectIdHolder = new Holder<String>(objectId);
- ContentStream contentStream = createContentStream(request);
-
- try {
- service.checkIn(repositoryId, objectIdHolder, major,
- createUpdateProperties(cp, typeId, null, Collections.singletonList(objectId), typeCache),
- contentStream, checkinComment, createPolicies(cp), createAddAcl(cp), createRemoveAcl(cp), null);
- } finally {
- closeContentStream(contentStream);
- }
+ public static class CheckIn extends AbstractBrowserServiceCall {
+ public void serve(CallContext context, CmisService service, String repositoryId, HttpServletRequest request,
+ HttpServletResponse response) throws Exception {
+ // get parameters
+ String objectId = ((BrowserCallContextImpl) context).getObjectId();
+ String typeId = ((BrowserCallContextImpl) context).getTypeId();
+ Boolean major = getBooleanParameter(request, PARAM_MAJOR);
+ String checkinComment = getStringParameter(request, PARAM_CHECKIN_COMMENT);
+ String token = getStringParameter(request, PARAM_TOKEN);
+ boolean succinct = getBooleanParameter(request, Constants.CONTROL_SUCCINCT, false);
+
+ // execute
+ ControlParser cp = new ControlParser(request);
+ TypeCache typeCache = new ServerTypeCacheImpl(repositoryId, service);
+ Holder<String> objectIdHolder = new Holder<String>(objectId);
+ ContentStream contentStream = createContentStream(request);
+
+ try {
+ service.checkIn(repositoryId, objectIdHolder, major,
+ createUpdateProperties(cp, typeId, null, Collections.singletonList(objectId), typeCache),
+ contentStream, checkinComment, createPolicies(cp), createAddAcl(cp), createRemoveAcl(cp), null);
+ } finally {
+ closeContentStream(contentStream);
+ }
+
+ String newObjectId = (objectIdHolder.getValue() == null ? objectId : objectIdHolder.getValue());
+
+ ObjectData object = getSimpleObject(service, repositoryId, newObjectId);
+ if (object == null) {
+ throw new CmisRuntimeException("New version is null!");
+ }
+
+ // return object
+ JSONObject jsonObject = JSONConverter.convert(object, typeCache, JSONConverter.PropertyMode.OBJECT,
+ succinct);
+
+ // set headers
+ setStatus(request, response, HttpServletResponse.SC_CREATED);
+ response.setHeader("Location", compileObjectLocationUrl(request, repositoryId, object.getId()));
- String newObjectId = (objectIdHolder.getValue() == null ? objectId : objectIdHolder.getValue());
+ setCookie(request, response, repositoryId, token,
+ createCookieValue(HttpServletResponse.SC_CREATED, object.getId(), null, null));
- ObjectData object = getSimpleObject(service, repositoryId, newObjectId);
- if (object == null) {
- throw new CmisRuntimeException("New version is null!");
+ writeJSON(jsonObject, request, response);
}
-
- // return object
- JSONObject jsonObject = JSONConverter.convert(object, typeCache, JSONConverter.PropertyMode.OBJECT, succinct);
-
- String location = compileUrl(compileBaseUrl(request, repositoryId), RESOURCE_CONTENT, object.getId());
-
- setStatus(request, response, HttpServletResponse.SC_CREATED);
- response.setHeader("Location", location);
-
- setCookie(request, response, repositoryId, token,
- createCookieValue(HttpServletResponse.SC_CREATED, object.getId(), null, null));
-
- writeJSON(jsonObject, request, response);
}
/**
* getAllVersions.
*/
- public static void getAllVersions(CallContext context, CmisService service, String repositoryId,
- HttpServletRequest request, HttpServletResponse response) throws Exception {
- // get parameters
- String objectId = (String) context.get(CONTEXT_OBJECT_ID);
- String filter = getStringParameter(request, PARAM_FILTER);
- Boolean includeAllowableActions = getBooleanParameter(request, PARAM_ALLOWABLE_ACTIONS);
- boolean succinct = getBooleanParameter(request, Constants.PARAM_SUCCINCT, false);
-
- // execute
- List<ObjectData> versions = service.getAllVersions(repositoryId, objectId, null, filter,
- includeAllowableActions, null);
-
- if (versions == null) {
- throw new CmisRuntimeException("Versions are null!");
- }
+ public static class GetAllVersions extends AbstractBrowserServiceCall {
+ public void serve(CallContext context, CmisService service, String repositoryId, HttpServletRequest request,
+ HttpServletResponse response) throws Exception {
+ // get parameters
+ String objectId = ((BrowserCallContextImpl) context).getObjectId();
+ String filter = getStringParameter(request, PARAM_FILTER);
+ Boolean includeAllowableActions = getBooleanParameter(request, PARAM_ALLOWABLE_ACTIONS);
+ boolean succinct = getBooleanParameter(request, Constants.PARAM_SUCCINCT, false);
+
+ // execute
+ List<ObjectData> versions = service.getAllVersions(repositoryId, objectId, null, filter,
+ includeAllowableActions, null);
+
+ if (versions == null) {
+ throw new CmisRuntimeException("Versions are null!");
+ }
+
+ TypeCache typeCache = new ServerTypeCacheImpl(repositoryId, service);
+ JSONArray jsonVersions = new JSONArray();
+ for (ObjectData version : versions) {
+ jsonVersions
+ .add(JSONConverter.convert(version, typeCache, JSONConverter.PropertyMode.OBJECT, succinct));
+ }
- TypeCache typeCache = new ServerTypeCacheImpl(repositoryId, service);
- JSONArray jsonVersions = new JSONArray();
- for (ObjectData version : versions) {
- jsonVersions.add(JSONConverter.convert(version, typeCache, JSONConverter.PropertyMode.OBJECT, succinct));
+ response.setStatus(HttpServletResponse.SC_OK);
+ writeJSON(jsonVersions, request, response);
}
-
- response.setStatus(HttpServletResponse.SC_OK);
- writeJSON(jsonVersions, request, response);
}
}
Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/token/AbstractSimpleTokenHandler.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/token/AbstractSimpleTokenHandler.java?rev=1481420&r1=1481419&r2=1481420&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/token/AbstractSimpleTokenHandler.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/token/AbstractSimpleTokenHandler.java Sat May 11 21:19:48 2013
@@ -35,9 +35,11 @@ import org.apache.chemistry.opencmis.com
import org.apache.chemistry.opencmis.commons.impl.json.JSONArray;
import org.apache.chemistry.opencmis.commons.impl.json.JSONObject;
import org.apache.chemistry.opencmis.commons.impl.json.JSONStreamAware;
+import org.apache.chemistry.opencmis.commons.server.CallContext;
+import org.apache.chemistry.opencmis.commons.server.CmisService;
import org.apache.chemistry.opencmis.commons.server.CmisServiceFactory;
import org.apache.chemistry.opencmis.server.impl.CmisRepositoryContextListener;
-import org.apache.chemistry.opencmis.server.impl.browser.BrowserBindingUtils;
+import org.apache.chemistry.opencmis.server.impl.browser.AbstractBrowserServiceCall;
public abstract class AbstractSimpleTokenHandler implements TokenHandler, Serializable {
@@ -61,6 +63,8 @@ public abstract class AbstractSimpleToke
private static final String LOGIN_LOGOUT = "logout";
private static final String LOGIN_TOKEN = "token";
+ private static final UrlServiceCall URL_SERVICE_CALL = new UrlServiceCall();
+
public void service(ServletContext servletContext, HttpServletRequest request, HttpServletResponse response) {
String repositoryId = null; // TODO: determine repository id
@@ -127,7 +131,7 @@ public abstract class AbstractSimpleToke
protected void sendJavaScript(ServletContext servletContext, HttpServletRequest request,
HttpServletResponse response, String repositoryId) throws IOException {
- UrlBuilder baseUrl = BrowserBindingUtils.compileBaseUrl(request, repositoryId);
+ UrlBuilder baseUrl = URL_SERVICE_CALL.compileBaseUrl(request, repositoryId);
URL url = new URL(baseUrl.toString());
request.setAttribute(ATTR_PREFIX + "domain", encodeJavaScriptString(url.getProtocol() + "://" + url.getHost()
@@ -156,7 +160,7 @@ public abstract class AbstractSimpleToke
request.setAttribute(
ATTR_PREFIX + "loginUrl",
- encodeJavaScriptString(BrowserBindingUtils.compileBaseUrl(request, repositoryId)
+ encodeJavaScriptString(URL_SERVICE_CALL.compileBaseUrl(request, repositoryId)
.addParameter(PARAM_LOGIN, "").toString()));
RequestDispatcher dispatcher = servletContext.getRequestDispatcher(JSP_PATH + JSP_IFRAME);
@@ -267,7 +271,7 @@ public abstract class AbstractSimpleToke
SimpleTokenHandlerSessionHelper.setLoginKey(request, loginKey, formKey, appURL);
- String formURL = encodeJavaScriptString(BrowserBindingUtils.compileBaseUrl(request, repositoryId)
+ String formURL = encodeJavaScriptString(URL_SERVICE_CALL.compileBaseUrl(request, repositoryId)
.addParameter(PARAM_LOGIN, LOGIN_LOGIN)
.addParameter(SimpleTokenHandlerSessionHelper.PARAM_KEY, formKey).toString());
@@ -395,4 +399,12 @@ public abstract class AbstractSimpleToke
return sb.toString();
}
+
+ static class UrlServiceCall extends AbstractBrowserServiceCall {
+ public void serve(CallContext context, CmisService service, String repositoryId, HttpServletRequest request,
+ HttpServletResponse response) throws Exception {
+ // no implementation
+
+ }
+ }
}
Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/token/SimpleTokenHandler.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/token/SimpleTokenHandler.java?rev=1481420&r1=1481419&r2=1481420&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/token/SimpleTokenHandler.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/token/SimpleTokenHandler.java Sat May 11 21:19:48 2013
@@ -22,6 +22,7 @@ import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import org.apache.chemistry.opencmis.commons.enums.CmisVersion;
import org.apache.chemistry.opencmis.commons.server.CallContext;
import org.apache.chemistry.opencmis.commons.server.CmisService;
import org.apache.chemistry.opencmis.commons.server.CmisServiceFactory;
@@ -39,7 +40,8 @@ public class SimpleTokenHandler extends
CmisServiceFactory factory = getCmisServiceFactory(servletContext);
// build a call context
- CallContextImpl context = new CallContextImpl(CallContext.BINDING_BROWSER, null, false);
+ CallContextImpl context = new CallContextImpl(CallContext.BINDING_BROWSER, CmisVersion.CMIS_1_1, null, null,
+ null, null, null, null);
context.put(CallContext.USERNAME, user);
context.put(CallContext.PASSWORD, password);
Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/webservices/AbstractService.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/webservices/AbstractService.java?rev=1481420&r1=1481419&r2=1481420&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/webservices/AbstractService.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/webservices/AbstractService.java Sat May 11 21:19:48 2013
@@ -89,58 +89,37 @@ public abstract class AbstractService {
*/
@SuppressWarnings("unchecked")
protected CallContext createContext(WebServiceContext wsContext, CmisServiceFactory factory, String repositoryId) {
- CallContextImpl context = new CallContextImpl(CallContext.BINDING_WEBSERVICES, repositoryId, false);
-
ServletContext servletContext = (ServletContext) wsContext.getMessageContext().get(
MessageContext.SERVLET_CONTEXT);
-
- MessageContext mc = wsContext.getMessageContext();
- Map<String, String> callContextMap = (Map<String, String>) mc.get(CALL_CONTEXT_MAP);
- if (callContextMap != null) {
- for (Map.Entry<String, String> e : callContextMap.entrySet()) {
- context.put(e.getKey(), e.getValue());
- }
- }
-
- context.put(CallContext.SERVLET_CONTEXT, servletContext);
-
HttpServletRequest request = (HttpServletRequest) wsContext.getMessageContext().get(
MessageContext.SERVLET_REQUEST);
- context.put(CallContext.HTTP_SERVLET_REQUEST, request);
-
- context.put(CallContext.CMIS_VERSION, request.getAttribute(CmisWebServicesServlet.CMIS_VERSION));
-
HttpServletResponse response = (HttpServletResponse) wsContext.getMessageContext().get(
MessageContext.SERVLET_RESPONSE);
- context.put(CallContext.HTTP_SERVLET_RESPONSE, response);
+
+ CmisVersion cmisVersion = (CmisVersion) request.getAttribute(CmisWebServicesServlet.CMIS_VERSION);
+
+ CallContextImpl context = new CallContextImpl(CallContext.BINDING_WEBSERVICES, cmisVersion, repositoryId,
+ servletContext, request, response, factory, null);
Map<String, List<String>> headers = (Map<String, List<String>>) wsContext.getMessageContext().get(
MessageContext.HTTP_REQUEST_HEADERS);
if (headers != null) {
for (Map.Entry<String, List<String>> header : headers.entrySet()) {
- if (header.getKey().equalsIgnoreCase("Accept-Language") && (header.getValue() != null)) {
- String acceptLanguage = header.getValue().get(0);
- if (acceptLanguage != null) {
- String[] locale = acceptLanguage.split("-");
- context.put(CallContext.LOCALE_ISO639_LANGUAGE, locale[0].trim());
- if (locale.length > 1) {
- int x = locale[1].indexOf(',');
- if (x == -1) {
- context.put(CallContext.LOCALE_ISO3166_COUNTRY, locale[1].trim());
- } else {
- context.put(CallContext.LOCALE_ISO3166_COUNTRY, locale[1].substring(0, x).trim());
- }
- }
- }
+ if (header.getKey().equalsIgnoreCase("Accept-Language") && header.getValue() != null
+ && !header.getValue().isEmpty()) {
+ context.setAcceptLanguage(header.getValue().get(0));
break;
}
}
}
- context.put(CallContext.TEMP_DIR, factory.getTempDirectory());
- context.put(CallContext.MEMORY_THRESHOLD, factory.getMemoryThreshold());
- context.put(CallContext.MAX_CONTENT_SIZE, -1);
- context.put(CallContext.ENCRYPT_TEMP_FILE, false);
+ MessageContext mc = wsContext.getMessageContext();
+ Map<String, String> callContextMap = (Map<String, String>) mc.get(CALL_CONTEXT_MAP);
+ if (callContextMap != null) {
+ for (Map.Entry<String, String> e : callContextMap.entrySet()) {
+ context.put(e.getKey(), e.getValue());
+ }
+ }
return context;
}
Added: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/AbstractCmisHttpServlet.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/AbstractCmisHttpServlet.java?rev=1481420&view=auto
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/AbstractCmisHttpServlet.java (added)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/AbstractCmisHttpServlet.java Sat May 11 21:19:48 2013
@@ -0,0 +1,160 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.chemistry.opencmis.server.shared;
+
+import java.util.Map;
+
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.chemistry.opencmis.commons.enums.CmisVersion;
+import org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException;
+import org.apache.chemistry.opencmis.commons.impl.ClassLoaderUtil;
+import org.apache.chemistry.opencmis.commons.server.CallContext;
+import org.apache.chemistry.opencmis.commons.server.CmisServiceFactory;
+import org.apache.chemistry.opencmis.server.impl.CallContextImpl;
+import org.apache.chemistry.opencmis.server.impl.CmisRepositoryContextListener;
+import org.apache.chemistry.opencmis.server.impl.browser.BrowserCallContextImpl;
+
+public abstract class AbstractCmisHttpServlet extends HttpServlet {
+
+ public static final String PARAM_CALL_CONTEXT_HANDLER = "callContextHandler";
+ public static final String PARAM_CMIS_VERSION = "cmisVersion";
+
+ private static final long serialVersionUID = 1L;
+
+ private CmisServiceFactory factory;
+ private String binding;
+ private CmisVersion cmisVersion;
+ private CallContextHandler callContextHandler;
+ private ThresholdOutputStreamFactory streamFactory;
+
+ @Override
+ public void init(ServletConfig config) throws ServletException {
+ super.init(config);
+
+ // initialize the call context handler
+ callContextHandler = null;
+ String callContextHandlerClass = config.getInitParameter(PARAM_CALL_CONTEXT_HANDLER);
+ if (callContextHandlerClass != null) {
+ try {
+ callContextHandler = (CallContextHandler) ClassLoaderUtil.loadClass(callContextHandlerClass)
+ .newInstance();
+ } catch (Exception e) {
+ throw new ServletException("Could not load call context handler: " + e, e);
+ }
+ }
+
+ // get service factory
+ factory = (CmisServiceFactory) config.getServletContext().getAttribute(
+ CmisRepositoryContextListener.SERVICES_FACTORY);
+
+ if (factory == null) {
+ throw new CmisRuntimeException("Service factory not available! Configuration problem?");
+ }
+
+ // set up stream factory
+ streamFactory = ThresholdOutputStreamFactory.newInstance(factory.getTempDirectory(),
+ factory.getMemoryThreshold(), factory.getMaxContentSize(), factory.encryptTempFiles());
+ }
+
+ /**
+ * Sets the binding.
+ */
+ protected void setBinding(String binding) {
+ this.binding = binding;
+ }
+
+ /**
+ * Returns the CMIS version configured for this servlet.
+ */
+ protected CmisVersion getCmisVersion() {
+ return cmisVersion;
+ }
+
+ protected void setCmisVersion(CmisVersion cmisVersion) {
+ this.cmisVersion = cmisVersion;
+ }
+
+ /**
+ * Returns the {@link CmisServiceFactory}.
+ */
+ protected CmisServiceFactory getServiceFactory() {
+ return factory;
+ }
+
+ /**
+ * Return the {@link CallContextHandler}
+ */
+ protected CallContextHandler getCallContextHandler() {
+ return callContextHandler;
+ }
+
+ /**
+ * Returns the {@link ThresholdOutputStreamFactory}.
+ */
+ protected ThresholdOutputStreamFactory getThresholdOutputStreamFactory() {
+ return streamFactory;
+ }
+
+ /**
+ * Creates a {@link CallContext} object from a servlet request.
+ */
+ protected CallContext createContext(ServletContext servletContext, HttpServletRequest request,
+ HttpServletResponse response) {
+ String[] pathFragments = HttpUtils.splitPath(request);
+
+ String repositoryId = null;
+ if (pathFragments.length > 0) {
+ repositoryId = pathFragments[0];
+ }
+
+ CallContextImpl context = null;
+
+ if (CallContext.BINDING_BROWSER.equals(binding)) {
+ context = new BrowserCallContextImpl(binding, cmisVersion, repositoryId, servletContext, request, response,
+ factory, streamFactory);
+ } else {
+ context = new CallContextImpl(binding, cmisVersion, repositoryId, servletContext, request, response,
+ factory, streamFactory);
+ }
+
+ // decode range
+ context.setRange(request.getHeader("Range"));
+
+ // get locale
+ context.setAcceptLanguage(request.getHeader("Accept-Language"));
+
+ // call call context handler
+ if (callContextHandler != null) {
+ Map<String, String> callContextMap = callContextHandler.getCallContextMap(request);
+ if (callContextMap != null) {
+ for (Map.Entry<String, String> e : callContextMap.entrySet()) {
+ context.put(e.getKey(), e.getValue());
+ }
+ }
+ }
+
+ return context;
+ }
+}
Added: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/AbstractServiceCall.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/AbstractServiceCall.java?rev=1481420&view=auto
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/AbstractServiceCall.java (added)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/AbstractServiceCall.java Sat May 11 21:19:48 2013
@@ -0,0 +1,213 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.chemistry.opencmis.server.shared;
+
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.math.BigInteger;
+import java.util.Date;
+import java.util.GregorianCalendar;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.chemistry.opencmis.commons.data.CacheHeaderContentStream;
+import org.apache.chemistry.opencmis.commons.data.ContentLengthContentStream;
+import org.apache.chemistry.opencmis.commons.data.ContentStream;
+import org.apache.chemistry.opencmis.commons.data.LastModifiedContentStream;
+import org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException;
+import org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException;
+import org.apache.chemistry.opencmis.commons.impl.DateTimeHelper;
+
+public abstract class AbstractServiceCall implements ServiceCall {
+
+ /**
+ * Extracts a string parameter.
+ */
+ public String getStringParameter(HttpServletRequest request, String name) {
+ return HttpUtils.getStringParameter(request, name);
+ }
+
+ /**
+ * Extracts a boolean parameter (with default).
+ */
+ public boolean getBooleanParameter(HttpServletRequest request, String name, boolean def) {
+ String value = getStringParameter(request, name);
+ if ((value == null) || (value.length() == 0)) {
+ return def;
+ }
+
+ return Boolean.valueOf(value);
+ }
+
+ /**
+ * Extracts a boolean parameter.
+ */
+ public Boolean getBooleanParameter(HttpServletRequest request, String name) {
+ String value = getStringParameter(request, name);
+ if ((value == null) || (value.length() == 0)) {
+ return null;
+ }
+
+ return Boolean.valueOf(value);
+ }
+
+ /**
+ * Extracts an integer parameter (with default).
+ */
+ public BigInteger getBigIntegerParameter(HttpServletRequest request, String name, long def) {
+ BigInteger result = getBigIntegerParameter(request, name);
+ if (result == null) {
+ result = BigInteger.valueOf(def);
+ }
+
+ return result;
+ }
+
+ /**
+ * Extracts an integer parameter.
+ */
+ public BigInteger getBigIntegerParameter(HttpServletRequest request, String name) {
+ String value = getStringParameter(request, name);
+ if ((value == null) || (value.length() == 0)) {
+ return null;
+ }
+
+ try {
+ return new BigInteger(value);
+ } catch (Exception e) {
+ throw new CmisInvalidArgumentException("Invalid parameter '" + name + "'!");
+ }
+ }
+
+ /**
+ * Extracts an enum parameter.
+ */
+ @SuppressWarnings("unchecked")
+ public <T> T getEnumParameter(HttpServletRequest request, String name, Class<T> clazz) {
+ String value = getStringParameter(request, name);
+ if ((value == null) || (value.length() == 0)) {
+ return null;
+ }
+
+ try {
+ Method m = clazz.getMethod("fromValue", new Class[] { String.class });
+ return (T) m.invoke(null, new Object[] { value });
+ } catch (Exception e) {
+ if (e instanceof InvocationTargetException && e.getCause() instanceof IllegalArgumentException) {
+ throw new CmisInvalidArgumentException("Invalid parameter '" + name + "'!");
+ }
+
+ throw new CmisRuntimeException(e.getMessage(), e);
+ }
+ }
+
+ /**
+ * Closes a content stream.
+ */
+ public void closeContentStream(ContentStream contentStream) {
+ if (contentStream != null && contentStream.getStream() != null) {
+ try {
+ contentStream.getStream().close();
+ } catch (IOException e) {
+ // we tried our best
+ }
+ }
+ }
+
+ /**
+ * Sets certain HTTP headers if the server implementation requested them.
+ *
+ * @return <code>true</code> if the request has been served by this method
+ * (e.g. status code 304 was send), <code>false</code> if the
+ * content should be served.
+ */
+ public boolean sendContentStreamHeaders(ContentStream content, HttpServletRequest request,
+ HttpServletResponse response) throws IOException {
+
+ // check if Last-Modified header should be set
+ if (content instanceof LastModifiedContentStream) {
+ GregorianCalendar lastModified = ((LastModifiedContentStream) content).getLastModified();
+ if (lastModified != null) {
+ long lastModifiedSecs = (long) Math.floor((double) lastModified.getTimeInMillis() / 1000);
+
+ Date modifiedSince = DateTimeHelper.parseHttpDateTime(request.getHeader("If-Modified-Since"));
+ if (modifiedSince != null) {
+ long modifiedSinceSecs = (long) Math.floor((double) modifiedSince.getTime() / 1000);
+
+ if (modifiedSinceSecs >= lastModifiedSecs) {
+ // close stream
+ content.getStream().close();
+
+ // send not modified status code
+ response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
+ response.setContentLength(0);
+ return true;
+ }
+ }
+
+ response.setHeader("Last-Modified", DateTimeHelper.formatHttpDateTime(lastModifiedSecs * 1000));
+ }
+ }
+
+ // check if cache headers should be set
+ if (content instanceof CacheHeaderContentStream) {
+ CacheHeaderContentStream chcs = (CacheHeaderContentStream) content;
+
+ if (chcs.getETag() != null) {
+ String etag = request.getHeader("If-None-Match");
+ if (etag != null && !etag.equals("*")) {
+ if (etag.length() > 2 && etag.startsWith("\"") && etag.endsWith("\"")) {
+ etag = etag.substring(1, etag.length() - 1);
+ }
+
+ if (chcs.getETag().equals(etag)) {
+ // close stream
+ content.getStream().close();
+
+ // send not modified status code
+ response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
+ response.setContentLength(0);
+ return true;
+ }
+ }
+
+ response.setHeader("ETag", "\"" + chcs.getETag() + "\"");
+ }
+
+ if (chcs.getCacheControl() != null) {
+ response.setHeader("Cache-Control", chcs.getCacheControl());
+ }
+
+ if (chcs.getExpires() != null) {
+ response.setHeader("Expires", DateTimeHelper.formatHttpDateTime(chcs.getExpires()));
+ }
+ }
+
+ // check if Content-Length header should be set
+ if (content instanceof ContentLengthContentStream) {
+ if (content.getBigLength() != null && content.getBigLength().signum() >= 0) {
+ response.setHeader("Content-Length", content.getBigLength().toString());
+ }
+ }
+
+ return false;
+ }
+}
Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/Dispatcher.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/Dispatcher.java?rev=1481420&r1=1481419&r2=1481420&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/Dispatcher.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/Dispatcher.java Sat May 11 21:19:48 2013
@@ -19,8 +19,6 @@
package org.apache.chemistry.opencmis.server.shared;
import java.io.Serializable;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
import java.util.HashMap;
import javax.servlet.http.HttpServletRequest;
@@ -50,7 +48,7 @@ public class Dispatcher implements Seria
private static final Logger LOG = LoggerFactory.getLogger(Dispatcher.class.getName());
private final boolean caseSensitive;
- private final HashMap<String, Method> methodMap;
+ private final HashMap<String, ServiceCall> serviceCallMap;
public Dispatcher() {
this(true);
@@ -58,48 +56,39 @@ public class Dispatcher implements Seria
public Dispatcher(boolean caseSensitive) {
this.caseSensitive = caseSensitive;
- methodMap = new HashMap<String, Method>();
+ serviceCallMap = new HashMap<String, ServiceCall>();
}
/**
- * Connects a resource and HTTP method with a class and a class method.
+ * Connects a resource and HTTP method with an object that handles the call.
*/
- public synchronized void addResource(String resource, String httpMethod, Class<?> clazz, String classmethod)
- throws NoSuchMethodException {
-
- Method m = clazz.getMethod(classmethod, CallContext.class, CmisService.class, String.class,
- HttpServletRequest.class, HttpServletResponse.class);
-
- methodMap.put(getKey(resource, httpMethod), m);
+ public void addResource(String resource, String httpMethod, ServiceCall serviceCall) {
+ serviceCallMap.put(getKey(resource, httpMethod), serviceCall);
}
/**
- * Find the appropriate method an call it.
+ * Handles the a call.
*
- * @return <code>true</code> if the method was found, <code>false</code>
- * otherwise.
+ * @return <code>true</code> if an object was found that can handle the
+ * request, <code>false</code> otherwise.
*/
public boolean dispatch(String resource, String httpMethod, CallContext context, CmisService service,
String repositoryId, HttpServletRequest request, HttpServletResponse response) {
- Method m = methodMap.get(getKey(resource, httpMethod));
- if (m == null) {
+ ServiceCall serviceCall = serviceCallMap.get(getKey(resource, httpMethod));
+ if (serviceCall == null) {
return false;
}
if (LOG.isDebugEnabled()) {
- LOG.debug(repositoryId + " / " + resource + ", " + httpMethod + " -> " + m.getName());
+ LOG.debug(repositoryId + " / " + resource + ", " + httpMethod + " -> " + serviceCall.getClass().getName());
}
try {
- m.invoke(null, context, service, repositoryId, request, response);
- } 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);
- }
+ serviceCall.serve(context, service, repositoryId, request, response);
+ } catch (CmisBaseException ce) {
+ throw ce;
+ } catch (Exception e) {
+ throw new CmisRuntimeException(e.getMessage(), e);
}
return true;
Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/HttpUtils.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/HttpUtils.java?rev=1481420&r1=1481419&r2=1481420&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/HttpUtils.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/HttpUtils.java Sat May 11 21:19:48 2013
@@ -18,137 +18,36 @@
*/
package org.apache.chemistry.opencmis.server.shared;
-import java.io.IOException;
import java.io.UnsupportedEncodingException;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.math.BigInteger;
import java.net.URLDecoder;
-import java.util.Date;
-import java.util.GregorianCalendar;
-import java.util.Locale;
import java.util.Map;
-import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import org.apache.chemistry.opencmis.commons.data.CacheHeaderContentStream;
-import org.apache.chemistry.opencmis.commons.data.ContentLengthContentStream;
-import org.apache.chemistry.opencmis.commons.data.ContentStream;
-import org.apache.chemistry.opencmis.commons.data.LastModifiedContentStream;
-import org.apache.chemistry.opencmis.commons.enums.CmisVersion;
-import org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException;
import org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException;
-import org.apache.chemistry.opencmis.commons.impl.DateTimeHelper;
-import org.apache.chemistry.opencmis.commons.server.CallContext;
-import org.apache.chemistry.opencmis.server.impl.CallContextImpl;
-/**
- * Utility methods that are used by the AtomPub and Browser binding.
- */
-public final class HttpUtils {
-
- private HttpUtils() {
- }
+public class HttpUtils {
/**
- * Creates a {@link CallContext} object from a servlet request.
+ * Extracts a string parameter.
*/
- public static CallContext createContext(HttpServletRequest request, HttpServletResponse response,
- ServletContext servletContext, String binding, CmisVersion cmisVersion,
- CallContextHandler callContextHandler, ThresholdOutputStreamFactory streamFactory) {
- String[] pathFragments = splitPath(request);
-
- String repositoryId = null;
- if (pathFragments.length > 0) {
- repositoryId = pathFragments[0];
- }
-
- CallContextImpl context = new CallContextImpl(binding, repositoryId,
- CallContext.BINDING_ATOMPUB.equals(binding));
-
- // call call context handler
- if (callContextHandler != null) {
- Map<String, String> callContextMap = callContextHandler.getCallContextMap(request);
- if (callContextMap != null) {
- for (Map.Entry<String, String> e : callContextMap.entrySet()) {
- context.put(e.getKey(), e.getValue());
- }
- }
- }
-
- // servlet context and HTTP servlet request and response
- context.put(CallContext.SERVLET_CONTEXT, servletContext);
- context.put(CallContext.HTTP_SERVLET_REQUEST, request);
- context.put(CallContext.HTTP_SERVLET_RESPONSE, response);
-
- // CMIS version
- context.put(CallContext.CMIS_VERSION, cmisVersion);
-
- // content
- context.put(CallContext.TEMP_DIR, streamFactory.getTempDir());
- context.put(CallContext.MEMORY_THRESHOLD, streamFactory.getMemoryThreshold());
- context.put(CallContext.MAX_CONTENT_SIZE, streamFactory.getMaxContentSize());
- context.put(CallContext.ENCRYPT_TEMP_FILE, streamFactory.isEncrypted());
- context.put(CallContext.STREAM_FACTORY, streamFactory);
-
- // decode range
- String rangeHeader = request.getHeader("Range");
- if (rangeHeader != null) {
- rangeHeader = rangeHeader.trim().toLowerCase(Locale.ENGLISH);
-
- if (rangeHeader.length() > 6 && rangeHeader.startsWith("bytes=") && rangeHeader.indexOf(',') == -1
- && rangeHeader.charAt(6) != '-') {
- BigInteger offset = null;
- BigInteger length = null;
-
- int ds = rangeHeader.indexOf('-');
- if (ds > 6) {
- try {
- String firstBytePosStr = rangeHeader.substring(6, ds);
- if (firstBytePosStr.length() > 0) {
- offset = new BigInteger(firstBytePosStr);
- }
-
- if (!rangeHeader.endsWith("-")) {
- String lastBytePosStr = rangeHeader.substring(ds + 1);
- if (offset == null) {
- length = (new BigInteger(lastBytePosStr)).add(BigInteger.ONE);
- } else {
- length = (new BigInteger(lastBytePosStr)).subtract(offset).add(BigInteger.ONE);
- }
- }
-
- if (offset != null) {
- context.put(CallContext.OFFSET, offset);
- }
- if (length != null) {
- context.put(CallContext.LENGTH, length);
- }
- } catch (NumberFormatException e) {
- // invalid Range header must be ignored
- }
- }
- }
+ public static String getStringParameter(final HttpServletRequest request, final String name) {
+ if (name == null) {
+ return null;
}
- // get locale
- String acceptLanguage = request.getHeader("Accept-Language");
- if (acceptLanguage != null) {
- String[] locale = acceptLanguage.split("-");
- context.put(CallContext.LOCALE_ISO639_LANGUAGE, locale[0].trim());
- if (locale.length > 1) {
- int x = locale[1].indexOf(',');
- if (x == -1) {
- context.put(CallContext.LOCALE_ISO3166_COUNTRY, locale[1].trim());
- } else {
- context.put(CallContext.LOCALE_ISO3166_COUNTRY, locale[1].substring(0, x).trim());
+ @SuppressWarnings("unchecked")
+ Map<String, String[]> parameters = (Map<String, String[]>) request.getParameterMap();
+ for (Map.Entry<String, String[]> parameter : parameters.entrySet()) {
+ if (name.equalsIgnoreCase(parameter.getKey())) {
+ if (parameter.getValue() == null) {
+ return null;
}
+ return parameter.getValue()[0];
}
}
- return context;
+ return null;
}
/**
@@ -168,188 +67,10 @@ public final class HttpUtils {
result[i] = URLDecoder.decode(result[i], "UTF-8");
} catch (UnsupportedEncodingException e) {
// should not happen
+ throw new CmisRuntimeException(e.getMessage(), e);
}
}
return result;
}
-
- // -------------------------------------------------------------------------
- // --- HTTP headers ---
- // -------------------------------------------------------------------------
-
- /**
- * Sets certain HTTP headers if the server implementation requested them.
- */
- public static boolean setContentStreamHeaders(ContentStream content, HttpServletRequest request,
- HttpServletResponse response) throws IOException {
-
- // check if Last-Modified header should be set
- if (content instanceof LastModifiedContentStream) {
- GregorianCalendar lastModified = ((LastModifiedContentStream) content).getLastModified();
- if (lastModified != null) {
- long lastModifiedSecs = (long) Math.floor((double) lastModified.getTimeInMillis() / 1000);
-
- Date modifiedSince = DateTimeHelper.parseHttpDateTime(request.getHeader("If-Modified-Since"));
- if (modifiedSince != null) {
- long modifiedSinceSecs = (long) Math.floor((double) modifiedSince.getTime() / 1000);
-
- if (modifiedSinceSecs >= lastModifiedSecs) {
- // close stream
- content.getStream().close();
-
- // send not modified status code
- response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
- response.setContentLength(0);
- return true;
- }
- }
-
- response.setHeader("Last-Modified", DateTimeHelper.formatHttpDateTime(lastModifiedSecs * 1000));
- }
- }
-
- // check if cache headers should be set
- if (content instanceof CacheHeaderContentStream) {
- CacheHeaderContentStream chcs = (CacheHeaderContentStream) content;
-
- if (chcs.getETag() != null) {
- String etag = request.getHeader("If-None-Match");
- if (etag != null && !etag.equals("*")) {
- if (etag.length() > 2 && etag.startsWith("\"") && etag.endsWith("\"")) {
- etag = etag.substring(1, etag.length() - 1);
- }
-
- if (chcs.getETag().equals(etag)) {
- // close stream
- content.getStream().close();
-
- // send not modified status code
- response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
- response.setContentLength(0);
- return true;
- }
- }
-
- response.setHeader("ETag", "\"" + chcs.getETag() + "\"");
- }
-
- if (chcs.getCacheControl() != null) {
- response.setHeader("Cache-Control", chcs.getCacheControl());
- }
-
- if (chcs.getExpires() != null) {
- response.setHeader("Expires", DateTimeHelper.formatHttpDateTime(chcs.getExpires()));
- }
- }
-
- // check if Content-Length header should be set
- if (content instanceof ContentLengthContentStream) {
- if (content.getBigLength() != null && content.getBigLength().signum() >= 0) {
- response.setHeader("Content-Length", content.getBigLength().toString());
- }
- }
-
- return false;
- }
-
- // -------------------------------------------------------------------------
- // --- parameters ---
- // -------------------------------------------------------------------------
-
- /**
- * Extracts a string parameter.
- */
- @SuppressWarnings("unchecked")
- public static String getStringParameter(HttpServletRequest request, String name) {
- if (name == null) {
- return null;
- }
-
- Map<String, String[]> parameters = (Map<String, String[]>) request.getParameterMap();
- for (Map.Entry<String, String[]> parameter : parameters.entrySet()) {
- if (name.equalsIgnoreCase(parameter.getKey())) {
- if (parameter.getValue() == null) {
- return null;
- }
- return parameter.getValue()[0];
- }
- }
-
- return null;
- }
-
- /**
- * Extracts a boolean parameter (with default).
- */
- public static boolean getBooleanParameter(HttpServletRequest request, String name, boolean def) {
- String value = getStringParameter(request, name);
- if ((value == null) || (value.length() == 0)) {
- return def;
- }
-
- return Boolean.valueOf(value);
- }
-
- /**
- * Extracts a boolean parameter.
- */
- public static Boolean getBooleanParameter(HttpServletRequest request, String name) {
- String value = getStringParameter(request, name);
- if ((value == null) || (value.length() == 0)) {
- return null;
- }
-
- return Boolean.valueOf(value);
- }
-
- /**
- * Extracts an integer parameter (with default).
- */
- public static BigInteger getBigIntegerParameter(HttpServletRequest request, String name, long def) {
- BigInteger result = getBigIntegerParameter(request, name);
- if (result == null) {
- result = BigInteger.valueOf(def);
- }
-
- return result;
- }
-
- /**
- * Extracts an integer parameter.
- */
- public static BigInteger getBigIntegerParameter(HttpServletRequest request, String name) {
- String value = getStringParameter(request, name);
- if ((value == null) || (value.length() == 0)) {
- return null;
- }
-
- try {
- return new BigInteger(value);
- } catch (Exception e) {
- throw new CmisInvalidArgumentException("Invalid parameter '" + name + "'!");
- }
- }
-
- /**
- * Extracts an enum parameter.
- */
- @SuppressWarnings("unchecked")
- public static <T> T getEnumParameter(HttpServletRequest request, String name, Class<T> clazz) {
- String value = getStringParameter(request, name);
- if ((value == null) || (value.length() == 0)) {
- return null;
- }
-
- try {
- Method m = clazz.getMethod("fromValue", new Class[] { String.class });
- return (T) m.invoke(null, new Object[] { value });
- } catch (Exception e) {
- if (e instanceof InvocationTargetException && e.getCause() instanceof IllegalArgumentException) {
- throw new CmisInvalidArgumentException("Invalid parameter '" + name + "'!");
- }
-
- throw new CmisRuntimeException(e.getMessage(), e);
- }
- }
}
Added: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/ServiceCall.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/ServiceCall.java?rev=1481420&view=auto
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/ServiceCall.java (added)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/ServiceCall.java Sat May 11 21:19:48 2013
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.chemistry.opencmis.server.shared;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.chemistry.opencmis.commons.server.CallContext;
+import org.apache.chemistry.opencmis.commons.server.CmisService;
+
+public interface ServiceCall {
+
+ /**
+ * Serves an AtomPub or Browser binding call.
+ */
+ void serve(CallContext context, CmisService service, String repositoryId, HttpServletRequest request,
+ HttpServletResponse response) throws Exception;
+}
Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/test/java/org/apache/chemistry/opencmis/server/impl/ProxyRequestTest.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/test/java/org/apache/chemistry/opencmis/server/impl/ProxyRequestTest.java?rev=1481420&r1=1481419&r2=1481420&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/test/java/org/apache/chemistry/opencmis/server/impl/ProxyRequestTest.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/test/java/org/apache/chemistry/opencmis/server/impl/ProxyRequestTest.java Sat May 11 21:19:48 2013
@@ -26,9 +26,12 @@ import java.net.URI;
import java.net.URISyntaxException;
import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import org.apache.chemistry.opencmis.commons.server.CallContext;
+import org.apache.chemistry.opencmis.commons.server.CmisService;
import org.apache.chemistry.opencmis.server.filter.ProxyHttpServletRequestWrapper;
-import org.apache.chemistry.opencmis.server.impl.atompub.AtomPubUtils;
+import org.apache.chemistry.opencmis.server.impl.atompub.AbstractAtomPubServiceCall;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
@@ -48,6 +51,8 @@ public class ProxyRequestTest {
private static final String BACKEND_SERVER_NAME = "www.backend.be";
private static final String BACKEND_SERVER_PROTO = ProxyHttpServletRequestWrapper.HTTP_SCHEME;
+ private static final UrlSerivceCall URL_SERVICE_CALL = new UrlSerivceCall();
+
@Mock
private HttpServletRequest request;
@@ -71,7 +76,7 @@ public class ProxyRequestTest {
assertEquals(FORWARDED_HTTPS_PROTO, proxyRequest.getScheme());
- URI baseUri = new URI(AtomPubUtils.compileBaseUrl(proxyRequest, REPOSITORY_ID).toString());
+ URI baseUri = new URI(URL_SERVICE_CALL.compileBaseUrl(proxyRequest, REPOSITORY_ID).toString());
assertEquals(FORWARDED_HTTPS_PROTO, baseUri.getScheme());
assertEquals(BACKEND_SERVER_NAME, baseUri.getHost());
@@ -91,7 +96,7 @@ public class ProxyRequestTest {
assertEquals(FORWARDED_HTTPS_PROTO, proxyRequest.getScheme());
assertEquals(FORWARDED_SERVER_NAME, proxyRequest.getServerName());
- URI baseUri = new URI(AtomPubUtils.compileBaseUrl(proxyRequest, REPOSITORY_ID).toString());
+ URI baseUri = new URI(URL_SERVICE_CALL.compileBaseUrl(proxyRequest, REPOSITORY_ID).toString());
assertEquals(FORWARDED_HTTPS_PROTO, baseUri.getScheme());
assertEquals(FORWARDED_SERVER_NAME, baseUri.getHost());
@@ -108,7 +113,7 @@ public class ProxyRequestTest {
assertEquals(FORWARDED_SERVER_NAME, proxyRequest.getServerName());
- URI baseUri = new URI(AtomPubUtils.compileBaseUrl(proxyRequest, REPOSITORY_ID).toString());
+ URI baseUri = new URI(URL_SERVICE_CALL.compileBaseUrl(proxyRequest, REPOSITORY_ID).toString());
assertEquals(BACKEND_SERVER_PROTO, baseUri.getScheme());
assertEquals(FORWARDED_SERVER_NAME, baseUri.getHost());
@@ -127,7 +132,7 @@ public class ProxyRequestTest {
assertEquals(FORWARDED_SERVER_NAME, proxyRequest.getServerName());
- URI baseUri = new URI(AtomPubUtils.compileBaseUrl(proxyRequest, REPOSITORY_ID).toString());
+ URI baseUri = new URI(URL_SERVICE_CALL.compileBaseUrl(proxyRequest, REPOSITORY_ID).toString());
assertEquals(BACKEND_SERVER_PROTO, baseUri.getScheme());
assertEquals(FORWARDED_SERVER_NAME, baseUri.getHost());
@@ -143,7 +148,7 @@ public class ProxyRequestTest {
assertTrue(FORWARDED_HOST.startsWith(proxyRequest.getServerName()));
- URI baseUri = new URI(AtomPubUtils.compileBaseUrl(proxyRequest, REPOSITORY_ID).toString());
+ URI baseUri = new URI(URL_SERVICE_CALL.compileBaseUrl(proxyRequest, REPOSITORY_ID).toString());
assertEquals(BACKEND_SERVER_PROTO, baseUri.getScheme());
assertEquals(FORWARDED_SERVER_NAME, baseUri.getHost());
@@ -162,7 +167,7 @@ public class ProxyRequestTest {
assertEquals(FORWARDED_HTTPS_PROTO, proxyRequest.getScheme());
assertTrue(FORWARDED_HOST.startsWith(proxyRequest.getServerName()));
- URI baseUri = new URI(AtomPubUtils.compileBaseUrl(proxyRequest, REPOSITORY_ID).toString());
+ URI baseUri = new URI(URL_SERVICE_CALL.compileBaseUrl(proxyRequest, REPOSITORY_ID).toString());
assertEquals(FORWARDED_HTTPS_PROTO, baseUri.getScheme());
assertEquals(FORWARDED_SERVER_NAME, baseUri.getHost());
@@ -182,7 +187,7 @@ public class ProxyRequestTest {
assertEquals(FORWARDED_HTTP_PROTO, proxyRequest.getScheme());
assertTrue(FORWARDED_HOST.startsWith(proxyRequest.getServerName()));
- URI baseUri = new URI(AtomPubUtils.compileBaseUrl(proxyRequest, REPOSITORY_ID).toString());
+ URI baseUri = new URI(URL_SERVICE_CALL.compileBaseUrl(proxyRequest, REPOSITORY_ID).toString());
assertEquals(FORWARDED_HTTP_PROTO, baseUri.getScheme());
assertEquals(FORWARDED_SERVER_NAME, baseUri.getHost());
@@ -202,7 +207,7 @@ public class ProxyRequestTest {
assertEquals(FORWARDED_HTTPS_PROTO, proxyRequest.getScheme());
assertTrue(FORWARDED_HOST.startsWith(proxyRequest.getServerName()));
- URI baseUri = new URI(AtomPubUtils.compileBaseUrl(proxyRequest, REPOSITORY_ID).toString());
+ URI baseUri = new URI(URL_SERVICE_CALL.compileBaseUrl(proxyRequest, REPOSITORY_ID).toString());
assertEquals(FORWARDED_HTTPS_PROTO, baseUri.getScheme());
assertEquals(FORWARDED_SERVER_NAME, baseUri.getHost());
@@ -212,11 +217,19 @@ public class ProxyRequestTest {
@Test
public void testCompileBaseUrl() throws URISyntaxException {
- URI baseUri = new URI(AtomPubUtils.compileBaseUrl(request, REPOSITORY_ID).toString());
+ URI baseUri = new URI(URL_SERVICE_CALL.compileBaseUrl(request, REPOSITORY_ID).toString());
assertEquals(BACKEND_SERVER_PROTO, baseUri.getScheme());
assertEquals(BACKEND_SERVER_NAME, baseUri.getHost());
assertEquals(BACKEND_SERVER_PORT, baseUri.getPort());
assertEquals(EXPECTED_PATH, baseUri.getPath());
}
+
+ static class UrlSerivceCall extends AbstractAtomPubServiceCall {
+ public void serve(CallContext context, CmisService service, String repositoryId, HttpServletRequest request,
+ HttpServletResponse response) throws Exception {
+ // no implementation
+
+ }
+ }
}