theClam
theClam

Reputation: 1

WSO2 not allowing '@' symbol as input parameter in methods

Whenever I input an @ symbol I get an error instead of the empty list of roles that I would expect. The method being roles() and the last part of the URL being the input parameter. I need to use the @ symbol as I want to use email addresses as the input parameter.

TERMINAL COMMAND: curl --header 'Accept: application/json' --header 'Authorization: Bearer b85f73f2-f2fb-3a92-9066-d0af4d6a50eb' 'https://apitst.linkedsystems.uk/account/v1/user/roles/oeoe' OUTPUT: {"Roles":[]}

TERMINAL COMMAND WITH '@' SYMBOL: curl --header 'Accept: application/json' --header 'Authorization: Bearer b85f73f2-f2fb-3a92-9066-d0af4d6a50eb' 'https://apitst.linkedsystems.uk/account/v1/user/roles/oeoe@' OUTPUT: 404Status reportRuntime ErrorNo matching resource found for given API Request

Any idea how to alter the API so that it allows @ symbols as input parameters? I've tried changing the carbon.xml & user-mgt.xml but no luck.

Any help is much appreciated. Thanks.

Upvotes: 0

Views: 459

Answers (2)

Sashika Wijesinghe
Sashika Wijesinghe

Reputation: 425

You have two options to use the '@' sign in your API

  1. Use the encoded value for the @ sign in the URL. If you have an API defined like "/user/{email}" you have to provide the percentage encoded value for the @ sign with the curl command.

ex: curl --header 'Accept: application/json' 'http://localhost:8280/testapi/user/test%40gmail.com'

<api xmlns="http://ws.apache.org/ns/synapse" name="testAPI" context="/testapi">
       <resource methods="GET" uri-template="/user/{email}">
          <inSequence>
             <payloadFactory media-type="json">
                <format>{    "id": 1,    "email": "$1"}</format>
                <args>
                   <arg evaluator="xml" expression="get-property('uri.var.email')"/>
                </args>
             </payloadFactory>
             <respond/>
          </inSequence>
       </resource>
    </api>
  1. If you define the API with /user/{+email} it will accept the @ sign in your URL (Refer - https://www.rfc-editor.org/rfc/rfc6570#section-3.2.3 )

ex: curl --header 'Accept: application/json' 'http://localhost:8280/testapi/user/[email protected]'

Upvotes: 2

hbn1991
hbn1991

Reputation: 274

The problem here is, you are not urlencoding the data you are sending. If you are using curl to invoke the API, change the curl command as follows,

curl -G --header 'Accept: application/json' --header 'Authorization: Bearer b85f73f2-f2fb-3a92-9066-d0af4d6a50eb' 'https://apitst.linkedsystems.uk/account/v1/user/roles/oeoe@' -k

Replace the token value with the new token and it should do the trick.

Upvotes: 0

Related Questions