Re: [mule-scm] [mule][24721] branches/mule-3.2.x/patterns/core/src/main/java/org/mule/ module/ws/construct/WSProxy.java: MULE-6388: Preserve parameters when serving WSDL in ws-proxy and also support XSD

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Re: [mule-scm] [mule][24721] branches/mule-3.2.x/patterns/core/src/main/java/org/mule/ module/ws/construct/WSProxy.java: MULE-6388: Preserve parameters when serving WSDL in ws-proxy and also support XSD

Pablo Kraan
Hi Eva,

Looking at the code, seems like isWsdlOrXSDRequest is not safe, in the sense that matches any parameter that starts with xsd like xsd1, etc.
Can you improve that method?

Pablo

On Thu, Aug 9, 2012 at 7:18 PM, <[hidden email]> wrote:
Revision
24721
Author
evangelinamrm
Date
2012-08-09 17:18:56 -0500 (Thu, 09 Aug 2012)

Log Message

MULE-6388: Preserve parameters when serving WSDL in ws-proxy and also support XSD

Modified Paths

Diff

Modified: branches/mule-3.2.x/patterns/core/src/main/java/org/mule/module/ws/construct/WSProxy.java (24720 => 24721)


--- branches/mule-3.2.x/patterns/core/src/main/java/org/mule/module/ws/construct/WSProxy.java	2012-08-09 19:59:40 UTC (rev 24720)
+++ branches/mule-3.2.x/patterns/core/src/main/java/org/mule/module/ws/construct/WSProxy.java	2012-08-09 22:18:56 UTC (rev 24721)
@@ -166,6 +166,9 @@
         private static final String HTTP_REQUEST = "http.request";
         private static final String WSDL_PARAM_1 = "?wsdl";
         private static final String WSDL_PARAM_2 = "&wsdl";
+        // Web Services can also serve Schemas
+        private static final String XSD_PARAM_1 = "?xsd=";
+        private static final String XSD_PARAM_2 = "&xsd=";
         private static final String LOCALHOST = "localhost";
         
         protected final Log logger = LogFactory.getLog(WSProxy.class);
@@ -178,9 +181,9 @@
 
         public MuleEvent process(final MuleEvent event) throws MuleException
         {
-            if (isWsdlRequest(event))
+            if (isWsdlOrXSDRequest(event))
             {
-                return buildWsdlResult(event);
+                return buildWsdlOrXSDResult(event);
             }
 
             if (logger.isDebugEnabled())
@@ -191,7 +194,7 @@
             return event;
         }
 
-        private MuleEvent buildWsdlResult(final MuleEvent event) throws MuleException
+        private MuleEvent buildWsdlOrXSDResult(final MuleEvent event) throws MuleException
         {
             try
             {
@@ -245,7 +248,7 @@
             return wsdlContents;
         }
 
-        private boolean isWsdlRequest(final MuleEvent event) throws MuleException
+        private boolean isWsdlOrXSDRequest(final MuleEvent event) throws MuleException
         {
             // retrieve the original HTTP request. This will be used to check if the
             // user asked for the WSDL or a service method.
@@ -259,9 +262,11 @@
 
             final String lowerHttpRequest = httpRequest.toLowerCase();
 
-            // check if the inbound request contains the WSDL parameter
+            // check if the inbound request contains the WSDL or XSD parameter
             return (lowerHttpRequest.indexOf(WSDL_PARAM_1) != -1)
-                   || (lowerHttpRequest.indexOf(WSDL_PARAM_2) != -1);
+                   || (lowerHttpRequest.indexOf(WSDL_PARAM_2) != -1)
+                    || (lowerHttpRequest.indexOf(XSD_PARAM_1) != -1)
+                    || (lowerHttpRequest.indexOf(XSD_PARAM_2) != -1);
         }
 
         protected abstract String getWsdlContents(MuleEvent event) throws Exception;
@@ -365,7 +370,7 @@
                             .getExpressionManager()
                             .parse(wsAddress, event.getMessage(), true);
 
-                        return makeWsdlAddress(resolvedWsAddress);
+                        return makeWsdlOrXSDAddress(resolvedWsAddress, event.getMessage());
                     }
                 };
 
@@ -373,29 +378,38 @@
             }
             else
             {
-                final String wsdlAddress = makeWsdlAddress(wsAddress);
-
                 wsdlAddressProvider = new WsdlAddressProvider()
                 {
                     public String get(final MuleEvent event)
                     {
-                        return wsdlAddress;
+                        return makeWsdlOrXSDAddress(wsAddress, event.getMessage());
                     }
                 };
 
-                logger.info("Setting WSDL address to: " + wsdlAddress);
+                logger.info("Setting WSDL address for: " + wsAddress);
             }
         }
 
-        private static String makeWsdlAddress(final String wsAddress)
+        private static String makeWsdlOrXSDAddress(final String wsAddress, MuleMessage message)
         {
-            return StringUtils.substringBefore(wsAddress, "?").concat("?wsdl");
+            String request = message.getInboundProperty("http.request");
+            String address = StringUtils.substringBefore(wsAddress, "?") + "?";
+            // Parameters should be propagated, wsdl=1 or xsd=1 are valid
+            if(request != null && request.indexOf("?") > -1)
+            {
+                String queryString = StringUtils.substringAfter(request, "?");
+                return address.concat(queryString);
+            }
+            else
+            {
+                return address.concat("wsdl");
+            }
         }
 
         @Override
         protected String getWsdlContents(final MuleEvent event) throws Exception
         {
-            final String wsdlAddress = wsdlAddressProvider.get(event);
+            String wsdlAddress = wsdlAddressProvider.get(event);
             String wsdlString;
 
             final MuleContext muleContext = event.getMuleContext();

To unsubscribe from this list please visit:

http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: [mule-scm] [mule][24721] branches/mule-3.2.x/patterns/core/src/main/java/org/mule/ module/ws/construct/WSProxy.java: MULE-6388: Preserve parameters when serving WSDL in ws-proxy and also support XSD

Evangelina Martinez
Hi Pablo,

Actually it needs to start with "xsd=". Which is the same that CXF does when validating the WSDL requests.

Eva

On Fri, Aug 10, 2012 at 12:56 PM, Pablo Kraan <[hidden email]> wrote:
Hi Eva,

Looking at the code, seems like isWsdlOrXSDRequest is not safe, in the sense that matches any parameter that starts with xsd like xsd1, etc.
Can you improve that method?

Pablo

On Thu, Aug 9, 2012 at 7:18 PM, <[hidden email]> wrote:
Revision
24721
Author
evangelinamrm
Date
2012-08-09 17:18:56 -0500 (Thu, 09 Aug 2012)

Log Message

MULE-6388: Preserve parameters when serving WSDL in ws-proxy and also support XSD

Modified Paths

Diff

Modified: branches/mule-3.2.x/patterns/core/src/main/java/org/mule/module/ws/construct/WSProxy.java (24720 => 24721)


--- branches/mule-3.2.x/patterns/core/src/main/java/org/mule/module/ws/construct/WSProxy.java	2012-08-09 19:59:40 UTC (rev 24720)
+++ branches/mule-3.2.x/patterns/core/src/main/java/org/mule/module/ws/construct/WSProxy.java	2012-08-09 22:18:56 UTC (rev 24721)
@@ -166,6 +166,9 @@
         private static final String HTTP_REQUEST = "http.request";
         private static final String WSDL_PARAM_1 = "?wsdl";
         private static final String WSDL_PARAM_2 = "&wsdl";
+        // Web Services can also serve Schemas
+        private static final String XSD_PARAM_1 = "?xsd=";
+        private static final String XSD_PARAM_2 = "&xsd=";
         private static final String LOCALHOST = "localhost";
         
         protected final Log logger = LogFactory.getLog(WSProxy.class);
@@ -178,9 +181,9 @@
 
         public MuleEvent process(final MuleEvent event) throws MuleException
         {
-            if (isWsdlRequest(event))
+            if (isWsdlOrXSDRequest(event))
             {
-                return buildWsdlResult(event);
+                return buildWsdlOrXSDResult(event);
             }
 
             if (logger.isDebugEnabled())
@@ -191,7 +194,7 @@
             return event;
         }
 
-        private MuleEvent buildWsdlResult(final MuleEvent event) throws MuleException
+        private MuleEvent buildWsdlOrXSDResult(final MuleEvent event) throws MuleException
         {
             try
             {
@@ -245,7 +248,7 @@
             return wsdlContents;
         }
 
-        private boolean isWsdlRequest(final MuleEvent event) throws MuleException
+        private boolean isWsdlOrXSDRequest(final MuleEvent event) throws MuleException
         {
             // retrieve the original HTTP request. This will be used to check if the
             // user asked for the WSDL or a service method.
@@ -259,9 +262,11 @@
 
             final String lowerHttpRequest = httpRequest.toLowerCase();
 
-            // check if the inbound request contains the WSDL parameter
+            // check if the inbound request contains the WSDL or XSD parameter
             return (lowerHttpRequest.indexOf(WSDL_PARAM_1) != -1)
-                   || (lowerHttpRequest.indexOf(WSDL_PARAM_2) != -1);
+                   || (lowerHttpRequest.indexOf(WSDL_PARAM_2) != -1)
+                    || (lowerHttpRequest.indexOf(XSD_PARAM_1) != -1)
+                    || (lowerHttpRequest.indexOf(XSD_PARAM_2) != -1);
         }
 
         protected abstract String getWsdlContents(MuleEvent event) throws Exception;
@@ -365,7 +370,7 @@
                             .getExpressionManager()
                             .parse(wsAddress, event.getMessage(), true);
 
-                        return makeWsdlAddress(resolvedWsAddress);
+                        return makeWsdlOrXSDAddress(resolvedWsAddress, event.getMessage());
                     }
                 };
 
@@ -373,29 +378,38 @@
             }
             else
             {
-                final String wsdlAddress = makeWsdlAddress(wsAddress);
-
                 wsdlAddressProvider = new WsdlAddressProvider()
                 {
                     public String get(final MuleEvent event)
                     {
-                        return wsdlAddress;
+                        return makeWsdlOrXSDAddress(wsAddress, event.getMessage());
                     }
                 };
 
-                logger.info("Setting WSDL address to: " + wsdlAddress);
+                logger.info("Setting WSDL address for: " + wsAddress);
             }
         }
 
-        private static String makeWsdlAddress(final String wsAddress)
+        private static String makeWsdlOrXSDAddress(final String wsAddress, MuleMessage message)
         {
-            return StringUtils.substringBefore(wsAddress, "?").concat("?wsdl");
+            String request = message.getInboundProperty("http.request");
+            String address = StringUtils.substringBefore(wsAddress, "?") + "?";
+            // Parameters should be propagated, wsdl=1 or xsd=1 are valid
+            if(request != null && request.indexOf("?") > -1)
+            {
+                String queryString = StringUtils.substringAfter(request, "?");
+                return address.concat(queryString);
+            }
+            else
+            {
+                return address.concat("wsdl");
+            }
         }
 
         @Override
         protected String getWsdlContents(final MuleEvent event) throws Exception
         {
-            final String wsdlAddress = wsdlAddressProvider.get(event);
+            String wsdlAddress = wsdlAddressProvider.get(event);
             String wsdlString;
 
             final MuleContext muleContext = event.getMuleContext();

To unsubscribe from this list please visit:

http://xircles.codehaus.org/manage_email



Reply | Threaded
Open this post in threaded view
|

Re: [mule-scm] [mule][24721] branches/mule-3.2.x/patterns/core/src/main/java/org/mule/ module/ws/construct/WSProxy.java: MULE-6388: Preserve parameters when serving WSDL in ws-proxy and also support XSD

Pablo Kraan
Your are right, I saw WSDL_PARAM_1 = "?wsdl"; and though that was the same witht the xsd param.
Is still a problem regarding the wsdl param, right?

On Fri, Aug 10, 2012 at 1:47 PM, Evangelina Martinez <[hidden email]> wrote:
Hi Pablo,

Actually it needs to start with "xsd=". Which is the same that CXF does when validating the WSDL requests.

Eva


On Fri, Aug 10, 2012 at 12:56 PM, Pablo Kraan <[hidden email]> wrote:
Hi Eva,

Looking at the code, seems like isWsdlOrXSDRequest is not safe, in the sense that matches any parameter that starts with xsd like xsd1, etc.
Can you improve that method?

Pablo

On Thu, Aug 9, 2012 at 7:18 PM, <[hidden email]> wrote:
Revision
24721
Author
evangelinamrm
Date
2012-08-09 17:18:56 -0500 (Thu, 09 Aug 2012)

Log Message

MULE-6388: Preserve parameters when serving WSDL in ws-proxy and also support XSD

Modified Paths

Diff

Modified: branches/mule-3.2.x/patterns/core/src/main/java/org/mule/module/ws/construct/WSProxy.java (24720 => 24721)


--- branches/mule-3.2.x/patterns/core/src/main/java/org/mule/module/ws/construct/WSProxy.java	2012-08-09 19:59:40 UTC (rev 24720)
+++ branches/mule-3.2.x/patterns/core/src/main/java/org/mule/module/ws/construct/WSProxy.java	2012-08-09 22:18:56 UTC (rev 24721)
@@ -166,6 +166,9 @@
         private static final String HTTP_REQUEST = "http.request";
         private static final String WSDL_PARAM_1 = "?wsdl";
         private static final String WSDL_PARAM_2 = "&wsdl";
+        // Web Services can also serve Schemas
+        private static final String XSD_PARAM_1 = "?xsd=";
+        private static final String XSD_PARAM_2 = "&xsd=";
         private static final String LOCALHOST = "localhost";
         
         protected final Log logger = LogFactory.getLog(WSProxy.class);
@@ -178,9 +181,9 @@
 
         public MuleEvent process(final MuleEvent event) throws MuleException
         {
-            if (isWsdlRequest(event))
+            if (isWsdlOrXSDRequest(event))
             {
-                return buildWsdlResult(event);
+                return buildWsdlOrXSDResult(event);
             }
 
             if (logger.isDebugEnabled())
@@ -191,7 +194,7 @@
             return event;
         }
 
-        private MuleEvent buildWsdlResult(final MuleEvent event) throws MuleException
+        private MuleEvent buildWsdlOrXSDResult(final MuleEvent event) throws MuleException
         {
             try
             {
@@ -245,7 +248,7 @@
             return wsdlContents;
         }
 
-        private boolean isWsdlRequest(final MuleEvent event) throws MuleException
+        private boolean isWsdlOrXSDRequest(final MuleEvent event) throws MuleException
         {
             // retrieve the original HTTP request. This will be used to check if the
             // user asked for the WSDL or a service method.
@@ -259,9 +262,11 @@
 
             final String lowerHttpRequest = httpRequest.toLowerCase();
 
-            // check if the inbound request contains the WSDL parameter
+            // check if the inbound request contains the WSDL or XSD parameter
             return (lowerHttpRequest.indexOf(WSDL_PARAM_1) != -1)
-                   || (lowerHttpRequest.indexOf(WSDL_PARAM_2) != -1);
+                   || (lowerHttpRequest.indexOf(WSDL_PARAM_2) != -1)
+                    || (lowerHttpRequest.indexOf(XSD_PARAM_1) != -1)
+                    || (lowerHttpRequest.indexOf(XSD_PARAM_2) != -1);
         }
 
         protected abstract String getWsdlContents(MuleEvent event) throws Exception;
@@ -365,7 +370,7 @@
                             .getExpressionManager()
                             .parse(wsAddress, event.getMessage(), true);
 
-                        return makeWsdlAddress(resolvedWsAddress);
+                        return makeWsdlOrXSDAddress(resolvedWsAddress, event.getMessage());
                     }
                 };
 
@@ -373,29 +378,38 @@
             }
             else
             {
-                final String wsdlAddress = makeWsdlAddress(wsAddress);
-
                 wsdlAddressProvider = new WsdlAddressProvider()
                 {
                     public String get(final MuleEvent event)
                     {
-                        return wsdlAddress;
+                        return makeWsdlOrXSDAddress(wsAddress, event.getMessage());
                     }
                 };
 
-                logger.info("Setting WSDL address to: " + wsdlAddress);
+                logger.info("Setting WSDL address for: " + wsAddress);
             }
         }
 
-        private static String makeWsdlAddress(final String wsAddress)
+        private static String makeWsdlOrXSDAddress(final String wsAddress, MuleMessage message)
         {
-            return StringUtils.substringBefore(wsAddress, "?").concat("?wsdl");
+            String request = message.getInboundProperty("http.request");
+            String address = StringUtils.substringBefore(wsAddress, "?") + "?";
+            // Parameters should be propagated, wsdl=1 or xsd=1 are valid
+            if(request != null && request.indexOf("?") > -1)
+            {
+                String queryString = StringUtils.substringAfter(request, "?");
+                return address.concat(queryString);
+            }
+            else
+            {
+                return address.concat("wsdl");
+            }
         }
 
         @Override
         protected String getWsdlContents(final MuleEvent event) throws Exception
         {
-            final String wsdlAddress = wsdlAddressProvider.get(event);
+            String wsdlAddress = wsdlAddressProvider.get(event);
             String wsdlString;
 
             final MuleContext muleContext = event.getMuleContext();

To unsubscribe from this list please visit:

http://xircles.codehaus.org/manage_email