added prototype web interface written in nim
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
package com.oggio88.jpacrepo.annotation;
|
||||
|
||||
import javax.ws.rs.NameBinding;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
@NameBinding
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface CORSManaged
|
||||
{
|
||||
}
|
@@ -33,6 +33,8 @@ public class ApplicationContext
|
||||
|
||||
public boolean invalidateCache = true;
|
||||
|
||||
public boolean cors_enabled;
|
||||
|
||||
public ApplicationContext(String propertyFile)
|
||||
{
|
||||
systemProperties = new Properties();
|
||||
@@ -65,6 +67,10 @@ public class ApplicationContext
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
String prop = System.getProperty("org.oggio88.jpacrepo.cors");
|
||||
if (prop != null)
|
||||
cors_enabled = Boolean.parseBoolean(prop);
|
||||
}
|
||||
|
||||
public Properties getSystemProperties()
|
||||
|
@@ -24,6 +24,7 @@ public class ApplicationConfig extends Application
|
||||
{
|
||||
HashSet<Class<?>> c = new HashSet<>();
|
||||
c.add(PacmanWebService.class);
|
||||
c.add(CORSFilter.class);
|
||||
classes = Collections.unmodifiableSet(c);
|
||||
}
|
||||
|
||||
|
35
src/main/java/com/oggio88/jpacrepo/service/CORSFilter.java
Normal file
35
src/main/java/com/oggio88/jpacrepo/service/CORSFilter.java
Normal file
@@ -0,0 +1,35 @@
|
||||
package com.oggio88.jpacrepo.service;
|
||||
|
||||
import com.oggio88.jpacrepo.annotation.CORSManaged;
|
||||
import com.oggio88.jpacrepo.context.ApplicationContext;
|
||||
import com.oggio88.jpacrepo.context.DefaultConfiguration;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.ws.rs.container.ContainerRequestContext;
|
||||
import javax.ws.rs.container.ContainerResponseContext;
|
||||
import javax.ws.rs.container.ContainerResponseFilter;
|
||||
import javax.ws.rs.ext.Provider;
|
||||
import java.io.IOException;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
@Provider
|
||||
@CORSManaged
|
||||
public class CORSFilter implements ContainerResponseFilter
|
||||
{
|
||||
private final Logger log = Logger.getLogger(CORSFilter.class.getName());
|
||||
|
||||
@Inject
|
||||
@DefaultConfiguration
|
||||
ApplicationContext ctx;
|
||||
|
||||
@Override
|
||||
public void filter(ContainerRequestContext containerRequestContext,
|
||||
ContainerResponseContext containerResponseContext) throws IOException
|
||||
{
|
||||
if (!ctx.cors_enabled)
|
||||
{
|
||||
containerResponseContext.getHeaders().add("Access-Control-Allow-Origin", "*");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,5 +1,6 @@
|
||||
package com.oggio88.jpacrepo.service;
|
||||
|
||||
import com.oggio88.jpacrepo.annotation.CORSManaged;
|
||||
import com.oggio88.jpacrepo.context.ApplicationContext;
|
||||
import com.oggio88.jpacrepo.context.DefaultConfiguration;
|
||||
import com.oggio88.jpacrepo.model.PkgData;
|
||||
@@ -8,6 +9,7 @@ import com.oggio88.jpacrepo.model.PkgName;
|
||||
import com.oggio88.jpacrepo.model.StringList;
|
||||
import com.oggio88.jpacrepo.pacbase.Parser;
|
||||
import com.oggio88.jpacrepo.persistence.QueryEngine;
|
||||
import org.apache.commons.compress.archivers.tar.TarArchiveInputStream;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.ejb.*;
|
||||
@@ -30,6 +32,7 @@ import java.util.TreeMap;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
@CORSManaged
|
||||
@Singleton
|
||||
@Path("/pkg")
|
||||
@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
|
||||
@@ -59,35 +62,6 @@ public class PacmanWebService
|
||||
@DefaultConfiguration
|
||||
private ApplicationContext ctx;
|
||||
|
||||
@GET
|
||||
@Path("search")
|
||||
public Response getPackage(@QueryParam("name") String name,
|
||||
@QueryParam("version") String version,
|
||||
@QueryParam("arch") String arch,
|
||||
@QueryParam("filename") String filename,
|
||||
@QueryParam("md5sum") String md5sum)
|
||||
{
|
||||
if (md5sum != null)
|
||||
{
|
||||
return getPackageByHash(md5sum);
|
||||
}
|
||||
else if (filename != null)
|
||||
{
|
||||
return getPackageByFileName(filename);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
QueryEngine qe = new QueryEngine(PkgData.class);
|
||||
qe.select();
|
||||
if (name != null) qe.where("name", "=", name);
|
||||
if (version != null) qe.where("version", "=", version);
|
||||
if (arch != null) qe.where("arch", "=", arch);
|
||||
String query = qe.build();
|
||||
return manageQueryResult(em.createQuery(query).getResultList());
|
||||
}
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("searchByName/{name}")
|
||||
public Response searchByName(@PathParam("name") String name)
|
||||
@@ -139,6 +113,7 @@ public class PacmanWebService
|
||||
}
|
||||
|
||||
@GET
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@Path("map")
|
||||
public Response getPackageMap()
|
||||
{
|
||||
@@ -317,6 +292,7 @@ public class PacmanWebService
|
||||
}
|
||||
|
||||
@GET
|
||||
@CORSManaged
|
||||
@Path("/search")
|
||||
public List<PkgData> searchPackage(
|
||||
@QueryParam("name") String name,
|
||||
@@ -377,6 +353,12 @@ public class PacmanWebService
|
||||
return query.getResultList();
|
||||
}
|
||||
|
||||
@POST
|
||||
public Response foo()
|
||||
{
|
||||
TarArchiveouputStream tais = new TarArchiveOutputStream();
|
||||
}
|
||||
|
||||
private Response manageQueryResult(List<PkgData> list)
|
||||
{
|
||||
return manageQueryResult(list, false);
|
||||
|
Reference in New Issue
Block a user