Skip to content

Package: InstalledCargoApplicationContainer

InstalledCargoApplicationContainer

nameinstructionbranchcomplexitylinemethod
InstalledCargoApplicationContainer(WsTool, WsTool, String, File, int, boolean)
M: 260 C: 0
0%
M: 10 C: 0
0%
M: 6 C: 0
0%
M: 51 C: 0
0%
M: 1 C: 0
0%
assembleWar(DeployedService)
M: 20 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
getPort()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
toString()
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*
2: * Copyright (c) 1997, 2020 Oracle and/or its affiliates. All rights reserved.
3: *
4: * This program and the accompanying materials are made available under the
5: * terms of the Eclipse Distribution License v. 1.0, which is available at
6: * http://www.eclipse.org/org/documents/edl-v10.php.
7: *
8: * SPDX-License-Identifier: BSD-3-Clause
9: */
10:
11: package com.sun.xml.ws.test.container.cargo;
12:
13: import com.sun.xml.ws.test.World;
14: import com.sun.xml.ws.test.container.ApplicationContainer;
15: import com.sun.xml.ws.test.container.DeployedService;
16: import com.sun.xml.ws.test.container.WAR;
17: import com.sun.xml.ws.test.container.cargo.gf.GlassfishPropertySet;
18: import com.sun.xml.ws.test.tool.WsTool;
19: import com.sun.xml.ws.test.util.FileUtil;
20: import org.codehaus.cargo.container.ContainerType;
21: import org.codehaus.cargo.container.InstalledLocalContainer;
22: import org.codehaus.cargo.container.configuration.ConfigurationType;
23: import org.codehaus.cargo.container.configuration.LocalConfiguration;
24: import org.codehaus.cargo.container.property.ServletPropertySet;
25: import org.codehaus.cargo.generic.AbstractFactoryRegistry;
26: import org.codehaus.cargo.generic.DefaultContainerFactory;
27: import org.codehaus.cargo.generic.configuration.ConfigurationFactory;
28: import org.codehaus.cargo.generic.configuration.DefaultConfigurationFactory;
29:
30: import java.io.File;
31: import java.io.IOException;
32: import java.util.HashMap;
33: import java.util.Map;
34: import javax.net.ssl.HostnameVerifier;
35: import javax.net.ssl.HttpsURLConnection;
36: import javax.net.ssl.SSLSession;
37: import org.apache.tools.ant.Project;
38: import org.apache.tools.ant.taskdefs.Zip;
39: import org.codehaus.cargo.container.property.GeneralPropertySet;
40: import org.codehaus.cargo.container.tomcat.TomcatPropertySet;
41:
42: /**
43: * {@link ApplicationContainer} that launches a container from within the harness.
44: *
45: * <p>
46: * This uses an image of the container installed locally, but
47: * this operation does not affect the data file and configuration
48: * files in that installation, so you need not have an installation
49: * dedicated to this test harness.
50: *
51: * @author Kohsuke Kawaguchi
52: */
53: public class InstalledCargoApplicationContainer extends AbstractRunnableCargoContainer<InstalledLocalContainer> {
54: /**
55: *
56: * @param containerId
57: * The ID that represents the container. "tomcat5x" for Tomcat.
58: * @param homeDir
59: * The installation of the container. For Tomcat, this is
60: */
61: public InstalledCargoApplicationContainer(WsTool wsimport, WsTool wsgen, String containerId, File homeDir, int port, boolean httpspi) throws IOException {
62: super(wsimport,wsgen,port,httpspi);
63:
64: // needed until glassfish becomes a part of Cargo
65:
66: ConfigurationFactory configurationFactory = new DefaultConfigurationFactory(AbstractFactoryRegistry.class.getClassLoader());
67: // For tomcat local, cargo doesn't copy shared/lib jars to working dir
68: // configurationFactory.registerConfiguration("tomcat5x", ContainerType.INSTALLED, ConfigurationType.STANDALONE, Tomcat5xMetroStandaloneLocalConfiguration.class);
69:
70: DefaultContainerFactory containerFactory = new DefaultContainerFactory(AbstractFactoryRegistry.class.getClassLoader());
71:
72: File containerWorkDir = FileUtil.createTmpDir(true);
73: containerWorkDir.mkdirs();
74: System.out.println("Container working directory: "+containerWorkDir);
75:
76: LocalConfiguration configuration =
77: (LocalConfiguration) configurationFactory.createConfiguration(
78: containerId, ContainerType.INSTALLED, ConfigurationType.STANDALONE,
79: containerWorkDir.getAbsolutePath());
80:
81: configuration.setProperty(ServletPropertySet.PORT, Integer.toString(httpPort));
82: configuration.setProperty(GeneralPropertySet.RMI_PORT, getPort());
83: // configuration.setLogger(new SimpleLogger());
84:
85: // In case this is Glassfish, override all the other TCP ports
86: // so that multiple test runs can co-exist on the same machine
87: configuration.setProperty(GlassfishPropertySet.JMS_PORT, getPort());
88: configuration.setProperty(GlassfishPropertySet.IIOP_PORT, getPort());
89: configuration.setProperty(GlassfishPropertySet.HTTPS_PORT, getPort());
90: configuration.setProperty(GlassfishPropertySet.IIOPS_PORT, getPort());
91: configuration.setProperty(GlassfishPropertySet.IIOP_MUTUAL_AUTH_PORT, getPort());
92: configuration.setProperty(GlassfishPropertySet.JMX_ADMIN_PORT, getPort());
93: configuration.setProperty(GlassfishPropertySet.ADMIN_PORT, getPort());
94:
95:• if (containerId.startsWith("tomcat")) {
96: configuration.setProperty(TomcatPropertySet.AJP_PORT, getPort());
97:
98:• if (Boolean.getBoolean("harness.useSSL")) {
99: configuration.setProperty(GeneralPropertySet.PROTOCOL, "https");
100: configuration.setProperty(TomcatPropertySet.HTTP_SECURE, "true");
101: configuration.setProperty(TomcatPropertySet.CONNECTOR_KEY_STORE_FILE, new File(System.getProperty("harness.ssl.home"), "server-keystore.jks").getAbsolutePath());
102: configuration.setProperty(TomcatPropertySet.CONNECTOR_KEY_STORE_PASSWORD, "changeit");
103: configuration.setProperty(TomcatPropertySet.CONNECTOR_KEY_STORE_TYPE, "JKS");
104: configuration.setProperty(TomcatPropertySet.CONNECTOR_TRUST_STORE_FILE, new File(System.getProperty("harness.ssl.home"), "server-truststore.jks").getAbsolutePath());
105: configuration.setProperty(TomcatPropertySet.CONNECTOR_TRUST_STORE_PASSWORD, "changeit");
106: configuration.setProperty(TomcatPropertySet.CONNECTOR_TRUST_STORE_TYPE, "JKS");
107:
108: HostnameVerifier hv = new HostnameVerifier() {
109: public boolean verify(String urlHostName, SSLSession session) {
110: System.out.println("Warning: got: '" + urlHostName
111: + "' expected '" + session.getPeerHost() + "'");
112: return true;
113: }
114: };
115: HttpsURLConnection.setDefaultHostnameVerifier(hv);
116: }
117: }
118:
119: // TODO: we should provide a mode to launch the container with debugger
120:
121: container = (InstalledLocalContainer) containerFactory.createContainer(
122: containerId, ContainerType.INSTALLED, configuration);
123: container.setHome(homeDir.getAbsolutePath());
124: container.setOutput(containerWorkDir.getAbsolutePath() + File.separatorChar + "server.log");
125:
126: Map<String, String> props = new HashMap<String, String>();
127: props.put("WSIT_HOME", System.getProperty("WSIT_HOME"));
128: // props.put("com.sun.xml.ws.transport.local.LocalTransportTube.dump", "true");
129: // props.put("com.sun.xml.ws.transport.http.client.HttpTransportPipe.dump", "true");
130: // props.put("com.sun.xml.ws.transport.http.HttpAdapter.dump", "true");
131: container.setSystemProperties(props);
132:
133:• for (File f : World.runtime.list()) {
134:• if (f.getName().endsWith(".jar")) {
135: container.addExtraClasspath(f.getAbsolutePath());
136: } else {
137:• if ("classes".equals(f.getName())) {
138: String fName = f.getParentFile().getParentFile().getName();
139: File jar = new File(new File(System.getProperty("java.io.tmpdir")), fName + System.currentTimeMillis() + ".jar");
140: jar.deleteOnExit();
141: Zip zip = new Zip();
142: zip.setProject(new Project());
143: zip.setDestFile(jar);
144: zip.setBasedir(f);
145: zip.execute();
146: container.addExtraClasspath(jar.getAbsolutePath());
147: }
148: }
149: }
150:
151: }
152:
153: /**
154: * For tomcat local, since cargo doesn't support copying of shared/lib jars,
155: * the war can be created with the jars in the WEB-INF/lib. Other option is
156: * to subclass Tomcat5xStandaloneLocalConfiguration and do the copying of
157: * jars from Tomcat installation to local working dir in doConfigure()
158: *
159: * Copy JAX-WS runtime code?
160: *
161: protected boolean copyRuntimeLibraries() {
162: return false;
163: }
164: */
165:
166: @Override
167: public String toString() {
168: return "CargoLocalContainer:"+container.getId();
169: }
170:
171: private String getPort() {
172: return String.valueOf(AbstractRunnableCargoContainer.getFreePort());
173: }
174:
175: @Override
176: protected WAR assembleWar(DeployedService service) throws Exception {
177: WAR war = super.assembleWar(service);
178:• if (service.service.isSTS) {
179: updateWsitClient(war, service, getServiceUrl(service.service.getGlobalUniqueName()).toExternalForm());
180: }
181: return war;
182: }
183:
184:
185: }