CatalogService.java [src/csip] Revision: 0904889a146754fe9a6b190735191a13b36f3796 Date: Fri Apr 01 09:14:04 MDT 2016
/*
* $Id$
*
* This file is part of the Cloud Services Integration Platform (CSIP),
* 2010-2013, Olaf David and others, Colorado State University.
*
* CSIP is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, version 2.1.
*
* CSIP is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with OMS. If not, see <http://www.gnu.org/licenses/lgpl.txt>.
*/
package csip;
import csip.Config.Registry;
import csip.utils.JSONUtils;
import csip.utils.Services;
import javax.ws.rs.*;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.UriInfo;
import org.codehaus.jettison.json.JSONArray;
import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;
/**
* Catalog service
*
* @author wlloyd,od
*/
@Path("")
public class CatalogService {
@GET
@Produces(MediaType.TEXT_PLAIN)
public String getTextCatalog(@Context UriInfo uriInfo) {
return getJSONCatalog(uriInfo);
}
@GET
@Produces(MediaType.APPLICATION_JSON)
public String getJSONCatalog(@Context UriInfo uriInfo) {
JSONArray o = new JSONArray();
try {
Registry r = Config.registry();
String host = Services.toPublicURL(uriInfo.getRequestUri()).toString();
for (Class<?> c : r.getServices()) {
JSONObject m = new JSONObject();
String url = host + "/" + r.getServicePath(c);
m.put(ModelDataService.KEY_NAME, r.getServiceName(c));
m.put(ModelDataService.KEY_DESC, r.getServiceDescription(c));
m.put(ModelDataService.KEY_URL, url);
o.put(m);
}
return o.toString(2).replace("\\/", "/");
} catch (JSONException ex) {
o.put(JSONUtils.error(ex.getMessage()));
}
return o.toString().replace("\\/", "/");
}
}