Skip to content

Package: AbstractApplicationContainer

AbstractApplicationContainer

nameinstructionbranchcomplexitylinemethod
AbstractApplicationContainer(WsTool, WsTool, boolean)
M: 17 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 6 C: 0
0%
M: 1 C: 0
0%
assembleWar(DeployedService)
M: 140 C: 0
0%
M: 16 C: 0
0%
M: 9 C: 0
0%
M: 36 C: 0
0%
M: 1 C: 0
0%
copyRuntimeLibraries()
M: 2 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
createWARZip(DeployedService, File)
M: 21 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 7 C: 0
0%
M: 1 C: 0
0%
getExternalMetadataFiles(TestService)
M: 45 C: 0
0%
M: 8 C: 0
0%
M: 5 C: 0
0%
M: 8 C: 0
0%
M: 1 C: 0
0%
getUnsupportedUses()
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%
isSkipMode()
M: 12 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
updateWsgenOpts(TestService)
M: 30 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 6 C: 0
0%
M: 1 C: 0
0%
updateWsitClient(WAR, DeployedService, String)
M: 34 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 7 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*
2: * Copyright (c) 1997, 2022 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;
12:
13: import com.sun.istack.NotNull;
14: import com.sun.xml.ws.test.World;
15: import com.sun.xml.ws.test.container.jelly.EndpointInfoBean;
16: import com.sun.xml.ws.test.model.TestService;
17: import com.sun.xml.ws.test.tool.WsTool;
18: import com.sun.xml.ws.test.util.WSITUtil;
19:
20: import java.io.File;
21: import java.io.FileWriter;
22: import java.io.PrintWriter;
23: import java.util.ArrayList;
24: import java.util.HashSet;
25: import java.util.List;
26: import java.util.Set;
27:
28: /**
29: * Base implementation of {@link ApplicationContainer}.
30: * <p>
31: * This implementation provides code for common tasks, such as assembling files
32: * into a war, etc.
33: *
34: * @author Kohsuke Kawaguchi
35: * @author Ken Hofsass
36: */
37: public abstract class AbstractApplicationContainer implements ApplicationContainer {
38: private final WsTool wsimport;
39: private final WsTool wsgen;
40: private final Set<String> unsupportedUses;
41: private final boolean httpspi;
42:
43: protected AbstractApplicationContainer(WsTool wsimport, WsTool wsgen, boolean httpspi) {
44: this.wsimport = wsimport;
45: this.wsgen = wsgen;
46: this.unsupportedUses = new HashSet<String>();
47: this.httpspi = httpspi;
48: }
49:
50: @NotNull
51: public Set<String> getUnsupportedUses() {
52: return unsupportedUses;
53: }
54:
55: /**
56: * Prepares an exploded war file image for this service.
57: */
58: protected WAR assembleWar(DeployedService service) throws Exception {
59: WAR war = new WAR(service);
60:
61: boolean fromJava = service.service.wsdl.isEmpty();
62:
63:• if (!fromJava) {
64: war.compileWSDL(wsimport);
65: }
66:
67:• if (!isSkipMode()) {
68: war.compileJavac();
69: }
70:
71: // copy external metadata files, if any ....
72: File[] externalMetadataFiles = getExternalMetadataFiles(service.service);
73:• if (externalMetadataFiles != null) {
74: war.copyToClasses(externalMetadataFiles);
75: updateWsgenOpts(service.service);
76: }
77:
78:• if (fromJava) {
79: war.generateWSDL(wsgen);
80: }
81:
82:• if (!isSkipMode()) {
83:
84: // search for endpoints only in case we need to generate any descriptor ...
85: List<EndpointInfoBean> endpoints = null;
86:
87: // we only need this for Glassfish, but it's harmless to generate for other containers.
88: // TODO: figure out how not to do this for other containers
89: File configuredSunJaxwsXml = service.service.getConfiguredFile("sun-jaxws.xml");
90:• if (configuredSunJaxwsXml == null) {
91: endpoints = war.getEndpointsInfos();
92: war.generateSunJaxWsXml(endpoints);
93: } else {
94: war.copyToWEBINF(configuredSunJaxwsXml);
95: }
96:
97: File configuredWebXml = service.service.getConfiguredFile("web.xml");
98:• if (configuredWebXml == null) {
99:• if (endpoints == null) {
100: endpoints = war.getEndpointsInfos();
101: }
102: war.generateWebXml(endpoints, httpspi);
103: } else {
104: war.copyToWEBINF(configuredWebXml);
105: }
106:
107: PrintWriter w = new PrintWriter(new FileWriter(new File(war.root, "index.html")));
108: w.println("<html><body>Deployed by the JAX-WS test harness</body></html>");
109: w.close();
110:
111: // we only need this for embedded Tomcat, but it's harmless to generate for other containers.
112: // TODO: figure out how not to do this for other containers
113: File metainf = new File(war.root,"META-INF");
114: metainf.mkdirs();
115: w = new PrintWriter(new FileWriter(new File(metainf, "context.xml")));
116: //avoid default scanning of Class-Path in manifest to get rif of warnings during test run
117: w.println("<Context><JarScanner scanManifest=\"false\"/></Context>");
118: w.close();
119: }
120: //Package Handler Configuration files
121: war.copyToClasses(service.service.getHandlerConfiguration());
122:
123: //copy resources to amke it available on classpath.
124: war.copyResources(service.getResources());
125: return war;
126: }
127:
128: protected void updateWsgenOpts(TestService service) {
129:
130:• if (service.parent.metadatafiles != null) {
131:• for (String path : service.parent.metadatafiles) {
132: service.parent.wsgenOptions.add("-x");
133: service.parent.wsgenOptions.add(path);
134: }
135: }
136: }
137:
138: protected void updateWsitClient(WAR war, DeployedService deployedService, String id) throws Exception {
139: File wsitClientFile = new File(deployedService.getResources(), "wsit-client.xml");
140:• if (wsitClientFile.exists()) {
141: WSITUtil.updateWsitClient(wsitClientFile, id, deployedService.service.wsdl.get(0).wsdlFile.toURI().toString());
142: war.copyWsit(wsitClientFile);
143: } else {
144: throw new RuntimeException("wsit-client.xml is absent. It is required. \n"
145: + "Please check " + deployedService.getResources());
146: }
147: }
148:
149: private File[] getExternalMetadataFiles(TestService service) {
150: List<File> files = null;
151:• if (service.parent.metadatafiles != null) {
152:• for (String path : service.parent.metadatafiles) {
153:• if (files == null) {
154: files = new ArrayList<File>();
155: }
156: files.add(new File(service.getAbsolutePath(path)));
157: }
158: }
159:• return files == null ? null : files.toArray(new File[files.size()]);
160: }
161:
162: /**
163: * Returns true if we are running with the "-skip" option,
164: * where we shouldn't generate any artifacts and just pick up the results from the last run.
165: */
166: private boolean isSkipMode() {
167:• return wsgen.isNoop() && wsimport.isNoop();
168: }
169:
170: /**
171: * Prepares a fully packaged war file to the specified location.
172: */
173: protected final WAR createWARZip(DeployedService service, File archive) throws Exception {
174: WAR assembly = assembleWar(service);
175:
176: // copy runtime classes into the classpath. this is slow.
177: // isn't there a better way to do this?
178:• if (copyRuntimeLibraries()) {
179: System.out.println("Copying runtime libraries");
180: assembly.copyClasspath(World.runtime);
181: }
182:
183: System.out.println("Assembling a war file");
184: assembly.zipTo(archive);
185:
186: return assembly;
187: }
188:
189: /**
190: * Copy JAX-WS runtime code?
191: */
192: protected boolean copyRuntimeLibraries() {
193: return false;
194: }
195: }