1 7 8 package org.jboss.webservice.client; 10 11 13 import org.jboss.deployment.DeploymentInfo; 14 import org.jboss.mx.util.MBeanServerLocator; 15 import org.jboss.webservice.AxisServiceMBean; 16 import org.jboss.webservice.metadata.serviceref.PortComponentRefMetaData; 17 import org.jboss.webservice.metadata.serviceref.ServiceRefMetaData; 18 19 import javax.management.MBeanServer ; 20 import javax.naming.BinaryRefAddr ; 21 import javax.naming.NamingException ; 22 import javax.naming.Reference ; 23 import javax.naming.Referenceable ; 24 import javax.naming.StringRefAddr ; 25 import java.io.ByteArrayOutputStream ; 26 import java.io.IOException ; 27 import java.io.ObjectOutputStream ; 28 import java.net.URL ; 29 30 39 public class ServiceReferenceable implements Referenceable 40 { 41 public static final String SERVICE_REF_META_DATA = "SERVICE_REF_META_DATA"; 42 public static final String DEPLOYMENT_URL = "DEPLOYMENT_URL"; 43 public static final String PORT_COMPONENT_LINK = "PORT_COMPONENT_LINK"; 44 public static final String PORT_COMPONENT_LINK_SERVLET = "PORT_COMPONENT_LINK_SERVLET"; 45 46 private ServiceRefMetaData refMetaData; 48 private DeploymentInfo di; 50 51 57 public ServiceReferenceable(ServiceRefMetaData refMetaData, DeploymentInfo di) 58 { 59 this.refMetaData = refMetaData; 60 this.di = di; 61 } 62 63 69 public Reference getReference() throws NamingException 70 { 71 Reference myRef = new Reference (ServiceReferenceable.class.getName(), ServiceObjectFactory.class.getName(), null); 72 73 URL deploymentURL = (di.localUrl != null ? di.localUrl : di.url); 75 myRef.add(new StringRefAddr (DEPLOYMENT_URL, deploymentURL.toExternalForm())); 76 77 myRef.add(new BinaryRefAddr (SERVICE_REF_META_DATA, marshallServiceRef())); 79 80 PortComponentRefMetaData[] pcrArr = refMetaData.getPortComponentRefs(); 82 for (int i = 0; i < pcrArr.length; i++) 83 { 84 PortComponentRefMetaData pcr = pcrArr[i]; 85 String pcLink = pcr.getPortComponentLink(); 86 if (pcLink != null) 87 { 88 String deploymentName = di.getCanonicalName(); 89 90 int hashIndex = pcLink.indexOf("#"); 91 if (hashIndex > 0) 92 { 93 deploymentName = pcLink.substring(0, hashIndex); 94 pcLink = pcLink.substring(hashIndex + 1); 95 while (deploymentName.startsWith(".") || deploymentName.startsWith("/")) 96 deploymentName = deploymentName.substring(1); 97 } 98 99 String serviceID = deploymentName + "#" + pcLink; 100 myRef.add(new StringRefAddr (PORT_COMPONENT_LINK, serviceID)); 101 102 try 103 { 104 MBeanServer server = MBeanServerLocator.locateJBoss(); 105 String host = (String )server.getAttribute(AxisServiceMBean.OBJECT_NAME, "WebServiceHost"); 106 int port = ((Integer )server.getAttribute(AxisServiceMBean.OBJECT_NAME, "WebServicePort")).intValue(); 107 108 String servletURL = "http://" + host + ":" + port + "/ws4ee/pclink"; 109 myRef.add(new StringRefAddr (PORT_COMPONENT_LINK_SERVLET, servletURL)); 110 } 111 catch (Exception e) 112 { 113 throw new NamingException ("Cannot obtain path to PortComponentLinkServlet, cause is " + e); 114 } 115 } 116 } 117 118 return myRef; 119 } 120 121 124 private byte[] marshallServiceRef() throws NamingException 125 { 126 ByteArrayOutputStream baos = new ByteArrayOutputStream (512); 128 try 129 { 130 ObjectOutputStream oos = new ObjectOutputStream (baos); 131 oos.writeObject(refMetaData); 132 oos.close(); 133 } 134 catch (IOException e) 135 { 136 throw new NamingException ("Cannot marshall_01 service ref meta data, cause: " + e.toString()); 137 } 138 return baos.toByteArray(); 139 } 140 } 141 | Popular Tags |