You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wink.apache.org by lr...@apache.org on 2013/04/12 05:14:41 UTC
svn commit: r1467159 - in
/wink/trunk/wink-server/src/main/java/org/apache/wink/server/internal/handlers:
FlushResultHandler.java PopulateResponseMediaTypeHandler.java
Author: lresende
Date: Fri Apr 12 03:14:41 2013
New Revision: 1467159
URL: http://svn.apache.org/r1467159
Log:
Minor formattings
Modified:
wink/trunk/wink-server/src/main/java/org/apache/wink/server/internal/handlers/FlushResultHandler.java
wink/trunk/wink-server/src/main/java/org/apache/wink/server/internal/handlers/PopulateResponseMediaTypeHandler.java
Modified: wink/trunk/wink-server/src/main/java/org/apache/wink/server/internal/handlers/FlushResultHandler.java
URL: http://svn.apache.org/viewvc/wink/trunk/wink-server/src/main/java/org/apache/wink/server/internal/handlers/FlushResultHandler.java?rev=1467159&r1=1467158&r2=1467159&view=diff
==============================================================================
--- wink/trunk/wink-server/src/main/java/org/apache/wink/server/internal/handlers/FlushResultHandler.java (original)
+++ wink/trunk/wink-server/src/main/java/org/apache/wink/server/internal/handlers/FlushResultHandler.java Fri Apr 12 03:14:41 2013
@@ -56,9 +56,7 @@ import org.slf4j.LoggerFactory;
public class FlushResultHandler extends AbstractHandler {
- private static final Logger logger =
- LoggerFactory
- .getLogger(FlushResultHandler.class);
+ private static final Logger logger = LoggerFactory.getLogger(FlushResultHandler.class);
private static final RuntimeDelegate runtimeDelegate = RuntimeDelegate.getInstance();
@SuppressWarnings("unchecked")
@@ -150,8 +148,7 @@ public class FlushResultHandler extends
// use the provider to write the entity
if (messageBodyWriter != null) {
if (logger.isTraceEnabled()) {
- logger
- .trace("Serialization using provider {}", messageBodyWriter.getClass().getName()); //$NON-NLS-1$
+ logger.trace("Serialization using provider {}", messageBodyWriter.getClass().getName()); //$NON-NLS-1$
}
final MultivaluedMap<String, Object> headers = httpHeaders;
@@ -187,8 +184,7 @@ public class FlushResultHandler extends
FlushHeadersOutputStream outputStream =
new FlushHeadersOutputStream(httpResponse, headers, responseMediaType);
if (logger.isTraceEnabled()) {
- logger
- .trace("{}@{}.writeTo({}, {}, {}, {}, {}, {}, {}) being called", new Object[] { //$NON-NLS-1$
+ logger.trace("{}@{}.writeTo({}, {}, {}, {}, {}, {}, {}) being called", new Object[] { //$NON-NLS-1$
messageBodyWriter.getClass().getName(),
Integer.toHexString(System.identityHashCode(messageBodyWriter)),
Integer.toHexString(System.identityHashCode(entity)), rawType,
@@ -204,8 +200,7 @@ public class FlushResultHandler extends
httpHeaders,
outputStream);
} catch (RuntimeException e) {
- ProviderUtils
- .logUserProviderException(e,
+ ProviderUtils.logUserProviderException(e,
messageBodyWriter,
ProviderUtils.PROVIDER_EXCEPTION_ORIGINATOR.writeTo,
new Object[] {entity, rawType, genericType,
@@ -219,8 +214,7 @@ public class FlushResultHandler extends
return;
} else {
- logger
- .trace("Could not find a writer for {} and {}. Try to find JAF DataSourceProvider", //$NON-NLS-1$
+ logger.trace("Could not find a writer for {} and {}. Try to find JAF DataSourceProvider", //$NON-NLS-1$
entity.getClass().getName(),
responseMediaType);
}
@@ -230,8 +224,7 @@ public class FlushResultHandler extends
// try to find a data handler using JavaBeans Activation Framework, if
// found use DataSourceProvider
- dataContentHandler =
- CommandMap
+ dataContentHandler = CommandMap
.getDefaultCommandMap()
.createDataContentHandler(responseMediaType.getType() + "/" + responseMediaType.getSubtype()); //$NON-NLS-1$
if (dataContentHandler == null) {
@@ -248,8 +241,7 @@ public class FlushResultHandler extends
.getName());
}
- FlushHeadersOutputStream outputStream =
- new FlushHeadersOutputStream(httpResponse, httpHeaders, responseMediaType);
+ FlushHeadersOutputStream outputStream = new FlushHeadersOutputStream(httpResponse, httpHeaders, responseMediaType);
if (logger.isTraceEnabled()) {
logger.trace("{}@{}.writeTo({}, {}, {}) being called", new Object[] { //$NON-NLS-1$
dataContentHandler.getClass().getName(),
Modified: wink/trunk/wink-server/src/main/java/org/apache/wink/server/internal/handlers/PopulateResponseMediaTypeHandler.java
URL: http://svn.apache.org/viewvc/wink/trunk/wink-server/src/main/java/org/apache/wink/server/internal/handlers/PopulateResponseMediaTypeHandler.java?rev=1467159&r1=1467158&r2=1467159&view=diff
==============================================================================
--- wink/trunk/wink-server/src/main/java/org/apache/wink/server/internal/handlers/PopulateResponseMediaTypeHandler.java (original)
+++ wink/trunk/wink-server/src/main/java/org/apache/wink/server/internal/handlers/PopulateResponseMediaTypeHandler.java Fri Apr 12 03:14:41 2013
@@ -39,9 +39,7 @@ import org.slf4j.LoggerFactory;
public class PopulateResponseMediaTypeHandler extends AbstractHandler {
- private static final Logger logger =
- LoggerFactory
- .getLogger(PopulateResponseMediaTypeHandler.class);
+ private static final Logger logger = LoggerFactory.getLogger(PopulateResponseMediaTypeHandler.class);
private static final MediaType APPLICATION_TYPE = new MediaType("application", "*"); //$NON-NLS-1$ //$NON-NLS-2$
@@ -55,16 +53,18 @@ public class PopulateResponseMediaTypeHa
boolean debug = logger.isDebugEnabled();
if (result == null) {
- if (debug)
+ if (debug) {
logger.trace("No entity so no Content-Type needs to be set"); //$NON-NLS-1$
+ }
return;
}
if (result instanceof Response) {
Response response = (Response)result;
if (response.getEntity() == null) {
- if (debug)
+ if (debug) {
logger.trace("No entity so no Content-Type needs to be set"); //$NON-NLS-1$
+ }
return;
}
@@ -77,8 +77,9 @@ public class PopulateResponseMediaTypeHa
responseMediaType = MediaType.valueOf(first.toString());
}
}
- if (debug)
+ if (debug) {
logger.trace("Content-Type was set by application to {}", responseMediaType); //$NON-NLS-1$
+ }
}
if (responseMediaType == null) {
@@ -87,54 +88,49 @@ public class PopulateResponseMediaTypeHa
if (searchResult != null && searchResult.isFound()) {
MethodMetadata methodMetadata = searchResult.getMethod().getMetadata();
producedMime = methodMetadata.getProduces();
- if (debug)
- logger
- .trace("Determining Content-Type from @Produces on method: {}", producedMime); //$NON-NLS-1$
+ if (debug) {
+ logger.trace("Determining Content-Type from @Produces on method: {}", producedMime); //$NON-NLS-1$
+ }
}
if (producedMime == null || producedMime.isEmpty()) {
if (result instanceof Response) {
Response response = (Response)result;
- producedMime =
- context.getAttribute(ProvidersRegistry.class)
- .getMessageBodyWriterMediaTypes(response.getEntity().getClass());
- if (debug)
- logger
- .trace("Determining Content-Type from compatible generic type to {} from MessageBodyWriters: {}", //$NON-NLS-1$
+ producedMime = context.getAttribute(ProvidersRegistry.class).getMessageBodyWriterMediaTypes(response.getEntity().getClass());
+ if (debug) {
+ logger.trace("Determining Content-Type from compatible generic type to {} from MessageBodyWriters: {}", //$NON-NLS-1$
response.getEntity().getClass(),
producedMime);
+ }
} else {
producedMime =
- context.getAttribute(ProvidersRegistry.class)
- .getMessageBodyWriterMediaTypes(result.getClass());
- if (debug)
- logger
- .trace("Determining Content-Type from compatible generic type to {} from MessageBodyWriters: {}", //$NON-NLS-1$
+ context.getAttribute(ProvidersRegistry.class).getMessageBodyWriterMediaTypes(result.getClass());
+ if (debug) {
+ logger.trace("Determining Content-Type from compatible generic type to {} from MessageBodyWriters: {}", //$NON-NLS-1$
result.getClass(),
producedMime);
+ }
}
/*
* This is to inform the application developer that they should
* specify the Content-Type.
*/
if (debug) {
- logger
- .debug(Messages
- .getMessage("populateResponseMediaTypeHandlerFromCompatibleMessageBodyWriters")); //$NON-NLS-1$
+ logger.debug(Messages.getMessage("populateResponseMediaTypeHandlerFromCompatibleMessageBodyWriters")); //$NON-NLS-1$
}
}
if (producedMime.isEmpty()) {
producedMime.add(MediaType.WILDCARD_TYPE);
}
- List<MediaType> acceptableMediaTypes =
- context.getHttpHeaders().getAcceptableMediaTypes();
+ List<MediaType> acceptableMediaTypes = context.getHttpHeaders().getAcceptableMediaTypes();
// collect all candidates
List<CandidateMediaType> candidates = new LinkedList<CandidateMediaType>();
for (MediaType acceptableMediaType : acceptableMediaTypes) {
for (MediaType mediaType : producedMime) {
- if (debug)
+ if (debug) {
logger.trace("Comparing {} to {}", acceptableMediaType, mediaType); //$NON-NLS-1$
+ }
if (mediaType.isCompatible(acceptableMediaType)) {
MediaType candidateMediaType = null;
if (MediaTypeUtils.compareTo(mediaType, acceptableMediaType) > 0) {
@@ -142,18 +138,15 @@ public class PopulateResponseMediaTypeHa
} else {
candidateMediaType = acceptableMediaType;
}
- if (debug)
- logger.trace("MediaType compatible so using candidate type {}", //$NON-NLS-1$
- candidateMediaType);
+ if (debug) {
+ logger.trace("MediaType compatible so using candidate type {}", candidateMediaType); //$NON-NLS-1$
+ }
String q = acceptableMediaType.getParameters().get("q"); //$NON-NLS-1$
CandidateMediaType candidate =
new CandidateMediaType(candidateMediaType, q);
if (Double.compare(candidate.q, 0.0) != 0) {
if (debug) {
- logger
- .trace("Candidate {} has q value {} so adding to possible candidates", //$NON-NLS-1$
- candidate.getMediaType(),
- q);
+ logger.trace("Candidate {} has q value {} so adding to possible candidates", candidate.getMediaType(), q); //$NON-NLS-1$
}
candidates.add(candidate);
}
@@ -164,13 +157,12 @@ public class PopulateResponseMediaTypeHa
// there are no candidates
if (candidates.isEmpty()) {
if (isErrorFlow()) {
- if (debug)
- logger
- .trace("Error flow and no candidates so not going to set a Content-Type"); //$NON-NLS-1$
+ if (debug) {
+ logger.trace("Error flow and no candidates so not going to set a Content-Type"); //$NON-NLS-1$
+ }
return;
}
- logger.info(Messages
- .getMessage("populateResponseMediaTypeHandlerNoAcceptableResponse")); //$NON-NLS-1$
+ logger.info(Messages.getMessage("populateResponseMediaTypeHandlerNoAcceptableResponse")); //$NON-NLS-1$
throw new WebApplicationException(Response.Status.NOT_ACCEPTABLE);
}
@@ -183,39 +175,31 @@ public class PopulateResponseMediaTypeHa
if (max == null) {
max = candidate;
if (debug) {
- logger.trace("No previous best candidate so using candidate {}", max //$NON-NLS-1$
- .getMediaType());
+ logger.trace("No previous best candidate so using candidate {}", max.getMediaType()); //$NON-NLS-1$
}
} else {
// select the more specific media type before a media type
// that has a wildcard in it
// even if its q value is greater
- int comparison =
- MediaTypeUtils.compareTo(candidate.getMediaType(), max.getMediaType());
+ int comparison = MediaTypeUtils.compareTo(candidate.getMediaType(), max.getMediaType());
if (comparison > 0) {
max = candidate;
if (debug) {
- logger
- .trace("Best candidate is now {} because it was a more specific media type", //$NON-NLS-1$
- max.getMediaType());
+ logger.trace("Best candidate is now {} because it was a more specific media type", max.getMediaType()); //$NON-NLS-1$
}
} else if (comparison == 0 && candidate.getQ() > max.getQ()) {
max = candidate;
if (debug) {
- logger
- .trace("Best candidate is now {} because it had a higher quality value {} compared to {} with quality value {}", //$NON-NLS-1$
- new Object[] {max.getMediaType(), max.getQ(), candidate,
- candidate.getQ()});
+ logger.trace("Best candidate is now {} because it had a higher quality value {} compared to {} with quality value {}", //$NON-NLS-1$
+ new Object[] {max.getMediaType(), max.getQ(), candidate, candidate.getQ()});
}
}
}
- if (!useOctetStream && (candidate.getMediaType().equals(MediaType.WILDCARD_TYPE) || candidate
- .getMediaType().equals(APPLICATION_TYPE))) {
- if (debug)
- logger
- .trace("If necessary, use an application/octet-stream because there is a wildcard", //$NON-NLS-1$
- candidate.getMediaType());
+ if (!useOctetStream && (candidate.getMediaType().equals(MediaType.WILDCARD_TYPE) || candidate.getMediaType().equals(APPLICATION_TYPE))) {
+ if (debug) {
+ logger.trace("If necessary, use an application/octet-stream because there is a wildcard", candidate.getMediaType()); //$NON-NLS-1$
+ }
useOctetStream = true;
}
}
@@ -223,24 +207,25 @@ public class PopulateResponseMediaTypeHa
if (max.getMediaType().isWildcardSubtype() == false) {
responseMediaType = max.getMediaType();
} else if (useOctetStream) {
- if (debug)
- logger
- .trace("Content-Type was reset to application/octet-stream because it was either */* or was application/*"); //$NON-NLS-1$
+ if (debug) {
+ logger.trace("Content-Type was reset to application/octet-stream because it was either */* or was application/*"); //$NON-NLS-1$
+ }
responseMediaType = MediaType.APPLICATION_OCTET_STREAM_TYPE;
} else {
if (isErrorFlow()) {
- if (debug)
+ if (debug) {
logger.trace("Error flow so not going to set a response Content-Type"); //$NON-NLS-1$
+ }
return;
}
- logger.info(Messages
- .getMessage("populateResponseMediaTypeHandlerNoAcceptableResponse")); //$NON-NLS-1$
+ logger.info(Messages.getMessage("populateResponseMediaTypeHandlerNoAcceptableResponse")); //$NON-NLS-1$
throw new WebApplicationException(Response.Status.NOT_ACCEPTABLE);
}
}
- if (debug)
+ if (debug) {
logger.trace("Response Content-Type will be set to {}", responseMediaType); //$NON-NLS-1$
+ }
context.setResponseMediaType(responseMediaType);
}