Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9158115
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T13:10:30+00:00 2026-06-17T13:10:30+00:00

I am developing a RESTlet API (JAVA), and I’ve created a custom authorization filter

  • 0

I am developing a RESTlet API (JAVA), and I’ve created a custom authorization filter that I run all requests through before passing it to my router. In my requests I always pass the session ID as a request attribute, e.g.

    http://localhost:8080/myAPI/{sid}/someResource/

Now, in my functions that extends ServerResource, I can do something like this to easily extract that {sid}:

    String sid = (getRequestAttributes().containsKey("sid")) ? getRequestAttributes().get("sid").toString() : "";

My problem is, in my authorization function, which extends Filter (the authorization function is not called via a router, but is called in my main createInboundRoot() function), I cannot use the same method to extract the {sid}. I’ve created a workaround using string manipulation of request.getResourceRef().getSegments(), but there must be a better way?

Any help will be appreciated!

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T13:10:31+00:00Added an answer on June 17, 2026 at 1:10 pm

    You can create a common parent class for any child of ServerResource. like this:

    public class CommonParentResource extends ServerResource
    {
        // class definition
    }
    

    And then override the doInit() method of the ServerResource class in it.

    public class CommonParentResource extends ServerResource
    {
        public void doInit()
        {
            boolean authorized=false;
    
            String sid = getRequestAttributes().containsKey("sid") ? (String)getRequestAttributes().get("sid") : StringUtils.EMPTY;
    
            // Authorization logic here.
    
            if(!authorized)//after authorization process completed.
            {
                getResponse().setStatus(Status.CLIENT_ERROR_UNAUTHORIZED);
                getResponse().setEntity(/*Representation carrrying message for unauthorized user*/);
            }
        }
    }
    

    Now any new child class of ServerResource that you want to perform this authorization check, must extend this CommonParentResource class. Like this:

    public class FriendsListResource extends CommonParentResource
    {
        @Get
        //......
    }
    

    Two points are important here:

    1. doInit() of any child class of ServerResource is called before calling any method annotated with @Get / @Post / …

    2. (Caution) If you do not use this statement:

      getResponse().setStatus(Status.CLIENT_ERROR_UNAUTHORIZED);
      

      i.e. if you do not set status of response to an error, then methods annotated with @Get / @Post / @Put / … will get called ! But if your program sets the status of the response to an error-status, then the @Get / @Post / @Put / … will not get executed, and the end user will see the error message represented by:

      getResponse().setEntity(/*Representation carrrying message for unauthorized user*/);
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm developing an API using Luracast Restler library. All I'm looking for is to
I'm developing a product that will use extensively of Restlet for consume WCF Rest
Developing Java, you have always learned that its best to create an ArrayList by
I am developing a restlet server inside a Glassfish server that will receive petitions
Iam developing one application.In that iam placing the radio buttons(uiimageview) on table view and
Developing a web application that will act similar to a daily journal. The user
Developing a site that requires monthly subscriptions via PayPal. If a buyer has an
Developing a series of POCOs on my project, and just realized that some of
Developing for iPhone, I have a collection of points that I need to make
Developing a desktop application based on Java + Swing I faced the problem of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.