Skip to content

Commit dc935d9

Browse files
authored
Use UriBuilder when creating HttpRequest.setUri in annotation processor (#45201)
Use UriBuilder when creating HttpRequest.setUri in annotation processor
1 parent 0ad6db6 commit dc935d9

File tree

21 files changed

+668
-528
lines changed

21 files changed

+668
-528
lines changed

sdk/clientcore/annotation-processor-test/src/main/java/io/clientcore/annotation/processor/test/HostEdgeCase1ServiceImpl.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,8 @@ public static HostEdgeCase1Service getNewInstance(HttpPipeline httpPipeline) {
4646
@SuppressWarnings("cast")
4747
@Override
4848
public byte[] getByteArray(String url, int numberOfBytes) {
49-
String uri = url + "/bytes/" + numberOfBytes;
50-
// Create the HTTP request
51-
HttpRequest httpRequest = new HttpRequest().setMethod(HttpMethod.GET).setUri(uri);
49+
// Create the HttpRequest.
50+
HttpRequest httpRequest = new HttpRequest().setMethod(HttpMethod.GET).setUri(url + "/bytes/" + numberOfBytes);
5251
// Send the request through the httpPipeline
5352
try (Response<BinaryData> networkResponse = this.httpPipeline.send(httpRequest)) {
5453
int responseCode = networkResponse.getStatusCode();

sdk/clientcore/annotation-processor-test/src/main/java/io/clientcore/annotation/processor/test/HostEdgeCase2ServiceImpl.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,8 @@ public static HostEdgeCase2Service getNewInstance(HttpPipeline httpPipeline) {
4646
@SuppressWarnings("cast")
4747
@Override
4848
public byte[] getByteArray(String uri, int numberOfBytes) {
49-
String requestUri = uri + "/bytes/" + numberOfBytes;
50-
// Create the HTTP request
51-
HttpRequest httpRequest = new HttpRequest().setMethod(HttpMethod.GET).setUri(requestUri);
49+
// Create the HttpRequest.
50+
HttpRequest httpRequest = new HttpRequest().setMethod(HttpMethod.GET).setUri(uri + "/bytes/" + numberOfBytes);
5251
// Send the request through the httpPipeline
5352
try (Response<BinaryData> networkResponse = this.httpPipeline.send(httpRequest)) {
5453
int responseCode = networkResponse.getStatusCode();

sdk/clientcore/annotation-processor-test/src/main/java/io/clientcore/annotation/processor/test/ParameterizedHostServiceImpl.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,8 @@ public static ParameterizedHostService getNewInstance(HttpPipeline httpPipeline)
4646
@SuppressWarnings("cast")
4747
@Override
4848
public byte[] getByteArray(String scheme, String host, int numberOfBytes) {
49-
String uri = scheme + "://" + host + "/bytes/" + numberOfBytes;
50-
// Create the HTTP request
51-
HttpRequest httpRequest = new HttpRequest().setMethod(HttpMethod.GET).setUri(uri);
49+
// Create the HttpRequest.
50+
HttpRequest httpRequest = new HttpRequest().setMethod(HttpMethod.GET).setUri(scheme + "://" + host + "/bytes/" + numberOfBytes);
5251
// Send the request through the httpPipeline
5352
try (Response<BinaryData> networkResponse = this.httpPipeline.send(httpRequest)) {
5453
int responseCode = networkResponse.getStatusCode();

sdk/clientcore/annotation-processor-test/src/main/java/io/clientcore/annotation/processor/test/ParameterizedMultipleHostServiceImpl.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,8 @@ public static ParameterizedMultipleHostService getNewInstance(HttpPipeline httpP
5050
@SuppressWarnings("cast")
5151
@Override
5252
public HttpBinJSON get(String scheme, String hostPart1, String hostPart2) {
53-
String uri = scheme + "://" + hostPart1 + hostPart2 + "/get";
54-
// Create the HTTP request
55-
HttpRequest httpRequest = new HttpRequest().setMethod(HttpMethod.GET).setUri(uri);
53+
// Create the HttpRequest.
54+
HttpRequest httpRequest = new HttpRequest().setMethod(HttpMethod.GET).setUri(scheme + "://" + hostPart1 + hostPart2 + "/get");
5655
// Send the request through the httpPipeline
5756
Response<BinaryData> networkResponse = this.httpPipeline.send(httpRequest);
5857
int responseCode = networkResponse.getStatusCode();

sdk/clientcore/annotation-processor-test/src/main/java/io/clientcore/annotation/processor/test/SimpleXmlSerializableServiceImpl.java

+8-12
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,8 @@ public static SimpleXmlSerializableService getNewInstance(HttpPipeline httpPipel
5151
@SuppressWarnings("cast")
5252
@Override
5353
public void sendApplicationXml(SimpleXmlSerializable simpleXmlSerializable) {
54-
String uri = "http://localhost/sendApplicationXml";
55-
// Create the HTTP request
56-
HttpRequest httpRequest = new HttpRequest().setMethod(HttpMethod.PUT).setUri(uri);
54+
// Create the HttpRequest.
55+
HttpRequest httpRequest = new HttpRequest().setMethod(HttpMethod.PUT).setUri("http://localhost/sendApplicationXml");
5756
httpRequest.getHeaders().set(HttpHeaderName.CONTENT_TYPE, "application/xml");
5857
if (simpleXmlSerializable != null) {
5958
SerializationFormat serializationFormat = CoreUtils.serializationFormatFromContentType(httpRequest.getHeaders());
@@ -78,9 +77,8 @@ public void sendApplicationXml(SimpleXmlSerializable simpleXmlSerializable) {
7877
@SuppressWarnings("cast")
7978
@Override
8079
public void sendTextXml(SimpleXmlSerializable simpleXmlSerializable) {
81-
String uri = "http://localhost/sendTextXml";
82-
// Create the HTTP request
83-
HttpRequest httpRequest = new HttpRequest().setMethod(HttpMethod.PUT).setUri(uri);
80+
// Create the HttpRequest.
81+
HttpRequest httpRequest = new HttpRequest().setMethod(HttpMethod.PUT).setUri("http://localhost/sendTextXml");
8482
httpRequest.getHeaders().set(HttpHeaderName.CONTENT_TYPE, "text/xml");
8583
if (simpleXmlSerializable != null) {
8684
SerializationFormat serializationFormat = CoreUtils.serializationFormatFromContentType(httpRequest.getHeaders());
@@ -105,9 +103,8 @@ public void sendTextXml(SimpleXmlSerializable simpleXmlSerializable) {
105103
@SuppressWarnings("cast")
106104
@Override
107105
public SimpleXmlSerializable getXml(String contentType) {
108-
String uri = "http://localhost/getXml";
109-
// Create the HTTP request
110-
HttpRequest httpRequest = new HttpRequest().setMethod(HttpMethod.GET).setUri(uri);
106+
// Create the HttpRequest.
107+
HttpRequest httpRequest = new HttpRequest().setMethod(HttpMethod.GET).setUri("http://localhost/getXml");
111108
if (contentType != null) {
112109
httpRequest.getHeaders().add(new HttpHeader(HttpHeaderName.CONTENT_TYPE, contentType));
113110
}
@@ -136,9 +133,8 @@ public SimpleXmlSerializable getXml(String contentType) {
136133
@SuppressWarnings("cast")
137134
@Override
138135
public SimpleXmlSerializable getInvalidXml(String contentType) {
139-
String uri = "http://localhost/getInvalidXml";
140-
// Create the HTTP request
141-
HttpRequest httpRequest = new HttpRequest().setMethod(HttpMethod.GET).setUri(uri);
136+
// Create the HttpRequest.
137+
HttpRequest httpRequest = new HttpRequest().setMethod(HttpMethod.GET).setUri("http://localhost/getInvalidXml");
142138
if (contentType != null) {
143139
httpRequest.getHeaders().add(new HttpHeader(HttpHeaderName.CONTENT_TYPE, contentType));
144140
}

sdk/clientcore/annotation-processor-test/src/main/java/io/clientcore/annotation/processor/test/SpecialReturnBodiesServiceImpl.java

+12-18
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,8 @@ public static SpecialReturnBodiesService getNewInstance(HttpPipeline httpPipelin
4747
@SuppressWarnings("cast")
4848
@Override
4949
public BinaryData getBinaryData(String url) {
50-
String uri = url + "/bytes";
51-
// Create the HTTP request
52-
HttpRequest httpRequest = new HttpRequest().setMethod(HttpMethod.GET).setUri(uri);
50+
// Create the HttpRequest.
51+
HttpRequest httpRequest = new HttpRequest().setMethod(HttpMethod.GET).setUri(url + "/bytes");
5352
// Send the request through the httpPipeline
5453
Response<BinaryData> networkResponse = this.httpPipeline.send(httpRequest);
5554
int responseCode = networkResponse.getStatusCode();
@@ -65,9 +64,8 @@ public BinaryData getBinaryData(String url) {
6564
@SuppressWarnings("cast")
6665
@Override
6766
public Response<BinaryData> getBinaryDataWithResponse(String url) {
68-
String uri = url + "/bytes";
69-
// Create the HTTP request
70-
HttpRequest httpRequest = new HttpRequest().setMethod(HttpMethod.GET).setUri(uri);
67+
// Create the HttpRequest.
68+
HttpRequest httpRequest = new HttpRequest().setMethod(HttpMethod.GET).setUri(url + "/bytes");
7169
// Send the request through the httpPipeline
7270
Response<BinaryData> networkResponse = this.httpPipeline.send(httpRequest);
7371
int responseCode = networkResponse.getStatusCode();
@@ -83,9 +81,8 @@ public Response<BinaryData> getBinaryDataWithResponse(String url) {
8381
@SuppressWarnings("cast")
8482
@Override
8583
public byte[] getByteArray(String url) {
86-
String uri = url + "/bytes";
87-
// Create the HTTP request
88-
HttpRequest httpRequest = new HttpRequest().setMethod(HttpMethod.GET).setUri(uri);
84+
// Create the HttpRequest.
85+
HttpRequest httpRequest = new HttpRequest().setMethod(HttpMethod.GET).setUri(url + "/bytes");
8986
// Send the request through the httpPipeline
9087
try (Response<BinaryData> networkResponse = this.httpPipeline.send(httpRequest)) {
9188
int responseCode = networkResponse.getStatusCode();
@@ -102,9 +99,8 @@ public byte[] getByteArray(String url) {
10299
@SuppressWarnings("cast")
103100
@Override
104101
public Response<byte[]> getByteArrayWithResponse(String url) {
105-
String uri = url + "/bytes";
106-
// Create the HTTP request
107-
HttpRequest httpRequest = new HttpRequest().setMethod(HttpMethod.GET).setUri(uri);
102+
// Create the HttpRequest.
103+
HttpRequest httpRequest = new HttpRequest().setMethod(HttpMethod.GET).setUri(url + "/bytes");
108104
// Send the request through the httpPipeline
109105
try (Response<BinaryData> networkResponse = this.httpPipeline.send(httpRequest)) {
110106
int responseCode = networkResponse.getStatusCode();
@@ -121,9 +117,8 @@ public Response<byte[]> getByteArrayWithResponse(String url) {
121117
@SuppressWarnings("cast")
122118
@Override
123119
public InputStream getInputStream(String url) {
124-
String uri = url + "/bytes";
125-
// Create the HTTP request
126-
HttpRequest httpRequest = new HttpRequest().setMethod(HttpMethod.GET).setUri(uri);
120+
// Create the HttpRequest.
121+
HttpRequest httpRequest = new HttpRequest().setMethod(HttpMethod.GET).setUri(url + "/bytes");
127122
// Send the request through the httpPipeline
128123
Response<BinaryData> networkResponse = this.httpPipeline.send(httpRequest);
129124
int responseCode = networkResponse.getStatusCode();
@@ -139,9 +134,8 @@ public InputStream getInputStream(String url) {
139134
@SuppressWarnings("cast")
140135
@Override
141136
public Response<InputStream> getInputStreamWithResponse(String url) {
142-
String uri = url + "/bytes";
143-
// Create the HTTP request
144-
HttpRequest httpRequest = new HttpRequest().setMethod(HttpMethod.GET).setUri(uri);
137+
// Create the HttpRequest.
138+
HttpRequest httpRequest = new HttpRequest().setMethod(HttpMethod.GET).setUri(url + "/bytes");
145139
// Send the request through the httpPipeline
146140
Response<BinaryData> networkResponse = this.httpPipeline.send(httpRequest);
147141
int responseCode = networkResponse.getStatusCode();

0 commit comments

Comments
 (0)