[ 
https://issues.apache.org/jira/browse/AXIS2-5929?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Marti Pamies Sola updated AXIS2-5929:
-------------------------------------
          Component/s: transports
    Affects Version/s: 1.8.3
                           (was: 1.7.8)
          Description: 
I am implementing a REST services according to [HL7 
FHIR|[http://www.hl7.org/fhir/],] that must be able to return a Patient 
resource, both on xml or json, depending on http Accept header, and I am not 
able to implement it using axis.

Request is:
 * 
{color:#505050}[http://localhost:8080/opencdefhirserver/services/FHIR/Binary/4295642378]{color}
 * {color:#505050}Accept =application/fhir+json
{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.

The exception I get is:

"{_}No JSON message received through HTTP GET or POST"{_}

I've been reviewing source code and I guess the issue comes from this fragment 
of code at org.apache.axis2.json.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.

Also once previous code fixed, I realize that axis does not take care or Accept 
HTTP Header, so GET Requests where not payload is provided and so no 
contentType is specified, are just able to return as XML, but not JSON. 

See org.apache.axis2.transport.http.util.RESTUtil line 144
{code:java}
            if (contentType == null || "".equals(contentType)) {
                contentType = HTTPConstants.MEDIA_TYPE_X_WWW_FORM;
            } {code}
 

I've implemented and improvement on both classes in order to be able to mange 
those request and done the Pull Request.

Hope useful.

Thanks,

Martí

 

  was:
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í

 

              Summary: REST GET request using Accept HTTP Header to indicate 
JSON, does not working  (was: REST Services URL GET json request not working)

I've update issue description as when I've updated my projecte to axis1.8.2 I 
realize I've to do another improvement.

Hope this fixed at next version.

> REST GET request using Accept HTTP Header to indicate JSON, does not working
> ----------------------------------------------------------------------------
>
>                 Key: AXIS2-5929
>                 URL: https://issues.apache.org/jira/browse/AXIS2-5929
>             Project: Axis2
>          Issue Type: Improvement
>          Components: json, transports
>    Affects Versions: 1.8.3
>            Reporter: Marti Pamies Sola
>            Priority: Minor
>         Attachments: AbstractJSONOMBuilder.java, 
> AbstractJSONOMBuilder.java.patch
>
>
> I am implementing a REST services according to [HL7 
> FHIR|[http://www.hl7.org/fhir/],] that must be able to return a Patient 
> resource, both on xml or json, depending on http Accept header, and I am not 
> able to implement it using axis.
> Request is:
>  * 
> {color:#505050}[http://localhost:8080/opencdefhirserver/services/FHIR/Binary/4295642378]{color}
>  * {color:#505050}Accept =application/fhir+json
> {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.
> The exception I get is:
> "{_}No JSON message received through HTTP GET or POST"{_}
> I've been reviewing source code and I guess the issue comes from this 
> fragment of code at org.apache.axis2.json.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.
> Also once previous code fixed, I realize that axis does not take care or 
> Accept HTTP Header, so GET Requests where not payload is provided and so no 
> contentType is specified, are just able to return as XML, but not JSON. 
> See org.apache.axis2.transport.http.util.RESTUtil line 144
> {code:java}
>             if (contentType == null || "".equals(contentType)) {
>                 contentType = HTTPConstants.MEDIA_TYPE_X_WWW_FORM;
>             } {code}
>  
> I've implemented and improvement on both classes in order to be able to mange 
> those request and done the Pull Request.
> Hope useful.
> Thanks,
> Martí
>  



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

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

Reply via email to