Powered By Blogger

Thursday, 9 April 2009

How to get mimeType in Java

Recently, I tried to write a piece of code that uploads my file directly to Google docs (I'm so in love with Google :-x) and I needed the mime type of the file I intended to upload , to my surprise, default packages in JDK does not return correct mimeTypes e.g java.net.FileNameMap.

Java by default returns 'application/octet-stream' as Microsoft word document mime type instead of 'application/msword'. This however causes an exception

ServiceException: com.google.gdata.util.InvalidEntryException: Bad Request
Content-Type application/octet-stream is not a valid media type

Strange isn't it? I also tried a couple of Classes that uses JAVA_HOME/lib/content-types.properties file. The is my solution perhaps you alsi have similar troubles like me.

1. Grab a copy of install-ocutil-2.4.2

2. Open a command prompt and type java -jar install-ocutil-2.4.2.jar

3. Follow the instructions and choose default installation path

4. Add C:\Program Files\clapper.org\util\lib\ocutil-2.4.2.jar to your application- In Netbeans IDE 6.5 you may follow these steps

5. Right click on Library of your project node

6. Click on Add JAR/Folder... and select C:\Program Files\clapper.org\util\lib\ocutil-2.4.2.jar

Please when adding hefty lib like gdata client libary you may want to create a library using library manager and then import. See getting started with Java and google soon in my next blog :-)

7. You may test using this sample code I have written, Note that org.clapper.util.misc.MIMETypeUtil was imported.

All the best and happy coding!!! :-)

How to configure PHP to use Oracle database

Author: Agbebiyi Babajide Adebiyi

Remark: ITS Documentation

Date: 22022009

Link: jide@live.co.za

INTRODUCTION

This documentation is intended to help quickly configure the TUT(Tshwane university of technology, SA) ITS connection. ITS connection is simply the Oracle database connection that TUT uses to store all crucial information about student and staff of TUT. This documentation hereby written for a simple purpose of connecting to this database to read information stored on TUT database.

PURPOSE

This documentation may be used by anyone testing, trying or wanting to build applications that connects to an oracle database system and also to help configure or recompile oracle(OCI8 installation with world’s powerful server scripting language php) on a LINUX OS.

HARDWARE AND SPECIFIIC CONFIG

OS:Linux

DISTRO: Centos

VERSION: 5

NEEDED TOOLS OR SOFTWARE

At the time of writing, the following versions were used

Oracle Instant client 11

PHP5

SETTING UP THE ENVIROMENT

1. Grab a copy of Oracle instantclient (basic and devel packages ) at http://www.oracle.com/technology/software/tech/oci/instantclient/index.html Note: I will illustrate using the .zip files. It is the same thing either you use rpm versions too.

mkdir -p /opt/oracle/instantclient

cd /opt/oracle/instantclient

unzip instantclient-basic-linux32-XXXXXXX.zip

unzip instantclient-sdk-linux32XXXXXX.zip

NB: Make sure all your instantclient files are in /opt/oracle/instantclient

We have to create symbolic links to some very crucial files in our instantclient folder.

cd /opt/oracle/instantclient

ln -s libclntsh.so.10.1 libclntsh.so libclntsh.so.10.1 will be whatever version you have

ln -s libocci.so.10.1 libocci.so

2. Now we have to download OCI8 module and build it ourselves. Grab it at http://pecl.php.net/package/oci8 .

mkdir -p /usr/local/srcs

cd /usr/local/srcs

Move the oci8 module to this folder created in step 3 above.

mv oci8-xxx.tgz /usr/local/srcs

tar xzf oci8-xxx.tgz

cd oci8-xxx

phpize

./configure --with-oci8=shared,instantclient,/opt/oracle/instantclient

make

make install

3. Edit your php.ini and add

extension=oci8.so

TESTING IF OCI8 IS ENABLED

Quickly write a phpinfo() script and see if you will see anything about oci8 like below

ENVIROMENT VARIABLE

type

export LD_LIBRARY_PATH= opt/oracle/instantclient

export TNS-ADMIN= opt/oracle

Grab and copy tnsnames.ora from your database administrator to

opt/oracle Folder

Restart apache server, depending on how you installed apache, traditionally use/etc/init.d/httpd restart

Run the phpinfo() script and look for image below about oci8

NB: The variable you might see may differ a bit due to difference in oci8

version but what is important is that you see oci8

MORE ENVIROMENT VARIABLE / START UP SCRIPT

You may want to create a script and set these environment variables, e.g. you can put in

/etc/rc.local – this script runs last during system startup ensuring that your connection to Oracle DB is always active

cd /etc/rc.local

type vi oci-init.sh

type the following command

/etc/init.d/httpd stop #stop web server and set environment

export LD_LIBRARY_PATH= opt/oracle/instantclient

export TNS-ADMIN= opt/oracle

/etc/init.d/httpd start

Thank you for using my how to, any comment, e-mail me, see above

Agbebiyi Babajide Adebiyi (Prince)