Skip to content

Commit 52aa2b6

Browse files
authored
Remove ResponseBodyMode (Azure#44635)
1 parent 1f2d04e commit 52aa2b6

File tree

20 files changed

+32
-1209
lines changed

20 files changed

+32
-1209
lines changed

sdk/clientcore/annotation-processor-test/src/test/java/io/clientcore/annotation/processor/test/PagingOperationTests.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import io.clientcore.core.http.models.HttpRequest;
1313
import io.clientcore.core.http.models.RequestOptions;
1414
import io.clientcore.core.http.models.Response;
15-
import io.clientcore.core.http.models.ResponseBodyMode;
1615
import io.clientcore.core.http.paging.PagedIterable;
1716
import io.clientcore.core.http.paging.PagedResponse;
1817
import io.clientcore.core.http.pipeline.HttpPipeline;
@@ -43,11 +42,9 @@ public void testListFoo() {
4342
String uri = "https://example.com";
4443
String firstPageUri = uri + "/foos";
4544
String nextLinkUri = uri + "/foos?page=2";
46-
RequestOptions requestOptions = new RequestOptions().setResponseBodyMode(ResponseBodyMode.DESERIALIZE);
4745
HttpPipeline pipeline = new HttpPipelineBuilder()
4846
.httpClient(request -> {
4947
String requestUri = request.getUri().toString();
50-
request.setRequestOptions(requestOptions);
5148
if (firstPageUri.equals(requestUri)) {
5249
return createMockResponse(request, FIRST_PAGE_RESPONSE, nextLinkUri);
5350
} else if (nextLinkUri.equals(requestUri)) {
@@ -87,11 +84,9 @@ public void testListFooListResult() {
8784
String uri = "https://example.com";
8885
String firstPageUri = uri + "/foos";
8986
String nextLinkUri = uri + "/foos?page=2";
90-
RequestOptions requestOptions = new RequestOptions().setResponseBodyMode(ResponseBodyMode.DESERIALIZE);
9187
HttpPipeline pipeline = new HttpPipelineBuilder()
9288
.httpClient(request -> {
9389
String requestUri = request.getUri().toString();
94-
request.setRequestOptions(requestOptions);
9590
if (firstPageUri.equals(requestUri)) {
9691
return createMockResponse(request, BinaryData.fromString(
9792
"{\"items\":[{\"bar\":\"hello.world\",\"baz\":[\"hello\",\"hello.world\"],\"qux\":{\"a" +

sdk/clientcore/annotation-processor-test/src/test/java/io/clientcore/annotation/processor/test/TestInterfaceGenerationTests.java

Lines changed: 2 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,8 @@
55

66
import io.clientcore.annotation.processor.test.implementation.TestInterfaceClientImpl;
77
import io.clientcore.annotation.processor.test.implementation.models.Foo;
8-
import io.clientcore.annotation.processor.test.implementation.models.HttpBinJSON;
98
import io.clientcore.core.http.client.HttpClient;
10-
import io.clientcore.core.http.models.RequestOptions;
119
import io.clientcore.core.http.models.Response;
12-
import io.clientcore.core.http.models.ResponseBodyMode;
1310
import io.clientcore.core.http.pipeline.HttpPipeline;
1411
import io.clientcore.core.http.pipeline.HttpPipelineBuilder;
1512
import io.clientcore.core.models.binarydata.BinaryData;
@@ -21,16 +18,9 @@
2118
import org.junit.jupiter.api.Disabled;
2219
import org.junit.jupiter.api.Test;
2320

24-
import java.io.IOException;
25-
26-
import static io.clientcore.core.http.models.ResponseBodyMode.BUFFER;
27-
import static io.clientcore.core.http.models.ResponseBodyMode.DESERIALIZE;
28-
import static io.clientcore.core.http.models.ResponseBodyMode.IGNORE;
29-
import static io.clientcore.core.http.models.ResponseBodyMode.STREAM;
3021
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
3122
import static org.junit.jupiter.api.Assertions.assertEquals;
3223
import static org.junit.jupiter.api.Assertions.assertNotNull;
33-
import static org.junit.jupiter.api.Assertions.assertNull;
3424

3525
public class TestInterfaceGenerationTests {
3626
private static LocalTestServer server;
@@ -64,12 +54,8 @@ public void testGetFoo() {
6454
=
6555
"{\"bar\":\"hello.world\",\"baz\":[\"hello\",\"hello.world\"],\"qux\":{\"a.b\":\"c.d\",\"bar.a\":\"ttyy\",\"bar.b\":\"uuzz\",\"hello\":\"world\"},\"additionalProperties\":{\"bar\":\"baz\",\"a.b\":\"c.d\",\"properties.bar\":\"barbar\"}}";
6656

67-
HttpPipeline pipeline = new HttpPipelineBuilder().httpClient((request) -> {
68-
// what is the default response body mode?
69-
request.setRequestOptions(new RequestOptions().setResponseBodyMode(ResponseBodyMode.DESERIALIZE));
70-
return new MockHttpResponse(request, 200,
71-
BinaryData.fromString(wireValue));
72-
}).build();
57+
HttpPipeline pipeline = new HttpPipelineBuilder().httpClient(request ->
58+
new MockHttpResponse(request, 200, BinaryData.fromString(wireValue))).build();
7359

7460
TestInterfaceClientImpl.TestInterfaceClientService testInterface =
7561
TestInterfaceClientImpl.TestInterfaceClientService.getNewInstance(pipeline, null);
@@ -90,88 +76,6 @@ public void testGetFoo() {
9076
assertEquals("barbar", foo.additionalProperties().get("properties.bar"));
9177
}
9278

93-
@Test
94-
public void bodyIsEmptyWhenIgnoreBodyIsSet() throws IOException {
95-
HttpPipeline pipeline = new HttpPipelineBuilder().httpClient(getHttpClient()).build();
96-
97-
TestInterfaceClientImpl.TestInterfaceClientService testInterface =
98-
TestInterfaceClientImpl.TestInterfaceClientService.getNewInstance(pipeline, null);
99-
assertNotNull(testInterface);
100-
RequestOptions requestOptions = new RequestOptions().setResponseBodyMode(IGNORE);
101-
HttpBinJSON httpBinJSON = testInterface.putConvenience(getServerUri(false), 42, requestOptions);
102-
103-
assertNull(httpBinJSON);
104-
105-
try (Response<HttpBinJSON> response = testInterface.putResponse(getServerUri(false), 42, requestOptions)) {
106-
assertNull(response.getValue());
107-
}
108-
}
109-
110-
@Test
111-
public void bodyIsEmptyWhenIgnoreBodyIsSetForStreamResponse() throws IOException {
112-
HttpPipeline pipeline = new HttpPipelineBuilder().httpClient(getHttpClient()).build();
113-
TestInterfaceClientImpl.TestInterfaceClientService testInterface =
114-
TestInterfaceClientImpl.TestInterfaceClientService.getNewInstance(pipeline, null);
115-
assertNotNull(testInterface);
116-
RequestOptions requestOptions = new RequestOptions().setResponseBodyMode(IGNORE);
117-
HttpBinJSON httpBinJSON = testInterface.postStreamConvenience(getServerUri(false), 42, requestOptions);
118-
119-
assertNull(httpBinJSON);
120-
121-
try (
122-
Response<HttpBinJSON> response = testInterface.postStreamResponse(getServerUri(false), 42, requestOptions)) {
123-
assertNull(response.getValue());
124-
}
125-
}
126-
127-
// TODO (alzimmer): How do we handle streaming?
128-
@Test
129-
public void bodyIsStreamedWhenResponseBodyModeIndicatesIt() throws IOException {
130-
HttpPipeline pipeline = new HttpPipelineBuilder().httpClient(getHttpClient()).build();
131-
TestInterfaceClientImpl.TestInterfaceClientService testInterface =
132-
TestInterfaceClientImpl.TestInterfaceClientService.getNewInstance(pipeline, null);
133-
assertNotNull(testInterface);
134-
RequestOptions requestOptions = new RequestOptions().setResponseBodyMode(STREAM);
135-
136-
try (
137-
Response<HttpBinJSON> response = testInterface.postStreamResponse(getServerUri(false), 42, requestOptions)) {
138-
assertNotNull(response.getValue());
139-
}
140-
}
141-
142-
@Test
143-
public void bodyIsBufferedWhenResponseBodyModeIndicatesIt() throws IOException {
144-
HttpPipeline pipeline = new HttpPipelineBuilder().httpClient(getHttpClient()).build();
145-
TestInterfaceClientImpl.TestInterfaceClientService testInterface =
146-
TestInterfaceClientImpl.TestInterfaceClientService.getNewInstance(pipeline, null);
147-
assertNotNull(testInterface);
148-
RequestOptions requestOptions = new RequestOptions().setResponseBodyMode(BUFFER);
149-
HttpBinJSON httpBinJSON = testInterface.postStreamConvenience(getServerUri(false), 42, requestOptions);
150-
151-
assertNotNull(httpBinJSON);
152-
153-
try (
154-
Response<HttpBinJSON> response = testInterface.postStreamResponse(getServerUri(false), 42, requestOptions)) {
155-
assertNotNull(response.getValue());
156-
}
157-
}
158-
159-
@Test
160-
public void bodyIsDeserializedWhenResponseBodyModeIndicatesIt() throws IOException {
161-
HttpPipeline pipeline = new HttpPipelineBuilder().httpClient(getHttpClient()).build();
162-
TestInterfaceClientImpl.TestInterfaceClientService testInterface =
163-
TestInterfaceClientImpl.TestInterfaceClientService.getNewInstance(pipeline, null);
164-
assertNotNull(testInterface);
165-
RequestOptions requestOptions = new RequestOptions().setResponseBodyMode(DESERIALIZE);
166-
HttpBinJSON httpBinJSON = testInterface.postStreamConvenience(getServerUri(false), 42, requestOptions);
167-
168-
assertNotNull(httpBinJSON);
169-
170-
try (Response<HttpBinJSON> response = testInterface.postStreamResponse(getServerUri(false), 42, requestOptions)) {
171-
assertNotNull(response.getValue());
172-
}
173-
}
174-
17579
@Test
17680
public void requestWithByteArrayReturnType() {
17781
HttpPipeline pipeline = new HttpPipelineBuilder().httpClient(getHttpClient()).build();

sdk/clientcore/annotation-processor/src/main/java/io/clientcore/annotation/processor/templating/JavaParserTemplateProcessor.java

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@
2828
import io.clientcore.core.http.models.HttpHeaderName;
2929
import io.clientcore.core.http.models.HttpMethod;
3030
import io.clientcore.core.http.models.HttpRequest;
31-
import io.clientcore.core.http.models.RequestOptions;
3231
import io.clientcore.core.http.models.Response;
33-
import io.clientcore.core.http.models.ResponseBodyMode;
3432
import io.clientcore.core.http.pipeline.HttpPipeline;
3533
import io.clientcore.core.instrumentation.logging.ClientLogger;
3634
import io.clientcore.core.models.binarydata.BinaryData;
@@ -175,8 +173,6 @@ void createClass(String serviceInterfaceImplShortName, String serviceInterfaceSh
175173

176174
addDeserializeHelperMethod(
177175
classBuilder.addMethod("decodeNetworkResponse", Modifier.Keyword.PRIVATE, Modifier.Keyword.STATIC));
178-
addDefaultResponseHandlingMethod(
179-
classBuilder.addMethod("getOrDefaultResponseBodyMode", Modifier.Keyword.PRIVATE, Modifier.Keyword.STATIC));
180176
}
181177

182178
/**
@@ -187,20 +183,6 @@ CompilationUnit getCompilationUnit() {
187183
return this.compilationUnit;
188184
}
189185

190-
private void addDefaultResponseHandlingMethod(MethodDeclaration defaultResponseHandlingMethod) {
191-
defaultResponseHandlingMethod.setType(ResponseBodyMode.class)
192-
.addParameter(RequestOptions.class, "requestOptions");
193-
defaultResponseHandlingMethod
194-
.setJavadocComment("Retrieve the ResponseBodyMode from RequestOptions or use the default "
195-
+ "ResponseBodyMode.BUFFER.\n" + "@param requestOptions the request options set on the HttpRequest\n"
196-
+ "@return the ResponseBodyMode from RequestOptions or ResponseBodyMode.BUFFER");
197-
defaultResponseHandlingMethod.setBody(StaticJavaParser.parseBlock("{ ResponseBodyMode responseBodyMode;"
198-
+ " if (requestOptions != null && requestOptions.getResponseBodyMode() != null) {"
199-
+ " responseBodyMode = requestOptions.getResponseBodyMode();" + " } else {"
200-
+ " responseBodyMode = ResponseBodyMode.BUFFER;" + " }" + " return responseBodyMode; }"));
201-
202-
}
203-
204186
private void addDeserializeHelperMethod(MethodDeclaration deserializeHelperMethod) {
205187
deserializeHelperMethod.setType("Object")
206188
.addParameter("BinaryData", "data")

sdk/clientcore/annotation-processor/src/main/java/io/clientcore/annotation/processor/utils/ResponseBodyModeGeneration.java

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
import com.github.javaparser.ast.stmt.ReturnStmt;
1111
import io.clientcore.annotation.processor.models.HttpRequestContext;
1212
import io.clientcore.core.http.models.HttpMethod;
13-
import io.clientcore.core.http.models.RequestOptions;
14-
import io.clientcore.core.http.models.ResponseBodyMode;
1513
import io.clientcore.core.implementation.TypeUtil;
1614
import io.clientcore.core.models.binarydata.BinaryData;
1715
import io.clientcore.core.utils.CoreUtils;
@@ -32,18 +30,6 @@
3230
*/
3331
public final class ResponseBodyModeGeneration {
3432

35-
/**
36-
* Generates response body mode assignment based on request options and return type.
37-
*
38-
* @param body the method builder to append generated code.
39-
*/
40-
public static void generateResponseBodyMode(BlockStmt body) {
41-
body.tryAddImportToParentCompilationUnit(ResponseBodyMode.class);
42-
body.tryAddImportToParentCompilationUnit(RequestOptions.class);
43-
body.addStatement(StaticJavaParser.parseStatement(
44-
"ResponseBodyMode responseBodyMode = getOrDefaultResponseBodyMode" + "(httpRequest.getRequestOptions());"));
45-
}
46-
4733
/**
4834
* Handles deserialization response mode logic.
4935
*
@@ -54,8 +40,6 @@ public static void generateResponseBodyMode(BlockStmt body) {
5440
*/
5541
public static void handleResponseBody(BlockStmt body, TypeMirror returnType, java.lang.reflect.Type entityType,
5642
HttpRequestContext method) {
57-
body.tryAddImportToParentCompilationUnit(ResponseBodyMode.class);
58-
5943
String typeCast = entityType.toString();
6044
if (method.getHttpMethod() == HttpMethod.HEAD
6145
&& (TypeUtil.isTypeOrSubTypeOf(entityType, Boolean.TYPE)
@@ -149,7 +133,6 @@ public static void generateResponseHandling(BlockStmt body, TypeMirror returnTyp
149133
+ "networkResponse.getRequest(), responseCode, networkResponse.getHeaders(), null);"));
150134
} else {
151135
// If this type has type arguments, then we look at the last one to determine if it expects a body
152-
generateResponseBodyMode(body);
153136
handleResponseBody(body, returnType, bodyType, method);
154137
createResponseIfNecessary(body);
155138
}

sdk/clientcore/annotation-processor/src/test/java/io/clientcore/annotation/processor/utils/ResponseBodyModeGenerationTest.java

Lines changed: 0 additions & 50 deletions
This file was deleted.

sdk/clientcore/core/spotbugs-exclude.xml

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,6 @@
2525
<Class name="io.clientcore.core.implementation.ReflectionUtilsMethodHandle" />
2626
<Class name="io.clientcore.core.implementation.http.HttpPipelineCallState" />
2727
<Class name="io.clientcore.core.implementation.http.rest.PercentEscaper" />
28-
<Class name="io.clientcore.core.implementation.http.rest.ResponseConstructorsCache" />
29-
<Class name="io.clientcore.core.implementation.http.rest.ResponseConstructorsCacheLambdaMetaFactory" />
30-
<Class name="io.clientcore.core.implementation.http.rest.ResponseConstructorsCacheLambdaMetaFactory$ResponseConstructor" />
31-
<Class name="io.clientcore.core.implementation.http.rest.ResponseConstructorsNoCacheReflection" />
32-
<Class name="io.clientcore.core.implementation.http.rest.ResponseExceptionConstructorCache" />
3328
<Class name="io.clientcore.core.implementation.http.rest.RestProxyImpl" />
3429
<Class name="io.clientcore.core.implementation.utils.AuthenticateChallengeParser" />
3530
<Class name="io.clientcore.core.implementation.utils.InternalContext" />
@@ -425,10 +420,7 @@
425420
</Match>
426421
<Match>
427422
<Bug pattern="UWF_UNWRITTEN_FIELD" />
428-
<Or>
429-
<Class name="io.clientcore.core.implementation.TypeUtilTests$Dog" />
430-
<Class name="io.clientcore.core.implementation.http.rest.ResponseConstructorsCacheBenchMarkTestData$FooHeader" />
431-
</Or>
423+
<Class name="io.clientcore.core.implementation.TypeUtilTests$Dog" />
432424
</Match>
433425
<Match>
434426
<Bug pattern="VO_VOLATILE_REFERENCE_TO_ARRAY" />

sdk/clientcore/core/src/main/java/io/clientcore/core/http/models/RequestOptions.java

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@ public final class RequestOptions {
121121
private Consumer<HttpRequest> requestCallback = request -> {
122122
};
123123
private Context context;
124-
private ResponseBodyMode responseBodyMode;
125124
private boolean locked;
126125
private ClientLogger logger;
127126
private InstrumentationContext instrumentationContext;
@@ -152,17 +151,6 @@ public Context getContext() {
152151
return context;
153152
}
154153

155-
/**
156-
* Gets the configuration indicating how the body of the resulting HTTP response should be handled.
157-
*
158-
* <p>For more information about the options for handling an HTTP response body, see {@link ResponseBodyMode}.</p>
159-
*
160-
* @return The configuration indicating how the body of the resulting HTTP response should be handled.
161-
*/
162-
public ResponseBodyMode getResponseBodyMode() {
163-
return responseBodyMode;
164-
}
165-
166154
/**
167155
* Gets the {@link ClientLogger} used to log the request and response.
168156
*
@@ -292,24 +280,6 @@ public RequestOptions setContext(Context context) {
292280
return this;
293281
}
294282

295-
/**
296-
* Sets the configuration indicating how the body of the resulting HTTP response should be handled. If {@code null},
297-
* the response body will be handled based on the content type of the response.
298-
*
299-
* <p>For more information about the options for handling an HTTP response body, see {@link ResponseBodyMode}.</p>
300-
*
301-
* @param responseBodyMode The configuration indicating how the body of the resulting HTTP response should be
302-
* handled.
303-
* @return The updated {@link RequestOptions} object.
304-
* @throws IllegalStateException if this instance is obtained by calling {@link RequestOptions#none()}.
305-
*/
306-
public RequestOptions setResponseBodyMode(ResponseBodyMode responseBodyMode) {
307-
checkLocked("Cannot set response body mode.");
308-
this.responseBodyMode = responseBodyMode;
309-
310-
return this;
311-
}
312-
313283
/**
314284
* Sets the {@link ClientLogger} used to log the request and response.
315285
*

0 commit comments

Comments
 (0)