You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stanbol.apache.org by re...@apache.org on 2013/06/06 16:31:00 UTC

svn commit: r1490298 - in /stanbol/branches/commons-ng: ./ commons/ commons/web/base/ commons/web/base/src/main/java/org/apache/stanbol/commons/web/base/ commons/web/base/src/main/java/org/apache/stanbol/commons/web/base/readers/ commons/web/base/src/m...

Author: reto
Date: Thu Jun  6 14:31:00 2013
New Revision: 1490298

URL: http://svn.apache.org/r1490298
Log:
STANBOL-1097: brute force to have it compile without servlet dependencies

Removed:
    stanbol/branches/commons-ng/commons/web/base/src/main/java/org/apache/stanbol/commons/web/base/ContextHelper.java
    stanbol/branches/commons-ng/commons/web/base/src/test/java/org/apache/stanbol/commons/web/base/MockHttpHeaders.java
    stanbol/branches/commons-ng/commons/web/base/src/test/java/org/apache/stanbol/commons/web/base/MockServletContext.java
Modified:
    stanbol/branches/commons-ng/commons/pom.xml
    stanbol/branches/commons-ng/commons/web/base/pom.xml
    stanbol/branches/commons-ng/commons/web/base/src/main/java/org/apache/stanbol/commons/web/base/CorsHelper.java
    stanbol/branches/commons-ng/commons/web/base/src/main/java/org/apache/stanbol/commons/web/base/readers/GraphReader.java
    stanbol/branches/commons-ng/commons/web/base/src/main/java/org/apache/stanbol/commons/web/base/resource/BaseStanbolResource.java
    stanbol/branches/commons-ng/commons/web/base/src/main/java/org/apache/stanbol/commons/web/base/writers/GraphWriter.java
    stanbol/branches/commons-ng/commons/web/base/src/test/java/org/apache/stanbol/commons/web/base/CorsAccessControlAllowMethodTest.java
    stanbol/branches/commons-ng/pom.xml

Modified: stanbol/branches/commons-ng/commons/pom.xml
URL: http://svn.apache.org/viewvc/stanbol/branches/commons-ng/commons/pom.xml?rev=1490298&r1=1490297&r2=1490298&view=diff
==============================================================================
--- stanbol/branches/commons-ng/commons/pom.xml (original)
+++ stanbol/branches/commons-ng/commons/pom.xml Thu Jun  6 14:31:00 2013
@@ -21,13 +21,13 @@
   <parent>
     <groupId>org.apache.stanbol</groupId>
     <artifactId>stanbol-parent</artifactId>
-    <version>4-SNAPSHOT</version>
+    <version>5-SNAPSHOT</version>
     <relativePath>../parent</relativePath>
   </parent>
 
   <groupId>org.apache.stanbol</groupId>
   <artifactId>apache-stanbol-commons</artifactId>
-  <version>0.12.0-SNAPSHOT</version>
+  <version>1.0.0-SNAPSHOT</version>
   <packaging>pom</packaging>
 
   <name>Apache Stanbol Commons</name>

Modified: stanbol/branches/commons-ng/commons/web/base/pom.xml
URL: http://svn.apache.org/viewvc/stanbol/branches/commons-ng/commons/web/base/pom.xml?rev=1490298&r1=1490297&r2=1490298&view=diff
==============================================================================
--- stanbol/branches/commons-ng/commons/web/base/pom.xml (original)
+++ stanbol/branches/commons-ng/commons/web/base/pom.xml Thu Jun  6 14:31:00 2013
@@ -21,13 +21,13 @@
   <parent>
     <groupId>org.apache.stanbol</groupId>
     <artifactId>stanbol-parent</artifactId>
-    <version>4-SNAPSHOT</version>
+    <version>5-SNAPSHOT</version>
     <relativePath>../../../parent</relativePath>
   </parent>
 
   <groupId>org.apache.stanbol</groupId>
   <artifactId>org.apache.stanbol.commons.web.base</artifactId>
-  <version>0.12.0-SNAPSHOT</version>
+  <version>1.0.0-SNAPSHOT</version>
   <packaging>bundle</packaging>
 
   <name>Apache Stanbol Commons Web Base</name>
@@ -70,9 +70,9 @@
             </Export-Package>
             <Import-Package>
               javax.servlet.*; version="[2.5.0,4.0.0)",
-              javax.ws.rs;version="[0,2)",
-              javax.ws.rs.ext;version="[0,2)",
-              javax.ws.rs.core;version="[0,2)",
+              javax.ws.rs;version="[2,3)",
+              javax.ws.rs.ext;version="[2,3)",
+              javax.ws.rs.core;version="[2,3)",
               org.apache.stanbol.commons.web.base,
               org.apache.stanbol.commons.web.base.format,
               org.apache.stanbol.commons.web.base.readers,
@@ -102,12 +102,12 @@
 
     <dependency>
         <groupId>javax.ws.rs</groupId>
-        <artifactId>jsr311-api</artifactId>
+        <artifactId>javax.ws.rs-api</artifactId>
     </dependency>
-    <dependency>
+    <!-- <dependency>
       <groupId>javax.servlet</groupId>
       <artifactId>servlet-api</artifactId>
-    </dependency>
+    </dependency> -->
 
     <!-- generic tax -->
     <dependency>

Modified: stanbol/branches/commons-ng/commons/web/base/src/main/java/org/apache/stanbol/commons/web/base/CorsHelper.java
URL: http://svn.apache.org/viewvc/stanbol/branches/commons-ng/commons/web/base/src/main/java/org/apache/stanbol/commons/web/base/CorsHelper.java?rev=1490298&r1=1490297&r2=1490298&view=diff
==============================================================================
--- stanbol/branches/commons-ng/commons/web/base/src/main/java/org/apache/stanbol/commons/web/base/CorsHelper.java (original)
+++ stanbol/branches/commons-ng/commons/web/base/src/main/java/org/apache/stanbol/commons/web/base/CorsHelper.java Thu Jun  6 14:31:00 2013
@@ -23,7 +23,6 @@ import java.util.Collection;
 import java.util.List;
 import java.util.Set;
 
-import javax.servlet.ServletContext;
 import javax.ws.rs.WebApplicationException;
 import javax.ws.rs.core.HttpHeaders;
 import javax.ws.rs.core.Response.ResponseBuilder;
@@ -46,216 +45,218 @@ import javax.ws.rs.core.Response.Status;
  * @author Rupert Westenthaler
  * 
  */
-public final class CorsHelper {
-
-    /**
-     * The "Origin" header as used in requests
-     */
-    public static final String ORIGIN = "Origin";
-    /**
-     * The ALLOW_ORIGIN header as added to responses
-     */
-    public static final String ALLOW_ORIGIN = "Access-Control-Allow-Origin";
-
-    /**
-     * The "Access-Control-Request-Method" header
-     */
-    public static final String REQUEST_METHOD = "Access-Control-Request-Method";
-
-    /**
-     * The "Access-Control-Request-Headers" header
-     */
-    public static final String REQUEST_HEADERS = "Access-Control-Request-Headers";
-
-    /**
-     * The "Access-Control-Request-Headers" header
-     */
-    public static final String ALLOW_HEADERS = "Access-Control-Allow-Headers";
-
-    /**
-     * The "Access-Control-Allow-Methods" header
-     */
-    public static final String ALLOW_METHODS = "Access-Control-Allow-Methods";
-
-    /**
-     * The "Access-Control-Expose-Headers" header
-     */
-    public static final String EXPOSE_HEADERS = "Access-Control-Expose-Headers";
-
-    /**
-     * The default methods for the Access-Control-Request-Method header field. Set to "GET, POST, OPTIONS"
-     */
-    public static final String DEFAULT_REQUEST_METHODS = "GET, POST, OPTIONS";
-
-    /**
-     * This methods checks the parsed origin against the present configuration and returns if the data
-     * returned by this Stanbol instance can be shared with the parsed origin.
-     * <p>
-     * The allowed <a href="http://enable-cors.org/">CORS</a> origins for this Stanbol instance are configured
-     * for the {@link JerseyEndpoint} component and added to the {@link ServletContext} under the
-     * {@link JerseyEndpoint#CORS_ORIGIN} key.
-     * 
-     * @param origin
-     *            the origin host
-     * @param context
-     *            the servlet context
-     * @return <code>true</code> if the configuration includes the pased origin and the data can be shared
-     *         with this host. Otherwise <code>false</code>.
-     */
-    @SuppressWarnings("unchecked")
-    public static boolean checkCorsOrigin(String origin, ServletContext context) {
-        Set<String> originsConfig = (Set<String>) context.getAttribute(CORS_ORIGIN);
-        return originsConfig.contains("*") || originsConfig.contains(origin);
-    }
-
-    /**
-     * Adds the Origin response header to the parsed response builder based on the headers of an request.
-     * 
-     * @param context
-     *            the ServletContext holding the {@link JerseyEndpoint#CORS_ORIGIN} configuration.
-     * @param responseBuilder
-     *            The {@link ResponseBuilder} the origin header is added to if (1) a origin header is present
-     *            in the request headers and (1) the parsed origin is compatible with the configuration set
-     *            for the {@link JerseyEndpoint}.
-     * @param requestHeaders
-     *            the request headers
-     * @return <code>true</code> if the origin header was added. Otherwise <code>false</code>
-     * @throws WebApplicationException
-     *             it the request headers define multiple values for the "Origin" header an
-     *             WebApplicationException with the Status "BAD_REQUEST" is thrown.
-     */
-    public static boolean addCORSOrigin(ServletContext servletContext,
-                                        ResponseBuilder responseBuilder,
-                                        HttpHeaders requestHeaders) throws WebApplicationException {
-        List<String> originHeaders = requestHeaders.getRequestHeader(CorsHelper.ORIGIN);
-        if (originHeaders != null && !originHeaders.isEmpty()) {
-            if (originHeaders.size() != 1) {
-                throw new WebApplicationException(new IllegalStateException(
-                        "Multiple 'Origin' header values '" + originHeaders
-                                + "' found in the request headers"), Status.BAD_REQUEST);
-            } else {
-                Set<String> originsConfig = (Set<String>) servletContext.getAttribute(CORS_ORIGIN);
-                if (originsConfig.contains("*")) { // if config includes *
-                    responseBuilder.header(CorsHelper.ALLOW_ORIGIN, "*"); // add also * to the header
-                    addExposedHeaders(servletContext, responseBuilder, requestHeaders);
-                    return true;
-                } else if (originsConfig.contains(originHeaders.get(0))) {
-                    // otherwise add the specific Origin host
-                    addExposedHeaders(servletContext, responseBuilder, requestHeaders);
-                    responseBuilder.header(CorsHelper.ALLOW_ORIGIN, originHeaders.get(0));
-                    return true;
-                }
-            }
-        }
-        return false;
-    }
-
-    /**
-     * Adds the
-     * 
-     * @param servletContext
-     * @param responseBuilder
-     * @param httpHeaders
-     */
-    private static void addExposedHeaders(ServletContext servletContext,
-                                          ResponseBuilder responseBuilder,
-                                          HttpHeaders httpHeaders) {
-
-        Set<String> exposedHeadersConfig = (Set<String>) servletContext
-                .getAttribute(CORS_ACCESS_CONTROL_EXPOSE_HEADERS);
-        if (exposedHeadersConfig != null && !exposedHeadersConfig.isEmpty()) {
-            StringBuilder requestHeader = new StringBuilder();
-            boolean added = false;
-            for (String header : exposedHeadersConfig) {
-                if (header != null && !header.isEmpty()) {
-                    if (added) {
-                        requestHeader.append(", ");
-                    }
-                    requestHeader.append(header);
-                    added = true;
-                }
-            }
-            if (added) {
-                responseBuilder.header(EXPOSE_HEADERS, requestHeader.toString());
-            }
-        }
-    }
-
-    /**
-     * Enable CORS for OPTION requests based on the provided request headers and the allowMethods.
-     * <p>
-     * The {@link #addCORSOrigin(ResponseBuilder, HttpHeaders)} method is used deal with the origin. The
-     * allowMethods are set to the parsed values or to {@link CorsHelper#DEFAULT_REQUEST_METHODS} if non is
-     * parsed of the parsed values do not contain a single value that is not <code>null</code> nor empty.
-     * 
-     * @param context
-     *            the ServletContext holding the {@link JerseyEndpoint#CORS_ORIGIN} configuration.
-     * @param responseBuilder
-     *            The {@link ResponseBuilder} to add the CORS headers
-     * @param requestHeaders
-     *            the headers of the request
-     * @param allowMethods
-     *            the allowMethods to if <code>null</code> or empty, the
-     *            {@link CorsHelper#DEFAULT_REQUEST_METHODS} are added
-     * @return <code>true</code> if the CORS header where added or
-     * @throws WebApplicationException
-     *             it the request headers define multiple values for the "Origin" header an
-     *             WebApplicationException with the Status "BAD_REQUEST" is thrown.
-     * @throws IllegalArgumentException
-     *             if a parsed allowMethods is <code>null</code> or empty. NOT if the String array is
-     *             <code>null</code> or empty, but if any of the items within the array is <code>null</code>
-     *             or empty!
-     */
-    public static boolean enableCORS(ServletContext context,
-                                     ResponseBuilder responseBuilder,
-                                     HttpHeaders requestHeaders,
-                                     String... allowMethods) throws WebApplicationException {
-        // first check if the Origin is present
-        if (addCORSOrigin(context, responseBuilder, requestHeaders)) {
-            // now add the allowedMethods
-            boolean added = false;
-            StringBuilder methods = new StringBuilder();
-            if (allowMethods != null) {
-                for (String method : allowMethods) {
-                    if (method != null && !method.isEmpty()) {
-                        if (added) {
-                            methods.append(", ");
-                        }
-                        methods.append(method);
-                        added = true;
-                    } else {
-                        // throw an exception to make it easier to debug errors
-                        throw new IllegalArgumentException("Parsed allow methods MUST NOT be NULL nor empty!");
-                    }
-                }
-            }
-            if (!added) {
-                methods.append(CorsHelper.DEFAULT_REQUEST_METHODS);
-            }
-            responseBuilder.header(CorsHelper.ALLOW_METHODS, methods.toString());
-            // third replay parsed "Access-Control-Request-Headers" values
-            // currently there is no need to restrict such headers so the simplest
-            // way is to return them as they are parsed
-            List<String> requestHeaderValues = requestHeaders.getRequestHeader(REQUEST_HEADERS);
-            added = false;
-            if (requestHeaderValues != null && !requestHeaderValues.isEmpty()) {
-                StringBuilder requestHeader = new StringBuilder();
-                for (String header : requestHeaderValues) {
-                    if (header != null && !header.isEmpty()) {
-                        if (added) {
-                            requestHeader.append(", ");
-                        }
-                        requestHeader.append(header);
-                        added = true;
-                    }
-                }
-                if (added) {
-                    responseBuilder.header(ALLOW_HEADERS, requestHeader.toString());
-                }
-            }
-            return true;
-        } else {
-            return false;
-        }
-    }
-}
+//TODO recreate (or provide functionality by other means
+public final class CorsHelper {}
+//
+//    /**
+//     * The "Origin" header as used in requests
+//     */
+//    public static final String ORIGIN = "Origin";
+//    /**
+//     * The ALLOW_ORIGIN header as added to responses
+//     */
+//    public static final String ALLOW_ORIGIN = "Access-Control-Allow-Origin";
+//
+//    /**
+//     * The "Access-Control-Request-Method" header
+//     */
+//    public static final String REQUEST_METHOD = "Access-Control-Request-Method";
+//
+//    /**
+//     * The "Access-Control-Request-Headers" header
+//     */
+//    public static final String REQUEST_HEADERS = "Access-Control-Request-Headers";
+//
+//    /**
+//     * The "Access-Control-Request-Headers" header
+//     */
+//    public static final String ALLOW_HEADERS = "Access-Control-Allow-Headers";
+//
+//    /**
+//     * The "Access-Control-Allow-Methods" header
+//     */
+//    public static final String ALLOW_METHODS = "Access-Control-Allow-Methods";
+//
+//    /**
+//     * The "Access-Control-Expose-Headers" header
+//     */
+//    public static final String EXPOSE_HEADERS = "Access-Control-Expose-Headers";
+//
+//    /**
+//     * The default methods for the Access-Control-Request-Method header field. Set to "GET, POST, OPTIONS"
+//     */
+//    public static final String DEFAULT_REQUEST_METHODS = "GET, POST, OPTIONS";
+//
+//    /**
+//     * This methods checks the parsed origin against the present configuration and returns if the data
+//     * returned by this Stanbol instance can be shared with the parsed origin.
+//     * <p>
+//     * The allowed <a href="http://enable-cors.org/">CORS</a> origins for this Stanbol instance are configured
+//     * for the {@link JerseyEndpoint} component and added to the {@link ServletContext} under the
+//     * {@link JerseyEndpoint#CORS_ORIGIN} key.
+//     * 
+//     * @param origin
+//     *            the origin host
+//     * @param context
+//     *            the servlet context
+//     * @return <code>true</code> if the configuration includes the pased origin and the data can be shared
+//     *         with this host. Otherwise <code>false</code>.
+//     */
+//    @SuppressWarnings("unchecked")
+//    public static boolean checkCorsOrigin(String origin, ServletContext context) {
+//        Set<String> originsConfig = (Set<String>) context.getAttribute(CORS_ORIGIN);
+//        return originsConfig.contains("*") || originsConfig.contains(origin);
+//    }
+//
+//    /**
+//     * Adds the Origin response header to the parsed response builder based on the headers of an request.
+//     * 
+//     * @param context
+//     *            the ServletContext holding the {@link JerseyEndpoint#CORS_ORIGIN} configuration.
+//     * @param responseBuilder
+//     *            The {@link ResponseBuilder} the origin header is added to if (1) a origin header is present
+//     *            in the request headers and (1) the parsed origin is compatible with the configuration set
+//     *            for the {@link JerseyEndpoint}.
+//     * @param requestHeaders
+//     *            the request headers
+//     * @return <code>true</code> if the origin header was added. Otherwise <code>false</code>
+//     * @throws WebApplicationException
+//     *             it the request headers define multiple values for the "Origin" header an
+//     *             WebApplicationException with the Status "BAD_REQUEST" is thrown.
+//     */
+//    public static boolean addCORSOrigin(ServletContext servletContext,
+//                                        ResponseBuilder responseBuilder,
+//                                        HttpHeaders requestHeaders) throws WebApplicationException {
+//        List<String> originHeaders = requestHeaders.getRequestHeader(CorsHelper.ORIGIN);
+//        if (originHeaders != null && !originHeaders.isEmpty()) {
+//            if (originHeaders.size() != 1) {
+//                throw new WebApplicationException(new IllegalStateException(
+//                        "Multiple 'Origin' header values '" + originHeaders
+//                                + "' found in the request headers"), Status.BAD_REQUEST);
+//            } else {
+//                Set<String> originsConfig = (Set<String>) servletContext.getAttribute(CORS_ORIGIN);
+//                if (originsConfig.contains("*")) { // if config includes *
+//                    responseBuilder.header(CorsHelper.ALLOW_ORIGIN, "*"); // add also * to the header
+//                    addExposedHeaders(servletContext, responseBuilder, requestHeaders);
+//                    return true;
+//                } else if (originsConfig.contains(originHeaders.get(0))) {
+//                    // otherwise add the specific Origin host
+//                    addExposedHeaders(servletContext, responseBuilder, requestHeaders);
+//                    responseBuilder.header(CorsHelper.ALLOW_ORIGIN, originHeaders.get(0));
+//                    return true;
+//                }
+//            }
+//        }
+//        return false;
+//    }
+//
+//    /**
+//     * Adds the
+//     * 
+//     * @param servletContext
+//     * @param responseBuilder
+//     * @param httpHeaders
+//     */
+//    private static void addExposedHeaders(ServletContext servletContext,
+//                                          ResponseBuilder responseBuilder,
+//                                          HttpHeaders httpHeaders) {
+//
+//        Set<String> exposedHeadersConfig = (Set<String>) servletContext
+//                .getAttribute(CORS_ACCESS_CONTROL_EXPOSE_HEADERS);
+//        if (exposedHeadersConfig != null && !exposedHeadersConfig.isEmpty()) {
+//            StringBuilder requestHeader = new StringBuilder();
+//            boolean added = false;
+//            for (String header : exposedHeadersConfig) {
+//                if (header != null && !header.isEmpty()) {
+//                    if (added) {
+//                        requestHeader.append(", ");
+//                    }
+//                    requestHeader.append(header);
+//                    added = true;
+//                }
+//            }
+//            if (added) {
+//                responseBuilder.header(EXPOSE_HEADERS, requestHeader.toString());
+//            }
+//        }
+//    }
+//
+//    /**
+//     * Enable CORS for OPTION requests based on the provided request headers and the allowMethods.
+//     * <p>
+//     * The {@link #addCORSOrigin(ResponseBuilder, HttpHeaders)} method is used deal with the origin. The
+//     * allowMethods are set to the parsed values or to {@link CorsHelper#DEFAULT_REQUEST_METHODS} if non is
+//     * parsed of the parsed values do not contain a single value that is not <code>null</code> nor empty.
+//     * 
+//     * @param context
+//     *            the ServletContext holding the {@link JerseyEndpoint#CORS_ORIGIN} configuration.
+//     * @param responseBuilder
+//     *            The {@link ResponseBuilder} to add the CORS headers
+//     * @param requestHeaders
+//     *            the headers of the request
+//     * @param allowMethods
+//     *            the allowMethods to if <code>null</code> or empty, the
+//     *            {@link CorsHelper#DEFAULT_REQUEST_METHODS} are added
+//     * @return <code>true</code> if the CORS header where added or
+//     * @throws WebApplicationException
+//     *             it the request headers define multiple values for the "Origin" header an
+//     *             WebApplicationException with the Status "BAD_REQUEST" is thrown.
+//     * @throws IllegalArgumentException
+//     *             if a parsed allowMethods is <code>null</code> or empty. NOT if the String array is
+//     *             <code>null</code> or empty, but if any of the items within the array is <code>null</code>
+//     *             or empty!
+//     */
+//    public static boolean enableCORS(ServletContext context,
+//                                     ResponseBuilder responseBuilder,
+//                                     HttpHeaders requestHeaders,
+//                                     String... allowMethods) throws WebApplicationException {
+//        // first check if the Origin is present
+//        if (addCORSOrigin(context, responseBuilder, requestHeaders)) {
+//            // now add the allowedMethods
+//            boolean added = false;
+//            StringBuilder methods = new StringBuilder();
+//            if (allowMethods != null) {
+//                for (String method : allowMethods) {
+//                    if (method != null && !method.isEmpty()) {
+//                        if (added) {
+//                            methods.append(", ");
+//                        }
+//                        methods.append(method);
+//                        added = true;
+//                    } else {
+//                        // throw an exception to make it easier to debug errors
+//                        throw new IllegalArgumentException("Parsed allow methods MUST NOT be NULL nor empty!");
+//                    }
+//                }
+//            }
+//            if (!added) {
+//                methods.append(CorsHelper.DEFAULT_REQUEST_METHODS);
+//            }
+//            responseBuilder.header(CorsHelper.ALLOW_METHODS, methods.toString());
+//            // third replay parsed "Access-Control-Request-Headers" values
+//            // currently there is no need to restrict such headers so the simplest
+//            // way is to return them as they are parsed
+//            List<String> requestHeaderValues = requestHeaders.getRequestHeader(REQUEST_HEADERS);
+//            added = false;
+//            if (requestHeaderValues != null && !requestHeaderValues.isEmpty()) {
+//                StringBuilder requestHeader = new StringBuilder();
+//                for (String header : requestHeaderValues) {
+//                    if (header != null && !header.isEmpty()) {
+//                        if (added) {
+//                            requestHeader.append(", ");
+//                        }
+//                        requestHeader.append(header);
+//                        added = true;
+//                    }
+//                }
+//                if (added) {
+//                    responseBuilder.header(ALLOW_HEADERS, requestHeader.toString());
+//                }
+//            }
+//            return true;
+//        } else {
+//            return false;
+//        }
+//    }
+//}
+//
\ No newline at end of file

Modified: stanbol/branches/commons-ng/commons/web/base/src/main/java/org/apache/stanbol/commons/web/base/readers/GraphReader.java
URL: http://svn.apache.org/viewvc/stanbol/branches/commons-ng/commons/web/base/src/main/java/org/apache/stanbol/commons/web/base/readers/GraphReader.java?rev=1490298&r1=1490297&r2=1490298&view=diff
==============================================================================
--- stanbol/branches/commons-ng/commons/web/base/src/main/java/org/apache/stanbol/commons/web/base/readers/GraphReader.java (original)
+++ stanbol/branches/commons-ng/commons/web/base/src/main/java/org/apache/stanbol/commons/web/base/readers/GraphReader.java Thu Jun  6 14:31:00 2013
@@ -34,7 +34,6 @@ import java.util.Collections;
 import java.util.HashSet;
 import java.util.Set;
 
-import javax.servlet.ServletContext;
 import javax.ws.rs.WebApplicationException;
 import javax.ws.rs.core.Context;
 import javax.ws.rs.core.MediaType;
@@ -44,11 +43,12 @@ import javax.ws.rs.ext.Provider;
 
 import org.apache.clerezza.rdf.core.Graph;
 import org.apache.clerezza.rdf.core.serializedform.Parser;
-import org.apache.stanbol.commons.web.base.ContextHelper;
+import org.apache.felix.scr.annotations.Reference;
 
 /**
- * JAX-RS provider that parses RDF by fetching the OSGi parsing service from the ServletContext.
+ * JAX-RS provider that parses RDF by using the OSGi parsing service
  */
+//TODO make it a service/component
 @Provider
 public class GraphReader implements MessageBodyReader<Graph> {
 
@@ -67,12 +67,9 @@ public class GraphReader implements Mess
         SUPPORTED_MEDIA_TYPES = Collections.unmodifiableSet(types);
     }
 
-    @Context
-    protected ServletContext servletContext;
 
-    protected Parser getParser() {
-        return ContextHelper.getServiceFromContext(Parser.class, servletContext);
-    }
+    @Reference
+    private Parser parser;
 
     @Override
     public boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
@@ -86,12 +83,6 @@ public class GraphReader implements Mess
                           MediaType mediaType,
                           MultivaluedMap<String,String> httpHeaders,
                           InputStream entityStream) throws IOException, WebApplicationException {
-        Parser parser = getParser();
-        if (parser == null) {
-            RuntimeException e = new RuntimeException(String.format(
-                "Could not find RDF Parser implementing '%s' in OSGi context.", Parser.class.getName()));
-            throw new WebApplicationException(e);
-        }
         return parser.parse(entityStream, mediaType.toString());
     }
 }

Modified: stanbol/branches/commons-ng/commons/web/base/src/main/java/org/apache/stanbol/commons/web/base/resource/BaseStanbolResource.java
URL: http://svn.apache.org/viewvc/stanbol/branches/commons-ng/commons/web/base/src/main/java/org/apache/stanbol/commons/web/base/resource/BaseStanbolResource.java?rev=1490298&r1=1490297&r2=1490298&view=diff
==============================================================================
--- stanbol/branches/commons-ng/commons/web/base/src/main/java/org/apache/stanbol/commons/web/base/resource/BaseStanbolResource.java (original)
+++ stanbol/branches/commons-ng/commons/web/base/src/main/java/org/apache/stanbol/commons/web/base/resource/BaseStanbolResource.java Thu Jun  6 14:31:00 2013
@@ -21,7 +21,6 @@ import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
 
-import javax.servlet.ServletContext;
 import javax.ws.rs.Path;
 import javax.ws.rs.core.Context;
 import javax.ws.rs.core.UriBuilder;
@@ -54,8 +53,6 @@ public class BaseStanbolResource {
     @Context
     protected UriInfo uriInfo;
 
-    @Context
-    protected ServletContext servletContext;
 
     public URI getRequestUri(){
         return uriInfo.getAbsolutePath();
@@ -75,7 +72,7 @@ public class BaseStanbolResource {
      * Because of this it will only work with the default {@link #SYSTEM_CONSOLE}.
      * @return The URI for the Apache Felix Webconsole
      */
-    public URI getConsoleBaseUri() {
+    /*public URI getConsoleBaseUri() {
         String root = getRootUrl();
         UriBuilder consolePathBuilder;
         if(StringUtils.isNotBlank(root) && !"/".equals(root)){
@@ -98,26 +95,26 @@ public class BaseStanbolResource {
         }
         
     	return consolePathBuilder.path(SYSTEM_CONSOLE).build();
-    }
+    }*/
 
     /**
      * @return the sorted list of navigation links data transfer objects
      */
-    @SuppressWarnings("unchecked")
+    /*@SuppressWarnings("unchecked")
     public List<NavigationLink> getNavigationLinks() {
         return (List<NavigationLink>) servletContext.getAttribute(NAVIGATION_LINKS);
-    }
+    }*/
 
     /**
      * @return menu items with "selected" CSS class for the active link precomputed where applicable
      */
-    public List<MenuItem> getMainMenuItems() {
+    /*public List<MenuItem> getMainMenuItems() {
         List<MenuItem> items = new ArrayList<MenuItem>();
         for (NavigationLink link : getNavigationLinks()) {
             items.add(new MenuItem(link.getLabel(), link.getPath(), uriInfo));
         }
         return items;
-    }
+    }*/
 
     public static class MenuItem {
 
@@ -150,7 +147,7 @@ public class BaseStanbolResource {
 
     }
 
-    public String getRootUrl() {
+    /*public String getRootUrl() {
         return (String) servletContext.getAttribute(ROOT_URL);
     }
 
@@ -176,5 +173,5 @@ public class BaseStanbolResource {
         } else {
             return Collections.emptyList();
         }
-    }
+    }*/
 }

Modified: stanbol/branches/commons-ng/commons/web/base/src/main/java/org/apache/stanbol/commons/web/base/writers/GraphWriter.java
URL: http://svn.apache.org/viewvc/stanbol/branches/commons-ng/commons/web/base/src/main/java/org/apache/stanbol/commons/web/base/writers/GraphWriter.java?rev=1490298&r1=1490297&r2=1490298&view=diff
==============================================================================
--- stanbol/branches/commons-ng/commons/web/base/src/main/java/org/apache/stanbol/commons/web/base/writers/GraphWriter.java (original)
+++ stanbol/branches/commons-ng/commons/web/base/src/main/java/org/apache/stanbol/commons/web/base/writers/GraphWriter.java Thu Jun  6 14:31:00 2013
@@ -34,9 +34,7 @@ import java.util.Collections;
 import java.util.HashSet;
 import java.util.Set;
 
-import javax.servlet.ServletContext;
 import javax.ws.rs.WebApplicationException;
-import javax.ws.rs.core.Context;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.ext.MessageBodyWriter;
@@ -44,10 +42,11 @@ import javax.ws.rs.ext.Provider;
 
 import org.apache.clerezza.rdf.core.TripleCollection;
 import org.apache.clerezza.rdf.core.serializedform.Serializer;
-import org.apache.stanbol.commons.web.base.ContextHelper;
+import org.apache.felix.scr.annotations.Reference;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+//TODO make it a service/component
 @Provider
 // @Produces({TEXT_PLAIN, N3, N_TRIPLE, RDF_XML, TURTLE, X_TURTLE, RDF_JSON, APPLICATION_JSON})
 public class GraphWriter implements MessageBodyWriter<TripleCollection> {
@@ -70,12 +69,8 @@ public class GraphWriter implements Mess
 
     public static final String ENCODING = "UTF-8";
 
-    @Context
-    protected ServletContext servletContext;
-
-    protected Serializer getSerializer() {
-        return ContextHelper.getServiceFromContext(Serializer.class, servletContext);
-    }
+    @Reference
+    private Serializer serializer;
 
     public boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
         String mediaTypeString = mediaType.getType() + '/' + mediaType.getSubtype();
@@ -103,9 +98,9 @@ public class GraphWriter implements Mess
         if (mediaType.isWildcardType() || TEXT_PLAIN.equals(mediaTypeString)
             || APPLICATION_OCTET_STREAM.equals(mediaTypeString)) {
             httpHeaders.putSingle("Content-Type", APPLICATION_JSON);
-            getSerializer().serialize(entityStream, t, APPLICATION_JSON);
+            serializer.serialize(entityStream, t, APPLICATION_JSON);
         } else {
-            getSerializer().serialize(entityStream, t, mediaTypeString);
+            serializer.serialize(entityStream, t, mediaTypeString);
         }
         log.debug("Serialized {} in {}ms", t.size(), System.currentTimeMillis() - start);
     }

Modified: stanbol/branches/commons-ng/commons/web/base/src/test/java/org/apache/stanbol/commons/web/base/CorsAccessControlAllowMethodTest.java
URL: http://svn.apache.org/viewvc/stanbol/branches/commons-ng/commons/web/base/src/test/java/org/apache/stanbol/commons/web/base/CorsAccessControlAllowMethodTest.java?rev=1490298&r1=1490297&r2=1490298&view=diff
==============================================================================
--- stanbol/branches/commons-ng/commons/web/base/src/test/java/org/apache/stanbol/commons/web/base/CorsAccessControlAllowMethodTest.java (original)
+++ stanbol/branches/commons-ng/commons/web/base/src/test/java/org/apache/stanbol/commons/web/base/CorsAccessControlAllowMethodTest.java Thu Jun  6 14:31:00 2013
@@ -24,7 +24,6 @@ import static javax.ws.rs.HttpMethod.PUT
 import java.util.Arrays;
 import java.util.Collections;
 
-import javax.servlet.ServletContext;
 import javax.ws.rs.core.HttpHeaders;
 import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.core.Response;
@@ -43,7 +42,7 @@ import org.junit.Test;
  */
 public class CorsAccessControlAllowMethodTest {
 
-    @Test
+    /*@Test
     public void testAccessControlAllowMethodTest() {
         ServletContext context = new MockServletContext();
         context.setAttribute(CorsConstants.CORS_ORIGIN, Collections.singleton("*"));
@@ -76,6 +75,6 @@ public class CorsAccessControlAllowMetho
         value = (String) metadata.getFirst("Access-Control-Expose-Headers");
         Assert.assertTrue("'Access-Control-Expose-Headers' does not contain the expected valur 'Location'",
             value.contains("Location"));
-    }
+    }*/
 
 }

Modified: stanbol/branches/commons-ng/pom.xml
URL: http://svn.apache.org/viewvc/stanbol/branches/commons-ng/pom.xml?rev=1490298&r1=1490297&r2=1490298&view=diff
==============================================================================
--- stanbol/branches/commons-ng/pom.xml (original)
+++ stanbol/branches/commons-ng/pom.xml Thu Jun  6 14:31:00 2013
@@ -63,10 +63,10 @@
     <module>releasing/source-assembly</module>    
     
     <module>parent</module>
-    <!-- <module>data</module>
+    <!-- <module>data</module> -->
     <module>commons</module>
 
-    <module>entityhub</module>
+    <!-- <module>entityhub</module>
     <module>ontologymanager</module>
     <module>rules</module>
     <module>enhancer</module>