Author: alessio.soldano(a)jboss.com
Date: 2010-11-30 10:16:57 -0500 (Tue, 30 Nov 2010)
New Revision: 13366
Added:
spi/trunk/src/main/java/org/jboss/wsf/spi/metadata/AbstractHandlerChainsMetaDataParser.java
spi/trunk/src/main/java/org/jboss/wsf/spi/metadata/ParserConstants.java
spi/trunk/src/test/java/org/jboss/test/wsf/spi/metadata/webservices/
spi/trunk/src/test/java/org/jboss/test/wsf/spi/metadata/webservices/WebServiceFactoryTestCase.java
spi/trunk/src/test/resources/metadata/webservices/
spi/trunk/src/test/resources/metadata/webservices/test-webservices.xml
Removed:
spi/trunk/src/main/java/org/jboss/wsf/spi/metadata/j2ee/serviceref/HandlerChainsObjectFactory.java
Modified:
spi/trunk/src/main/java/org/jboss/wsf/spi/metadata/j2ee/serviceref/UnifiedHandlerChainsMetaDataParser.java
spi/trunk/src/main/java/org/jboss/wsf/spi/metadata/webservices/WebservicesFactory.java
spi/trunk/src/main/java/org/jboss/wsf/spi/metadata/webservices/WebservicesMetaData.java
spi/trunk/src/main/java/org/jboss/wsf/spi/util/StAXUtils.java
Log:
[JBWS-3169]
- Removing HandlerChainsObjectFactory (not used anymore)
- Initial StAX based parsing of webservices.xml (still cohexists with the XB code, WIP as
ASIL needs to be updated)
- WebservicesMetaData now builds to JSR109 v.1.2 by default instead of 1.1 (to avoid
supporting the 7yrs old NS for jsr 109 v.1.1)
- few additions to StAXUtils
Added:
spi/trunk/src/main/java/org/jboss/wsf/spi/metadata/AbstractHandlerChainsMetaDataParser.java
===================================================================
---
spi/trunk/src/main/java/org/jboss/wsf/spi/metadata/AbstractHandlerChainsMetaDataParser.java
(rev 0)
+++
spi/trunk/src/main/java/org/jboss/wsf/spi/metadata/AbstractHandlerChainsMetaDataParser.java 2010-11-30
15:16:57 UTC (rev 13366)
@@ -0,0 +1,199 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, 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.spi.metadata;
+
+import static org.jboss.wsf.spi.metadata.ParserConstants.*;
+import static org.jboss.wsf.spi.util.StAXUtils.elementAsQName;
+import static org.jboss.wsf.spi.util.StAXUtils.elementAsString;
+import static org.jboss.wsf.spi.util.StAXUtils.match;
+
+import org.jboss.wsf.spi.metadata.j2ee.serviceref.UnifiedHandlerChainMetaData;
+import org.jboss.wsf.spi.metadata.j2ee.serviceref.UnifiedHandlerChainsMetaData;
+import org.jboss.wsf.spi.metadata.j2ee.serviceref.UnifiedHandlerMetaData;
+import org.jboss.wsf.spi.metadata.j2ee.serviceref.UnifiedInitParamMetaData;
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+/**
+ * Basic handler-chains parser
+ *
+ * @author alessio.soldano(a)jboss.com
+ * @since 30-Nov-2010
+ */
+public abstract class AbstractHandlerChainsMetaDataParser
+{
+ protected UnifiedHandlerChainsMetaData parseHandlerChains(XMLStreamReader reader)
throws XMLStreamException
+ {
+ UnifiedHandlerChainsMetaData handlerChains = new UnifiedHandlerChainsMetaData();
+ while (reader.hasNext())
+ {
+ switch (reader.nextTag())
+ {
+ case XMLStreamConstants.END_ELEMENT : {
+ if (match(reader, QNAME_HANDLER_CHAINS))
+ {
+ return handlerChains;
+ }
+ else
+ {
+ throw new IllegalStateException("Unexpected end tag: " +
reader.getLocalName());
+ }
+ }
+ case XMLStreamConstants.START_ELEMENT : {
+ if (match(reader, QNAME_HANDLER_CHAIN)) {
+ handlerChains.addHandlerChain(parseHandlerChain(reader,
handlerChains));
+ }
+ else
+ {
+ throw new IllegalStateException("Unexpected element: " +
reader.getLocalName());
+ }
+ }
+ }
+ }
+ throw new IllegalStateException("Reached end of xml document
unexpectedly");
+ }
+
+ private UnifiedHandlerChainMetaData parseHandlerChain(XMLStreamReader reader,
UnifiedHandlerChainsMetaData handlerChains) throws XMLStreamException
+ {
+ UnifiedHandlerChainMetaData handlerChain = new
UnifiedHandlerChainMetaData(handlerChains);
+ while (reader.hasNext())
+ {
+ switch (reader.nextTag())
+ {
+ case XMLStreamConstants.END_ELEMENT : {
+ if (match(reader, QNAME_HANDLER_CHAIN))
+ {
+ return handlerChain;
+ }
+ else
+ {
+ throw new IllegalStateException("Unexpected end tag: " +
reader.getLocalName());
+ }
+ }
+ case XMLStreamConstants.START_ELEMENT : {
+ if (match(reader, QNAME_CHAIN_PORT_PATTERN))
+ {
+ handlerChain.setPortNamePattern(elementAsQName(reader));
+ }
+ else if (match(reader, QNAME_CHAIN_SERVICE_PATTERN))
+ {
+ handlerChain.setServiceNamePattern(elementAsQName(reader));
+ }
+ else if(match(reader, QNAME_CHAIN_PROTOCOL_BINDING))
+ {
+ handlerChain.setProtocolBindings(elementAsString(reader));
+ }
+ else if (match(reader, QNAME_HANDLER)) {
+ handlerChain.addHandler(parseHandler(reader, handlerChain));
+ }
+ else
+ {
+ throw new IllegalStateException("Unexpected element: " +
reader.getLocalName());
+ }
+ }
+ }
+ }
+ throw new IllegalStateException("Reached end of xml document
unexpectedly");
+ }
+
+ private UnifiedHandlerMetaData parseHandler(XMLStreamReader reader,
UnifiedHandlerChainMetaData handlerChain) throws XMLStreamException
+ {
+ UnifiedHandlerMetaData handler = new UnifiedHandlerMetaData(handlerChain);
+ while (reader.hasNext())
+ {
+ switch (reader.nextTag())
+ {
+ case XMLStreamConstants.END_ELEMENT : {
+ if (match(reader, QNAME_HANDLER))
+ {
+ return handler;
+ }
+ else
+ {
+ throw new IllegalStateException("Unexpected end tag: " +
reader.getLocalName());
+ }
+ }
+ case XMLStreamConstants.START_ELEMENT : {
+ if (match(reader, QNAME_HANDLER_NAME))
+ {
+ handler.setHandlerName(elementAsString(reader));
+ }
+ else if (match(reader, QNAME_HANDLER_CLASS))
+ {
+ handler.setHandlerClass(elementAsString(reader));
+ }
+ else if (match(reader, QNAME_HANDLER_PARAM)) {
+ handler.addInitParam(parseInitParam(reader));
+ }
+ else if (match(reader, QNAME_HANDLER_SOAP_ROLE)) {
+ handler.addSoapRole(elementAsString(reader));
+ }
+ else if (match(reader, QNAME_HANDLER_SOAP_HEADER)) {
+ handler.addSoapHeader(elementAsQName(reader));
+ }
+ else
+ {
+ throw new IllegalStateException("Unexpected element: " +
reader.getLocalName());
+ }
+ }
+ }
+ }
+ throw new IllegalStateException("Reached end of xml document
unexpectedly");
+ }
+
+ private UnifiedInitParamMetaData parseInitParam(XMLStreamReader reader) throws
XMLStreamException
+ {
+ UnifiedInitParamMetaData initParam = new UnifiedInitParamMetaData();
+ while (reader.hasNext())
+ {
+ switch (reader.nextTag())
+ {
+ case XMLStreamConstants.END_ELEMENT : {
+ if (match(reader, QNAME_HANDLER_PARAM))
+ {
+ return initParam;
+ }
+ else
+ {
+ throw new IllegalStateException("Unexpected end tag: " +
reader.getLocalName());
+ }
+ }
+ case XMLStreamConstants.START_ELEMENT : {
+ if (match(reader, QNAME_HANDLER_PARAM_NAME))
+ {
+ initParam.setParamName(elementAsString(reader));
+ }
+ else if (match(reader, QNAME_HANDLER_PARAM_VALUE))
+ {
+ initParam.setParamValue(elementAsString(reader));
+ }
+ else
+ {
+ throw new IllegalStateException("Unexpected element: " +
reader.getLocalName());
+ }
+ }
+ }
+ }
+ throw new IllegalStateException("Reached end of xml document
unexpectedly");
+ }
+}
Added: spi/trunk/src/main/java/org/jboss/wsf/spi/metadata/ParserConstants.java
===================================================================
--- spi/trunk/src/main/java/org/jboss/wsf/spi/metadata/ParserConstants.java
(rev 0)
+++ spi/trunk/src/main/java/org/jboss/wsf/spi/metadata/ParserConstants.java 2010-11-30
15:16:57 UTC (rev 13366)
@@ -0,0 +1,104 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, 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.spi.metadata;
+
+import javax.xml.namespace.QName;
+
+/**
+ * Constants for parsing descriptors
+ *
+ * @author alessio.soldano(a)jboss.com
+ * @since 30-Nov-2010
+ *
+ */
+public abstract class ParserConstants
+{
+ public static final String JAVAEE_NS = "http://java.sun.com/xml/ns/javaee";
+
+ public static final QName QNAME_CHAIN_PORT_PATTERN = new QName(JAVAEE_NS,
"port-name-pattern");
+
+ public static final QName QNAME_CHAIN_PROTOCOL_BINDING = new QName(JAVAEE_NS,
"protocol-bindings");
+
+ public static final QName QNAME_CHAIN_SERVICE_PATTERN = new QName(JAVAEE_NS,
"service-name-pattern");
+
+ public static final QName QNAME_HANDLER_CHAIN = new QName(JAVAEE_NS,
"handler-chain");
+
+ public static final QName QNAME_HANDLER_CHAINS = new QName(JAVAEE_NS,
"handler-chains");
+
+ public static final QName QNAME_HANDLER = new QName(JAVAEE_NS, "handler");
+
+ public static final QName QNAME_HANDLER_NAME = new QName(JAVAEE_NS,
"handler-name");
+
+ public static final QName QNAME_HANDLER_CLASS = new QName(JAVAEE_NS,
"handler-class");
+
+ public static final QName QNAME_HANDLER_SOAP_ROLE = new QName(JAVAEE_NS,
"soap-role");
+
+ public static final QName QNAME_HANDLER_SOAP_HEADER = new QName(JAVAEE_NS,
"soap-header");
+
+ public static final QName QNAME_HANDLER_PARAM = new QName(JAVAEE_NS,
"init-param");
+
+ public static final QName QNAME_HANDLER_PARAM_NAME = new QName(JAVAEE_NS,
"param-name");
+
+ public static final QName QNAME_HANDLER_PARAM_VALUE = new QName(JAVAEE_NS,
"param-value");
+
+ public static final QName QNAME_WEBSERVICES = new QName(JAVAEE_NS,
"webservices");
+
+ public static final QName QNAME_WEBSERVICE_DESCRIPTION = new QName(JAVAEE_NS,
"webservice-description");
+
+ public static final QName QNAME_WEBSERVICE_DESCRIPTION_NAME = new QName(JAVAEE_NS,
"webservice-description-name");
+
+ public static final QName QNAME_JAXRPC_MAPPING_FILE = new QName(JAVAEE_NS,
"jaxrpc-mapping-file");
+
+ public static final QName QNAME_WSDL_FILE = new QName(JAVAEE_NS,
"wsdl-file");
+
+ public static final QName QNAME_PORT_COMPONENT = new QName(JAVAEE_NS,
"port-component");
+
+ public static final QName QNAME_PORT_COMPONENT_NAME = new QName(JAVAEE_NS,
"port-component-name");
+
+ public static final QName QNAME_WSDL_SERVICE = new QName(JAVAEE_NS,
"wsdl-service");
+
+ public static final QName QNAME_WSDL_PORT = new QName(JAVAEE_NS,
"wsdl-port");
+
+ public static final QName QNAME_ENABLE_MTOM = new QName(JAVAEE_NS,
"enable-mtom");
+
+ public static final QName QNAME_MTOM_THRESHOLD = new QName(JAVAEE_NS,
"mtom-threshold");
+
+ public static final QName QNAME_ADDRESSING = new QName(JAVAEE_NS,
"addressing");
+
+ public static final QName QNAME_ADDRESSING_RESPONSES = new QName(JAVAEE_NS,
"responses");
+
+ public static final QName QNAME_RESPECT_BINDING = new QName(JAVAEE_NS,
"respect-binding");
+
+ public static final QName QNAME_PROTOCOL_BINDING = new QName(JAVAEE_NS,
"protocol-binding");
+
+ public static final QName QNAME_SERVICE_ENDPOINT_INTERFACE = new QName(JAVAEE_NS,
"service-endpoint-interface");
+
+ public static final QName QNAME_SERVICE_IMPL_BEAN = new QName(JAVAEE_NS,
"service-impl-bean");
+
+ public static final QName QNAME_EJB_LINK = new QName(JAVAEE_NS,
"ejb-link");
+
+ public static final QName QNAME_SERVLET_LINK = new QName(JAVAEE_NS,
"servlet-link");
+
+ public static final QName QNAME_ENABLED = new QName(JAVAEE_NS, "enabled");
+
+ public static final QName QNAME_REQUIRED = new QName(JAVAEE_NS,
"required");
+}
Deleted:
spi/trunk/src/main/java/org/jboss/wsf/spi/metadata/j2ee/serviceref/HandlerChainsObjectFactory.java
===================================================================
---
spi/trunk/src/main/java/org/jboss/wsf/spi/metadata/j2ee/serviceref/HandlerChainsObjectFactory.java 2010-11-30
08:25:28 UTC (rev 13365)
+++
spi/trunk/src/main/java/org/jboss/wsf/spi/metadata/j2ee/serviceref/HandlerChainsObjectFactory.java 2010-11-30
15:16:57 UTC (rev 13366)
@@ -1,168 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2006, 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.spi.metadata.j2ee.serviceref;
-
-import org.jboss.logging.Logger;
-import org.jboss.wsf.spi.metadata.j2ee.serviceref.UnifiedHandlerMetaData.HandlerType;
-import org.jboss.xb.binding.ObjectModelFactory;
-import org.jboss.xb.binding.UnmarshallingContext;
-import org.xml.sax.Attributes;
-
-/**
- * A JBossXB factory for jsr181 the HandlerChain annotation
- *
- * @author Thomas.Diesler(a)jboss.org
- * @since 15-Oct-2005
- */
-@Deprecated
-public class HandlerChainsObjectFactory implements ObjectModelFactory
-{
- // provide logging
- private static final Logger log = Logger.getLogger(HandlerChainsObjectFactory.class);
-
- public HandlerChainsObjectFactory()
- {
- }
-
- /**
- * This method is called on the factory by the object model builder when the parsing
starts.
- *
- * @return the root of the object model.
- */
- public Object newRoot(Object root, UnmarshallingContext navigator, String
namespaceURI, String localName, Attributes attrs)
- {
- UnifiedHandlerChainsMetaData handlerConfigMetaData = new
UnifiedHandlerChainsMetaData(HandlerType.ENDPOINT);
- return handlerConfigMetaData;
- }
-
- public Object completeRoot(Object root, UnmarshallingContext ctx, String uri, String
name)
- {
- return root;
- }
-
- /**
- * Called when parsing of a new element started.
- */
- public Object newChild(UnifiedHandlerChainsMetaData handlerConfig,
UnmarshallingContext navigator, String namespaceURI, String localName, Attributes attrs)
- {
- if ("handler-chain".equals(localName))
- return new UnifiedHandlerChainMetaData(handlerConfig);
- else return null;
- }
-
- /**
- * Called when parsing character is complete.
- */
- public void addChild(UnifiedHandlerChainsMetaData handlerConfig,
UnifiedHandlerChainMetaData handlerChain, UnmarshallingContext navigator, String
namespaceURI,
- String localName)
- {
- if (!handlerChain.isExcluded()) handlerConfig.addHandlerChain(handlerChain);
- }
-
- /**
- * Called when parsing of a new element started.
- */
- public Object newChild(UnifiedHandlerChainMetaData chainConfig, UnmarshallingContext
navigator, String namespaceURI, String localName, Attributes attrs)
- {
- if ("handler".equals(localName))
- return new UnifiedHandlerMetaData(chainConfig);
- else return null;
- }
-
- /**
- * Called when parsing character is complete.
- */
- public void addChild(UnifiedHandlerChainMetaData handlerConfig, UnifiedHandlerMetaData
handler, UnmarshallingContext navigator, String namespaceURI, String localName)
- {
- handlerConfig.addHandler(handler);
- }
-
- /**
- * Called when parsing of a new element started.
- */
- public Object newChild(UnifiedHandlerMetaData handler, UnmarshallingContext navigator,
String namespaceURI, String localName, Attributes attrs)
- {
- if ("init-param".equals(localName))
- return new UnifiedInitParamMetaData();
- else return null;
- }
-
- /**
- * Called when parsing character is complete.
- */
- public void addChild(UnifiedHandlerMetaData handler, UnifiedInitParamMetaData param,
UnmarshallingContext navigator, String namespaceURI, String localName)
- {
- handler.addInitParam(param);
- }
-
- /**
- * Called when a new simple child element with text value was read from the XML
content.
- */
- public void setValue(UnifiedHandlerChainMetaData handlerChain, UnmarshallingContext
navigator, String namespaceURI, String localName, String value)
- {
- if (log.isTraceEnabled())
- log.trace("UnifiedHandlerChainMetaData setValue: nuri=" + namespaceURI
+ " localName=" + localName + " value=" + value);
- try
- {
- if (localName.equals("protocol-bindings"))
- handlerChain.setProtocolBindings(value);
- else if (localName.equals("service-name-pattern"))
- handlerChain.setServiceNamePattern(navigator.resolveQName(value));
- else if (localName.equals("port-name-pattern"))
- handlerChain.setPortNamePattern(navigator.resolveQName(value));
- }
- catch (java.lang.IllegalStateException ex)
- {
- log.warn("Could not get " + localName + " value : "
- + ex.getMessage() + ", this handler chain will be ingored");
- handlerChain.setExcluded(true);
- }
- }
-
- /**
- * Called when a new simple child element with text value was read from the XML
content.
- */
- public void setValue(UnifiedHandlerMetaData handler, UnmarshallingContext navigator,
String namespaceURI, String localName, String value)
- {
- if (log.isTraceEnabled())
- log.trace("UnifiedHandlerMetaData setValue: nuri=" + namespaceURI +
" localName=" + localName + " value=" + value);
-
- if (localName.equals("handler-name"))
- handler.setHandlerName(value);
- else if (localName.equals("handler-class"))
- handler.setHandlerClass(value);
- }
-
- /**
- * Called when a new simple child element with text value was read from the XML
content.
- */
- public void setValue(UnifiedInitParamMetaData param, UnmarshallingContext navigator,
String namespaceURI, String localName, String value)
- {
- if (log.isTraceEnabled())
- log.trace("UnifiedInitParamMetaData setValue: nuri=" + namespaceURI +
" localName=" + localName + " value=" + value);
-
- if (localName.equals("param-name"))
- param.setParamName(value);
- else if (localName.equals("param-value"))
- param.setParamValue(value);
- }
-}
Modified:
spi/trunk/src/main/java/org/jboss/wsf/spi/metadata/j2ee/serviceref/UnifiedHandlerChainsMetaDataParser.java
===================================================================
---
spi/trunk/src/main/java/org/jboss/wsf/spi/metadata/j2ee/serviceref/UnifiedHandlerChainsMetaDataParser.java 2010-11-30
08:25:28 UTC (rev 13365)
+++
spi/trunk/src/main/java/org/jboss/wsf/spi/metadata/j2ee/serviceref/UnifiedHandlerChainsMetaDataParser.java 2010-11-30
15:16:57 UTC (rev 13366)
@@ -23,47 +23,36 @@
import static javax.xml.stream.XMLStreamConstants.END_ELEMENT;
import static javax.xml.stream.XMLStreamConstants.START_ELEMENT;
-import static org.jboss.wsf.spi.util.StAXUtils.createXMLStreamReader;
-import static org.jboss.wsf.spi.util.StAXUtils.elementAsQName;
-import static org.jboss.wsf.spi.util.StAXUtils.elementAsString;
+import static org.jboss.wsf.spi.metadata.ParserConstants.*;
import static org.jboss.wsf.spi.util.StAXUtils.match;
import java.io.IOException;
import java.io.InputStream;
-import javax.xml.namespace.QName;
-import javax.xml.stream.XMLStreamConstants;
+import org.jboss.wsf.spi.metadata.AbstractHandlerChainsMetaDataParser;
+import org.jboss.wsf.spi.util.StAXUtils;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
-/** The interface of the parser for the unified metadata handler chains element
+/**
+ * The parser for the unified metadata handler chains element
*
* @author alessio.soldano(a)jboss.com
* @since 26-Nov-2010
*/
-public class UnifiedHandlerChainsMetaDataParser
+public class UnifiedHandlerChainsMetaDataParser extends
AbstractHandlerChainsMetaDataParser
{
- private static final String JAVAEE_NS =
"http://java.sun.com/xml/ns/javaee";
- private static final QName QNAME_CHAIN_PORT_PATTERN = new QName(JAVAEE_NS,
"port-name-pattern");
- private static final QName QNAME_CHAIN_PROTOCOL_BINDING = new QName(JAVAEE_NS,
"protocol-bindings");
- private static final QName QNAME_CHAIN_SERVICE_PATTERN = new QName(JAVAEE_NS,
"service-name-pattern");
- private static final QName QNAME_HANDLER_CHAIN = new QName(JAVAEE_NS,
"handler-chain");
- private static final QName QNAME_HANDLER_CHAINS = new QName(JAVAEE_NS,
"handler-chains");
- private static final QName QNAME_HANDLER = new QName(JAVAEE_NS, "handler");
- private static final QName QNAME_HANDLER_NAME = new QName(JAVAEE_NS,
"handler-name");
- private static final QName QNAME_HANDLER_CLASS = new QName(JAVAEE_NS,
"handler-class");
- private static final QName QNAME_HANDLER_SOAP_ROLE = new QName(JAVAEE_NS,
"soap-role");
- private static final QName QNAME_HANDLER_SOAP_HEADER = new QName(JAVAEE_NS,
"soap-header");
- private static final QName QNAME_HANDLER_PARAM = new QName(JAVAEE_NS,
"init-param");
- private static final QName QNAME_HANDLER_PARAM_NAME = new QName(JAVAEE_NS,
"param-name");
- private static final QName QNAME_HANDLER_PARAM_VALUE = new QName(JAVAEE_NS,
"param-value");
-
+ private UnifiedHandlerChainsMetaDataParser()
+ {
+ super();
+ }
+
public static UnifiedHandlerChainsMetaData parse(InputStream is) throws IOException
{
//
http://java.sun.com/xml/ns/javaee/javaee_web_services_1_2.xsd
try
{
- XMLStreamReader xmlr = createXMLStreamReader(is);
+ XMLStreamReader xmlr = StAXUtils.createXMLStreamReader(is);
return parse(xmlr);
}
catch (XMLStreamException e)
@@ -95,7 +84,8 @@
if (match(reader, QNAME_HANDLER_CHAINS))
{
- handlerChains = parseHandlerChains(reader);
+ UnifiedHandlerChainsMetaDataParser parser = new
UnifiedHandlerChainsMetaDataParser();
+ handlerChains = parser.parseHandlerChains(reader);
}
else
{
@@ -105,159 +95,4 @@
}
return handlerChains;
}
-
- private static UnifiedHandlerChainsMetaData parseHandlerChains(XMLStreamReader reader)
throws XMLStreamException
- {
- UnifiedHandlerChainsMetaData handlerChains = new UnifiedHandlerChainsMetaData();
- while (reader.hasNext())
- {
- switch (reader.nextTag())
- {
- case XMLStreamConstants.END_ELEMENT : {
- if (match(reader, QNAME_HANDLER_CHAINS))
- {
- return handlerChains;
- }
- else
- {
- throw new IllegalStateException("Unexpected end tag: " +
reader.getLocalName());
- }
- }
- case XMLStreamConstants.START_ELEMENT : {
- if (match(reader, QNAME_HANDLER_CHAIN)) {
- handlerChains.addHandlerChain(parseHandlerChain(reader,
handlerChains));
- }
- else
- {
- throw new IllegalStateException("Unexpected element: " +
reader.getLocalName());
- }
- }
- }
- }
- throw new IllegalStateException("Reached end of xml document
unexpectedly");
- }
-
- private static UnifiedHandlerChainMetaData parseHandlerChain(XMLStreamReader reader,
UnifiedHandlerChainsMetaData handlerChains) throws XMLStreamException
- {
- UnifiedHandlerChainMetaData handlerChain = new
UnifiedHandlerChainMetaData(handlerChains);
- while (reader.hasNext())
- {
- switch (reader.nextTag())
- {
- case XMLStreamConstants.END_ELEMENT : {
- if (match(reader, QNAME_HANDLER_CHAIN))
- {
- return handlerChain;
- }
- else
- {
- throw new IllegalStateException("Unexpected end tag: " +
reader.getLocalName());
- }
- }
- case XMLStreamConstants.START_ELEMENT : {
- if (match(reader, QNAME_CHAIN_PORT_PATTERN))
- {
- handlerChain.setPortNamePattern(elementAsQName(reader));
- }
- else if (match(reader, QNAME_CHAIN_SERVICE_PATTERN))
- {
- handlerChain.setServiceNamePattern(elementAsQName(reader));
- }
- else if(match(reader, QNAME_CHAIN_PROTOCOL_BINDING))
- {
- handlerChain.setProtocolBindings(elementAsString(reader));
- }
- else if (match(reader, QNAME_HANDLER)) {
- handlerChain.addHandler(parseHandler(reader, handlerChain));
- }
- else
- {
- throw new IllegalStateException("Unexpected element: " +
reader.getLocalName());
- }
- }
- }
- }
- throw new IllegalStateException("Reached end of xml document
unexpectedly");
- }
-
- private static UnifiedHandlerMetaData parseHandler(XMLStreamReader reader,
UnifiedHandlerChainMetaData handlerChain) throws XMLStreamException
- {
- UnifiedHandlerMetaData handler = new UnifiedHandlerMetaData(handlerChain);
- while (reader.hasNext())
- {
- switch (reader.nextTag())
- {
- case XMLStreamConstants.END_ELEMENT : {
- if (match(reader, QNAME_HANDLER))
- {
- return handler;
- }
- else
- {
- throw new IllegalStateException("Unexpected end tag: " +
reader.getLocalName());
- }
- }
- case XMLStreamConstants.START_ELEMENT : {
- if (match(reader, QNAME_HANDLER_NAME))
- {
- handler.setHandlerName(elementAsString(reader));
- }
- else if (match(reader, QNAME_HANDLER_CLASS))
- {
- handler.setHandlerClass(elementAsString(reader));
- }
- else if (match(reader, QNAME_HANDLER_PARAM)) {
- handler.addInitParam(parseInitParam(reader));
- }
- else if (match(reader, QNAME_HANDLER_SOAP_ROLE)) {
- handler.addSoapRole(elementAsString(reader));
- }
- else if (match(reader, QNAME_HANDLER_SOAP_HEADER)) {
- handler.addSoapHeader(elementAsQName(reader));
- }
- else
- {
- throw new IllegalStateException("Unexpected element: " +
reader.getLocalName());
- }
- }
- }
- }
- throw new IllegalStateException("Reached end of xml document
unexpectedly");
- }
-
- private static UnifiedInitParamMetaData parseInitParam(XMLStreamReader reader) throws
XMLStreamException
- {
- UnifiedInitParamMetaData initParam = new UnifiedInitParamMetaData();
- while (reader.hasNext())
- {
- switch (reader.nextTag())
- {
- case XMLStreamConstants.END_ELEMENT : {
- if (match(reader, QNAME_HANDLER_PARAM))
- {
- return initParam;
- }
- else
- {
- throw new IllegalStateException("Unexpected end tag: " +
reader.getLocalName());
- }
- }
- case XMLStreamConstants.START_ELEMENT : {
- if (match(reader, QNAME_HANDLER_PARAM_NAME))
- {
- initParam.setParamName(elementAsString(reader));
- }
- else if (match(reader, QNAME_HANDLER_PARAM_VALUE))
- {
- initParam.setParamValue(elementAsString(reader));
- }
- else
- {
- throw new IllegalStateException("Unexpected element: " +
reader.getLocalName());
- }
- }
- }
- }
- throw new IllegalStateException("Reached end of xml document
unexpectedly");
- }
}
Modified:
spi/trunk/src/main/java/org/jboss/wsf/spi/metadata/webservices/WebservicesFactory.java
===================================================================
---
spi/trunk/src/main/java/org/jboss/wsf/spi/metadata/webservices/WebservicesFactory.java 2010-11-30
08:25:28 UTC (rev 13365)
+++
spi/trunk/src/main/java/org/jboss/wsf/spi/metadata/webservices/WebservicesFactory.java 2010-11-30
15:16:57 UTC (rev 13366)
@@ -21,21 +21,33 @@
*/
package org.jboss.wsf.spi.metadata.webservices;
+import static javax.xml.stream.XMLStreamConstants.END_ELEMENT;
+import static javax.xml.stream.XMLStreamConstants.START_ELEMENT;
+import static org.jboss.wsf.spi.metadata.ParserConstants.*;
+import static org.jboss.wsf.spi.util.StAXUtils.elementAsBoolean;
+import static org.jboss.wsf.spi.util.StAXUtils.elementAsInt;
+import static org.jboss.wsf.spi.util.StAXUtils.elementAsQName;
+import static org.jboss.wsf.spi.util.StAXUtils.elementAsString;
+import static org.jboss.wsf.spi.util.StAXUtils.match;
+
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
import javax.xml.ws.WebServiceException;
import org.jboss.logging.Logger;
import org.jboss.wsf.spi.deployment.UnifiedVirtualFile;
+import org.jboss.wsf.spi.metadata.AbstractHandlerChainsMetaDataParser;
import org.jboss.wsf.spi.metadata.j2ee.serviceref.UnifiedHandlerChainMetaData;
import org.jboss.wsf.spi.metadata.j2ee.serviceref.UnifiedHandlerChainsMetaData;
import org.jboss.wsf.spi.metadata.j2ee.serviceref.UnifiedHandlerMetaData;
import org.jboss.wsf.spi.metadata.j2ee.serviceref.UnifiedInitParamMetaData;
+import org.jboss.wsf.spi.util.StAXUtils;
import org.jboss.xb.binding.ObjectModelFactory;
-import org.jboss.xb.binding.Unmarshaller;
-import org.jboss.xb.binding.UnmarshallerFactory;
import org.jboss.xb.binding.UnmarshallingContext;
import org.xml.sax.Attributes;
@@ -45,7 +57,7 @@
* @author Thomas.Diesler(a)jboss.org
* @since 16-Apr-2004
*/
-public class WebservicesFactory implements ObjectModelFactory
+public class WebservicesFactory extends AbstractHandlerChainsMetaDataParser implements
ObjectModelFactory
{
// provide logging
private static final Logger log = Logger.getLogger(WebservicesFactory.class);
@@ -100,46 +112,322 @@
{
URL wsddUrl = wsdd.toURL();
+ InputStream is = null;
try
{
- webservices = load(wsddUrl);
+ is = wsddUrl.openStream();
+ XMLStreamReader xmlr = StAXUtils.createXMLStreamReader(is);
+ webservices = parse(xmlr, wsddUrl);
}
- catch (IOException e)
+ catch (Exception e)
{
- throw new WebServiceException("Failed to unmarshall
webservices.xml:" + e.getMessage());
+ throw new WebServiceException("Failed to unmarshall " + wsddUrl +
":" + e.getMessage());
}
+ finally
+ {
+ try
+ {
+ if (is != null) is.close();
+ }
+ catch (IOException e) {} //ignore
+ }
}
return webservices;
}
- /**
- * Load webservices.xml from <code>META-INF/webservices.xml</code>
- * or <code>WEB-INF/webservices.xml</code>.
- *
- * @param root virtual file root
- * @return WebservicesMetaData or <code>null</code> if it cannot be found
- */
- public static WebservicesMetaData load(URL wsddUrl) throws IOException
+ public static WebservicesMetaData parse(InputStream is)
{
- InputStream is = null;
+ return parse(is, null);
+ }
+
+ public static WebservicesMetaData parse(InputStream is, URL descriptorURL)
+ {
try
{
- is = wsddUrl.openStream();
- Unmarshaller unmarshaller =
UnmarshallerFactory.newInstance().newUnmarshaller();
- ObjectModelFactory factory = new WebservicesFactory(wsddUrl);
- return (WebservicesMetaData)unmarshaller.unmarshal(is, factory, null);
+ XMLStreamReader xmlr = StAXUtils.createXMLStreamReader(is);
+ return parse(xmlr, descriptorURL);
}
catch (Exception e)
{
- throw new WebServiceException("Failed to unmarshall " + wsddUrl +
":" + e.getMessage());
+ throw new WebServiceException(e);
}
- finally
+ }
+
+ public static WebservicesMetaData parse(XMLStreamReader reader) throws
XMLStreamException
+ {
+ return parse(reader, null);
+ }
+
+ private static WebservicesMetaData parse(XMLStreamReader reader, URL descriptorURL)
throws XMLStreamException
+ {
+ int iterate;
+ try
{
- if (is != null)
- is.close();
+ iterate = reader.nextTag();
}
+ catch (XMLStreamException e)
+ {
+ // skip non-tag elements
+ iterate = reader.nextTag();
+ }
+ WebservicesMetaData metadata = null;
+ switch (iterate)
+ {
+ case END_ELEMENT : {
+ // we're done
+ break;
+ }
+ case START_ELEMENT : {
+
+ if (match(reader, QNAME_WEBSERVICES))
+ {
+ WebservicesFactory factory = new WebservicesFactory(descriptorURL);
+ metadata = factory.parseWebservices(reader, descriptorURL);
+ }
+ else
+ {
+ throw new IllegalStateException("Unexpected element: " +
reader.getLocalName());
+ }
+ }
+ }
+ return metadata;
}
+
+ private WebservicesMetaData parseWebservices(XMLStreamReader reader, URL
descriptorURL) throws XMLStreamException
+ {
+ WebservicesMetaData metadata = new WebservicesMetaData(descriptorURL);
+ while (reader.hasNext())
+ {
+ switch (reader.nextTag())
+ {
+ case XMLStreamConstants.END_ELEMENT : {
+ if (match(reader, QNAME_WEBSERVICES))
+ {
+ return metadata;
+ }
+ else
+ {
+ throw new IllegalStateException("Unexpected end tag: " +
reader.getLocalName());
+ }
+ }
+ case XMLStreamConstants.START_ELEMENT : {
+ if (match(reader, QNAME_WEBSERVICE_DESCRIPTION)) {
+ metadata.addWebserviceDescription(parseWebserviceDescription(reader,
metadata));
+ }
+ else
+ {
+ throw new IllegalStateException("Unexpected element: " +
reader.getLocalName());
+ }
+ }
+ }
+ }
+ throw new IllegalStateException("Reached end of xml document
unexpectedly");
+ }
+
+ private WebserviceDescriptionMetaData parseWebserviceDescription(XMLStreamReader
reader, WebservicesMetaData wsMetaData) throws XMLStreamException
+ {
+ WebserviceDescriptionMetaData description = new
WebserviceDescriptionMetaData(wsMetaData);
+ while (reader.hasNext())
+ {
+ switch (reader.nextTag())
+ {
+ case XMLStreamConstants.END_ELEMENT : {
+ if (match(reader, QNAME_WEBSERVICE_DESCRIPTION))
+ {
+ return description;
+ }
+ else
+ {
+ throw new IllegalStateException("Unexpected end tag: " +
reader.getLocalName());
+ }
+ }
+ case XMLStreamConstants.START_ELEMENT : {
+ if (match(reader, QNAME_WEBSERVICE_DESCRIPTION_NAME)) {
+ description.setWebserviceDescriptionName(elementAsString(reader));
+ }
+ else if (match(reader, QNAME_WSDL_FILE)) {
+ description.setWsdlFile(elementAsString(reader));
+ }
+ else if (match(reader, QNAME_JAXRPC_MAPPING_FILE)) {
+ description.setJaxrpcMappingFile(elementAsString(reader));
+ }
+ else if (match(reader, QNAME_PORT_COMPONENT)) {
+ description.addPortComponent(parsePortComponent(reader, description));
+ }
+ else
+ {
+ throw new IllegalStateException("Unexpected element: " +
reader.getLocalName());
+ }
+ }
+ }
+ }
+ throw new IllegalStateException("Reached end of xml document
unexpectedly");
+ }
+
+ private PortComponentMetaData parsePortComponent(XMLStreamReader reader,
WebserviceDescriptionMetaData desc) throws XMLStreamException
+ {
+ PortComponentMetaData pc = new PortComponentMetaData(desc);
+ while (reader.hasNext())
+ {
+ switch (reader.nextTag())
+ {
+ case XMLStreamConstants.END_ELEMENT : {
+ if (match(reader, QNAME_PORT_COMPONENT))
+ {
+ return pc;
+ }
+ else
+ {
+ throw new IllegalStateException("Unexpected end tag: " +
reader.getLocalName());
+ }
+ }
+ case XMLStreamConstants.START_ELEMENT : {
+ if (match(reader, QNAME_PORT_COMPONENT_NAME)) {
+ pc.setPortComponentName(elementAsString(reader));
+ }
+ else if (match(reader, QNAME_WSDL_SERVICE)) {
+ pc.setWsdlService(elementAsQName(reader));
+ }
+ else if (match(reader, QNAME_WSDL_PORT)) {
+ pc.setWsdlPort(elementAsQName(reader));
+ }
+ else if (match(reader, QNAME_ENABLE_MTOM)) {
+ pc.setMtomEnabled(elementAsBoolean(reader));
+ }
+ else if (match(reader, QNAME_MTOM_THRESHOLD)) {
+ pc.setMtomThreshold(elementAsInt(reader));
+ }
+ else if (match(reader, QNAME_ADDRESSING)) {
+ parseAddressing(reader, pc);
+ }
+ else if (match(reader, QNAME_RESPECT_BINDING)) {
+ parseRespectBinding(reader, pc);
+ }
+ else if (match(reader, QNAME_PROTOCOL_BINDING)) {
+ pc.setProtocolBinding(elementAsString(reader));
+ }
+ else if (match(reader, QNAME_SERVICE_ENDPOINT_INTERFACE)) {
+ pc.setServiceEndpointInterface(elementAsString(reader));
+ }
+ else if (match(reader, QNAME_SERVICE_IMPL_BEAN)) {
+ parseServiceImplBean(reader, pc);
+ }
+ else if (match(reader, QNAME_HANDLER_CHAINS)) {
+ pc.setHandlerChains(parseHandlerChains(reader));
+ }
+ else
+ {
+ throw new IllegalStateException("Unexpected element: " +
reader.getLocalName());
+ }
+ }
+ }
+ }
+ throw new IllegalStateException("Reached end of xml document
unexpectedly");
+ }
+
+ private void parseAddressing(XMLStreamReader reader, PortComponentMetaData pc) throws
XMLStreamException
+ {
+ while (reader.hasNext())
+ {
+ switch (reader.nextTag())
+ {
+ case XMLStreamConstants.END_ELEMENT : {
+ if (match(reader, QNAME_ADDRESSING))
+ {
+ return;
+ }
+ else
+ {
+ throw new IllegalStateException("Unexpected end tag: " +
reader.getLocalName());
+ }
+ }
+ case XMLStreamConstants.START_ELEMENT : {
+ if (match(reader, QNAME_ENABLED)) {
+ pc.setAddressingEnabled(elementAsBoolean(reader));
+ }
+ else if (match(reader, QNAME_REQUIRED)) {
+ pc.setAddressingRequired(elementAsBoolean(reader));
+ }
+ else if (match(reader, QNAME_ADDRESSING_RESPONSES)) {
+ pc.setAddressingResponses(elementAsString(reader));
+ }
+ else
+ {
+ throw new IllegalStateException("Unexpected element: " +
reader.getLocalName());
+ }
+ }
+ }
+ }
+ throw new IllegalStateException("Reached end of xml document
unexpectedly");
+ }
+
+ private void parseRespectBinding(XMLStreamReader reader, PortComponentMetaData pc)
throws XMLStreamException
+ {
+ while (reader.hasNext())
+ {
+ switch (reader.nextTag())
+ {
+ case XMLStreamConstants.END_ELEMENT : {
+ if (match(reader, QNAME_RESPECT_BINDING))
+ {
+ return;
+ }
+ else
+ {
+ throw new IllegalStateException("Unexpected end tag: " +
reader.getLocalName());
+ }
+ }
+ case XMLStreamConstants.START_ELEMENT : {
+ if (match(reader, QNAME_ENABLED)) {
+ pc.setRespectBindingEnabled(elementAsBoolean(reader));
+ }
+ else
+ {
+ throw new IllegalStateException("Unexpected element: " +
reader.getLocalName());
+ }
+ }
+ }
+ }
+ throw new IllegalStateException("Reached end of xml document
unexpectedly");
+ }
+
+ private void parseServiceImplBean(XMLStreamReader reader, PortComponentMetaData pc)
throws XMLStreamException
+ {
+ while (reader.hasNext())
+ {
+ switch (reader.nextTag())
+ {
+ case XMLStreamConstants.END_ELEMENT : {
+ if (match(reader, QNAME_SERVICE_IMPL_BEAN))
+ {
+ return;
+ }
+ else
+ {
+ throw new IllegalStateException("Unexpected end tag: " +
reader.getLocalName());
+ }
+ }
+ case XMLStreamConstants.START_ELEMENT : {
+ if (match(reader, QNAME_SERVLET_LINK)) {
+ pc.setServletLink(elementAsString(reader));
+ }
+ else if (match(reader, QNAME_EJB_LINK)) {
+ pc.setEjbLink(elementAsString(reader));
+ }
+ else
+ {
+ throw new IllegalStateException("Unexpected element: " +
reader.getLocalName());
+ }
+ }
+ }
+ }
+ throw new IllegalStateException("Reached end of xml document
unexpectedly");
+ }
+
+ //-----------------------------------------
+ //TODO Below are methods to be removed....
+ //-----------------------------------------
/**
* This method is called on the factory by the object model builder when the parsing
starts.
Modified:
spi/trunk/src/main/java/org/jboss/wsf/spi/metadata/webservices/WebservicesMetaData.java
===================================================================
---
spi/trunk/src/main/java/org/jboss/wsf/spi/metadata/webservices/WebservicesMetaData.java 2010-11-30
08:25:28 UTC (rev 13365)
+++
spi/trunk/src/main/java/org/jboss/wsf/spi/metadata/webservices/WebservicesMetaData.java 2010-11-30
15:16:57 UTC (rev 13366)
@@ -84,9 +84,9 @@
private void createHeader(StringBuilder buf)
{
- buf.append("<webservices
xmlns='http://java.sun.com/xml/ns/j2ee'");
+ buf.append("<webservices
xmlns='http://java.sun.com/xml/ns/javaee'");
buf.append("
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'");
- buf.append("
xsi:schemaLocation='http://java.sun.com/xml/ns/j2ee
http://www.ibm.com/webservices/xsd/j2ee_web_services_1_1.xsd'");
- buf.append(" version='1.1'>");
+ buf.append("
xsi:schemaLocation='http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/javaee_web_services_1_2.xsd'");
+ buf.append(" version='1.2'>");
}
}
Modified: spi/trunk/src/main/java/org/jboss/wsf/spi/util/StAXUtils.java
===================================================================
--- spi/trunk/src/main/java/org/jboss/wsf/spi/util/StAXUtils.java 2010-11-30 08:25:28 UTC
(rev 13365)
+++ spi/trunk/src/main/java/org/jboss/wsf/spi/util/StAXUtils.java 2010-11-30 15:16:57 UTC
(rev 13366)
@@ -135,4 +135,16 @@
String namespaceURI = prefix == null ? reader.getNamespaceURI() :
reader.getNamespaceURI(prefix);
return prefix == null ? new QName(namespaceURI, localPart) : new
QName(namespaceURI, localPart, prefix);
}
+
+ public static boolean elementAsBoolean(XMLStreamReader reader) throws
XMLStreamException
+ {
+ String text = reader.getElementText();
+ return Boolean.parseBoolean(text);
+ }
+
+ public static int elementAsInt(XMLStreamReader reader) throws XMLStreamException
+ {
+ String text = reader.getElementText();
+ return Integer.parseInt(text);
+ }
}
Added:
spi/trunk/src/test/java/org/jboss/test/wsf/spi/metadata/webservices/WebServiceFactoryTestCase.java
===================================================================
---
spi/trunk/src/test/java/org/jboss/test/wsf/spi/metadata/webservices/WebServiceFactoryTestCase.java
(rev 0)
+++
spi/trunk/src/test/java/org/jboss/test/wsf/spi/metadata/webservices/WebServiceFactoryTestCase.java 2010-11-30
15:16:57 UTC (rev 13366)
@@ -0,0 +1,136 @@
+/*
+ * 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.test.wsf.spi.metadata.webservices;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.List;
+
+import javax.xml.namespace.QName;
+
+import junit.framework.TestCase;
+
+import org.jboss.wsf.spi.metadata.j2ee.serviceref.UnifiedHandlerChainMetaData;
+import org.jboss.wsf.spi.metadata.j2ee.serviceref.UnifiedHandlerChainsMetaData;
+import org.jboss.wsf.spi.metadata.j2ee.serviceref.UnifiedHandlerMetaData;
+import org.jboss.wsf.spi.metadata.j2ee.serviceref.UnifiedInitParamMetaData;
+import org.jboss.wsf.spi.metadata.webservices.PortComponentMetaData;
+import org.jboss.wsf.spi.metadata.webservices.WebserviceDescriptionMetaData;
+import org.jboss.wsf.spi.metadata.webservices.WebservicesFactory;
+import org.jboss.wsf.spi.metadata.webservices.WebservicesMetaData;
+
+/**
+ * Test the WebServiceFactory
+ *
+ * @author alessio.soldano(a)jboss.com
+ * @since 29-Nov-2010
+ */
+public class WebServiceFactoryTestCase extends TestCase
+{
+ public void testParse() throws Exception
+ {
+ File file = new
File("src/test/resources/metadata/webservices/test-webservices.xml");
+ InputStream is = new FileInputStream(file);
+ URL url = file.toURI().toURL();
+ WebservicesMetaData metadata = WebservicesFactory.parse(is, url);
+ assertEquals(url, metadata.getDescriptorURL());
+ assertEquals(2, metadata.getWebserviceDescriptions().length);
+ testDescription1(metadata.getWebserviceDescriptions()[0], metadata);
+ testDescription2(metadata.getWebserviceDescriptions()[1], metadata);
+ }
+
+ private void testDescription1(WebserviceDescriptionMetaData description,
WebservicesMetaData webservicesMetaData) throws Exception
+ {
+ assertEquals(null, description.getJaxrpcMappingFile());
+ assertEquals("HelloService",
description.getWebserviceDescriptionName());
+ assertEquals("META-INF/wsdl/HelloService.wsdl",
description.getWsdlFile());
+ assertEquals(webservicesMetaData, description.getWebservices());
+ PortComponentMetaData[] pcmds = description.getPortComponents();
+ assertEquals(1, pcmds.length);
+ PortComponentMetaData pcmd = pcmds[0];
+ assertEquals(description, pcmd.getWebserviceDescription());
+ assertEquals("HelloBean", pcmd.getPortComponentName());
+ assertEquals("ANONYMOUS", pcmd.getAddressingResponses());
+ assertEquals("jbws2999Test", pcmd.getEjbLink());
+ assertEquals(null, pcmd.getServletLink());
+ assertEquals(500, pcmd.getMtomThreshold());
+ assertEquals(new QName("http://Hello.org", "HelloService"),
pcmd.getWsdlService());
+ assertEquals(new QName("http://Hello.org", "Hello"),
pcmd.getWsdlPort());
+ assertEquals(true, pcmd.isMtomEnabled());
+ assertEquals(true, pcmd.isAddressingEnabled());
+ assertEquals(true, pcmd.isRespectBindingEnabled());
+ assertEquals(true, pcmd.isAddressingRequired());
+ assertEquals("##SOAP11_HTTP", pcmd.getProtocolBinding());
+ assertEquals("org.jboss.test.ws.jaxws.jbws2999.Hello",
pcmd.getServiceEndpointInterface());
+ assertEquals(null, pcmd.getContextRoot());
+
+ UnifiedHandlerChainsMetaData chains = pcmd.getHandlerChains();
+ assertEquals(1, chains.getHandlerChains().size());
+ UnifiedHandlerChainMetaData chain = chains.getHandlerChains().get(0);
+ assertEquals(null, chain.getPortNamePattern());
+ assertEquals(null, chain.getServiceNamePattern());
+ assertEquals(null, chain.getProtocolBindings());
+ List<UnifiedHandlerMetaData> handlers = chain.getHandlers();
+ assertEquals(1, handlers.size());
+ UnifiedHandlerMetaData handler = handlers.get(0);
+// assertEquals(chain, handler.getHandlerChain());
+ assertEquals("CustomHandler", handler.getHandlerName());
+ assertEquals("org.jboss.test.ws.jaxws.jbws2999.CustomHandler",
handler.getHandlerClass());
+ List<UnifiedInitParamMetaData> params = handler.getInitParams();
+ assertEquals(0, params.size());
+ assertEquals(0, handler.getPortNames().size());
+ assertEquals(0, handler.getSoapHeaders().size());
+ assertEquals(0, handler.getSoapRoles().size());
+ }
+
+ private void testDescription2(WebserviceDescriptionMetaData description,
WebservicesMetaData webservicesMetaData) throws Exception
+ {
+ assertEquals("WEB-INF/jaxrpc-mapping.xml",
description.getJaxrpcMappingFile());
+ assertEquals("SampleService",
description.getWebserviceDescriptionName());
+ assertEquals("WEB-INF/wsdl/SampleService.wsdl",
description.getWsdlFile());
+ assertEquals(webservicesMetaData, description.getWebservices());
+ PortComponentMetaData[] pcmds = description.getPortComponents();
+ assertEquals(1, pcmds.length);
+ PortComponentMetaData pcmd = pcmds[0];
+ assertEquals(description, pcmd.getWebserviceDescription());
+ assertEquals("TrivialServicePort", pcmd.getPortComponentName());
+ assertEquals("ALL", pcmd.getAddressingResponses());
+ assertEquals(null, pcmd.getEjbLink());
+ assertEquals("TrivialEndpoint", pcmd.getServletLink());
+ assertEquals(0, pcmd.getMtomThreshold());
+ assertEquals(null, pcmd.getWsdlService());
+ assertEquals(new QName("http://org.jboss.ws/samples/docstyle/bare",
"TrivialServicePort"), pcmd.getWsdlPort());
+ assertEquals(false, pcmd.isMtomEnabled());
+ assertEquals(false, pcmd.isAddressingEnabled());
+ assertEquals(false, pcmd.isRespectBindingEnabled());
+ assertEquals(false, pcmd.isAddressingRequired());
+ assertEquals(null, pcmd.getProtocolBinding());
+
assertEquals("org.jboss.test.ws.jaxrpc.samples.docstyle.bare.TrivialService",
pcmd.getServiceEndpointInterface());
+ assertEquals(null, pcmd.getContextRoot());
+
+ UnifiedHandlerChainsMetaData chains = pcmd.getHandlerChains();
+ assertEquals(null, chains);
+ }
+
+}
\ No newline at end of file
Added: spi/trunk/src/test/resources/metadata/webservices/test-webservices.xml
===================================================================
--- spi/trunk/src/test/resources/metadata/webservices/test-webservices.xml
(rev 0)
+++ spi/trunk/src/test/resources/metadata/webservices/test-webservices.xml 2010-11-30
15:16:57 UTC (rev 13366)
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<webservices
xmlns="http://java.sun.com/xml/ns/javaee"
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:wsdl="http://Hello.org"
+
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/javaee_web_services_1_3.xsd"
+ version="1.3">
+ <webservice-description>
+ <webservice-description-name>HelloService</webservice-description-name>
+ <wsdl-file>META-INF/wsdl/HelloService.wsdl</wsdl-file>
+ <port-component>
+ <port-component-name>HelloBean</port-component-name>
+ <wsdl-service>wsdl:HelloService</wsdl-service>
+ <wsdl-port>wsdl:Hello</wsdl-port>
+ <enable-mtom>true</enable-mtom>
+ <mtom-threshold>500</mtom-threshold>
+ <addressing>
+ <enabled>true</enabled>
+ <required>true</required>
+ <responses>ANONYMOUS</responses>
+ </addressing>
+ <respect-binding>
+ <enabled>true</enabled>
+ </respect-binding>
+ <protocol-binding>##SOAP11_HTTP</protocol-binding>
+
<service-endpoint-interface>org.jboss.test.ws.jaxws.jbws2999.Hello</service-endpoint-interface>
+ <service-impl-bean>
+ <ejb-link>jbws2999Test</ejb-link>
+ </service-impl-bean>
+ <handler-chains>
+ <handler-chain>
+ <handler>
+ <handler-name>CustomHandler</handler-name>
+
<handler-class>org.jboss.test.ws.jaxws.jbws2999.CustomHandler</handler-class>
+ </handler>
+ </handler-chain>
+ </handler-chains>
+ </port-component>
+ </webservice-description>
+
+ <webservice-description>
+ <webservice-description-name>SampleService</webservice-description-name>
+ <wsdl-file>WEB-INF/wsdl/SampleService.wsdl</wsdl-file>
+ <jaxrpc-mapping-file>WEB-INF/jaxrpc-mapping.xml</jaxrpc-mapping-file>
+ <port-component>
+ <port-component-name>TrivialServicePort</port-component-name>
+ <wsdl-port
xmlns:portNS='http://org.jboss.ws/samples/docstyle/bare'>portNS:TrivialServicePort</wsdl-port>
+
<service-endpoint-interface>org.jboss.test.ws.jaxrpc.samples.docstyle.bare.TrivialService</service-endpoint-interface>
+ <service-impl-bean>
+ <servlet-link>TrivialEndpoint</servlet-link>
+ </service-impl-bean>
+ </port-component>
+ </webservice-description>
+</webservices>
\ No newline at end of file