/** * Helper to build and encode a remote store call * * @param method Remote store method name * @param documentPath Document path to encode * * @return encoded URL to execute */ private String buildEncodeCall(String method, String documentPath) { return buildEncodeCall(method, documentPath, null); }
/** * Perform a POST call to the given URI with the supplied input. */ protected Response callPost(String uri, InputStream in) { try { Connector con = getConnector(); return con.call(buildUri(uri), null, in); } catch (ConnectorProviderException cpe) { throw new WebScriptsPlatformException("Unable to find config for remote store.", cpe); } }
public void init() { if (this.connectorService == null) { throw new IllegalArgumentException("ConnectorService reference is mandatory for RemoteStore."); } if (this.getEndpoint() == null || getEndpoint().length() == 0) { throw new IllegalArgumentException("Endpoint ID is mandatory for RemoteStore."); } if (this.getApi() == null || this.getApi().length() == 0) { throw new IllegalArgumentException("API name is mandatory for RemoteStore."); } if (this.getStorePath() == null) { throw new IllegalArgumentException("Path prefix is mandatory for RemoteStore."); } if (logger.isDebugEnabled()) { logger.debug("RemoteStore initialised with endpoint id '" + this.getEndpoint() + "' API path '" + this.getApi() + "' path prefix '" + this.getStorePath() + "'."); } }
public boolean hasDocument(String documentPath) throws IOException { boolean hasDocument = false; Response res = callGet(buildEncodeCall(API_HAS, documentPath)); if (Status.STATUS_OK == res.getStatus().getCode()) { hasDocument = Boolean.parseBoolean(res.getResponse()); } else { throw new IOException("Unable to test document path: " + documentPath + " in remote store: " + this.getEndpoint() + " due to error: " + res.getStatus().getCode() + " " + res.getStatus().getMessage()); } if (logger.isDebugEnabled()) logger.debug("RemoteStore.hasDocument() " + documentPath + " = " + hasDocument); return hasDocument; }
public void createDocument(String documentPath, String content) throws IOException { ByteArrayInputStream in = new ByteArrayInputStream(content.getBytes("UTF-8")); Response res = callPost(buildEncodeCall(API_CREATE, documentPath), in); if (logger.isDebugEnabled()) logger.debug("RemoteStore.createDocument() " + documentPath + " = " + res.getStatus().getCode()); if (Status.STATUS_OK != res.getStatus().getCode()) { throw new IOException("Unable to create document path: " + documentPath + " in remote store: " + this.getEndpoint() + " due to error: " + res.getStatus().getCode() + " " + res.getStatus().getMessage()); } }
public String[] getAllDocumentPaths() { Response res = callGet(buildEncodeCall(API_LISTALL, "")); if (logger.isDebugEnabled()) logger.debug("RemoteStore.getAllDocumentPaths() " + res.getStatus().getCode()); if (Status.STATUS_OK == res.getStatus().getCode()) { // convert to an array of store root-relative paths List<String> list = new ArrayList<String>(128); StringTokenizer t = new StringTokenizer(res.getResponse(), "\n"); while (t.hasMoreTokens()) { list.add(t.nextToken()); } String[] paths = list.toArray(new String[list.size()]); // truncate paths so that they are relative to the store path // and invariant of the type of AVM store (WCM or plain) convertToRelativePaths(paths); return paths; } else { return new String[0]; } }
final String storePath = getStorePath(); document.addAttribute("path", (storePath.equals("/") ? storePath : '/' + storePath) + pathContent.getFirst()); document.add(pathContent.getSecond().getRootElement().createCopy()); out.close(); ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()); Response res = callPost(buildEncodeCall(API_CREATE_MULTI, ""), in); throw new IOException("Unable to create documents in remote store: " + this.getEndpoint() + " due to error: " + res.getStatus().getCode() + " " + res.getStatus().getMessage());
buf.append(this.getApi()); buf.append('/'); buf.append(method); String fullPath = this.getStorePath() + "/" + documentPath; for (StringTokenizer t = new StringTokenizer(fullPath, "/"); t.hasMoreTokens(); /**/) String storeId = this.getStoreId(); if (storeId != null) String webappId = this.getWebappId(); if (webappId != null)
public boolean removeDocument(String documentPath) throws IOException { Response res = callDelete(buildEncodeCall(API_DELETE, documentPath)); boolean removed = (Status.STATUS_OK == res.getStatus().getCode()); if (logger.isDebugEnabled()) logger.debug("RemoteStore.removeDocument() " + documentPath + " = " + res.getStatus().getCode() + " (removed = "+removed+")"); return removed; }
/** * Get a Connector for access to the endpoint. If a connector has been bound to the * current thread then use it, else retrieve a transient connector instance from the * ConnectorService. * * @return Connector * * @throws ConnectorProviderException */ protected Connector getConnector() throws ConnectorProviderException { Connector conn = null; // use a default connector provider if none injected if (connectorProvider == null) { connectorProvider = new ConnectorProviderImpl(); } // provision connector conn = getConnectorProvider().provide(this.getEndpoint()); return conn; }
public String[] getDescriptionDocumentPaths() { return getDocumentPaths("", true, DESC_PATH_PATTERN); }
public boolean hasDocument(String documentPath) throws IOException { boolean hasDocument = false; Response res = callGet(buildEncodeCall(API_HAS, documentPath)); if (Status.STATUS_OK == res.getStatus().getCode()) { hasDocument = Boolean.parseBoolean(res.getResponse()); } else { throw new IOException("Unable to test document path: " + documentPath + " in remote store: " + this.getEndpoint() + " due to error: " + res.getStatus().getCode() + " " + res.getStatus().getMessage()); } if (logger.isDebugEnabled()) logger.debug("RemoteStore.hasDocument() " + documentPath + " = " + hasDocument); return hasDocument; }
public void updateDocument(String documentPath, String content) throws IOException { ByteArrayInputStream in = new ByteArrayInputStream(content.getBytes("UTF-8")); Response res = callPost(buildEncodeCall(API_UPDATE, documentPath), in); if (logger.isDebugEnabled()) logger.debug("RemoteStore.updateDocument() " + documentPath + " = " + res.getStatus().getCode()); if (Status.STATUS_OK != res.getStatus().getCode()) { throw new IOException("Unable to update document path: " + documentPath + " in remote store: " + this.getEndpoint() + " due to error: " + res.getStatus().getCode() + " " + res.getStatus().getMessage()); } }
public String[] getAllDocumentPaths() { Response res = callGet(buildEncodeCall(API_LISTALL, "")); if (logger.isDebugEnabled()) logger.debug("RemoteStore.getAllDocumentPaths() " + res.getStatus().getCode()); if (Status.STATUS_OK == res.getStatus().getCode()) { // convert to an array of store root-relative paths List<String> list = new ArrayList<String>(128); StringTokenizer t = new StringTokenizer(res.getResponse(), "\n"); while (t.hasMoreTokens()) { list.add(t.nextToken()); } String[] paths = list.toArray(new String[list.size()]); // truncate paths so that they are relative to the store path // and invariant of the type of AVM store (WCM or plain) convertToRelativePaths(paths); return paths; } else { return new String[0]; } }
final String storePath = getStorePath(); document.addAttribute("path", (storePath.equals("/") ? storePath : '/' + storePath) + pathContent.getFirst()); document.add(pathContent.getSecond().getRootElement().createCopy()); out.close(); ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()); Response res = callPost(buildEncodeCall(API_CREATE_MULTI, ""), in); throw new IOException("Unable to create documents in remote store: " + this.getEndpoint() + " due to error: " + res.getStatus().getCode() + " " + res.getStatus().getMessage());
buf.append(this.getApi()); buf.append('/'); buf.append(method); String fullPath = this.getStorePath() + "/" + documentPath; for (StringTokenizer t = new StringTokenizer(fullPath, "/"); t.hasMoreTokens(); /**/) String storeId = this.getStoreId(); if (storeId != null) String webappId = this.getWebappId(); if (webappId != null)
public boolean removeDocument(String documentPath) throws IOException { Response res = callDelete(buildEncodeCall(API_DELETE, documentPath)); boolean removed = (Status.STATUS_OK == res.getStatus().getCode()); if (logger.isDebugEnabled()) logger.debug("RemoteStore.removeDocument() " + documentPath + " = " + res.getStatus().getCode() + " (removed = "+removed+")"); return removed; }
/** * Get a Connector for access to the endpoint. If a connector has been bound to the * current thread then use it, else retrieve a transient connector instance from the * ConnectorService. * * @return Connector * * @throws ConnectorProviderException */ protected Connector getConnector() throws ConnectorProviderException { Connector conn = null; // use a default connector provider if none injected if (connectorProvider == null) { connectorProvider = new ConnectorProviderImpl(); } // provision connector conn = getConnectorProvider().provide(this.getEndpoint()); return conn; }
public String[] getDescriptionDocumentPaths() { return getDocumentPaths("", true, DESC_PATH_PATTERN); }
public long lastModified(String documentPath) throws IOException { Response res = callGet(buildEncodeCall(API_LASTMODIFIED, documentPath)); if (Status.STATUS_OK == res.getStatus().getCode()) { try { long lastMod = Long.parseLong(res.getResponse()); if (logger.isDebugEnabled()) logger.debug("RemoteStore.lastModified() " + documentPath + " = " + lastMod); return lastMod; } catch (NumberFormatException ne) { throw new IOException("Failed to process lastModified response: " + ne.getMessage()); } } else { throw new IOException("Unable to get lastModified date of document path: " + documentPath + " in remote store: " + this.getEndpoint() + " due to error: " + res.getStatus().getCode() + " " + res.getStatus().getMessage()); } }