Tuesday, October 16, 2012

Find Class in .jar files

So I had a load of .jar files and was looking for a specific class that should be contain in one of them. I found you can run the following command to search for a class file:

find -name "*.jar" -exec sh -c 'unzip -l "{}" | grep -q <class name>' \; -print

Just replace <class name> with the class name e.g. 

find -name "*.jar" -exec sh -c 'unzip -l "{}" | grep -q HttpServletRequest' \; -print

Ref: http://unix.stackexchange.com/questions/25503/looking-for-a-java-class-in-a-set-of-jars-with-find-unzip-grep

Thursday, October 11, 2012

Microsoft Security Essentials and VMware

Note to self. Make sure you add exclusions to Security Essentials not to scan the vmdk amd vmem files:

Wednesday, August 8, 2012

ECMAScript parseInt

So I seem to have a love hate relationship with ECMAScript. Today is very much not a loving day for ECMAScript.

I needed to convert text like '06' to an integar, so I just used the parseInt function.

What I did not reliase was that if you do not provide a value for the radix you get very strange results like so:

 js> print(parseInt('06'));   
 6  
 js> print(parseInt('08'));  
 NaN  
 js> print(parseInt('08',10));  
 8  

When you add the radix everthting works as expected as can be seen above.
Note to self: Don't assume functions work the same across all programming languages.

Really enjoyed this video: WAT -> https://www.destroyallsoftware.com/talks/wat

This was a nice 'bug' I found using ECMAScript

js> var a = '1';
js> var b = a + 1;
js> print(b);
11
WAT!

js> var a = 1;
js> var b = a + 1;
js> print(b);
2
 

Java Query Soap HTTP and HTTPS

One of the end points that we query was suddenly changed from HTTP and HTTPS using a self signed cert and invalid host name in the cert. Sadly you can't just change the URL in your config file and everything works. What I needed to do was to change my querySOAP function to work for both HTTP and HTTPS. Here's what I came up with.Oh and this function also supports HTTP authentication. Nice!

      public static String querySoap(String url, String soapAction, String msg, final String username, final String password) {  
           String ret = null;   
           try {  
                boolean HTTPS = false;  
                if( url.substring(0, 5).equalsIgnoreCase("https") ) HTTPS = true;  
                Config c = new Config();  
                Log.log(Level.INFO, "Url: " + url  
                     + "\r\nSoapAction: " + soapAction  
                     + "\r\nSoapMessage: " + msg);       
                URLConnection connection;  
                URL u = new URL(url);       
                if( HTTPS ) {  
                     Log.log(Level.INFO, "We use SSL to connect to : " + url);  
                     // Create a trust manager that does not validate certificate chains  
                     TrustManager[] trustAllCerts = new TrustManager[] {new X509TrustManager() {  
                               public java.security.cert.X509Certificate[] getAcceptedIssuers() {  
                                    return null;  
                               }  
                               public void checkClientTrusted(X509Certificate[] certs, String authType) {  
                               }  
                               public void checkServerTrusted(X509Certificate[] certs, String authType) {  
                               }  
                          }  
                     };  
                     // Install the all-trusting trust manager  
                     try {  
                       SSLContext sc = SSLContext.getInstance("SSL");  
                       sc.init(null, trustAllCerts, new java.security.SecureRandom());  
                       HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());  
                     } catch (Exception e) {  
                     }                 
                     // Create all-trusting host name verifier  
                     HostnameVerifier allHostsValid = new HostnameVerifier() {  
                          public boolean verify(String hostname, SSLSession session) {  
                               return true;  
                          }  
                     };  
                     // Install the all-trusting host verifier  
                     HttpsURLConnection.setDefaultHostnameVerifier(allHostsValid);  
                } else {  
                     Log.log(Level.INFO, "We do not use SSL to connect to : " + url);  
                }  
                connection = u.openConnection();  
                connection.setConnectTimeout(c.httpConTimeout);  
                connection.setReadTimeout(c.httpConReadTimeout);  
                connection.setDoOutput(true);  
                connection.setDoInput(true);  
                connection.setUseCaches(false);  
                connection.setRequestProperty("Content-Type","text/xml;charset=UTF-8");  
                connection.setRequestProperty("SOAPAction", soapAction);  
                connection.setRequestProperty("User-Agent","Jakarta Commons-HttpClient/3.1");                 
                connection.setRequestProperty("Content-Length","" + msg.length());  
                if( username != null && password != null) {  
                     String login = username + ":" + password;  
                     String encodedLogin = Base64.encodeBytes(login.getBytes());  
                     connection.setRequestProperty("Authorization", "Basic " + encodedLogin);  
                }  
                OutputStream out = connection.getOutputStream();       
                Writer wout = new OutputStreamWriter(out);  
                wout.write(msg);  
                wout.flush();  
                wout.close();  
                StringBuffer strBuf = new StringBuffer();  
                String inputLine;                 
                BufferedReader bufRead = new BufferedReader(new InputStreamReader(connection.getInputStream(),"UTF-8"));                 
                while ((inputLine = bufRead.readLine()) != null) {  
                     strBuf.append(inputLine);  
                }  
                bufRead.close();  
                ret = strBuf.toString();  
                Log.log(Level.INFO, "SoapResponse: " + ret);  
           } catch (Exception e) {  
                e.printStackTrace();            
           }            
           return ret;  
      }  

Reference: http://www.nakov.com/blog/2009/07/16/disable-certificate-validation-in-java-ssl-connections/

Monday, August 6, 2012

Sunrise

The traffic ain't so bad when you can watch the Sunrise like this:



Note to self: Look for the Good in the World.

Thought for the day: 'While chasing the moon some people miss the flowers blossoming at their feet.'


Tuesday, July 24, 2012

How to invoke a Web service using curl

To invoke a Web service using curl you basically just need to post the soap envelope and the required soap action. I needed to invoke a Web service from cron so I wrote this script to do it using this method:

#!/bin/bash
LOG_FILE="/var/log/armcron.log"
echo "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:arm=\"http://www.com.co.za/ARM/\">
   <soapenv:Header/>
   <soapenv:Body>
      <arm:warnForEndDate/>
   </soapenv:Body>
</soapenv:Envelope>" > /tmp/warnForEndDate
echo "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:arm=\"http://www.com.co.za/ARM/\">
   <soapenv:Header/>
   <soapenv:Body>
      <arm:revokeForEndDate/>
   </soapenv:Body>
</soapenv:Envelope>" > /tmp/revokeForEndDate

curl -H 'SOAPAction: "http://www.com.co.za/ARM/warnForEndDate"' -X POST -H 'Content-Type: text/xml;charset=UTF-8' -d @/tmp/
revokeForEndDate http://localhost:8080/armws/services/ARM/ >> $LOG_FILE 2>&1

Friday, July 13, 2012

Novell RBPM Logging Configuration to Debug Workflow

Set the following log levels to trace to debug the workflow:

- com.novell.soa.af.impl
- com.novell.soa.script

Thursday, July 12, 2012

How not to do XML

This is some sample XML I get from a customers Web service. In my opinion this is a prime example on how not to represent data using XML.

  <ImplementorList>
               <Implementor xsi:nil="true">
                  <ArrayOfImplementorItem>
                     <OID xsi:nil="true"/>
                     <Name xsi:nil="true"/>
                     <Email xsi:nil="true"/>
                  </ArrayOfImplementorItem>
               </Implementor>
               <OID>
                  281527649831711
                  <Implementor>
                     <ArrayOfImplementorItem>
                        <OID xsi:nil="true"/>
                        <Name xsi:nil="true"/>
                        <Email xsi:nil="true"/>
                     </ArrayOfImplementorItem>
                  </Implementor>
               </OID>

Wednesday, July 11, 2012

A Dell Rolling in the Deep


Go Well Go Dell!

Effective Writing Skills

Found this a while ago, but it's still very good material on effective writing skills.

Click here

My VPN Speed for Today

Not too bad, just need to see where the 102ms ping is coming from.


Tuesday, March 27, 2012

How to enable HTTPS with AXIS 2

I've been using AXIS2 for a couple of months now and decided to take the HTTPS / SSL plunge. The following notes are guidelines on how I configured HTTPS with AXIS2.

I am using Tomcat 6, so firstly you need to enable HTTPS in Tomcat:
1) Create a keystore with the following command and enter the required values:
  keytool -genkey -alias tomcat -keyalg RSA -validity 365
2) Then copy this file to a directory e.g. /usr/share/tomcat6/.keystore
3) Edit the Tomcat server.xml e.g. /etc/tomcat6/server.xml and add the following section inside the <Service name="Catalina"> tag

 <Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
               maxThreads="150" scheme="https" secure="true"
                keystorePass="yourkeystorepassword" keystoreFile="/usr/share/tomcat6/.keystore"
               clientAuth="false" sslProtocol="TLS" /> 
(replace yourkeystorepassword with the password you used in step 1)
4) Restart Tomcat and test that you can access Tomcat via HTTPS on port 8443 (you will get a certificate error in your browser as it's not a trusted certificate).

Now onto AXIS2:
5) I downloaded the axis2.war file.
6) Extract the war file with unzip to a empty directory.
7) Edit the WEB-INF/conf/axis2.xml file
8) Change this:
<transportReceiver name="http"
                       class="org.apache.axis2.transport.http.AxisServletListener"/> 
to this:
   <transportReceiver name="http"
                       class="org.apache.axis2.transport.http.AxisServletListener">
        <parameter name="port">8080</parameter>
    </transportReceiver>
    <transportReceiver name="https"
                       class="org.apache.axis2.transport.http.AxisServletListener">
        <parameter name="port">8443</parameter>
    </transportReceiver>
9) Now restart Tomcat and go to the HappyAxis(https://localhost:8443/axis2/axis2-web/HappyAxis.jsp) page. You'll see you get some internal server error. This is because Tomcat does not have the keystore configured for AXIS2 to use.
I fixed this by adding the following JAVA_OPT options:
        JAVA_OPTS="$JAVA_OPTS -Djavax.net.ssl.trustStore=\"/usr/share/tomcat6/.keystore\" - Djavax.net.ssl.trustStorePassword=\"yourkeystorepassword\""
(replace yourkeystorepassword with the password you used in step 1)
10) Check HappyAxis page and WSDL -> https://localhost:8443/axis2/services/Version?wsdl

All done no mess no fuss :)


Friday, March 23, 2012

stackoverflow.com

I must say I love stackoverflow.com I really don't know what I did without the helpful posts you can find on the site. Recently I had to do a recursive SQL query and found a nice solution here. I also needed some help with threads and found a quick answer here. A big thanks to the people at stackoverflow.com.

Friday, February 24, 2012

Oracle Database Fun and Games

I've been working with a number of Oracle databases lately and decide to post some of the tips and tricks that I found:

SQL Developer
Error when you connect to database:
"Status : Failure -Test failed: ORA-00604: error occurred at recursive SQL level 1ORA-01882: timezone region not found"
Solution: Edit the sqldeveloper.conf file and add the following line:
AddVMOption -Duser.timezone=GMT

Error, running out of RAM
Solution: Edit the sqldeveloper.bat file and change the following parameters as required:
-Xmx640M -Xms128M
You can also set the -XX:MaxPermSize setting in the sqldeveloper.conf file, but I have not had to increase this yet.

Start Database Script
Old but good article here -> http://tldp.org/HOWTO/Oracle-7-HOWTO-6.html
Basically you need to do this:
Start the listner: lsnrctl start listener
Start Enterprise Manager: emctl start dbconsole
Set the SID of the database: export ORACLE_SID=report
Connect to sqlplus: sqlsplus "sys as sysdba"
Run the startup command: startup

Get list of tables
select tname from tab

Delete all tables
select 'drop table '||table_name||' cascade constraints;' from user_tables; ref

Stop it from prompting you for input values due to the & character
set define off

Cool tool to create new database
dbca (ssh -X into the server and run this command)

Friday, February 3, 2012

Novell IDM Convert Structured Attribute


Every time I need to work with structured attributes on a driver I land up googling for that same page of how to convert a structured attribute to a string and vice verse. Thus to save time I decide to post a link to the forum   here

The meat of the what you need to do to convert from a structured attribute to a string and back again is below, just remember to replace the attribute and component names as required:

Output Transform (struct -&gt; string):
<do-reformat-op-attr name="faxnumber">
<arg-value>
<token-xpath expression='$current-value/component[@name="faxNumber"]/text()'/>
</arg-value>
</do-reformat-op-attr>

Input Transform (string -&gt; struct): 
<do-reformat-op-attr name="faxnumber">
<arg-value type="structured">
<arg-component name="faxNumber">
<token-local-variable name="current-value"/>
</arg-component>
<arg-component name="faxBitCount">
<token-text xml:space="preserve">0</token-text>
</arg-component>
<arg-component name="faxParameters">
<token-text/>
</arg-component>
</arg-value>
</do-reformat-op-attr>

Wednesday, January 25, 2012

Why don't you run Linux? An absolute classic

Steve the super villain

Software testing

Lately I've been involved in a lot of software testing and came across this awesome article about it:

Top Five (Wrong) Reasons You Don't Have Testers

I find this guys blog very insightful and like the list of checks he recommends for software development:

Do you use source control?
Can you make a build in one step?
Do you make daily builds?
Do you have a bug database?
Do you fix bugs before writing new code?
Do you have an up-to-date schedule?
Do you have a spec?
Do programmers have quiet working conditions?
Do you use the best tools money can buy?
Do you have testers?
Do new candidates write code during their interview?
Do you do hallway usability testing?

Tuesday, January 24, 2012

My WSDL Cheat Sheet



Service -> ‘Java Class’

Operation -> ‘Java Function’ The Operation defines the name of the Operation and ties the request response messages together.

Port -> A service is assessable on a Port.  A Port has a unique name space and binding attribute. The Port specifies the service address. Web service can be exposed as SOAP or HTTP. The same web service can also be exposed by multiple Ports.
SOAP example:
<port name='WeatherSoapPort' binding='wsdlns:WeatherSoapBinding' >
<soap:address   location='http://localhost/demos/wsdl/devxpert/weatherservice.asp' />
</port>

HTTP example:
<port name='WeatherSoapPort' binding='wsdlns:WeatherSoapBinding' >
<http:address location="http://localhost/demos/wsdl/devxpert/weatherGET.asp"/
</port>

Message -> Normally two messages required i.e. input message and output message. Messages contain zero or more <part> elements. Sample messages below
<message name='Weather.GetTemperature'>
    <part name='zipcode' type='xsd:string'/>
    <part name='celsius' type='xsd:boolean'/>
 </message>

 <message name='Weather.GetTemperatureResponse'>
    <part name='Result' type='xsd:float'/>
 </message>rt name='WeatherSoapPort'

Binding -> ‘Ties it all together’ - specifies binding(s) of each operation in the PortTypes section

Sunday, January 15, 2012

More Holiday Photos

Cartoon effect on my camera

Dam on Table Mountain

Dam water

More dam water

Some people choose to ignore warnings

Nice bird

uShaka

uShaka
Swimming at Silvermine


Holiday Photos December 2011

Table Mountain

St James Beach - 26 December 2011
View of Constantia wine farms

View of Table Mountain from Milnerton - I like the panorama mode on my camera phone :)

Out at the Baxter for 'Some like it Vrot'

Sea Point

View from Hillcrest Berry Farm



Beware of the Prawns (only in Joburg)

Followers