WSO2 Synapse:设置URL参数 [英] WSO2 Synapse: setting a URL parameter

查看:236
本文介绍了WSO2 Synapse:设置URL参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试做一些看似简单但无法正常工作的事情.基本上,我希望WSO2 API管理器将URL参数添加到REST调用中.

I am trying to do something that seems straightforward but can't get it to work. Basically I want the WSO2 API manager to add a URL parameter to a REST call.

我安装了WSO2 API管理器.我也有一个运行着名为 someservlet 的伪servlet的Tomcat,它简单地记录它收到的所有内容并返回ok.我已将servlet作为API添加到管理器中,因此我可以直接调用该servlet,也可以通过WSO2 API mgr调用该servlet.

I have a WSO2 API manager installed. I also have a Tomcat running with a bogus servlet called someservlet that simply logs anything it receives and returns ok. I have added the servlet as an API in the manager, so I can either call the servlet directly or via WSO2 API mgr.

我可以跑步

curl http://localhost:8080/someservlet/servlet/toto?blob=blib&secret=pass

并且servlet工作正常,它告诉我它已收到路径/toto 和参数 blob secret .

and the servlet works fine, it tells me it's received the path /toto and parameters blob and secret.

我可以跑步

curl -H "Authorization: Bearer [...]" --url "http://192.168.23.1:8280/someservlet/1.0/toto?blob=blib&secret=pass"

它的作用完全相同.到目前为止,一切都很好.

And it does exactly the same. So far, so good.

我要运行:

curl -H "Authorization: Bearer MqVQuHqLNphtPV3XF1CtXVmbyP8a" --url "http://192.168.23.1:8280/someservlet/1.0/toto?blob=blib"

(请注意,我已经删除了秘密参数)

(note that I've removed the secret parameter)

...仍然得到相同的结果.

...and still get the same result.

所以基本上我希望API管理器添加URL参数 secret = pass .

So basically I want API manager to add the URL parameter secret=pass.

将Synapse XML配置与属性REST_URL_POSTFIX 一起使用.

Use Synapse XML config with property REST_URL_POSTFIX.

我编辑了API配置文件,并添加了

I edited the API config file, and added

<property name="REST_URL_POSTFIX" value="/blob?toto=titi" scope="axis2" type="STRING"/>

现在,如果我跑步

curl -H "Authorization: Bearer [...]" --url "http://192.168.23.1:8280/someservlet/1.0/toti?blab=blib&secret=puss"

好像我运行了 someservlet/1.0/blob?toto = titi :我的所有路径和参数都消失了,并使用配置的参数进行了替换.嘿,这就是应该的方式,不是吗!

it's as if I ran someservlet/1.0/blob?toto=titi: all my path and parameters have disappeared and been repaced with the configured ones. Hey, that's how it's supposed to work, isn't it!

问题:

  1. 这不会在URL中添加任何内容,它设置了URL后缀,这意味着现有参数消失了(在上例中, blab = blib )
  2. 它必须以"/" 开头才是有效值,所以我不能只添加& secret = pass (当然,由于问题1,反正就没用了
  1. this doesn't add something to the URL, it sets the URL postfix, meaning that existing parameters disappear (in the above example, blab=blib)
  2. it has to start with a "/" to be a valid value, so I can't just add &secret=pass (of course, because of problem 1, this would be useless anyway)

因此,基本上,这使我无法附加最终的& secret = pass .

So basically this doesn't enable me to append the final &secret=pass.

我找到了这个调解人,尽管它可能无法解决问题,但这是一个很好的线索:我可以使用 secret = foo 进行呼叫,并让调解人将其替换为 secret = pass .

I found this mediator, and although it probably won't do the trick, it's a good lead: I can just call with secret=foo, and get the mediator to replace it with secret=pass.

我把它放在配置文件中:

I put this in the config file:

<rewrite>
  <rewriterule>
    <action type="replace" value="pass" fragment="query" regex="foo"/>
  </rewriterule>
</rewrite>

这不起作用.起初我以为我没有正确的动作参数.但是错误消息是:

This doesn't work. At first I thought I didn't have the action parameters right. But the error message is:

Malformed URL when processing /someservlet/1.0/toti?blab=blib&amp;secret=foo

格式错误?异常堆栈跟踪中有更多详细信息:

Malformed? There's more detail in the exception stack trace:

java.net.MalformedURLException: no protocol: /someservlet/1.0/toti?blab=blib&secret=foo

因此,正在发生的情况是调解器(记录或重写)收到一条消息,该消息的收件人:" 字段指向没有协议的URL!

So what's happening is that the mediators (log or rewrite) receive a message whose "To:" field points to a URL with no protocol!

我当然一直在搜索,在某些情况下我发现其他人有 logMediator:收件人:/blabla ,而在其他大多数情况下,他们有 logMediator :收件人:http://://blabla .我真的看不出是什么造成了差异. :-(

Of course I've been googling around, and there are some cases where I find other people have logMediator: To: /blabla, and other (most) cases where they have logMediator: To: http ://blabla. I don't really see what's causing the difference. :-(

所以这就是我被困住的地方!! :-(

我知道可能有一个大锤解决方案应该起作用:

I'm aware that there's probably a sledgehammer solution that should work:

  1. 使用属性存储完整路径和所有参数
  2. 实现我自己的介体(例如Java)来修改这些参数
  3. 使用属性REST_URL_POSTFIX 将修改后的后缀放在通话中
  1. use property to store the full path and all parameters
  2. implement my own mediator (e.g. in Java) to modify these parameters
  3. use property REST_URL_POSTFIX to put the modified postfix on the call

但是我觉得这个问题应该有一个更简单的解决方案.

However I feel that this problem should have a simpler solution.

我有一种希望,有人会把我指向一个我没有找到的简单资源(调解器,示例,语法错误等),这正是我想要的.乐观...:-)

I have a kind of hope that someone will point me to a simple resource (mediator, sample, syntax error, anything) that I haven't found and that does just what I want. Optimism... :-)

感谢您的阅读.有什么想法吗?

Thanks for reading. Any ideas?

推荐答案

对于可能遇到相同问题的任何人,这是另一个更简单,更有效的解决方案.

For anyone who may have the same issue, here's another solution, simpler and works.

转到carbon admin门户,进入API列表,找到相关的API并单击它. 这导致API的XML配置. 在地址"字段之后(和XML中的同一级别)添加字段:

Go to the carbon admin portal, to the list of APIs, find the relevant API and click on it. This leads to the XML config of the API. After the "address" field (and at the same level in the XML) add the field:

<property name="Authorization" value="stuff to add" scope="transport"/>

这将为属性"Authorization"添加值"stuff".

This adds the property "Authorization" with value "stuff".

这篇关于WSO2 Synapse:设置URL参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆