/
ServletClient.java
263 lines (241 loc) · 10.1 KB
/
ServletClient.java
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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
/*
* Copyright (c) 2009, 2020 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
* version 2 with the GNU Classpath Exception, which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/
/*
* $Id: ServletClient.java 52684 2009-04-15 04:30:10Z adf $
*/
package com.sun.ts.tests.webservices13.servlet.WSRespBindAndAddressingTestUsingAnnotations;
import com.sun.ts.lib.util.*;
import com.sun.ts.lib.porting.*;
import com.sun.ts.tests.jaxws.common.*;
import com.sun.ts.tests.jaxws.wsa.common.W3CAddressingConstants;
import com.sun.ts.tests.jaxws.wsa.common.WsaSOAPUtils;
import java.io.*;
import java.sql.*;
import jakarta.servlet.*;
import jakarta.servlet.http.*;
import jakarta.servlet.annotation.WebServlet;
import java.util.*;
import jakarta.xml.ws.*;
import jakarta.xml.ws.soap.*;
@WebServlet("/ServletTest")
public class ServletClient extends HttpServlet {
private Properties harnessProps = null;
private static final boolean debug = false;
@Addressing(enabled = true, required = false)
@RespectBinding(enabled = true)
@WebServiceRef(name = "service/wsrespbindandaddrtestusingannotationsport4a", value = EchoService.class)
Echo port4a = null;
@Addressing(enabled = true, required = true)
@RespectBinding(enabled = true)
@WebServiceRef(name = "service/wsrespbindandaddrtestusingannotationsport5a", value = EchoService.class)
Echo port5a = null;
@Addressing(enabled = false)
@RespectBinding(enabled = true)
@WebServiceRef(name = "service/wsrespbindandaddrtestusingannotationsport6a", value = EchoService.class)
Echo port6a = null;
@Addressing(enabled = true, required = false)
@RespectBinding(enabled = true)
@WebServiceRef(name = "service/wsrespbindandaddrtestusingannotationsport7a", value = EchoService.class)
Echo2 port7a = null;
@Addressing(enabled = true, required = true)
@RespectBinding(enabled = true)
@WebServiceRef(name = "service/wsrespbindandaddrtestusingannotationsport8a", value = EchoService.class)
Echo2 port8a = null;
@WebServiceRef(name = "service/wsrespbindandaddrtestusingannotationsservice")
EchoService service = null;
public void init(ServletConfig config) throws ServletException {
super.init(config);
System.out.println("DEBUG ServletClient:init()");
System.out.println("ServletClient DEBUG: service=" + service);
System.out.println("ServletClient DEBUG: port4a=" + port4a);
System.out.println("ServletClient DEBUG: port5a=" + port5a);
System.out.println("ServletClient DEBUG: port6a=" + port6a);
System.out.println("ServletClient DEBUG: port7a=" + port7a);
System.out.println("ServletClient DEBUG: port8a=" + port8a);
if (service == null || port4a == null || port5a == null || port6a == null
|| port7a == null || port8a == null) {
throw new ServletException("init() failed: port injection failed");
}
}
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
boolean pass = true;
Properties p = new Properties();
res.setContentType("text/plain");
PrintWriter out = res.getWriter();
try {
String test = harnessProps.getProperty("TEST");
System.out.println("doGet: test to execute is: " + test);
if (test
.equals("afCltEnabledREQSvrEnabledREQrbfSvrEnabledCltEnabledTest")) {
if (afCltEnabledREQSvrEnabledREQrbfSvrEnabledCltEnabledTest())
p.setProperty("TESTRESULT", "pass");
else
p.setProperty("TESTRESULT", "fail");
} else if (test
.equals("afCltNotEnabledSvrEnabledREQrbfSvrEnabledCltEnabledTest")) {
if (afCltNotEnabledSvrEnabledREQrbfSvrEnabledCltEnabledTest())
p.setProperty("TESTRESULT", "pass");
else
p.setProperty("TESTRESULT", "fail");
} else if (test.equals(
"afCltEnabledNotREQSvrNotEnabledrbfSvrEnabledCltEnabledTest")) {
if (afCltEnabledNotREQSvrNotEnabledrbfSvrEnabledCltEnabledTest())
p.setProperty("TESTRESULT", "pass");
else
p.setProperty("TESTRESULT", "fail");
} else if (test
.equals("afCltEnabledREQSvrNotEnabledrbfSvrEnabledCltEnabledTest")) {
if (afCltEnabledREQSvrNotEnabledrbfSvrEnabledCltEnabledTest())
p.setProperty("TESTRESULT", "pass");
else
p.setProperty("TESTRESULT", "fail");
}
p.list(out);
} catch (Exception e) {
TestUtil.logErr("doGet: Exception: " + e);
e.printStackTrace(out);
System.out.println("doGet: Exception: " + e);
e.printStackTrace();
p.setProperty("TESTRESULT", "fail");
p.list(out);
}
out.close();
}
public void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
harnessProps = new Properties();
Enumeration enumlist = req.getParameterNames();
while (enumlist.hasMoreElements()) {
String name = (String) enumlist.nextElement();
String value = req.getParameter(name);
harnessProps.setProperty(name, value);
}
try {
TestUtil.init(harnessProps);
if (debug) {
System.out.println("Remote logging intialized for Servlet");
System.out.println("Here are the harness props");
harnessProps.list(System.out);
}
} catch (Exception e) {
System.out.println("doPost: Exception: " + e);
e.printStackTrace();
throw new ServletException("unable to initialize remote logging");
}
doGet(req, res);
harnessProps = null;
}
private boolean afCltEnabledREQSvrEnabledREQrbfSvrEnabledCltEnabledTest() {
try {
TestUtil.logMsg("ServletClient invoking EchoService echo() method");
TestUtil.logMsg(
"Addressing headers MUST be present on the SOAPRequest and SOAPResponse");
TestUtil
.logMsg("afCltEnabledREQSvrEnabledREQrbfSvrEnabledCltEnabledTest");
Holder<String> testName = new Holder(
"afCltEnabledREQSvrEnabledREQrbfSvrEnabledCltEnabledTest");
port5a.echo("Echo from ServletClient on port5a", testName);
return true;
} catch (Exception e) {
return false;
}
}
private boolean afCltNotEnabledSvrEnabledREQrbfSvrEnabledCltEnabledTest() {
boolean pass = true;
try {
TestUtil.logMsg("ServletClient invoking EchoService echo() method");
TestUtil.logMsg("This scenario MUST throw back a SOAPFault");
TestUtil
.logMsg("afCltNotEnabledSvrEnabledREQrbfSvrEnabledCltEnabledTest()");
Holder<String> testName = new Holder(
"afCltNotEnabledSvrEnabledREQrbfSvrEnabledCltEnabledTest()");
port6a.echo("Echo from ServletClient on port6a", testName);
TestUtil.logErr("SOAPFaultException was not thrown back");
pass = false;
} catch (SOAPFaultException sfe) {
TestUtil
.logMsg("Caught expected SOAPFaultException: " + sfe.getMessage());
try {
TestUtil.logMsg("FaultCode=" + WsaSOAPUtils.getFaultCode(sfe));
TestUtil.logMsg("FaultString=" + WsaSOAPUtils.getFaultString(sfe));
if (WsaSOAPUtils.isMessageAddressingHeaderRequiredFaultCode(sfe)) {
TestUtil.logMsg(
"SOAPFault contains expected faultcode MessageAddressingHeaderRequired");
} else {
String faultcode = WsaSOAPUtils.getFaultCode(sfe);
TestUtil.logErr("SOAPFault contains unexpected faultcode got: "
+ faultcode + ", expected: MessageAddressingHeaderRequired");
pass = false;
}
if (WsaSOAPUtils.getFaultString(sfe) == null) {
TestUtil
.logErr("The faultstring element MUST EXIST for SOAP 1.1 Faults");
pass = false;
}
if (WsaSOAPUtils.getFaultDetail(sfe) != null) {
TestUtil.logErr("The faultdetail element MUST NOT EXIST for SOAP 1.1 "
+ "Faults related to header entries");
pass = false;
}
} catch (Exception e2) {
TestUtil.logErr("Caught unexpected exception: " + e2.getMessage());
pass = false;
}
} catch (Exception e) {
TestUtil.logErr("Caught Exception: " + e.getMessage());
TestUtil.printStackTrace(e);
pass = false;
}
return pass;
}
private boolean afCltEnabledNotREQSvrNotEnabledrbfSvrEnabledCltEnabledTest() {
try {
TestUtil.logMsg("ServletClient invoking EchoService echo() method");
TestUtil.logMsg(
"Addressing headers MAY be present on the SOAPRequest and MUST NOT be present on SOAPResponse");
TestUtil
.logMsg("afCltEnabledNotREQSvrNotEnabledrbfSvrEnabledCltEnabledTest");
Holder<String> testName = new Holder(
"afCltEnabledNotREQSvrNotEnabledrbfSvrEnabledCltEnabledTest");
port7a.echo("Echo from ServletClient on port7a", testName);
return true;
} catch (Exception e) {
return false;
}
}
private boolean afCltEnabledREQSvrNotEnabledrbfSvrEnabledCltEnabledTest() {
boolean pass = true;
try {
TestUtil.logMsg("ServletClient invoking EchoService echo() method");
TestUtil.logMsg("This scenario MUST throw back a WebServiceException");
TestUtil
.logMsg("afCltEnabledREQSvrNotEnabledrbfSvrEnabledCltEnabledTest()");
Holder<String> testName = new Holder(
"afCltEnabledREQSvrNotEnabledrbfSvrEnabledCltEnabledTest()");
port8a.echo("Echo from ServletClient on port8a", testName);
TestUtil.logErr("WebServiceException was not thrown back");
pass = false;
} catch (WebServiceException e) {
TestUtil.logMsg("Caught expected WebServiceException: " + e.getMessage());
} catch (Exception e) {
TestUtil.logErr("Caught unexpected exception: " + e.getMessage());
TestUtil.printStackTrace(e);
pass = false;
}
return pass;
}
}