blueprint - A React-based UI toolkit for the web Blueprint – A React-based UI toolkit for the web a react-based ui toolkit for the web

OSGi: Blueprint vs. Spring DM

I am a little bit confused about Blueprint and Spring DM:

From what I think is true:

  • Spring DM is a framework defined by Spring Source
  • Blueprint is a framework defined by the OSGi Alliance
  • Blueprint has "taken" many of it's ideas from Spring DM


Can we expect that those two frameworks become one in the future (merge)? If not, which one will be the most future-proof?

Source: (StackOverflow)

flask: error_handler for blueprints

Can error_handler be set for a blueprint?

def page_not_found(error):
    return 'This page does not exist', 404



you can specify an app wide and a blueprint local error_handler

Source: (StackOverflow)

Multiple subdomains allowed in the same blueprint

I need to have two sub domains allowed in this blueprint. In this case, pt and br. How can i do that? As far as i know, i can only have a sub-domain parameter. I want to use this function for both languages [pt and br].

mod = Blueprint('landing', __name__, url_prefix='/', subdomain='pt')

@mod.route('/', methods=['GET'])
def index():

I want to avoid dynamic sub-domains because I don't want to change all my url_for().

Source: (StackOverflow)

Flask blueprint unit-testing

Is there a good practice to unit-test a flask blueprint?


I didn't found something that helped me or that is simple enough.

// Edit
Here are my code:

# -*- coding: utf-8 -*-
import sys
import os
import unittest
import flask

sys.path = [os.path.abspath('')] + sys.path

from app import create_app
from views import bp

class SimplepagesTestCase(unittest.TestCase):
    def setUp(self):
        self.app = create_app('development.py')
        self.test_client = self.app.test_client()

    def tearDown(self):

    def test_show(self):
        page = self.test_client.get('/')
        assert '404 Not Found' not in page.data

if __name__ == '__main__':

In this case, i test the blueprint. Not the entire app. To test the blueprint i've added the root path of the app to sys.path. Now i can import the create_app function to ...create the app. I also init the test_client.

I think i've found a good solution. Or will is there a better way?

Source: (StackOverflow)

flask-login can not be used in Blueprint object?

I have a question regarding flask-login and blueprint.


admin = Blueprint('admin', __name__)
login_manager = LoginManager()

def load_user(userid):
    return User.query.get(int(userid))

@admin.route('/login', methods=["GET", "POST"])
def login():
    login_form = LoginForm()
    if request.method == 'POST':
    #####user validation####
        return redirect('/')
    return render_template('admin/login.html', login_form=login_form)


app = Flask(__name__)
if __name__ == "__main__":

But when I post a form, and use login_user(user), an error occurred.

AttributeError: 'Flask' object has no attribute 'login_manager'

Then I try to use flask-login in run.py, It works fine.


login_manager = LoginManager()

def load_user(userid):
    return User.query.get(int(userid))

So, What I want to ask is,flask-login can not be used in Blueprint object? THX!

Source: (StackOverflow)

Flask register_blueprint error (Python)

I have a project on Flask. And when I include Blueprint on my Flask app I have errors. The code is from a book, Miguel Grinberg about Flask.

Project tree:

├── app
│   ├── __init__.py
│   ├── main
│   │   ├── errors.py
│   │   ├── __init__.py
│   │   └── views.py
│   ├── static
│   │   ├── static_files
│   └── templates
│       └── html_files
├── config.py
├── manage.py

create_app() in app/__init__.py

def create_app(config_name):
    app = Flask(__name__)

    from .main import main as main_blueprint

    return app

listing app/main/__init__.py

from flask import Blueprint

main = Blueprint('main', __name__)

from . import views, errors

Passenger row process output

Traceback (most recent call last):
  File "/opt/passenger/passenger-4.0.57/helper-scripts/wsgi-loader.py", line 320, in <module>
    app_module = load_app()
  File "/opt/passenger/passenger-4.0.57/helper-scripts/wsgi-loader.py", line 61, in load_app
    return imp.load_source('passenger_wsgi', startup_file)
  File "/home/m/mallts/dev.wget-studio.ru/myenv/lib/python3.4/imp.py", line 171, in load_source
    module = methods.load()
  File "<frozen importlib._bootstrap>", line 1220, in load
  File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 1129, in _exec
  File "<frozen importlib._bootstrap>", line 1471, in exec_module
  File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
  File "passenger_wsgi.py", line 16, in <module>
    from manage import app as application
  File "/home/m/mallts/dev.wget-studio.ru/fikls/manage.py", line 7, in <module>
    app = create_app('default') #(os.getenv('FLASK_CONFIG') or 'default')
  File "/home/m/mallts/dev.wget-studio.ru/fikls/app/__init__.py", line 19, in create_app
  File "/home/m/mallts/dev.wget-studio.ru/myenv/lib/python3.4/site-packages/flask/app.py", line 62, in wrapper_func
    return f(self, *args, **kwargs)
  File "/home/m/mallts/dev.wget-studio.ru/myenv/lib/python3.4/site-packages/flask/app.py", line 889, in register_blueprint
    blueprint.register(self, options, first_registration)
  File "/home/m/mallts/dev.wget-studio.ru/myenv/lib/python3.4/site-packages/flask/blueprints.py", line 153, in register
  File "/home/m/mallts/dev.wget-studio.ru/myenv/lib/python3.4/site-packages/flask/blueprints.py", line 128, in wrapper
  File "/home/m/mallts/dev.wget-studio.ru/myenv/lib/python3.4/site-packages/flask/blueprints.py", line 399, in <lambda>
    self.name, code_or_exception, f))
  File "/home/m/mallts/dev.wget-studio.ru/myenv/lib/python3.4/site-packages/flask/app.py", line 62, in wrapper_func
    return f(self, *args, **kwargs)
  File "/home/m/mallts/dev.wget-studio.ru/myenv/lib/python3.4/site-packages/flask/app.py", line 1090, in _register_error_handler
    'It is currently not possible to register a 500 internal ' \
AssertionError: It is currently not possible to register a 500 internal server error on a per-blueprint level.

My app/main/errors.py

from flask import render_template
from . import main 

def page_not_found(e):
    return render_template('404.html'), 404

def internal_server_error(e):
    return render_template('500.html'), 500

My app/main/views.py

from flask import render_template, url_for, session, redirect
from . import main 

def index():
    return render_template('index.html')

Source: (StackOverflow)

How to export Apiary Blueprint as PDF, stand-alone HTML or similar "deliverable"?

We need to export our Apiary Blueprint for task assignment purposes as a self containing "deliverable" like PDF or ZIP or similar. I'm aware of the feature request and the discussion below. Is it possible to "hack" something better than the poor html exporter? Maybe by injecting some css style into the page with chrome? Has somebody found a "good-enough" solution?

Source: (StackOverflow)

Apache Camel Endpoint injection to direct route "No consumers available on endpoint"

I want to use Camel to take a message from ActiveMQ and then, based on the message contents (a protobuf), send one or more messages to Twitter. I've written a bean that is called from within a route and which uses injection to send multiple messages to a "direct:xyz" endpoint.

However, Camel is complaining at runtime that:

2012-11-16 09:56:33,376 | WARN  | ication.twitter] | DirectProducer                   | 160 - org.apache.camel.camel-core - 2.10.2 | No consumers available on endpoint: Endpoint[direct://twitter] to process: Exchange[Message: hello world]

If I instead inject directly to the Twitter endpoint from within the bean, it works fine. However, in order to ease testing, simplify configuration etc, I'd like to keep the actual Twitter config separate, hence wanting to send to a separate route.

The camel context config looks like:-

<camelContext id="NotificationTwitter"
    trace="false" xmlns="http://camel.apache.org/schema/blueprint">
        <protobuf id="notificationProto" instanceClass="org.abc.schemas.protobuf.NotificationDef$NotificationMsg" />

    <route id="TwitterPreparation">
        <from uri="activemq:notification.twitter" />
        <unmarshal ref="notificationProto" />
        <log logName="abc" loggingLevel="INFO"
            message="Twitter request received: ${body}" />
        <bean ref="NotificationTweeter" method="createTweets" />

    <route id="Twitter">
        <from uri="direct:twitter" />
        <log logName="abc" loggingLevel="INFO"
            message="Tweeting: ${body}" />
        <to uri="twitter://timeline/user?consumerKey=itsasecret&amp;consumerSecret=itsasecret&amp;accessToken=itsasecret&amp;accessTokenSecret=itsasecret" />

The bean looks like:-

public class NotificationTweeter {

  @EndpointInject(uri = "direct:twitter")
  private ProducerTemplate producerTemplate;

  public void createTweets(NotificationMsg notification) {

    String tweet = notification.getMessageDetail().getTitle();

    try {
      // only send tweets where the notification message contains the Twitter mechanism
      for (MechanismMsg mechanism : notification.getMechanismList()) {
        if (mechanism.getType() == MechanismTypeEnum.TWITTER) {

          // Cycle round the recipients
          for (RecipientMsg recipient : mechanism.getRecipientList()) {
            tweet = "@" + recipient.getIdentifier() + " " + tweet;


          // TODO exceptions if no recipients found, etc
    } catch (Exception ex) {

I've had this problem in other routes (it's certainly not related to the Twitter feature) but have just worked around it. This time, however, I'd like to actually understand what the issue is! Any help gratefully received, thanks.

Source: (StackOverflow)

python flask-restful blueprint and factory pattern work together?

I am working on a restful service using flask-restful, and i want to leverage both factory pattern and blueprint in my project. in app/__init__.py i have a create_app function to create a flask app and return it to outside caller, so the caller can start the app.

def create_app():
    app = Flask(__name__)
    from app.resource import resource
    app.register_blueprint(v1, url_prefix='/api')
    print app.url_map
    return app

Inside that function i intended to register a blueprint pointing to the implementation package with a prefix url.

In app/resource/__init__.py there is following code

from flask import current_app, Blueprint, render_template
from flask.ext import restful
resource = Blueprint('resource', __name__, url_prefix='/api')

def index():    
    api = restful.Api(current_app)
    from resource.HelloWorld import HelloWorld
    api.add_resource(HelloWorld, '/hello')

My goal is that i can access the HelloWorld rest service at url /api/hello , but i know the above code has something wrong at part of @resource.route('/') .... I got some error like AssertionError: A setup function was called after the first request was handled. This usually indicates a bug in the app ... at api.add_resource(HelloWorld, '/hello') . Could you pls give me some hints on correct approach ? Thanks!

Source: (StackOverflow)

How to load from more then one template_folder for Flask blueprint?

I learned how to create Flask Blueprints and can create blueprint for non flask products that uses Jinja2 templates and use them inside flask projects. I do something like this:

# blueprint code
from flask import Blueprint
from pkg_resources import resource_filename
app = Blueprint('formgear', __name__, 
                template_folder=resource_filename('formgear', 'templates'))

And now I want to add another set of templates, which is logically connected with my non-Flask project but are Flask-only specific. I'm completely not sure is it good desing, but is there any way to propagate both templates folders from one blueprint? And make both templates set available for whole Flask project?

Note: formgear is name of my non-Flask project.

Source: (StackOverflow)

Does Aries managed-service-factory also manage properties?

I'm using Apache Aries 0.2 in Servicemix 4.3.1 and creating a cm:managed-service-factory. Creation of the services with .cfg files works fine (except for #ARIES-584), but the properties from the .cfg file do not get injected into the service object. They do get set properly in ConfigAdmin, just my bean setter methods never get called for the values in my config file.

I was thinking I should maybe use a cm:managed-properties or something like that nested inside my managed-service-factory, but that would require a separate pid, so doesn't seem right.

If I don't put the property tag in, then no value ever gets set. With the property tag, then just the default value gets set, but never the actual config file value.

I can't find any documentation for usage of the Aries CM subproject, except for blueprint-sample.xml, which doesn't show managed properties inside a managed service factory. I've really been trying to use Servicemix, but around every corner there is missing documentation, broken or missing features, or bugs that affect core functionality.

Both the spring and gemini documentation indicate that their managed-service-factory implementations should also function as managed-properties.


  <cm:managed-service-factory id="myfoo-msf" factory-pid="my.msf" interface="my.IFoo">
    <cm:managed-component class="my.Foo"> 
      <property name="name" value="default />


package my;
public interface IFoo {
  public String getName();
  public void setName(String name);


package my;
public class Foo implements IFoo {
  private String name;
  public void setName(String name) {
    this.name = name;
    System.out.println("name set to: " + name);
  public String getName() {
    return name;






name set to default
name set to default


service.pid = my.msf.xxxxxxx-xx-xx-xxxxxxxxxxxxxxx
name = name1
service.factoryPid = my.msf

service.pid = my.msf.yyyyyyy-yy-yy-yyyyyyyyyyyyyyy
name = name2
service.factoryPid = my.msf

Source: (StackOverflow)

Run Compass/SASS with a different version

I am trying to find a nice solution working on two different compass projects. One is based off Compass using Blueprint (older version), and the other is based on susy grid (newer version).

Currently, I have to reinstall the right version for the watch process.

Is it possible to run compile with a specified version? It would be great if it is also possible to run a watch process with a specified version.

Source: (StackOverflow)

Configure SQL datasource through properties in Camel Blueprint (within Karaf)

Given a very simple Camel bundle for Karaf, generated with the camel-archetype-blueprint, I want to add a datasource that is configured via properties and not within the blueprint.xml.

I tried configuring a PropertiesComponent and accessing the property within the property value for the MySQL datasource in various ways, but none seems to work. When logging a message though, the properties are accessible.

How can a datasource be configured using parameter values from a properties file?

I especially need this to use the same datasource configuration for multiple bundles and distinguish between production/test environments. I thought about writing the properties with Maven during the build, depending on the target environment. Are there any other best practices on how to solve this datasource issue?

<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
    xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
       http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/blueprint/camel-blueprint.xsd">

    <bean id="properties" class="org.apache.camel.component.properties.PropertiesComponent">
        <property name="location" value="classpath:config.properties" />

    <bean id="dataSourceMySQL" class="com.mysql.jdbc.jdbc2.optional.MysqlDataSource">
        <property name="url" value="jdbc:mysql://" />
        <!-- This causes an error, as it tries to connect with
             `${mysqlUser}`@`localhost` without any evaluation -->
        <property name="user" value="${mysqlUser}" />
        <property name="password" value="${mysqlPassword}" />

    <service interface="javax.sql.DataSource" ref="dataSourceMySQL">
            <entry key="osgi.jndi.service.name" value="jdbc/mysqlDatasource" />
    <bean id="sql" class="org.apache.camel.component.sql.SqlComponent">
        <property name="dataSource" ref="dataSourceMySQL" />

    <camelContext xmlns="http://camel.apache.org/schema/blueprint">
        <route id="messageQuery">
            <from uri="sql:SELECT * FROM messages" />
            <log message="The user property is: {{mysqlUser}}, the query result is: ${body}" />


Just for an overview, the project layout looks like this:

Project layout

Source: (StackOverflow)

What API blueprint renderer can generate a three-column html file for API documentation purpose?

Here's the API doc of Stripe: https://stripe.com/docs/api They seem to be using a three-columns template. I am wondering whether they use some API blueprint renderer (markdown-to-html type of script) to generate it, similarly to Aglio: https://github.com/danielgtaylor/aglio

If they don't use any renderer, what other types of API blueprint renderers exist out there?

Source: (StackOverflow)

Service reference in OSGi/blueprint not working properly

I currently have two OSGi bundles (bundle1 and bundle2) both both exposing services through a blueprint in an EBA. In bundle2's blueprint.xml i want to reference a service from bundle1 and Inject it into the BuildService (code below), as BuildService will be used to call TicketService. This however results in a Timeout exception (also below). It seems like the BuildService never gets registered with OSGi. How would I make something like this work?

blueprint.xml for bundle1:

<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" xmlns:bptx="http://aries.apache.org/xmlns/transactions/v1.0.0">

    <bean id="TicketServiceBean" class="com.example.b2.impl.TicketServiceImpl">
        <bptx:transaction value="Required" method="*" />

        <service ranking="0" id="TicketService" interface="com.example.b2.service.TicketService" ref="TicketServiceBean">
            <entry key="service.exported.interfaces" value="*" />


blueprint.xml for bundle2

<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">

        activation="eager" >
        <property name="ticketService" ref="TicketServiceRef" />


            <entry key="service.exported.interfaces" value="*" />


        activation="eager" />


Implementation of the BuildService:

public class BuildServiceImpl implements BuildService {

    private TicketService ticketService;

    public TicketBuildResponse ticketBuild(TicketBuildRequest ticketBuildRequest) throws BuildServiceException {

        //do stuff here

    public TicketService getTicketService() {
        return ticketService;

    public void setTicketService(TicketService ticketService) {
        this.ticketService = ticketService;


When starting up the application server (Websphere) I get the following exception:

  BlueprintCont E org.apache.aries.blueprint.container.BlueprintContainerImpl$1 run Unable to start blueprint container for bundle com.example.b1.module due to unresolved dependencies [(objectClass=com.example.b2.service.TicketService)]
        at org.apache.aries.blueprint.container.BlueprintContainerImpl$1.run(BlueprintContainerImpl.java:273)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:453)
        at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:315)
        at java.util.concurrent.FutureTask.run(FutureTask.java:150)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:98)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:207)
        at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
        at java.lang.Thread.run(Thread.java:736)

Source: (StackOverflow)