Software engineering

Pages

Thursday, December 13, 2012

It was quite a long journey. More than a month. The road-map looks approximately as such:
need to improve unit testability -> need for injection framework -> Guice arkwardness -> CDI arkwardness -> fall back to Guice -> Guice restrictions -> fall back to CDI -> Jetty+CDI arkwardess (which I've still made working) -> Glassfish. There were somewhere in the middle investigations of Scala cake pattern, but it turned not so comprehensive as injection frameworks.
See previous post for some details.

Guice + JSF problems:
1. Bean fields resolving
2. Mess up with order of initialization of Eager servlets, Eager beans, Context creation listeners.
3. Field injection doen't works with scala default constructors if injected fields are used immediately.
4. It should be used in conjuction with guice servlet module.
5. Note: Every servlet (or filter) is required to be a @Singleton. If you cannot annotate the class directly, you must bind it using bind(..).in(Singleton.class), separate to the filter() or servlet() rules. //http://code.google.com/p/google-guice/wiki/ServletModule
6. Guice servlet doesn't tolerate filters (at least) in web.xml. They should be moved to configServlets.
7. Guice configureServlets doesn't provide a whole replacement for web.xml
8. serve(...).with(classOf[javax.faces.webapp.FacesServlet]) - won't, because it requires HttpServlet.
9. There is no mention of JSF on Guice referense site. Guice development looks abandoned.
10. The implementation of EL variable resolver (GuiceResolver) is incomplete. It doesn't provide setters etc.

6,7,8 looks like a design flow, i.e. following this design we will have a lot of mess.

CDI troubles.
1. Seems bounded to WebSphere, IBM and proprietary marketing.
2. Problems with eager singletons. There is no alternative to JSF's @ManagedBean(eager=true)
3. To solve 2 I decided to use CODI cause here http://stackoverflow.com/questions/7828987/jsf-named-bean-eager-application-scoped-aka-managedbeaneager-true/7903857#7903857 some guy promises it will help.
4. Got error while initializing of CODI.
"no org.apache.myfaces.extensions.cdi.core.api.provider.BeanManagerProvider in place! Please ensure that you configured the CDI implementation of your choice properly. If your setup is correct, please clear all caches and compiled artifacts. If there is still a problem, try one of the controlled bootstrapping add-ons for the CDI implementation you are using."
==========================================
After poking for half an hour around found this
https://cwiki.apache.org/EXTCDI/workarounds-for-containers.html
without any links of bootstrap addons. Another 15 minutes:
http://code.google.com/a/apache-extras.org/p/myfaces-codi-addons/
Copypasted one class.
Got some progress but with many exceptions. Seems maven failed to resolve dependencies:
=====================================================java.lang.ClassNotFoundException: org.eclipse.jetty.servlet.ServletContextHandler$Decorator

2. WELD-001435 Normal scoped bean class alehro.{mysite}.background.BackgroundTasksSupervisor is not proxyable because it has no no-args constructor
Fix: add no-args constructors for the sake of internal features of Weld: http://stackoverflow.com/a/7584762/585819.
==========================================================
++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Trying Glassfish
Got error while trying to deploy {mySite}:
[#|2012-11-23T01:32:25.422+0300|FINE|glassfish3.1.2|javax.enterprise.resource.webcontainer.jsf.config|_ThreadID=20;_ThreadName=Thread-2;ClassName=com.sun.faces.config.WebConfiguration;MethodName=processJndiEntries;|javax.naming.NamingException: Lookup failed for 'java:comp/env/ClientStateSavingPassword' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming} [Root exception is javax.naming.NameNotFoundException: No object bound to name java:comp/env/ClientStateSavingPassword]|#]

Probably it's because I'm new to JNDI. Solution:
Recreate all from scratch Create project
http://www.tech-juice.org/2012/05/13/hello-world-with-jsf-2-0-glassfish-3-maven-svn-and-eclipse/

================================================================
Another big trouble while starting with Glassfish 3.1.2.
Averybody says that beans.xml can be empty. But it shouldn't. guessnumber oracle's example won't deploy with errors. But my code taken from tutorial
http://www.tech-juice.org/2012/05/13/hello-world-with-jsf-2-0-glassfish-3-maven-svn-and-eclipse/
just silently doesn't work. #{helloWord.greetings} doesn't get calculated.
I made a mistake: beans.xml instead of bean.xml. IT WAS STUPID, STUPID - error killed another half a day. guessnumber helped.

The reeason of failed deploy: <listener-class>org.apacheExtras.myfaces.codi.addon.weld.startup.WeldAwareConfigurationListener</listener-class>
in web.xml
======================================================================
Cannot use arquillian with glassfish. Have exception durin deployment of tests:

Saturday, July 9, 2011

How do I handle multipart form data? or How do I handle file uploads to my app?

You can obtain the uploaded file data from a multipart form post using classes from the Apache Commons FileUpload package. Specifically you may want to use FileItemStream, FileItermIterator and ServletFileUpload as illustrated below.

If you see a java.lang.NoClassDefFoundError after starting your application, make sure that the Apache Commons FileUpload JAR file has been copied to your war/WEB-INF/lib directory and added to your build path.

Monday, June 27, 2011

I need free voice recorder app for Android. Unfortunately there isn't such app on the market powerful enough. All applications I've tried missed record pause/continue functionality. So, I decided to take ready solution (http://code.google.com/p/diktofon/) and add some features. Because it uses AudioRecord adding the pause/continue recording functionality wasn't a problem. So, it's done.But saving audio to wav files, i.e. without compression takes a lot of space (1 MByte per minute). And I decided to compress the audio. I've tried two solutions JSpeex and oggDroid.It turned that they are both two slow.So, I've added two commands to context menu of files list in the Diktofon. They are "Continue recording" and "Compress record"."Continue recording" allows to continue recording of any wav file with the same settings as current settings. This command works well."Compress record" allows to convert wav file to ogg file (ogg is open source audio codec supported in the Android). But currently this command works very slow. E.g. it converts 1 minute speech for about 10 minutes. Although at the current release converting freezes app's GUI completely.Here is my release: http://alehro.com/distr/advvoicerecorder/Diktofon.apk