Tuesday, November 2, 2010

Where Are My File Extensions

Due to some seriously strict email servers, I was unable to send a .zip file in an email. It was being blocked by the individual I was sending it to's server (poor English).

The easy solution was to rename my file james.zip to james.allow, faking the mail server out so it wouldn't be blocked. On the other end, the user could just alter it back from james.allow to james.zip and bam, problem solved.

However I was unable to rename my file in Windows using the right click -> rename feature. If I changed the file james.zip to james.allow, it would call it james.allow.zip. Being ignorant to all things simple, I was unaware that Windows hides the file extensions from you by default.

The way to add those file extensions into your file names, so you can rename the file extension, is to go into Windows Explorer->Tools->Folder Options->View (tab) and uncheck the "Hide extensions for known file types" box. Once you do this, all your files (with extensions) will appear and you can rename james.zip to james.allow to successfully get it across.

Tuesday, October 26, 2010

Visual Studio Basics - DLL's

Just starting to go to work on Visual Studio. Was receiving an error when I was running a program that said, "This application has failed to start because libfrsdk-8.1.0d.dll was not found. Re-installing the application may fix this problem."

First for dll's, they seem to be the .NET equivalent of JAR files. Dynamic Linked Libraries. What this error seems to be saying is that it can't find the library needed to execute the code. Sort of like a ClassNotFoundException in Java (may be a bit of a stretch).

One option was to add the folder housing the libfrsdk-8.1.0d.dll to my PATH variable but that seems kind of ehhh. Why should I alter an environment variable when most of the shit I do isn't going to need this .dll file?

Another option and the one I went with was to add the .dll to the same folder that houses my actual application. Pasting in the appropriate dll did the trick when I ran the program.

So the last question you may have if you're totally ignorant on Visual Studio and whatnot is "how do I know what folder has my application?" Visual Studio when you build/compile creates a Debug folder underneath your project. This Debug folder contains all sorts of interesting files, most importantly an Application type file with the name of your program. Pasting the dll's in this Debug folder did the trick for me.

More to come I'm sure as I attempt to become savvy in .NET

Monday, October 25, 2010

How to Remove Security Tool Virus

Was doing some totally legit website surfing (guitar tabs, thank you), and got a pop-up saying a virus had been detected and that a scan was running to find the problem. These items were masquerading as legitimate Windows programs. The name of the running program was simply "Security Tool".

Don't believe the hype, it is a virus and it is trying to force you to purchase their tool (via credit card) to remove the virus (which it just created). Very dodgy shit. Once you enter in your credit card information who knows what gets done with it. Totally illegal.

Not only did Security Tool constantly pop up after I closed it saying the same message over and over, it also managed to completely take over my Internet access and stop my antivirus programs from running. Fortunately I had an IPhone so I was able to search for solutions.

The simplest way I found to get rid of it and regain internet access was this:
1) Stop the computer and restart it with booting options (F-12 in Windows).
2) Start the computer in Safe Mode with Networking (because you'll need the Internet).
3) Download MalwareBytes' free product and make sure it is updated to the most recent version.
4) Run a full system scan with MalwareBytes. This will find the evil files and remove them. It will take around an hour to complete.
5) Select all the items the program found and remove them using the MalwareBytes tool. (Seriously these MalwareBytes people are awesome!)
6) Restart your computer normally. You should no longer see any evil messages and whatnot, the virus should be removed and you should be good to go now.....
7) EXCEPT!!! When you try to launch the Internet, you'll be unable to. This is because the virus does some ignorant shit to force your internet requests to go to a proxy server (the evil virus' proxy server...this is how they control your internet access).
8) The way to turn this proxy server off differs depending on your browser, but for Google Chrome, go to Wrench Icon -> Options -> Under the Hood -> Change proxy settings -> LAN Settings (similar for other browsers I suspect)
9) Uncheck the "Use a proxy server for your LAN" button and "OK" out of those windows. Now when you restart your browser you should have your internet back.

Simple as that. Thanks to MalwareBytes for totally being wonderful human beings.

And whoever the a-holes are that created the Security Tool virus/trojan horse/malware that is taking over peoples computers and stealing credit cards.....you're pieces of trash.

Friday, October 22, 2010

Ant Javac stops Compiling when fork=true

This one was a beast and unfortunately I still don't have any definitive answers as to why this happens. I had an Ant javac task with the following attribute:


fork="true"

When I would run Ant, it would say that it was starting to compile, and then it'd just stop. My class files would never be generated, but it would not have an error explaining what went wrong. (For the record there were more attributes, blogger doesn't accept the javac xml tag though....trust me, all the other attributes were right as rain.)

I tried playing around with setting an executable attribute, ensuring it was pointing to a javac executable (when you set fork = true, you're telling it to compile externally). This didn't work either. I turned on verbose logging by going into Eclipse->External Tool Configurations and setting -verbose as an argument in the arguments section of the configurations. This spit out a bunch more detail, but still nothing helpful.

The javac process would start without error, it'd list all the .java files that it found that needed compiling, and then stop. No error, no warning, just hang there doing nothing.

After much playing around, I found out that if I removed the fork attribute everything would work fine.

Unfortunately that's all I've got for you. I've wasted 8 hours on this thing and still am not closer to why this happens. If anyone happens to know why this is happening please let me know. I've tried altering JAVA_HOME's, default JDK's being used, etc. I've tried increasing the amount of memory......

I give up. If you experience this problem, where javac hangs without error and without completing, try making fork="false".

Tuesday, October 19, 2010

Clever Way to Handle SimpleDateFormat ParseException

I was having a few issues dealing with dates and XMLGregorianCalendar objects. Here's what went down.

I had a method that was parsing String dates and placing them into XMLGregorianCalendar objects. In order to get the XMLGregorianCalendar object created, you can use something similar to this code (You'll be forced to catch DatatypeConfigurationException):

GregorianCalendar gc = (GregorianCalendar) GregorianCalendar.getInstance();
DatatypeFactory dataTypeFactory = DatatypeFactory.newInstance();
XMLGregorianCalendar xmlCal = dataTypeFactory.newXMLGregorianCalendar(gc);


The above code will give you the current time in an XMLGregorianCalendar object. Unfortunately I needed to accept a String date (like: 6/10/2010 5:40:30 PM) and use that instead of the current time.

The way you do this is the following (you'll be forced to catch ParseException AND DatatypeConfigurationException):

Date date = null;
SimpleDateFormat dateFormat = new SimpleDateFormat("M/dd/yyyy hh:mm:ss a")
GregorianCalendar gc = (GregorianCalendar) GregorianCalendar.getInstance();
date = dateFormat.parse(
"6/10/2010 5:40:30 PM");
gc.setTime(date);
DatatypeFactory dataTypeFactory = DatatypeFactory.newInstance();
XMLGregorianCalendar xmlCal = dataTypeFactory.newXMLGregorianCalendar(gc);


The issue was, different dates were coming back in different formats (crappy but I don't control the String passed in). So one date would be 6/10/2010 5:40:30 AM and another would be 7/11/11 5:40. When the method tried to parse a date without an AM/PM specifier, ParseException would be thrown. Very lame.

The way I've come up with to handle this is to place several SimpleDateFormat objects in a list and order them most specific to least specific (the term granularity is popping up in my mind). You can add as many SimpleDateFormat objects to the list with different patterns as you'd like.

Here is my complete example code that handles this:

private XMLGregorianCalendar getXmlGregorianCalendarFromString(
String stringDate)
{
XMLGregorianCalendar xmlCal = null;
GregorianCalendar gc = (GregorianCalendar) GregorianCalendar
.getInstance();
Date date = null;
DatatypeFactory dataTypeFactory = null;

List dateFormatsList = new ArrayList();
dateFormatsList.add(new SimpleDateFormat("M/dd/yyyy hh:mm:ss a"));
dateFormatsList.add(new SimpleDateFormat("M/dd/yyyy hh:mm:ss"));
dateFormatsList.add(new SimpleDateFormat("M/dd/yyyy hh:mm"));

for (SimpleDateFormat dateFormat : dateFormatsList)
{
try
{
date = dateFormat.parse(stringDate);
gc.setTime(date);
dataTypeFactory = DatatypeFactory.newInstance();
xmlCal = dataTypeFactory.newXMLGregorianCalendar(gc);
// If we've made it here we have everything we need to proceed
// so break from the loop
logger.warn("Successfully parsed the date: " + stringDate
+ " with the format: " + dateFormat.toPattern());
break;
}
catch (ParseException e)
{
logger.warn("Failed to parse the incoming date: " + stringDate
+ " given the format: " + dateFormat.toPattern()
+ " attempting another date format. ");
continue;
}
catch (DatatypeConfigurationException exception)
{
logger
.warn("An error occurred generating a DatatypeFactory object. ");
}
}
return xmlCal;
}


There may be some hiccups to the above method (I only need 3 possible date formats), and if a better way exists to handle multiple SimpleDateFormats let me know, but I gotta say, it's more flexible and simple than I thought it could be.

Monday, October 18, 2010

Increase Server Startup Timeout in Eclipse

I was receiving a Server startup timeout in Eclipse when I started Tomcat. It was complaining that startup took more than 45 seconds so it wouldn't start at all.

Trickier than I thought to alter this setting as I couldn't find in the the Preferences->Server section.

If you want to change the startup timeout in Eclipse, the way to go about it is to double click on your server in the Servers tab. This pops up a window with a lot of nice options to configure. Click the Timeout arrow, increase the timeout to be more than 45 seconds, and that's all there is to it.

Friday, October 15, 2010

The Battle With Solaris Part 3

The final fight with Solaris 10 in order to get my Oracle DB up and running....

When I ran the .sql script using sqlplus to build the DB, I was receiving an error:

ORA-27102: out of memory

Followed by a:

solaris-amd64 Error: 12: Not Enough Space

Did a lot of digging around trying to find what the problem was. Doing a df -k (this command gets you the space available on various filesystems) it appeared I had enough space necessary to create a DB.....so what was the problem.

The solution was to increase my swap space which was apparently running out.

It is detailed here: http://www.tek-tips.com/viewthread.cfm?qid=1051183&page=10

Essentially those commands take a chunk of memory from the root filesystem / (1024M or 1 Gig) and allocates it as swap space.

After that when the .sql script ran it had the necessary space to do what it needed.

Everything worked fine, the DB was installed and that was that.

So I learned a bunch of random unix commands, and learned a bit about VMWare and Solaris. All in all a nice opportunity to increase my knowhow.

And now it's all blogged so I'll never be clueless again, right?

The Battle With Solaris Part 2

Ok, so the next fight with Solaris 10 had to do with .profile and ownership of files/directories. This is probably remedial shit for a Unix person but it's new to me.

There was a .sql file I needed to run using sqlplus. When I navigated to the directory where the .sql file was and tried to run the command "sqlplus /nolog @create_me.sql" I received a Command Not Found error in my terminal/shell-window/command prompt/whatever you want to call it. I assume this error is similar to when you try to run a program in DOS that isn't on your PATH.

So the solution I read about was to alter your .profile of the user you're logging in as. Again, similar to Windows Environment Variables. The issue was when I tried to find my .profile file I couldn't see it. It was nowhere to be found in /export/home/myuser.

There was a local.profile file but altering that did nothing beneficial for me. For some reason Solaris hides your .profile file. Don't know why but they do. It's there even if you don't see it. So I VI'd the .profile file, and added ORACLE_BASE, ORACLE_HOME variables, and added in my ORACLE_HOME variable to the existing PATH variable by doing something like:
PATH=$ORACLE_HOME/bin:$PATH; export PATH

This adds ORACLE_HOME to the beginning of the current PATH variable. I assume this is important. I had to re-login for the changes to take effect. Once I logged back in running the env command showed me these new environment variables and their values as well as a bunch of other environment variables that weren't in my file at all. No clue what's going on there.

Sooooo.....

Now I was able to run my sql script using sqlplus. However when I ran it, it was giving me a "Permission Denied" error on a folder I had created. This was because I created the folder using user "root" but had not given access to everyone. So my "myuser" user couldn't utilize it.

There are probably many ways to solve this, but I found there was a command called chown which you can run to change the user who owns it as well as the group access. The command was:
chown -R oracle:oinstall /mydirectoryname

What this does is change the owner of the files and directories in the mydirectoryname folder to oracle, and the group that owns those files/directories to oinstall. The -R (capital) flag says "change ownership for every file/directory in mydirectoryname" vs. chown oracle:oinstall /mydirectoryname which would just alter the owner(ship) of that individual folder. Keep in mind that I had to su - root in order to change the ownership. This makes sense, a lesser privileged user who doesn't own a file shouldn't get giving everyone and their mother ownership to a file. Only the user who created it can.

Alternatively I probably could have read up about chmod and done some sort of chmod a+rwx /mydirectoryname but whatever, I learned something new with chown.

With this fixed I was able to get to a whole different Solaris 10 issue that I'll discuss in Part 3.

The Battle With Solaris Part 1

I was asked to re-ip a Solaris 10 box via the VMWare Infrastructure Client and set up an Oracle DB on that machine (Oracle was already installed). Being a novice at Oracle, having to google what Solaris was (unix-like), never using VMWare before, and having to re-learn unix made for a pretty daunting task. Here is Part 1 of what I learned:

First with the Re-IP'ing. You can alter files directly to change your IP or you can open a terminal on your Solaris machine and run the command "sys-unconfig". It will ask you if you're sure you want to and blah blah blah, but when the machine restarts your hostname will be "unknown" and you will be able to specify a new IP address, default gateway, hostname, etc.

The steps are relatively self-explanatory. There were a few terms I didn't know. In general if I didn't understand what the term meant, I didn't set it up. One thing worth noting, before running sys-unconfig I wasn't able to type the | (pipe) character into the shell. When you sys-unconfig, you have the option to change your keyboard configuration and wouldn't you know, it was set up as some UK bull rather than a US keyboard, so I made that change and the | character was typable again.

Anyway back to the re-ip. I entered the new values into the sys-unconfig wizard, the machine restarted, and it had altered all of those files that I would have had to manually alter. When doing a ping from the Solaris box I was getting a response, however when I was pinging the common gateway from the Solaris box, or the IP from my local machine, I was not getting a response.

This made little sense to me who has no networking experience. Why could I ping internally but not from my external machine. And why could I externally ping the common gateway but not from the Solaris box.....

Long story short, after I re-ip'd the machine, I was supposed to go into VMWare and right click -> Edit Settings on the Solaris machine. On the Hardware tab, clicking Network Adapter 1, the device status was not connected and connect at power on was unchecked. By clicking those checkboxes and saying "Ok" everything worked internally and externally (both the default gateway and the IP were pingable).

My guess as to what was going on:
1) With no network connectivity, when pinging the IP from the solaris box, it saw it was the local IP and therefore did not need network connectivity to hit that IP.
2) Since there was no network connectivity, when pinging the default gateway the Solaris box wasn't able to call out to the gateway IP which is why ping was unsuccessful
3) My local machine could ping the gateway IP because both my machine and the gateway had network connectivity
4) My local machine could not ping the new Solaris IP because the machine had no connectivity.

These are guesses.

And the end of this post.

More to come in later parts like chown, df -k, and stuff.

CSV Encoding

Two relatively simple lines of code:

FileInputStream fstream = new FileInputStream("C:\\MyFilePath\\" + "myFileName.csv");

BufferedReader reader = new BufferedReader(new InputStreamReader(
fstream, "UTF-8"));

When I run this code and try to do a reader.readLine() call I wasn't seeing the line in the csv file coming back properly.

I changed UTF-8 to UTF-16 as the encoding of the InputStreamReader and was having a little bit more success, but still odd characters were showing up in between legit characters.

I did some reading and I'm not sure if this is all CSV files but there is an encoding the InputStreamReader accepts called UTF-16LE (LE for Little Endian). Changing that as the encoding type to my InputStreamReader did the trick and I can now read line by line successfully.

Friday, October 8, 2010

First Batch Script setlocal EnableDelayedExpansion

Needed to create a batch script to kick off a Java program. Had never written a batch script before and had some troubles getting the class path set properly. The code I was using was:

@echo on
if "%JAVA_HOME%"=="" (
echo The JAVA_HOME environment variable is not set.
goto end
)

set TEMP_CLASSPATH=.;
for %%i in (..\lib\*.jar) do (
set TEMP_CLASSPATH=!TEMP_CLASSPATH!;%%i
)

set TEMP_CLASSPATH=!TEMP_CLASSPATH!.;
echo %TEMP_CLASSPATH%

java -cp %TEMP_CLASSPATH% com.amphibiousrodents.MyJavaProgram
pause

I wrote it in Windows XP (not sure if this has any bearing on anything). When I ran this script from my Eclipse project's /bin folder it was causing a java.lang.NoClassDefFoundError

After some digging around someone mentioned that adding a line:
setlocal EnableDelayedExpansion would do the trick. After adding that into the .bat file at the top, the classpath was properly set and the program ran without problem. setlocal EnableDelayedExpansion......hmmmm......shoe