JBossWS SVN: r18808 - in common/trunk/src/main/java/org/jboss/ws/common: utils and 1 other directory.
by jbossws-commits@lists.jboss.org
Author: rsearls
Date: 2014-07-21 15:54:06 -0400 (Mon, 21 Jul 2014)
New Revision: 18808
Added:
common/trunk/src/main/java/org/jboss/ws/common/utils/UrlPatternUtils.java
Modified:
common/trunk/src/main/java/org/jboss/ws/common/deployment/URLPatternDeploymentAspect.java
Log:
[JBWS-3809] refactored urlPattern code into a new util class.
Modified: common/trunk/src/main/java/org/jboss/ws/common/deployment/URLPatternDeploymentAspect.java
===================================================================
--- common/trunk/src/main/java/org/jboss/ws/common/deployment/URLPatternDeploymentAspect.java 2014-07-21 19:31:56 UTC (rev 18807)
+++ common/trunk/src/main/java/org/jboss/ws/common/deployment/URLPatternDeploymentAspect.java 2014-07-21 19:54:06 UTC (rev 18808)
@@ -24,13 +24,9 @@
import static org.jboss.ws.common.integration.WSHelper.isEjbEndpoint;
import static org.jboss.ws.common.integration.WSHelper.isJseEndpoint;
-import java.util.StringTokenizer;
-
-import javax.jws.WebService;
-
-import org.jboss.ws.api.annotation.WebContext;
import org.jboss.ws.common.Messages;
import org.jboss.ws.common.integration.AbstractDeploymentAspect;
+import org.jboss.ws.common.utils.UrlPatternUtils;
import org.jboss.wsf.spi.deployment.Deployment;
import org.jboss.wsf.spi.deployment.Endpoint;
import org.jboss.wsf.spi.deployment.HttpEndpoint;
@@ -58,14 +54,11 @@
if (urlPattern == null)
{
urlPattern = getExplicitPattern(dep, ep);
- if (urlPattern == null)
+ if (urlPattern == null) {
urlPattern = ep.getShortName();
-
+ }
// Always prefix with '/'
- if (urlPattern.startsWith("/") == false)
- urlPattern = "/" + urlPattern;
-
- httpEp.setURLPattern(urlPattern);
+ httpEp.setURLPattern(UrlPatternUtils.getUrlPattern(urlPattern));
}
}
}
@@ -90,64 +83,30 @@
if (appMetaData != null && appMetaData.getBeanByEjbName(ep.getShortName()) != null && isEjbEndpoint(ep))
{
EJBMetaData bmd = appMetaData.getBeanByEjbName(ep.getShortName());
- urlPattern = bmd.getPortComponentURI();
- if (urlPattern != null)
- {
- String contextRoot = dep.getService().getContextRoot();
-
- if (urlPattern.startsWith("/") == false)
- urlPattern = "/" + urlPattern;
-
- StringTokenizer st = new StringTokenizer(urlPattern, "/");
- if (st.countTokens() > 1 && urlPattern.startsWith(contextRoot + "/"))
- {
- urlPattern = urlPattern.substring(contextRoot.length());
- }
- }
+ urlPattern = UrlPatternUtils.getUrlPatternByPortComponentURI(bmd.getPortComponentURI(),
+ dep.getService().getContextRoot());
}
// #3 For EJB use @WebContext.urlPattern
if (urlPattern == null)
{
- Class<?> beanClass = ep.getTargetBeanClass();
- WebContext anWebContext = (WebContext)beanClass.getAnnotation(WebContext.class);
- if (anWebContext != null && anWebContext.urlPattern().length() > 0)
- {
- urlPattern = anWebContext.urlPattern();
- }
-
+ urlPattern = UrlPatternUtils.getUrlPatternByWebContext(ep.getTargetBeanClass());
}
// #4 Use @WebService
if (urlPattern == null)
{
- Class<?> beanClass = ep.getTargetBeanClass();
- WebService webServiceAnnotation = (WebService)beanClass.getAnnotation(WebService.class);
- if (webServiceAnnotation != null)
- {
- String name = webServiceAnnotation.name();
- urlPattern = !isEmpty(name) ? name : beanClass.getSimpleName();
- String serviceName = webServiceAnnotation.serviceName();
- if (!isEmpty(serviceName))
- {
- urlPattern = serviceName + "/" + urlPattern;
- }
- }
+ urlPattern = UrlPatternUtils.getUrlPatternByWebService(ep.getTargetBeanClass());
}
// TODO: WebServiceProvider ???
// #5 Use simple class name
if (urlPattern == null)
{
- Class<?> beanClass = ep.getTargetBeanClass();
- urlPattern = beanClass.getSimpleName();
+ urlPattern = UrlPatternUtils.getUrlPatternByClassname(ep.getTargetBeanClass());
}
return urlPattern;
}
- private static boolean isEmpty(final String s) {
- return s == null || s.length() == 0;
- }
-
}
Added: common/trunk/src/main/java/org/jboss/ws/common/utils/UrlPatternUtils.java
===================================================================
--- common/trunk/src/main/java/org/jboss/ws/common/utils/UrlPatternUtils.java (rev 0)
+++ common/trunk/src/main/java/org/jboss/ws/common/utils/UrlPatternUtils.java 2014-07-21 19:54:06 UTC (rev 18808)
@@ -0,0 +1,108 @@
+package org.jboss.ws.common.utils;
+
+import org.jboss.ws.api.annotation.WebContext;
+import org.jboss.wsf.spi.metadata.webservices.JBossPortComponentMetaData;
+
+import javax.jws.WebService;
+import java.util.StringTokenizer;
+
+/**
+ * Shared rules for ws endpoint urlPattern generation,
+ * also a single point for the rules.
+ *
+ * User: rsearls
+ * Date: 7/21/14
+ */
+public class UrlPatternUtils {
+
+ public static String getUrlPatternByClassname(Class<?> beanClass){
+ return beanClass.getSimpleName();
+ }
+
+
+ public static String getUrlPatternByWebServiceProvider(Class<?> beanClass){
+ return null;
+ }
+
+
+ public static String getUrlPatternByWebService(Class<?> beanClass){
+ String urlPattern = null;
+ WebService webServiceAnnotation = (WebService)beanClass.getAnnotation(WebService.class);
+ if (webServiceAnnotation != null)
+ {
+ String name = webServiceAnnotation.name();
+ urlPattern = !isEmpty(name) ? name : beanClass.getSimpleName();
+ String serviceName = webServiceAnnotation.serviceName();
+ if (!isEmpty(serviceName))
+ {
+ urlPattern = serviceName + "/" + urlPattern;
+ }
+ }
+ return urlPattern;
+ }
+
+
+ public static String getUrlPatternByWebContext(Class<?> beanClass){
+ WebContext anWebContext = (WebContext)beanClass.getAnnotation(WebContext.class);
+ if (anWebContext != null && anWebContext.urlPattern().length() > 0)
+ {
+ return anWebContext.urlPattern();
+ }
+ return null;
+ }
+
+ public static String getUrlPatternByPortComponentURI (String urlPattern, String contextRoot) {
+
+ if (urlPattern != null)
+ {
+ urlPattern = getUrlPattern(urlPattern);
+
+ if (contextRoot != null) {
+ StringTokenizer st = new StringTokenizer(urlPattern, "/");
+ if (st.countTokens() > 1 && urlPattern.startsWith(contextRoot + "/")) {
+ urlPattern = urlPattern.substring(contextRoot.length());
+ }
+ }
+ }
+ return urlPattern;
+ }
+
+
+ public static String getUrlPatternByPortComponentURI (JBossPortComponentMetaData portComponent) {
+ String urlPattern = null;
+ if (portComponent != null) {
+ String portComponentURI = portComponent.getPortComponentURI();
+ if (portComponentURI != null && portComponentURI.length() > 0) {
+ urlPattern = portComponentURI;
+ }
+ }
+ return urlPattern;
+ }
+
+
+ public static String getUrlPattern(String classBasename, String serviceName, String name) {
+ String urlPattern = !isEmpty(name) ? name : classBasename;
+ if (!isEmpty(serviceName)) {
+ urlPattern = serviceName + "/" + urlPattern;
+ }
+ return urlPattern;
+ }
+
+
+ public static String getUrlPattern(String classBasename, String serviceName) {
+ return "/" + (!serviceName.equals("") ? serviceName : classBasename);
+ }
+
+
+ public static String getUrlPattern(String urlPattern) {
+ if (urlPattern.startsWith("/") == false)
+ urlPattern = "/" + urlPattern;
+
+ return urlPattern;
+ }
+
+ private static boolean isEmpty(final String s) {
+ return s == null || s.length() == 0;
+ }
+
+}