1 17 package org.apache.servicemix.http; 18 19 import javax.jbi.servicedesc.ServiceEndpoint; 20 import javax.xml.namespace.QName ; 21 22 import org.apache.servicemix.jbi.util.DOMUtil; 23 import org.w3c.dom.DocumentFragment ; 24 import org.w3c.dom.Element ; 25 import org.w3c.dom.Node ; 26 import org.w3c.dom.NodeList ; 27 28 public class HttpResolvedEndpoint implements ServiceEndpoint { 29 30 public final static String EPR_URI = "urn:servicemix:http"; 31 public final static QName EPR_SERVICE = new QName (EPR_URI, "HttpComponent"); 32 public final static String EPR_NAME = "epr"; 33 34 private DocumentFragment reference; 35 private String epName; 36 37 public HttpResolvedEndpoint(DocumentFragment epr, String epName) { 38 this.reference = epr; 39 this.epName = epName; 40 } 41 42 public DocumentFragment getAsReference(QName operationName) { 43 return reference; 44 } 45 46 public String getEndpointName() { 47 return epName; 48 } 49 50 public QName [] getInterfaces() { 51 return null; 52 } 53 54 public QName getServiceName() { 55 return EPR_SERVICE; 56 } 57 58 public static ServiceEndpoint resolveEndpoint(DocumentFragment epr) { 59 if (epr.getChildNodes().getLength() == 1) { 60 Node child = epr.getFirstChild(); 61 if (child instanceof Element ) { 62 Element elem = (Element ) child; 63 String nsUri = elem.getNamespaceURI(); 64 String name = elem.getLocalName(); 65 if (HttpResolvedEndpoint.EPR_URI.equals(nsUri) && HttpResolvedEndpoint.EPR_NAME.equals(name)) { 67 return new HttpResolvedEndpoint(epr, DOMUtil.getElementText(elem)); 68 } else { 70 NodeList nl = elem.getElementsByTagNameNS("http://www.w3.org/2005/08/addressing", "Address"); 71 if (nl.getLength() == 1) { 72 Element address = (Element ) nl.item(0); 73 String uri = DOMUtil.getElementText(address); 74 if (uri != null) { 75 uri = uri.trim(); 76 if (uri.startsWith("http://") || uri.startsWith("https://")) { 77 return new HttpResolvedEndpoint(epr, uri); 78 } 79 } 80 } 81 } 82 } 83 } 84 return null; 85 } 86 87 } | Popular Tags |