Using log4j as a shared library in Oracle Application Server 10.1.3.x.

Posted by Steve Racanovic | Posted in , | Posted on 2:48 PM

0

In this example I installed log4j as a shared library to my oc4j instance and then deploy my application from Jdev that utilises this library.

First Download log4j from

http://jakarta.apache.org/log4j/docs/download.html

Deploying log4j as shared library.

1. Unzip the downloaded log4j file.

2. In OAS ASC, select your oc4j instance -> Administration. Under Administration Tasks -> Properties and select Shared Libraries.



3. In Shared Libraries click Create.



4. Enter the library name/version

Shared Library Name = log4j
Shared Library Version = 1.0



5. Select the jar to load into the library.




6. Click finish and see the loaded library.



In Jdev, create a simple web application servlet that uses log4j.



7. My servlet looks like:

package project1;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;


public class Log4jDemoInOAS extends HttpServlet {
private static final String CONTENT_TYPE =
"text/html; charset=windows-1252";
Logger log = Logger.getLogger("Log4jDemoInOAS.class");

public void init(ServletConfig config) throws ServletException {
super.init(config);
String prefix = getServletContext().getRealPath("/");
String file = getInitParameter("log4j-prop-file");
if (file != null) {
PropertyConfigurator.configure(prefix + file);
}

}

public void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException,
IOException {
response.setContentType(CONTENT_TYPE);
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<head><title>Log4j Demo In OAS</title></head>");
out.println("<body>");
out.println("<h2>Using log4j shared libraries in OAS Demo</h2>");
System.out.println("=== Log4jDemo ===");
log.debug("== DEBUG Message ==");
log.info("== INFO Message ==");
log.warn("== WARN Message ==");
log.error("== ERROR Message ==");
log.fatal("== FATAL Message ==");
out.close();
}
}

8. The orion-application.xml must import the library name define in step 4. It looks like:

...
<imported-shared-libraries>
<import-shared-library name="log4j"></import-shared-library>
</imported-shared-libraries>
...

http://download-west.oracle.com/docs/cd/B32110_01/web.1013/b28957/deploysimple.htm#CHDIEFGE

9. Now, before deploying the application to oc4j, I need to uncheck the log4j library that we included in the JDev application during development. This is to ensure that when Jdev packages the application it does not for include the library in the package. From the deployment properties, uncheck this library.



10. Deploy the application and see the opmn container logs for the results.

Using admin_client.jar to deploy an application to oc4j

Posted by Steve Racanovic | Posted in , | Posted on 1:29 PM

0

An example of deploying an application to a single OC4J instance through the command line.

You can deploy an application using the admin_client.jar from the command line. Either locally or remotely. If you want to deploy from remotely, you will first need to download the Administration Client. Ensure you download the same client version as your OAS version.

10.1.3.0

http://download.oracle.com/otn/java/oc4j/1013/oc4j_admin_client_101300.zip

10.1.3.1

http://download.oracle.com/otn/java/oc4j/101310/oc4j_admin_client_101310.zip

10.1.3.2

http://download.oracle.com/otn/java/oc4j/101320/oc4j_admin_client_101320.zip

10.1.3.3 & 10.1.3.4

http://www.oracle.com/technology/software/products/ias/htdocs/utilsoft.html

In this example I will only deploy locally. Further details can be found here:
http://download-west.oracle.com/docs/cd/B32110_01/web.1013/b28951/adminclient.htm#BABFHIEB

1. Check the instance I want to deploy to is up and running.


[sracanov@sracanov-au D]$ opmnctl status

Processes in Instance: web.sracanov-au.au.oracle.com
---------------------------------+--------------------+---------+---------
ias-component | process-type | pid | status
---------------------------------+--------------------+---------+---------
OC4JGroup:default_group | OC4J:OC4J_Apps2 | 4296 | Alive
OC4JGroup:default_group | OC4J:home | 2308 | Alive
HTTP_Server | HTTP_Server | 2732 | Alive
ASG | ASG | N/A | Down

2. Find the opmn port.

[sracanov@sracanov-au D]$ opmnctl status -port
sracanov-au:6007

3. Go to the $OH/j2ee/home folder where admin_client.jar sits.

[sracanov@sracanov-au D]$ cd %ORACLE_HOME%\j2ee\home

[sracanov@sracanov-au D]$ pwd
D:\Oracle\product\10.1.3.2.0\OracleAS_1\j2ee\home

[sracanov@sracanov-au D]$ dir | grep admin_
11/01/2007 06:53 PM 733 admin_client.jar

4. Deploy the application to oc4j instance. In my example OC4J_Apps2. The command line should looks something like:

java -jar admin_client.jar deployer:oc4j:opmn://:/ -deploy -file C:\drvtest.ear -deploymentName drvtest -bindAllWebApps

[sracanov@sracanov-au D]$ echo %JAVA_HOME%
D:\Oracle\product\10.1.3.2.0\OracleAS_1\jdk

[sracanov@sracanov-au D]$ java -version
java version "1.5.0_06"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_06-b05)
Java HotSpot(TM) Client VM (build 1.5.0_06-b05, mixed mode)

[sracanov@sracanov-au D]$ java -jar admin_client.jar deployer:oc4j:opmn://localhost:6007/OC4J_Apps2
oc4jadmin welcome1 -deploy -file C:\drvtest.ear -deploymentName drvtest -bindAllWebApps
09/05/13 13:23:14 Notification ==>Application Deployer for drvtest STARTS.

09/05/13 13:23:14 Notification ==>Copy the archive to D:\Oracle\product\10.1.3.2.0
\OracleAS_1\j2ee\OC4J_Apps2\applications\drvtest.ear

09/05/13 13:23:14 Notification ==>Initialize D:\Oracle\product\10.1.3.2.0\OracleAS_1
\j2ee\OC4J_Apps2\applications\drvtest.ear begins...

09/05/13 13:23:14 Notification ==>Unpacking drvtest.ear

09/05/13 13:23:14 Notification ==>Done unpacking drvtest.ear

09/05/13 13:23:14 Notification ==>Unpacking drvtest.war

09/05/13 13:23:14 Notification ==>Done unpacking drvtest.war

09/05/13 13:23:14 Notification ==>Initialize D:\Oracle\product\10.1.3.2.0\OracleAS_1
\j2ee\OC4J_Apps2\applications\drvtest.ear ends...

09/05/13 13:23:14 Notification ==>Starting application : drvtest

09/05/13 13:23:14 Notification ==>Initializing ClassLoader(s)

09/05/13 13:23:14 Notification ==>Initializing EJB container

09/05/13 13:23:14 Notification ==>Loading connector(s)

09/05/13 13:23:14 Notification ==>Starting up resource adapters

09/05/13 13:23:14 Notification ==>Initializing EJB sessions

09/05/13 13:23:14 Notification ==>Committing ClassLoader(s)

09/05/13 13:23:14 Notification ==>Initialize drvtest begins...

09/05/13 13:23:14 Notification ==>Initialize drvtest ends...

09/05/13 13:23:14 Notification ==>Started application : drvtest

09/05/13 13:23:14 Notification ==>Binding web application(s) to site default-web-site begins...

09/05/13 13:23:14 Notification ==>Binding drvtest web-module for application drvtest
to site default-web-site under context root drvtest

09/05/13 13:23:17 Notification ==>Initializing Servlet:
org.apache.struts.action.ActionServlet for web application drvtest

09/05/13 13:23:17 Notification ==>Binding web application(s) to site
default-web-site ends...

09/05/13 13:23:17 Notification ==>Application Deployer for drvtest COMPLETES.
Operation time: 3328 msecs

5. Check the application is deployed and running:

[sracanov@sracanov-au D]$ opmnctl status -app

Applications in Instance: web.sracanov-au.au.oracle.com

application type: OC4J
-----+-----------+---------+---------+----------------+----------+--------
pid | name | state | rtid | classification | routable | parent
-----+-----------+---------+---------+----------------+----------+--------
4296 | drvtest | started | g_rt_id | external | true | default

4296 | system | started | g_rt_id | external | true |
4296 | default | started | g_rt_id | external | true | system
4296 | jamagent | started | g_rt_id | external | true | default
4296 | ascontrol | stopped | g_rt_id | external | false |
4296 | datatags | started | g_rt_id | internal | true | default
4296 | javasso | stopped | g_rt_id | internal | true |
2308 | system | started | g_rt_id | external | true |
2308 | default | started | g_rt_id | external | true | system
2308 | ascontrol | started | g_rt_id | external | true | system
2308 | datatags | started | g_rt_id | internal | true | default
2308 | javasso | stopped | g_rt_id | internal | true |

JDev11g Export Table To Excel

Posted by Steve Racanovic | Posted in | Posted on 9:11 AM

0

JDev 11g offers a simple way to export an ADF table to excel in a couple simple steps.

1. Create af:panelCollection on the jspx page.
2. Drag a data control onto af:panelCollection and drop it as table.
3. Set af:table id to table.
4. Expand Panel Collection facets, and drop af:toolbar on toolbar facet.
5. Drop af:commandButton on af:toolbar. Set the text to "Export To Excel"
6. Drop af:exportCollectionActionListener on af:commandButton. And set the following:

ExportId: table
Type: excelHTML
Filename: Emp.xls
Title: Employees.

The exportId needs to bind to the af:table id. Which we set as 'table' in step 3

7. Run the jspx page and test the export button.


This is how the my final code looks like:


<panelCollection>
<facet name="menus"/>
<facet name="toolbar">
<toolbar>
<commandButton text="Export To Excel">
<exportCollectionActionListener exportedId="table" type="excelHTML"
filename="Emp.xls" title="Employees"/>
</commandButton>
</toolbar>
</facet>
<facet name="statusbar"/>
<table value="#{bindings.EmpView1.collectionModel}" var="row"
rows="#{bindings.EmpView1.rangeSize}"
emptyText="#{bindings.EmpView1.viewable ? 'No rows yet.' : 'Access Denied.'}"
fetchSize="#{bindings.EmpView1.rangeSize}" filterVisible="false"
id="table">
<column sortProperty="Empno" sortable="false"
headerText="#{bindings.EmpView1.hints.Empno.label}"
filterable="false">
<outputText value="#{row.Empno}">
<convertNumber groupingUsed="false"
pattern="#{bindings.EmpView1.hints.Empno.format}"/>
</outputText>
</column>
...
...
...
</table>
</panelCollection>

Jdev 11g Web Service WSDL Parameter Name

Posted by Steve Racanovic | Posted in , | Posted on 11:01 AM

2


With Jdev 11g, after generating a Web Service from a java class, the WSDL contains the following
parameter names:

...
<xsd:complexType name="sayHello">
<xsd:sequence>
<xsd:element name="arg0" type="xsd:string"/>
<xsd:element name="arg1" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
...

My java code function looks like:
...
public String sayHello(String firstname, String lastname) {
return "Hello " + firstname + " " + lastname;
}
...

With Jdev 10g , the same code generates the appropriate values:
...
<xsd:complexType name="sayHello">
<xsd:sequence>
<xsd:element name="firstname" type="xsd:string"/>
<xsd:element name="lastname" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
...

To workaround this in 11g, I need to create my java class as follows:

package project1;

import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;

@WebService
public class Class1 {
@WebMethod
public String sayHello(@WebParam(name = "fname") String firstname,
@WebParam(name = "lname") String lastname) {
return "Hello " + firstname + " " + lastname;
}
}

And now my generated WSDL looks like:
...
<xsd:complexType name="sayHello">
<xsd:sequence>
<xsd:element name="fname" type="xsd:string"/>
<xsd:element name="lname" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
...

http://java.sun.com/javaee/5/docs/api/javax/jws/WebParam.html

ORA-29532: HTTP transport error: java.security.PrivilegedActionException: javax.xml.soap.SOAPException: Message send fail

Posted by Steve Racanovic | Posted in , | Posted on 1:57 PM

1

After running jpub using the 'get joke' web service and then calling the web service in sqlplus, I get the following error:


[sracanov@sracanov-au D]$ jpub -user=scott/tiger -sysuser=sys/welcome1
-proxywsdl=getjoke.asmx.xml
-endpoint=http://interpressfact.net/webservices/getjoke.asmx
tmp\src\genproxy\GetJokeSoapClientJPub.java
plsql_wrapper.sql
plsql_dropper.sql
plsql_grant.sql
plsql_revoke.sql
Executing plsql_dropper.sql
Executing plsql_wrapper.sql
Executing plsql_grant.sql
Loading plsql_proxy.jar

[sracanov@sracanov-au D]$ sqlplus scott/tiger
Logging into sqlplus - scott @orcl

SQL*Plus: Release 10.2.0.3.0 - Production on Wed Feb 25 14:06:32 2009

Copyright (c) 1982, 2006, Oracle. All Rights Reserved.

Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - Production
With the Partitioning, OLAP and Data Mining options

scott@orcl> select jpub_plsql_wrapper.getjoke('') from dual;
select jpub_plsql_wrapper.getjoke('') from dual
*
ERROR at line 1:
ORA-29532: Java call terminated by uncaught Java exception:
java.rmi.RemoteException: java.rmi.RemoteException:; nested exception is:
HTTP transport error: javax.xml.soap.SOAPException:
java.security.PrivilegedActionException: javax.xml.soap.SOAPException: Message
send failed: Connection refused

This error is occurring due to the proxy. So I need to execute setHttpProxy(host VARCHAR2, port NUMBER) to avoid this.

scott@orcl> call jpub_plsql_wrapper.setHttpProxy('www-proxy',8080);

Call completed.

scott@orcl> select jpub_plsql_wrapper.getjoke('') from dual;

JPUB_PLSQL_WRAPPER.GETJOKE('')
--------------------------------------------------------------------------------
Murphy's Military Laws:15.
Don't be conspicuous. In the combat zone, it draws fire. Out of the combat zone,
it draws sergeants.

To completely avoid this error, set jpub to call the WSDL directly rather than a local file and set the http proxy for jpub.

[sracanov@sracanov-au D]$ jpub -user=scott/tiger -sysuser=sys/welcome1
-proxywsdl=http://interpressfact.net/webservices/getjoke.asmx?WSDL
-endpoint=http://interpressfact.net/webservices/getjoke.asmx
-httpproxy=www-proxy:8080
tmp\src\genproxy\GetJokeSoapClientJPub.java
plsql_wrapper.sql
plsql_dropper.sql
plsql_grant.sql
plsql_revoke.sql
Executing plsql_dropper.sql
Executing plsql_wrapper.sql
Executing plsql_grant.sql
Loading plsql_proxy.jar

[sracanov@sracanov-au D]$ sqlplus scott/tiger
Logging into sqlplus - scott @orcl

SQL*Plus: Release 10.2.0.3.0 - Production on Wed Feb 25 14:02:50 2009

Copyright (c) 1982, 2006, Oracle. All Rights Reserved.

Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - Production
With the Partitioning, OLAP and Data Mining options

scott@orcl> select jpub_plsql_wrapper.getjoke('') from dual;

JPUB_PLSQL_WRAPPER.GETJOKE('')
--------------------------------------------------------------------------------
Q: How many `Real Men' does it take to change a light bulb?
A: None: `Real Men' aren't afraid of the dark.

java.sql.SQLException: Io exception: The Network Adapter

Posted by Steve Racanovic | Posted in | Posted on 11:50 AM

1

When using JDBC 10.2.0.3 to connect from java standalone client to the database I get the following error:

D:\Oracle\jdev\10134-prod\jdk\bin\javaw.exe -client -classpath "D:\Oracle\jdev\10134-prod\jdev\mywork\MyApplications\JDBC-SSL2\classes;D:\My Contents\My Software\Oracle\JDBC Drivers\10.2.0.3\ojdbc14_g.jar;D:\Oracle\jdev\10134-prod\jlib\oraclepki.jar" jdbcssl2.SSLEncryptionAuthenication
Exception in thread "main" java.sql.SQLException: Io exception: The Network Adapter could not establish the connection
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:145)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:190)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:363)
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:401)
at oracle.jdbc.driver.PhysicalConnection.(PhysicalConnection.java:466)
at oracle.jdbc.driver.T4CConnection.(T4CConnection.java:165)
at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:35)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:839)
at java.sql.DriverManager.getConnection(DriverManager.java:525)
at java.sql.DriverManager.getConnection(DriverManager.java:140)
at jdbcssl2.SSLEncryptionAuthenication.getConnection(SSLEncryptionAuthenication.java:57)
at jdbcssl2.SSLEncryptionAuthenication.run(SSLEncryptionAuthenication.java:39)
at jdbcssl2.SSLEncryptionAuthenication.main(SSLEncryptionAuthenication.java:62)
Process exited with exit code 1.

The "java.sql.SQLException: Io exception: The Network Adapter could not establish the connection" is very generic and can mean a number of different issue. Also the stack error is not very detailed.

Try using JDBC 11.1.0.7 and enable "-Djavax.net.debug=ssl" java property when you run your client to allow for a detailed stack error to help you find the problem.

Using jpub to create webserivce proxy for callouts.

Posted by Steve Racanovic | Posted in , | Posted on 11:58 AM

2

Im my preivous blog I created a simple webservice and used plsql to call the webservice from the database. Here I will use jpub to generate my java proxy and use that to call my webservice without the need to code any plsql. Note all of these steps are done upon the previous blog beginning completed.

1. Download and unzip jpub. You can get it from http://www.oracle.com/technology/software/tech/java/sqlj_jdbc/index.html
Im using JPublisher 10g Release 10.2


C:\Documents and Settings\stever\Desktop> set_database.bat
C:\Documents and Settings\stever\Desktop> oracle_home
D:\Oracle\product\10.2.0\db_1
C:\Documents and Settings\stever\Desktop> unzip jpub_102.zip -d %oracle_home%
Archive: jpub_102.zip
inflating: D:/Oracle/product/10.2.0/db_1/sqlj/lib/sqljutl.sql
inflating: D:/Oracle/product/10.2.0/db_1/sqlj/lib/translator.jar
...


2. Set the classpath and run jpub.


C:\Documents and Settings\stever\Desktop>cdo

D:\Oracle\product\10.2.0\db_1

D:\Oracle\product\10.2.0\db_1>cd sqlj\bin

D:\Oracle\product\10.2.0\db_1\sqlj\bin>ll
Volume in drive D is ACERDATA
Volume Serial Number is 4059-B823

Directory of D:\Oracle\product\10.2.0\db_1\sqlj\bin

07/21/2005 03:34 AM <DIR> .
07/21/2005 03:34 AM <DIR> ..
07/21/2005 03:34 AM 1,376 jpub
07/21/2005 03:34 AM 2,834 jpub.c
07/21/2005 03:34 AM 50,619 jpub.exe
07/21/2005 03:34 AM 267 README.txt
4 File(s) 55,096 bytes
2 Dir(s) 8,243,344,384 bytes free

D:\Oracle\product\10.2.0\db_1\sqlj\bin> cd ..
D:\Oracle\product\10.2.0\db_1\sqlj>java_home
D:\Oracle\product\10.2.0\db_1\jdk

D:\Oracle\product\10.2.0\db_1\sqlj>classpath
.;D:\Oracle\product\10.2.0\db_1\sqlj\lib\translator.jar;
D:\Oracle\product\10.2.0\db_1\sqlj\lib\runtime12.jar;
D:\Oracle\product\10.2.0\db_1\sqlj\lib\dbwsa.jar;D:\Oracle\product\10.2
.0\db_1\javavm\lib\aurora.zip;
D:\Oracle\product\10.2.0\db_1\jdbc\lib\ojdbc14.jar;

D:\Oracle\product\10.2.0\db_1\sqlj>jpub -u wsuser/wsuser -sysuser sys/welcome1
-proxywsdl=http://stever-5670:8988/DatabaseWSDemo-WS-context-root/MyWebService1SoapHttpPort?WSDL
-endpoint=http://stever-5670:8988/DatabaseWSDemo-WS-context-root/MyWebService1SoapHttpPort
tmp\src\genproxy\MyWebService1SoapHttpPortClientJPub.java
plsql_wrapper.sql
plsql_dropper.sql
plsql_grant.sql
plsql_revoke.sql
Executing plsql_dropper.sql
Executing plsql_wrapper.sql
Executing plsql_grant.sql
Loading plsql_proxy.jar


3. Call the webservice.


D:\Oracle\product\10.2.0\db_1\sqlj>sqlplus wsuser/wsuser

SQL*Plus: Release 10.2.0.3.0 - Production on Mon Nov 10 19:36:58 2008

Copyright (c) 1982, 2006, Oracle. All Rights Reserved.

Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - Production
With the Partitioning, OLAP and Data Mining options

SQL> select jpub_plsql_wrapper.sayhelloworld from dual;

SAYHELLOWORLD
--------------------------------------------------------------------------------
Hello World

SQL> select jpub_plsql_wrapper.sayhelloname('Steve') from dual;

JPUB_PLSQL_WRAPPER.SAYHELLONAME('STEVE')
--------------------------------------------------------------------------------
Hello Steve

SQL>

NOTE: My set_database.bat file simply has my environment settings in there.
This is where I set the classpath. It looks like:

set ORACLE_HOME=D:\Oracle\product\10.2.0\db_1
set ORACLE_SID=ORCL
set JAVA_HOME=%ORACLE_HOME%\jdk
set PATH=%ORACLE_HOME%\bin;%TT_HOME%\bin;%JAVA_HOME%\bin;%ORACLE_HOME%\sqlj\bin;%PATH%
set TNS_ADMIN=D:\Oracle\product\10.2.0\db_1\NETWORK\ADMIN
set CLASSPATH=.;%ORACLE_HOME%\sqlj\lib\translator.jar;
%ORACLE_HOME%\sqlj\lib\runtime12.jar;%ORACLE_HOME%\sqlj\lib\dbwsa.jar;
%ORACLE_HOME%\javavm\lib\aurora.zip;%ORACLE_HOME%\jdbc\lib\ojdbc14.jar;