My Oracle Support Banner

ORDS REST Redirection Problem With Optional Template Query String Parameters (Doc ID 2421101.1)

Last updated on JULY 16, 2018

Applies to:

Oracle REST Data Services - Version 3.0.12 and later
Information in this document applies to any platform.

Symptoms

Problem :
=========
Difference in behaviour when creating REST APIs

1. Create an ORDS template with a pattern of "A?TEST" as well as a separate template with a pattern of "A/:PARAMETER" (noting that :PARAMETER is mandatory in the template).

2. Perform an HTTP request for "/A?TEST". This results in HTTP 200. This is expected.

3. Perform an HTTP request for "/A?TEST2" (indeed, any query string parameter that does not meet the pattern) results in HTTP 404. This is what I expected.


Now, change the template to make "PARAMETER" optional, i.e. "A/:PARAMETER?".   Subsequently, an HTTP request to "/A?TEST" results in 200 but requesting  "/A?TEST2" results in a 301 redirect to "/A/?TEST2".
Expected this to still be the 404 and certainly not a redirect.

To test this, in sql developer, enabled ORDS for scott schema and executed the following by providing the values :

BEGIN
  ORDS.delete_module(p_module_name => 'support');
END;
/

BEGIN
 ORDS.define_module(
  p_module_name => 'support',
  p_base_path => '/support'
  );
END;
/

BEGIN
  ORDS.define_template(
  p_module_name => 'support',
  p_pattern => 'A?TEST');
END;
/

BEGIN
 ORDS.define_handler(
  p_module_name => 'support',
  p_pattern => 'A?TEST',
  p_method => 'GET',
  p_source_type => ORDS.source_type_plsql,
  p_source => 'BEGIN NULL; END;'
 );
END;
/
commit;


BEGIN
  ORDS.define_template(
  p_module_name => 'support',
  p_pattern => 'A/:PARAMETER?');
END;
/

BEGIN
 ORDS.define_handler(
  p_module_name => 'support',
  p_pattern => 'A/:PARAMETER?',
  p_method => 'GET',
  p_source_type => ORDS.source_type_plsql,
  p_source => 'BEGIN NULL; END;'
 );
END;
/

and tried :

http://localhost:8082/ords/scott/support/A?TEST ---> Blank page was got without any message.
http://localhost:8082/ords/scott/support/A?TEST2 --> routes to blank page but the URL changes to -->

http://localhost:8082/ords/scott/support/A/?TEST2 ---> After A a slash is added before ? like A/?

For some reason, the first request to /A?TEST2 returns a 301 that then redirects the browser to /A/?TEST2.

It's different behaviour if the :PARAMETER on the other template is mandatory (which works as expected).

Cause

To view full details, sign in with your My Oracle Support account.

Don't have a My Oracle Support account? Click to get started!


My Oracle Support provides customers with access to over a million knowledge articles and a vibrant support community of peers and Oracle experts.