axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Miguel Ángel Francisco Fernández (JIRA) <j...@apache.org>
Subject [jira] [Comment Edited] (AXIS2-5489) Encoding GET parameters with '+' character in generated REST clients with WSDL2Java
Date Thu, 28 Mar 2013 12:29:16 GMT

    [ https://issues.apache.org/jira/browse/AXIS2-5489?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13616210#comment-13616210
] 

Miguel Ángel Francisco Fernández edited comment on AXIS2-5489 at 3/28/13 12:28 PM:
-----------------------------------------------------------------------------------

Yes, the problem is that I can't send the + symbol in a GET parameter. For example, if I want
to send the string "a+b", I can't, because the + symbol is not encoded, and it is interpreted
as a blank space in the server.

This is an example that you can use to reproduce the problem:

------------------------------------------------------------------------------------------
WSDL
------------------------------------------------------------------------------------------

<?xml version="1.0" encoding="UTF-8"?>

<wsdl:description xmlns:wsdl="http://www.w3.org/ns/wsdl"
        targetNamespace="http://www.sample.com/wsdl"
        xmlns:tns="http://www.sample.com/wsdl"
        xmlns:whttp="http://www.w3.org/ns/wsdl/http"
        xmlns:wsdlx="http://www.w3.org/ns/wsdl-extensions"
        xmlns:xs="http://www.w3.org/2001/XMLSchema"
        xmlns:msg="http://www.sample.com/xsd">

    <wsdl:documentation>
    Example
    </wsdl:documentation>

    <!--
    Types
    -->
    <wsdl:types>
        <xs:import namespace="http://www.sample.com/xsd"
            schemaLocation="sample.xsd"/>
    </wsdl:types>

    <!--
    Interface
    -->
    <wsdl:interface name="SampleInterface">

        <wsdl:operation name="foo"
            pattern="http://www.w3.org/ns/wsdl/in-out"
            style="http://www.w3.org/ns/wsdl/style/iri"
            wsdlx:safe="true">

            <wsdl:documentation>
            Example operation.
            </wsdl:documentation>

            <wsdl:input element="msg:fooParams"/>
            <wsdl:output element="msg:fooResponse"/>
        </wsdl:operation>

    </wsdl:interface>

    <!--
    Binding
    -->
    <wsdl:binding name="SampleHTTPBinding"
        type="http://www.w3.org/ns/wsdl/http"
        interface="tns:SampleInterface">

        <wsdl:documentation>
        HTTP binding for the Sample service.
        </wsdl:documentation>

        <wsdl:operation ref="tns:foo" whttp:method="GET"
                whttp:location="foo"/>

    </wsdl:binding>

    <!--
    Service
    -->
    <wsdl:service name="Sample" interface="tns:SampleInterface">

        <wsdl:documentation>
        Sample service.
        </wsdl:documentation>

        <wsdl:endpoint name="SampleHTTPEndpoint"
            binding="tns:SampleHTTPBinding"
            address="http://www.sample.com/">

        </wsdl:endpoint>

    </wsdl:service>

</wsdl:description>

------------------------------------------------------------------------------------------
XSD
------------------------------------------------------------------------------------------

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
        targetNamespace="http://www.sample.com/xsd"
        xmlns:tns="http://www.sample.com/xsd"
        xmlns:wsdlx="http://www.w3.org/ns/wsdl-extensions">

    <!--
    Operations
    -->
    <xsd:element name="fooParams">
        <xsd:annotation>
            <xsd:documentation>
            Params for operation foo.
            </xsd:documentation>
        </xsd:annotation>
        <xsd:complexType>
            <xsd:sequence>
                <xsd:element name="bar" type="xsd:string" />
            </xsd:sequence>
        </xsd:complexType>
    </xsd:element>

    <xsd:element name="fooResponse">
        <xsd:annotation>
            <xsd:documentation>
            Response of operation foo.
            </xsd:documentation>
        </xsd:annotation>
        <xsd:complexType>
            <xsd:sequence>
                <xsd:element name="bar" type="xsd:string" />
            </xsd:sequence>
        </xsd:complexType>
    </xsd:element>

</xsd:schema>

------------------------------------------------------------------------------------------
wsdl2java command line
------------------------------------------------------------------------------------------

./wsdl2java.sh -wv 2 -uw -o /tmp/output -uri /tmp/sample.wsdl

------------------------------------------------------------------------------------------
Java client using the generated JAR file: Sample-test-client.jar
------------------------------------------------------------------------------------------
public class Main {

    public static void main(String[] args) {

        try {
            SampleStub sampleStub = new SampleStub();
            
            /*
             * Invoking the operation with "a b", AXIS2 makes the following HTTP
             * request:
             * 
             * GET /foo?bar=a%20b HTTP/1.1
             * Content-Type: application/x-www-form-urlencoded; charset=UTF-8
             * SOAPAction: ""
             * User-Agent: Axis2
             * Host: www.sample.com
             * 
             * This request is correct because it encodes the space as "%20".
             */
            sampleStub.foo("a b");
            
            /*
             * Invoking the operation with "a+b", AXIS2 makes the following HTTP
             * request:
             * 
             * GET /foo?bar=a+b HTTP/1.1
             * Content-Type: application/x-www-form-urlencoded; charset=UTF-8
             * SOAPAction: ""
             * User-Agent: Axis2
             * Host: www.sample.com
             * 
             * This request is incorrect because it does not encode the +
             * symbol, it should invoke:  GET /foo?bar=a%2Bb HTTP/1.1.
             */
            sampleStub.foo("a+b");
            
            /*
             * Invoking the operation with "a%2Bb", AXIS2 makes the following HTTP
             * request:
             * 
             * GET /foo?bar=a%252Bb HTTP/1.1
             * Content-Type: application/x-www-form-urlencoded; charset=UTF-8
             * SOAPAction: ""
             * User-Agent: Axis2
             * Host: www.sample.com
             * 
             * This request is correct because it encodes the symbol % as
             * space as "%25".
             */
            sampleStub.foo("a%2Bb");

        } catch(Exception e) {
            e.printStackTrace();
        }

    }

}


                
      was (Author: miguelafr):
    Yes, the problem is that I can't send the + symbol in a GET parameter. For example, if
I want to send the string "a+b", I can't, because the + symbol is not encoded, and it is interpreted
as a blank space in the server.

This is an example that you can use to reproduce the problem:

------------------------------------------------------------------------------------------
WSDL
------------------------------------------------------------------------------------------

<?xml version="1.0" encoding="UTF-8"?>

<wsdl:description xmlns:wsdl="http://www.w3.org/ns/wsdl"
        targetNamespace="http://www.sample.com/wsdl"
        xmlns:tns="http://www.sample.com/wsdl"
        xmlns:whttp="http://www.w3.org/ns/wsdl/http"
        xmlns:wsdlx="http://www.w3.org/ns/wsdl-extensions"
        xmlns:xs="http://www.w3.org/2001/XMLSchema"
        xmlns:msg="http://www.sample.com/xsd">

    <wsdl:documentation>
    Example
    </wsdl:documentation>

    <!--
    Types
    -->
    <wsdl:types>
        <xs:import namespace="http://www.sample.com/xsd"
            schemaLocation="sample.xsd"/>
    </wsdl:types>

    <!--
    Interface
    -->
    <wsdl:interface name="SampleInterface">

        <wsdl:operation name="foo"
            pattern="http://www.w3.org/ns/wsdl/in-out"
            style="http://www.w3.org/ns/wsdl/style/iri"
            wsdlx:safe="true">

            <wsdl:documentation>
            Example operation.
            </wsdl:documentation>

            <wsdl:input element="msg:fooParams"/>
            <wsdl:output element="msg:fooResponse"/>
        </wsdl:operation>

    </wsdl:interface>

    <!--
    Binding
    -->
    <wsdl:binding name="SampleHTTPBinding"
        type="http://www.w3.org/ns/wsdl/http"
        interface="tns:SampleInterface">

        <wsdl:documentation>
        HTTP binding for the Sample service.
        </wsdl:documentation>

        <wsdl:operation ref="tns:foo" whttp:method="GET"
                whttp:location="foo"/>

    </wsdl:binding>

    <!--
    Service
    -->
    <wsdl:service name="Sample" interface="tns:SampleInterface">

        <wsdl:documentation>
        Sample service.
        </wsdl:documentation>

        <wsdl:endpoint name="SampleHTTPEndpoint"
            binding="tns:SampleHTTPBinding"
            address="http://www.sample.com/">

        </wsdl:endpoint>

    </wsdl:service>

</wsdl:description>

------------------------------------------------------------------------------------------
XSD
------------------------------------------------------------------------------------------

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
        targetNamespace="http://www.sample.com/xsd"
        xmlns:tns="http://www.sample.com/xsd"
        xmlns:wsdlx="http://www.w3.org/ns/wsdl-extensions">

    <!--
    Operations
    -->
    <xsd:element name="fooParams">
        <xsd:annotation>
            <xsd:documentation>
            Params for operation foo.
            </xsd:documentation>
        </xsd:annotation>
        <xsd:complexType>
            <xsd:sequence>
                <xsd:element name="bar" type="xsd:string" />
            </xsd:sequence>
        </xsd:complexType>
    </xsd:element>

    <xsd:element name="fooResponse">
        <xsd:annotation>
            <xsd:documentation>
            Response of operation foo.
            </xsd:documentation>
        </xsd:annotation>
        <xsd:complexType>
            <xsd:sequence>
                <xsd:element name="bar" type="xsd:string" />
            </xsd:sequence>
        </xsd:complexType>
    </xsd:element>

</xsd:schema>

------------------------------------------------------------------------------------------
wsdl2java command line
------------------------------------------------------------------------------------------

./wsdl2java.sh -wv 2 -uw -o /tmp/output -uri /tmp/sample.wsdl

------------------------------------------------------------------------------------------
Java client using the generated JAR file: Sample-test-client.jar
------------------------------------------------------------------------------------------
public class Main {

    public static void main(String[] args) {

        try {
            SampleStub sampleStub = new SampleStub();
            
            /*
             * Invoking the operation with "a b", AXIS2 do the following HTTP
             * request:
             * 
             * GET /foo?bar=a%20b HTTP/1.1
             * Content-Type: application/x-www-form-urlencoded; charset=UTF-8
             * SOAPAction: ""
             * User-Agent: Axis2
             * Host: www.sample.com
             * 
             * This request is correct because it encodes the space as "%20".
             */
            sampleStub.foo("a b");
            
            /*
             * Invoking the operation with "a+b", AXIS2 do the following HTTP
             * request:
             * 
             * GET /foo?bar=a+b HTTP/1.1
             * Content-Type: application/x-www-form-urlencoded; charset=UTF-8
             * SOAPAction: ""
             * User-Agent: Axis2
             * Host: www.sample.com
             * 
             * This request is incorrect because it does not encode the +
             * symbol, it should invoke:  GET /foo?bar=a%2Bb HTTP/1.1.
             */
            sampleStub.foo("a+b");
            
            /*
             * Invoking the operation with "a%2Bb", AXIS2 do the following HTTP
             * request:
             * 
             * GET /foo?bar=a%252Bb HTTP/1.1
             * Content-Type: application/x-www-form-urlencoded; charset=UTF-8
             * SOAPAction: ""
             * User-Agent: Axis2
             * Host: www.sample.com
             * 
             * This request is correct because it encodes the symbol % as
             * space as "%25".
             */
            sampleStub.foo("a%2Bb");

        } catch(Exception e) {
            e.printStackTrace();
        }

    }

}


                  
> Encoding GET parameters with '+' character in generated REST clients with WSDL2Java
> -----------------------------------------------------------------------------------
>
>                 Key: AXIS2-5489
>                 URL: https://issues.apache.org/jira/browse/AXIS2-5489
>             Project: Axis2
>          Issue Type: Bug
>          Components: kernel, transports
>    Affects Versions: 1.6.2
>         Environment: Ubuntu
>            Reporter: Miguel Ángel Francisco Fernández
>            Priority: Blocker
>              Labels: +, GET, REST, encode,
>             Fix For: 1.6.2
>
>   Original Estimate: 2h
>  Remaining Estimate: 2h
>
> Using the wsdl2java tool to generate a Java client to access a REST web service described
with a WSDL 2.0, the generated client does not encode the symbol '+' in GET parameters.
> For example, if I have an URL "/get_url", and I set the parameter "param" to "x+x", the
symbol "+" is not encoded, and therefore it is interpreted as a space on the server ("x x").
If I try to send the parameter encoded, i.e., "%2B", then "%252B" is received in the server.
> Therefore, it is not possible to send the '+' symbol in a GET parameter.
> I guess that it is caused by the definition of the field LEGAL_CHARACTERS_IN_QUERY in
the interface org.apache.axis2.description.WSDL2Constants, which is set to "-._~!$'()*+,;=:@/?"

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

---------------------------------------------------------------------
To unsubscribe, e-mail: java-dev-unsubscribe@axis.apache.org
For additional commands, e-mail: java-dev-help@axis.apache.org


Mime
View raw message