mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-10 07:25:44 +01:00
added jersey for rest api
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package sonia.scm.api.rest;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import sonia.scm.Group;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import com.sun.jersey.api.json.JSONConfiguration;
|
||||
import com.sun.jersey.api.json.JSONJAXBContext;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import javax.ws.rs.ext.ContextResolver;
|
||||
import javax.ws.rs.ext.Provider;
|
||||
|
||||
import javax.xml.bind.JAXBContext;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
@Provider
|
||||
public class JsonJaxbContextResolver implements ContextResolver<JAXBContext>
|
||||
{
|
||||
|
||||
/**
|
||||
* Constructs ...
|
||||
*
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public JsonJaxbContextResolver() throws Exception
|
||||
{
|
||||
this.context = new JSONJAXBContext(
|
||||
JSONConfiguration.mapped().rootUnwrapping(true).arrays(
|
||||
"members").build(), types.toArray(new Class[0]));
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param objectType
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public JAXBContext getContext(Class<?> objectType)
|
||||
{
|
||||
return (types.contains(objectType))
|
||||
? context
|
||||
: null;
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
private JAXBContext context;
|
||||
|
||||
/** Field description */
|
||||
private List<Class> types = Arrays.asList(new Class[] { Group.class });
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package sonia.scm.api.rest;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import com.sun.jersey.api.core.PackagesResourceConfig;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
public class UriExtensionsConfig extends PackagesResourceConfig
|
||||
{
|
||||
|
||||
/**
|
||||
* Constructs ...
|
||||
*
|
||||
*/
|
||||
public UriExtensionsConfig()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs ...
|
||||
*
|
||||
*
|
||||
* @param props
|
||||
*/
|
||||
public UriExtensionsConfig(Map<String, Object> props)
|
||||
{
|
||||
super(props);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs ...
|
||||
*
|
||||
*
|
||||
* @param paths
|
||||
*/
|
||||
public UriExtensionsConfig(String[] paths)
|
||||
{
|
||||
super(paths);
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Map<String, MediaType> getMediaTypeMappings()
|
||||
{
|
||||
if (mediaTypeMap == null)
|
||||
{
|
||||
mediaTypeMap = new HashMap<String, MediaType>();
|
||||
mediaTypeMap.put("json", MediaType.APPLICATION_JSON_TYPE);
|
||||
mediaTypeMap.put("xml", MediaType.APPLICATION_XML_TYPE);
|
||||
}
|
||||
|
||||
return mediaTypeMap;
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
private Map<String, MediaType> mediaTypeMap;
|
||||
}
|
||||
Reference in New Issue
Block a user