-
Notifications
You must be signed in to change notification settings - Fork 44
support custom content-type #113
Changes from all commits
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 |
|---|---|---|
|
|
@@ -26,11 +26,13 @@ | |
| import java.security.cert.CertificateException; | ||
| import java.security.cert.X509Certificate; | ||
| import java.util.Collection; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.concurrent.Callable; | ||
| import java.util.concurrent.ScheduledExecutorService; | ||
| import java.util.concurrent.TimeUnit; | ||
|
|
||
| import org.apache.commons.collections.MapUtils; | ||
| import org.apache.hugegraph.util.E; | ||
| import org.apache.hugegraph.util.ExecutorUtil; | ||
| import jakarta.ws.rs.client.Client; | ||
|
|
@@ -396,17 +398,35 @@ private Pair<Builder, Entity<?>> buildRequest( | |
| * because Entity.json() method will reset "content encoding = | ||
| * null" that has been set up by headers before. | ||
| */ | ||
| MediaType customContentType = parseCustomContentType(headers); | ||
| Entity<?> entity; | ||
| if (encoding == null) { | ||
| entity = Entity.json(object); | ||
| entity = Entity.entity(object, customContentType); | ||
| } else { | ||
| Variant variant = new Variant(MediaType.APPLICATION_JSON_TYPE, | ||
| Variant variant = new Variant(customContentType, | ||
| (String) null, encoding); | ||
| entity = Entity.entity(object, variant); | ||
| } | ||
| return Pair.of(builder, entity); | ||
| } | ||
|
|
||
| /** | ||
| * parse user custom content-type, returns MediaType.APPLICATION_JSON_TYPE default. | ||
| * @param headers | ||
| * @return | ||
| */ | ||
| public static MediaType parseCustomContentType(MultivaluedMap<String, Object> headers) { | ||
| String customContentType = null; | ||
| if (MapUtils.isNotEmpty(headers) && headers.get("Content-Type") != null) { | ||
| Object contentTypeObj = headers.get("Content-Type"); | ||
|
Member
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. seems we don't need |
||
| if (contentTypeObj instanceof List) { | ||
|
Member
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. and here the judge is redundant, change it to |
||
| customContentType = ((List<?>) contentTypeObj).get(0).toString(); | ||
|
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. Is the contentTypeObj possible to be empty
Member
Author
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. it will happens, but i think no one will write code like this: i will fix this case in next PR |
||
| } | ||
| return MediaType.valueOf(customContentType); | ||
| } | ||
| return MediaType.APPLICATION_JSON_TYPE; | ||
| } | ||
|
|
||
| private static void configConnectionManager(String url, ClientConfig conf) { | ||
| /* | ||
| * Using httpclient with connection pooling, and configuring the | ||
|
|
||
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.
maybe
private staticshould be better, but it's not a big problemThere 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.
i will fix this case in next PR