forked from OpenFeign/feign
-
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
1 parent
5c460ae
commit 7067d23
Showing
3 changed files
with
72 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -155,7 +155,7 @@ public Map<String, MethodHandler> apply(Target target) { | |
if (!md.formParams().isEmpty() && md.template().bodyTemplate() == null) { | ||
buildTemplate = | ||
new BuildFormEncodedTemplateFromArgs(md, encoder, queryMapEncoder, target); | ||
} else if (md.bodyIndex() != null) { | ||
} else if (md.bodyIndex() != null || UnconditionalEncoder.class.isAssignableFrom(encoder.getClass())) { | ||
buildTemplate = new BuildEncodedTemplateFromArgs(md, encoder, queryMapEncoder, target); | ||
} else { | ||
buildTemplate = new BuildTemplateByResolvingArgs(md, queryMapEncoder, target); | ||
|
@@ -379,10 +379,22 @@ private BuildEncodedTemplateFromArgs(MethodMetadata metadata, Encoder encoder, | |
protected RequestTemplate resolve(Object[] argv, | ||
RequestTemplate mutable, | ||
Map<String, Object> variables) { | ||
Object body = argv[metadata.bodyIndex()]; | ||
checkArgument(body != null, "Body parameter %s was null", metadata.bodyIndex()); | ||
|
||
boolean unconditionalEncoder = UnconditionalEncoder.class.isAssignableFrom(encoder.getClass()); | ||
|
||
Object body = null; | ||
if (!unconditionalEncoder) { | ||
body = argv[metadata.bodyIndex()]; | ||
This comment has been minimized.
Sorry, something went wrong. |
||
checkArgument(body != null, "Body parameter %s was null", metadata.bodyIndex()); | ||
This comment has been minimized.
Sorry, something went wrong.
fabiocarvalho777
Author
Owner
|
||
} | ||
|
||
try { | ||
encoder.encode(body, metadata.bodyType(), mutable); | ||
if (unconditionalEncoder) { | ||
UnconditionalEncoder unEncoder = (UnconditionalEncoder) encoder; | ||
unEncoder.encode(argv, mutable); | ||
This comment has been minimized.
Sorry, something went wrong. |
||
} else { | ||
encoder.encode(body, metadata.bodyType(), mutable); | ||
} | ||
} catch (EncodeException e) { | ||
throw e; | ||
} catch (RuntimeException e) { | ||
|
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,55 @@ | ||
/** | ||
* Copyright 2012-2020 The Feign Authors | ||
* | ||
* Licensed 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 | ||
* | ||
* http://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 feign.codec; | ||
|
||
import feign.RequestTemplate; | ||
import java.lang.reflect.Type; | ||
|
||
/** | ||
* {@link Encoder} extension that allows user provided custom encoders to define the request message | ||
* payload using only the request template and the method parameters, not requiring a specific and | ||
* unique body object. | ||
* | ||
* This type of encoder is useful when an application needs a Feign client whose request payload is | ||
* defined entirely by a custom Feign encoder regardless of how many parameters are declared at the | ||
* client method. In this case, even with no presence of body parameter the encoder will have to | ||
* know how to define the request payload (for example, based on the method name, method return | ||
* type, and other metadata provided by custom annotations, all available via the provided | ||
* {@link RequestTemplate} object). | ||
* | ||
* @author [email protected] | ||
*/ | ||
public interface UnconditionalEncoder extends Encoder { | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
@Override | ||
default void encode(Object object, Type bodyType, RequestTemplate template) | ||
throws EncodeException { | ||
throw new UnsupportedOperationException( | ||
"This encode method is not supported in this type of encoder, instead, use the overloaded version with parameters array and request template"); | ||
} | ||
|
||
/** | ||
* Produces message body exclusively based on the request template. | ||
* | ||
* @param parameters the values of the parameters passed by the client when calling the method, | ||
* ordered according to parameters definition order. | ||
* @param template the request template to populate. | ||
* @throws EncodeException when encoding failed due to a checked exception. | ||
*/ | ||
void encode(Object[] parameters, RequestTemplate template) throws EncodeException; | ||
This comment has been minimized.
Sorry, something went wrong. |
||
|
||
} |
Just a small javadoc fix