1 25 26 package org.objectweb.jonas.examples.clients.webservices; 27 28 import java.io.File ; 29 import java.io.FileInputStream ; 30 import java.util.Properties ; 31 32 import javax.wsdl.Definition; 33 import javax.wsdl.Port; 34 import javax.wsdl.Service; 35 import javax.wsdl.extensions.soap.SOAPAddress; 36 import javax.wsdl.factory.WSDLFactory; 37 import javax.wsdl.xml.WSDLReader; 38 import javax.xml.namespace.QName ; 39 40 import com.meterware.httpunit.WebForm; 41 import com.meterware.httpunit.WebLink; 42 import com.meterware.httpunit.WebResponse; 43 44 49 public abstract class A_WebServicesEndpoint extends A_WebServices { 50 51 54 private static final String JPROP_WSDL_LOCATION = "jonas.service.publish.file.directory"; 55 56 public A_WebServicesEndpoint(String s, String urlPrefix) { 57 super(s, urlPrefix); 58 } 59 60 66 public void checkAxisServicesAccessible(int idServicesLink, String context, String portName) throws Exception { 67 68 WebResponse wr = wc.getResponse(url + "index.html"); 69 WebLink services = wr.getLinks()[idServicesLink]; 70 71 WebResponse swr = services.click(); 73 74 boolean found = false; 76 for (int i = 0; i < swr.getLinks().length; i++) { 77 String ws_url = swr.getLinks()[i].getURLString(); 78 if (ws_url.equalsIgnoreCase(url + portName + "/" + portName + "?jwsdl")) 79 found = true; 80 } 81 if (!found) 82 fail("endpoint '" + portName + "' not found in /" + context); 83 84 } 85 86 92 public void checkAxisWSDL(String path) throws Exception { 93 94 WebResponse wr = wc.getResponse(url + path); 95 assertEquals("Must be an XML mime type", "text/xml", wr.getContentType()); 96 97 } 98 99 107 public void checkDeployedWebService(String formPage, 108 String endpoint, 109 String name, 110 String pageTitle) throws Exception { 111 112 WebResponse wr = wc.getResponse(url + formPage); 114 115 WebForm form = wr.getFormWithName("prepare"); 117 form.setParameter("endpoint", endpoint); 119 form.setParameter("name", name); 120 WebResponse wr2 = form.submit(); 122 123 String text = wr2.getText(); 124 125 String valTitle = "<title>" + pageTitle + "</title>"; 126 String valURL = "Working with URL : <i>" + endpoint + "</i><br/>"; 127 String valHello = "<b>result of sayHello(name) method :</b><i>Hello " + name + "</i><br/>"; 128 String valQuotes = "<b>result of getCotes() method :</b><i>12</i><br/>"; 129 boolean testOK = false; 130 131 if ((text.indexOf(valTitle) != -1) 132 && (text.indexOf(valURL) != -1) 133 && (text.indexOf(valHello) != -1) 134 && (text.indexOf(valQuotes) != -1)) { 135 testOK = true; 136 } 137 138 if (!testOK) { 139 fail("Call fails"); 140 } 141 142 } 143 144 145 154 public void checkWSDLPublication(String wsdlFilename, 155 String tns, 156 String serviceName, 157 String portName, 158 String endpoint) throws Exception { 159 160 String jonasbase = System.getProperty("jonas.base"); 161 Properties props = new Properties (); 162 props.load(new FileInputStream (new File (jonasbase, "conf/file1.properties"))); 163 String wsdlLoc = props.getProperty(JPROP_WSDL_LOCATION); 164 165 File wsdl = new File (wsdlLoc, wsdlFilename); 166 167 assertTrue("WSDL is not created", wsdl.exists()); 168 assertTrue("WSDL is not a file", wsdl.isFile()); 169 170 WSDLFactory f = WSDLFactory.newInstance(); 171 WSDLReader r = f.newWSDLReader(); 172 173 r.setFeature("javax.wsdl.verbose", true); 174 r.setFeature("javax.wsdl.importDocuments", false); 175 176 Definition def = r.readWSDL(wsdl.getPath()); 177 Service s = def.getService(new QName (tns, serviceName)); 178 Port p = s.getPort(portName); 179 SOAPAddress sa = (SOAPAddress) p.getExtensibilityElements().get(0); 180 181 assertEquals("URL has not been updated", endpoint, sa.getLocationURI()); 182 183 } 184 185 186 } 187 | Popular Tags |