wink-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From b...@apache.org
Subject svn commit: r818645 - in /incubator/wink/trunk: wink-common/src/main/resources/org/apache/wink/common/internal/i18n/ wink-server/src/main/java/org/apache/wink/server/internal/handlers/
Date Thu, 24 Sep 2009 22:39:31 GMT
Author: bluk
Date: Thu Sep 24 22:39:30 2009
New Revision: 818645

URL: http://svn.apache.org/viewvc?rev=818645&view=rev
Log:
Add debug statements to server handlers

Modified:
    incubator/wink/trunk/wink-common/src/main/resources/org/apache/wink/common/internal/i18n/resource.properties
    incubator/wink/trunk/wink-server/src/main/java/org/apache/wink/server/internal/handlers/CheckLocationHeaderHandler.java
    incubator/wink/trunk/wink-server/src/main/java/org/apache/wink/server/internal/handlers/CreateInvocationParametersHandler.java
    incubator/wink/trunk/wink-server/src/main/java/org/apache/wink/server/internal/handlers/FindResourceMethodHandler.java
    incubator/wink/trunk/wink-server/src/main/java/org/apache/wink/server/internal/handlers/FindRootResourceHandler.java
    incubator/wink/trunk/wink-server/src/main/java/org/apache/wink/server/internal/handlers/FlushResultHandler.java
    incubator/wink/trunk/wink-server/src/main/java/org/apache/wink/server/internal/handlers/HeadMethodHandler.java
    incubator/wink/trunk/wink-server/src/main/java/org/apache/wink/server/internal/handlers/OptionsMethodHandler.java
    incubator/wink/trunk/wink-server/src/main/java/org/apache/wink/server/internal/handlers/PopulateErrorResponseHandler.java
    incubator/wink/trunk/wink-server/src/main/java/org/apache/wink/server/internal/handlers/PopulateResponseMediaTypeHandler.java
    incubator/wink/trunk/wink-server/src/main/java/org/apache/wink/server/internal/handlers/PopulateResponseStatusHandler.java

Modified: incubator/wink/trunk/wink-common/src/main/resources/org/apache/wink/common/internal/i18n/resource.properties
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-common/src/main/resources/org/apache/wink/common/internal/i18n/resource.properties?rev=818645&r1=818644&r2=818645&view=diff
==============================================================================
--- incubator/wink/trunk/wink-common/src/main/resources/org/apache/wink/common/internal/i18n/resource.properties
(original)
+++ incubator/wink/trunk/wink-common/src/main/resources/org/apache/wink/common/internal/i18n/resource.properties
Thu Sep 24 22:39:30 2009
@@ -119,3 +119,8 @@
 clientIssueRequest=Issuing client {} method request to URI at {} with {} entity class and
{} headers
 clientAcceptHeaderHandlerSetAccept=Accept header automatically set to: {}
 clientResponseIsErrorCode=Client response is an error code: {}
+
+# Server Handlers
+checkLocationHeaderHandlerIllegalArg=Mandatory 'Location' header was not set for status code
%1$s
+populateResponseMediaTypeHandlerFromCompatibleMessageBodyWriters=Content-Type not specified
via Response object or via @Produces annotation so automatically setting via generic-type
compatible MessageBodyWriter providers
+populateResponseMediaTypeHandlerNoAcceptableResponse=No acceptable concrete Content-Types,
so sending a 406 Not Acceptable response to the client.
\ No newline at end of file

Modified: incubator/wink/trunk/wink-server/src/main/java/org/apache/wink/server/internal/handlers/CheckLocationHeaderHandler.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-server/src/main/java/org/apache/wink/server/internal/handlers/CheckLocationHeaderHandler.java?rev=818645&r1=818644&r2=818645&view=diff
==============================================================================
--- incubator/wink/trunk/wink-server/src/main/java/org/apache/wink/server/internal/handlers/CheckLocationHeaderHandler.java
(original)
+++ incubator/wink/trunk/wink-server/src/main/java/org/apache/wink/server/internal/handlers/CheckLocationHeaderHandler.java
Thu Sep 24 22:39:30 2009
@@ -23,6 +23,7 @@
 import javax.ws.rs.core.Response;
 
 import org.apache.wink.common.http.HttpStatus;
+import org.apache.wink.common.internal.i18n.Messages;
 import org.apache.wink.server.handlers.AbstractHandler;
 import org.apache.wink.server.handlers.MessageContext;
 
@@ -39,8 +40,8 @@
         if (result instanceof Response && isStatusWithLocation(statusCode)) {
             Response clientResponse = (Response)result;
             if (!clientResponse.getMetadata().containsKey(HttpHeaders.LOCATION)) {
-                throw new IllegalStateException(
-                                                "Mandatory 'Location' header was not set
for status code " + statusCode);
+                throw new IllegalStateException(Messages
+                    .getMessage("checkLocationHeaderHandlerIllegalArg", statusCode));
             }
         }
     }

Modified: incubator/wink/trunk/wink-server/src/main/java/org/apache/wink/server/internal/handlers/CreateInvocationParametersHandler.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-server/src/main/java/org/apache/wink/server/internal/handlers/CreateInvocationParametersHandler.java?rev=818645&r1=818644&r2=818645&view=diff
==============================================================================
--- incubator/wink/trunk/wink-server/src/main/java/org/apache/wink/server/internal/handlers/CreateInvocationParametersHandler.java
(original)
+++ incubator/wink/trunk/wink-server/src/main/java/org/apache/wink/server/internal/handlers/CreateInvocationParametersHandler.java
Thu Sep 24 22:39:30 2009
@@ -28,15 +28,21 @@
 import org.apache.wink.server.handlers.HandlersChain;
 import org.apache.wink.server.handlers.MessageContext;
 import org.apache.wink.server.handlers.RequestHandler;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public class CreateInvocationParametersHandler implements RequestHandler {
 
+    private Logger logger = LoggerFactory.getLogger(CreateInvocationParametersHandler.class);
+
     public void handleRequest(MessageContext context, HandlersChain chain) throws Throwable
{
         SearchResult result = context.getAttribute(SearchResult.class);
 
         // create and save the invocation parameters for the found method
         List<Injectable> formal = result.getMethod().getMetadata().getFormalParameters();
+        logger.debug("Formal Injectable parameters listis: {}", formal);
         Object[] parameters = InjectableFactory.getInstance().instantiate(formal, context);
+        logger.debug("Actual parameters list to inject is: {}", parameters);
         result.setInvocationParameters(parameters);
 
         chain.doChain(context);

Modified: incubator/wink/trunk/wink-server/src/main/java/org/apache/wink/server/internal/handlers/FindResourceMethodHandler.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-server/src/main/java/org/apache/wink/server/internal/handlers/FindResourceMethodHandler.java?rev=818645&r1=818644&r2=818645&view=diff
==============================================================================
--- incubator/wink/trunk/wink-server/src/main/java/org/apache/wink/server/internal/handlers/FindResourceMethodHandler.java
(original)
+++ incubator/wink/trunk/wink-server/src/main/java/org/apache/wink/server/internal/handlers/FindResourceMethodHandler.java
Thu Sep 24 22:39:30 2009
@@ -29,6 +29,7 @@
 import javax.ws.rs.core.Response;
 import javax.ws.rs.core.Response.Status;
 
+import org.apache.wink.common.internal.registry.metadata.MethodMetadata;
 import org.apache.wink.common.internal.uritemplate.UriTemplateMatcher;
 import org.apache.wink.common.internal.uritemplate.UriTemplateProcessor;
 import org.apache.wink.server.handlers.HandlersChain;
@@ -43,10 +44,14 @@
 import org.apache.wink.server.internal.registry.SubResourceInstance;
 import org.apache.wink.server.internal.registry.SubResourceMethodRecord;
 import org.apache.wink.server.internal.registry.SubResourceRecord;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public class FindResourceMethodHandler implements RequestHandler {
 
-    private boolean isContinuedSearchPolicy;
+    private boolean      isContinuedSearchPolicy;
+
+    private final Logger logger = LoggerFactory.getLogger(FindResourceMethodHandler.class);
 
     public void handleRequest(MessageContext context, HandlersChain chain) throws Throwable
{
 
@@ -55,6 +60,7 @@
 
         // resource method
         if (resource.isExactMatch()) {
+            logger.debug("Root resource @Path matches exactly so finding root resource method");
             handleResourceMethod(context, chain);
             return;
         }
@@ -62,9 +68,11 @@
         // sub-resource method or locator
         UriTemplateMatcher templateMatcher = resource.getMatcher();
         String tail = UriTemplateProcessor.normalizeUri(templateMatcher.getTail(false));
+        logger.debug("Unmatched tail to the URI: {}", tail);
 
-        // get a sorted set of all the sub-resources (methods and locators)
+        // get a sorted list of all the sub-resources (methods and locators)
         List<SubResourceInstance> subResources = resource.getRecord().getMatchingSubResources(tail);
+        logger.debug("Possible subresources found: {}", subResources);
         if (subResources.size() == 0) {
             result.setError(new WebApplicationException(Response.Status.NOT_FOUND));
             return;
@@ -72,7 +80,7 @@
 
         // get all the searchable sub-resources
         List<SubResourceInstance> searchableSubResources = getSearchableSubResources(subResources);
-
+        logger.debug("Possible searchable subresources found: {}", searchableSubResources);
         // save the current data in case we need to role back the information if
         // the search fails and we will need to continue to the next
         // sub-resource
@@ -129,6 +137,10 @@
         result.setFound(true);
         result.setMethod(method);
         // continue the chain to invoke the method
+        if (logger.isDebugEnabled()) {
+            MethodMetadata metadata = (method == null) ? null : method.getMetadata();
+            logger.debug("Found root resource method to invoke: {} ", metadata);
+        }
         chain.doChain(context);
     }
 
@@ -157,6 +169,10 @@
         saveFoundMethod(result, matcher, method, context);
 
         // continue the chain to invoke the method
+        if (logger.isDebugEnabled()) {
+            MethodMetadata metadata = (method == null) ? null : method.getMetadata();
+            logger.debug("Found subresource method to invoke: {} ", metadata);
+        }
         chain.doChain(context);
     }
 
@@ -179,12 +195,18 @@
         saveFoundMethod(result, matcher, subResourceInstance, context);
 
         // continue the chain to invoke the locator
+        if (logger.isDebugEnabled()) {
+            MethodMetadata metadata =
+                (subResourceInstance == null) ? null : subResourceInstance.getMetadata();
+            logger.debug("Found subresource locator to invoke: {} ", metadata);
+        }
         chain.doChain(context);
 
         // the object returned from the locator is a sub-resource so we must
         // continue the search in it
         Object subResource = context.getResponseEntity();
         if (subResource == null) {
+            logger.debug("Subresource returned was null so returning a 404 Not Found");
             result.setError(new WebApplicationException(Status.NOT_FOUND));
             return;
         }
@@ -195,6 +217,9 @@
 
         // call recursively to search in the sub-resource
         result.setFound(false);
+        logger
+            .debug("Re-invoking the chain (due to hitting a subresource locator method) with
the new subresource instance {}",
+                   resourceInstance);
         handleRequest(context, chain);
     }
 

Modified: incubator/wink/trunk/wink-server/src/main/java/org/apache/wink/server/internal/handlers/FindRootResourceHandler.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-server/src/main/java/org/apache/wink/server/internal/handlers/FindRootResourceHandler.java?rev=818645&r1=818644&r2=818645&view=diff
==============================================================================
--- incubator/wink/trunk/wink-server/src/main/java/org/apache/wink/server/internal/handlers/FindRootResourceHandler.java
(original)
+++ incubator/wink/trunk/wink-server/src/main/java/org/apache/wink/server/internal/handlers/FindRootResourceHandler.java
Thu Sep 24 22:39:30 2009
@@ -50,8 +50,9 @@
 
         // create a path stripped from all matrix parameters to use for matching
         List<PathSegment> segments = context.getUriInfo().getPathSegments(false);
+        logger.debug("Getting URI Info path segments: {}", segments);
         String strippedPath = buildPathForMatching(segments);
-
+        logger.debug("Getting stripped path from segments: {}", strippedPath);
         // get a list of root resources that can handle the request
 
         // JAX-RS specification requires to search only the first matching
@@ -60,6 +61,7 @@
         // matching resources
         List<ResourceInstance> matchedResources =
             registry.getMatchingRootResources(strippedPath, isContinuedSearchPolicy);
+        logger.debug("Found resource instances: {}", matchedResources);
         if (matchedResources.size() == 0) {
             logger.debug("No resource found matching {}", context.getUriInfo().getPath(false));
             SearchResult result =
@@ -82,6 +84,8 @@
                                             headSegmentsCount,
                                             result.getData().getMatchedVariablesPathSegments());
 
+            logger.debug("Using SearchResult: {}", result);
+
             // continue that chain to find the actual resource that will handle
             // the request.
             // it may be the current resource or a sub-resource of the current

Modified: incubator/wink/trunk/wink-server/src/main/java/org/apache/wink/server/internal/handlers/FlushResultHandler.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-server/src/main/java/org/apache/wink/server/internal/handlers/FlushResultHandler.java?rev=818645&r1=818644&r2=818645&view=diff
==============================================================================
--- incubator/wink/trunk/wink-server/src/main/java/org/apache/wink/server/internal/handlers/FlushResultHandler.java
(original)
+++ incubator/wink/trunk/wink-server/src/main/java/org/apache/wink/server/internal/handlers/FlushResultHandler.java
Thu Sep 24 22:39:30 2009
@@ -77,6 +77,7 @@
         }
 
         // set the status code
+        logger.debug("Response status code set to: {}", statusCode);
         httpResponse.setStatus(statusCode);
 
         // get the entity
@@ -127,6 +128,7 @@
 
         // we're done if the actual entity is null
         if (entity == null) {
+            logger.debug("No entity so writing only the headers");
             flushHeaders(httpResponse, httpHeaders);
             return;
         }
@@ -134,6 +136,7 @@
         // we have an entity, set the response media type
         MediaType responseMediaType = context.getResponseMediaType();
         if (responseMediaType != null) {
+            logger.debug("Set response Content-Type to: {} ", responseMediaType);
             httpResponse.setContentType(responseMediaType.toString());
         }
 
@@ -208,10 +211,13 @@
             RequestImpl.VaryHeader varyHeader =
                 RuntimeContextTLS.getRuntimeContext().getAttribute(RequestImpl.VaryHeader.class);
             if (varyHeader != null) {
+                logger.debug("Vary header automatically set by a call to RequestImpl");
                 headers.putSingle(HttpHeaders.VARY, varyHeader.getVaryHeaderValue());
             }
         }
 
+        logger.debug("Flushing headers: {}", headers);
+
         for (Entry<String, List<Object>> entry : headers.entrySet()) {
             String key = entry.getKey();
             List<Object> values = entry.getValue();

Modified: incubator/wink/trunk/wink-server/src/main/java/org/apache/wink/server/internal/handlers/HeadMethodHandler.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-server/src/main/java/org/apache/wink/server/internal/handlers/HeadMethodHandler.java?rev=818645&r1=818644&r2=818645&view=diff
==============================================================================
--- incubator/wink/trunk/wink-server/src/main/java/org/apache/wink/server/internal/handlers/HeadMethodHandler.java
(original)
+++ incubator/wink/trunk/wink-server/src/main/java/org/apache/wink/server/internal/handlers/HeadMethodHandler.java
Thu Sep 24 22:39:30 2009
@@ -35,9 +35,15 @@
 import org.apache.wink.server.handlers.MessageContext;
 import org.apache.wink.server.handlers.RequestHandler;
 import org.apache.wink.server.handlers.ResponseHandler;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public class HeadMethodHandler implements RequestHandler, ResponseHandler {
 
+    private static final Logger logger                     =
+                                                               LoggerFactory
+                                                                   .getLogger(HeadMethodHandler.class);
+
     private static final String ORIGINAL_RESPONSE_ATT_NAME =
                                                                HeadMethodHandler.class.getName()
+ "_original_response";
 
@@ -54,6 +60,8 @@
         if (searchResult.isError() && searchResult.getError().getResponse().getStatus()
== HttpStatus.METHOD_NOT_ALLOWED
             .getCode()
             && context.getHttpMethod().equalsIgnoreCase(HttpMethod.HEAD)) {
+            logger
+                .debug("No HEAD method so trying GET method while not sending the response
entity");
             context.setHttpMethod(HttpMethod.GET);
             HttpServletResponse originalResponse = context.getAttribute(HttpServletResponse.class);
             NoBodyResponse noBodyResponse = new NoBodyResponse(originalResponse);
@@ -69,7 +77,7 @@
         if (originalResponse != null) {
             HttpServletResponse response = context.getAttribute(HttpServletResponse.class);
             response.flushBuffer();
-            response.setContentLength(((NoBodyResponse)response).getContentLenghtValue());
+            response.setContentLength(((NoBodyResponse)response).getContentLengthValue());
             // set the original response on the context
             context.setAttribute(HttpServletResponse.class, originalResponse);
         }
@@ -85,7 +93,7 @@
             super(servletResponse);
         }
 
-        int getContentLenghtValue() {
+        int getContentLengthValue() {
             return countingStream.getByteCount();
         }
 

Modified: incubator/wink/trunk/wink-server/src/main/java/org/apache/wink/server/internal/handlers/OptionsMethodHandler.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-server/src/main/java/org/apache/wink/server/internal/handlers/OptionsMethodHandler.java?rev=818645&r1=818644&r2=818645&view=diff
==============================================================================
--- incubator/wink/trunk/wink-server/src/main/java/org/apache/wink/server/internal/handlers/OptionsMethodHandler.java
(original)
+++ incubator/wink/trunk/wink-server/src/main/java/org/apache/wink/server/internal/handlers/OptionsMethodHandler.java
Thu Sep 24 22:39:30 2009
@@ -33,9 +33,13 @@
 import org.apache.wink.server.handlers.MessageContext;
 import org.apache.wink.server.handlers.RequestHandler;
 import org.apache.wink.server.internal.registry.ResourceRegistry;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public class OptionsMethodHandler implements RequestHandler {
 
+    private static final Logger logger = LoggerFactory.getLogger(OptionsMethodHandler.class);
+
     public void handleRequest(MessageContext context, HandlersChain chain) throws Throwable
{
 
         // first thing - proceed the chain
@@ -51,6 +55,10 @@
             // get supported HTTP methods
             ResourceRegistry resourceRegistry = context.getAttribute(ResourceRegistry.class);
             Set<String> httpMethods = resourceRegistry.getOptions(searchResult.getResource());
+            logger
+                .debug("Invoking OPTIONS request handled by runtime with {} resource and
{} HTTP methods",
+                       searchResult.getResource(),
+                       httpMethods);
             if (httpMethods.size() > 0) {
                 String allowHeader = HeaderUtils.buildOptionsHeader(httpMethods);
                 // add 'Allow' header to the response

Modified: incubator/wink/trunk/wink-server/src/main/java/org/apache/wink/server/internal/handlers/PopulateErrorResponseHandler.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-server/src/main/java/org/apache/wink/server/internal/handlers/PopulateErrorResponseHandler.java?rev=818645&r1=818644&r2=818645&view=diff
==============================================================================
--- incubator/wink/trunk/wink-server/src/main/java/org/apache/wink/server/internal/handlers/PopulateErrorResponseHandler.java
(original)
+++ incubator/wink/trunk/wink-server/src/main/java/org/apache/wink/server/internal/handlers/PopulateErrorResponseHandler.java
Thu Sep 24 22:39:30 2009
@@ -47,6 +47,7 @@
             ExceptionMapper<Throwable> provider =
                 (ExceptionMapper<Throwable>)findProvider(context, exception);
             if (provider != null) {
+                logger.debug("Using provider {} to map exception {}", provider, exception);
                 context.setResponseEntity(executeProvider(exception, provider));
             } else {
                 throw exception;
@@ -73,12 +74,16 @@
                                                WebApplicationException exception) {
         ExceptionMapper<WebApplicationException> provider = null;
         if (exception.getResponse().getEntity() == null) {
+            // only look for a provider if the response entity on the
+            // WebApplicationException is null (per spec)
             provider =
                 (ExceptionMapper<WebApplicationException>)findProvider(msgContext,
exception);
         }
         if (provider != null) {
+            logger.debug("Using ExceptionMapper to map response from WebApplicationException");
             msgContext.setResponseEntity(provider.toResponse(exception));
         } else {
+            logger.debug("Getting response directly from WebApplicationException");
             msgContext.setResponseEntity(exception.getResponse());
         }
     }

Modified: incubator/wink/trunk/wink-server/src/main/java/org/apache/wink/server/internal/handlers/PopulateResponseMediaTypeHandler.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-server/src/main/java/org/apache/wink/server/internal/handlers/PopulateResponseMediaTypeHandler.java?rev=818645&r1=818644&r2=818645&view=diff
==============================================================================
--- incubator/wink/trunk/wink-server/src/main/java/org/apache/wink/server/internal/handlers/PopulateResponseMediaTypeHandler.java
(original)
+++ incubator/wink/trunk/wink-server/src/main/java/org/apache/wink/server/internal/handlers/PopulateResponseMediaTypeHandler.java
Thu Sep 24 22:39:30 2009
@@ -28,14 +28,21 @@
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.Response;
 
+import org.apache.wink.common.internal.i18n.Messages;
 import org.apache.wink.common.internal.registry.ProvidersRegistry;
 import org.apache.wink.common.internal.registry.metadata.MethodMetadata;
 import org.apache.wink.common.internal.utils.MediaTypeUtils;
 import org.apache.wink.server.handlers.AbstractHandler;
 import org.apache.wink.server.handlers.MessageContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public class PopulateResponseMediaTypeHandler extends AbstractHandler {
 
+    private static final Logger    logger           =
+                                                        LoggerFactory
+                                                            .getLogger(PopulateResponseMediaTypeHandler.class);
+
     private static final MediaType APPLICATION_TYPE = new MediaType("application", "*");
 
     private boolean                errorFlow        = false;
@@ -46,6 +53,7 @@
         Object result = context.getResponseEntity();
 
         if (result == null) {
+            logger.debug("No entity so no Content-Type needs to be set");
             return;
         }
 
@@ -61,6 +69,7 @@
                     responseMediaType = MediaType.valueOf(first.toString());
                 }
             }
+            logger.debug("Content-Type was set by application to {}", responseMediaType);
         }
 
         if (responseMediaType == null) {
@@ -69,11 +78,23 @@
             if (searchResult != null && searchResult.isFound()) {
                 MethodMetadata methodMetadata = searchResult.getMethod().getMetadata();
                 producedMime = methodMetadata.getProduces();
+                logger.debug("Determining Content-Type from @Produces on method: {}", producedMime);
             }
             if (producedMime == null || producedMime.isEmpty()) {
                 producedMime =
                     context.getAttribute(ProvidersRegistry.class)
                         .getMessageBodyWriterMediaTypes(result.getClass());
+                /*
+                 * This is to inform the application developer that they should
+                 * specify the Content-Type.
+                 */
+                logger
+                    .info(Messages
+                        .getMessage("populateResponseMediaTypeHandlerFromCompatibleMessageBodyWriters"));
+                logger
+                    .debug("Determining Content-Type from compatible generic type to {} from
MessageBodyWriters: {}",
+                           result.getClass(),
+                           producedMime);
             }
             if (producedMime.isEmpty()) {
                 producedMime.add(MediaType.WILDCARD_TYPE);
@@ -86,6 +107,7 @@
             List<CandidateMediaType> candidates = new LinkedList<CandidateMediaType>();
             for (MediaType acceptableMediaType : acceptableMediaTypes) {
                 for (MediaType mediaType : producedMime) {
+                    logger.debug("Comparing {} to {}", acceptableMediaType, mediaType);
                     if (mediaType.isCompatible(acceptableMediaType)) {
                         MediaType candidateMediaType = null;
                         if (MediaTypeUtils.compareTo(mediaType, acceptableMediaType) >
0) {
@@ -93,10 +115,18 @@
                         } else {
                             candidateMediaType = acceptableMediaType;
                         }
+                        logger.debug("MediaType compatible so using candidate type {}",
+                                     candidateMediaType);
                         String q = acceptableMediaType.getParameters().get("q");
                         CandidateMediaType candidate =
                             new CandidateMediaType(candidateMediaType, q);
                         if (Double.compare(candidate.q, 0.0) != 0) {
+                            if (logger.isDebugEnabled()) {
+                                logger
+                                    .debug("Candidate {} has q value {} so adding to possible
candidates",
+                                           candidate.getMediaType(),
+                                           q);
+                            }
                             candidates.add(candidate);
                         }
                     }
@@ -106,8 +136,11 @@
             // there are no candidates
             if (candidates.isEmpty()) {
                 if (isErrorFlow()) {
+                    logger.debug("Error flow and no candidates so not going to set a Content-Type");
                     return;
                 }
+                logger.info(Messages
+                    .getMessage("populateResponseMediaTypeHandlerNoAcceptableResponse"));
                 throw new WebApplicationException(Response.Status.NOT_ACCEPTABLE);
             }
 
@@ -119,6 +152,10 @@
             for (CandidateMediaType candidate : candidates) {
                 if (max == null) {
                     max = candidate;
+                    if (logger.isDebugEnabled()) {
+                        logger.debug("No previous best candidate so using candidate {}",
max
+                            .getMediaType());
+                    }
                 } else {
                     // select the more specific media type before a media type
                     // that has a wildcard in it
@@ -127,13 +164,27 @@
                         MediaTypeUtils.compareTo(candidate.getMediaType(), max.getMediaType());
                     if (comparison > 0) {
                         max = candidate;
+                        if (logger.isDebugEnabled()) {
+                            logger
+                                .debug("Best candidate is now {} because it was a more specific
media type",
+                                       max.getMediaType());
+                        }
                     } else if (comparison == 0 && candidate.getQ() > max.getQ())
{
                         max = candidate;
+                        if (logger.isDebugEnabled()) {
+                            logger
+                                .debug("Best candidate is now {} because it had a higher
quality value {} compared to {} with quality value {}",
+                                       new Object[] {max.getMediaType(), max.getQ(), candidate,
+                                           candidate.getQ()});
+                        }
                     }
                 }
 
                 if (!useOctetStream && (candidate.getMediaType().equals(MediaType.WILDCARD_TYPE)
|| candidate
                     .getMediaType().equals(APPLICATION_TYPE))) {
+                    logger
+                        .debug("If necessary, use an application/octet-stream because there
is a wildcard",
+                               candidate.getMediaType());
                     useOctetStream = true;
                 }
             }
@@ -141,15 +192,21 @@
             if (max.getMediaType().isWildcardSubtype() == false) {
                 responseMediaType = max.getMediaType();
             } else if (useOctetStream) {
+                logger
+                    .debug("Content-Type was reset to application/octet-stream because it
was either */* or was application/*");
                 responseMediaType = MediaType.APPLICATION_OCTET_STREAM_TYPE;
             } else {
                 if (isErrorFlow()) {
+                    logger.debug("Error flow so not going to set a response Content-Type");
                     return;
                 }
+                logger.info(Messages
+                    .getMessage("populateResponseMediaTypeHandlerNoAcceptableResponse"));
                 throw new WebApplicationException(Response.Status.NOT_ACCEPTABLE);
             }
 
         }
+        logger.debug("Response Content-Type will be set to {}", responseMediaType);
         context.setResponseMediaType(responseMediaType);
     }
 

Modified: incubator/wink/trunk/wink-server/src/main/java/org/apache/wink/server/internal/handlers/PopulateResponseStatusHandler.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-server/src/main/java/org/apache/wink/server/internal/handlers/PopulateResponseStatusHandler.java?rev=818645&r1=818644&r2=818645&view=diff
==============================================================================
--- incubator/wink/trunk/wink-server/src/main/java/org/apache/wink/server/internal/handlers/PopulateResponseStatusHandler.java
(original)
+++ incubator/wink/trunk/wink-server/src/main/java/org/apache/wink/server/internal/handlers/PopulateResponseStatusHandler.java
Thu Sep 24 22:39:30 2009
@@ -25,9 +25,15 @@
 
 import org.apache.wink.server.handlers.AbstractHandler;
 import org.apache.wink.server.handlers.MessageContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public class PopulateResponseStatusHandler extends AbstractHandler {
 
+    private static final Logger logger =
+                                           LoggerFactory
+                                               .getLogger(PopulateResponseStatusHandler.class);
+
     public void handleResponse(MessageContext context) throws Throwable {
         Object entity = context.getResponseEntity();
 
@@ -45,9 +51,13 @@
         }
 
         if (status == -1) {
-            status = HttpServletResponse.SC_OK;
             if (entity == null) {
+                logger
+                    .debug("No status set and no entity so setting response status to 204
No Content");
                 status = HttpServletResponse.SC_NO_CONTENT;
+            } else {
+                logger.debug("No status set so setting response status to 200 OK");
+                status = HttpServletResponse.SC_OK;
             }
         }
 



Mime
View raw message