Shut the default web page of Apache Aries down - jax-rs

I am using the Apache Aries in karaf. I have setup my homepage in a separate bundle. The problem is that when i stop the 'web-home' bundle of mine, I see the apache aries default page.
In the karaf-logs I see the default page is always called anyway.
"WARN JAXRSUtils - Both org.apache.aries.jax.rs.whiteboard.internal.DefaultWeb#home and my.packet.Home#home are equal candidates for handling the current request which can lead to unpredictable results"
This is how my Home.java looks like:
#Path("/")
#Component(
property = {
JaxrsWhiteboardConstants.JAX_RS_APPLICATION_SELECT + "=(osgi.jaxrs.name=.default)",
JaxrsWhiteboardConstants.JAX_RS_RESOURCE + "=true"
},
service = Home.class
)
public class Home {...
So, how does one configure the Aries to shut its homepage off, or otherwise just prevent this potentially unpredictable result?
I'd be happy to clarify further necessary details if asked. Thanks in advance.

it looks like the DefaultWeb is created by a configuration called default.web at the WhiteBoard class right here:
return OSGi.register(
Application.class,
() -> new DefaultApplication() {
#Override
public Set<Object> getSingletons() {
Object defaultApplication = _configurationMap.get(
"default.web");
if (defaultApplication == null ||
Boolean.parseBoolean(defaultApplication.toString())) {
return Collections.singleton(new DefaultWeb());
}
else {
return Collections.emptySet();
}
}
},
Looking at the bundle activator it looks like that if you set the configuration default.web to false it will disable the Default page.
In order to do that, create or find this file:
.../etc/org.apache.aries.jax.rs.whiteboard.default.cfg
(Which is the default config file of this bundle. As a general rule, the default config file is: ../etc/<Persistent ID of Bundel.cfg)
and add / set this line:
default.web=false

Related

How to list configured routes in Ktor

I am setting up a project with multiple modules that contain different versions of api.
To verify correct route configuration I would like to print configured routes to application log like it is done in spring framework.
Is it possible and what should I use for that?
You can do it by recursively traversing routes starting from the root all the way down the tree and filtering in only ones with the HTTP method selector. This solution is described here.
fun Application.module() {
// routing configuration goes here
val root = feature(Routing)
val allRoutes = allRoutes(root)
val allRoutesWithMethod = allRoutes.filter { it.selector is HttpMethodRouteSelector }
allRoutesWithMethod.forEach {
println("route: $it")
}
}
fun allRoutes(root: Route): List<Route> {
return listOf(root) + root.children.flatMap { allRoutes(it) }
}
Please note that the code above must be placed after the routing configuration.

Issue running Symfony 3 on Apache

I have Wamp64 running on my Windows 10 machine.
Localhost set up fine and I can see the Wamp64 home page at Localhost.
I've installed Symfony and followed the instructions as per their website.
I set up "project1" at C:\wamp64\www\project1, it has a public directory with an index.php file in it.
When I browse to http://localhost/project1/public/index.php I get an HTTP 404 error
Error page...
Should be getting the Symfony welcome page.
Any help gratefully received
You need to define a route with the path /
routes.yaml:
home:
path: /
defaults: { _controller: 'AppBundle\Controller\DefaultController::index' }
OR
Annotation:
// src/AppBundle/Controller/DefaultController.php
namespace AppBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\Routing\Annotation\Route;
class DefaultController extends Controller
{
/**
* Matches / exactly
*
* #Route("/", name="home")
*/
public function index()
{
// ...
}
}
You can also define these with XML and PHP. See the docs.
IF you're using Symfony 4 as suggested in the comments, the namespace is App\Controller and the localtion of your controller is /src/Controller instead of /src/AppBundle/Controller

Tapestry: How to redirect deprecated URLs to an error page

I have legacy web application built using apache Tapestry. I have deprecated most of the application's functionality except few pages. I want this application to be running in production, but I want to redirect deprecated pages/URLs to some error page with 404 error code. Where should I configure it? I have web.xml and jboss-web.xml. Do I need to do it in some Tapestry configuration file?
You can contribute a RequestFilter to the RequestHandler service, i.e. in your AppModule:
public void contributeRequestHandler(
OrderedConfiguration<RequestFilter> configuration)
{
// Each contribution to an ordered configuration has a name,
// When necessary, you may set constraints to precisely control
// the invocation order of the contributed filter within the pipeline.
configuration.add("DeprecatedURLs", new RequestFilter() {
#Override
public boolean service(Request request,
Response response,
RequestHandler handler) throws IOException
{
String path = request.getPath();
if (isDeprecated(path))
{
response.sendError(404, "Not found");
return;
}
return handler.service(request, response);
}
}, "before:*");
}
Notice the before:* ordering constraint, it should register this filter as the first in RequestHandler's configuration.

UniqueConstraints bundle not picked up by EmbeddableDocumentStore with custom plugins directory

We are using EmbeddableDocumentStore for non-production deployments and in general it works great. I stumbled upon an issue which took me few hours to solve and it would be good to know if the behaviour I am experiencing is by design.
I init EmbeddableDocumentStore like this:
var store = new EmbeddableDocumentStore()
{
DataDirectory = dataDirectory,
DefaultDatabase = "DbName",
RunInMemory = false,
UseEmbeddedHttpServer = true,
};
store.Configuration.Port = 10001;
store.Configuration.PluginsDirectory = pluginsDirectory; // this is the important line
store.Configuration.CompiledIndexCacheDirectory = compiledIntexCacheDirectory;
store.Configuration.Storage.Voron.AllowOn32Bits = true;
store.RegisterListener(new UniqueConstraintsStoreListener());
store.Initialize();
With this setup UniqueConstraints are not working on the embedded server.
However, when I put plugins directory to it's default location (WorkingDirectory + /Plugins), it magically starts working. Is it expected behaviour?
More info:
I can reproduce it in Console app and in Web app. In web app, the default location is web root + /Plugins.
After a little bit of investigation I found out that there is a difference in how UniqueConstraints' triggers are registered in store.Configuration.Catalog.Catalogs which might have something to do with the unexpected (for me) behaviour.
With custom PluginDirectory, triggers are registered in store.Configuration.Catalog.Catalogs as BuiltinFitleringCatalog:
When bundle is in the default location, triggers are added to BundlesFilteredCatalog in store.Configuration.Catalog.Catalogs with all other default triggers:
What version of RavenDB?
In RavenDB 3.5 registering plugins on the server-side requires a magic string. Adding this to your example above will probably fix it.
store.Configuration.Settings =
{
{ "Raven/ActiveBundles", "Unique Constraints" }
};

Dynamically loading service providers

I am creating an application with a control panel for three different versions of a server, and they may have different database layouts (that's the reason I am modularizing). I am following this tutorial.
How can I, dynamically, load only the service provider of the corrent server version? Every version has it's own folder, and the version chosen is stored is accessible with Config::get, is it already loaded when the service providers are loaded?
Also, if I use the HMVC architecture, can I still use the default folders (not modules) for application-wide, server-common controllers? (like news, which are not server-dependent).
If I didn't make myself clear, please ask.
As far as I can tell, you cannot dinamically load a Service Provider without doing something odd in your code, but Service Providers are class loaders themselves and you should be using one Service Provider to load, dynamically, your services:
<?php
class ServiceProvider extends Illuminate\Support\ServiceProvider {
protected $defer = true;
public function register()
{
$this->app->bind('server', function($app) {
switch ($this->app['config']['serverVersion']) {
case 'versionX':
return new ServiceClassForServerX();
break;
case 'versionY':
return new ServiceClassForServerY();
break;
default:
return new ServiceClassForDefaultServer();
break;
}
});
}
public function provides()
{
return array('sever');
}
}
About folders, Laravel gives you 100% freedom to choose whatever folder structure you want to use in app/*.