/
EjbClient.java
161 lines (144 loc) · 5.99 KB
/
EjbClient.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
/*
* 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
*/
package com.sun.ts.tests.webservices13.ejb.annotations.WSEjbWSRefRespBindAndAddressingCombinedTest;
import com.sun.ts.lib.util.*;
import com.sun.ts.lib.porting.*;
import java.util.*;
import jakarta.xml.ws.*;
import jakarta.xml.ws.soap.*;
import jakarta.ejb.EJBException;
import jakarta.ejb.Remote;
import jakarta.ejb.Stateful;
import jakarta.ejb.SessionContext;
import jakarta.annotation.Resource;
import jakarta.annotation.PostConstruct;
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;
@Stateful(name = "WSEjbWSRefRespBindAndAddressingCombinedTestClntBean")
@Remote({ EjbClientIF.class })
public class EjbClient implements EjbClientIF {
private Properties harnessProps = null;
private static final boolean debug = false;
@Addressing
@RespectBinding(enabled = true)
@WebServiceRef(name = "service/wsejbwsrefrespbindandaddrcombtestport1", type = Echo.class, value = EchoService.class)
Echo port1 = null;
@Addressing(enabled = true, required = true)
@RespectBinding(enabled = true)
@WebServiceRef(name = "service/wsejbwsrefrespbindandaddrcombtestport2", type = Echo.class, value = EchoService.class)
Echo port2 = null;
@Addressing(enabled = false)
@RespectBinding(enabled = true)
@WebServiceRef(name = "service/wsejbwsrefrespbindandaddrcombtestport3", type = Echo.class, value = EchoService.class)
Echo port3 = null;
@WebServiceRef(name = "service/wsejbwsrefrespbindandaddrcombtestservice")
EchoService service = null;
@PostConstruct
public void postConstruct() {
System.out.println("EjbClient:postConstruct()");
System.out.println("EjbClient DEBUG: service=" + service);
System.out.println("EjbClient DEBUG: port1=" + port1);
System.out.println("EjbClient DEBUG: port2=" + port2);
System.out.println("EjbClient DEBUG: port3=" + port3);
if (service == null || port2 == null || port1 == null || port3 == null) {
throw new EJBException("postConstruct failed: injection failure");
}
}
public void init(Properties p) {
harnessProps = p;
try {
TestUtil.init(p);
} catch (RemoteLoggingInitException e) {
TestUtil.printStackTrace(e);
throw new EJBException("init: failed");
} catch (Exception e) {
TestUtil.printStackTrace(e);
throw new EJBException("init: failed");
}
}
public boolean echo(String string, String testName) {
if (testName.equals("VerifyAddrHeadersExistForEnabledRequiredPort"))
return VerifyAddrHeadersExistForEnabledRequiredPort();
else
return VerifyFaultConditionOnPort();
}
private String getTargetEndpointAddress(Object stub) throws Exception {
BindingProvider bindingprovider = (BindingProvider) stub;
java.util.Map<String, Object> context = bindingprovider.getRequestContext();
String url = (String) context
.get(BindingProvider.ENDPOINT_ADDRESS_PROPERTY);
return url;
}
private boolean VerifyAddrHeadersExistForEnabledRequiredPort() {
try {
TestUtil.logMsg("EjbClient invoking EchoService echo() method");
TestUtil.logMsg("Addressing headers MUST be present on the SOAPRequest");
TestUtil.logMsg("VerifyAddrHeadersExistForEnabledRequiredPort");
Holder<String> testName = new Holder(
"VerifyAddrHeadersExistForEnabledRequiredPort");
port2.echo("Echo from EjbClient on port2", testName);
return true;
} catch (Exception e) {
return false;
}
}
private boolean VerifyFaultConditionOnPort() {
boolean pass = true;
try {
TestUtil.logMsg("EjbClient invoking EchoService echo() method");
TestUtil.logMsg("VerifyFaultConditionOnPort");
Holder<String> testName = new Holder("VerifyFaultConditionOnPort");
port3.echo("Echo from EjbClient on port3", 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;
}
}