0

Encountered this error message below:

org.apache.commons.httpclient.URIException: Invalid query
    at org.apache.commons.httpclient.URI.parseUriReference(URI.java:2049)
    at org.apache.commons.httpclient.URI.<init>(URI.java:147)

Here are my exact codes below, encountering an issue when calling

<?xml version="1.0" encoding="UTF-8"?>
<api context="/test_api" name="rest" xmlns="http://ws.apache.org/ns/synapse">
    <resource methods="GET" uri-template="/hello?name={namVal}">
        <inSequence>

            <property name="SYSTEM" expression="$url:name"/>
            <property name="uri.var.name" expression="$ctx:SYSTEM"/>

            <call blocking="true">
                <endpoint key="hello_EP"/>
            </call>
            <payloadFactory media-type="xml">
                .....
            </payloadFactory>
            <respond />
        </inSequence>
        <outSequence />
        <faultSequence />
    </resource>
</api>

Here is my EP for reference

<?xml version="1.0" encoding="UTF-8"?>
<endpoint name="hello_EP" xmlns="http://ws.apache.org/ns/synapse">
    <address uri="http://xxxxxxxxxx:(port)/spring/hello?name={uri.var.fname}" methods="POST"/>
</endpoint>

2 Answers2

0

Query param in the endpoint is {uri.var.fname} but the property name uri.var.name. Therefore change the property name to uri.var.fname.

This can be directly done by a single property instead of having two properties as below,

<property name="uri.var.fname" expression="$url:name"/>
Saad Sahibjan
  • 300
  • 1
  • 6
0

The issue i posted was already fixed yesterday. To fix the issue i need to change the uri-template to url-mapping.

here is my updated code now:

Endpoint:

<?xml version="1.0" encoding="UTF-8"?>
<endpoint name="hello_EP" xmlns="http://ws.apache.org/ns/synapse">
    <address uri="http://xxxxxxxxxxxxxxxxxx:12345/SpringRest/"/>
</endpoint>

API code.

<?xml version="1.0" encoding="UTF-8"?>
<api context="/temp_api" name="springRest" xmlns="http://ws.apache.org/ns/synapse">
    <resource methods="GET" url-mapping="/hello">
        <inSequence>
            <!-- URL Parameters -->
            <property expression="$url:name" name="SYSTEM" scope="default" type="STRING"/>
            <!-- Logs -->
            <log level="custom">
                <property expression="$ctx:SYSTEM" name="value-system"/>
            </log>
            <!-- URL param value passed to endpoint param -->
            <property expression="$ctx:SYSTEM" name="uri.var.fname" scope="default" type="STRING"/>
            <!-- Call endpoint -->
            <call blocking="true">
                <endpoint key="hello_EP"/>
            </call>
            <payloadFactory media-type="xml">
               ..
               ..
            </payloadFactory>
            <respond/>
        </inSequence>
        <outSequence/>
        <faultSequence/>
    </resource>
</api>

output:

<body xmlns="http://ws.apache.org/ns/synapse">
                        {
                        "id": 1,
                        "content": "Hello, world!"
                        }
                    </body>