AWG Blogs

Friday, February 13, 2015

Creating a sequence diagram from a stack trace

Install AmaterasUML:
- download AmaterasUML from http://amateras.sourceforge.jp/cgi-bin/fswiki_en/wiki.cgi?page=AmaterasUML
- unzip AmaterasUML_1.3.4.zip
- copy the three jars to eclipse plugin folder, e.g. D:\App\eclipse-jee-luna-R-win32-x86_64\eclipse\plugins
- install Graphical Editing Framework eclipse plugin. It was already installed in mine, maybe through a dependency on BPMN2 Modeler or something else.
- restart eclipse
Get the stack trace
- in Eclipse put a breakpoint in some method you want to analyze via sequence diagram
- start debug 
- in the debug view right-click the Daemon Thread and click Copy Stack
- paste into text editor
Fix up stack trace
- remove unwanted lines including lines that end with "line: 1" or start with "Daemon Thread" or "owns:" leaving only the lines that start with entities to be added to the sequence diagram
- save the file e.g. D:\work\AmaterasPrepWork\MyStackTrace.txt
- create a second text file and paste into it the following awk script:
{
str = $0;\
sub(/^\t/, "", str);\
sub(/\(.*\./,".",str);\
sub(/\$.*\./,".",str);\
match(str, /(.*)\./, arr);\
sub(/^/, "at ", str);\
#print str;\
sub(/\([^\)]*\)/, "(", str);\
sub(/ line: /, arr[1]".java:", str);\
sub(/$/, ")", str);\
sub(/\t\)$/, ")", str);\
print str}
- save the file as e.g. D:\work\AmaterasPrepWork\AmaterasPrepProg.txt
- download gawk and run file e.g. gawk-3.1.6-1-setup.exe
- open a command prompt and cd to e.g. D:\work\AmaterasPrepWork
- execute the following commands:
D:\AmaterasPrepWork>set path=%path%;D:\Program Files (x86)\GnuWin32\bin
D:\AmaterasPrepWork>echo awk -f AmaterasPrepProg.txt MyStackTrace.txt ^> out.txt > run.bat
D:\AmaterasPrepWork>run.bat
Make sequence diagram in eclipse
- Do Window, Show View, AmaterasUML, Stack Trace Sample, OK
- paste the contents of D:\AmaterasPrepWork\out.txt into the window
- click the 'i' (image of lower case 'i') button in upper right-hand corner of the Stack Trace Sample view
- select a folder in your project as the destination of new sequence
- refresh the folder in eclipse
- open sequence.sqd
- do finishing touches. It appears e.g. that some entities weren't added and need to be added?? will check on this...
- save the file as MySequence.sqd or save sequence.sqd and refactor to another name because AmaterasUML uses sequence.sqd as the target file name evidently.


ref:

Sunday, November 2, 2014

Solving Sruts2 Core Jar File Conflict

I was adding a Struts2 application to an embedded Tomcat 6 instance by adding the context and assigning the path to the Struts2 application programmatically. The Struts2 application's WEB-INF/lib was empty similar to what's known as a "skinny war." When attempting to access a jsp page though I would get the error: "/struts-tags" not found.

This was solved by adding struts2-core-2.3.4.1.jar to the WEB-INF/lib. However then application would not load and I would get:
Bean type class com.opensymphony.xwork2.ObjectFactory with the name xwork has already been loaded by bean - jar:file:C:/MyCustomContainer/plugins/struts2-core-2.3.4.1.jar!/struts-default.xml:29:72 - bean - jar:file:/D:/temp/configs/pings/strutssd/WEB-INF/lib/struts2-core-2.3.4.1.jar!/struts-default.xml:29:72

So I removed struts2-core-2.3.4.1.jar from the plugins dir leaving only the copy in the WEB-INF/lib. This fixed the problem and the Struts2 application finally worked.

Note this could cause problems if I were to add another Struts2 application to the container although I haven't tried it.

Related problems with workarounds including removing struts-tags.tld and putting in WEB-INF, or adding Class-Path entries  to MANIFEST.MF:
http://stackoverflow.com/questions/19380836/skinny-war-libraries-in-ear-struts-tags-not-found-error
http://stackoverflow.com/questions/6339323/file-struts-tags-not-found-in-struts-1-3
http://stackoverflow.com/questions/19666413/what-is-the-right-way-to-package-struts2-jar-files
http://docs.codehaus.org/display/MAVENUSER/Solving+the+Skinny+Wars+problem

Saturday, March 8, 2014

Deploy Small Java App to OpenShift

This is the code deploy method. For deploying an existing WAR there are other methods will plenty of how-tos on the web.

- Create a JBoss Application Server 7 app preferably from the rhc client.
- Create a file TestBean.java under src\main\java\action and paste in the sample TestBean class from this tutorial on JSP actions: http://www.tutorialspoint.com/jsp/jsp_actions.htm
- Create a folder "classes" under src\main\webapp\WEB-INF (although I'm not sure this step is necessary)
- Create a file "main.jsp" under src\main\webapp and paste in the corresponding sample code from the above referenced tutorial
- Git add, commit, and push it up.
- Load it in the browser e.g. http://jbossas-<your namespace>.rhcloud.com/main.jsp

see also: http://awgjournal.blogspot.com/2014/03/tomcat-openshift-projects.html

Saturday, November 30, 2013

Create empty file with bcp

I wasn't sure if multiple statements (using semicolon as delimiter) could be passed to bcp, so I tried it, specifically prepending a DECLARE statement and it worked, in this case for creating an empty file:
DECLARE @FilePath VARCHAR(1000)
DECLARE @FileExists int
DECLARE @nulltable TABLE ( foo integer)
SET @FilePath = 'C:\my\path\somefile.csv'

exec master.dbo.xp_fileexist @FilePath, @FileExists OUTPUT
if not @FileExists = 1 
begin
declare @bcpCommand varchar(255), @Result int
set @bcpCommand = 'bcp "DECLARE @nulltable TABLE ( foo integer); Select * from @nulltable" queryout "' + @FilePath + '" -c -t, -T -S '
exec @Result = master..xp_cmdshell @bcpCommand  --, no_output
end

Wednesday, August 7, 2013

Get Value of Form Element

I had names to compare only (as they are generated from DB). I needed the value regardless of element type; most would try to detect type then get the value.

For now I will settle on a one liner expression, and see how it goes in testing:

 $("input[name='NameOfElement']:checked").val() || document['formName']['NameOfElement'].value || false

This should handle radio buttons and checkboxes first (if checked), then selects and inputs, then false. My use case doesn't require comparing values of textareas or multiselects, so I am not accounting for them for now.
Note: I found the above to cause "Do you want to continue running scripts on this page?" messages on old clients, namely IE 7 or 8 on single core Windows XP PCs. So I was forced to replace the above jQuery-reliant code with the following more verbose pure JavaScript:
if ( ! ( (document['Form1']['ItemFoo'].length && document['Form1']['ItemFoo'][0].type=="radio" && myGetSelectedRadioValueByName('ItemFoo')=="Yes") || (!document['Form1']['ItemFoo'].disabled && document['Form1']['ItemFoo'].type=="checkbox" && document['Form1']['ItemFoo'].checked==true && document['Form1']['ItemFoo'].value == "Yes") || (!document['Form1']['ItemFoo'].disabled && document['Form1']['ItemFoo'].type!="checkbox" && document['Form1']['ItemFoo'].value == "Yes"))){ var elems = document.getElementsByName('TargetShowHideElement'); for (var i = 0; i < elems.length; i++) { elems[i].disabled= false; } }


A side note about the above: It is a work in progress; the language-specific expressions are generated from a DSL (a table of variables and corresponding conditions), in a manner similar to a suggestion by "Doc Brown" at http://programmers.stackexchange.com/questions/182025/creating-huge-decision-tree

Friday, June 21, 2013

Disabling Siblings of Selected Radio Button

I couldn't find a "contains" selector that applied to html elements, hence the following hack less elegent (more verbose than it should be) method that functionally and stylistically disables all li containers that don't contain the radio button that's selected:
var enableOnlySelectedListItem = function(parentId, radioItemName) {
     $('#' + parentId + ' input:radio[name=' + radioItemName + ']')
         .on('click', null,"",function (event) {
            $(this).closest('ul')
                .find('input[name=' + radioItemName + ']')
                .not(this)
                .parent()
                .find(':input')
                .not('input[name=' + radioItemName + ']')
                .prop('disabled', true)
            .end()
            .end()
            .addClass('disabledtext');    
                
            $(this).closest('li')
                .find(':input')
                .prop('disabled', false)
            .end()
            .removeClass('disabledtext');    
                
             event.stopPropagation();
     });
};

Sunday, May 19, 2013

Installing Stunnel on CenOS 5

Download tar.gz file from http://www.stunnel.org/downloads.html?extra=/source.html
to ~/temp
did: 
gzip -dc stunnel-4.56.tar.gz | tar xvf -
cd stunnel-4.56
./configure
make
make install

vi /usr/local/etc/stunnel/stunnel.conf-sample
add the line
fips = no
change cert = line to read
cert = /usr/local/etc/stunnel/stunnel.pem
adjust service section, e.g. for forwarding smtp securely

cp /usr/local/etc/stunnel/stunnel.conf-sample /etc/stunnel/stunnel.conf
cp /etc/stunnel/stunnel.conf /usr/local/etc/stunnel/stunnel.conf
#this last one to satisfy stunnel from cmd line, the prior for the service
#perhaps should make them hard linked

cp /usr/local/share/doc/stunnel/examples/stunnel.init /etc/init.d/stunnel
cd /etc/init.d
chmod 755 stunnel

vi stunnel
modify top of file to read:
#! /bin/sh -e
# description: stunnel Start Stop Restart
# processname: stunnel
# chkconfig: 234 20 80

then in startdeamons() change the install line to read:
install -d -o nobody -g nobody /var/run/stunnel

save file
do:
echo "ENABLED=1" > /etc/default/stunnel

Disable sendmail
chkconfig sendmail off; service sendmail stop

Enable stunnel
chkconfig --add stunnel
In case tests are running:
pkill stunnel 
service stunnel start

References: