Return-Path: Delivered-To: apmail-cxf-commits-archive@www.apache.org Received: (qmail 50589 invoked from network); 5 Mar 2010 06:49:50 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 5 Mar 2010 06:49:50 -0000 Received: (qmail 61505 invoked by uid 500); 5 Mar 2010 06:49:37 -0000 Delivered-To: apmail-cxf-commits-archive@cxf.apache.org Received: (qmail 61392 invoked by uid 500); 5 Mar 2010 06:49:34 -0000 Mailing-List: contact commits-help@cxf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cxf.apache.org Delivered-To: mailing list commits@cxf.apache.org Received: (qmail 61384 invoked by uid 99); 5 Mar 2010 06:49:33 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 05 Mar 2010 06:49:33 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 05 Mar 2010 06:49:31 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 95F80238897F; Fri, 5 Mar 2010 06:49:09 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r919314 - in /cxf/sandbox/geronimo-jaxrs_1.0_spec/src/main/java/javax/ws/rs: core/Response.java ext/RuntimeDelegate.java Date: Fri, 05 Mar 2010 06:49:09 -0000 To: commits@cxf.apache.org From: bluk@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20100305064909.95F80238897F@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: bluk Date: Fri Mar 5 06:49:09 2010 New Revision: 919314 URL: http://svn.apache.org/viewvc?rev=919314&view=rev Log: Fix RuntimeDelegate Modified: cxf/sandbox/geronimo-jaxrs_1.0_spec/src/main/java/javax/ws/rs/core/Response.java cxf/sandbox/geronimo-jaxrs_1.0_spec/src/main/java/javax/ws/rs/ext/RuntimeDelegate.java Modified: cxf/sandbox/geronimo-jaxrs_1.0_spec/src/main/java/javax/ws/rs/core/Response.java URL: http://svn.apache.org/viewvc/cxf/sandbox/geronimo-jaxrs_1.0_spec/src/main/java/javax/ws/rs/core/Response.java?rev=919314&r1=919313&r2=919314&view=diff ============================================================================== --- cxf/sandbox/geronimo-jaxrs_1.0_spec/src/main/java/javax/ws/rs/core/Response.java (original) +++ cxf/sandbox/geronimo-jaxrs_1.0_spec/src/main/java/javax/ws/rs/core/Response.java Fri Mar 5 06:49:09 2010 @@ -89,12 +89,13 @@ "Bad Request"), CONFLICT(Family.CLIENT_ERROR, 409, "Conflict"), CREATED( Family.SUCCESSFUL, 201, "Created"), FORBIDDEN(Family.CLIENT_ERROR, 403, "Forbidden"), GONE( Family.CLIENT_ERROR, 410, "Gone"), INTERNAL_SERVER_ERROR(Family.SERVER_ERROR, 500, - "Internal Server Error"), MOVED_PERMANENTLY(Family.REDIRECTION, 303, "See Other"), NO_CONTENT( - Family.SUCCESSFUL, 204, "No Content"), NOT_ACCEPTABLE(Family.CLIENT_ERROR, 406, - "Not Acceptable"), NOT_FOUND(Family.CLIENT_ERROR, 404, "Not Found"), NOT_MODIFIED( - Family.REDIRECTION, 304, "Not Modified"), OK(Family.SUCCESSFUL, 200, "OK"), PRECONDITION_FAILED( - Family.CLIENT_ERROR, 412, "Precondition Failed"), SEE_OTHER(Family.REDIRECTION, 303, - "See Other"), SERVICE_UNAVAILABLE(Family.SERVER_ERROR, 503, "Service Unavailable"), TEMPORARY_REDIRECT( + "Internal Server Error"), MOVED_PERMANENTLY(Family.REDIRECTION, 301, + "Moved Permanently"), NO_CONTENT(Family.SUCCESSFUL, 204, "No Content"), NOT_ACCEPTABLE( + Family.CLIENT_ERROR, 406, "Not Acceptable"), NOT_FOUND(Family.CLIENT_ERROR, 404, + "Not Found"), NOT_MODIFIED(Family.REDIRECTION, 304, "Not Modified"), OK( + Family.SUCCESSFUL, 200, "OK"), PRECONDITION_FAILED(Family.CLIENT_ERROR, 412, + "Precondition Failed"), SEE_OTHER(Family.REDIRECTION, 303, "See Other"), SERVICE_UNAVAILABLE( + Family.SERVER_ERROR, 503, "Service Unavailable"), TEMPORARY_REDIRECT( Family.REDIRECTION, 307, "Temporary Redirect"), UNAUTHORIZED(Family.CLIENT_ERROR, 401, "Unauthorized"), UNSUPPORTED_MEDIA_TYPE(Family.CLIENT_ERROR, 415, "Unsupported Media Type"), ; Modified: cxf/sandbox/geronimo-jaxrs_1.0_spec/src/main/java/javax/ws/rs/ext/RuntimeDelegate.java URL: http://svn.apache.org/viewvc/cxf/sandbox/geronimo-jaxrs_1.0_spec/src/main/java/javax/ws/rs/ext/RuntimeDelegate.java?rev=919314&r1=919313&r2=919314&view=diff ============================================================================== --- cxf/sandbox/geronimo-jaxrs_1.0_spec/src/main/java/javax/ws/rs/ext/RuntimeDelegate.java (original) +++ cxf/sandbox/geronimo-jaxrs_1.0_spec/src/main/java/javax/ws/rs/ext/RuntimeDelegate.java Fri Mar 5 06:49:09 2010 @@ -19,11 +19,22 @@ package javax.ws.rs.ext; +import java.io.BufferedReader; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.UnsupportedEncodingException; +import java.util.Properties; + +import javax.ws.rs.core.Application; import javax.ws.rs.core.Response; import javax.ws.rs.core.UriBuilder; import javax.ws.rs.core.Variant; public abstract class RuntimeDelegate { + public static final String JAXRS_RUNTIME_DELEGATE_PROPERTY = "javax.ws.rs.ext.RuntimeDelegate"; public static interface HeaderDelegate { public T fromString(String str); @@ -31,9 +42,7 @@ public String toString(T obj); } - public static RuntimeDelegate getInstance() { - return null; - } + public abstract T createEndpoint(Application app, java.lang.Class type); public abstract UriBuilder createUriBuilder(); @@ -43,4 +52,171 @@ public abstract Response.ResponseBuilder createResponseBuilder(); + private static volatile RuntimeDelegate delegate; + + public static void setInstance(RuntimeDelegate delegate) throws SecurityException { + RuntimeDelegate.delegate = delegate; + } + + public static RuntimeDelegate getInstance() { + if (delegate != null) { + return delegate; + } + + // cannot synchronize on any instance so synchronize on class + synchronized (RuntimeDelegate.class) { + if (delegate != null) { + return delegate; + } + + String className = null; + InputStream is = null; + + // try META-INF/services/javax.ws.rs.ext.RuntimeDelegate + try { + is = + Thread.currentThread().getContextClassLoader() + .getResourceAsStream("META-INF/services/javax.ws.rs.ext.RuntimeDelegate"); + if (is != null) { + BufferedReader br = new BufferedReader(new InputStreamReader(is, "UTF-8")); + try { + className = br.readLine(); + if (className != null && !"".equals(className)) { + Class delegateClass = null; + try { + delegateClass = + Class.forName(className, true, Thread.currentThread() + .getContextClassLoader()); + delegate = (RuntimeDelegate)delegateClass.newInstance(); + return delegate; + } catch (ClassNotFoundException e) { + // try Class.forName + try { + delegateClass = Class.forName(className); + delegate = (RuntimeDelegate)delegateClass.newInstance(); + return delegate; + } catch (ClassNotFoundException e1) { + // do nothing + } + } + } + } catch (IOException e) { + // do nothing + } catch (InstantiationException e) { + // do nothing + } catch (IllegalAccessException e) { + // do nothing + } + } + } catch (SecurityException e) { + // do nothing + } catch (UnsupportedEncodingException e) { + // do nothing + } finally { + if (is != null) { + try { + is.close(); + } catch (IOException e) { + // do nothing + } + is = null; + } + } + + // try ${java.home}/lib/jaxrs.properties + try { + is = new FileInputStream(System.getProperty("java.home") + "/lib/jaxrs.properties"); + if (is != null) { + Properties props = new Properties(); + try { + props.load(is); + className = props.getProperty("javax.ws.rs.ext.RuntimeDelegate"); + if (className != null && !"".equals(className)) { + Class delegateClass; + try { + delegateClass = + Class.forName(className, true, Thread.currentThread() + .getContextClassLoader()); + delegate = (RuntimeDelegate)delegateClass.newInstance(); + return delegate; + } catch (ClassNotFoundException e) { + // try Class.forName + try { + delegateClass = Class.forName(className); + delegate = (RuntimeDelegate)delegateClass.newInstance(); + return delegate; + } catch (ClassNotFoundException e1) { + // do nothing + } + } + } + } catch (IOException e) { + // do nothing + } catch (InstantiationException e) { + // do nothing + } catch (IllegalAccessException e) { + // do nothing + } + } + } catch (SecurityException e) { + // do nothing + } catch (FileNotFoundException e) { + // do nothing + } finally { + if (is != null) { + try { + is.close(); + } catch (IOException e) { + // do nothing + } + is = null; + } + } + + // try system property + try { + className = System.getProperty("javax.ws.rs.ext.RuntimeDelegate"); + } catch (SecurityException e) { + // do nothing + } + + // if the system property is null or empty go ahead and use the + // default implementation class name + + if (className == null || "".equals(className)) { + // dunno which should be the default. this might be interesting + // for OSGi purposes later to somehow set the + // "current implementation" to be the current default. dunno if + // spec allows for that + className = "org.apache.wink.common.internal.runtime.RuntimeDelegateImpl"; + } + Class delegateClass; + try { + try { + delegateClass = + Class.forName(className, true, Thread.currentThread() + .getContextClassLoader()); + delegate = (RuntimeDelegate)delegateClass.newInstance(); + return delegate; + } catch (ClassNotFoundException e) { + // try Class.forName + try { + delegateClass = Class.forName(className); + delegate = (RuntimeDelegate)delegateClass.newInstance(); + return delegate; + } catch (ClassNotFoundException e1) { + // do nothing + } + } + } catch (SecurityException e) { + // do nothing + } catch (InstantiationException e) { + // do nothing + } catch (IllegalAccessException e) { + // do nothing + } + + return delegate; + } + } }