forked from line/armeria
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
66 changed files
with
1,614 additions
and
191 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
117 changes: 117 additions & 0 deletions
117
core/src/main/java/com/linecorp/armeria/client/ClientBuilderParamsBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
/* | ||
* Copyright 2024 LINE Corporation | ||
* | ||
* LINE Corporation licenses this file to you under the Apache License, | ||
* version 2.0 (the "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at: | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package com.linecorp.armeria.client; | ||
|
||
import static com.google.common.base.MoreObjects.firstNonNull; | ||
import static com.linecorp.armeria.internal.client.ClientBuilderParamsUtil.nullOrEmptyToSlash; | ||
|
||
import java.net.URI; | ||
import java.net.URISyntaxException; | ||
|
||
import com.linecorp.armeria.common.Scheme; | ||
import com.linecorp.armeria.common.SerializationFormat; | ||
import com.linecorp.armeria.common.annotation.Nullable; | ||
|
||
/** | ||
* TBU. | ||
*/ | ||
public final class ClientBuilderParamsBuilder { | ||
|
||
private final ClientBuilderParams params; | ||
|
||
@Nullable | ||
private SerializationFormat serializationFormat; | ||
@Nullable | ||
private String absolutePathRef; | ||
@Nullable | ||
private Class<?> type; | ||
@Nullable | ||
private ClientOptions options; | ||
|
||
ClientBuilderParamsBuilder(ClientBuilderParams params) { | ||
this.params = params; | ||
} | ||
|
||
/** | ||
* TBU. | ||
*/ | ||
public ClientBuilderParamsBuilder serializationFormat(SerializationFormat serializationFormat) { | ||
this.serializationFormat = serializationFormat; | ||
return this; | ||
} | ||
|
||
/** | ||
* TBU. | ||
*/ | ||
public ClientBuilderParamsBuilder absolutePathRef(String absolutePathRef) { | ||
this.absolutePathRef = absolutePathRef; | ||
return this; | ||
} | ||
|
||
/** | ||
* TBU. | ||
*/ | ||
public ClientBuilderParamsBuilder clientType(Class<?> type) { | ||
this.type = type; | ||
return this; | ||
} | ||
|
||
/** | ||
* TBU. | ||
*/ | ||
public ClientBuilderParamsBuilder options(ClientOptions options) { | ||
this.options = options; | ||
return this; | ||
} | ||
|
||
/** | ||
* TBU. | ||
*/ | ||
public ClientBuilderParams build() { | ||
final Scheme scheme; | ||
if (serializationFormat != null) { | ||
scheme = Scheme.of(serializationFormat, params.scheme().sessionProtocol()); | ||
} else { | ||
scheme = params.scheme(); | ||
} | ||
final String schemeStr; | ||
if (scheme.serializationFormat() == SerializationFormat.NONE) { | ||
schemeStr = scheme.sessionProtocol().uriText(); | ||
} else { | ||
schemeStr = scheme.uriText(); | ||
} | ||
|
||
final String path; | ||
if (absolutePathRef != null) { | ||
path = nullOrEmptyToSlash(absolutePathRef); | ||
} else { | ||
path = params.absolutePathRef(); | ||
} | ||
|
||
final URI prevUri = params.uri(); | ||
final URI uri; | ||
try { | ||
uri = new URI(schemeStr, prevUri.getRawAuthority(), path, | ||
prevUri.getRawQuery(), prevUri.getRawFragment()); | ||
} catch (URISyntaxException e) { | ||
throw new IllegalArgumentException(e); | ||
} | ||
return new DefaultClientBuilderParams(scheme, params.endpointGroup(), uri.getRawPath(), | ||
uri, firstNonNull(type, params.clientType()), | ||
firstNonNull(options, params.options())); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.