Re: Invalid character found in the request target TomEE 10.0.1

Nanjangud Shivakumar Karthik <[email protected]> Mon, 14 Apr 2025 20:20:23 +0530
Newsgroups gmane.comp.java.openejb.user
Message-ID <CAFVhWXiScWPcG7afnQBAstYnVM=SAC9HM0OVd-jLXd=pTUR5FA__11186.2081846752$1744642342$gmane$org@mail.gmail.com>
--000000000000c4633d0632be2c36
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

Richard

>>

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

*Alternatively I have already been using  the same*

*Json String  ~ *{ "searcharg": "jakarta.ws.rs.ext.Provider",
"folderfilepatharg": "F:/TOOLS/APACHEMAVEN/MAVEN-REPO", "searchextnarg" :
"jar", "searchstartno": 120, "searchendno": 150 }

@GET

@Path("/SearchStringGet/{searchVal}")

@Consumes(MediaType.TEXT_PLAIN)

@Produces(MediaType.APPLICATION_JSON)

public SearchZipJarBean getSearchBean( @PathParam("searchVal") String searc=
hVal
) {

try {

SearchZipJarResourceControllerlog.debug("@Path SearchStringGet/{searchVal}
: " + searchVal);

.......( String to Pojo using jakson )

srchZpjra.processinSearchEngine();

} catch (Exception e) {

throw new SearchZipJarException("getSearchBean()",this.getClass(), e);

}finally {

}
}

I would like to use  Pojo Object to be passed to the GET processing instead
of  String @PathParam("searchVal")


public SearchZipJarBean getSearchBean(SearchZipJarBean srchBean)

Can you suggest  any solutions for the same.


with regards
N.S.Karthik


On Sat, Apr 12, 2025 at 12:18=E2=80=AFAM Richard Zowalla <[email protected]> =
wrote:

>
> 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]>:
> >
> > Hello
> >
> >
> > *>> if you insist on GET, you need to correctly encode the json into a
> > query parameter.*
> >
> > 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
> >
> > Could u suggest on correcting to encode the Json into the Query Paramet=
er
> >
> > Json  fetched from UI
> >
> > {  "searcharg": "jakarta.ws.rs.ext.Provider",  "folderfilepatharg":
> > "F:/TOOLS/APACHEMAVEN/MAVEN-REPO",   "searchextnarg" : "jar",
> > "searchstartno": 120, "searchendno": 150 }
> >
> > on the Controller the method defined is as follows used to  prefilter
> args
> > to process
> >
> > @GET
> >
> > @Consumes(MediaType.APPLICATION_JSON)
> >
> > @Produces(MediaType.APPLICATION_JSON)
> >
> > @Path("/SearchBeanGet")
> >
> > public SearchZipJarBean getSearchBean(SearchZipJarBean srchBean) {
> >
> > loggerlog.info("Pre Process " + srchBean.toString());
> >
> > ....
> >
> > loggerlog.info("Post Process " + srchBean.toString()); return srchZpjra
> > .getSrchBean();
> >
> > }
> >
> > with regards
> > N.S.Karthik
> >
> > On Thu, Apr 10, 2025 at 1:56=E2=80=AFPM Richard Zowalla <[email protected]=
g> wrote:
> >
> >> 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
> >>
> >> That being said, =E2=80=9Edata=E2=80=9C is appended to the URL as quer=
y parameters, the
> >> content type is ignored and the JSON strings will appear (encoded) in
> the
> >> URL.
> >>
> >> 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.
> >>
> >>> Am 10.04.2025 um 07:25 schrieb KARTHIK SHIVAKUMAR <
> [email protected]
> >>> :
> >>>
> >>>
> >>>
> >>> Hello
> >>>
> >>> Spec :
> >>> Container : Apache TomEE PLUS -10.0.1
> >>> Java      : 22
> >>> Ide       : Eclipse IDE
> >>> O/s       : Win-10
> >>> Browser : Firefox
> >>> RESTClient : PostMan
> >>>
> >>> 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
> >>>
> >>>
> >>> 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("AJ=
AX
> >> PASS" + jqXHR.status);
> >>>                                                },
> >>>                                               error    :
> >> function(responseObject, textStatus, jqXHR) {
> >>>
> >> console.log("AJAX FAIL : " + JSON.stringify(responseObject));
> >>>                                                }
> >>>                                                    });
> >>>                                                      return InstMesg;
> >>>                                      }
> >>>
> >>> Browser O/p
> >>> "{ \"searcharg\" : \"jakarta.ws.rs.ext.Provider\" ,
> >> \"folderfilepatharg\": \"F:/MAVEN-REPO\" , \"searchextnarg\": \"jar\" =
,
> >> \"searchstartno\": 120 , \"searchendno\" : 150}" searchobjtest.js:17:2=
1
> <
> >> http://localhost:8080/SearchWebZipJar/searchobjtest/searchobjtest.js>
> >>> { "searcharg" : "jakarta.ws.rs.ext.Provider" , "folderfilepatharg":
> >> "F:/MAVEN-REPO" , "searchextnarg": "jar" , "searchstartno": 120 ,
> >> "searchendno" : 150}
> >>>
> >>>
> >>
> XHRGEThttp://localhost:8080/SearchWebZipJar/restapiview/cmpressapi/Search=
BeanGet?"{
> >> \"searcharg\" : \"jakarta.ws.rs.ext.Provider\" , \"folderfilepatharg\"=
:
> >> \"F:/MAVEN-REPO\" , \"searchextnarg\": \"jar\" , \"searchstartno\": 12=
0
> ,
> >> \"searchendno\" : 150}"&_=3D1744261534750 <
> >>
> http://localhost:8080/SearchWebZipJar/restapiview/cmpressapi/SearchBeanGe=
t?%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
> >>>
> >>>
> >>> Invalid character found in the request target
> >>
> [&#47;SearchWebZipJar&#47;restapiview&#47;cmpressapi&#47;SearchBeanGet?%2=
2{%20\\%22searcharg\\%22%20:%20\\%22jakarta.ws.rs.ext.Provider\\%22%20,%20\=
\%22folderfilepatharg\\%22:%20\\%22F:&#47;TOOLS&#47;APACHEMAVEN&#47;MAVEN-R=
EPO\\%22%20,%20\\%22searchextnarg\\%22:%20\\%22jar\\%22%20,%20\\%22searchst=
artno\\%22:%20120%20,%20\\%22searchendno\\%22%20:%20150}%22&amp;_=3D1744256=
939455
> >> ].
> >>> The valid characters are defined in RFC 7230 and RFC 3986</p>
> >>>
> >>> Question :  Chars used in json  are  . ,  { , } , /   Error caused by
> >> "Invalid character found in the request"
> >>>
> >>> Please Suggest
> >>> --
> >>> with regards
> >>> N.S.KARTHIK
> >>>
> >>
> >>
> >
> > --
> >
> > *with regards*
> > *N.S.KARTHIK*
>
>

--=20

*with regards*
*N.S.KARTHIK*

--000000000000c4633d0632be2c36--