Skip to Content.
Sympa Menu

idok-commit - [idok-commit] idok commit r160 - in branches/rest: . java/ch/idok/common/util java/ch/idok/service/common/search java/ch/idok/service/server java/ch/idok/service/server/rest java/ch/idok/service/server/search/rest

idok-commit AT lists.psi.ch

Subject: Commit emails of the iDok project

List archive

[idok-commit] idok commit r160 - in branches/rest: . java/ch/idok/common/util java/ch/idok/service/common/search java/ch/idok/service/server java/ch/idok/service/server/rest java/ch/idok/service/server/search/rest


Chronological Thread 
  • From: "AFS account Roman Geus" <geus AT savannah.psi.ch>
  • To: idok-commit AT lists.psi.ch
  • Subject: [idok-commit] idok commit r160 - in branches/rest: . java/ch/idok/common/util java/ch/idok/service/common/search java/ch/idok/service/server java/ch/idok/service/server/rest java/ch/idok/service/server/search/rest
  • Date: Wed, 6 Aug 2008 11:31:21 +0200
  • List-archive: <https://lists.web.psi.ch/pipermail/idok-commit/>
  • List-id: Commit emails of the iDok project <idok-commit.lists.psi.ch>

Author: geus
Date: Wed Aug 6 11:31:20 2008
New Revision: 160

Log:
Added incomplete implementation of REST server and REST search service

Added:
branches/rest/java/ch/idok/common/util/Pair.java
branches/rest/java/ch/idok/service/server/rest/
branches/rest/java/ch/idok/service/server/rest/IdokAppConfig.java
branches/rest/java/ch/idok/service/server/rest/JaasBasicAuthGuard.java
branches/rest/java/ch/idok/service/server/rest/RestServer.java
branches/rest/java/ch/idok/service/server/search/rest/
branches/rest/java/ch/idok/service/server/search/rest/IteratorCache.java

branches/rest/java/ch/idok/service/server/search/rest/RestSearchServiceResource.java
Modified:
branches/rest/build.xml
branches/rest/java/ch/idok/service/common/search/SearchService.java
branches/rest/java/ch/idok/service/server/Server.java
branches/rest/local-server.xml

Modified: branches/rest/build.xml
==============================================================================
--- branches/rest/build.xml (original)
+++ branches/rest/build.xml Wed Aug 6 11:31:20 2008
@@ -50,6 +50,10 @@
<include name="FontBox.jar" />
<include name="bcprov.jar" />
<include name="bcmail.jar" />
+ <include name="org.restlet.ext.jaxrs_0.9.jar" />
+ <include name="org.restlet.jar" />
+ <include name="com.noelios.reslet.jar" />
+ <include name="javax.ws.rs.jar" />
</fileset>

<!-- jar files needed for development only -->
@@ -222,10 +226,10 @@
description="Java classes and resources for
idok.jar">
<include name="ch/idok/**" />
<exclude name="ch/idok/qtgui/**" />
- <exclude name="ch/idok/tools/**" />
- <exclude name="com/trolltech/**" />
- <exclude name="**/*Test.class" />
- <exclude name="**/*TestBase.class" />
+ <exclude name="ch/idok/tools/**" />
+ <exclude name="com/trolltech/**" />
+ <exclude name="**/*Test.class" />
+ <exclude name="**/*TestBase.class" />
</fileset>

<!-- Clean distribution directory ${dist.dir} -->

Added: branches/rest/java/ch/idok/common/util/Pair.java
==============================================================================
--- (empty file)
+++ branches/rest/java/ch/idok/common/util/Pair.java Wed Aug 6 11:31:20
2008
@@ -0,0 +1,52 @@
+package ch.idok.common.util;
+
+/**
+ * Container for two objects of arbitrary types
+ *
+ * @param <L> type of first object
+ * @param <R> type of second object
+ */
+public class Pair<L, R> {
+
+ private final L left;
+ private final R right;
+
+ public R getRight() {
+ return right;
+ }
+
+ public L getLeft() {
+ return left;
+ }
+
+ public Pair(final L left, final R right) {
+ this.left = left;
+ this.right = right;
+ }
+
+ public static <A, B> Pair<A, B> create(A left, B right) {
+ return new Pair<A, B>(left, right);
+ }
+
+ public final boolean equals(Object o) {
+ if (!(o instanceof Pair))
+ return false;
+
+ final Pair<?, ?> other = (Pair) o;
+ return equal(getLeft(), other.getLeft()) && equal(getRight(),
other.getRight());
+ }
+
+ public static final boolean equal(Object o1, Object o2) {
+ if (o1 == null) {
+ return o2 == null;
+ }
+ return o1.equals(o2);
+ }
+
+ public int hashCode() {
+ int hLeft = getLeft() == null ? 0 : getLeft().hashCode();
+ int hRight = getRight() == null ? 0 : getRight().hashCode();
+
+ return hLeft + (57 * hRight);
+ }
+}

Modified: branches/rest/java/ch/idok/service/common/search/SearchService.java
==============================================================================
--- branches/rest/java/ch/idok/service/common/search/SearchService.java
(original)
+++ branches/rest/java/ch/idok/service/common/search/SearchService.java Wed
Aug 6 11:31:20 2008
@@ -54,7 +54,7 @@
* Query string, which is specific to the indexer package
* used by the DMS server (Lucene).
* @param fields
- * A string of commaseparated metadata field names (commas
+ * A string of comma-separated metadata field names
(commas
* and backslashes that are part of the field name must be
* escaped with \). Only the specifield metadata fields
will
* be returned. If all (or no) metadata fields are
desired,

Modified: branches/rest/java/ch/idok/service/server/Server.java
==============================================================================
--- branches/rest/java/ch/idok/service/server/Server.java (original)
+++ branches/rest/java/ch/idok/service/server/Server.java Wed Aug 6
11:31:20 2008
@@ -28,6 +28,9 @@
public interface Server {
/**
* @brief Run the server request dispatch loop.
+ *
+ * This method does not return.
+ *
* @param serviceProvider
* The server side service provider.
*/

Added: branches/rest/java/ch/idok/service/server/rest/IdokAppConfig.java
==============================================================================
--- (empty file)
+++ branches/rest/java/ch/idok/service/server/rest/IdokAppConfig.java Wed
Aug 6 11:31:20 2008
@@ -0,0 +1,22 @@
+package ch.idok.service.server.rest;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.ws.rs.core.ApplicationConfig;
+
+import ch.idok.service.server.search.rest.RestSearchServiceResource;
+
+public class IdokAppConfig extends ApplicationConfig {
+
+ /**
+ * @see javax.ws.rs.core.ApplicationConfig#getResourceClasses()
+ */
+ @Override
+ public Set<Class<?>> getResourceClasses() {
+ Set<Class<?>> rrcs = new HashSet<Class<?>>();
+ rrcs.add(RestSearchServiceResource.class);
+ return rrcs;
+ }
+
+}

Added: branches/rest/java/ch/idok/service/server/rest/JaasBasicAuthGuard.java
==============================================================================
--- (empty file)
+++ branches/rest/java/ch/idok/service/server/rest/JaasBasicAuthGuard.java
Wed Aug 6 11:31:20 2008
@@ -0,0 +1,79 @@
+package ch.idok.service.server.rest;
+
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.security.auth.Subject;
+import javax.security.auth.callback.CallbackHandler;
+import javax.security.auth.login.LoginContext;
+import javax.security.auth.login.LoginException;
+
+import org.restlet.Context;
+import org.restlet.Guard;
+import org.restlet.data.ChallengeScheme;
+import org.restlet.data.Request;
+
+import ch.idok.common.errorhandling.DmsException;
+import ch.idok.common.util.AuthUtil;
+import ch.idok.common.util.DmsCredentials;
+import ch.idok.common.util.DummyCallbackHandler;
+import ch.idok.common.util.Krb5DmsCredentials;
+
+/**
+ * A guard that a implements HTTP basic authentication using a JAAS
+ * authentication module
+ */
+public class JaasBasicAuthGuard extends Guard {
+
+ private String jaasConfigName;
+ private Logger logger;
+
+ private static final String subjectAttributeName =
"ch.idok.service.server.rest.Subject";
+ private static final String passwordAttributeName =
"ch.idok.service.server.rest.Password";
+
+ public JaasBasicAuthGuard(Context context, String realm,
+ String jaasConfigName) {
+ super(context, ChallengeScheme.HTTP_BASIC, realm);
+ logger = context.getLogger();
+ this.jaasConfigName = jaasConfigName;
+ }
+
+ /**
+ * @see org.restlet.Guard#checkSecret(org.restlet.data.Request,
+ * java.lang.String, char[])
+ */
+ @Override
+ public boolean checkSecret(Request request, String identifier, char[]
secret) {
+ CallbackHandler handler = new DummyCallbackHandler(identifier,
secret);
+
+ try {
+ LoginContext lc = new LoginContext(jaasConfigName, handler);
+ lc.login();
+ request.getAttributes().put(subjectAttributeName,
lc.getSubject());
+ request.getAttributes().put(passwordAttributeName, secret);
+ logger.finer("Authentication successful for user " + identifier);
+ return true;
+ } catch (LoginException e) {
+ logger.log(Level.FINER, "Authentication failed for user "
+ + identifier, e);
+ return false;
+ }
+ }
+
+ /**
+ * Return a DmsCredentials object created from the current Restlet
request.
+ *
+ * @throws DmsException
+ */
+ static public DmsCredentials getDmsCredentials() throws DmsException {
+ Request request = Request.getCurrent();
+ Subject subject = (Subject) request.getAttributes().get(
+ subjectAttributeName);
+ char[] password = (char[]) request.getAttributes().get(
+ passwordAttributeName);
+
+ return new Krb5DmsCredentials(AuthUtil.getUserPrincipal(subject)
+ .getName(), password, subject);
+ }
+
+}

Added: branches/rest/java/ch/idok/service/server/rest/RestServer.java
==============================================================================
--- (empty file)
+++ branches/rest/java/ch/idok/service/server/rest/RestServer.java Wed
Aug 6 11:31:20 2008
@@ -0,0 +1,91 @@
+package ch.idok.service.server.rest;
+
+import java.util.logging.Logger;
+
+import org.restlet.Component;
+import org.restlet.Guard;
+import org.restlet.Server;
+import org.restlet.data.Protocol;
+import org.restlet.ext.jaxrs.JaxRsApplication;
+
+import ch.idok.common.config.Setup;
+import ch.idok.common.errorhandling.DmsException;
+import ch.idok.common.errorhandling.ErrorType;
+import ch.idok.service.common.Provider;
+import ch.idok.service.server.search.rest.RestSearchServiceResource;
+
+/**
+ * This class initializes and runs the REST server
+ */
+public class RestServer implements ch.idok.service.server.Server {
+ Component comp;
+ Logger logger =
Setup.getInstance().getLogger("ch.idok.service.server.rest");
+
+ /** The service provider */
+ public Provider serviceProvider;
+
+
+ /**
+ * @see ch.idok.service.server.Server#init(java.lang.String[])
+ */
+ public void init(String[] args) throws DmsException {
+ // no initialization necessary
+ }
+
+ /**
+ * Returns Logger for logging REST specific information
+ */
+ public Logger getLogger() {
+ return logger;
+ }
+
+ /**
+ * @see
ch.idok.service.server.Server#run(ch.idok.service.common.Provider)
+ */
+ public void run(Provider serviceProvider) throws DmsException {
+ this.serviceProvider = serviceProvider;
+ RestSearchServiceResource.init(this);
+
+ // create Component (as ever for Restlet)
+ comp = new Component();
+ Server server = comp.getServers().add(Protocol.HTTP, 8183);
+
+ // create JAX-RS runtime environment
+ JaxRsApplication application = new
JaxRsApplication(comp.getContext());
+
+ // create a custom Guard that authenticates using JAAS
+ Guard guard = new JaasBasicAuthGuard(application.getContext(),
+ "JAX-RS example", "DmsNoCache");
+
+ // attach ApplicationConfig and Guard
+ application.attach(new IdokAppConfig());
+ application.setGuard(guard);
+
+ // attach the application to the component and start it
+ comp.getDefaultHost().attach("/v1", application);
+ try {
+ comp.start();
+ logger.info("REST server started on port " + server.getPort());
+ while (true)
+ try {
+ Thread.sleep(60000);
+ } catch (InterruptedException e) {
+ }
+ } catch (Exception e) {
+ throw new DmsException(ErrorType.INTERNAL, null,
+ "Could not start REST server", "", e);
+ }
+
+ }
+
+ public void stop(Provider serviceProvider) throws DmsException {
+ try {
+ comp.stop();
+ } catch (Exception e) {
+ throw new DmsException(ErrorType.INTERNAL, null,
+ "Could not stop REST server", "", e);
+ }
+ logger.info("REST server stopped");
+ }
+
+}

Added:
branches/rest/java/ch/idok/service/server/search/rest/IteratorCache.java
==============================================================================
--- (empty file)
+++ branches/rest/java/ch/idok/service/server/search/rest/IteratorCache.java
Wed Aug 6 11:31:20 2008
@@ -0,0 +1,192 @@
+package ch.idok.service.server.search.rest;
+
+import java.util.Calendar;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Timer;
+import java.util.TimerTask;
+import java.util.Map.Entry;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import ch.idok.common.errorhandling.DmsException;
+import ch.idok.common.util.DmsCredentials;
+import ch.idok.common.util.Pair;
+import ch.idok.service.common.search.QueryMatch;
+import ch.idok.service.common.search.SearchService;
+
+/**
+ * This class implements a cache for iterators returned by the
+ * SearchService.query() method.
+ *
+ * The IteratorCache is a singleton class.
+ *
+ */
+public class IteratorCache {
+
+ /**
+ * Maximum number of cached iterators
+ */
+ private final int maxEntries = 20;
+
+ /**
+ * Interval in milliseconds between cache cleanup runs
+ */
+ private final long interval = 10000;
+
+ /**
+ * Timeout in milliseconds, cache entries older than the timeout will be
+ * removed during cleanup
+ */
+ private final long timeout = 60000;
+
+ /**
+ * The one and only IteratorCache instance
+ */
+ static private IteratorCache theIteratorCache = null;
+
+ /** The search service used to produce results. */
+ private SearchService searchService;
+
+ /**
+ * Collection storing the cached iterators
+ */
+ private Map<String, CacheEntry> iterators;
+
+ private Timer timer;
+
+ private final Logger logger;
+
+ private class CacheEntry {
+ private Iterator<QueryMatch> it;
+ private long timestamp;
+
+ CacheEntry(Iterator<QueryMatch> it, long timestamp) {
+ this.it = it;
+ this.timestamp = timestamp;
+ }
+ }
+
+ /**
+ * Private constructor called by getIteratorCache()
+ */
+ private IteratorCache(SearchService searchService, Logger logger) {
+ this.searchService = searchService;
+ this.logger = logger;
+ iterators = new HashMap<String, CacheEntry>();
+
+ // Schedule periodic cleanup of old cache entries
+ timer = new Timer();
+ timer.schedule(new TimerTask() {
+
+ @Override
+ public void run() {
+
+ synchronized (IteratorCache.this) {
+
+ IteratorCache.this.logger.log(Level.FINEST,
+ "Starting cache cleanup");
+ long now = Calendar.getInstance().getTime().getTime();
+ Iterator<Entry<String, CacheEntry>> p = iterators
+ .entrySet().iterator();
+ while (p.hasNext()) {
+ Map.Entry<String, CacheEntry> entry = p.next();
+ if (now - entry.getValue().timestamp > timeout) {
+ IteratorCache.this.logger.log(Level.FINEST,
+ "Removed cache entry \"{0}\"", entry
+ .getKey());
+ p.remove();
+ }
+ }
+
+ }
+ }
+ }, interval, interval);
+ }
+
+ /**
+ * Return the IteratorCache singleton
+ */
+ public static synchronized IteratorCache getIteratorCache(
+ SearchService searchService, Logger logger) {
+ if (theIteratorCache == null)
+ theIteratorCache = new IteratorCache(searchService, logger);
+ return theIteratorCache;
+ }
+
+ /**
+ * Obtain a Iterator<QueryMatch> object for the given query.
+ *
+ * This method will either return a cached iterator or create a new one,
if
+ * no suitable iterator is found in the cache.
+ *
+ * @return Pair consisting of the iterator object and its current
position
+ * @throws DmsException
+ */
+ public synchronized Pair<Iterator<QueryMatch>, Integer> retrieve(
+ DmsCredentials cred, String luceneQuery, String metaFields,
+ long resultType, int start) throws DmsException {
+ String key = genKey(cred, luceneQuery, metaFields, resultType,
start);
+ Iterator<QueryMatch> it = get(key);
+ int pos = 0;
+ if (it == null) {
+ it = searchService.query(cred, luceneQuery, metaFields,
resultType);
+ logger.log(Level.FINEST, "Created new iterator for \"{0}\"",
key);
+ } else {
+ pos = start;
+ logger.log(Level.FINEST,
+ "Retrieved iterator for \"{0}\" from cache", key);
+ }
+ return new Pair<Iterator<QueryMatch>, Integer>(it, pos);
+ }
+
+ /**
+ * Store an iterator in the cache
+ */
+ public synchronized void submit(DmsCredentials cred, String luceneQuery,
+ String metaFields, long resultType, int position,
+ Iterator<QueryMatch> hits) {
+ String key = genKey(cred, luceneQuery, metaFields, resultType,
position);
+ put(key, hits);
+ }
+
+ /**
+ * Retrieve an iterator with the given key from the cache
+ *
+ * The retrieved iterator is removed from the cache in the process.
+ *
+ * @return the retrieved key or <code>null</code> if none was found
+ */
+ private Iterator<QueryMatch> get(String key) {
+ CacheEntry entry = iterators.remove(key);
+ if (entry == null)
+ return null;
+ else
+ return entry.it;
+ }
+
+ /**
+ * Store an iterator with the given key in the cache
+ */
+ private void put(String key, Iterator<QueryMatch> hits) {
+ if (iterators.size() < maxEntries)
+ iterators.put(key, new CacheEntry(hits, Calendar.getInstance()
+ .getTime().getTime()));
+ }
+
+ /**
+ * Generate a key for the Map storing the cache elements
+ *
+ * The key is built from the parameters of the SearchService query and
the
+ * current position of the iterator and the authenticated user.
+ */
+ private String genKey(DmsCredentials cred, String luceneQuery,
+ String metaFields, long resultType, int start) {
+ String key = String.format("%s//%s//%s//%d//%d", cred == null ? ""
+ : cred.getUsername(), luceneQuery, metaFields, resultType,
+ start);
+ return key;
+ }
+
+}

Added:
branches/rest/java/ch/idok/service/server/search/rest/RestSearchServiceResource.java
==============================================================================
--- (empty file)
+++
branches/rest/java/ch/idok/service/server/search/rest/RestSearchServiceResource.java
Wed Aug 6 11:31:20 2008
@@ -0,0 +1,199 @@
+package ch.idok.service.server.search.rest;
+
+import java.util.Iterator;
+import java.util.Map;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.ws.rs.DefaultValue;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.ProduceMime;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.SecurityContext;
+import javax.ws.rs.core.Response.Status;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.dom.DOMSource;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+import ch.idok.common.errorhandling.DmsException;
+import ch.idok.common.util.Base64Coder;
+import ch.idok.common.util.DmsCredentials;
+import ch.idok.common.util.Pair;
+import ch.idok.service.common.search.QueryMatch;
+import ch.idok.service.common.search.SearchService;
+import ch.idok.service.server.rest.JaasBasicAuthGuard;
+import ch.idok.service.server.rest.RestServer;
+
+/**
+ * JAX-RS resource class for the iDok search service
+ */
+@Path("")
+public class RestSearchServiceResource {
+
+ /** The search service used to produce results. */
+ static SearchService searchService;
+
+ static Logger logger;
+
+ static IteratorCache iteratorCache;
+
+ /**
+ * JAX-RS security context
+ */
+ @Context
+ SecurityContext securityContext;
+
+ static public void init(RestServer server) throws DmsException {
+ searchService = server.serviceProvider.getSearchService();
+ logger = server.getLogger();
+ iteratorCache = IteratorCache.getIteratorCache(searchService,
logger);
+ }
+
+ @GET
+ @Path("{project}/{repository}/")
+ @ProduceMime("text/xml")
+ public Response query(@PathParam("project")
+ String project, @PathParam("repository")
+ String repository, @QueryParam("q")
+ String query, @QueryParam("metafields")
+ String metaFields, @QueryParam("outputfields")
+ String resultTypeString, @QueryParam("start")
+ @DefaultValue("0")
+ String startString, @QueryParam("num")
+ @DefaultValue("20")
+ String numString) {
+
+ // parse and validate query parameters
+ if (query == null)
+ return Response.status(Status.BAD_REQUEST).entity(
+ "empty query string").build();
+ int num = Integer.parseInt(numString);
+ if (num < 1 || num > 100)
+ return Response.status(Status.BAD_REQUEST).entity(
+ "num parameter out of range").build();
+ int start = Integer.parseInt(startString);
+ if (start < 0)
+ return Response.status(Status.BAD_REQUEST).entity(
+ "start parameter out of range").build();
+ long resultType = 0;
+ if (resultTypeString != null) {
+ String[] outputFields = resultTypeString.split(",");
+ for (String outputField : outputFields)
+ if (outputField.equals("meta"))
+ resultType |= SearchService.METADATA;
+ else if (outputField.equals("env"))
+ resultType |= SearchService.MATCH_ENVIRONEMENT;
+ else if (outputField.equals("doc"))
+ resultType |= SearchService.DOC_CONTENT;
+ else
+ return Response.status(Status.BAD_REQUEST).entity(
+ "error in outputfields parameter").build();
+ }
+ if (metaFields != null)
+ resultType |= SearchService.METADATA;
+ else
+ metaFields = "";
+
+ try {
+ // TODO JAAS login using HTTP Negotiate authentication
+ DmsCredentials cred = null;
+ if (securityContext.getUserPrincipal() != null) {
+ cred = JaasBasicAuthGuard.getDmsCredentials();
+ }
+
+ // build Lucene query string
+ String luceneQuery = String.format("%s/%s::%s", project,
+ repository, query);
+
+ // initialize XML DOM
+ DocumentBuilderFactory factory = DocumentBuilderFactory
+ .newInstance();
+ DocumentBuilder parser = factory.newDocumentBuilder();
+ Document doc = parser.newDocument();
+ Element root = doc.createElement("Hits");
+ doc.appendChild(root);
+
+ // call Lucene (currently the resultType parameter is ignored by
the
+ // query method)
+ Pair<Iterator<QueryMatch>, Integer> cacheResult;
+ cacheResult = iteratorCache.retrieve(cred, luceneQuery,
metaFields,
+ resultType, start);
+ Iterator<QueryMatch> hits = cacheResult.getLeft();
+ int pos = cacheResult.getRight();
+
+ // advance to requested position
+ for (int i = pos; i < start; ++i)
+ hits.next();
+
+ for (int i = 0; i < num; ++i) {
+ if (!hits.hasNext())
+ break;
+ QueryMatch hit = hits.next();
+ // TODO generate JSON output
+
+ // update DOM tree
+ Element hitElement = doc.createElement("Hit");
+ root.appendChild(hitElement);
+
+ Element idElement = doc.createElement("Id");
+ idElement.setTextContent(hit.getId());
+ hitElement.appendChild(idElement);
+
+ if ((resultType & SearchService.MATCH_ENVIRONEMENT) != 0) {
+ Element envElement = doc.createElement("Environment");
+ envElement.setTextContent(hit.getEnvironment());
+ hitElement.appendChild(envElement);
+ }
+
+ if ((resultType & SearchService.METADATA) != 0) {
+ Element metaElement = doc.createElement("Meta");
+ Map<String, String> meta = hit.getMetadata();
+ for (String key : meta.keySet()) {
+ Element meElement = doc.createElement("MetaElement");
+
+ Element keyElement = doc.createElement("Key");
+ keyElement.setTextContent(key);
+ meElement.appendChild(keyElement);
+
+ Element valElement = doc.createElement("Value");
+ valElement.setTextContent(meta.get(key));
+ meElement.appendChild(valElement);
+
+ metaElement.appendChild(meElement);
+ }
+ hitElement.appendChild(metaElement);
+ }
+
+ if ((resultType & SearchService.DOC_CONTENT) != 0) {
+ Element contentElement = doc.createElement("Content");
+ contentElement.setTextContent(new String(Base64Coder
+ .encode(hit.getContent())));
+ hitElement.appendChild(contentElement);
+ }
+
+ }
+
+ iteratorCache.submit(cred, luceneQuery, metaFields, resultType,
+ start + num, hits);
+
+ DOMSource source = new DOMSource(doc);
+ return Response.ok().entity(source).build();
+ } catch (DmsException e) {
+ // TODO translate DmsException to an entity
+ logger.log(Level.FINER, "Error in REST call", e);
+ return Response.serverError().entity("DmsException: " +
e).build();
+ } catch (ParserConfigurationException e) {
+ logger.log(Level.FINER, "Error in REST call", e);
+ return Response.serverError().entity("DmsException: " +
e).build();
+ }
+
+ }
+}

Modified: branches/rest/local-server.xml
==============================================================================
--- branches/rest/local-server.xml (original)
+++ branches/rest/local-server.xml Wed Aug 6 11:31:20 2008
@@ -43,6 +43,11 @@
<include name="lib/derby.jar" />
<include name="lib/javamail.jar" />
<include name="lib/smtphandler.jar" />
+ <include name="lib/org.restlet.ext.jaxrs_0.9.jar" />
+ <include name="lib/org.restlet.jar" />
+ <include name="lib/com.noelios.reslet.jar" />
+ <include name="lib/javax.ws.rs.jar" />
+ <include name="lib/org.json.jar" />
</fileset>

<fileset id="idok.libs.indexer" dir="">
@@ -245,7 +250,10 @@
<sysproperty key="privateKeyPassword"
value="VgxfhGau7WL1T4qlD1NE" />
<sysproperty key="ch.idok.service.server"
+
value="ch.idok.service.server.rest.RestServer" />
+ <!-- <sysproperty
key="ch.idok.service.server"

value="ch.idok.service.server.corba.CorbaServer" />
+-->
<sysproperty key="ch.idok.service.provider"

value="ch.idok.service.server.ServerProvider" />
<sysproperty key="ch.idok.service.client.provider"
@@ -329,13 +337,13 @@
description="sign all jar files for Java webstart">
<!-- Delete existing signatures in all lib/*.jar files -->
<exec executable="/bin/bash">
- <arg value="-c"/>
- <arg value="for j in lib/*.jar; do echo $j; zip -d $j
'META-INF/INDEX.LIST' 'META-INF/*.MF' 'META-INF/*.SF' 'META-INF/*.RSA'
'META-INF/*.DSA'; done"/>
+ <arg value="-c" />
+ <arg value="for j in lib/*.jar; do echo $j; zip -d $j
'META-INF/INDEX.LIST' 'META-INF/*.MF' 'META-INF/*.SF' 'META-INF/*.RSA'
'META-INF/*.DSA'; done" />
</exec>
<!-- Delete existing signatures in all ant_dist/*.jar files
-->
<exec executable="/bin/bash">
- <arg value="-c"/>
- <arg value="for j in ant_dist/*.jar; do echo $j; zip
-d $j 'META-INF/INDEX.LIST' 'META-INF/*.MF' 'META-INF/*.SF' 'META-INF/*.RSA'
'META-INF/*.DSA'; done"/>
+ <arg value="-c" />
+ <arg value="for j in ant_dist/*.jar; do echo $j; zip
-d $j 'META-INF/INDEX.LIST' 'META-INF/*.MF' 'META-INF/*.SF' 'META-INF/*.RSA'
'META-INF/*.DSA'; done" />
</exec>
<signjar alias="jarsign"
storepass="${keystore.passwd}"



  • [idok-commit] idok commit r160 - in branches/rest: . java/ch/idok/common/util java/ch/idok/service/common/search java/ch/idok/service/server java/ch/idok/service/server/rest java/ch/idok/service/server/search/rest, AFS account Roman Geus, 08/06/2008

Archive powered by MHonArc 2.6.19.

Top of Page