You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by di...@apache.org on 2008/04/07 06:22:22 UTC
svn commit: r645366 - in
/webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/description/impl:
DescriptionUtils.java HandlerChainsParser.java
Author: dims
Date: Sun Apr 6 21:22:22 2008
New Revision: 645366
URL: http://svn.apache.org/viewvc?rev=645366&view=rev
Log:
Fix for AXIS2-3709 - Improve handler-chains.xml parsing
Added:
webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/description/impl/HandlerChainsParser.java
Modified:
webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/description/impl/DescriptionUtils.java
Modified: webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/description/impl/DescriptionUtils.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/description/impl/DescriptionUtils.java?rev=645366&r1=645365&r2=645366&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/description/impl/DescriptionUtils.java (original)
+++ webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/description/impl/DescriptionUtils.java Sun Apr 6 21:22:22 2008
@@ -330,15 +330,8 @@
public static HandlerChainsType loadHandlerChains(InputStream is, ClassLoader classLoader) {
try {
- // All the classes we need should be part of this package
- JAXBContext jc = JAXBContext
- .newInstance("org.apache.axis2.jaxws.description.xml.handler", classLoader);
-
- Unmarshaller u = jc.createUnmarshaller();
-
- JAXBElement<?> o = (JAXBElement<?>)u.unmarshal(is);
- return (HandlerChainsType)o.getValue();
-
+ HandlerChainsParser parser = new HandlerChainsParser();
+ return parser.loadHandlerChains(is);
} catch (Exception e) {
throw ExceptionFactory
.makeWebServiceException(Messages.getMessage("loadHandlerChainErr", e.getMessage()));
Added: webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/description/impl/HandlerChainsParser.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/description/impl/HandlerChainsParser.java?rev=645366&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/description/impl/HandlerChainsParser.java (added)
+++ webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/description/impl/HandlerChainsParser.java Sun Apr 6 21:22:22 2008
@@ -0,0 +1,131 @@
+/*
+ * 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.apache.axis2.jaxws.description.impl;
+
+import java.io.InputStream;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
+import javax.xml.bind.Unmarshaller;
+import javax.xml.namespace.QName;
+import javax.xml.ws.WebServiceException;
+
+import org.apache.axis2.jaxws.description.xml.handler.HandlerChainType;
+import org.apache.axis2.jaxws.description.xml.handler.HandlerChainsType;
+import org.apache.axis2.jaxws.description.xml.handler.HandlerType;
+import org.apache.axis2.util.XMLUtils;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+public class HandlerChainsParser {
+
+ private static final String JAVA_EE_NS = "http://java.sun.com/xml/ns/javaee";
+ private static JAXBContext context;
+
+ public HandlerChainsType loadHandlerChains(InputStream in) throws Exception {
+ Document document = XMLUtils.newDocument(in);
+ Element el = document.getDocumentElement();
+ if (!JAVA_EE_NS.equals(el.getNamespaceURI()) ||
+ !"handler-chains".equals(el.getLocalName())) {
+ throw new WebServiceException("Unexpected element. Expected handler-chains element");
+ }
+
+ HandlerChainsType handlerChains = new HandlerChainsType();
+ Node node = el.getFirstChild();
+ while (node != null) {
+ if (node instanceof Element) {
+ el = (Element)node;
+ if (!JAVA_EE_NS.equals(el.getNamespaceURI()) ||
+ !el.getLocalName().equals("handler-chain")) {
+ throw new WebServiceException("Unexpected element. Expected handler-chain element.");
+ }
+ handlerChains.getHandlerChain().add(processHandlerChainElement(el));
+ }
+ node = node.getNextSibling();
+ }
+
+ return handlerChains;
+ }
+
+ private HandlerChainType processHandlerChainElement(Element el) throws Exception {
+ HandlerChainType handler = new HandlerChainType();
+ Node node = el.getFirstChild();
+ while (node != null) {
+ Node cur = node;
+ node = node.getNextSibling();
+ if (cur instanceof Element) {
+ el = (Element)cur;
+ if (!JAVA_EE_NS.equals(el.getNamespaceURI())) {
+ throw new WebServiceException();
+ }
+ String name = el.getLocalName();
+ if ("port-name-pattern".equals(name)) {
+ handler.setPortNamePattern(processPatternElement(el));
+ } else if ("service-name-pattern".equals(name)) {
+ handler.setServiceNamePattern(processPatternElement(el));
+ } else if ("protocol-bindings".equals(name)) {
+ handler.getProtocolBindings().add(processProtocolBindingsElement(el));
+ } else if ("handler".equals(name)) {
+ handler.getHandler().add(processHandlerElement(el));
+ }
+ }
+ }
+ return handler;
+ }
+
+ private String processProtocolBindingsElement(Element el) {
+ return el.getTextContent().trim();
+ }
+
+ private QName processPatternElement(Element el) throws Exception {
+ String namePattern = el.getTextContent().trim();
+ if ("*".equals(namePattern)) {
+ return new QName("*");
+ }
+
+ if (!namePattern.contains(":")) {
+ throw new WebServiceException("Not a qname pattern");
+ }
+ 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;
+ }
+ return new QName(ns, localPart);
+ }
+
+ private HandlerType processHandlerElement(Element el) throws Exception {
+ JAXBContext ctx = getContextForHandlerType();
+ Unmarshaller unmarshaller = ctx.createUnmarshaller();
+ HandlerType handler = unmarshaller.unmarshal(el, HandlerType.class).getValue();
+ return handler;
+ }
+
+ private static synchronized JAXBContext getContextForHandlerType()
+ throws JAXBException {
+ if (context == null) {
+ context = JAXBContext.newInstance(HandlerType.class);
+ }
+ return context;
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org