// Path: com.swookiee.runtime.ewok/src/main/java/com/swookiee/runtime/ewok/representation/ServiceRepresenation.java
// public class ServiceRepresenation {
// 
//     Map<String, Object> properties = new HashMap<>();
//     String bundle;
//     List<String> usingBundles = new ArrayList<>();
// 
//     public ServiceRepresenation() {
//     }
// 
//     public Map<String, Object> getProperties() {
//         return properties;
//     }
// 
//     public void setProperties(final Map<String, Object> properties) {
//         this.properties = properties;
//     }
// 
//     public void addProperty(final String key, final Object value) {
//         properties.put(key, value);
//     }
// 
//     public String getBundle() {
//         return bundle;
//     }
// 
//     public void setBundle(final String bundle) {
//         this.bundle = bundle;
//     }
// 
//     public List<String> getUsingBundles() {
//         return usingBundles;
//     }
// 
//     public void setUsingBundles(final List<String> usingBundles) {
//         this.usingBundles = usingBundles;
//     }
// 
//     public void addUsingBundle(final String usingBundle) {
//         usingBundles.add(usingBundle);
//     }
// 
// }


import java.io.IOException;
import java.util.Dictionary;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.swookiee.runtime.ewok.representation.ServiceRepresenation;
    public static <T> void jsonResponse(final HttpServletResponse response, final T toJson)
            throws IOException {
        final String jsonResponse = mapper.writeValueAsString(toJson);
        response.setContentType(APPLICATION_JSON);
        response.getWriter().println(jsonResponse);
    }

    public static long getId(final HttpServletRequest request) throws HttpErrorException {
        return ServletUtil.idExtractor.getId(request.getPathInfo());
    }

    public static Bundle checkAndGetBundle(final BundleContext bundleContext, final long bundleId) throws HttpErrorException {
        final Bundle bundle = bundleContext.getBundle(bundleId);

        if (bundle == null) {
            throw new HttpErrorException(String.format("Could not find Bundle %d", bundleId),
                    HttpServletResponse.SC_NOT_FOUND);
        }
        return bundle;
    }

    public static Map<String, String> transformToMapAndCleanUp(final Dictionary<String, String> source) {
        final Map<String, String> result = new HashMap<>();
        for (final Enumeration<String> keys = source.keys(); keys.hasMoreElements();) {
            final String key = keys.nextElement();
            result.put(key, source.get(key).replaceAll("[\u0000-\u001f]", ""));
        }
        return result;
    }

// Path: com.swookiee.runtime.ewok/src/main/java/com/swookiee/runtime/ewok/representation/ServiceRepresenation.java
// public class ServiceRepresenation {
// 
//     Map<String, Object> properties = new HashMap<>();
//     String bundle;
//     List<String> usingBundles = new ArrayList<>();
// 
//     public ServiceRepresenation() {
//     }
// 
//     public Map<String, Object> getProperties() {
//         return properties;
//     }
// 
//     public void setProperties(final Map<String, Object> properties) {
//         this.properties = properties;
//     }
// 
//     public void addProperty(final String key, final Object value) {
//         properties.put(key, value);
//     }
// 
//     public String getBundle() {
//         return bundle;
//     }
// 
//     public void setBundle(final String bundle) {
//         this.bundle = bundle;
//     }
// 
//     public List<String> getUsingBundles() {
//         return usingBundles;
//     }
// 
//     public void setUsingBundles(final List<String> usingBundles) {
//         this.usingBundles = usingBundles;
//     }
// 
//     public void addUsingBundle(final String usingBundle) {
//         usingBundles.add(usingBundle);
//     }
// 
// }


// Path: com.swookiee.runtime.ewok/src/main/java/com/swookiee/runtime/ewok/util/ServletUtil.java
import java.io.IOException;
import java.util.Dictionary;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.swookiee.runtime.ewok.representation.ServiceRepresenation;

    public static <T> void jsonResponse(final HttpServletResponse response, final T toJson)
            throws IOException {
        final String jsonResponse = mapper.writeValueAsString(toJson);
        response.setContentType(APPLICATION_JSON);
        response.getWriter().println(jsonResponse);
    }

    public static long getId(final HttpServletRequest request) throws HttpErrorException {
        return ServletUtil.idExtractor.getId(request.getPathInfo());
    }

    public static Bundle checkAndGetBundle(final BundleContext bundleContext, final long bundleId) throws HttpErrorException {
        final Bundle bundle = bundleContext.getBundle(bundleId);

        if (bundle == null) {
            throw new HttpErrorException(String.format("Could not find Bundle %d", bundleId),
                    HttpServletResponse.SC_NOT_FOUND);
        }
        return bundle;
    }

    public static Map<String, String> transformToMapAndCleanUp(final Dictionary<String, String> source) {
        final Map<String, String> result = new HashMap<>();
        for (final Enumeration<String> keys = source.keys(); keys.hasMoreElements();) {
            final String key = keys.nextElement();
            result.put(key, source.get(key).replaceAll("[\u0000-\u001f]", ""));
        }
        return result;
    }

    public static void addServiceProperties(final ServiceReference<?> serviceReference, final ServiceRepresenation represenation) {