Skip to content

Fix to support restlets that serve static content. #1129

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
import javax.servlet.http.HttpServletResponse;

import org.restlet.Application;
import org.restlet.Client;
import org.restlet.Component;
import org.restlet.Context;
import org.restlet.Restlet;
import org.restlet.ext.servlet.ServletAdapter;
Expand Down Expand Up @@ -90,12 +92,59 @@ public class RestletFrameworkServlet extends FrameworkServlet {

private static final long serialVersionUID = 1L;

/** The Component. */
private volatile Component component;

/** The adapter of Servlet calls into Restlet equivalents. */
private volatile ServletAdapter adapter;

/** The bean name of the target Restlet. */
private volatile String targetRestletBeanName;

/** The bean name of the Component. */
private volatile String componentBeanName;

/** List of supported client protocols. */
private volatile String clientProtocolsString;

/**
* Creates an {@link Component} for the {@link Application}
* by trying to look one up from the web application context
* using the configured <code>componentBeanName</code>.
* If no component bean name is configured then a default Component is created.
* <p>
* Additionally, if any client protocols are configured via <code>clientProtocols</code>
* then these are also added to the component.
*
* @return A new instance of {@link Component}
*/
protected Component createComponent() {
Component component;
if(componentBeanName != null) {
component = (Component) getWebApplicationContext().getBean(
componentBeanName);
} else {
component = new Component();
}
if (clientProtocolsString != null) {
final String[] clientProtocols = clientProtocolsString
.split(" ");
Client client;

for (final String clientProtocol : clientProtocols) {
client = new Client(clientProtocol);

if (client.isAvailable()) {
component.getClients().add(client);
} else {
log("[Restlet] Couldn't find a client connector for protocol "
+ clientProtocol);
}
}
}
return component;
}

/**
* Creates the Restlet {@link Context} to use if the target application does
* not already have a context associated, or if the target restlet is not an
Expand All @@ -106,7 +155,9 @@ public class RestletFrameworkServlet extends FrameworkServlet {
* @return A new instance of {@link Context}
*/
protected Context createContext() {
return new Context();
this.component = createComponent();
Context parentContext = this.component.getContext();
return parentContext.createChildContext();
}

@Override
Expand All @@ -125,6 +176,15 @@ protected void doService(HttpServletRequest request,
protected ServletAdapter getAdapter() {
return this.adapter;
}
/**
* Provides access to the {@link Component} used.
* Exposed so that subclasses may do additional configuration.
*
* @return The {@link Component}.
*/
protected Component getComponent() {
return this.component;
}

/**
* Returns the target Restlet from Spring's Web application context.
Expand Down Expand Up @@ -177,4 +237,24 @@ protected void initFrameworkServlet() throws ServletException,
public void setTargetRestletBeanName(String targetRestletBeanName) {
this.targetRestletBeanName = targetRestletBeanName;
}

/**
* Sets the bean name of the Component.
*
* @param componentBeanName
* The bean name.
*/
public void setComponentBeanName(String componentBeanName) {
this.componentBeanName = componentBeanName;
}

/**
* Sets the client protocols.
*
* @param clientProtocols
* Space-separated list of protocols (e.g. FILE CLAP).
*/
public void setClientProtocols(String clientProtocolsString) {
this.clientProtocolsString = clientProtocolsString;
}
}