19
19
import ca .uhn .fhir .rest .api .EncodingEnum ;
20
20
import ca .uhn .fhir .rest .api .server .RequestDetails ;
21
21
import ca .uhn .fhir .rest .client .api .IGenericClient ;
22
+ import ca .uhn .fhir .rest .client .api .IRestfulClientFactory ;
23
+ import ca .uhn .fhir .rest .client .api .ServerValidationModeEnum ;
24
+ import ca .uhn .fhir .rest .client .interceptor .LoggingInterceptor ;
22
25
import ca .uhn .fhir .rest .client .interceptor .SimpleRequestHeaderInterceptor ;
23
26
import ca .uhn .fhir .rest .server .RestfulServer ;
24
27
import ca .uhn .fhir .rest .server .servlet .ServletRequestDetails ;
30
33
import org .eclipse .jetty .ee10 .servlet .ServletHolder ;
31
34
import org .eclipse .jetty .server .Server ;
32
35
import org .hl7 .fhir .r4 .model .Bundle ;
33
- import org .hl7 .fhir .r4 .model .Resource ;
34
36
import org .junit .jupiter .api .AfterEach ;
35
37
import org .junit .jupiter .api .BeforeEach ;
36
38
import org .opencds .cqf .fhir .cql .EvaluationSettings ;
37
39
import org .springframework .beans .factory .annotation .Autowired ;
38
40
import org .springframework .mock .web .MockHttpServletRequest ;
39
41
import org .springframework .test .context .ContextConfiguration ;
40
42
41
- import java .util .List ;
42
43
import java .util .concurrent .TimeUnit ;
43
44
44
45
@@ -63,8 +64,6 @@ public abstract class BaseCrR4TestServer extends BaseJpaR4Test implements IResou
63
64
public static IParser ourParser ;
64
65
65
66
66
- //@Autowired
67
- //ApplicationContext myApplicationContext;
68
67
private SimpleRequestHeaderInterceptor mySimpleHeaderInterceptor ;
69
68
70
69
@ Autowired
@@ -108,20 +107,16 @@ public void beforeStartServer() throws Exception {
108
107
builder .setConnectionManager (connectionManager );
109
108
ourHttpClient = builder .build ();
110
109
111
- ourCtx .getRestfulClientFactory ().setSocketTimeout (600 * 1000 );
112
- ourClient = ourCtx .newRestfulGenericClient (ourServerBase );
113
- ourClient .setLogRequestAndResponse (true );
114
-
115
110
ourParser = ourCtx .newJsonParser ().setPrettyPrint (true );
116
111
117
112
ourRestfulServer .setDefaultResponseEncoding (EncodingEnum .XML );
118
113
ourPagingProvider = myAppCtx .getBean (DatabaseBackedPagingProvider .class );
119
114
ourRestfulServer .setPagingProvider (ourPagingProvider );
120
115
121
116
mySimpleHeaderInterceptor = new SimpleRequestHeaderInterceptor ();
122
- ourClient .registerInterceptor (mySimpleHeaderInterceptor );
123
117
myStorageSettings .setIndexMissingFields (JpaStorageSettings .IndexEnabledEnum .DISABLED );
124
118
119
+ ourClient = initClient (mySimpleHeaderInterceptor );
125
120
}
126
121
127
122
@ Override
@@ -139,23 +134,6 @@ public void loadBundle(String theLocation) {
139
134
ourClient .transaction ().withBundle (bundy ).execute ();
140
135
}
141
136
142
-
143
- public Bundle makeBundle (List <? extends Resource > theResources ) {
144
- return makeBundle (theResources .toArray (new Resource [theResources .size ()]));
145
- }
146
-
147
- public Bundle makeBundle (Resource ... theResources ) {
148
- Bundle bundle = new Bundle ();
149
- bundle .setType (Bundle .BundleType .SEARCHSET );
150
- bundle .setTotal (theResources != null ? theResources .length : 0 );
151
- if (theResources != null ) {
152
- for (Resource l : theResources ) {
153
- bundle .addEntry ().setResource (l ).setFullUrl ("/" + l .fhirType () + "/" + l .getId ());
154
- }
155
- }
156
- return bundle ;
157
- }
158
-
159
137
protected RequestDetails setupRequestDetails () {
160
138
var requestDetails = new ServletRequestDetails ();
161
139
requestDetails .setServletRequest (new MockHttpServletRequest ());
@@ -164,4 +142,21 @@ protected RequestDetails setupRequestDetails() {
164
142
return requestDetails ;
165
143
}
166
144
145
+ private static IGenericClient initClient (SimpleRequestHeaderInterceptor simpleHeaderInterceptor ) {
146
+ final IRestfulClientFactory restfulClientFactory = ourCtx .getRestfulClientFactory ();
147
+
148
+ restfulClientFactory .setServerValidationMode (ServerValidationModeEnum .NEVER );
149
+ restfulClientFactory .setSocketTimeout (600 * 1000 );
150
+
151
+ final IGenericClient genericClient = restfulClientFactory .newGenericClient (ourServerBase );
152
+
153
+ var loggingInterceptor = new LoggingInterceptor ();
154
+ loggingInterceptor .setLogRequestBody (true );
155
+ loggingInterceptor .setLogResponseBody (true );
156
+
157
+ genericClient .registerInterceptor (loggingInterceptor );
158
+ genericClient .registerInterceptor (simpleHeaderInterceptor );
159
+
160
+ return genericClient ;
161
+ }
167
162
}
0 commit comments