Marti Pamies Sola created AXIS2-5929:
----------------------------------------

             Summary: REST Services URL GET json request not working
                 Key: AXIS2-5929
                 URL: https://issues.apache.org/jira/browse/AXIS2-5929
             Project: Axis2
          Issue Type: Improvement
          Components: json
    Affects Versions: 1.7.8
            Reporter: Marti Pamies Sola
         Attachments: AbstractJSONOMBuilder.java, 
AbstractJSONOMBuilder.java.patch

At a REST services, I do not receive HTTP GET requests when content-type is 
json, and parameters are at request URL path (not as Query string). Let me 
explain in detail:

I am implementing a REST services according to [HL7 
FHIR|[http://www.hl7.org/fhir/],] that must be able to return content both on 
xml and json (depending on http header content-type), once an HTTP GET request 
is received. Keys for the information to be returned can be provided both 
directly at the request URL path or as a Query String:
 * Keys at URL path: 
{color:#505050}[http://localhost:8080/opencdefhirserver/services/FHIR/Binary/4295642378]{color}
 * Keys as Query string: 
{color:#505050}[http://localhost:8080/opencdefhirserver/services/FHIR/Binary?id4295642378|http://localhost:8080/opencdefhirserver/services/FHIR/Binary/4295642378]{color}

Where, FHIR is my service; Binary is the axis2 operation to be executed 
(mapping to a FHIR resource); and {color:#505050}4295642378{color} the resource 
id.

Providing keys as Query String work properly with xml and json, but providing 
key at URL path just work with xml, on json I get the following exception:

"_No JSON message received through HTTP GET or POST"_

I've been reviewing source code and I guess the issue comes form this fragment 
of code at AbstractJSONOMBuilder.java line 85:

 
{code:java}
//            if ((index = requestURL.indexOf("=")) > 0) {
                jsonString = requestURL.substring(index + 1);
                reader = new StringReader(jsonString);
            } else {
                throw new AxisFault("No JSON message received through HTTP GET 
or POST");
            }
{code}
As it only accepts parameters as Query String, and when not provided it raise 
an exception.

I propose the following modification, where if not Query String is provided, it 
considers full request URL as input json.
{code:java}
//             if ((index = requestURL.indexOf("=")) > 0) {
                jsonString = requestURL.substring(index + 1);
                reader = new StringReader(jsonString);
            } else {
                /*
                 * MARTI PAMIES SOLA
                 * Get JSON message from request URI if not present as 
parameter.
                 * To be able to response to full URL requests
                 */
                HttpServletRequest httpServeltRqst 
=(HttpServletRequest)messageContext.getProperty("transport.http.servletRequest");
                String requestParam=httpServeltRqst.getRequestURI();
                if (!(requestParam.equals(""))) {
                    jsonString = requestParam;
                    reader = new StringReader(jsonString);
                }else {
                    throw new AxisFault("No JSON message received through HTTP 
GET or POST");
                }
            }
{code}
I've test locally and it work for me, so I propose to include modification at 
next release. Attached is the new AbstractJSONOMBuilder.java file and also the 
svn patch.

Hope useful.

Thanks,

Martí

 



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to