-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Added ability to expand and encode variables in body annotation and expand request line variables that are not already key pairs #107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
e368139
a325e91
ade22c8
8a80513
69fa0b5
d20bbe6
91367d6
e6400da
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -199,6 +199,49 @@ public void postBodyParam() throws IOException, InterruptedException { | |
| server.shutdown(); | ||
| } | ||
| } | ||
|
|
||
| class Operation { | ||
| public String param1; | ||
| public String param2; | ||
| public Operation(String param1, String param2) { | ||
| this.param1 = param1; | ||
| this.param2 = param2; | ||
| } | ||
| } | ||
| interface ObjectBodyParamInterface { | ||
| @RequestLine("POST /sdpapi/request") | ||
| @Body("OPERATION_NAME=GET_REQUESTS&TECHNICIAN_KEY={technicalKey}&INPUT_DATA={inputData}") | ||
| public String getRequests( | ||
| @Named("technicalKey") String technicalKey, | ||
| @Named("inputData") Operation operation | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ex. if this weren't |
||
| ); | ||
| } | ||
|
|
||
| @Test | ||
| public void postBodyEncodedBodyParam() throws Exception { | ||
| final MockWebServer server = new MockWebServer(); | ||
| server.enqueue(new MockResponse().setBody("foo")); | ||
| server.play(); | ||
| ObjectBodyParamInterface api = Feign.builder() | ||
| .encoder(new Encoder() { | ||
| public void encode(Object object, RequestTemplate template) | ||
| throws feign.codec.EncodeException { | ||
| if(object instanceof Operation) { | ||
| Operation op = (Operation) object; | ||
| template.body("<param1>"+op.param1+"</param1>" | ||
| +"<param2>"+op.param2+"</param2>"); | ||
| } else { | ||
| template.body(object.toString()); | ||
| } | ||
| } | ||
| }) | ||
| .target(ObjectBodyParamInterface.class, "http://localhost:"+ server.getPort()); | ||
| api.getRequests("Test", new Operation("param1", "param2")); | ||
| RecordedRequest request = server.takeRequest(); | ||
|
|
||
| assertEquals(new String(request.getBody(), UTF_8), | ||
| "OPERATION_NAME=GET_REQUESTS&TECHNICIAN_KEY=Test&INPUT_DATA=<param1>param1</param1><param2>param2</param2>"); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ps I sincerely pity you for having to deal with an api that encodes xml as a query param :P |
||
| } | ||
|
|
||
| @Test | ||
| public void postGZIPEncodedBodyParam() throws IOException, InterruptedException { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm this looks kindof meh. Seems we should not do something as magical as this, and instead use the type adapter system. feign tries really hard to avoid reflection.