Author: struberg
Date: Tue Jun 20 07:38:13 2017
New Revision: 1799311
URL: http://svn.apache.org/viewvc?rev=1799311&view=rev
Log:
extract inline lambda to own function for readability
Modified:
openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/cxf/CxfCdiAutoSetup.java
Modified:
openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/cxf/CxfCdiAutoSetup.java
URL:
http://svn.apache.org/viewvc/openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/cxf/CxfCdiAutoSetup.java?rev=1799311&r1=1799310&r2=1799311&view=diff
==============================================================================
---
openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/cxf/CxfCdiAutoSetup.java
(original)
+++
openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/cxf/CxfCdiAutoSetup.java
Tue Jun 20 07:38:13 2017
@@ -64,6 +64,7 @@ import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
+import java.util.function.Function;
import java.util.stream.Stream;
import static java.util.Optional.ofNullable;
@@ -321,90 +322,97 @@ public class CxfCdiAutoSetup implements
prefixes = registry.getDestinations().stream()
.filter(ServletDestination.class::isInstance)
.map(ServletDestination.class::cast)
- .map(sd -> {
- final Endpoint endpoint =
ChainInitiationObserver.class.cast(sd.getMessageObserver()).getEndpoint();
- final ApplicationInfo app =
ApplicationInfo.class.cast(endpoint.get(Application.class.getName()));
- final JAXRSServiceFactoryBean sfb =
JAXRSServiceFactoryBean.class.cast(endpoint.get(JAXRSServiceFactoryBean.class.getName()));
- final String base = sd.getEndpointInfo().getAddress();
-
- if (sfb != null) {
- final List<Logs.LogResourceEndpointInfo>
resourcesToLog = new ArrayList<>();
- int classSize = 0;
- int addressSize = 0;
-
- final List<ClassResourceInfo> resources =
sfb.getClassResourceInfo();
- for (final ClassResourceInfo info : resources) {
- if (info.getResourceClass() == null) { //
possible?
- continue;
- }
-
- final String address = Logs.singleSlash(base,
info.getURITemplate().getValue());
-
- final String clazz =
uproxyName(info.getResourceClass().getName());
- classSize = Math.max(classSize,
clazz.length());
- addressSize = Math.max(addressSize,
address.length());
-
- int methodSize = 7;
- int methodStrSize = 0;
-
- final List<Logs.LogOperationEndpointInfo>
toLog = new ArrayList<>();
-
- final MethodDispatcher md =
info.getMethodDispatcher();
- for (final OperationResourceInfo ori :
md.getOperationResourceInfos()) {
- final String httpMethod =
ori.getHttpMethod();
- final String currentAddress =
Logs.singleSlash(address, ori.getURITemplate().getValue());
- final String methodToStr =
Logs.toSimpleString(ori.getMethodToInvoke());
- toLog.add(new
Logs.LogOperationEndpointInfo(httpMethod, currentAddress, methodToStr));
-
- if (httpMethod != null) {
- methodSize = Math.max(methodSize,
httpMethod.length());
- }
- addressSize = Math.max(addressSize,
currentAddress.length());
- methodStrSize = Math.max(methodStrSize,
methodToStr.length());
- }
+ .map(getServletDestinationPath(sc, log))
+ .filter(Objects::nonNull)
+ .toArray(String[]::new);
+ }
- Collections.sort(toLog);
+ private Function<ServletDestination, String>
getServletDestinationPath(ServletConfig sc, LogFacade log)
+ {
+ return sd -> {
+ final Endpoint endpoint =
ChainInitiationObserver.class.cast(sd.getMessageObserver()).getEndpoint();
+ final ApplicationInfo app =
ApplicationInfo.class.cast(endpoint.get(Application.class.getName()));
+ final JAXRSServiceFactoryBean sfb =
JAXRSServiceFactoryBean.class.cast(endpoint.get(JAXRSServiceFactoryBean.class.getName()));
+ final String base = sd.getEndpointInfo().getAddress();
+
+ if (sfb != null) {
+ final List<Logs.LogResourceEndpointInfo> resourcesToLog =
new ArrayList<>();
+ int classSize = 0;
+ int addressSize = 0;
+
+ final List<ClassResourceInfo> resources =
sfb.getClassResourceInfo();
+ for (final ClassResourceInfo info : resources) {
+ if (info.getResourceClass() == null) { // possible?
+ continue;
+ }
- resourcesToLog.add(new
Logs.LogResourceEndpointInfo(address, clazz, toLog, methodSize, methodStrSize));
- }
+ final String address = Logs.singleSlash(base,
info.getURITemplate().getValue());
- // effective logging
- log.info("REST Application: " +
endpoint.getEndpointInfo().getAddress() + " -> "
- +
ofNullable(app).map(ApplicationInfo::getResourceClass).map(Class::getName).map(CxfCdiAutoSetup::uproxyName).orElse(""));
-
- Collections.sort(resourcesToLog);
- final int fClassSize = classSize;
- final int fAddressSize = addressSize;
- resourcesToLog.forEach(resource -> {
- log.info(" Service URI: "
- + Logs.forceLength(resource.address,
fAddressSize, true) + " -> "
- + Logs.forceLength(resource.classname,
fClassSize, true));
-
- resource.operations.forEach(info -> {
- log.info(" "
- + Logs.forceLength(info.http,
resource.methodSize, false) + " "
- + Logs.forceLength(info.address,
fAddressSize, true) + " -> "
- + Logs.forceLength(info.method,
resource.methodStrSize, true));
- });
- resource.operations.clear();
- });
- resourcesToLog.clear();
-
- // log @Providers
- if
(Meecrowave.Builder.class.cast(sc.getServletContext().getAttribute("meecrowave.configuration")).isJaxrsLogProviders())
{
- final ServerProviderFactory spf =
ServerProviderFactory.class.cast(endpoint.get(ServerProviderFactory.class.getName()));
- dump(log, spf, "MessageBodyReaders",
"messageReaders");
- dump(log, spf, "MessageBodyWriters",
"messageWriters");
- }
- } else {
- final EndpointInfo endpointInfo =
endpoint.getEndpointInfo();
- if (endpointInfo.getName() != null) {
- log.info("@WebService > " +
endpointInfo.getName().toString() + " -> " + base);
+ final String clazz =
uproxyName(info.getResourceClass().getName());
+ classSize = Math.max(classSize, clazz.length());
+ addressSize = Math.max(addressSize, address.length());
+
+ int methodSize = 7;
+ int methodStrSize = 0;
+
+ final List<Logs.LogOperationEndpointInfo> toLog = new
ArrayList<>();
+
+ final MethodDispatcher md = info.getMethodDispatcher();
+ for (final OperationResourceInfo ori :
md.getOperationResourceInfos()) {
+ final String httpMethod = ori.getHttpMethod();
+ final String currentAddress =
Logs.singleSlash(address, ori.getURITemplate().getValue());
+ final String methodToStr =
Logs.toSimpleString(ori.getMethodToInvoke());
+ toLog.add(new
Logs.LogOperationEndpointInfo(httpMethod, currentAddress, methodToStr));
+
+ if (httpMethod != null) {
+ methodSize = Math.max(methodSize,
httpMethod.length());
}
+ addressSize = Math.max(addressSize,
currentAddress.length());
+ methodStrSize = Math.max(methodStrSize,
methodToStr.length());
}
- return base;
- }).filter(Objects::nonNull).toArray(String[]::new);
+ Collections.sort(toLog);
+
+ resourcesToLog.add(new
Logs.LogResourceEndpointInfo(address, clazz, toLog, methodSize, methodStrSize));
+ }
+
+ // effective logging
+ log.info("REST Application: " +
endpoint.getEndpointInfo().getAddress() + " -> "
+ +
ofNullable(app).map(ApplicationInfo::getResourceClass).map(Class::getName).map(CxfCdiAutoSetup::uproxyName).orElse(""));
+
+ Collections.sort(resourcesToLog);
+ final int fClassSize = classSize;
+ final int fAddressSize = addressSize;
+ resourcesToLog.forEach(resource -> {
+ log.info(" Service URI: "
+ + Logs.forceLength(resource.address,
fAddressSize, true) + " -> "
+ + Logs.forceLength(resource.classname,
fClassSize, true));
+
+ resource.operations.forEach(info -> {
+ log.info(" "
+ + Logs.forceLength(info.http,
resource.methodSize, false) + " "
+ + Logs.forceLength(info.address,
fAddressSize, true) + " -> "
+ + Logs.forceLength(info.method,
resource.methodStrSize, true));
+ });
+ resource.operations.clear();
+ });
+ resourcesToLog.clear();
+
+ // log @Providers
+ if
(Meecrowave.Builder.class.cast(sc.getServletContext().getAttribute("meecrowave.configuration")).isJaxrsLogProviders())
{
+ final ServerProviderFactory spf =
ServerProviderFactory.class.cast(endpoint.get(ServerProviderFactory.class.getName()));
+ dump(log, spf, "MessageBodyReaders", "messageReaders");
+ dump(log, spf, "MessageBodyWriters", "messageWriters");
+ }
+ } else {
+ final EndpointInfo endpointInfo =
endpoint.getEndpointInfo();
+ if (endpointInfo.getName() != null) {
+ log.info("@WebService > " +
endpointInfo.getName().toString() + " -> " + base);
+ }
+ }
+
+ return base;
+ };
}
private void dump(final LogFacade log, final ServerProviderFactory
spf, final String description, final String fieldName) {