The ProxyFactoryFactory was not configured - asp.net

Considering this example as a base example, I created the application but when I execute this application I am getting the following error.
The ProxyFactoryFactory was not configured. Initialize 'proxyfactory.factory_class' property of the session-factory configuration section with one of the available NHibernate.ByteCode providers. Example: NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu Example: NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle
The following is the code snippet I am using.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using NHibernate;
using NHibernate.Cfg;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Configuration cfg = new Configuration();
cfg.AddAssembly("NHibernate");
ISessionFactory factory = cfg.BuildSessionFactory();
ISession session = factory.OpenSession();
ITransaction transaction = session.BeginTransaction();
User newUser = new User();
newUser.Id = "joe_cool";
newUser.UserName = "Joseph Cool";
newUser.Password = "abc123";
newUser.EmailAddress = "joe#cool.com";
newUser.LastLogon = DateTime.Now;
// Tell NHibernate that this object should be saved
session.Save(newUser);
// commit all of the changes to the DB and close the ISession
transaction.Commit();
session.Close();
}
}
And my app.config file looks like
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section
name="nhibernate"
type="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
/>
</configSections>
<nhibernate>
<add
key="hibernate.connection.provider"
value="NHibernate.Connection.DriverConnectionProvider"
/>
<add
key="hibernate.dialect"
value="NHibernate.Dialect.MsSql2000Dialect"
/>
<add
key="hibernate.connection.driver_class"
value="NHibernate.Driver.SqlClientDriver"
/>
<add
key="hibernate.connection.connection_string"
value="Server=localhost;initial catalog=nhibernate;Integrated Security=SSPI"
/>
<!--<add value="nhibernate.bytecode.castle.proxyfactoryfactory, nhibernate.bytecode.castle" key="proxyfactory.factory_class" />-->
<!--<property name="proxyfactory.factory_class">NHibernate.ByteCode.Linfu.ProxyFactoryFactory, NHibernate.ByteCode.Linfu</property>-->
<!-- I have tried both the lines but still getting the same error -->
</nhibernate>
</configuration>
I have LinFu.DynamicProxy.dll instead of linfu.dll. Will it work? If not, then from where do I get this linfu.dll?
Or is there any other solution?

Assuming you have NHibernate 2.1 Alpha3, copy LinFu.DynamicProxy.dll and NHibernate.ByteCode.LinFu.dll from \Required_For_LazyLoading\LinFu to your bin (or references)
Then your configuration line should work:
<add key="proxyfactory.factory_class" value="NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu" />
As an aside, I prefer the hibernate-configuration section block for configuration.
Edit: Here's the relevant sections from my web configuration if you wanted to set up with hibernate-configuration instead of key/value pairs.
Also, it's possible to just put the hibernate-configuration part in its own file called hibernate.cfg.xml. You can then use the xsd nhibernate-configuration.xsd that's in the download to validate your configuration.
<configSections>
<section name="hibernate-configuration" type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate"/>
</configSections>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory>
<property name="dialect">NHibernate.Dialect.MsSql2005Dialect</property>
<property name="default_schema">kennelfinder.dbo</property>
<property name="connection.provider">
NHibernate.Connection.DriverConnectionProvider
</property>
<property name="proxyfactory.factory_class">
NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu
</property>
<property name="connection.connection_string">{Your connection string}</property>
<property name="show_sql">false</property>
<property name="connection.driver_class">
NHibernate.Driver.SqlClientDriver
</property>
<property name="connection.isolation">ReadCommitted</property>
<property name="use_proxy_validator">true</property>
<mapping assembly="KennelFinder"/>
</session-factory>
</hibernate-configuration>

We actually use Castle Proxy and have the following.
<property name='proxyfactory.factory_class'>NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle</property>
After that it's just a matter of making sure that ALL of the files in the NHibernate Castle lazy loading directory are in the bin.
LinFu.DynamicProxy.dll isn't enough. You also need NHibernate.ByteCode.Linfu.dll (and potentially others).

<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="hibernate-configuration" type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate"/>
</configSections>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory>
<property name="dialect">NHibernate.Dialect.MsSql2005Dialect</property>
<property name="connection.provider"> NHibernate.Connection.DriverConnectionProvider </property>
<property name="proxyfactory.factory_class"> NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu </property>
<property name="connection.connection_string">Server=(local);database=HelloNHibernate;Integrated Security=SSPI;</property>
<property name="show_sql">false</property>
<property name="connection.driver_class"> NHibernate.Driver.SqlClientDriver </property>
<property name="connection.isolation">ReadCommitted</property>
<property name="use_proxy_validator">true</property>
</session-factory>
</hibernate-configuration>
</configuration>
Copy LinFu.DynamicProxy.dll and NHibernate.ByteCode.LinFu.dll to the NHibernate's folder and add the same DLL files to the project reference.

I got this error after publishing my project via Visual Studio 2008's right-click "Publish..." feature, when trying to push our MVC/NHibernate project out to our web server.
It turned out I just needed to set the correct options in the publish dialog. In particular, in the "Copy" section, specify "All files in the source project folder", and then it started working. "Only files needed to run this application" was not good enough, perhaps Visual Studio was not smart enough to figure out which DLLs were being lazy loaded?

rnate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu</property>
<property name='proxyfactory.factory_class'>NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle</property>

Related

Switch on/off IBM MQ listener based on flag from DB

This is an existing monolith app and fix is required without a drastic change of the setup.
Project setup:
project 1 (config) - > where all mq-xml files are present (e.g - ibm_mq_config.xml)
e.g - content of dev_bm_mq.xml
${hname}
${port}
${qmgr}
1
<!-- JMS Queue Connection Factory -->
<bean id="jmsQueueIdsConnectionFactory"
class="org.springframework.jms.connection.SingleConnectionFactory">
<property name="targetConnectionFactory">
<ref bean="mqIdsConnectionFactory" />
</property>
</bean>
<!-- JMS Destination Resolver -->
<bean id="jmsDestinationResolver"
class="org.springframework.jms.support.destination.DynamicDestinationResolver">
</bean>
<!-- JMS Queue Template -->
<bean id="jmsQueueIdsTemplate" class="org.springframework.jms.core.JmsTemplate">
<property name="connectionFactory">
<ref bean="jmsQueueIdsConnectionFactory" />
</property>
<property name="defaultDestinationName">
<value>${myQUEUE}</value>
</property>
<property name="pubSubDomain">
<value>false</value>
</property>
<property name="receiveTimeout">
<value>20000</value>
</property>
</bean>
<bean id="jmsContainer"
class="org.springframework.jms.listener.DefaultMessageListenerContainer">
<property name="connectionFactory" ref="jmsQueueConnectionFactory" />
<property name="destinationName">
<value>${myQUEUE}</value>
</property>
<property name="messageListener" ref="simpleMessageListener" />
<property name="concurrentConsumers" value="2" />
<property name="maxConcurrentConsumers" value="3" />
<property name="idleTaskExecutionLimit" value="4" />
<property name="maxMessagesPerTask" value="4" />
<property name="receiveTimeout" value="5000" />
<property name="recoveryInterval" value="5000" />
<property name="sessionTransacted" value="true" />
</bean>
****Project B (App)****
loads the spring xml from project config as below:
WebContent/WEB-INF/spring/sprint-context.xm
<import resource="classpath*:com/my/package/${config.env}-${config-broker}.mq.xml"
public class TestMessageListener implements MessageListener {
public void onMessage(Message message) {
//process the message
}
}
When the server starts up, it's able to start the server and setup the listener without any issues.
Issue with the above setup : When we scale the app horizontally (add few nodes ), it's gives max channel issues which I am trying to solve.
Requirement:
based on a DB table I want to turn off the mq listener on few nodes on the fly. or when I horizontally scale the app.
e.g -
Table:mq-config
|host|broker|flag
-----------------------------
|qa5|ibm|false
|qa2|ibm|true
So, I want mq listener on qa5 not to start and qa2 to start and listen to the Queue. Also, I want to stop/start listener on the fly (just by updating the DB)
Question - Any thoughts on how do I achieve the above use case without re-writing the entire setup.
Inject the listener container (e.g. #Autowired).
Then
jmsContainer.stop();
jmsContainer.shutdown();
...
jmsContainer.initialize();
jmsContainer.start();
You can also set the autoStartup property to false to prevent the container from starting during application initialization (but don't call initialize() before the first start() - only after calling shutdown().

Spring Security : convert XML to Annotation

I want to use the OpenID Connect client with Spring Java annotation.
Unfortunately, the sample Mitre ID Connect client is based on XML.
I managed to load XML by #ImportResource("classpath:servlet-context.xml")
but it would be much better to have pure Java annotation based solution.
I could not translate the following XML stuff into Spring Annotation:
<security:http auto-config="false" use-expressions="true"
disable-url-rewriting="true" entry-point-ref="authenticationEntryPoint"
pattern="/**">
<security:custom-filter before="PRE_AUTH_FILTER" ref="openIdConnectAuthenticationFilter" />
<security:logout />
</security:http>
<security:authentication-manager alias="authenticationManager">
<security:authentication-provider ref="openIdConnectAuthenticationProvider" />
</security:authentication-manager>
<bean id="authenticationEntryPoint" class="org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint">
<property name="loginFormUrl" value="http://localhost:10239/test" />
</bean>
<util:set id="namedAdmins" value-type="org.mitre.openid.connect.client.SubjectIssuerGrantedAuthority">
<bean class="org.mitre.openid.connect.client.SubjectIssuerGrantedAuthority">
<constructor-arg name="subject" value="XXX" />
<constructor-arg name="issuer" value="http://localhost:10239/test" />
</bean>
</util:set>
The bean xml tag is similar to the #bean annotation. See http://docs.spring.io/spring-javaconfig/docs/1.0.0.M4/reference/html/ch02s02.html
The util:set tag is similar to a method that returns a set of type org.mitre.openid.connect.client.SubjectIssuerGrantedAuthority. However this method has the #bean annotation as well.
For security related tags you can extend WebSecurityConfigurerAdapter
see https://www.mkyong.com/spring-security/spring-security-hello-world-annotation-example/

How to config basing condition in Spring IOC?

How can I config IOC basing condition,like following:
<bean id="beanid" class="com...Class1" >
<if var='xxx'>
<property name="formView"
value="RegistrationApprovalForm" />
<else if var ='yyy'>
<property name="formView"
value="RegistrationApprovalForm1" />
</bean>
so I can put var in properties files,this will make configration easy.
Here is the code.
${ServiceMgmt.showEnabler}
</bean>
I want to redirect to the view based on configuration as below.
else
Is this possible with spring configuration??

HTTP Request from WebScript in Alfresco

I'm writing a WebScript in Alfresco using JS controller and I want to make a HTTP request to the local HTTP resource. This resource is a Java-based app and gives me its own REST API.
My WebScript is not a Share Component: so I don't have a remote object to call another webscript.
How can I make a HTTP request to the local resource (something like '/sdo/documents/getName?type=fl') from a WebScript?
EDIT: Alfresco is overriding the Spring Surf webscripts.container bean removing the remote definition (in web-scripts-application-context.xml of remote-api):
<bean id="webscripts.container" class="org.alfresco.repo.web.scripts.RepositoryContainer" parent="webscripts.abstractcontainer">
<property name="name"><value>Repository</value></property>
<property name="scriptObjects">
<map merge="true">
<entry key="paging">
<ref bean="webscripts.js.paging"/>
</entry>
</map>
<!-- ..... -->
</bean>
I suggest you include it again as a custom Javascript API root level object.
The remote root object comes from the Spring Surf framework, meaning you have it regardless of being developing your Web Scripts against the Alfresco repository or Share. As a proof, here's the source for a Web Script available in the public Alfresco CMIS server (-> Alfresco repository instance, admin/admin if you are asked to login):
var serviceUrl = (args.service === null) ? "/api/repository" : args.service;
var conn = remote.connect("alfresco");
var result = conn.get(stringUtils.urlEncodeComponent(serviceUrl));
var service = atom.toService(result.response);
var workspace = service.workspaces.get(0);
model.repo = workspace.getExtension(atom.names.cmisra_repositoryInfo);
The following snippet is taken from spring-surf-application-context.xml as found inside spring-webscripts-1.0.0.CI-SNAPSHOT.jar of Alfresco 3.4.0, which is where the remote root object gets its definition:
<bean id="webscripts.container" parent="webscripts.abstractcontainer" class="org.springframework.extensions.webscripts.LocalWebScriptRuntimeContainer">
<property name="name"><value>Spring Surf Container</value></property>
<property name="registry" ref="webscripts.registry" />
<property name="searchPath" ref="webframework.webscripts.searchpath" />
<property name="templateProcessorRegistry" ref="webframework.webscripts.registry.templateprocessor" />
<property name="scriptProcessorRegistry" ref="webframework.webscripts.registry.scriptprocessor" />
<property name="scriptParameterFactoryRegistry" ref="webscripts.web.scriptparameterfactoryregistry" />
<property name="configService" ref="web.config" />
<property name="scriptObjects">
<map merge="true">
<entry key="remote" value-ref="webframework.webscripts.scriptremote" />
</map>
</property>
<property name="processorModelHelper" ref="processor.model.helper"/>
<property name="extensibilityModuleHandler" ref="webscripts.extensibility.handler"/>
</bean>
<bean id="webframework.webscripts.scriptremote" class="org.springframework.extensions.webscripts.ScriptRemote">
<property name="configService" ref="web.config"/>
<property name="connectorProvider" ref="webframework.connector.provider"/>
</bean>

Trouble with object injection in Spring.Net

I have a issue with my Spring.Net configuration where its not injecting an object. I have a CommService to which an object named GeneralEmail is injected to. Here is the configuration:
<!-- GeneralMail Object -->
<object id="GeneralMailObject" type="CommUtil.Email.GeneralEmail, CommUtil">
<constructor-arg name="host" value="xxxxx.com"/>
<constructor-arg name="port" value="25"/>
<constructor-arg name="user" value="xxxx#xxxxx.com"/>
<constructor-arg name="password" value="xxxxx"/>
<constructor-arg name="template" value="xxxxx"/>
</object>
<!-- Communication Service -->
<object id="CommServiceObject" type="TApp.Code.Services.CommService, TApp">
<property name="emailService" ref="GeneralMailObject" />
</object>
The communication service object is again injected to many other aspx pages & service. In one scenario, I need to call the commnucation service from an static WebMethod. I try doing:
CommService cso = new CommService();
But when i try to get the emailService object, its null! why didn't the spring inject the GeneralMail object into my cso object? What am I doing wrong and how do I access the object from spring container.
Thanks in advance for the suggestions and solutions.
Reagrds,
Abdel Olakara
IApplicationContext ctx = ContextRegistry.GetContext();
CommService cso= (CommService)ctx.GetObject("CommServiceObject");

Resources