[resteasy-dev] Chinese text was wrong transfered
Jim Ma
ema at redhat.com
Wed Oct 19 23:17:43 EDT 2016
Hi Jianhua,
Which version of resteasy are you using ?
Can you try with resteasy-3.0.19.Final and create entity with utf-8
character like this ?
Form form = new Form();
form.param("album", "光明随想");
Entity<Form> entity = Entity.entity(form,
MediaType.APPLICATION_FORM_URLENCODED_TYPE.withCharset("utf-8"));
ClientBuilder.newClient().target(youadress).request().post(entity)
I tested and it works.
Thanks,
Jim
On 10/19/2016 10:30 AM, Jianhua Zhang wrote:
> hi,
>
> I have a interface need post two parameters (long string, cannot use
> get or path params), so i choose FormParam annotation:
>
> @Path(value="/song/search")
> @POST
> @Consumes("application/x-www-form-urlencoded;charset=utf-8")
> @Produces("application/json;charset=utf-8")
> ServiceResult getSongList(@FormParam("songs") String songsInfoJson,
> @FormParam("clientid") String clientId);
>
>
> and i use reasteasy-client to call this interface, post paramters like
> below:
>
> songs:[{"album":"Sunshine
> 光明随想","title":"婚礼场面舞","artist":"金元辉;","id":"fb49e3de456bee952c8c9b3d3d8977c4","fileName":"100455298.mp3","disk":-1,"duration":112431,"sid":-1,"size":1694184,"albumSid":-1,"albumId":-1},{"album":"","title":"幻想即兴曲","id":"934fdf53d47304e30b587cfae7219136","fileName":"73864517.mp3","disk":-1,"duration":376058,"sid":-1,"size":6018215,"albumSid":-1,"albumId":-1},{"album":"","title":"谷粒飞舞","id":"bffdd1bfa0bfedaf7690540221fee91e","fileName":"73891360.mp3","disk":-1,"duration":145658,"sid":-1,"size":2331813,"albumSid":-1,"albumId":-1}]
> clientid:test123
>
> when server side received, the songsInfoJson content changed to like
> below:
>
> [{"album":"Sunshine å…‰æ˜Žéš æƒ³","title":"婚礼场é
> ¢èˆž","artist":"金元辉;","id":"fb49e3de456bee952c8c9b3d3d8977c4","fileName":"100455298.mp3","disk":-1,"duration":112431,"sid":-1,"size":1694184,"albumSid":-1,"albumId":-1},{"album":"","title":"幻想å
> ³å…´æ›²","id":"934fdf53d47304e30b587cfae7219136","fileName":"73864517.mp3","disk":-1,"duration":376058,"sid":-1,"size":6018215,"albumSid":-1,"albumId":-1},{"album":"","title":"谷粒飞舞","id":"bffdd1bfa0bfedaf7690540221fee91e","fileName":"73891360.mp3","disk":-1,"duration":145658,"sid":-1,"size":2331813,"albumSid":-1,"albumId":-1}]
>
> ========================
>
> i find the problem is the charset is not set in http request header.
>
> org.jboss.resteasy.client.jaxrs.internal.proxy.processors.invocation.FormParamProcessor
> create the new form entity, for this entity, the media type is hard
> code as: APPLICATION_FORM_URLENCODED_TYPE = new
> MediaType("application", "x-www-form-urlencoded"), the consumes
> annotaion doesn't take effect.
>
> form = new Form();
> target.getInvocation().setEntity(Entity.form(form));
>
>
> org.jboss.resteasy.client.jaxrs.internal.ClientInvocation
>
> public void setEntity(Entity entity)
> {
> ...
> Object ent = entity.getEntity();
> setEntityObject(ent);
> this.entityAnnotations = entity.getAnnotations();
> Variant v = entity.getVariant();
> //header set
> headers.setMediaType(v.getMediaType());
> headers.setLanguage(v.getLanguage());
> headers.header("Content-Encoding", v.getEncoding());
> ...
>
> }
>
>
> if manual change x-www-form-urlencoded to
> x-www-form-urlencoded;charset=utf-8, the problem will save.
> is this a bug or anything wrong with me.
>
> --
> Jianhua Zhang
> iFLYTEK
>
>
> _______________________________________________
> resteasy-dev mailing list
> resteasy-dev at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/resteasy-dev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/resteasy-dev/attachments/20161020/5b759e6d/attachment-0001.html
More information about the resteasy-dev
mailing list