[jbossws-commits] JBossWS SVN: r18238 - in projects/jaxws-undertow-httpspi/trunk/src: main/java/org/jboss/ws/undertow_httpspi and 2 other directories.

jbossws-commits at lists.jboss.org jbossws-commits at lists.jboss.org
Wed Jan 15 01:23:18 EST 2014


Author: jim.ma
Date: 2014-01-15 01:23:18 -0500 (Wed, 15 Jan 2014)
New Revision: 18238

Added:
   projects/jaxws-undertow-httpspi/trunk/src/main/java/org/jboss/ws/undertow_httpspi/
   projects/jaxws-undertow-httpspi/trunk/src/main/java/org/jboss/ws/undertow_httpspi/PathUtils.java
   projects/jaxws-undertow-httpspi/trunk/src/main/java/org/jboss/ws/undertow_httpspi/UndertowContextFactory.java
   projects/jaxws-undertow-httpspi/trunk/src/main/java/org/jboss/ws/undertow_httpspi/UndertowHeaderMap.java
   projects/jaxws-undertow-httpspi/trunk/src/main/java/org/jboss/ws/undertow_httpspi/UndertowHttpContext.java
   projects/jaxws-undertow-httpspi/trunk/src/main/java/org/jboss/ws/undertow_httpspi/UndertowHttpExchange.java
   projects/jaxws-undertow-httpspi/trunk/src/main/java/org/jboss/ws/undertow_httpspi/UndertowHttpHandler.java
   projects/jaxws-undertow-httpspi/trunk/src/main/java/org/jboss/ws/undertow_httpspi/UndertowServer.java
   projects/jaxws-undertow-httpspi/trunk/src/test/java/org/jboss/ws/undertow_httpspi/
   projects/jaxws-undertow-httpspi/trunk/src/test/java/org/jboss/ws/undertow_httpspi/DHRequest.java
   projects/jaxws-undertow-httpspi/trunk/src/test/java/org/jboss/ws/undertow_httpspi/DHResponse.java
   projects/jaxws-undertow-httpspi/trunk/src/test/java/org/jboss/ws/undertow_httpspi/EndpointAPITest.java
   projects/jaxws-undertow-httpspi/trunk/src/test/java/org/jboss/ws/undertow_httpspi/EndpointBean.java
   projects/jaxws-undertow-httpspi/trunk/src/test/java/org/jboss/ws/undertow_httpspi/EndpointInterface.java
   projects/jaxws-undertow-httpspi/trunk/src/test/java/org/jboss/ws/undertow_httpspi/PathUtilsTest.java
Removed:
   projects/jaxws-undertow-httpspi/trunk/src/main/java/org/jboss/ws/httpserver_httpspi/
   projects/jaxws-undertow-httpspi/trunk/src/test/java/org/jboss/ws/httpserver_httpspi/
Log:
Refactor the package and class name after this impl is moved to a standalone project

Added: projects/jaxws-undertow-httpspi/trunk/src/main/java/org/jboss/ws/undertow_httpspi/PathUtils.java
===================================================================
--- projects/jaxws-undertow-httpspi/trunk/src/main/java/org/jboss/ws/undertow_httpspi/PathUtils.java	                        (rev 0)
+++ projects/jaxws-undertow-httpspi/trunk/src/main/java/org/jboss/ws/undertow_httpspi/PathUtils.java	2014-01-15 06:23:18 UTC (rev 18238)
@@ -0,0 +1,118 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ws.undertow_httpspi;
+
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URL;
+
+public class PathUtils
+{
+   /**
+    * Get the final path section of an address (for servlet
+    * container, this is typically a url-pattern for an endpoint)
+    * 
+    * @param addr
+    * @return
+    */
+   public static String getPath(String addr)
+   {
+      return getPathInternal(getPathFromString(addr));
+   }
+   
+   public static String getPath(URI addr)
+   {
+      return getPathInternal(addr.getPath());
+   }
+   
+   public static String getPathFromRequest(String requestPath)
+   {
+      return getPathInternal(requestPath);
+   }
+
+   private static String getPathInternal(String rawpath)
+   {
+      String path = removeTrailingSlash(rawpath);
+      if (path == null || path.length() == 0)
+      {
+         return path;
+      }
+      int idx = path.lastIndexOf("/");
+      return idx > 0 ? path.substring(path.lastIndexOf("/")) : "";
+   }
+   
+   /**
+    * Get the context path section of an address
+    * 
+    * @param addr
+    * @return
+    */
+   public static String getContextPath(String addr)
+   {
+      return getContextPathInternal(getPathFromString(addr));
+   }
+   
+   public static String getContextPathFromRequest(String requestPath)
+   {
+      return getContextPathInternal(requestPath);
+   }
+   
+   public static String getContextPath(URI addr)
+   {
+      return getContextPathInternal(addr.getPath());
+   }
+   
+   private static String getContextPathInternal(String rawpath)
+   {
+      String path = removeTrailingSlash(rawpath);
+      if (path == null || path.length() == 0)
+      {
+         return "/";
+      }
+      int idx = path.lastIndexOf("/");
+      return idx > 0 ? path.substring(0, idx) : path;
+   }
+   
+   private static String getPathFromString(String addr)
+   {
+      String path = null;
+      try
+      {
+         path = new URL(addr).getPath();
+      }
+      catch (MalformedURLException e)
+      {
+         //ignore
+      }
+      return path;
+   }
+   
+   public static String removeTrailingSlash(String path)
+   {
+      if (path != null && path.length() > 0 && path.lastIndexOf('/') == path.length() - 1)
+      {
+         path = path.substring(0, path.length() - 1);
+      }
+      return path;
+   }
+   
+}


Property changes on: projects/jaxws-undertow-httpspi/trunk/src/main/java/org/jboss/ws/undertow_httpspi/PathUtils.java
___________________________________________________________________
Added: svn:keywords
   + Rev Date
Added: svn:eol-style
   + native

Added: projects/jaxws-undertow-httpspi/trunk/src/main/java/org/jboss/ws/undertow_httpspi/UndertowContextFactory.java
===================================================================
--- projects/jaxws-undertow-httpspi/trunk/src/main/java/org/jboss/ws/undertow_httpspi/UndertowContextFactory.java	                        (rev 0)
+++ projects/jaxws-undertow-httpspi/trunk/src/main/java/org/jboss/ws/undertow_httpspi/UndertowContextFactory.java	2014-01-15 06:23:18 UTC (rev 18238)
@@ -0,0 +1,39 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ws.undertow_httpspi;
+
+import javax.xml.ws.spi.http.HttpContext;
+
+/**
+ * A factory for building httpcontext based on undertow 
+ * 
+ * @author alessio.soldano at jboss.com
+ * @since 22-Aug-2010
+ *
+ */
+public class UndertowContextFactory
+{  
+   public static HttpContext createHttpContext(UndertowServer server, String contextPath, String path)
+   {
+     return new UndertowHttpContext(server.getPathHandler(), contextPath, path); 
+   }
+}


Property changes on: projects/jaxws-undertow-httpspi/trunk/src/main/java/org/jboss/ws/undertow_httpspi/UndertowContextFactory.java
___________________________________________________________________
Added: svn:keywords
   + Rev Date
Added: svn:eol-style
   + native

Added: projects/jaxws-undertow-httpspi/trunk/src/main/java/org/jboss/ws/undertow_httpspi/UndertowHeaderMap.java
===================================================================
--- projects/jaxws-undertow-httpspi/trunk/src/main/java/org/jboss/ws/undertow_httpspi/UndertowHeaderMap.java	                        (rev 0)
+++ projects/jaxws-undertow-httpspi/trunk/src/main/java/org/jboss/ws/undertow_httpspi/UndertowHeaderMap.java	2014-01-15 06:23:18 UTC (rev 18238)
@@ -0,0 +1,208 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2014, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ws.undertow_httpspi;
+
+import io.undertow.util.HeaderMap;
+import io.undertow.util.HeaderValues;
+import io.undertow.util.HttpString;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+
+
+public class UndertowHeaderMap implements Map<String, List<String>>
+{
+
+   private HeaderMap headerMap;
+
+   public UndertowHeaderMap(HeaderMap headerMap) {
+      this.headerMap = headerMap;
+   }
+
+   @Override
+   public int size()
+   {
+      return headerMap.size();
+   }
+
+   @Override
+   public boolean isEmpty()
+   {
+      return headerMap.size() > 0;
+   }
+
+   @Override
+   public boolean containsKey(Object key)
+   {
+      return headerMap.contains(key.toString());
+   }
+
+   @Override
+   public boolean containsValue(Object value)
+   {
+      Iterator<HeaderValues> ite = headerMap.iterator();
+      while (ite.hasNext())
+      {
+         HeaderValues values = ite.next();
+         if (values.contains(value))
+         {
+            return true;
+         }
+      }
+      return false;
+   }
+
+   @Override
+   public List<String> get(Object key)
+   {
+      HeaderValues values = headerMap.get(key.toString());
+      List<String> result = new ArrayList<String>();
+      if (values != null)
+      {
+         for (String value : values.toArray())
+         {
+            result.add(value);
+         }
+      }
+      return result;
+   }
+
+   @Override
+   public List<String> put(String key, List<String> value)
+   {
+      List<String> previous = get(key);
+      if (previous.isEmpty())
+      {
+         previous = null;
+      }
+      headerMap.addAll(new HttpString(key), value);
+      return previous;
+
+   }
+
+   @Override
+   public List<String> remove(Object key)
+   {
+      List<String> previous = get(key);
+      if (previous.isEmpty())
+      {
+         previous = null;
+      }
+      headerMap.remove(key.toString());
+      return previous;
+   }
+
+   @Override
+   public void putAll(Map<? extends String, ? extends List<String>> m)
+   {
+      for (String key : m.keySet())
+      {
+         headerMap.putAll(new HttpString(key), m.get(key));
+      }
+
+   }
+
+   @Override
+   public void clear()
+   {
+      headerMap.clear();
+
+   }
+
+   @Override
+   public Set<String> keySet()
+   {
+      Set<String> result = new HashSet<String>();
+      for (HeaderValues value : headerMap)
+      {
+         result.add(value.getHeaderName().toString());
+      }
+      return result;
+   }
+
+   @Override
+   public Collection<List<String>> values()
+   {
+      List<List<String>> collections = new ArrayList<List<String>>();
+      for (HeaderValues value : headerMap)
+      {
+         List<String> values = new ArrayList<String>();
+         for (String headerValue : value)
+         {
+            values.add(headerValue);
+         }
+         collections.add(values);
+      }
+      return collections;
+   }
+
+   @Override
+   public Set<java.util.Map.Entry<String, List<String>>> entrySet()
+   {
+      Set<java.util.Map.Entry<String, List<String>>> result = new HashSet<java.util.Map.Entry<String, List<String>>>();
+      for (HeaderValues headerValues : headerMap)
+      {
+         final String key = headerValues.getHeaderName().toString();
+         final List<String> headerValueList = new ArrayList<String>();
+         for (String value : headerValues)
+         {
+            headerValueList.add(value);
+         }
+         result.add(new Entry<String, List<String>>() {
+
+            @Override
+            public String getKey()
+            {
+               return key;
+            }
+
+            @Override
+            public List<String> getValue()
+            {
+               return headerValueList;
+            }
+
+            @Override
+            public List<String> setValue(List<String> value)
+            {
+               List<String> previous = headerMap.get(key);
+               if (previous.isEmpty())
+               {
+                  previous = null;
+               }
+               headerMap.addAll(new HttpString(key), value);
+
+               return previous;
+
+            }
+         });
+      }
+      return result;
+   }
+
+}


Property changes on: projects/jaxws-undertow-httpspi/trunk/src/main/java/org/jboss/ws/undertow_httpspi/UndertowHeaderMap.java
___________________________________________________________________
Added: svn:keywords
   + Rev Date
Added: svn:eol-style
   + native

Added: projects/jaxws-undertow-httpspi/trunk/src/main/java/org/jboss/ws/undertow_httpspi/UndertowHttpContext.java
===================================================================
--- projects/jaxws-undertow-httpspi/trunk/src/main/java/org/jboss/ws/undertow_httpspi/UndertowHttpContext.java	                        (rev 0)
+++ projects/jaxws-undertow-httpspi/trunk/src/main/java/org/jboss/ws/undertow_httpspi/UndertowHttpContext.java	2014-01-15 06:23:18 UTC (rev 18238)
@@ -0,0 +1,75 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2014, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ws.undertow_httpspi;
+
+import io.undertow.server.handlers.PathHandler;
+
+import java.util.Set;
+
+import javax.xml.ws.spi.http.HttpContext;
+import javax.xml.ws.spi.http.HttpHandler;
+
+/**
+ * @author <a href="mailto:ema at redhat.com">Jim Ma</a>
+ *
+ */
+//TODO:Look at HttpHandlerImpl - avoid to create duplicate UndertowHttpContext to publish endpoint
+public class UndertowHttpContext extends HttpContext
+{
+   private String handlerpath;
+   private PathHandler pathHandler;
+   private String path;
+
+   public UndertowHttpContext(PathHandler pathHandler, String contextPath, String path)
+   {
+      this.pathHandler = pathHandler;
+      this.path = path;
+      this.handlerpath = contextPath + path;
+   }
+
+   @Override
+   public void setHandler(HttpHandler handler)
+   {
+      pathHandler.addExactPath(handlerpath, new UndertowHttpHandler(handler));
+   }
+
+   @Override
+   public String getPath()
+   {
+      return this.path;
+   }
+
+   @Override
+   public Object getAttribute(String name)
+   {
+      // TODO 
+      return null;
+   }
+
+   @Override
+   public Set<String> getAttributeNames()
+   {
+      // TODO 
+      return null;
+   }
+
+}


Property changes on: projects/jaxws-undertow-httpspi/trunk/src/main/java/org/jboss/ws/undertow_httpspi/UndertowHttpContext.java
___________________________________________________________________
Added: svn:keywords
   + Rev Date
Added: svn:eol-style
   + native

Added: projects/jaxws-undertow-httpspi/trunk/src/main/java/org/jboss/ws/undertow_httpspi/UndertowHttpExchange.java
===================================================================
--- projects/jaxws-undertow-httpspi/trunk/src/main/java/org/jboss/ws/undertow_httpspi/UndertowHttpExchange.java	                        (rev 0)
+++ projects/jaxws-undertow-httpspi/trunk/src/main/java/org/jboss/ws/undertow_httpspi/UndertowHttpExchange.java	2014-01-15 06:23:18 UTC (rev 18238)
@@ -0,0 +1,209 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2014, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ws.undertow_httpspi;
+
+import io.undertow.server.HttpServerExchange;
+import io.undertow.server.handlers.PathHandler;
+import io.undertow.util.HeaderValues;
+import io.undertow.util.HttpString;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.InetSocketAddress;
+import java.security.Principal;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.xml.ws.spi.http.HttpContext;
+import javax.xml.ws.spi.http.HttpExchange;
+
+/**
+ * @author <a href="mailto:ema at redhat.com">Jim Ma</a>
+ *
+ */
+public class UndertowHttpExchange extends HttpExchange
+{
+   private HttpServerExchange undertowExchange;
+
+   private UndertowHttpContext context;
+
+   public UndertowHttpExchange(HttpServerExchange serverExchange)
+   {
+      undertowExchange = serverExchange;
+   }
+
+   @Override
+   public Map<String, List<String>> getRequestHeaders()
+   {
+      return new UndertowHeaderMap(undertowExchange.getRequestHeaders());
+   }
+
+   @Override
+   public String getRequestHeader(String name)
+   {
+      HeaderValues headerValues = undertowExchange.getRequestHeaders().get(name);
+      if (headerValues != null && headerValues.size() > 0)
+      {
+         String result = "";
+         for (String headerValue : headerValues)
+         {
+            result = result + headerValue;
+         }
+         return result;
+      }
+      return null;
+   }
+
+   @Override
+   public Map<String, List<String>> getResponseHeaders()
+   {
+      return new UndertowHeaderMap(undertowExchange.getResponseHeaders());
+   }
+
+   @Override
+   public void addResponseHeader(String name, String value)
+   {
+      undertowExchange.getResponseHeaders().add(new HttpString(name), value);
+
+   }
+
+   @Override
+   public String getRequestURI()
+   {
+      return undertowExchange.getRequestURI();
+   }
+
+   @Override
+   public String getContextPath()
+   {
+      return PathUtils.getContextPathFromRequest(undertowExchange.getRequestPath());
+   }
+
+   @Override
+   public String getRequestMethod()
+   {
+      return undertowExchange.getRequestMethod().toString();
+   }
+
+   @Override
+   public HttpContext getHttpContext()
+   {
+      if (context == null)
+      {
+         context = new UndertowHttpContext(new PathHandler(), PathUtils.getContextPathFromRequest(undertowExchange.getRequestPath()),
+               PathUtils.getPathFromRequest(undertowExchange.getRequestPath()));
+      }
+      return context;
+   }
+
+   @Override
+   public void close() throws IOException
+   {
+      undertowExchange.endExchange();
+   }
+
+   @Override
+   public InputStream getRequestBody() throws IOException
+   {
+      return undertowExchange.getInputStream();
+   }
+
+   @Override
+   public OutputStream getResponseBody() throws IOException
+   {
+      return undertowExchange.getOutputStream();
+   }
+
+   @Override
+   public void setStatus(int status)
+   {
+      undertowExchange.setResponseCode(status);
+
+   }
+
+   @Override
+   public InetSocketAddress getRemoteAddress()
+   {
+      return undertowExchange.getSourceAddress();
+   }
+
+   @Override
+   public InetSocketAddress getLocalAddress()
+   {
+      return undertowExchange.getDestinationAddress();
+   }
+
+   @Override
+   public String getProtocol()
+   {
+      return undertowExchange.getProtocol().toString();
+   }
+
+   @Override
+   public String getScheme()
+   {
+      return undertowExchange.getRequestScheme();
+   }
+
+   @Override
+   public String getPathInfo()
+   {
+      return undertowExchange.getRequestPath();
+   }
+
+   @Override
+   public String getQueryString()
+   {
+      return undertowExchange.getQueryString();
+   }
+
+   @Override
+   public Object getAttribute(String name)
+   {
+      // TODO
+      return null;
+   }
+
+   @Override
+   public Set<String> getAttributeNames()
+   {
+      // TODO 
+      return null;
+   }
+
+   @Override
+   public Principal getUserPrincipal()
+   {
+      //TODO
+      return null;
+   }
+
+   @Override
+   public boolean isUserInRole(String role)
+   {
+      //TODO
+      return false;
+   }
+
+}


Property changes on: projects/jaxws-undertow-httpspi/trunk/src/main/java/org/jboss/ws/undertow_httpspi/UndertowHttpExchange.java
___________________________________________________________________
Added: svn:keywords
   + Rev Date
Added: svn:eol-style
   + native

Added: projects/jaxws-undertow-httpspi/trunk/src/main/java/org/jboss/ws/undertow_httpspi/UndertowHttpHandler.java
===================================================================
--- projects/jaxws-undertow-httpspi/trunk/src/main/java/org/jboss/ws/undertow_httpspi/UndertowHttpHandler.java	                        (rev 0)
+++ projects/jaxws-undertow-httpspi/trunk/src/main/java/org/jboss/ws/undertow_httpspi/UndertowHttpHandler.java	2014-01-15 06:23:18 UTC (rev 18238)
@@ -0,0 +1,47 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2014, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ws.undertow_httpspi;
+
+import io.undertow.server.HttpHandler;
+import io.undertow.server.HttpServerExchange;
+
+/**
+ * @author <a href="mailto:ema at redhat.com">Jim Ma</a>
+ *
+ */
+public class UndertowHttpHandler implements HttpHandler
+{
+
+   private javax.xml.ws.spi.http.HttpHandler spihandler;
+
+   public UndertowHttpHandler(javax.xml.ws.spi.http.HttpHandler handler)
+   {
+      spihandler = handler;
+   }
+
+   @Override
+   public void handleRequest(HttpServerExchange exchange) throws Exception
+   {
+      spihandler.handle(new UndertowHttpExchange(exchange));
+   }
+
+}


Property changes on: projects/jaxws-undertow-httpspi/trunk/src/main/java/org/jboss/ws/undertow_httpspi/UndertowHttpHandler.java
___________________________________________________________________
Added: svn:keywords
   + Rev Date
Added: svn:eol-style
   + native

Added: projects/jaxws-undertow-httpspi/trunk/src/main/java/org/jboss/ws/undertow_httpspi/UndertowServer.java
===================================================================
--- projects/jaxws-undertow-httpspi/trunk/src/main/java/org/jboss/ws/undertow_httpspi/UndertowServer.java	                        (rev 0)
+++ projects/jaxws-undertow-httpspi/trunk/src/main/java/org/jboss/ws/undertow_httpspi/UndertowServer.java	2014-01-15 06:23:18 UTC (rev 18238)
@@ -0,0 +1,69 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2014, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ws.undertow_httpspi;
+
+import io.undertow.Undertow;
+import io.undertow.Undertow.Builder;
+import io.undertow.server.handlers.BlockingHandler;
+import io.undertow.server.handlers.PathHandler;
+
+/**
+ * @author <a href="mailto:ema at redhat.com">Jim Ma</a>
+ *
+ */
+public class UndertowServer
+{
+   private Builder builder;
+   private PathHandler pathHandler;
+   private Undertow undertow;
+
+   public UndertowServer(int port, String host)
+   {
+      builder = Undertow.builder().addListener(port, host);
+      pathHandler = new PathHandler();
+   }
+
+   public Builder getBuilder()
+   {
+      return builder;
+   }
+
+   public PathHandler getPathHandler()
+   {
+      return pathHandler;
+   }
+
+   public void start()
+   {
+      undertow = builder.setHandler(new BlockingHandler(pathHandler)).build();
+      undertow.start();
+   }
+
+   public void stop()
+   {
+      if (undertow != null)
+      {
+         undertow.stop();
+      }
+   }
+
+}


Property changes on: projects/jaxws-undertow-httpspi/trunk/src/main/java/org/jboss/ws/undertow_httpspi/UndertowServer.java
___________________________________________________________________
Added: svn:keywords
   + Rev Date
Added: svn:eol-style
   + native

Added: projects/jaxws-undertow-httpspi/trunk/src/test/java/org/jboss/ws/undertow_httpspi/DHRequest.java
===================================================================
--- projects/jaxws-undertow-httpspi/trunk/src/test/java/org/jboss/ws/undertow_httpspi/DHRequest.java	                        (rev 0)
+++ projects/jaxws-undertow-httpspi/trunk/src/test/java/org/jboss/ws/undertow_httpspi/DHRequest.java	2014-01-15 06:23:18 UTC (rev 18238)
@@ -0,0 +1,46 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.jboss.ws.undertow_httpspi;
+
+import javax.activation.DataHandler;
+import javax.xml.bind.annotation.XmlMimeType;
+import javax.xml.bind.annotation.XmlType;
+
+ at XmlType(name = "dataRequest", namespace = "http://org.apache.cxf/jaxws/endpoint/")
+public class DHRequest {
+
+    private DataHandler dataHandler;
+
+    public DHRequest() {
+    }
+
+    public DHRequest(DataHandler dataHandler) {
+        this.dataHandler = dataHandler;
+    }
+
+    @XmlMimeType("text/plain")
+    public DataHandler getDataHandler() {
+        return dataHandler;
+    }
+
+    public void setDataHandler(DataHandler dataHandler) {
+        this.dataHandler = dataHandler;
+    }
+
+}


Property changes on: projects/jaxws-undertow-httpspi/trunk/src/test/java/org/jboss/ws/undertow_httpspi/DHRequest.java
___________________________________________________________________
Added: svn:keywords
   + Rev Date
Added: svn:eol-style
   + native

Added: projects/jaxws-undertow-httpspi/trunk/src/test/java/org/jboss/ws/undertow_httpspi/DHResponse.java
===================================================================
--- projects/jaxws-undertow-httpspi/trunk/src/test/java/org/jboss/ws/undertow_httpspi/DHResponse.java	                        (rev 0)
+++ projects/jaxws-undertow-httpspi/trunk/src/test/java/org/jboss/ws/undertow_httpspi/DHResponse.java	2014-01-15 06:23:18 UTC (rev 18238)
@@ -0,0 +1,45 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.jboss.ws.undertow_httpspi;
+
+import javax.activation.DataHandler;
+import javax.xml.bind.annotation.XmlMimeType;
+import javax.xml.bind.annotation.XmlType;
+
+ at XmlType(name = "dataResponse", namespace = "http://org.apache.cxf/jaxws/endpoint/")
+public class DHResponse {
+
+    private DataHandler dataHandler;
+
+    public DHResponse() {
+    }
+
+    public DHResponse(DataHandler dataHandler) {
+        this.dataHandler = dataHandler;
+    }
+
+    @XmlMimeType("text/plain")
+    public DataHandler getDataHandler() {
+        return dataHandler;
+    }
+
+    public void setDataHandler(DataHandler dataHandler) {
+        this.dataHandler = dataHandler;
+    }
+}


Property changes on: projects/jaxws-undertow-httpspi/trunk/src/test/java/org/jboss/ws/undertow_httpspi/DHResponse.java
___________________________________________________________________
Added: svn:keywords
   + Rev Date
Added: svn:eol-style
   + native

Added: projects/jaxws-undertow-httpspi/trunk/src/test/java/org/jboss/ws/undertow_httpspi/EndpointAPITest.java
===================================================================
--- projects/jaxws-undertow-httpspi/trunk/src/test/java/org/jboss/ws/undertow_httpspi/EndpointAPITest.java	                        (rev 0)
+++ projects/jaxws-undertow-httpspi/trunk/src/test/java/org/jboss/ws/undertow_httpspi/EndpointAPITest.java	2014-01-15 06:23:18 UTC (rev 18238)
@@ -0,0 +1,232 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ws.undertow_httpspi;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.URL;
+
+import javax.activation.DataHandler;
+import javax.activation.DataSource;
+import javax.xml.namespace.QName;
+import javax.xml.ws.Endpoint;
+import javax.xml.ws.Service;
+import javax.xml.ws.soap.MTOMFeature;
+import javax.xml.ws.spi.http.HttpContext;
+
+import org.jboss.ws.undertow_httpspi.UndertowContextFactory;
+import org.jboss.ws.undertow_httpspi.UndertowServer;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * A JAXWS 2.2 Endoint.publish(HttpContext context) API test
+ * using the JDK6 httpsever as underlying http container
+ * 
+ * @author alessio.soldano at jboss.com
+ * @since 22-Aug-2010
+ *
+ */
+public class EndpointAPITest extends Assert
+{
+
+   private static int currentPort = 9876;
+
+   private UndertowServer server;
+
+   @Before
+   public void setUp() throws IOException
+   {
+      currentPort++;
+      server = new UndertowServer(currentPort, "localhost");
+   }
+
+   @After
+   public void tearDown()
+   {
+      server.stop();
+      server = null;
+   }
+
+   @Test
+   public void testSingleEndpoint() throws Exception
+   {
+
+      String contextPath = "/ctxt";
+      String path = "/echo";
+      String address = "http://localhost:" + currentPort + contextPath + path;
+
+      HttpContext context = UndertowContextFactory.createHttpContext(server, contextPath, path);
+
+      Endpoint endpoint = Endpoint.create(new EndpointBean());
+      endpoint.publish(context); // Use httpserver context for publishing
+
+      server.start();
+
+      invokeEndpoint(address);
+
+      endpoint.stop();
+   }
+
+   @Test
+   public void testMultiplePublishSameAddress() throws Exception
+   {
+      server.start();
+      String contextPath = "/ctxt";
+      String path = "/echo";
+      for (int i = 0; i < 3; i++)
+      {
+         HttpContext ctx = UndertowContextFactory.createHttpContext(server, contextPath, path);
+         String address = "http://localhost:" + currentPort + contextPath + path;
+
+         Endpoint endpoint = Endpoint.create(new EndpointBean());
+         endpoint.publish(ctx); // Use httpserver context for publishing
+
+         invokeEndpoint(address);
+
+         endpoint.stop();
+      }
+   }
+   
+   @Test
+   public void testMultipleEndpointsSameContext() throws Exception
+   {
+      server.start();
+      String contextPath = "/ctxt";
+      String path = "/echo";
+      int k = 3;
+      Endpoint[] endpoints = new Endpoint[k];
+      HttpContext[] contexts = new HttpContext[k];
+      String[] addresses = new String[k];
+      for (int i = 0; i < k; i++)
+      {
+         addresses[i] = "http://localhost:" + currentPort + contextPath + path + i;
+         contexts[i] = UndertowContextFactory.createHttpContext(server, contextPath, path + i);
+         endpoints[i] = Endpoint.create(new EndpointBean());
+         endpoints[i].publish(contexts[i]);
+      }
+      for (int i = 0; i < k; i++)
+      {
+         invokeEndpoint(addresses[i]);
+      }
+      for (int i = 0; i < k; i++)
+      {
+         endpoints[i].stop();
+      }
+   }
+
+   @Test
+   public void testMultipleEndpointsDifferentContexts() throws Exception
+   {
+      server.start();
+      String contextPath = "/ctxt";
+      String path = "/echo";
+      int k = 3;
+      Endpoint[] endpoints = new Endpoint[k];
+      HttpContext[] contexts = new HttpContext[k];
+      String[] addresses = new String[k];
+      for (int i = 0; i < k; i++)
+      {
+         addresses[i] = "http://localhost:" + currentPort + contextPath + i + path;
+         contexts[i] = UndertowContextFactory.createHttpContext(server, contextPath + i, path);
+         endpoints[i] = Endpoint.create(new EndpointBean());
+         endpoints[i].publish(contexts[i]);
+      }
+      for (int i = 0; i < k; i++)
+      {
+         invokeEndpoint(addresses[i]);
+      }
+      for (int i = 0; i < k; i++)
+      {
+         endpoints[i].stop();
+      }
+   }
+
+   private void invokeEndpoint(String publishURL) throws Exception
+   {
+      URL wsdlURL = new URL(publishURL + "?wsdl");
+      QName qname = new QName("http://org.apache.cxf/jaxws/endpoint/", "EndpointService");
+      Service service = Service.create(wsdlURL, qname);
+      checkBasicInvocations(service);
+      checkMTOMInvocation(service);
+   }
+
+   private static void checkBasicInvocations(Service service)
+   {
+      EndpointInterface port = (EndpointInterface) service.getPort(EndpointInterface.class);
+      String helloWorld = "Hello world!";
+      assertEquals(0, port.getCount());
+      Object retObj = port.echo(helloWorld);
+      assertEquals(helloWorld, retObj);
+      assertEquals(1, port.getCount());
+      port.echo(helloWorld);
+      assertEquals(2, port.getCount());
+      try
+      {
+         port.getException();
+         fail("Exception expected!");
+      }
+      catch (Exception e)
+      {
+         assertEquals("Ooops", e.getMessage());
+      }
+   }
+
+   private static void checkMTOMInvocation(Service service) throws IOException
+   {
+      DataSource ds = new DataSource()
+      {
+         public String getContentType()
+         {
+            return "text/plain";
+         }
+
+         public InputStream getInputStream() throws IOException
+         {
+            return new ByteArrayInputStream("some string".getBytes());
+         }
+
+         public String getName()
+         {
+            return "none";
+         }
+
+         public OutputStream getOutputStream() throws IOException
+         {
+            return null;
+         }
+      };
+      EndpointInterface port = (EndpointInterface) service.getPort(EndpointInterface.class, new MTOMFeature(true));
+      DataHandler dh = new DataHandler(ds);
+      DHResponse response = port.echoDataHandler(new DHRequest(dh));
+      assertNotNull(response);
+      Object content = response.getDataHandler().getContent();
+      assertEquals("Server data", content);
+      String contentType = response.getDataHandler().getContentType();
+      assertEquals("text/plain", contentType);
+   }
+
+}


Property changes on: projects/jaxws-undertow-httpspi/trunk/src/test/java/org/jboss/ws/undertow_httpspi/EndpointAPITest.java
___________________________________________________________________
Added: svn:keywords
   + Rev Date
Added: svn:eol-style
   + native

Added: projects/jaxws-undertow-httpspi/trunk/src/test/java/org/jboss/ws/undertow_httpspi/EndpointBean.java
===================================================================
--- projects/jaxws-undertow-httpspi/trunk/src/test/java/org/jboss/ws/undertow_httpspi/EndpointBean.java	                        (rev 0)
+++ projects/jaxws-undertow-httpspi/trunk/src/test/java/org/jboss/ws/undertow_httpspi/EndpointBean.java	2014-01-15 06:23:18 UTC (rev 18238)
@@ -0,0 +1,89 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.jboss.ws.undertow_httpspi;
+
+import java.io.IOException;
+
+import javax.activation.DataHandler;
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
+import javax.jws.WebService;
+import javax.xml.ws.WebServiceException;
+import javax.xml.ws.soap.MTOM;
+
+ at WebService(serviceName = "EndpointService",
+            endpointInterface = "org.jboss.ws.undertow_httpspi.EndpointInterface",
+            targetNamespace = "http://org.apache.cxf/jaxws/endpoint/")
+ at MTOM
+public class EndpointBean implements EndpointInterface {
+
+    private int count;
+    private boolean initialized;
+
+    public String echo(String input) {
+        count++;
+        return input;
+    }
+
+    @PostConstruct
+    public void init() {
+        this.initialized = true;
+    }
+
+    @PreDestroy
+    public void destroy() {
+        // nothing to do
+    }
+
+    public int getCount() {
+        this.ensureInit();
+        return count;
+    }
+
+    public void getException() {
+        this.ensureInit();
+        throw new WebServiceException("Ooops");
+    }
+
+    public DHResponse echoDataHandler(DHRequest request) {
+        this.ensureInit();
+        DataHandler dataHandler = request.getDataHandler();
+
+        try {
+            if (!dataHandler.getContentType().equals("text/plain")) {
+                throw new WebServiceException("Wrong content type");
+            }
+            if (!dataHandler.getContent().equals("some string")) {
+                throw new WebServiceException("Wrong data");
+            }
+        } catch (IOException e) {
+            throw new WebServiceException(e);
+        }
+
+        DataHandler responseData = new DataHandler("Server data", "text/plain");
+        return new DHResponse(responseData);
+    }
+
+    private void ensureInit() {
+        if (!this.initialized) {
+            throw new IllegalStateException();
+        }
+    }
+
+}


Property changes on: projects/jaxws-undertow-httpspi/trunk/src/test/java/org/jboss/ws/undertow_httpspi/EndpointBean.java
___________________________________________________________________
Added: svn:keywords
   + Rev Date
Added: svn:eol-style
   + native

Added: projects/jaxws-undertow-httpspi/trunk/src/test/java/org/jboss/ws/undertow_httpspi/EndpointInterface.java
===================================================================
--- projects/jaxws-undertow-httpspi/trunk/src/test/java/org/jboss/ws/undertow_httpspi/EndpointInterface.java	                        (rev 0)
+++ projects/jaxws-undertow-httpspi/trunk/src/test/java/org/jboss/ws/undertow_httpspi/EndpointInterface.java	2014-01-15 06:23:18 UTC (rev 18238)
@@ -0,0 +1,36 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.jboss.ws.undertow_httpspi;
+
+import javax.jws.WebService;
+import javax.jws.soap.SOAPBinding;
+
+ at WebService(targetNamespace = "http://org.apache.cxf/jaxws/endpoint/")
+ at SOAPBinding(style = SOAPBinding.Style.RPC)
+public interface EndpointInterface {
+
+    String echo(String input);
+
+    int getCount();
+
+    void getException();
+
+    DHResponse echoDataHandler(DHRequest request);
+
+}


Property changes on: projects/jaxws-undertow-httpspi/trunk/src/test/java/org/jboss/ws/undertow_httpspi/EndpointInterface.java
___________________________________________________________________
Added: svn:keywords
   + Rev Date
Added: svn:eol-style
   + native

Added: projects/jaxws-undertow-httpspi/trunk/src/test/java/org/jboss/ws/undertow_httpspi/PathUtilsTest.java
===================================================================
--- projects/jaxws-undertow-httpspi/trunk/src/test/java/org/jboss/ws/undertow_httpspi/PathUtilsTest.java	                        (rev 0)
+++ projects/jaxws-undertow-httpspi/trunk/src/test/java/org/jboss/ws/undertow_httpspi/PathUtilsTest.java	2014-01-15 06:23:18 UTC (rev 18238)
@@ -0,0 +1,88 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ws.undertow_httpspi;
+
+import java.net.URI;
+
+import org.jboss.ws.undertow_httpspi.PathUtils;
+
+import junit.framework.TestCase;
+
+public class PathUtilsTest extends TestCase
+{
+   public void testPath() {
+      assertEquals("", PathUtils.getPath("http://localhost:8080"));
+      assertEquals("", PathUtils.getPath("http://localhost:8080/foo"));
+      assertEquals("", PathUtils.getPath("http://localhost:8080/foo/"));
+      assertEquals("/bar", PathUtils.getPath("http://localhost:8080/foo/bar"));
+      assertEquals("/bar", PathUtils.getPath("http://localhost:8080/foo/bar/"));
+      assertEquals("/bar", PathUtils.getPath("http://localhost:8080/foo/bar?wsdl"));
+      assertEquals("/bar", PathUtils.getPath("http://localhost:8080/foo/bar/?wsdl"));
+      assertEquals("/bar", PathUtils.getPath("http://localhost:8080/foo/fooagain/bar"));
+      assertEquals("/bar", PathUtils.getPath("http://localhost:8080/foo/fooagain/bar?wsdl"));
+      assertEquals("/bar", PathUtils.getPath("http://localhost:8080/foo/fooagain/bar?wsdl&xsd=ff"));
+      assertEquals("/bar", PathUtils.getPath("http://localhost/foo/bar"));
+      assertEquals("/bar", PathUtils.getPath("https://localhost/foo/bar"));
+      
+   }
+   
+   public void testContextPath() {
+      assertEquals("/", PathUtils.getContextPath("http://localhost:8080"));
+      assertEquals("/foo", PathUtils.getContextPath("http://localhost:8080/foo"));
+      assertEquals("/foo", PathUtils.getContextPath("http://localhost:8080/foo/"));
+      assertEquals("/foo", PathUtils.getContextPath("http://localhost:8080/foo/bar"));
+      assertEquals("/foo", PathUtils.getContextPath("http://localhost:8080/foo/bar/"));
+      assertEquals("/foo/bar", PathUtils.getContextPath("http://localhost:8080/foo/bar/baragain"));
+      assertEquals("/foo", PathUtils.getContextPath("http://localhost:8080/foo/bar?wsdl&xsd=kk"));
+      assertEquals("/foo", PathUtils.getContextPath("http://localhost:8080/foo/bar/?wsdl&xsd=kk"));
+      assertEquals("/foo", PathUtils.getContextPath("http://localhost/foo/bar"));
+      assertEquals("/foo", PathUtils.getContextPath("https://localhost/foo/bar"));
+   }
+   
+   public void testURIPath() throws Exception {
+      assertEquals("", PathUtils.getPath(new URI("http", "", "localhost", 8080, "", "", "")));
+      assertEquals("", PathUtils.getPath(new URI("http", "", "localhost", 8080, "/foo", "", "")));
+      assertEquals("", PathUtils.getPath(new URI("http", "", "localhost", 8080, "/foo/", "", "")));
+      assertEquals("/bar", PathUtils.getPath(new URI("http", "", "localhost", 8080, "/foo/bar", "", "")));
+      assertEquals("/bar", PathUtils.getPath(new URI("http", "", "localhost", 8080, "/foo/bar/", "", "")));
+      assertEquals("/bar", PathUtils.getPath(new URI("http", "", "localhost", 8080, "/foo/bar", "wsdl", "")));
+      assertEquals("/bar", PathUtils.getPath(new URI("http", "", "localhost", 8080, "/foo/bar/", "wsdl", "")));
+      assertEquals("/bar", PathUtils.getPath(new URI("http", "", "localhost", 8080, "/foo/fooagain/bar", "", "")));
+      assertEquals("/bar", PathUtils.getPath(new URI("http", "", "localhost", 8080, "/foo/fooagain/bar", "wsdl", "")));
+      assertEquals("/bar", PathUtils.getPath(new URI("http", "", "localhost", 8080, "/foo/fooagain/bar", "wsdl&xsd=ff", "")));
+      assertEquals("/bar", PathUtils.getPath(new URI("http", "", "localhost", 0, "/foo/bar", "", "")));
+      assertEquals("/bar", PathUtils.getPath(new URI("https", "", "localhost", 0, "/foo/bar", "", "")));
+   }
+   
+   public void testURIContextPath() throws Exception {
+      assertEquals("/", PathUtils.getContextPath(new URI("http", "", "localhost", 8080, "", "", "")));
+      assertEquals("/foo", PathUtils.getContextPath(new URI("http", "", "localhost", 8080, "/foo", "", "")));
+      assertEquals("/foo", PathUtils.getContextPath(new URI("http", "", "localhost", 8080, "/foo/", "", "")));
+      assertEquals("/foo", PathUtils.getContextPath(new URI("http", "", "localhost", 8080, "/foo/bar", "", "")));
+      assertEquals("/foo", PathUtils.getContextPath(new URI("http", "", "localhost", 8080, "/foo/bar/", "", "")));
+      assertEquals("/foo/bar", PathUtils.getContextPath(new URI("http", "", "localhost", 8080, "/foo/bar/baragain", "", "")));
+      assertEquals("/foo", PathUtils.getContextPath(new URI("http", "", "localhost", 8080, "/foo/bar", "wsdl&xsd=kk", "")));
+      assertEquals("/foo", PathUtils.getContextPath(new URI("http", "", "localhost", 8080, "/foo/bar/", "wsdl&xsd=kk", "")));
+      assertEquals("/foo", PathUtils.getContextPath(new URI("http", "", "localhost", 0, "/foo/bar", "", "")));
+      assertEquals("/foo", PathUtils.getContextPath(new URI("https", "", "localhost", 0, "/foo/bar", "", "")));
+   }
+}


Property changes on: projects/jaxws-undertow-httpspi/trunk/src/test/java/org/jboss/ws/undertow_httpspi/PathUtilsTest.java
___________________________________________________________________
Added: svn:keywords
   + Rev Date
Added: svn:eol-style
   + native



More information about the jbossws-commits mailing list