1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233
|
/*
* JBoss, Home of Professional Open Source
* Copyright 2005, JBoss Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.wsf.test;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Hashtable;
import javax.management.MBeanServerConnection;
import javax.management.ObjectName;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.xml.namespace.QName;
import javax.xml.transform.Source;
import javax.xml.ws.Service;
import javax.xml.ws.Service.Mode;
import javax.xml.ws.soap.SOAPBinding;
import org.jboss.logging.Logger;
import org.jboss.wsf.common.ObjectNameFactory;
/**
* A JBossWS test helper that deals with test deployment/undeployment, etc.
*
* @author Thomas.Diesler@jboss.org
* @since 14-Oct-2004
*/
public class JBossWSTestHelper
{
// provide logging
private static Logger log = Logger.getLogger(JBossWSTestHelper.class);
private static MBeanServerConnection server;
private static String integrationTarget;
private static String implVendor;
private static String implTitle;
private static String implVersion;
/** Deploy the given archive
*/
public void deploy(String archive) throws Exception
{
URL url = getArchiveURL(archive);
getDeployer().deploy(url);
}
/** Undeploy the given archive
*/
public void undeploy(String archive) throws Exception
{
URL url = getArchiveURL(archive);
getDeployer().undeploy(url);
}
/** True, if -Djbossws.integration.target=jboss50x */
public boolean isTargetJBoss50()
{
String target = getIntegrationTarget();
return target.startsWith("jboss50");
}
/** True, if -Djbossws.integration.target=jboss42x */
public boolean isTargetJBoss42()
{
String target = getIntegrationTarget();
return target.startsWith("jboss42");
}
/** True, if -Djbossws.integration.target=jboss40x */
public boolean isTargetJBoss40()
{
String target = getIntegrationTarget();
return target.startsWith("jboss40");
}
public boolean isIntegrationNative()
{
String vendor = getImplementationVendor();
return vendor.indexOf("JBoss") != -1;
}
public boolean isIntegrationSunRI()
{
String vendor = getImplementationVendor();
return vendor.indexOf("Sun") != -1;
}
public boolean isIntegrationCXF()
{
String vendor = getImplementationVendor();
return vendor.indexOf("Apache") != -1;
}
private String getImplementationVendor()
{
if (implVendor == null)
{
Service service = Service.create(new QName("dummyService"));
Object obj = service.getHandlerResolver();
if (obj == null)
{
service.addPort(new QName("dummyPort"), SOAPBinding.SOAP11HTTP_BINDING, "http://dummy-address");
obj = service.createDispatch(new QName("dummyPort"), Source.class, Mode.PAYLOAD);
}
implVendor = obj.getClass().getPackage().getImplementationVendor();
implTitle = obj.getClass().getPackage().getImplementationTitle();
implVersion = obj.getClass().getPackage().getImplementationVersion();
System.out.println(implVendor + ", " + implTitle + ", " + implVersion);
}
return implVendor;
}
/**
* Get the JBoss server host from system property "jboss.bind.address"
* This defaults to "localhost"
*/
public static String getServerHost()
{
String hostName = System.getProperty("jboss.bind.address", "localhost");
return hostName;
}
public static MBeanServerConnection getServer()
{
if (server == null)
{
Hashtable jndiEnv = null;
try
{
InitialContext iniCtx = new InitialContext();
jndiEnv = iniCtx.getEnvironment();
server = (MBeanServerConnection)iniCtx.lookup("jmx/invoker/RMIAdaptor");
}
catch (NamingException ex)
{
throw new RuntimeException("Cannot obtain MBeanServerConnection using jndi props: " + jndiEnv, ex);
}
}
return server;
}
private TestDeployer getDeployer()
{
return new TestDeployerJBoss(getServer());
}
public String getIntegrationTarget()
{
if (integrationTarget == null)
{
integrationTarget = System.getProperty("jbossws.integration.target");
if (integrationTarget == null)
throw new IllegalStateException("Cannot obtain jbossws.integration.target");
// Read the JBoss SpecificationVersion
String jbossVersion = null;
try
{
ObjectName oname = ObjectNameFactory.create("jboss.system:type=ServerConfig");
jbossVersion = (String)getServer().getAttribute(oname, "SpecificationVersion");
if (jbossVersion.startsWith("5.0"))
jbossVersion = "jboss50";
else if (jbossVersion.startsWith("4.2"))
jbossVersion = "jboss42";
else if (jbossVersion.startsWith("4.0"))
jbossVersion = "jboss40";
else throw new RuntimeException("Unsupported jboss version: " + jbossVersion);
}
catch (Throwable th)
{
// ignore, we are not running on jboss-4.2 or greater
}
if (jbossVersion != null && integrationTarget.startsWith(jbossVersion) == false)
throw new IllegalStateException("Integration target mismatch, using: " + jbossVersion);
}
return integrationTarget;
}
/** Try to discover the URL for the deployment archive */
public URL getArchiveURL(String archive) throws MalformedURLException
{
URL url = null;
try
{
url = new URL(archive);
}
catch (MalformedURLException ignore)
{
// ignore
}
if (url == null)
{
File file = new File(archive);
if (file.exists())
url = file.toURL();
}
if (url == null)
{
File file = new File("libs/" + archive);
if (file.exists())
url = file.toURL();
}
if (url == null)
throw new IllegalArgumentException("Cannot obtain URL for: " + archive);
return url;
}
}
|