Re: Invalid character found in the request target TomEE 10.0.1

Richard Zowalla <[email protected]> Fri, 11 Apr 2025 20:46:51 +0200
Newsgroups gmane.comp.java.openejb.user
Message-ID <[email protected]>
If you want to hack around (into the undefined semantics sea), you can =
define a query parameter and add that to your endpoint (String or a =
like) and do the JSON processing yourself.
I wouldn=E2=80=99t do though.

> Am 11.04.2025 um 18:52 schrieb Nanjangud Shivakumar Karthik =
<[email protected]>:
>=20
> Hello
>=20
>=20
> *>> if you insist on GET, you need to correctly encode the json into a
> query parameter.*
>=20
> I still would like to use GET instead of POST ( Since the  args  =
submitted
> is  Processing ,Filtering   the data on return , It has nothing to =
persist
>=20
> Could u suggest on correcting to encode the Json into the Query =
Parameter
>=20
> Json  fetched from UI
>=20
> {  "searcharg": "jakarta.ws.rs.ext.Provider",  "folderfilepatharg":
> "F:/TOOLS/APACHEMAVEN/MAVEN-REPO",   "searchextnarg" : "jar",
> "searchstartno": 120, "searchendno": 150 }
>=20
> on the Controller the method defined is as follows used to  prefilter =
args
> to process
>=20
> @GET
>=20
> @Consumes(MediaType.APPLICATION_JSON)
>=20
> @Produces(MediaType.APPLICATION_JSON)
>=20
> @Path("/SearchBeanGet")
>=20
> public SearchZipJarBean getSearchBean(SearchZipJarBean srchBean) {
>=20
> loggerlog.info("Pre Process " + srchBean.toString());
>=20
> ....
>=20
> loggerlog.info("Post Process " + srchBean.toString()); return =
srchZpjra
> .getSrchBean();
>=20
> }
>=20
> with regards
> N.S.Karthik
>=20
> On Thu, Apr 10, 2025 at 1:56=E2=80=AFPM Richard Zowalla =
<[email protected]> wrote:
>=20
>> GET with a (JSON) payload is against the RFC; a GET with a payload =
has no
>> defined semantics:
>> https://datatracker.ietf.org/doc/html/rfc7231#section-4.3.1
>>=20
>> That being said, =E2=80=9Edata=E2=80=9C is appended to the URL as =
query parameters, the
>> content type is ignored and the JSON strings will appear (encoded) in =
the
>> URL.
>>=20
>> I would suggest to switch to POST here =E2=80=A6 if you insist on =
GET, you need to
>> correctly encode the json into a query parameter.
>>=20
>>> Am 10.04.2025 um 07:25 schrieb KARTHIK SHIVAKUMAR =
<[email protected]
>>> :
>>>=20
>>>=20
>>>=20
>>> Hello
>>>=20
>>> Spec :
>>> Container : Apache TomEE PLUS -10.0.1
>>> Java      : 22
>>> Ide       : Eclipse IDE
>>> O/s       : Win-10
>>> Browser : Firefox
>>> RESTClient : PostMan
>>>=20
>>> a) Process
>>>     A simple Web GET request  to  REST Web Service used top parse
>> Folder  and return with  results.
>>>    The request fails thru the BROWSER  but passes thru RESTClient
>>>=20
>>>=20
>>> b) Problem
>>> Ajax Submission of a JSON.Stringified   on GET type  is returning  =
"HTTP
>> 400 Bad Request" ( Image attached for reference )
>>> As suggested  Added thy Relaxation char to the Server.xml
>>>  Tomee/conf/Server.xml  : <Connector connectionTimeout=3D"20000"
>> maxParameterCount=3D"1000"  port=3D"8080"  protocol=3D"HTTP/1.1"
>> redirectPort=3D"8443"
>>>             server=3D"Apache TomEE"  xpoweredBy=3D"false"
>> relaxedPathChars=3D" [  ] { } ^ |  "  relaxedQueryChars=3D" [ ] { } ^ =
|  "   />
>>> Ajax Script :
>>>                     function
>> ajaxProcessContentjson(urljspVal,dataValue,httStatus){
>>>                                        var InstMesg =3D '';
>>>                                         $.ajax({
>>>                                               type     :  "GET",
>>>                                               url      :  urljspVal,
>>>                                               data     :
>> JSON.stringify(dataValue),
>>>                                               async       :  false,
>>>                                               global      :  false,
>>>                                               cache       :  false,
>>>                                               dataType    :  "json",
>>>                                               contentType :
>> "application/json",
>>>                                                success  :
>> function(responseObject, textStatus, jqXHR) {
>>>                                                       =
console.log("AJAX
>> PASS" + jqXHR.status);
>>>                                                },
>>>                                               error    :
>> function(responseObject, textStatus, jqXHR) {
>>>=20
>> console.log("AJAX FAIL : " + JSON.stringify(responseObject));
>>>                                                }
>>>                                                    });
>>>                                                      return =
InstMesg;
>>>                                      }
>>>=20
>>> Browser O/p
>>> "{ \"searcharg\" : \"jakarta.ws.rs.ext.Provider\" ,
>> \"folderfilepatharg\": \"F:/MAVEN-REPO\" , \"searchextnarg\": \"jar\" =
,
>> \"searchstartno\": 120 , \"searchendno\" : 150}" =
searchobjtest.js:17:21 <
>> http://localhost:8080/SearchWebZipJar/searchobjtest/searchobjtest.js>
>>> { "searcharg" : "jakarta.ws.rs.ext.Provider" , "folderfilepatharg":
>> "F:/MAVEN-REPO" , "searchextnarg": "jar" , "searchstartno": 120 ,
>> "searchendno" : 150}
>>>=20
>>>=20
>> =
XHRGEThttp://localhost:8080/SearchWebZipJar/restapiview/cmpressapi/SearchB=
eanGet?"{
>> \"searcharg\" : \"jakarta.ws.rs.ext.Provider\" , =
\"folderfilepatharg\":
>> \"F:/MAVEN-REPO\" , \"searchextnarg\": \"jar\" , \"searchstartno\": =
120 ,
>> \"searchendno\" : 150}"&_=3D1744261534750 <
>> =
http://localhost:8080/SearchWebZipJar/restapiview/cmpressapi/SearchBeanGet=
?%22%7B%20%5C%22searcharg%5C%22%20:%20%5C%22jakarta.ws.rs.ext.Provider%5C%=
22%20,%20%5C%22folderfilepatharg%5C%22:%20%5C%22F:/MAVEN-REPO%5C%22%20,%20=
%5C%22searchextnarg%5C%22:%20%5C%22jar%5C%22%20,%20%5C%22searchstartno%5C%=
22:%20120%20,%20%5C%22searchendno%5C%22%20:%20150%7D%22&_=3D1744261534750
>>>=20
>>>=20
>>> Invalid character found in the request target
>> =
[&#47;SearchWebZipJar&#47;restapiview&#47;cmpressapi&#47;SearchBeanGet?%22=
{%20\\%22searcharg\\%22%20:%20\\%22jakarta.ws.rs.ext.Provider\\%22%20,%20\=
\%22folderfilepatharg\\%22:%20\\%22F:&#47;TOOLS&#47;APACHEMAVEN&#47;MAVEN-=
REPO\\%22%20,%20\\%22searchextnarg\\%22:%20\\%22jar\\%22%20,%20\\%22search=
startno\\%22:%20120%20,%20\\%22searchendno\\%22%20:%20150}%22&amp;_=3D1744=
256939455
>> ].
>>> The valid characters are defined in RFC 7230 and RFC 3986</p>
>>>=20
>>> Question :  Chars used in json  are  . ,  { , } , /   Error caused =
by
>> "Invalid character found in the request"
>>>=20
>>> Please Suggest
>>> --
>>> with regards
>>> N.S.KARTHIK
>>>=20
>>=20
>>=20
>=20
> --=20
>=20
> *with regards*
> *N.S.KARTHIK*