apollo icon indicating copy to clipboard operation
apollo copied to clipboard

openapi请求如果key是a.bS/TT/AT,则报404错误

Open PeterHang opened this issue 2 years ago • 9 comments

openapi的Java client,1.7.0,如果key是a.bS/TT/AT,则请求就会报404错误。上次修完后,[]是可以了,但是key为a.bS/TT/AT还是不行,只不过这次报404了

PeterHang avatar Jul 06 '22 04:07 PeterHang

tomcat路径中允许未编码的字符和查询字符串中允许的未编码字符,/字符不在范围内

" < > [ \ ] ^ ` { | }

image tomcat attribute

CalebZYC avatar Jul 06 '22 15:07 CalebZYC

那这就比较尴尬了,在网页上操作是允许放 / 字符的,在openapi就不行了,那应该怎么办? 总不能因为网页上key是放在body里面,openapi的key是在url里面,然后有些key的字符在open api就不支持,对吧?

PeterHang avatar Jul 07 '22 02:07 PeterHang

tomcat路径中允许未编码的字符和查询字符串中允许的未编码字符,/字符不在范围内

" < > [ \ ] ^ ` { | }

image tomcat attribute

那这就比较尴尬了,在网页上操作是允许放 / 字符的,在openapi就不行了,那应该怎么办? 总不能因为网页上key是放在body里面,openapi的key是在url里面,然后有些key的字符在open api就不支持,对吧?

PeterHang avatar Jul 08 '22 03:07 PeterHang

tomcat具体支持哪些字符不重要,重要的是所有客户端必须严格按照HTTP协议规定的格式发送请求,该怎么编码就怎么编码,不能与具体哪一个web container绑定。

On Jul 8, 2022, at 11:13, PeterHang @.***> wrote:

tomcat路径中允许未编码的字符和查询字符串中允许的未编码字符,/字符不在范围内

" < > [ \ ] ^ ` { | } https://user-images.githubusercontent.com/42887532/177584445-a2450cce-999c-44bd-8ce1-a249335a73c7.png tomcat attribute https://tomcat.apache.org/tomcat-8.5-doc/config/http.html 那这就比较尴尬了,在网页上操作是允许放 / 字符的,在openapi就不行了,那应该怎么办? 总不能因为网页上key是放在body里面,openapi的key是在url里面,然后有些key的字符在open api就不支持,对吧?

— Reply to this email directly, view it on GitHub https://github.com/apolloconfig/apollo/issues/4447#issuecomment-1178494125, or unsubscribe https://github.com/notifications/unsubscribe-auth/AASQE76E63SX7N76INUPDILVS6MEPANCNFSM52YHMFWA. You are receiving this because you are subscribed to this thread.

qmwu2000 avatar Jul 11 '22 02:07 qmwu2000

tomcat具体支持哪些字符不重要,重要的是所有客户端必须严格按照HTTP协议规定的格式发送请求,该怎么编码就怎么编码,不能与具体哪一个web container绑定。

image 那现在可以在网页上保存key里面含有“/”字符,用Apollo open api的Java client 应该请求?

PeterHang avatar Jul 11 '22 02:07 PeterHang

tomcat具体支持哪些字符不重要,重要的是所有客户端必须严格按照HTTP协议规定的格式发送请求,该怎么编码就怎么编码,不能与具体哪一个web container绑定。 On Jul 8, 2022, at 11:13, PeterHang @.***> wrote: tomcat路径中允许未编码的字符和查询字符串中允许的未编码字符,/字符不在范围内 " < > [ \ ] ^ ` { | } https://user-images.githubusercontent.com/42887532/177584445-a2450cce-999c-44bd-8ce1-a249335a73c7.png tomcat attribute https://tomcat.apache.org/tomcat-8.5-doc/config/http.html 那这就比较尴尬了,在网页上操作是允许放 / 字符的,在openapi就不行了,那应该怎么办? 总不能因为网页上key是放在body里面,openapi的key是在url里面,然后有些key的字符在open api就不支持,对吧? — Reply to this email directly, view it on GitHub <#4447 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AASQE76E63SX7N76INUPDILVS6MEPANCNFSM52YHMFWA. You are receiving this because you are subscribed to this thread.

image 那现在可以在网页上保存key里面含有“/”字符,用Apollo open api的Java client 应该请求?

PeterHang avatar Jul 11 '22 02:07 PeterHang

那现在可以在网页上保存key里面含有“/”字符,用Apollo open api的Java client 应该请求?

造成这个差异的原因是通过页面修改/删除配置的接口没有把 key 放在 url path 上,而 open api 的实现是把 key 放在 url path 上的。 updateItem 可以比较简单的适配一下,比如新开一个不带 key 的接口。 deleteItem 的适配就要麻烦一点了,因为 openapi 现在的 dto 没有把 item id 返回给调用端,这个得看下实现方案。

https://github.com/apolloconfig/apollo/blob/3440475ca0ad59fadc23f583c9fc36594dda1318/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/ItemController.java#L109-L113

https://github.com/apolloconfig/apollo/blob/3440475ca0ad59fadc23f583c9fc36594dda1318/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/ItemController.java#L123-L127

https://github.com/apolloconfig/apollo/blob/3440475ca0ad59fadc23f583c9fc36594dda1318/apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/v1/controller/ItemController.java#L84-L89

https://github.com/apolloconfig/apollo/blob/3440475ca0ad59fadc23f583c9fc36594dda1318/apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/v1/controller/ItemController.java#L115-L120

nobodyiam avatar Jul 12 '22 01:07 nobodyiam

那现在可以在网页上保存key里面含有“/”字符,用Apollo open api的Java client 应该请求?

造成这个差异的原因是通过页面修改/删除配置的接口没有把 key 放在 url path 上,而 open api 的实现是把 key 放在 url path 上的。 updateItem 可以比较简单的适配一下,比如新开一个不带 key 的接口。 deleteItem 的适配就要麻烦一点了,因为 openapi 现在的 dto 没有把 item id 返回给调用端,这个得看下实现方案。

https://github.com/apolloconfig/apollo/blob/3440475ca0ad59fadc23f583c9fc36594dda1318/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/ItemController.java#L109-L113

https://github.com/apolloconfig/apollo/blob/3440475ca0ad59fadc23f583c9fc36594dda1318/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/ItemController.java#L123-L127

https://github.com/apolloconfig/apollo/blob/3440475ca0ad59fadc23f583c9fc36594dda1318/apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/v1/controller/ItemController.java#L84-L89

https://github.com/apolloconfig/apollo/blob/3440475ca0ad59fadc23f583c9fc36594dda1318/apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/v1/controller/ItemController.java#L115-L120

image 本地试了下,如果改的话,admin service也得改。查询item的话,还是将key放在URL上去查询的。

PeterHang avatar Aug 03 '22 06:08 PeterHang

@PeterHang 是的,更新还好搞一些,PUT 操作可以把 item key 放在 body 里面,查询和删除这两个操作比较麻烦,GET 和 DELETE 只能放在 url path 上

nobodyiam avatar Aug 06 '22 12:08 nobodyiam

是的,更新还好搞一些,PUT 操作可以把 item key 放在 body 里面,查询和删除这两个操作比较麻烦,GET 和 DELETE 只能放在 url path 上

what if we just encode/decode the item key ? we can provide new interface on get/update/delete , and we encode the item key in client and decode key in admin service. in this way , the old client can also work normally. what do you think ? @nobodyiam

AbnerHuang2 avatar Aug 17 '22 03:08 AbnerHuang2

有什么进展吗?考虑更新支持key中带/的openapi更新吗?

snowy861227 avatar Aug 18 '22 09:08 snowy861227

what if we just encode/decode the item key ? we can provide new interface on get/update/delete , and we encode the item key in client and decode key in admin service. in this way , the old client can also work normally. what do you think ?

@AbnerHuang2 I'm interested in this proposal, would you please give an example to show your idea?

nobodyiam avatar Aug 19 '22 00:08 nobodyiam

take getItem as an example, when we called getItem with openapi client, we can encode the key like the follow way,

    String encode = new String(Base64.getEncoder().encode(key.getBytes(StandardCharsets.UTF_8)));
    OpenApiPathBuilder pathBuilder = OpenApiPathBuilder.newBuilder()
        .envsPathVal(env)
        .appsPathVal(appId)
        .clustersPathVal(clusterName)
        .namespacesPathVal(namespaceName)
        .itemsPathVal(encode);

and this will execute in portal/ItemOpenController, and in this controller passthrough the key to adminservice/ItemController, and in adminservice/ItemController we decode the key like follow way,

key = new String(Base64.getDecoder().decode(key.getBytes(StandardCharsets.UTF_8)));
Item item = itemService.findOne(appId, clusterName, namespaceName, key);

then we can get the correct result.

ps, the encode/decode algorithm can be replace with other simple algorithm if their is more effective encode/decode algorithm. @nobodyiam

AbnerHuang2 avatar Aug 23 '22 00:08 AbnerHuang2

Test example:

企业微信截图_1c35ab62-226e-4344-8a13-ff877a257e5e

Test Result:

企业微信截图_37a85783-b41c-4fbd-a744-26ea074f5959

AbnerHuang2 avatar Aug 23 '22 01:08 AbnerHuang2

@AbnerHuang2

This is an interesting proposal! In this way, we could add a new set of open apis that accept encoded keys. I think we may still call the old set of apis if the key has no special character to make the apollo-openapi-client compatible with the old versions of apollo-portal.

nobodyiam avatar Aug 26 '22 00:08 nobodyiam

wow, this way is more practicable, in the normal sutuation, it works like the old workflow, and we just use little cost to deal with unexpectable key, I'll try this. but I need to finished #4519 first.

AbnerHuang2 avatar Aug 26 '22 06:08 AbnerHuang2

In my situation, I wrote a apollo portal http client, that also works.

chenxing1020 avatar Aug 29 '22 00:08 chenxing1020

Does the newclient can open to work now?Could you share me the note ?thanks

---原始邮件--- 发件人: "Jason @.> 发送时间: 2022年8月19日(周五) 上午8:59 收件人: @.>; 抄送: @.@.>; 主题: Re: [apolloconfig/apollo] openapi请求如果key是a.bS/TT/AT,则报404错误 (Issue #4447)

what if we just encode/decode the item key ? we can provide new interface on get/update/delete , and we encode the item key in client and decode key in admin service. in this way , the old client can also work normally. what do you think ?

@AbnerHuang2 I'm interested in this proposal, would you please give an example to show your idea?

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.Message ID: @.***>

snowy861227 avatar Sep 16 '22 07:09 snowy861227

@snowy861227 This fix was merged to the master branch and not yet released.

nobodyiam avatar Sep 17 '22 11:09 nobodyiam