Skip to content

Package: DeploymentExecutor

DeploymentExecutor

nameinstructionbranchcomplexitylinemethod
DeploymentExecutor(DeployedService)
M: 12 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
addSTSToClasspath()
M: 43 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 7 C: 0
0%
M: 1 C: 0
0%
createUndeployer()
M: 13 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
findServiceClass(File, List)
M: 82 C: 0
0%
M: 12 C: 0
0%
M: 7 C: 0
0%
M: 17 C: 0
0%
M: 1 C: 0
0%
generateClientArtifacts()
M: 304 C: 0
0%
M: 26 C: 0
0%
M: 14 C: 0
0%
M: 49 C: 0
0%
M: 1 C: 0
0%
runTest()
M: 27 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 7 C: 0
0%
M: 1 C: 0
0%
updateWsitClient()
M: 51 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.exec;
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.CodeGenerator;
16: import com.sun.xml.ws.test.container.DeployedService;
17: import com.sun.xml.ws.test.model.TestEndpoint;
18: import com.sun.xml.ws.test.model.TestService;
19: import com.sun.xml.ws.test.util.ArgumentListBuilder;
20: import com.sun.xml.ws.test.util.JavacTask;
21: import com.sun.xml.ws.test.util.WSITUtil;
22: import junit.framework.TestCase;
23:
24: import java.io.BufferedReader;
25: import java.io.File;
26: import java.io.FileReader;
27: import java.net.URI;
28: import java.net.URL;
29: import java.net.URLClassLoader;
30: import java.util.ArrayList;
31: import java.util.Arrays;
32: import java.util.List;
33:
34: /**
35: * {@link TestCase} that deploys a {@link TestService} to
36: * the {@link ApplicationContainer}.
37: *
38: * <p>
39: * After this test is run, {@link #createUndeployer()} needs
40: * to be used to undeploy the deployed service.
41: *
42: * @author Kohsuke Kawaguchi
43: */
44: public class DeploymentExecutor extends Executor {
45: private final DeployedService context;
46:
47: public DeploymentExecutor(DeployedService context) {
48: super("Deploy "+context.service.name,context.parent);
49: this.context = context;
50: }
51:
52: public void runTest() throws Throwable {
53: CodeGenerator.testStarting(context.workDir);
54: // deploy the service
55: context.app = context.parent.container.deploy(context);
56: //For STS we do not want to generate client artifacts
57:• if (!context.service.isSTS) {
58: // then use that WSDL to generate client
59: generateClientArtifacts();
60: } else {
61: addSTSToClasspath();
62: updateWsitClient();
63: }
64: }
65:
66: public void updateWsitClient()throws Exception {
67: File wsitClientFile = new File(context.parent.getResources(),"wsit-client.xml");
68:• if (wsitClientFile.exists()) {
69: URI uri = context.app.getEndpointAddress((TestEndpoint)context.service.endpoints.toArray()[0]);
70: WSITUtil.updateWsitClient(wsitClientFile, uri.toString(), context.service.wsdl.get(0).wsdlFile.toURI().toString());
71: } else {
72: throw new RuntimeException("wsit-client.xml is absent. It is required. \n"+
73: "Please check " + context.service.parent.resources );
74: }
75: }
76:
77: public void addSTSToClasspath() throws Exception{
78: List<URL> classpath = context.clientClasspaths;
79:
80: ClassLoader baseCl = World.runtime.getClassLoader();
81:• if (context.parent.clientClassLoader != null) {
82: baseCl = context.parent.clientClassLoader;
83: }
84:
85: classpath.add(new File(context.warDir, "WEB-INF/classes").toURL());
86:
87: context.parent.clientClassLoader= new URLClassLoader( classpath.toArray(new URL[classpath.size()]), baseCl );
88:
89: }
90: /**
91: * Generate & compile source files from service WSDL.
92: */
93: private void generateClientArtifacts() throws Exception {
94:
95: File gensrcDir = makeWorkDir("client-source");
96: File classDir = makeWorkDir("client-classes");
97:
98:• for (int i = 0; i < context.app.getWSDL().size(); i++) {
99: URL wsdl = context.app.getWSDL().get(i);
100: ArgumentListBuilder options = new ArgumentListBuilder();
101: // Generate cusomization file & add as wsimport option
102:
103: // we used to do this just to set the package name, but
104: // it turns out we can do it much easily with the -p option
105: //options.add("-b");
106: //options.add(genClientCustomizationFile(context).getAbsolutePath());
107:
108: //Don't add the default package option if -noPackage is specified
109: // this will be helpful in testing default/customization behavior.
110:• if (!context.service.parent.testOptions.contains("-noPackage")) {
111:
112: // set package name. use 'client' to avoid collision between server artifacts
113:• if (!context.service.parent.wsimportClientOptions.contains("-p")) {
114:• if (i > 0) {
115: options.add("-p").add(context.parent.descriptor.name + ".client" + (i + 1));
116: } else {
117: options.add("-p").add(context.parent.descriptor.name + ".client");
118: }
119: }
120: }
121: options.add("-extension");
122:
123: //Add user's additional customization files
124:• for (File custFile : context.parent.descriptor.clientCustomizations)
125: options.add("-b").add(custFile);
126:
127: //Other options
128:• if(World.debug)
129: options.add("-verbose");
130: options.add("-s").add(gensrcDir);
131: options.add("-d").add(classDir);
132: options.add("-Xnocompile");
133:• if (Boolean.getBoolean("harness.useSSL")) {
134: options.add("-XdisableSSLHostnameVerification");
135: }
136: options.add(wsdl);
137:• if(World.debug)
138: System.out.println("wsdl = " + wsdl);
139: options.addAll(context.service.parent.wsimportClientOptions);
140: // compile WSDL to generate client-side artifact
141: options.invoke(context.parent.wsimport);
142: }
143:
144: // compile the generated source files to javac
145: JavacTask javac = new JavacTask(context.parent.descriptor.javacOptions);
146: javac.setSourceDir(
147: gensrcDir,
148: context.parent.descriptor.common,
149: new File(context.parent.descriptor.home,"client")
150: );
151: javac.setDestdir(classDir);
152: javac.setDebug(true);
153:• if(!context.parent.wsimport.isNoop())
154: // if we are just reusing the existing artifacts, no need to recompile.
155: javac.execute();
156:
157: // load the generated classes
158: List<URL> classpath = context.clientClasspaths;
159: classpath.add(classDir.toURL());
160: // TODO: only the local container needs server classes in the classloader.
161: classpath.add(new File(context.warDir, "WEB-INF/classes").toURL());
162:• if(context.getResources()!=null) {
163: classpath.add(context.getResources().toURL());
164: }
165:
166: /*
167: * If there is a service like STS it has already been added to context.parent.clientClassLoader
168: * add that to the final classpath
169: */
170:• if (context.parent.clientClassLoader instanceof URLClassLoader) {
171: URL [] urls = ((URLClassLoader)context.parent.clientClassLoader).getURLs();
172: classpath.addAll(Arrays.asList(urls));
173: }
174:
175: ClassLoader cl = new URLClassLoader( classpath.toArray(new URL[classpath.size()]),
176: World.runtime.getClassLoader() );
177:
178: context.parent.clientClassLoader = cl;
179:
180: // The following code scans the generated source files and look for the class
181: // that extend from Service. This could be as simple as
182: // line-by-line scan of "extends Service" ---
183: // if we want to be more robust, we can write an AnnotationProcessor
184: // so that we can work on top of Java AST, but this simple grep-like
185: // approach would work just fine with wsimport.
186:
187: List<String> serviceClazzNames = new ArrayList<String>();
188: findServiceClass(gensrcDir,serviceClazzNames);
189:
190:• if (serviceClazzNames.isEmpty())
191: System.out.println("WARNING: Cannot find the generated 'service' class that extends from jakarta.xml.ws.Service. Assuming provider-only service");
192:
193:• for (String name : serviceClazzNames)
194: context.serviceClass.add(cl.loadClass(name));
195: }
196:
197: /**
198: * Creates another test to be exeucted at the end
199: * to undeploy the service that this test deployed.
200: */
201: public Executor createUndeployer() {
202: return new Executor("Undeploy "+context.service.name,context.parent) {
203: public void runTest() throws Throwable {
204: CodeGenerator.testStarting(context.workDir);
205: if(DeploymentExecutor.this.context.app!=null)
206: DeploymentExecutor.this.context.app.undeploy();
207: }
208: };
209: }
210:
211: /**
212: * Recursively scans the Java source directory and find a class
213: * that extends from "Service", add them to the given list.
214: */
215: private void findServiceClass(File dir,List<String> result) throws Exception {
216: OUTER:
217:• for (File child : dir.listFiles()) {
218:• if (child.isDirectory()) {
219: findServiceClass(child,result);
220: } else
221:• if (child.getName().endsWith(".java")) {
222: // check if this is the class that extends from "Service"
223:
224: BufferedReader reader = new BufferedReader(new FileReader(child));
225: String pkg = null; // this variable becomes Java package of this source file
226: String line;
227:• while ((line =reader.readLine()) != null){
228:• if(line.startsWith("package ")) {
229: pkg = line.substring(8,line.indexOf(';'));
230: }
231:• if (line.contains("extends Service")){
232: // found it.
233: reader.close();
234:
235: String className = child.getName();
236: // remove .java from the fileName
237: className = className.substring(0,className.lastIndexOf('.'));
238: //Get the package name for the file by taking a substring after
239: // client-classes and replacing '/' by '.'
240: result.add(pkg+'.'+ className);
241:
242: continue OUTER;
243: }
244: }
245: reader.close();
246: }
247: }
248: }
249:
250: /*
251: * Generates a JAX-WS customization file for generating client artifacts.
252: */
253: //private File genClientCustomizationFile(DeployedService service) throws Exception {
254: // File customizationFile = new File(service.workDir, "custom-client.xml");
255: // OutputStream outputStream =
256: // new FileOutputStream(customizationFile);
257: // XMLOutput output = XMLOutput.createXMLOutput(outputStream);
258: //
259: // String packageName = service.service.parent.shortName;
260: //
261: // // to avoid collision between the client artifacts and server artifacts
262: // // when testing everything inside a single classloader (AKA local transport),
263: // // put the client artifacts into a different package.
264: // CustomizationBean infoBean = new CustomizationBean(packageName+".client",
265: // service.app.getWSDL().toExternalForm());
266: // JellyContext jellyContext = new JellyContext();
267: // jellyContext.setVariable("data", infoBean);
268: // jellyContext.runScript(getClass().getResource("custom-client.jelly"),output);
269: // output.flush();
270: //
271: // return customizationFile;
272: //}
273: }
274: