Author: richard.opalka(a)jboss.com
Date: 2010-10-15 09:04:27 -0400 (Fri, 15 Oct 2010)
New Revision: 13139
Added:
stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/serviceref/CXFHandlerResolverImpl.java
stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/serviceref/CXFServiceRefStubPropertyConfigurer.java
Removed:
stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/HandlerResolverImpl.java
stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/serviceref/ServiceRefStubPropertyConfigurer.java
Modified:
stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/serviceref/CXFServiceObjectFactoryJAXWS.java
stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/serviceref/CXFServiceRefBinderFactoryImpl.java
stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/serviceref/CXFServiceReferenceableJAXWS.java
Log:
refactoring
Deleted:
stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/HandlerResolverImpl.java
===================================================================
---
stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/HandlerResolverImpl.java 2010-10-15
12:47:32 UTC (rev 13138)
+++
stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/HandlerResolverImpl.java 2010-10-15
13:04:27 UTC (rev 13139)
@@ -1,378 +0,0 @@
-/**
- * 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.
- */
-
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2009, 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.wsf.stack.cxf.client;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.regex.Pattern;
-
-import javax.xml.bind.JAXBContext;
-import javax.xml.bind.JAXBException;
-import javax.xml.namespace.QName;
-import javax.xml.ws.WebServiceException;
-import javax.xml.ws.handler.Handler;
-import javax.xml.ws.handler.HandlerResolver;
-import javax.xml.ws.handler.LogicalHandler;
-import javax.xml.ws.handler.PortInfo;
-
-import org.apache.cxf.Bus;
-import org.apache.cxf.common.injection.ResourceInjector;
-import org.apache.cxf.helpers.XMLUtils;
-import org.apache.cxf.jaxws.handler.HandlerChainBuilder;
-import org.apache.cxf.jaxws.javaee.PortComponentHandlerType;
-import org.apache.cxf.resource.DefaultResourceManager;
-import org.apache.cxf.resource.ResourceManager;
-import org.apache.cxf.resource.ResourceResolver;
-import org.jboss.logging.Logger;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-
-/**
- * Handler resolver for CXF integration
- * @author richard.opalka(a)jboss.com
- */
-public final class HandlerResolverImpl extends HandlerChainBuilder implements
HandlerResolver
-{
-
- private static final Logger log = Logger.getLogger(HandlerResolverImpl.class);
- private final Map<PortInfo, List<Handler>> handlerMap = new
HashMap<PortInfo, List<Handler>>();
- private final String handlerFile;
- private static JAXBContext context;
- private final Class<?> clazz;
- private final ClassLoader classLoader;
- private final Bus bus;
-
- public HandlerResolverImpl(Bus bus, String handlerFile, Class<?> clazz)
- {
- super();
- this.handlerFile = handlerFile;
- this.clazz = clazz;
- this.classLoader = clazz.getClassLoader();
- this.bus = bus;
- }
-
- public List<Handler> getHandlerChain(PortInfo portInfo)
- {
- List<Handler> handlerChain = handlerMap.get(portInfo);
- if (handlerChain == null) {
- QName portQName = portInfo.getPortName();
- QName serviceQName = portInfo.getServiceName();
- String bindingId = portInfo.getBindingID();
- handlerChain = createHandlerChain(portInfo, portQName, serviceQName,
bindingId);
- handlerMap.put(portInfo, handlerChain);
- }
-
- for (Handler h : handlerChain) {
- configHandler(h);
- }
-
- return handlerChain;
- }
-
- /**
- * JAX-WS section 9.3.1: The runtime MUST then carry out any injections
- * requested by the handler, typically via the javax .annotation.Resource
- * annotation. After all the injections have been carried out, including in
- * the case where no injections were requested, the runtime MUST invoke the
- * method carrying a javax.annotation .PostConstruct annotation, if present.
- */
- private void configHandler(Handler handler) {
- if (handler != null) {
- ResourceManager resourceManager = bus.getExtension(ResourceManager.class);
- List<ResourceResolver> resolvers =
resourceManager.getResourceResolvers();
- resourceManager = new DefaultResourceManager(resolvers);
-// resourceManager.addResourceResolver(new
WebContextEntriesResourceResolver());
- ResourceInjector injector = new ResourceInjector(resourceManager);
- injector.inject(handler);
- injector.construct(handler);
- }
- }
-
- private InputStream getInputStream()
- {
- return this.getInputStream(this.handlerFile, this.clazz);
- }
-
- public List<Handler> createHandlerChain(PortInfo portInfo, QName portQName,
QName serviceQName, String bindingID) {
- List<Handler> chain = new ArrayList<Handler>();
- InputStream is = getInputStream();
- try {
-
- if (is == null) {
- throw new WebServiceException("Handler config file not found: " +
handlerFile);
- }
-
- Document doc = XMLUtils.parse(is);
- Element el = doc.getDocumentElement();
- if (!"http://java.sun.com/xml/ns/javaee".equals(el.getNamespaceURI())
- || !"handler-chains".equals(el.getLocalName())) {
-
- String xml = XMLUtils.toString(el);
- throw new
WebServiceException("{http://java.sun.com/xml/ns/javaee}handler-chains element
expected");
- }
- chain = new ArrayList<Handler>();
- Node node = el.getFirstChild();
- while (node != null) {
- if (node instanceof Element) {
- el = (Element)node;
- if
(!el.getNamespaceURI().equals("http://java.sun.com/xml/ns/javaee")
- || !el.getLocalName().equals("handler-chain")) {
-
- String xml = XMLUtils.toString(el);
- throw new
WebServiceException("{http://java.sun.com/xml/ns/javaee}handler-chain element
expected");
- }
- processHandlerChainElement(el, chain, portQName, serviceQName,
bindingID);
- }
- node = node.getNextSibling();
- }
- } catch (WebServiceException e) {
- throw e;
- } catch (Exception e) {
- throw new WebServiceException("No handler chain found", e);
- }
- finally
- {
- if (is != null)
- {
- try { is.close(); } catch (IOException ioe) {};
- }
- }
- assert chain != null;
- return sortHandlers(chain);
- }
-
- private void processHandlerChainElement(Element el, List<Handler> chain,
- QName portQName, QName serviceQName, String bindingID) {
- Node node = el.getFirstChild();
- while (node != null) {
- Node cur = node;
- node = node.getNextSibling();
- if (cur instanceof Element) {
- el = (Element)cur;
- if
(!el.getNamespaceURI().equals("http://java.sun.com/xml/ns/javaee")) {
- String xml = XMLUtils.toString(el);
- throw new WebServiceException("Invalid element in handler: " +
xml);
- }
- String name = el.getLocalName();
- if ("port-name-pattern".equals(name)) {
- if (!patternMatches(el, portQName)) {
- return;
- }
- } else if ("service-name-pattern".equals(name)) {
- if (!patternMatches(el, serviceQName)) {
- return;
- }
- } else if ("protocol-bindings".equals(name)) {
- if (!protocolMatches(el, bindingID)) {
- return;
- }
- } else if ("handler".equals(name)) {
- processHandlerElement(el, chain);
- }
- }
- }
- }
- private boolean protocolMatches(Element el, String id) {
- if (id == null) {
- return true;
- }
- String name = el.getTextContent().trim();
- if ("##SOAP11_HTTP".equals(name)) {
- return "http://schemas.xmlsoap.org/wsdl/soap/http".contains(id)
- || "http://schemas.xmlsoap.org/soap/".contains(id);
- } else if ("##SOAP11_HTTP_MTOM".equals(name)) {
- return
"http://schemas.xmlsoap.org/wsdl/soap/http?mtom=true".contains(id)
- || "http://schemas.xmlsoap.org/soap/?mtom=true".contains(id);
- } else if ("##SOAP12_HTTP".equals(name)) {
- return "http://www.w3.org/2003/05/soap/bindings/HTTP/".contains(id)
- || "http://schemas.xmlsoap.org/wsdl/soap12/".contains(id);
- } else if ("##SOAP12_HTTP_MTOM".equals(name)) {
- return
"http://www.w3.org/2003/05/soap/bindings/HTTP/?mtom=true".contains(id)
- || "http://schemas.xmlsoap.org/wsdl/soap12/?mtom=true".contains(id);
- } else if ("##XML_HTTP".equals(name)) {
- name = "http://www.w3.org/2004/08/wsdl/http";
- }
- return name.contains(id);
- }
- private boolean patternMatches(Element el, QName comp) {
- if (comp == null) {
- return true;
- }
- String namePattern = el.getTextContent().trim();
- if ("*".equals(namePattern)) {
- return true;
- }
- if (!namePattern.contains(":")) {
- throw new WebServiceException("Not a qname pattern: " + namePattern);
- }
- String localPart = namePattern.substring(namePattern.indexOf(':') + 1,
- namePattern.length());
- String pfx = namePattern.substring(0, namePattern.indexOf(':'));
- String ns = el.lookupNamespaceURI(pfx);
- if (ns == null) {
- ns = pfx;
- }
- if (!ns.equals(comp.getNamespaceURI())) {
- return false;
- }
- if (localPart.contains("*")) {
- //wildcard pattern matching
- return Pattern.matches(localPart, comp.getLocalPart());
- } else if (!localPart.equals(comp.getLocalPart())) {
- return false;
- }
- return true;
- }
-
- public List<Handler> sortHandlers(List<Handler> handlers) {
-
- List<LogicalHandler> logicalHandlers = new
ArrayList<LogicalHandler>();
- List<Handler> protocolHandlers = new ArrayList<Handler>();
-
- for (Handler handler : handlers) {
- if (handler instanceof LogicalHandler) {
- logicalHandlers.add((LogicalHandler)handler);
- } else {
- protocolHandlers.add(handler);
- }
- }
-
- List<Handler> sortedHandlers = new ArrayList<Handler>();
- sortedHandlers.addAll(logicalHandlers);
- sortedHandlers.addAll(protocolHandlers);
- return sortedHandlers;
- }
-
- private InputStream getInputStream(String filename, Class<?> wsClass)
- {
- URL fileURL = null;
- log.debug("processHandlerChain [" + filename + "] on: " +
wsClass.getName());
-
- // Try the filename as URL
- try
- {
- fileURL = new URL(filename);
- }
- catch (MalformedURLException ex)
- {
- // ignore
- }
-
- // Try the filename as File
- if (fileURL == null)
- {
- try
- {
- File file = new File(filename);
- if (file.exists())
- fileURL = file.toURI().toURL();
- }
- catch (MalformedURLException e)
- {
- // ignore
- }
- }
-
- // Try the filename as Resource
- if (fileURL == null)
- {
- log.debug(wsClass.getProtectionDomain().getCodeSource());
- log.debug(wsClass.getClassLoader());
- fileURL = wsClass.getClassLoader().getResource(filename);
- }
-
- // Try the filename relative to class
- if (fileURL == null)
- {
- String filepath = filename;
- String packagePath = wsClass.getPackage().getName().replace('.',
'/');
- String resourcePath = packagePath + "/" + filepath;
- while (filepath.startsWith("../"))
- {
- packagePath = packagePath.substring(0,
packagePath.lastIndexOf("/"));
- filepath = filepath.substring(3);
- resourcePath = packagePath + "/" + filepath;
- }
- fileURL = wsClass.getClassLoader().getResource(resourcePath);
- }
-
- if (fileURL == null)
- throw new WebServiceException("Cannot resolve handler file '" +
filename + "' on " + wsClass.getName());
-
- try
- {
- return fileURL.openStream();
- }
- catch (IOException ioe)
- {
- throw new WebServiceException(ioe);
- }
- }
-
- private void processHandlerElement(Element el, List<Handler> chain) {
- try {
- JAXBContext ctx = getContextForPortComponentHandlerType();
- PortComponentHandlerType pt = ctx.createUnmarshaller()
- .unmarshal(el, PortComponentHandlerType.class).getValue();
- chain.addAll(buildHandlerChain(pt, classLoader));
- } catch (JAXBException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
-
- private static synchronized JAXBContext getContextForPortComponentHandlerType()
- throws JAXBException {
- if (context == null) {
- context = JAXBContext.newInstance(PortComponentHandlerType.class);
- }
- return context;
- }
-
-}
Added:
stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/serviceref/CXFHandlerResolverImpl.java
===================================================================
---
stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/serviceref/CXFHandlerResolverImpl.java
(rev 0)
+++
stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/serviceref/CXFHandlerResolverImpl.java 2010-10-15
13:04:27 UTC (rev 13139)
@@ -0,0 +1,376 @@
+/**
+ * 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.
+ */
+
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, 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.wsf.stack.cxf.client.serviceref;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.regex.Pattern;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
+import javax.xml.namespace.QName;
+import javax.xml.ws.WebServiceException;
+import javax.xml.ws.handler.Handler;
+import javax.xml.ws.handler.HandlerResolver;
+import javax.xml.ws.handler.LogicalHandler;
+import javax.xml.ws.handler.PortInfo;
+
+import org.apache.cxf.Bus;
+import org.apache.cxf.common.injection.ResourceInjector;
+import org.apache.cxf.helpers.XMLUtils;
+import org.apache.cxf.jaxws.handler.HandlerChainBuilder;
+import org.apache.cxf.jaxws.javaee.PortComponentHandlerType;
+import org.apache.cxf.resource.DefaultResourceManager;
+import org.apache.cxf.resource.ResourceManager;
+import org.apache.cxf.resource.ResourceResolver;
+import org.jboss.logging.Logger;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+/**
+ * Handler resolver for CXF integration
+ * @author richard.opalka(a)jboss.com
+ */
+final class CXFHandlerResolverImpl extends HandlerChainBuilder implements
HandlerResolver
+{
+
+ private static final Logger log = Logger.getLogger(CXFHandlerResolverImpl.class);
+ private final Map<PortInfo, List<Handler>> handlerMap = new
HashMap<PortInfo, List<Handler>>();
+ private final String handlerFile;
+ private static JAXBContext context;
+ private final Class<?> clazz;
+ private final ClassLoader classLoader;
+ private final Bus bus;
+
+ public CXFHandlerResolverImpl(Bus bus, String handlerFile, Class<?> clazz)
+ {
+ super();
+ this.handlerFile = handlerFile;
+ this.clazz = clazz;
+ this.classLoader = clazz.getClassLoader();
+ this.bus = bus;
+ }
+
+ public List<Handler> getHandlerChain(PortInfo portInfo)
+ {
+ List<Handler> handlerChain = handlerMap.get(portInfo);
+ if (handlerChain == null) {
+ QName portQName = portInfo.getPortName();
+ QName serviceQName = portInfo.getServiceName();
+ String bindingId = portInfo.getBindingID();
+ handlerChain = createHandlerChain(portInfo, portQName, serviceQName,
bindingId);
+ handlerMap.put(portInfo, handlerChain);
+ }
+
+ for (Handler h : handlerChain) {
+ configHandler(h);
+ }
+
+ return handlerChain;
+ }
+
+ /**
+ * JAX-WS section 9.3.1: The runtime MUST then carry out any injections
+ * requested by the handler, typically via the javax .annotation.Resource
+ * annotation. After all the injections have been carried out, including in
+ * the case where no injections were requested, the runtime MUST invoke the
+ * method carrying a javax.annotation .PostConstruct annotation, if present.
+ */
+ private void configHandler(Handler handler) {
+ if (handler != null) {
+ ResourceManager resourceManager = bus.getExtension(ResourceManager.class);
+ List<ResourceResolver> resolvers =
resourceManager.getResourceResolvers();
+ resourceManager = new DefaultResourceManager(resolvers);
+ ResourceInjector injector = new ResourceInjector(resourceManager);
+ injector.inject(handler);
+ injector.construct(handler);
+ }
+ }
+
+ private InputStream getInputStream()
+ {
+ return this.getInputStream(this.handlerFile, this.clazz);
+ }
+
+ public List<Handler> createHandlerChain(PortInfo portInfo, QName portQName,
QName serviceQName, String bindingID) {
+ List<Handler> chain = new ArrayList<Handler>();
+ InputStream is = getInputStream();
+ try {
+
+ if (is == null) {
+ throw new WebServiceException("Handler config file not found: " +
handlerFile);
+ }
+
+ Document doc = XMLUtils.parse(is);
+ Element el = doc.getDocumentElement();
+ if (!"http://java.sun.com/xml/ns/javaee".equals(el.getNamespaceURI())
+ || !"handler-chains".equals(el.getLocalName())) {
+
+ String xml = XMLUtils.toString(el);
+ throw new
WebServiceException("{http://java.sun.com/xml/ns/javaee}handler-chains element
expected");
+ }
+ chain = new ArrayList<Handler>();
+ Node node = el.getFirstChild();
+ while (node != null) {
+ if (node instanceof Element) {
+ el = (Element)node;
+ if
(!el.getNamespaceURI().equals("http://java.sun.com/xml/ns/javaee")
+ || !el.getLocalName().equals("handler-chain")) {
+
+ String xml = XMLUtils.toString(el);
+ throw new
WebServiceException("{http://java.sun.com/xml/ns/javaee}handler-chain element
expected");
+ }
+ processHandlerChainElement(el, chain, portQName, serviceQName,
bindingID);
+ }
+ node = node.getNextSibling();
+ }
+ } catch (WebServiceException e) {
+ throw e;
+ } catch (Exception e) {
+ throw new WebServiceException("No handler chain found", e);
+ }
+ finally
+ {
+ if (is != null)
+ {
+ try { is.close(); } catch (IOException ioe) {};
+ }
+ }
+ assert chain != null;
+ return sortHandlers(chain);
+ }
+
+ private void processHandlerChainElement(Element el, List<Handler> chain,
+ QName portQName, QName serviceQName, String bindingID) {
+ Node node = el.getFirstChild();
+ while (node != null) {
+ Node cur = node;
+ node = node.getNextSibling();
+ if (cur instanceof Element) {
+ el = (Element)cur;
+ if
(!el.getNamespaceURI().equals("http://java.sun.com/xml/ns/javaee")) {
+ String xml = XMLUtils.toString(el);
+ throw new WebServiceException("Invalid element in handler: " +
xml);
+ }
+ String name = el.getLocalName();
+ if ("port-name-pattern".equals(name)) {
+ if (!patternMatches(el, portQName)) {
+ return;
+ }
+ } else if ("service-name-pattern".equals(name)) {
+ if (!patternMatches(el, serviceQName)) {
+ return;
+ }
+ } else if ("protocol-bindings".equals(name)) {
+ if (!protocolMatches(el, bindingID)) {
+ return;
+ }
+ } else if ("handler".equals(name)) {
+ processHandlerElement(el, chain);
+ }
+ }
+ }
+ }
+ private boolean protocolMatches(Element el, String id) {
+ if (id == null) {
+ return true;
+ }
+ String name = el.getTextContent().trim();
+ if ("##SOAP11_HTTP".equals(name)) {
+ return "http://schemas.xmlsoap.org/wsdl/soap/http".contains(id)
+ || "http://schemas.xmlsoap.org/soap/".contains(id);
+ } else if ("##SOAP11_HTTP_MTOM".equals(name)) {
+ return
"http://schemas.xmlsoap.org/wsdl/soap/http?mtom=true".contains(id)
+ || "http://schemas.xmlsoap.org/soap/?mtom=true".contains(id);
+ } else if ("##SOAP12_HTTP".equals(name)) {
+ return "http://www.w3.org/2003/05/soap/bindings/HTTP/".contains(id)
+ || "http://schemas.xmlsoap.org/wsdl/soap12/".contains(id);
+ } else if ("##SOAP12_HTTP_MTOM".equals(name)) {
+ return
"http://www.w3.org/2003/05/soap/bindings/HTTP/?mtom=true".contains(id)
+ || "http://schemas.xmlsoap.org/wsdl/soap12/?mtom=true".contains(id);
+ } else if ("##XML_HTTP".equals(name)) {
+ name = "http://www.w3.org/2004/08/wsdl/http";
+ }
+ return name.contains(id);
+ }
+ private boolean patternMatches(Element el, QName comp) {
+ if (comp == null) {
+ return true;
+ }
+ String namePattern = el.getTextContent().trim();
+ if ("*".equals(namePattern)) {
+ return true;
+ }
+ if (!namePattern.contains(":")) {
+ throw new WebServiceException("Not a qname pattern: " + namePattern);
+ }
+ String localPart = namePattern.substring(namePattern.indexOf(':') + 1,
+ namePattern.length());
+ String pfx = namePattern.substring(0, namePattern.indexOf(':'));
+ String ns = el.lookupNamespaceURI(pfx);
+ if (ns == null) {
+ ns = pfx;
+ }
+ if (!ns.equals(comp.getNamespaceURI())) {
+ return false;
+ }
+ if (localPart.contains("*")) {
+ //wildcard pattern matching
+ return Pattern.matches(localPart, comp.getLocalPart());
+ } else if (!localPart.equals(comp.getLocalPart())) {
+ return false;
+ }
+ return true;
+ }
+
+ public List<Handler> sortHandlers(List<Handler> handlers) {
+
+ List<LogicalHandler> logicalHandlers = new
ArrayList<LogicalHandler>();
+ List<Handler> protocolHandlers = new ArrayList<Handler>();
+
+ for (Handler handler : handlers) {
+ if (handler instanceof LogicalHandler) {
+ logicalHandlers.add((LogicalHandler)handler);
+ } else {
+ protocolHandlers.add(handler);
+ }
+ }
+
+ List<Handler> sortedHandlers = new ArrayList<Handler>();
+ sortedHandlers.addAll(logicalHandlers);
+ sortedHandlers.addAll(protocolHandlers);
+ return sortedHandlers;
+ }
+
+ private InputStream getInputStream(String filename, Class<?> wsClass)
+ {
+ URL fileURL = null;
+ log.debug("processHandlerChain [" + filename + "] on: " +
wsClass.getName());
+
+ // Try the filename as URL
+ try
+ {
+ fileURL = new URL(filename);
+ }
+ catch (MalformedURLException ex)
+ {
+ // ignore
+ }
+
+ // Try the filename as File
+ if (fileURL == null)
+ {
+ try
+ {
+ File file = new File(filename);
+ if (file.exists())
+ fileURL = file.toURI().toURL();
+ }
+ catch (MalformedURLException e)
+ {
+ // ignore
+ }
+ }
+
+ // Try the filename as Resource
+ if (fileURL == null)
+ {
+ log.debug(wsClass.getProtectionDomain().getCodeSource());
+ log.debug(wsClass.getClassLoader());
+ fileURL = wsClass.getClassLoader().getResource(filename);
+ }
+
+ // Try the filename relative to class
+ if (fileURL == null)
+ {
+ String filepath = filename;
+ String packagePath = wsClass.getPackage().getName().replace('.',
'/');
+ String resourcePath = packagePath + "/" + filepath;
+ while (filepath.startsWith("../"))
+ {
+ packagePath = packagePath.substring(0,
packagePath.lastIndexOf("/"));
+ filepath = filepath.substring(3);
+ resourcePath = packagePath + "/" + filepath;
+ }
+ fileURL = wsClass.getClassLoader().getResource(resourcePath);
+ }
+
+ if (fileURL == null)
+ throw new WebServiceException("Cannot resolve handler file '" +
filename + "' on " + wsClass.getName());
+
+ try
+ {
+ return fileURL.openStream();
+ }
+ catch (IOException ioe)
+ {
+ throw new WebServiceException(ioe);
+ }
+ }
+
+ private void processHandlerElement(Element el, List<Handler> chain) {
+ try {
+ JAXBContext ctx = getContextForPortComponentHandlerType();
+ PortComponentHandlerType pt = ctx.createUnmarshaller()
+ .unmarshal(el, PortComponentHandlerType.class).getValue();
+ chain.addAll(buildHandlerChain(pt, classLoader));
+ } catch (JAXBException e) {
+ e.printStackTrace();
+ }
+ }
+
+ private static synchronized JAXBContext getContextForPortComponentHandlerType()
+ throws JAXBException {
+ if (context == null) {
+ context = JAXBContext.newInstance(PortComponentHandlerType.class);
+ }
+ return context;
+ }
+
+}
Modified:
stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/serviceref/CXFServiceObjectFactoryJAXWS.java
===================================================================
---
stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/serviceref/CXFServiceObjectFactoryJAXWS.java 2010-10-15
12:47:32 UTC (rev 13138)
+++
stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/serviceref/CXFServiceObjectFactoryJAXWS.java 2010-10-15
13:04:27 UTC (rev 13139)
@@ -55,7 +55,6 @@
import org.jboss.wsf.spi.deployment.UnifiedVirtualFile;
import org.jboss.wsf.spi.metadata.j2ee.serviceref.UnifiedPortComponentRefMetaData;
import org.jboss.wsf.spi.metadata.j2ee.serviceref.UnifiedServiceRefMetaData;
-import org.jboss.wsf.stack.cxf.client.HandlerResolverImpl;
import org.jboss.wsf.stack.cxf.client.configuration.JBossWSSpringBusFactory;
/**
@@ -116,7 +115,7 @@
final Service serviceInstance = this.instantiateService(serviceRef,
serviceClass);
if (serviceRef.getHandlerChain() != null)
{
- serviceInstance.setHandlerResolver(new HandlerResolverImpl(bus,
serviceRef.getHandlerChain(),
+ serviceInstance.setHandlerResolver(new CXFHandlerResolverImpl(bus,
serviceRef.getHandlerChain(),
serviceInstance.getClass()));
}
// construct port
@@ -172,7 +171,7 @@
//Add extension to configure stub properties using the UnifiedServiceRefMetaData
Configurer configurer = bus.getExtension(Configurer.class);
- bus.setExtension(new ServiceRefStubPropertyConfigurer(serviceRefMD, configurer),
Configurer.class);
+ bus.setExtension(new CXFServiceRefStubPropertyConfigurer(serviceRefMD, configurer),
Configurer.class);
return bus;
}
Modified:
stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/serviceref/CXFServiceRefBinderFactoryImpl.java
===================================================================
---
stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/serviceref/CXFServiceRefBinderFactoryImpl.java 2010-10-15
12:47:32 UTC (rev 13138)
+++
stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/serviceref/CXFServiceRefBinderFactoryImpl.java 2010-10-15
13:04:27 UTC (rev 13139)
@@ -26,7 +26,7 @@
import org.jboss.wsf.spi.serviceref.ServiceRefHandler.Type;
/**
- * Binds a JAXWS Service object in the client's ENC
+ * Binds either JAXRPC or JAXWS Service object in the client's ENC.
*
* @author Thomas.Diesler(a)jboss.com
* @author <a href="mailto:ropalka@redhat.com">Richard Opalka</a>
Added:
stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/serviceref/CXFServiceRefStubPropertyConfigurer.java
===================================================================
---
stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/serviceref/CXFServiceRefStubPropertyConfigurer.java
(rev 0)
+++
stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/serviceref/CXFServiceRefStubPropertyConfigurer.java 2010-10-15
13:04:27 UTC (rev 13139)
@@ -0,0 +1,127 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, 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.wsf.stack.cxf.client.serviceref;
+
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+import javax.xml.namespace.QName;
+import javax.xml.ws.WebServiceFeature;
+import javax.xml.ws.soap.MTOMFeature;
+
+import org.apache.cxf.configuration.Configurer;
+import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
+import org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean;
+import org.jboss.logging.Logger;
+import org.jboss.wsf.spi.metadata.j2ee.serviceref.UnifiedPortComponentRefMetaData;
+import org.jboss.wsf.spi.metadata.j2ee.serviceref.UnifiedServiceRefMetaData;
+import org.jboss.wsf.spi.metadata.j2ee.serviceref.UnifiedStubPropertyMetaData;
+
+/**
+ * A CXF configurer that sets the serviceref data in the JaxWsProxyFactoryBean
+ *
+ * @author alessio.soldano(a)jboss.com
+ * @since 21-Jul-2009
+ */
+final class CXFServiceRefStubPropertyConfigurer implements Configurer
+{
+ private UnifiedServiceRefMetaData serviceRefMD;
+ private Configurer delegate;
+
+ public CXFServiceRefStubPropertyConfigurer(UnifiedServiceRefMetaData serviceRefMD,
Configurer delegate)
+ {
+ this.serviceRefMD = serviceRefMD;
+ this.delegate = delegate;
+ }
+
+ public void configureBean(Object beanInstance)
+ {
+ if (delegate != null)
+ {
+ delegate.configureBean(beanInstance);
+ }
+ }
+
+ public void configureBean(String name, Object beanInstance)
+ {
+ if (name != null && beanInstance instanceof JaxWsProxyFactoryBean)
+ {
+ QName portQName = null;
+ try
+ {
+ String portName = name.substring(0,
name.indexOf(".jaxws-client.proxyFactory"));
+ portQName = QName.valueOf(portName);
+ }
+ catch (Exception e)
+ {
+ Logger.getLogger(this.getClass()).warn("Unable to retrieve port QName
from '" + name + "', trying matching port using endpoint interface name
only.");
+ }
+ configureJaxWsProxyFactoryBean(portQName, (JaxWsProxyFactoryBean)beanInstance);
+ }
+ if (delegate != null)
+ {
+ delegate.configureBean(name, beanInstance);
+ }
+ }
+
+ private synchronized void configureJaxWsProxyFactoryBean(QName portQName,
JaxWsProxyFactoryBean proxyFactory)
+ {
+ Class<?> clazz = proxyFactory.getServiceClass();
+ UnifiedPortComponentRefMetaData upcmd = serviceRefMD.getPortComponentRef(clazz !=
null ? clazz.getName() : null, portQName);
+ if (upcmd != null)
+ {
+ setProperties(proxyFactory, upcmd);
+ setMTOM((JaxWsServiceFactoryBean)proxyFactory.getServiceFactory(), upcmd);
+ }
+ }
+
+ private void setMTOM(JaxWsServiceFactoryBean serviceFactoryBean,
UnifiedPortComponentRefMetaData upcmd)
+ {
+ if (upcmd.isMtomEnabled())
+ {
+ List<WebServiceFeature> features = new
LinkedList<WebServiceFeature>();
+ List<WebServiceFeature> prevFeatures =
serviceFactoryBean.getWsFeatures();
+ if (prevFeatures != null)
+ {
+ features.addAll(prevFeatures);
+ }
+ features.add(new MTOMFeature(true));
+ serviceFactoryBean.setWsFeatures(features);
+ }
+ }
+
+ private void setProperties(JaxWsProxyFactoryBean proxyFactory,
UnifiedPortComponentRefMetaData upcmd)
+ {
+ Map<String, Object> properties = proxyFactory.getProperties();
+ if (properties == null)
+ {
+ properties = new HashMap<String, Object>();
+ proxyFactory.setProperties(properties);
+ }
+ for (UnifiedStubPropertyMetaData prop : upcmd.getStubProperties())
+ {
+ properties.put(prop.getPropName(), prop.getPropValue());
+ }
+ }
+}
Modified:
stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/serviceref/CXFServiceReferenceableJAXWS.java
===================================================================
---
stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/serviceref/CXFServiceReferenceableJAXWS.java 2010-10-15
12:47:32 UTC (rev 13138)
+++
stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/serviceref/CXFServiceReferenceableJAXWS.java 2010-10-15
13:04:27 UTC (rev 13139)
@@ -30,7 +30,7 @@
* @author Thomas.Diesler(a)jboss.org
* @author <a href="mailto:ropalka@redhat.com">Richard Opalka</a>
*/
-public class CXFServiceReferenceableJAXWS extends
AbstractServiceReferenceableJAXWS<CXFServiceObjectFactoryJAXWS>
+final class CXFServiceReferenceableJAXWS extends
AbstractServiceReferenceableJAXWS<CXFServiceObjectFactoryJAXWS>
{
public CXFServiceReferenceableJAXWS(final String serviceImplClass, final String
targetClassName,
final UnifiedServiceRefMetaData serviceRefUMDM)
Deleted:
stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/serviceref/ServiceRefStubPropertyConfigurer.java
===================================================================
---
stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/serviceref/ServiceRefStubPropertyConfigurer.java 2010-10-15
12:47:32 UTC (rev 13138)
+++
stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/serviceref/ServiceRefStubPropertyConfigurer.java 2010-10-15
13:04:27 UTC (rev 13139)
@@ -1,127 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2009, 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.wsf.stack.cxf.client.serviceref;
-
-import java.util.HashMap;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-
-import javax.xml.namespace.QName;
-import javax.xml.ws.WebServiceFeature;
-import javax.xml.ws.soap.MTOMFeature;
-
-import org.apache.cxf.configuration.Configurer;
-import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
-import org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean;
-import org.jboss.logging.Logger;
-import org.jboss.wsf.spi.metadata.j2ee.serviceref.UnifiedPortComponentRefMetaData;
-import org.jboss.wsf.spi.metadata.j2ee.serviceref.UnifiedServiceRefMetaData;
-import org.jboss.wsf.spi.metadata.j2ee.serviceref.UnifiedStubPropertyMetaData;
-
-/**
- * A CXF configurer that sets the serviceref data in the JaxWsProxyFactoryBean
- *
- * @author alessio.soldano(a)jboss.com
- * @since 21-Jul-2009
- */
-public class ServiceRefStubPropertyConfigurer implements Configurer
-{
- private UnifiedServiceRefMetaData serviceRefMD;
- private Configurer delegate;
-
- public ServiceRefStubPropertyConfigurer(UnifiedServiceRefMetaData serviceRefMD,
Configurer delegate)
- {
- this.serviceRefMD = serviceRefMD;
- this.delegate = delegate;
- }
-
- public void configureBean(Object beanInstance)
- {
- if (delegate != null)
- {
- delegate.configureBean(beanInstance);
- }
- }
-
- public void configureBean(String name, Object beanInstance)
- {
- if (name != null && beanInstance instanceof JaxWsProxyFactoryBean)
- {
- QName portQName = null;
- try
- {
- String portName = name.substring(0,
name.indexOf(".jaxws-client.proxyFactory"));
- portQName = QName.valueOf(portName);
- }
- catch (Exception e)
- {
- Logger.getLogger(this.getClass()).warn("Unable to retrieve port QName
from '" + name + "', trying matching port using endpoint interface name
only.");
- }
- configureJaxWsProxyFactoryBean(portQName, (JaxWsProxyFactoryBean)beanInstance);
- }
- if (delegate != null)
- {
- delegate.configureBean(name, beanInstance);
- }
- }
-
- private synchronized void configureJaxWsProxyFactoryBean(QName portQName,
JaxWsProxyFactoryBean proxyFactory)
- {
- Class<?> clazz = proxyFactory.getServiceClass();
- UnifiedPortComponentRefMetaData upcmd = serviceRefMD.getPortComponentRef(clazz !=
null ? clazz.getName() : null, portQName);
- if (upcmd != null)
- {
- setProperties(proxyFactory, upcmd);
- setMTOM((JaxWsServiceFactoryBean)proxyFactory.getServiceFactory(), upcmd);
- }
- }
-
- private void setMTOM(JaxWsServiceFactoryBean serviceFactoryBean,
UnifiedPortComponentRefMetaData upcmd)
- {
- if (upcmd.getEnableMTOM())
- {
- List<WebServiceFeature> features = new
LinkedList<WebServiceFeature>();
- List<WebServiceFeature> prevFeatures =
serviceFactoryBean.getWsFeatures();
- if (prevFeatures != null)
- {
- features.addAll(prevFeatures);
- }
- features.add(new MTOMFeature(true));
- serviceFactoryBean.setWsFeatures(features);
- }
- }
-
- private void setProperties(JaxWsProxyFactoryBean proxyFactory,
UnifiedPortComponentRefMetaData upcmd)
- {
- Map<String, Object> properties = proxyFactory.getProperties();
- if (properties == null)
- {
- properties = new HashMap<String, Object>();
- proxyFactory.setProperties(properties);
- }
- for (UnifiedStubPropertyMetaData prop : upcmd.getStubProperties())
- {
- properties.put(prop.getPropName(), prop.getPropValue());
- }
- }
-}