You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@karaf.apache.org by Max Spring <m2...@springdot.org> on 2018/03/13 00:15:22 UTC
Re: how to enable alias resolution in Jetty in Karaf?
I ended up implementing this via a ContainerRequestFilter:
package org.example.filters;
import org.example.engine.Engine;
import javax.ws.rs.container.ContainerRequestContext;
import javax.ws.rs.container.ContainerRequestFilter;
import javax.ws.rs.core.Response;
import java.io.IOException;
public class OfflineModeFilter implements ContainerRequestFilter{
private Engine engine;
public void setEngine(Engine engine){
this.engine = engine;
}
@Override
public void filter(ContainerRequestContext requestContext) throws IOException{
if (engine.isOfflineMode()){
requestContext.abortWith(Response.status(Response.Status.SERVICE_UNAVAILABLE)
.entity("engine offline").build()
);
}
}
}
...and injecting the engine via Blueprint:
<blueprint xmlns...>
<jaxrs:server id="restService" address="/">
<jaxrs:providers>
<bean class="org.example.filters.OfflineModeFilter">
<property name="engine" ref="engineSvc"/>
</bean>
</jaxrs:providers>
</jaxrs:server>
<reference id="engineSvc" interface="org.example.engine.Engine" availability="mandatory"/>
</blueprint>
-Max
On 02/16/2018 12:22 PM, Max Spring wrote:
> I'm still on Karaf 3.0.5 and Jetty 8.1.17.v20150415 / org.ops4j.pax.web.pax-web-jetty 3.2.6.
>
> Is there any way to enable alias resolution (i.e. Jetty following symlinks), or do I need to updgrade to a Jetty 9.x?
>
> The relevant places I found ([1], [2]) talk about Jetty 9 and I were unable to enable alias resolution.
>
> Thanks!
> -Max
>
> [1] https://www.eclipse.org/jetty/documentation/9.3.x/advanced-extras.html#default-servlet-init
> [2] https://portail.capsana.ca/doc/9.4.5.v20170502/serving-aliased-files.html
>
>
Re: how to enable alias resolution in Jetty in Karaf?
Posted by Max Spring <m2...@springdot.org>.
(Re-sending it due to copy/paste screw up in my earlier reply.)
I ended up implementing this by resolving symlinks and using an HttpServletRequestWrapper.
public class FileServlet extends DefaultServlet{
//Bean init-method
public void initBasePath() {
basePath = new File(System.getProperty("http.resource.base"));
}
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
File canonAbsBase = new File(basePath, request.getServletPath()).getCanonicalFile();
// this "flattens" symlinks!
String canonAbsPathInfo = new File(canonAbsBase, request.getPathInfo()).getCanonicalPath();
String canonPathInfo = canonAbsPathInfo.substring(canonAbsBase.toString().length());
response.setContentType(request.getPathInfo().endsWith(".html")? "text/html" : "text/plain");
super.doGet(
new HttpServletRequestWrapper(request){
@Override public String getPathInfo(){ return canonPathInfo; }
},
response
);
}
}
This works fine for my limited use case of having symlinks only *within* the hierarchy served out by Jetty.
-Max
On 03/12/2018 05:15 PM, Max Spring wrote:
> I ended up implementing this via a ContainerRequestFilter:
>
> package org.example.filters;
>
> import org.example.engine.Engine;
>
> import javax.ws.rs.container.ContainerRequestContext;
> import javax.ws.rs.container.ContainerRequestFilter;
> import javax.ws.rs.core.Response;
> import java.io.IOException;
>
> public class OfflineModeFilter implements ContainerRequestFilter{
>
> private Engine engine;
>
> public void setEngine(Engine engine){
> this.engine = engine;
> }
>
> @Override
> public void filter(ContainerRequestContext requestContext) throws IOException{
> if (engine.isOfflineMode()){
> requestContext.abortWith(Response.status(Response.Status.SERVICE_UNAVAILABLE)
> .entity("engine offline").build()
> );
> }
> }
> }
>
> ...and injecting the engine via Blueprint:
>
> <blueprint xmlns...>
>
> <jaxrs:server id="restService" address="/">
> <jaxrs:providers>
> <bean class="org.example.filters.OfflineModeFilter">
> <property name="engine" ref="engineSvc"/>
> </bean>
> </jaxrs:providers>
> </jaxrs:server>
>
> <reference id="engineSvc" interface="org.example.engine.Engine" availability="mandatory"/>
>
> </blueprint>
>
> -Max
>
>
> On 02/16/2018 12:22 PM, Max Spring wrote:
>> I'm still on Karaf 3.0.5 and Jetty 8.1.17.v20150415 / org.ops4j.pax.web.pax-web-jetty 3.2.6.
>>
>> Is there any way to enable alias resolution (i.e. Jetty following symlinks), or do I need to updgrade to a Jetty 9.x?
>>
>> The relevant places I found ([1], [2]) talk about Jetty 9 and I were unable to enable alias resolution.
>>
>> Thanks!
>> -Max
>>
>> [1] https://www.eclipse.org/jetty/documentation/9.3.x/advanced-extras.html#default-servlet-init
>> [2] https://portail.capsana.ca/doc/9.4.5.v20170502/serving-aliased-files.html
>>
>>
>