Search in sources :

Example 1 with BeanQueryAllPropertiesMessage

use of org.dcache.vehicles.BeanQueryAllPropertiesMessage in project dcache by dCache.

the class ProbeResponseEngine method queryUrl.

@Override
public void queryUrl(HttpRequest request) throws HttpException {
    try {
        String[] urlItems = request.getRequestTokens();
        if (urlItems.length < 2) {
            throw new HttpException(404, "No such property");
        }
        /* urlItems[0] is the mount point.
             */
        BeanQueryMessage queryMessage = (urlItems.length == 3) ? new BeanQuerySinglePropertyMessage(urlItems[2]) : new BeanQueryAllPropertiesMessage();
        BeanQueryMessage queryReply = stub.sendAndWait(new CellPath(urlItems[1]), queryMessage);
        request.setContentType("application/json; charset=utf-8");
        Writer writer = new OutputStreamWriter(request.getOutputStream(), UTF_8);
        writer.append(new GsonBuilder().serializeSpecialFloatingPointValues().setPrettyPrinting().disableHtmlEscaping().create().toJson(queryReply.getResult()));
        writer.flush();
    } catch (NoRouteToCellException e) {
        throw new HttpException(503, "The cell was unreachable, suspect trouble.");
    } catch (TimeoutCacheException e) {
        throw new HttpException(503, "The cell took too long to reply, suspect trouble.");
    } catch (InvalidMessageCacheException e) {
        throw new HttpException(404, "No such property");
    } catch (CacheException | IOException e) {
        throw new HttpException(500, e.getMessage());
    } catch (InterruptedException e) {
        throw new HttpException(503, "Received interrupt whilst processing data. Please try again later.");
    }
}
Also used : CellPath(dmg.cells.nucleus.CellPath) GsonBuilder(com.google.gson.GsonBuilder) TimeoutCacheException(diskCacheV111.util.TimeoutCacheException) CacheException(diskCacheV111.util.CacheException) InvalidMessageCacheException(diskCacheV111.util.InvalidMessageCacheException) InvalidMessageCacheException(diskCacheV111.util.InvalidMessageCacheException) IOException(java.io.IOException) BeanQueryMessage(org.dcache.vehicles.BeanQueryMessage) BeanQueryAllPropertiesMessage(org.dcache.vehicles.BeanQueryAllPropertiesMessage) NoRouteToCellException(dmg.cells.nucleus.NoRouteToCellException) HttpException(dmg.util.HttpException) BeanQuerySinglePropertyMessage(org.dcache.vehicles.BeanQuerySinglePropertyMessage) OutputStreamWriter(java.io.OutputStreamWriter) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter) TimeoutCacheException(diskCacheV111.util.TimeoutCacheException)

Aggregations

GsonBuilder (com.google.gson.GsonBuilder)1 CacheException (diskCacheV111.util.CacheException)1 InvalidMessageCacheException (diskCacheV111.util.InvalidMessageCacheException)1 TimeoutCacheException (diskCacheV111.util.TimeoutCacheException)1 CellPath (dmg.cells.nucleus.CellPath)1 NoRouteToCellException (dmg.cells.nucleus.NoRouteToCellException)1 HttpException (dmg.util.HttpException)1 IOException (java.io.IOException)1 OutputStreamWriter (java.io.OutputStreamWriter)1 Writer (java.io.Writer)1 BeanQueryAllPropertiesMessage (org.dcache.vehicles.BeanQueryAllPropertiesMessage)1 BeanQueryMessage (org.dcache.vehicles.BeanQueryMessage)1 BeanQuerySinglePropertyMessage (org.dcache.vehicles.BeanQuerySinglePropertyMessage)1