csip.CatalogService Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of csip-core Show documentation
Show all versions of csip-core Show documentation
The Cloud Services Integration Platform is a SoA implementation to offer a Model-as-a-Service framework, Application Programming Interface, deployment infrastructure, and service implementations for environmental modeling.
/*
* $Id: CatalogService.java 275e3562017d 2019-02-07 od $
*
* This file is part of the Cloud Services Integration Platform (CSIP),
* a Model-as-a-Service framework, API and application suite.
*
* 2012-2019, Olaf David and others, OMSLab, Colorado State University.
*
* OMSLab licenses this file to you under the MIT license.
* See the LICENSE file in the project root for more information.
*/
package csip;
import csip.utils.JSONUtils;
import csip.utils.Services;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.*;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
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 {
static final Logger LOG = Config.LOG;
// static SimpleCache cat = new SimpleCache<>();
@GET
@Produces(MediaType.TEXT_PLAIN)
public String getTextCatalog(@Context HttpServletRequest httpReq) {
return getJSONCatalog(httpReq);
}
@GET
@Produces(MediaType.APPLICATION_JSON)
public String getJSONCatalog(@Context HttpServletRequest httpReq) {
LOG.log(Level.INFO, "HTTP/GET {0}", httpReq.getRequestURL().toString());
// return cat.get(Config.getRegistry(), (Registry r) -> {
Registry r = Config.getRegistry();
JSONArray o = new JSONArray();
try {
String host = Services.getPublicRequestURL(httpReq);
if (!host.endsWith("/")) {
host += "/";
}
for (Class> c : r.getServices()) {
String path = host + Utils.getServicePath(c);
JSONObject info = Utils.getServiceInfo(c);
info.put(ModelDataService.KEY_SERVICE_URL, path);
o.put(info);
}
return o.toString(2).replace("\\/", "/");
} catch (JSONException ex) {
o.put(JSONUtils.error(ex.getMessage()));
LOG.log(Level.SEVERE, null, ex);
}
return o.toString().replace("\\/", "/");
// });
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy