325N/A/*
325N/A * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
325N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
325N/A *
325N/A * This code is free software; you can redistribute it and/or modify it
325N/A * under the terms of the GNU General Public License version 2 only, as
325N/A * published by the Free Software Foundation. Oracle designates this
325N/A * particular file as subject to the "Classpath" exception as provided
325N/A * by Oracle in the LICENSE file that accompanied this code.
325N/A *
325N/A * This code is distributed in the hope that it will be useful, but WITHOUT
325N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
325N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
325N/A * version 2 for more details (a copy is included in the LICENSE file that
325N/A * accompanied this code).
325N/A *
325N/A * You should have received a copy of the GNU General Public License version
325N/A * 2 along with this work; if not, write to the Free Software Foundation,
325N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
325N/A *
325N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
325N/A * or visit www.oracle.com if you need additional information or have any
325N/A * questions.
325N/A */
325N/A
325N/Apackage com.sun.xml.internal.ws.api.addressing;
325N/A
325N/Aimport com.sun.istack.internal.NotNull;
325N/Aimport com.sun.istack.internal.Nullable;
325N/Aimport com.sun.xml.internal.stream.buffer.MutableXMLStreamBuffer;
325N/Aimport com.sun.xml.internal.stream.buffer.XMLStreamBuffer;
325N/Aimport com.sun.xml.internal.stream.buffer.XMLStreamBufferResult;
325N/Aimport com.sun.xml.internal.stream.buffer.XMLStreamBufferSource;
325N/Aimport com.sun.xml.internal.stream.buffer.sax.SAXBufferProcessor;
325N/Aimport com.sun.xml.internal.stream.buffer.stax.StreamReaderBufferProcessor;
325N/Aimport com.sun.xml.internal.stream.buffer.stax.StreamWriterBufferCreator;
325N/Aimport com.sun.xml.internal.ws.addressing.EndpointReferenceUtil;
325N/Aimport com.sun.xml.internal.ws.addressing.W3CAddressingMetadataConstants;
325N/Aimport com.sun.xml.internal.ws.addressing.WSEPRExtension;
325N/Aimport com.sun.xml.internal.ws.addressing.model.InvalidAddressingHeaderException;
325N/Aimport com.sun.xml.internal.ws.addressing.v200408.MemberSubmissionAddressingConstants;
325N/Aimport com.sun.xml.internal.ws.api.message.Header;
325N/Aimport com.sun.xml.internal.ws.api.message.HeaderList;
325N/Aimport com.sun.xml.internal.ws.api.message.Message;
325N/Aimport com.sun.xml.internal.ws.api.streaming.XMLStreamReaderFactory;
325N/Aimport com.sun.xml.internal.ws.api.model.wsdl.WSDLExtension;
325N/Aimport com.sun.xml.internal.ws.resources.AddressingMessages;
325N/Aimport com.sun.xml.internal.ws.resources.ClientMessages;
325N/Aimport com.sun.xml.internal.ws.spi.ProviderImpl;
325N/Aimport com.sun.xml.internal.ws.streaming.XMLStreamReaderUtil;
325N/Aimport com.sun.xml.internal.ws.util.DOMUtil;
325N/Aimport com.sun.xml.internal.ws.util.xml.XMLStreamWriterFilter;
325N/Aimport com.sun.xml.internal.ws.util.xml.XmlUtil;
325N/Aimport com.sun.xml.internal.ws.util.xml.XMLStreamReaderToXMLStreamWriter;
325N/Aimport com.sun.xml.internal.ws.wsdl.parser.WSDLConstants;
325N/Aimport org.w3c.dom.Element;
325N/Aimport org.xml.sax.*;
325N/Aimport org.xml.sax.helpers.XMLFilterImpl;
325N/A
325N/Aimport javax.xml.bind.JAXBContext;
325N/Aimport javax.xml.namespace.QName;
325N/Aimport javax.xml.stream.XMLStreamException;
325N/Aimport javax.xml.stream.XMLStreamReader;
325N/Aimport javax.xml.stream.XMLStreamWriter;
325N/Aimport javax.xml.transform.Source;
325N/Aimport javax.xml.transform.TransformerException;
325N/Aimport javax.xml.transform.sax.SAXSource;
325N/Aimport javax.xml.transform.stream.StreamResult;
325N/Aimport javax.xml.transform.stream.StreamSource;
325N/Aimport javax.xml.ws.Dispatch;
325N/Aimport javax.xml.ws.EndpointReference;
325N/Aimport javax.xml.ws.Service;
325N/Aimport javax.xml.ws.WebServiceException;
325N/Aimport javax.xml.ws.WebServiceFeature;
325N/Aimport java.io.InputStream;
325N/Aimport java.io.StringWriter;
325N/Aimport java.net.URI;
325N/Aimport java.net.URL;
325N/Aimport java.util.*;
325N/A
325N/A/**
325N/A * Internal representation of the EPR.
325N/A *
325N/A * <p>
325N/A * Instances of this class are immutable and thread-safe.
325N/A *
325N/A * @author Kohsuke Kawaguchi
325N/A * @see AddressingVersion#anonymousEpr
325N/A */
325N/Apublic final class WSEndpointReference implements WSDLExtension {
325N/A private final XMLStreamBuffer infoset;
325N/A /**
325N/A * Version of the addressing spec.
325N/A */
325N/A private final AddressingVersion version;
325N/A
325N/A /**
325N/A * Marked Reference parameters inside this EPR.
325N/A *
325N/A * Parsed when the object is created. can be empty but never null.
325N/A * @see #parse()
325N/A */
325N/A private @NotNull Header[] referenceParameters;
325N/A private @NotNull String address;
325N/A
325N/A private @NotNull QName rootElement;
325N/A /**
325N/A * Creates from the spec version of {@link EndpointReference}.
325N/A *
325N/A * <p>
325N/A * This method performs the data conversion, so it's slow.
325N/A * Do not use this method in a performance critical path.
325N/A */
325N/A public WSEndpointReference(EndpointReference epr, AddressingVersion version) {
325N/A try {
325N/A MutableXMLStreamBuffer xsb = new MutableXMLStreamBuffer();
325N/A epr.writeTo(new XMLStreamBufferResult(xsb));
325N/A this.infoset = xsb;
325N/A this.version = version;
325N/A this.rootElement = new QName("EndpointReference", version.nsUri);
325N/A parse();
325N/A } catch (XMLStreamException e) {
325N/A throw new WebServiceException(ClientMessages.FAILED_TO_PARSE_EPR(epr),e);
325N/A }
325N/A }
325N/A
325N/A /**
325N/A * Creates from the spec version of {@link EndpointReference}.
325N/A *
325N/A * <p>
325N/A * This method performs the data conversion, so it's slow.
325N/A * Do not use this method in a performance critical path.
325N/A */
325N/A public WSEndpointReference(EndpointReference epr) {
325N/A this(epr,AddressingVersion.fromSpecClass(epr.getClass()));
325N/A }
325N/A
325N/A /**
325N/A * Creates a {@link WSEndpointReference} that wraps a given infoset.
325N/A */
325N/A public WSEndpointReference(XMLStreamBuffer infoset, AddressingVersion version) {
325N/A try {
325N/A this.infoset = infoset;
325N/A this.version = version;
325N/A this.rootElement = new QName("EndpointReference", version.nsUri);
325N/A parse();
325N/A } catch (XMLStreamException e) {
325N/A // this can never happen because XMLStreamBuffer never has underlying I/O error.
325N/A throw new AssertionError(e);
325N/A }
325N/A }
325N/A
325N/A /**
325N/A * Creates a {@link WSEndpointReference} by parsing an infoset.
325N/A */
325N/A public WSEndpointReference(InputStream infoset, AddressingVersion version) throws XMLStreamException {
325N/A this(XMLStreamReaderFactory.create(null,infoset,false),version);
325N/A }
325N/A
325N/A /**
325N/A * Creates a {@link WSEndpointReference} from the given infoset.
325N/A * The {@link XMLStreamReader} must point to either a document or an element.
325N/A */
325N/A public WSEndpointReference(XMLStreamReader in, AddressingVersion version) throws XMLStreamException {
325N/A this(XMLStreamBuffer.createNewBufferFromXMLStreamReader(in), version);
325N/A }
325N/A
325N/A /**
325N/A * @see #WSEndpointReference(String, AddressingVersion)
325N/A */
325N/A public WSEndpointReference(URL address, AddressingVersion version) {
325N/A this(address.toExternalForm(), version);
325N/A }
325N/A
325N/A /**
325N/A * @see #WSEndpointReference(String, AddressingVersion)
325N/A */
325N/A public WSEndpointReference(URI address, AddressingVersion version) {
325N/A this(address.toString(), version);
325N/A }
325N/A
325N/A /**
325N/A * Creates a {@link WSEndpointReference} that only has an address.
325N/A */
325N/A public WSEndpointReference(String address, AddressingVersion version) {
325N/A this.infoset = createBufferFromAddress(address,version);
325N/A this.version = version;
325N/A this.address = address;
325N/A this.rootElement = new QName("EndpointReference", version.nsUri);
325N/A this.referenceParameters = EMPTY_ARRAY;
325N/A }
325N/A
325N/A private static XMLStreamBuffer createBufferFromAddress(String address, AddressingVersion version) {
325N/A try {
325N/A MutableXMLStreamBuffer xsb = new MutableXMLStreamBuffer();
325N/A StreamWriterBufferCreator w = new StreamWriterBufferCreator(xsb);
325N/A w.writeStartDocument();
325N/A w.writeStartElement(version.getPrefix(),
325N/A "EndpointReference", version.nsUri);
325N/A w.writeNamespace(version.getPrefix(), version.nsUri);
325N/A w.writeStartElement(version.getPrefix(),version.eprType.address, version.nsUri);
325N/A w.writeCharacters(address);
325N/A w.writeEndElement();
325N/A w.writeEndElement();
325N/A w.writeEndDocument();
325N/A w.close();
325N/A return xsb;
325N/A } catch (XMLStreamException e) {
325N/A // can never happen because we are writing to XSB
325N/A throw new AssertionError(e);
325N/A }
325N/A }
325N/A
325N/A /**
325N/A * Creates an EPR from individual components.
325N/A *
325N/A * <p>
325N/A * This version takes various information about metadata, and creates an EPR that has
325N/A * the necessary embedded WSDL.
325N/A */
325N/A public WSEndpointReference(@NotNull AddressingVersion version,
325N/A @NotNull String address,
325N/A @Nullable QName service,
325N/A @Nullable QName port,
325N/A @Nullable QName portType,
325N/A @Nullable List<Element> metadata,
325N/A @Nullable String wsdlAddress,
325N/A @Nullable List<Element> referenceParameters) {
325N/A this(version, address, service, port, portType, metadata, wsdlAddress, null, referenceParameters, null, null);
325N/A }
325N/A
325N/A /**
325N/A * Creates an EPR from individual components.
325N/A *
325N/A * <p>
325N/A * This version takes various information about metadata, and creates an EPR that has
325N/A * the necessary embedded WSDL.
325N/A */
325N/A public WSEndpointReference(@NotNull AddressingVersion version,
325N/A @NotNull String address,
325N/A @Nullable QName service,
325N/A @Nullable QName port,
325N/A @Nullable QName portType,
325N/A @Nullable List<Element> metadata,
325N/A @Nullable String wsdlAddress,
325N/A @Nullable List<Element> referenceParameters,
325N/A @Nullable Collection<EPRExtension> extns,@Nullable Map<QName, String> attributes) {
325N/A this(createBufferFromData(version, address, referenceParameters, service, port, portType, metadata, wsdlAddress, null, extns, attributes),
325N/A version );
325N/A }
325N/A
325N/A /**
325N/A * Creates an EPR from individual components.
325N/A *
325N/A * <p>
325N/A * This version takes various information about metadata, and creates an EPR that has
325N/A * the necessary embedded WSDL.
325N/A * @since JAX-WS 2.2
325N/A */
325N/A public WSEndpointReference(@NotNull AddressingVersion version,
325N/A @NotNull String address,
325N/A @Nullable QName service,
325N/A @Nullable QName port,
325N/A @Nullable QName portType,
325N/A @Nullable List<Element> metadata,
325N/A @Nullable String wsdlAddress,
325N/A @Nullable String wsdlTargetNamepsace,
325N/A @Nullable List<Element> referenceParameters,
325N/A @Nullable List<Element> elements, @Nullable Map<QName, String> attributes) {
325N/A this(
325N/A createBufferFromData(version, address, referenceParameters, service, port, portType, metadata, wsdlAddress,wsdlTargetNamepsace, elements, attributes),
325N/A version );
325N/A }
325N/A
325N/A private static XMLStreamBuffer createBufferFromData(AddressingVersion version, String address, List<Element> referenceParameters, QName service, QName port, QName portType,
325N/A List<Element> metadata, String wsdlAddress, String wsdlTargetNamespace, @Nullable List<Element> elements, @Nullable Map<QName, String> attributes) {
325N/A
325N/A StreamWriterBufferCreator writer = new StreamWriterBufferCreator();
325N/A
325N/A try {
325N/A writer.writeStartDocument();
325N/A writer.writeStartElement(version.getPrefix(),"EndpointReference", version.nsUri);
325N/A writer.writeNamespace(version.getPrefix(),version.nsUri);
325N/A
325N/A writePartialEPRInfoset(writer, version, address, referenceParameters, service, port, portType,
325N/A metadata,wsdlAddress, wsdlTargetNamespace, attributes);
325N/A
325N/A //write extensibility elements in the EPR element
325N/A if (elements != null) {
325N/A for (Element e : elements)
325N/A DOMUtil.serializeNode(e, writer);
325N/A }
325N/A
325N/A writer.writeEndElement();
325N/A writer.writeEndDocument();
325N/A writer.flush();
325N/A
325N/A return writer.getXMLStreamBuffer();
325N/A } catch (XMLStreamException e) {
325N/A throw new WebServiceException(e);
325N/A }
325N/A }
325N/A
325N/A private static XMLStreamBuffer createBufferFromData(AddressingVersion version, String address, List<Element> referenceParameters, QName service, QName port, QName portType,
325N/A List<Element> metadata, String wsdlAddress, String wsdlTargetNamespace, @Nullable Collection<EPRExtension> extns, @Nullable Map<QName, String> attributes) {
325N/A
325N/A StreamWriterBufferCreator writer = new StreamWriterBufferCreator();
325N/A
325N/A try {
325N/A writer.writeStartDocument();
325N/A writer.writeStartElement(version.getPrefix(),"EndpointReference", version.nsUri);
325N/A writer.writeNamespace(version.getPrefix(),version.nsUri);
325N/A
325N/A writePartialEPRInfoset(writer, version, address, referenceParameters, service, port, portType,
325N/A metadata,wsdlAddress, wsdlTargetNamespace, attributes);
325N/A
325N/A //write extensibility elements in the EPR element
325N/A if (extns != null) {
325N/A for (EPRExtension e : extns) {
325N/A XMLStreamReaderToXMLStreamWriter c = new XMLStreamReaderToXMLStreamWriter();
325N/A XMLStreamReader r = e.readAsXMLStreamReader();
325N/A c.bridge(r, writer);
325N/A XMLStreamReaderFactory.recycle(r);
325N/A }
325N/A }
325N/A
325N/A writer.writeEndElement();
325N/A writer.writeEndDocument();
325N/A writer.flush();
325N/A
325N/A return writer.getXMLStreamBuffer();
325N/A } catch (XMLStreamException e) {
325N/A throw new WebServiceException(e);
325N/A }
325N/A }
325N/A
325N/A private static void writePartialEPRInfoset(StreamWriterBufferCreator writer, AddressingVersion version, String address, List<Element> referenceParameters, QName service, QName port, QName portType,
325N/A List<Element> metadata, String wsdlAddress, String wsdlTargetNamespace, @Nullable Map<QName, String> attributes) throws XMLStreamException {
325N/A //add extensibile attributes on the EPR element
325N/A if (attributes != null) {
325N/A for (Map.Entry<QName, String> entry : attributes.entrySet()) {
325N/A QName qname = entry.getKey();
325N/A writer.writeAttribute(qname.getPrefix(), qname.getNamespaceURI(), qname.getLocalPart(), entry.getValue());
325N/A }
325N/A }
325N/A
325N/A writer.writeStartElement(version.getPrefix(), version.eprType.address, version.nsUri);
325N/A writer.writeCharacters(address);
325N/A writer.writeEndElement();
325N/A if (referenceParameters != null) {
325N/A writer.writeStartElement(version.getPrefix(), version.eprType.referenceParameters, version.nsUri);
325N/A for (Element e : referenceParameters)
325N/A DOMUtil.serializeNode(e, writer);
325N/A writer.writeEndElement();
325N/A }
325N/A
325N/A switch (version) {
325N/A case W3C:
325N/A writeW3CMetaData(writer, service, port, portType, metadata, wsdlAddress, wsdlTargetNamespace);
325N/A break;
325N/A
325N/A case MEMBER:
325N/A writeMSMetaData(writer, service, port, portType, metadata);
325N/A if (wsdlAddress != null) {
325N/A //Inline the wsdl as extensibility element
325N/A //Write mex:Metadata wrapper
325N/A writer.writeStartElement(MemberSubmissionAddressingConstants.MEX_METADATA.getPrefix(),
325N/A MemberSubmissionAddressingConstants.MEX_METADATA.getLocalPart(),
325N/A MemberSubmissionAddressingConstants.MEX_METADATA.getNamespaceURI());
325N/A writer.writeStartElement(MemberSubmissionAddressingConstants.MEX_METADATA_SECTION.getPrefix(),
325N/A MemberSubmissionAddressingConstants.MEX_METADATA_SECTION.getLocalPart(),
325N/A MemberSubmissionAddressingConstants.MEX_METADATA_SECTION.getNamespaceURI());
325N/A writer.writeAttribute(MemberSubmissionAddressingConstants.MEX_METADATA_DIALECT_ATTRIBUTE,
325N/A MemberSubmissionAddressingConstants.MEX_METADATA_DIALECT_VALUE);
325N/A
325N/A writeWsdl(writer, service, wsdlAddress);
325N/A
325N/A writer.writeEndElement();
325N/A writer.writeEndElement();
325N/A }
325N/A
325N/A break;
325N/A }
325N/A }
325N/A
325N/A
325N/A private static void writeW3CMetaData(StreamWriterBufferCreator writer,
325N/A QName service,
325N/A QName port,
325N/A QName portType, List<Element> metadata,
325N/A String wsdlAddress, String wsdlTargetNamespace) throws XMLStreamException {
325N/A
325N/A writer.writeStartElement(AddressingVersion.W3C.getPrefix(),
325N/A AddressingVersion.W3C.eprType.wsdlMetadata.getLocalPart(), AddressingVersion.W3C.nsUri);
325N/A writer.writeNamespace(AddressingVersion.W3C.getWsdlPrefix(),
325N/A AddressingVersion.W3C.wsdlNsUri);
325N/A //write wsdliLication as defined in WS-Addressing 1.0 Metadata spec
325N/A if(wsdlAddress != null)
325N/A writeWsdliLocation(writer, service, wsdlAddress,wsdlTargetNamespace);
325N/A
325N/A //Write Interface info
325N/A if (portType != null) {
325N/A writer.writeStartElement(W3CAddressingMetadataConstants.WSAM_PREFIX_NAME,
325N/A AddressingVersion.W3C.eprType.portTypeName,
325N/A W3CAddressingMetadataConstants.WSAM_NAMESPACE_NAME);
325N/A String portTypePrefix = portType.getPrefix();
325N/A if (portTypePrefix == null || portTypePrefix.equals("")) {
325N/A //TODO check prefix again
325N/A portTypePrefix = "wsns";
325N/A }
325N/A writer.writeNamespace(portTypePrefix, portType.getNamespaceURI());
325N/A writer.writeCharacters(portTypePrefix + ":" + portType.getLocalPart());
325N/A writer.writeEndElement();
325N/A }
325N/A if (service != null) {
325N/A //Write service and Port info
325N/A if (!(service.getNamespaceURI().equals("") || service.getLocalPart().equals(""))) {
325N/A writer.writeStartElement(W3CAddressingMetadataConstants.WSAM_PREFIX_NAME,
325N/A AddressingVersion.W3C.eprType.serviceName,
325N/A W3CAddressingMetadataConstants.WSAM_NAMESPACE_NAME);
325N/A String servicePrefix = service.getPrefix();
325N/A if (servicePrefix == null || servicePrefix.equals("")) {
325N/A //TODO check prefix again
325N/A servicePrefix = "wsns";
325N/A }
325N/A writer.writeNamespace(servicePrefix, service.getNamespaceURI());
325N/A if (port != null) {
325N/A writer.writeAttribute(AddressingVersion.W3C.eprType.portName, port.getLocalPart());
325N/A }
325N/A writer.writeCharacters(servicePrefix + ":" + service.getLocalPart());
325N/A writer.writeEndElement();
325N/A }
325N/A }
325N/A /*
325N/A //Inline the wsdl
325N/A if (wsdlAddress != null) {
325N/A writeWsdl(writer, service, wsdlAddress);
325N/A }
325N/A */
325N/A //Add the extra metadata Elements
325N/A if (metadata != null)
325N/A for (Element e : metadata) {
325N/A DOMUtil.serializeNode(e, writer);
325N/A }
325N/A writer.writeEndElement();
325N/A
325N/A }
325N/A
325N/A /**
325N/A * @param writer the writer should be at the start of element.
325N/A * @param service Namespace URI of servcie is used as targetNamespace of wsdl if wsdlTargetNamespace is not null
325N/A * @param wsdlAddress wsdl location
325N/A * @param wsdlTargetNamespace targetnamespace of wsdl to be put in wsdliLocation
325N/A *
325N/A */
325N/A private static void writeWsdliLocation(StreamWriterBufferCreator writer, QName service,String wsdlAddress,String wsdlTargetNamespace) throws XMLStreamException {
325N/A String wsdliLocation = "";
325N/A if(wsdlTargetNamespace != null) {
325N/A wsdliLocation = wsdlTargetNamespace + " ";
325N/A } else if (service != null) {
325N/A wsdliLocation = service.getNamespaceURI() + " ";
325N/A } else {
325N/A throw new WebServiceException("WSDL target Namespace cannot be resolved");
325N/A }
325N/A wsdliLocation += wsdlAddress;
325N/A //writer.writeNamespace("wsdli","http://www.w3.org/ns/wsdl-instance");
325N/A writer.writeAttribute(W3CAddressingMetadataConstants.WSAM_WSDLI_ATTRIBUTE_PREFIX,
325N/A W3CAddressingMetadataConstants.WSAM_WSDLI_ATTRIBUTE_NAMESPACE,
325N/A W3CAddressingMetadataConstants.WSAM_WSDLI_ATTRIBUTE_LOCALNAME,
325N/A wsdliLocation);
325N/A
325N/A }
325N/A private static void writeMSMetaData(StreamWriterBufferCreator writer,
325N/A QName service,
325N/A QName port,
325N/A QName portType, List<Element> metadata) throws XMLStreamException {
325N/A // TODO: write ReferenceProperties
325N/A //TODO: write ReferenceParameters
325N/A if (portType != null) {
325N/A //Write Interface info
325N/A writer.writeStartElement(AddressingVersion.MEMBER.getPrefix(),
325N/A AddressingVersion.MEMBER.eprType.portTypeName,
325N/A AddressingVersion.MEMBER.nsUri);
325N/A
325N/A
325N/A String portTypePrefix = portType.getPrefix();
325N/A if (portTypePrefix == null || portTypePrefix.equals("")) {
325N/A //TODO check prefix again
325N/A portTypePrefix = "wsns";
325N/A }
325N/A writer.writeNamespace(portTypePrefix, portType.getNamespaceURI());
325N/A writer.writeCharacters(portTypePrefix + ":" + portType.getLocalPart());
325N/A writer.writeEndElement();
325N/A }
325N/A //Write service and Port info
325N/A if (service != null) {
325N/A if (!(service.getNamespaceURI().equals("") || service.getLocalPart().equals(""))) {
325N/A writer.writeStartElement(AddressingVersion.MEMBER.getPrefix(),
325N/A AddressingVersion.MEMBER.eprType.serviceName,
325N/A AddressingVersion.MEMBER.nsUri);
325N/A String servicePrefix = service.getPrefix();
325N/A if (servicePrefix == null || servicePrefix.equals("")) {
325N/A //TODO check prefix again
325N/A servicePrefix = "wsns";
325N/A }
325N/A writer.writeNamespace(servicePrefix, service.getNamespaceURI());
325N/A if (port != null) {
325N/A writer.writeAttribute(AddressingVersion.MEMBER.eprType.portName,
325N/A port.getLocalPart());
325N/A }
325N/A writer.writeCharacters(servicePrefix + ":" + service.getLocalPart());
325N/A writer.writeEndElement();
325N/A }
325N/A }
325N/A }
325N/A
325N/A private static void writeWsdl(StreamWriterBufferCreator writer, QName service, String wsdlAddress) throws XMLStreamException {
325N/A // Inline-wsdl
325N/A writer.writeStartElement(WSDLConstants.PREFIX_NS_WSDL,
325N/A WSDLConstants.QNAME_DEFINITIONS.getLocalPart(),
325N/A WSDLConstants.NS_WSDL);
325N/A writer.writeNamespace(WSDLConstants.PREFIX_NS_WSDL, WSDLConstants.NS_WSDL);
325N/A writer.writeStartElement(WSDLConstants.PREFIX_NS_WSDL,
325N/A WSDLConstants.QNAME_IMPORT.getLocalPart(),
325N/A WSDLConstants.NS_WSDL);
325N/A writer.writeAttribute("namespace", service.getNamespaceURI());
325N/A writer.writeAttribute("location", wsdlAddress);
325N/A writer.writeEndElement();
325N/A writer.writeEndElement();
325N/A }
325N/A
325N/A
325N/A
325N/A /**
325N/A * Converts from {@link EndpointReference}.
325N/A *
325N/A * This handles null {@link EndpointReference} correctly.
325N/A * Call {@link #WSEndpointReference(EndpointReference)} directly
325N/A * if you know it's not null.
325N/A */
325N/A public static @Nullable
325N/A WSEndpointReference create(@Nullable EndpointReference epr) {
325N/A if (epr != null)
325N/A return new WSEndpointReference(epr);
325N/A else
325N/A return null;
325N/A }
325N/A
325N/A /**
325N/A * @see #createWithAddress(String)
325N/A */
325N/A public @NotNull WSEndpointReference createWithAddress(@NotNull URI newAddress) {
325N/A return createWithAddress(newAddress.toString());
325N/A }
325N/A
325N/A /**
325N/A * @see #createWithAddress(String)
325N/A */
325N/A public @NotNull WSEndpointReference createWithAddress(@NotNull URL newAddress) {
325N/A return createWithAddress(newAddress.toString());
325N/A }
325N/A
325N/A /**
325N/A * Creates a new {@link WSEndpointReference} by replacing the address of this EPR
325N/A * to the new one.
325N/A *
325N/A * <p>
325N/A * The following example shows how you can use this to force an HTTPS EPR,
325N/A * when the endpoint can serve both HTTP and HTTPS requests.
325N/A * <pre>
325N/A * if(epr.getAddress().startsWith("http:"))
325N/A * epr = epr.createWithAddress("https:"+epr.getAddress().substring(5));
325N/A * </pre>
325N/A *
325N/A * @param newAddress
325N/A * This is a complete URL to be written inside &lt;Adress> element of the EPR,
325N/A * such as "http://foo.bar/abc/def"
325N/A */
325N/A public @NotNull WSEndpointReference createWithAddress(@NotNull final String newAddress) {
325N/A MutableXMLStreamBuffer xsb = new MutableXMLStreamBuffer();
325N/A XMLFilterImpl filter = new XMLFilterImpl() {
325N/A private boolean inAddress = false;
325N/A public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException {
325N/A if(localName.equals("Address") && uri.equals(version.nsUri))
325N/A inAddress = true;
325N/A super.startElement(uri,localName,qName,atts);
325N/A }
325N/A
325N/A public void characters(char ch[], int start, int length) throws SAXException {
325N/A if(!inAddress)
325N/A super.characters(ch, start, length);
325N/A }
325N/A
325N/A
325N/A public void endElement(String uri, String localName, String qName) throws SAXException {
325N/A if(inAddress)
325N/A super.characters(newAddress.toCharArray(),0,newAddress.length());
325N/A inAddress = false;
325N/A super.endElement(uri, localName, qName);
325N/A }
325N/A };
325N/A filter.setContentHandler(xsb.createFromSAXBufferCreator());
325N/A try {
325N/A infoset.writeTo(filter,false);
325N/A } catch (SAXException e) {
325N/A throw new AssertionError(e); // impossible since we are writing from XSB to XSB.
325N/A }
325N/A
325N/A return new WSEndpointReference(xsb,version);
325N/A }
325N/A
325N/A /**
325N/A * Convert the EPR to the spec version. The actual type of
325N/A * {@link EndpointReference} to be returned depends on which version
325N/A * of the addressing spec this EPR conforms to.
325N/A *
325N/A * @throws WebServiceException
325N/A * if the conversion fails, which can happen if the EPR contains
325N/A * invalid infoset (wrong namespace URI, etc.)
325N/A */
325N/A public @NotNull EndpointReference toSpec() {
325N/A return ProviderImpl.INSTANCE.readEndpointReference(asSource("EndpointReference"));
325N/A }
325N/A
325N/A /**
325N/A * Converts the EPR to the specified spec version.
325N/A *
325N/A * If the {@link #getVersion() the addressing version in use} and
325N/A * the given class is different, then this may involve version conversion.
325N/A */
325N/A public @NotNull <T extends EndpointReference> T toSpec(Class<T> clazz) {
325N/A return EndpointReferenceUtil.transform(clazz,toSpec());
325N/A }
325N/A
325N/A /**
325N/A * Creates a proxy that can be used to talk to this EPR.
325N/A *
325N/A * <p>
325N/A * All the normal WS-Addressing processing happens automatically,
325N/A * such as setting the endpoint address to {@link #getAddress() the address},
325N/A * and sending the reference parameters associated with this EPR as
325N/A * headers, etc.
325N/A */
325N/A public @NotNull <T> T getPort(@NotNull Service jaxwsService,
325N/A @NotNull Class<T> serviceEndpointInterface,
325N/A WebServiceFeature... features) {
325N/A // TODO: implement it in a better way
325N/A return jaxwsService.getPort(toSpec(),serviceEndpointInterface,features);
325N/A }
325N/A
325N/A /**
325N/A * Creates a {@link Dispatch} that can be used to talk to this EPR.
325N/A *
325N/A * <p>
325N/A * All the normal WS-Addressing processing happens automatically,
325N/A * such as setting the endpoint address to {@link #getAddress() the address},
325N/A * and sending the reference parameters associated with this EPR as
325N/A * headers, etc.
325N/A */
325N/A public @NotNull <T> Dispatch<T> createDispatch(
325N/A @NotNull Service jaxwsService,
325N/A @NotNull Class<T> type,
325N/A @NotNull Service.Mode mode,
325N/A WebServiceFeature... features) {
325N/A
325N/A // TODO: implement it in a better way
325N/A return jaxwsService.createDispatch(toSpec(),type,mode,features);
325N/A }
325N/A
325N/A /**
325N/A * Creates a {@link Dispatch} that can be used to talk to this EPR.
325N/A *
325N/A * <p>
325N/A * All the normal WS-Addressing processing happens automatically,
325N/A * such as setting the endpoint address to {@link #getAddress() the address},
325N/A * and sending the reference parameters associated with this EPR as
325N/A * headers, etc.
325N/A */
325N/A public @NotNull Dispatch<Object> createDispatch(
325N/A @NotNull Service jaxwsService,
325N/A @NotNull JAXBContext context,
325N/A @NotNull Service.Mode mode,
325N/A WebServiceFeature... features) {
325N/A
325N/A // TODO: implement it in a better way
325N/A return jaxwsService.createDispatch(toSpec(),context,mode,features);
325N/A }
325N/A
325N/A /**
325N/A * Gets the addressing version of this EPR.
325N/A */
325N/A public @NotNull AddressingVersion getVersion() {
325N/A return version;
325N/A }
325N/A
325N/A /**
325N/A * The value of the &lt;wsa:address> header.
325N/A */
325N/A public @NotNull String getAddress() {
325N/A return address;
325N/A }
325N/A
325N/A /**
325N/A * Returns true if this has anonymous URI as the {@link #getAddress() address}.
325N/A */
325N/A public boolean isAnonymous() {
325N/A return address.equals(version.anonymousUri);
325N/A }
325N/A
325N/A /**
325N/A * Returns true if this has {@link AddressingVersion#noneUri none URI}
325N/A * as the {@link #getAddress() address}.
325N/A */
325N/A public boolean isNone() {
325N/A return address.equals(version.noneUri);
325N/A }
325N/A
325N/A /**
325N/A * Parses inside EPR and mark all reference parameters.
325N/A */
325N/A private void parse() throws XMLStreamException {
325N/A // TODO: validate the EPR structure.
325N/A // check for non-existent Address, that sort of things.
325N/A
325N/A StreamReaderBufferProcessor xsr = infoset.readAsXMLStreamReader();
325N/A
325N/A // parser should be either at the start element or the start document
325N/A if(xsr.getEventType()==XMLStreamReader.START_DOCUMENT)
325N/A xsr.nextTag();
325N/A assert xsr.getEventType()==XMLStreamReader.START_ELEMENT;
325N/A
325N/A String rootLocalName = xsr.getLocalName();
325N/A if(!xsr.getNamespaceURI().equals(version.nsUri))
325N/A throw new WebServiceException(AddressingMessages.WRONG_ADDRESSING_VERSION(
325N/A version.nsUri, xsr.getNamespaceURI()));
325N/A
325N/A this.rootElement = new QName(xsr.getNamespaceURI(), rootLocalName);
325N/A
325N/A // since often EPR doesn't have a reference parameter, create array lazily
325N/A List<Header> marks=null;
325N/A
325N/A while(xsr.nextTag()==XMLStreamReader.START_ELEMENT) {
325N/A String localName = xsr.getLocalName();
325N/A if(version.isReferenceParameter(localName)) {
325N/A XMLStreamBuffer mark;
325N/A while((mark = xsr.nextTagAndMark())!=null) {
325N/A if(marks==null)
325N/A marks = new ArrayList<Header>();
325N/A
325N/A // TODO: need a different header for member submission version
325N/A marks.add(version.createReferenceParameterHeader(
325N/A mark, xsr.getNamespaceURI(), xsr.getLocalName()));
325N/A XMLStreamReaderUtil.skipElement(xsr);
325N/A }
325N/A } else
325N/A if(localName.equals("Address")) {
325N/A if(address!=null) // double <Address>. That's an error.
325N/A throw new InvalidAddressingHeaderException(new QName(version.nsUri,rootLocalName),AddressingVersion.fault_duplicateAddressInEpr);
325N/A address = xsr.getElementText().trim();
325N/A } else {
325N/A XMLStreamReaderUtil.skipElement(xsr);
325N/A }
325N/A }
325N/A
325N/A // hit to </EndpointReference> by now
325N/A
325N/A if(marks==null) {
325N/A this.referenceParameters = EMPTY_ARRAY;
325N/A } else {
325N/A this.referenceParameters = marks.toArray(new Header[marks.size()]);
325N/A }
325N/A
325N/A if(address==null)
325N/A throw new InvalidAddressingHeaderException(new QName(version.nsUri,rootLocalName),version.fault_missingAddressInEpr);
325N/A }
325N/A
325N/A
325N/A /**
325N/A * Reads this EPR as {@link XMLStreamReader}.
325N/A *
325N/A * @param localName
325N/A * EPR uses a different root tag name depending on the context.
325N/A * The returned {@link XMLStreamReader} will use the given local name
325N/A * for the root element name.
325N/A */
325N/A public XMLStreamReader read(final @NotNull String localName) throws XMLStreamException {
325N/A return new StreamReaderBufferProcessor(infoset) {
325N/A protected void processElement(String prefix, String uri, String _localName) {
325N/A if (_depth == 0)
325N/A _localName = localName;
325N/A super.processElement(prefix, uri, _localName);
325N/A }
325N/A };
325N/A }
325N/A
325N/A /**
325N/A * Returns a {@link Source} that represents this EPR.
325N/A *
325N/A * @param localName
325N/A * EPR uses a different root tag name depending on the context.
325N/A * The returned {@link Source} will use the given local name
325N/A * for the root element name.
325N/A */
325N/A public Source asSource(@NotNull String localName) {
325N/A return new SAXSource(new SAXBufferProcessorImpl(localName),new InputSource());
325N/A }
325N/A
325N/A /**
325N/A * Writes this EPR to the given {@link ContentHandler}.
325N/A *
325N/A * @param localName
325N/A * EPR uses a different root tag name depending on the context.
325N/A * The returned {@link Source} will use the given local name
325N/A * for the root element name.
325N/A * @param fragment
325N/A * If true, generate a fragment SAX events without start/endDocument callbacks.
325N/A * If false, generate a full XML document event.
325N/A */
325N/A public void writeTo(@NotNull String localName, ContentHandler contentHandler, ErrorHandler errorHandler, boolean fragment) throws SAXException {
325N/A SAXBufferProcessorImpl p = new SAXBufferProcessorImpl(localName);
325N/A p.setContentHandler(contentHandler);
325N/A p.setErrorHandler(errorHandler);
325N/A p.process(infoset,fragment);
325N/A }
325N/A
325N/A /**
325N/A * Writes this EPR into the given writer.
325N/A *
325N/A * @param localName
325N/A * EPR uses a different root tag name depending on the context.
325N/A * The returned {@link Source} will use the given local name
325N/A */
325N/A public void writeTo(final @NotNull String localName, @NotNull XMLStreamWriter w) throws XMLStreamException {
325N/A infoset.writeToXMLStreamWriter(new XMLStreamWriterFilter(w) {
325N/A private boolean root=true;
325N/A
325N/A @Override
325N/A public void writeStartDocument() throws XMLStreamException {
325N/A }
325N/A
325N/A @Override
325N/A public void writeStartDocument(String encoding, String version) throws XMLStreamException {
325N/A }
325N/A
325N/A @Override
325N/A public void writeStartDocument(String version) throws XMLStreamException {
325N/A }
325N/A
325N/A @Override
325N/A public void writeEndDocument() throws XMLStreamException {
325N/A }
325N/A
325N/A private String override(String ln) {
325N/A if(root) {
325N/A root = false;
325N/A return localName;
325N/A }
325N/A return ln;
325N/A }
325N/A
325N/A public void writeStartElement(String localName) throws XMLStreamException {
325N/A super.writeStartElement(override(localName));
325N/A }
325N/A
325N/A public void writeStartElement(String namespaceURI, String localName) throws XMLStreamException {
325N/A super.writeStartElement(namespaceURI, override(localName));
325N/A }
325N/A
325N/A public void writeStartElement(String prefix, String localName, String namespaceURI) throws XMLStreamException {
325N/A super.writeStartElement(prefix, override(localName), namespaceURI);
325N/A }
325N/A },true/*write as fragment*/);
325N/A }
325N/A
325N/A /**
325N/A * Returns a {@link Header} that wraps this {@link WSEndpointReference}.
325N/A *
325N/A * <p>
325N/A * The returned header is immutable too, and can be reused with
325N/A * many {@link Message}s.
325N/A *
325N/A * @param rootTagName
325N/A * The header tag name to be used, such as &lt;ReplyTo> or &lt;FaultTo>.
325N/A * (It's bit ugly that this method takes {@link QName} and not just local name,
325N/A * unlike other methods. If it's making the caller's life miserable, then
325N/A * we can talk.)
325N/A */
325N/A public Header createHeader(QName rootTagName) {
325N/A return new EPRHeader(rootTagName,this);
325N/A }
325N/A
325N/A /**
325N/A * Copies all the reference parameters in this EPR as headers
325N/A * to the given {@link HeaderList}.
325N/A */
325N/A public void addReferenceParameters(HeaderList outbound) {
325N/A for (Header header : referenceParameters) {
325N/A outbound.add(header);
325N/A }
325N/A }
325N/A
325N/A /**
325N/A * Dumps the EPR infoset in a human-readable string.
325N/A */
325N/A @Override
325N/A public String toString() {
325N/A try {
325N/A // debug convenience
325N/A StringWriter sw = new StringWriter();
325N/A XmlUtil.newTransformer().transform(asSource("EndpointReference"),new StreamResult(sw));
325N/A return sw.toString();
325N/A } catch (TransformerException e) {
325N/A return e.toString();
325N/A }
325N/A }
325N/A
325N/A /**
325N/A * Gets the QName of the EndpointReference element.
325N/A * @return
325N/A */
325N/A public QName getName() {
325N/A return rootElement;
325N/A }
325N/A
325N/A /**
325N/A * Filtering {@link SAXBufferProcessor} that replaces the root tag name.
325N/A */
325N/A class SAXBufferProcessorImpl extends SAXBufferProcessor {
325N/A private final String rootLocalName;
325N/A private boolean root=true;
325N/A
325N/A public SAXBufferProcessorImpl(String rootLocalName) {
325N/A super(infoset,false);
325N/A this.rootLocalName = rootLocalName;
325N/A }
325N/A
325N/A protected void processElement(String uri, String localName, String qName) throws SAXException {
325N/A if(root) {
325N/A root = false;
325N/A
325N/A if(qName.equals(localName)) {
325N/A qName = localName = rootLocalName;
325N/A } else {
325N/A localName = rootLocalName;
325N/A int idx = qName.indexOf(':');
325N/A qName = qName.substring(0,idx+1)+rootLocalName;
325N/A }
325N/A }
325N/A super.processElement(uri, localName, qName);
325N/A }
325N/A }
325N/A
325N/A private static final OutboundReferenceParameterHeader[] EMPTY_ARRAY = new OutboundReferenceParameterHeader[0];
325N/A
325N/A private Map<QName, EPRExtension> rootEprExtensions;
325N/A
325N/A /**
325N/A * Represents an extensibility element inside an EndpointReference
325N/A */
325N/A public static abstract class EPRExtension {
325N/A public abstract XMLStreamReader readAsXMLStreamReader() throws XMLStreamException;
325N/A
325N/A public abstract QName getQName();
325N/A }
325N/A
325N/A /**
325N/A * Returns the first extensibility element inside EPR root element with input QName.
325N/A */
325N/A public @Nullable
325N/A EPRExtension getEPRExtension(final QName extnQName) throws XMLStreamException {
325N/A if (rootEprExtensions == null)
325N/A parseEPRExtensions();
325N/A return rootEprExtensions.get(extnQName);
325N/A }
325N/A
325N/A public @NotNull Collection<EPRExtension> getEPRExtensions() throws XMLStreamException {
325N/A if (rootEprExtensions == null)
325N/A parseEPRExtensions();
325N/A return rootEprExtensions.values();
325N/A }
325N/A
325N/A private void parseEPRExtensions() throws XMLStreamException {
325N/A
325N/A rootEprExtensions = new HashMap<QName, EPRExtension>();
325N/A
325N/A
325N/A StreamReaderBufferProcessor xsr = infoset.readAsXMLStreamReader();
325N/A
325N/A // parser should be either at the start element or the start document
325N/A if (xsr.getEventType() == XMLStreamReader.START_DOCUMENT)
325N/A xsr.nextTag();
325N/A assert xsr.getEventType() == XMLStreamReader.START_ELEMENT;
325N/A
325N/A String rootLocalName = xsr.getLocalName();
325N/A if (!xsr.getNamespaceURI().equals(version.nsUri))
325N/A throw new WebServiceException(AddressingMessages.WRONG_ADDRESSING_VERSION(
325N/A version.nsUri, xsr.getNamespaceURI()));
325N/A
325N/A // since often EPR doesn't have extensions, create array lazily
325N/A XMLStreamBuffer mark;
325N/A String localName;
325N/A String ns;
325N/A while ((mark = xsr.nextTagAndMark()) != null) {
325N/A localName = xsr.getLocalName();
325N/A ns = xsr.getNamespaceURI();
325N/A if (version.nsUri.equals(ns)) {
325N/A //EPR extensions do not use the same namespace of the Addressing Version.
325N/A //Not an extension - SKIP
325N/A XMLStreamReaderUtil.skipElement(xsr);
325N/A } else {
325N/A QName qn = new QName(ns, localName);
325N/A rootEprExtensions.put(qn, new WSEPRExtension(mark,qn));
325N/A XMLStreamReaderUtil.skipElement(xsr);
325N/A }
325N/A }
325N/A // hit to </EndpointReference> by now
325N/A }
325N/A
325N/A /**
325N/A * Parses the metadata inside this EPR and obtains it in a easy-to-process form.
325N/A *
325N/A * <p>
325N/A * See {@link Metadata} class for what's avaliable as "metadata".
325N/A */
325N/A public @NotNull Metadata getMetaData() {
325N/A return new Metadata();
325N/A }
325N/A
325N/A /**
325N/A * Parses the Metadata in an EPR and provides convenience methods to access
325N/A * the metadata.
325N/A *
325N/A */
325N/A public class Metadata {
325N/A private @Nullable QName serviceName;
325N/A private @Nullable QName portName;
325N/A private @Nullable QName portTypeName; //interfaceName
325N/A private @Nullable Source wsdlSource;
325N/A private @Nullable String wsdliLocation;
325N/A
325N/A public @Nullable QName getServiceName(){
325N/A return serviceName;
325N/A }
325N/A public @Nullable QName getPortName(){
325N/A return portName;
325N/A }
325N/A public @Nullable QName getPortTypeName(){
325N/A return portTypeName;
325N/A }
325N/A public @Nullable Source getWsdlSource(){
325N/A return wsdlSource;
325N/A }
325N/A public @Nullable String getWsdliLocation(){
325N/A return wsdliLocation;
325N/A }
325N/A
325N/A private Metadata() {
325N/A try {
325N/A parseMetaData();
325N/A } catch (XMLStreamException e) {
325N/A throw new WebServiceException(e);
325N/A }
325N/A }
325N/A
325N/A /**
325N/A * Parses the Metadata section of the EPR.
325N/A */
325N/A private void parseMetaData() throws XMLStreamException {
325N/A StreamReaderBufferProcessor xsr = infoset.readAsXMLStreamReader();
325N/A
325N/A // parser should be either at the start element or the start document
325N/A if (xsr.getEventType() == XMLStreamReader.START_DOCUMENT)
325N/A xsr.nextTag();
325N/A assert xsr.getEventType() == XMLStreamReader.START_ELEMENT;
325N/A String rootElement = xsr.getLocalName();
325N/A if (!xsr.getNamespaceURI().equals(version.nsUri))
325N/A throw new WebServiceException(AddressingMessages.WRONG_ADDRESSING_VERSION(
325N/A version.nsUri, xsr.getNamespaceURI()));
325N/A String localName;
325N/A String ns;
325N/A if (version == AddressingVersion.W3C) {
325N/A do {
325N/A //If the current element is metadata enclosure, look inside
325N/A if (xsr.getLocalName().equals(version.eprType.wsdlMetadata.getLocalPart())) {
325N/A String wsdlLoc = xsr.getAttributeValue("http://www.w3.org/ns/wsdl-instance","wsdlLocation");
325N/A if (wsdlLoc != null)
325N/A wsdliLocation = wsdlLoc.trim();
325N/A XMLStreamBuffer mark;
325N/A while ((mark = xsr.nextTagAndMark()) != null) {
325N/A localName = xsr.getLocalName();
325N/A ns = xsr.getNamespaceURI();
325N/A if (localName.equals(version.eprType.serviceName)) {
325N/A String portStr = xsr.getAttributeValue(null, version.eprType.portName);
325N/A if(serviceName != null)
325N/A throw new RuntimeException("More than one "+ version.eprType.serviceName +" element in EPR Metadata");
325N/A serviceName = getElementTextAsQName(xsr);
325N/A if (serviceName != null && portStr != null)
325N/A portName = new QName(serviceName.getNamespaceURI(), portStr);
325N/A } else if (localName.equals(version.eprType.portTypeName)) {
325N/A if(portTypeName != null)
325N/A throw new RuntimeException("More than one "+ version.eprType.portTypeName +" element in EPR Metadata");
325N/A portTypeName = getElementTextAsQName(xsr);
325N/A } else if (ns.equals(WSDLConstants.NS_WSDL)
325N/A && localName.equals(WSDLConstants.QNAME_DEFINITIONS.getLocalPart())) {
325N/A wsdlSource = new XMLStreamBufferSource(mark);
325N/A } else {
325N/A XMLStreamReaderUtil.skipElement(xsr);
325N/A }
325N/A }
325N/A } else {
325N/A //Skip is it is not root element
325N/A if (!xsr.getLocalName().equals(rootElement))
325N/A XMLStreamReaderUtil.skipElement(xsr);
325N/A }
325N/A } while (XMLStreamReaderUtil.nextElementContent(xsr) == XMLStreamReader.START_ELEMENT);
325N/A
325N/A if(wsdliLocation != null) {
325N/A String wsdlLocation = wsdliLocation.trim();
325N/A wsdlLocation = wsdlLocation.substring(wsdliLocation.lastIndexOf(" "));
325N/A wsdlSource = new StreamSource(wsdlLocation);
325N/A }
325N/A } else if (version == AddressingVersion.MEMBER) {
325N/A do {
325N/A localName = xsr.getLocalName();
325N/A ns = xsr.getNamespaceURI();
325N/A //If the current element is metadata enclosure, look inside
325N/A if (localName.equals(version.eprType.wsdlMetadata.getLocalPart()) &&
325N/A ns.equals(version.eprType.wsdlMetadata.getNamespaceURI())) {
325N/A while (xsr.nextTag() == XMLStreamReader.START_ELEMENT) {
325N/A XMLStreamBuffer mark;
325N/A while ((mark = xsr.nextTagAndMark()) != null) {
325N/A localName = xsr.getLocalName();
325N/A ns = xsr.getNamespaceURI();
325N/A if (ns.equals(WSDLConstants.NS_WSDL)
325N/A && localName.equals(WSDLConstants.QNAME_DEFINITIONS.getLocalPart())) {
325N/A wsdlSource = new XMLStreamBufferSource(mark);
325N/A } else {
325N/A XMLStreamReaderUtil.skipElement(xsr);
325N/A }
325N/A }
325N/A }
325N/A } else if (localName.equals(version.eprType.serviceName)) {
325N/A String portStr = xsr.getAttributeValue(null, version.eprType.portName);
325N/A serviceName = getElementTextAsQName(xsr);
325N/A if (serviceName != null && portStr != null)
325N/A portName = new QName(serviceName.getNamespaceURI(), portStr);
325N/A } else if (localName.equals(version.eprType.portTypeName)) {
325N/A portTypeName = getElementTextAsQName(xsr);
325N/A } else {
325N/A //Skip is it is not root element
325N/A if (!xsr.getLocalName().equals(rootElement))
325N/A XMLStreamReaderUtil.skipElement(xsr);
325N/A }
325N/A } while (XMLStreamReaderUtil.nextElementContent(xsr) == XMLStreamReader.START_ELEMENT);
325N/A }
325N/A }
325N/A
325N/A private QName getElementTextAsQName(StreamReaderBufferProcessor xsr) throws XMLStreamException {
325N/A String text = xsr.getElementText().trim();
325N/A String prefix = XmlUtil.getPrefix(text);
325N/A String name = XmlUtil.getLocalPart(text);
325N/A if (name != null) {
325N/A if (prefix != null) {
325N/A String ns = xsr.getNamespaceURI(prefix);
325N/A if (ns != null)
325N/A return new QName(ns, name, prefix);
325N/A } else {
325N/A return new QName(null, name);
325N/A }
325N/A }
325N/A return null;
325N/A }
325N/A }
325N/A}