I am using restlet 2.1RC3 and using spring to manage beans. so my spring 
restful config looks like this:

    <bean id="xxxComponent" class="org.restlet.ext.spring.SpringComponent">
        <property name="name" value="xxx" />
        <property name="description" value="xxx" />
        <property name="owner" value="xxx" />
        <property name="author" value="xxx" />
        <property name="defaultTarget" ref="xxx" />
        <property name="statusService" ref="xxxStatusService" />
    </bean>
<bean name="drs-restfulRouter" class="org.restlet.ext.spring.SpringBeanRouter" 
/>
<bean name="/xxx"                              class="ABCServerResource"        
     scope="prototype"    autowire="byName" />

// this is the status bean injected in xxxComponent
public class xxxStatusService extends StatusService {

    @Override
    public Status getStatus(Throwable throwable, Request request, Response 
response) {
        log.warn("===============================get status");
        return Status.CLIENT_ERROR_UNAUTHORIZED;
    }
    
    @Override
    public Representation getRepresentation(Status status, Request request, 
Response response) {
        log.warn("============================get presentation");
        return super.getRepresentation(status, request, response);
    }
}

// This is the server resource

public interface ABCResource {

    @Get
    String doGet();
}

public class ABCServerResource implements ABCResource {
    /**
     * {@inheritDoc}
     */
    @Override
    public String doGet() {
        throw new RuntimeException("ah");
    }
}

It seems that when exception is thrown, only getRepresentation is invoked, but 
not getStatus.

I dig into the source code, found that two statusService bean have been created.

In ServerResource line 248, Status status = 
getStatusService().getStatus(throwable, this); this getStatusService() return a 
instance which is of class StatusService.
in the getStatusService() mehtod:
        StatusService result = null;

        result = getApplication().getStatusService();

        if (result == null) {
            result = new StatusService();
        }

        return result;
it get statusService from application. but I am using component, so it doesn't 
invoke my overrided getStatus();

BUT in StatusFilter line 252,         Representation result = 
getStatusService().getRepresentation(status, request, response);
getStatusService() return my subclass of StatusService, that's why 
getRepresentation is invoked.


Is this a bug in the framework? if not, how can I get my method invoked?

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2937885
  • getStatus doesn't get invoked in subclass of statusService Steve Teng

Reply via email to