java.lang.VerifyError exception while authenticating for Google Vision Api - spring-mvc

The code for vision api works fine when using a java application however when using spring a java.lang.VerifyError exception is thrown on the following line.
Labels app = new Labels(label.getVisionService());
It was certain that i had specified the json credentials for the system and not the web app so i have included the following bean in my root-context.xml:-
<bean id="googleVisionApiAuthenticator" class="com.something.mypackage.Labels">
<property name="APPLICATION_NAME" value="myCompany-VisionLabelSample/1.0" />
<property name="MAX_LABELS" value="3" />
</bean>
After inclusion of these lines in the root-context its gives page not found.

Well the problem was that some of the jars present were duplicate hence the error. A detailed study of the dependencies and removing the extra jars helped solve the error.

Related

UWP app errors when built in .Net Native

We've got a Windows 8.1 app that we've converted to a Windows 10 UWP app. The app works fine in debug, but when running in Release (.Net Native), we are getting a runtime error on app load. It's not at all clear what's causing the error. The error happens in the OnLaunched event in App.xaml.cs where some data is being initialized. The error:
An exception of type System.NullReferenceException occurred in
System.Private.CoreLib.dll
Additional information: Arg_NullReferenceException
We're using the latest versions of MVVM Light.
I know this isn't a lot of info, but it's really all we have right now and are pretty stumped. Anyone seen and issue like this or know where to start in tracking it down?
If, you're still using SQLite or any Reference.
Please Right Click to your Project => Add => Reference => Make sure your DLL of Nuget is checked.
Please Check this solution.
I had this exact problem in that I converted an 8.1 app to UWP. This was resolved by including a file called Default.rd.xml in the Properties folder. This was not mentioned in the migration guide that I had used.
Not including it means some pretty common coding patterns such as reflection will not work, and this includes in imported .dll's.
A basic Default.rd.xml file looks like the following ...
<!--
This file contains Runtime Directives used by .NET Native. The defaults here are suitable for most
developers. However, you can modify these parameters to modify the behavior of the .NET Native
optimizer.
Runtime Directives are documented at https://go.microsoft.com/fwlink/?LinkID=391919
To fully enable reflection for App1.MyClass and all of its public/private members
<Type Name="App1.MyClass" Dynamic="Required All"/>
To enable dynamic creation of the specific instantiation of AppClass<T> over System.Int32
<TypeInstantiation Name="App1.AppClass" Arguments="System.Int32" Activate="Required Public" />
Using the Namespace directive to apply reflection policy to all the types in a particular namespace
<Namespace Name="DataClasses.ViewModels" Serialize="All" />
-->
<Directives xmlns="http://schemas.microsoft.com/netfx/2013/01/metadata">
<Application>
<!--
An Assembly element with Name="*Application*" applies to all assemblies in
the application package. The asterisks are not wildcards.
-->
<Assembly Name="*Application*" Dynamic="Required All" />
<!-- Add your application specific runtime directives here. -->
</Application>
</Directives>
If this does not work, then try creating a new empty UWP project to get the latest format for the file.

Setting properties using Unity XML

I want to set the Entity Framework ObjectContext in a repository class - the ObjectContext being a property of the repository.
I am using Unity XML configuration:
<register type="IUsersRepository" mapTo="SqlUsersRepository" >
<property name="MyObjectContext">
<value value="Per-Request" typeConverter="ObjectContextTypeConverter" />
</property>
</register>
The ObjectContextTypeConverter interprets the value of the property - in this case "Per-Request" - and uses an ObjectContext stored in HttpContext.Current.Items (a per request collection in asp.net).
The ObjectContextTypeConverter.ConvertFrom method is only called once when the Unity configurations is loaded in the Application_Start method of the Global.asax file. Yet when I try to resolve an interface using Unity - the ConvertFrom method won't be called again.
Is there a way to solve this problem?
The reason is that you're setting it as a value. You can set it as a dependency:
<property name="MyObjectContext">
<dependency />
</property>
and inject the context through an in injection factory:
Container.RegisterType<ObjectContext>(
new InjectionFactory(c => GetTheContextInstance()));

Jrebel, Spring MVC and TIles. Can't get Jrebel to pick up changes to views.xml

I'm trying to use Jrebel with IntelliJ 10. I'm working on Spring Roo generated project which uses tiles. There are multiple views.xml in my class path.
What I would like to know is if JRebel will pick up changes to views.xml. So far I can't seem to make it.
Just report it to JRebel forum - it will be registered as a feature request
If you are using spring roo generated project than it uses tiles 2.2.1 at least. in that case you dont need Jrebel to do it as Tiles can do it directly, just set the useMutableTilesContainer and checkRefresh properties to true on spring's TilesConfigurer bean
<bean class="org.springframework.web.servlet.view.tiles2.TilesConfigurer"
id="tilesConfigurer" >
<property name="useMutableTilesContainer">true</property>
<property name="checkRefresh">true</property>
it's explained in detail here: http://lalyos.github.com/blog/2012/08/29/tiles-reload-definitions-in-springmvc/

Using component-scan in a web project

I have an Eclipse "Dynamic Web Project" and a Tomcat server configured in Eclipse to use that project. I have a file extension mapped to a servlet, and in the servlet config I have a component-scan element setup like this:
<context:component-scan base-package="com.mycompany.web" />
When my web server starts up, I see this error message in the log:
May 6, 2011 9:50:23 AM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Allocate exception for servlet cap
java.lang.IllegalArgumentException: Resource path [C:\...\src\main\webapp\WEB-INF\classes\com\mycompany\web] does not denote a directory
That directory does not exist (except in the packaged .war file). However, the com.mycompany.web package does exist.
Is there another way to do a component-scan? It needs to either look in another folder, or somehow find it in my project or something...
It doesn't appear to be possible to do a component-scan in this way. It does a directory listing, which I guess isn't possible when the class files aren't physically located where Spring is expecting. I solved this just by not using a component-scan, and listing the controllers in the spring config like this:
<context:annotation-config />
<bean class="com.mycompany.web.MyController"/>
Annotations in the controller still work, so listed the controllers manually is the only extra step.
it's possible to do what you want, but you need a little extra configuration.
You can annotate your classes with #Controller or #Repository or other Spring stereotype annotations and Spring will pick them up automatically.
Or you can give context:component-scan a bit more info. Example:
<context:component-scan base-package="com.mycompany.web">
<!-- scan all classes in the com.mycompany.web package (but
not in subpackages) -->
<context:include-filter type="aspectj" expression="com.mycompany.web.*"/>
<!-- or if you want to include subpackages this config scans all
classes in com.mycompany.web.special and in its subpackages
(that's what the ..* means) -->
<context:include-filter type="aspectj" expression="com.mycompany.web.special..*"/>
</context:component-scan>
Finally, if you don't like using aspectj, context:include-filter's type can be a regular expression, custom annotation, etc. See this link for more info.

Multiple database with NHibernate

I have two databases. One from Oracle 10g. Another from Mysql. I have configured my web application with Nhibernate for Oracle and now I am in need of using the MySQL database. So how can i configure the hibernate.cfg.xml so that i can use both of the database at the same application?
My current hibernate.cfg.xml is:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory>
<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
<property name="connection.driver_class">NHibernate.Driver.OracleClientDriver</property>
<property name="connection.connection_string">Data Source=xe;Persist Security Info=True;User ID=hr;Password=hr;Unicode=True</property>
<property name="show_sql">false</property>
<property name="dialect">NHibernate.Dialect.Oracle9Dialect</property>
<!-- mapping files -->
<mapping assembly="DataTransfer" />
</session-factory>
</hibernate-configuration>
You can check "Burrow" addin for nhibernate
http://nhforge.org/wikis/burrow/introduction.aspx
Multiple databases support. multiple databases becomes easy, you don't need a SessionFactoryPath, you simply give Burrow an entity type, and Burrow will find the right ISession for you. If you are using GenericDAO, the multiple DB support can be very transparent - your code does not need to know there are multiple databases.
Seems that you could also use unhaddins, haven't used it and I didn't find the documentation.
http://code.google.com/p/unhaddins/
I had to do that many time ago I followed this article, it's a more complex solution but I paste it just in case.
http://www.codeproject.com/KB/aspnet/NHibernateMultipleDBs.aspx
Here may be a simpler solution. It provides a new feature that allows the hibernate-configuration to have multiple session-factory elements by giving them names, and extends the NHibernate.Cfg.Configuration.Configure to accept a sessionFactoryName.
Configure NHibernate hibernate.cfg.xml file to have more connection strings

Resources