May 11, 2012

Failed to read wsdl file from url

javax.xml.ws.WebServiceException: weblogic.wsee.wsdl.WsdlException: Failed to read wsdl file from url due to -- java.net.ConnectException: Tried all: '1' addresses, but could not connect over HTTP to server: 'sinuxu31', port: '7909'


When the above error occurs, you must check the following.


1) Check that you can view the wsdl URL using a browser
  • If the WSDL URL is not accessible then the server hosting the web service is unavailable. 
  • Check if you are blocked by any firewall rules.
  • You can use the following command in UNIX to get the wsdl file
    • wget -O google-wget.txt http://www.google.com 
    • cat google-wget.txt
 2) If the WSDL URL is accessible via Browser then check the connectivity to the external server from the server where Web service client is hosted.
  • Try ping the external server to check whether able to reach the server in the network
    • ping <external_server_host_name></external_server_host_name>
  • If the ping is not working, check that hosting server is on the network
  • Check if there is any firewall rule set to blocking the network traffic from the calling server
  • Telnet to the external server to check whether the Connection to the server is established properly
    • telnet <external_server_host_name> <port_number></port_number></external_server_host_name>
  • If telnet fails, check whether the port is opened from the calling server to get a connection to the external server
  • Do  a nslookup for the external server to check whether the DNS server name mappings
    • nslookup 
    • > <external_server_host_name>
  • If the nslookup fails, check the DNS server name mappings are done properly.

JMS Message Destination Error

In this example i am trying to create a Point to Point messaging service. i am using JEE 5 and Glassfish. I encountered the following error message when using annotations.

SEVERE: NAM0007 : Message Destination Reference java:comp/env/jms/p2pQueue has not been linked to a Message Destination
15-Sep-2009 17:02:38 com.sun.enterprise.appclient.MainWithModuleSupport
WARNING: ACC003: Application threw an exception.
javax.naming.NamingException: Message Destination Reference java:comp/env/jms/p2pQueue has not been resolved
at com.sun.enterprise.naming.NamingManagerImpl.bindObjects(NamingManagerImpl.java:521)
at com.sun.enterprise.appclient.AppContainer.preInvoke(AppContainer.java:137)
at com.sun.enterprise.appclient.MainWithModuleSupport.(MainWithModuleSupport.java:383)
at com.sun.enterprise.appclient.MainWithModuleSupport.(MainWithModuleSupport.java:259)
at com.sun.enterprise.appclient.Main.main(Main.java:200)



This is caused by the following incorrect @Resource references.

@Resource(name = "jms/p2pQueue")
private static Queue p2pQueue;
@Resource(name = "jms/QueueConnectionFactory")
private static ConnectionFactory p2pQueueFactory;


The correct annotation should be

@Resource(mappedName = "jms/p2pQueue")
private static Queue p2pQueue;
@Resource(
mappedName = "jms/QueueConnectionFactory")
private static ConnectionFactory p2pQueueFactory;




February 8, 2010

Using Log4j and Streaming the Logs as per instance/file

The following setup can be used to generate a simple logging mechanism which will log the information on a per instance per file basis.

A simple log4j.properties file setup.

 
#### Use two appenders, one instance logs to X another to Y
log4j.logger.X=debug, X
log4j.logger.Y=debug, Y

log4j.appender.X.layout=org.apache.log4j.SimpleLayout
log4j.appender.X=org.apache.log4j.FileAppender
log4j.appender.X.File=exampleX.log

log4j.appender.Y.layout=org.apache.log4j.SimpleLayout
log4j.appender.Y=org.apache.log4j.FileAppender
log4j.appender.Y.File=exampleY.log

A Java code that decides which logger to use.

import java.math.BigDecimal;
import java.text.DecimalFormat;

public class FormatNumber
{    public static void main (String args[])
    {
        BigDecimal b = new BigDecimal("-1232323222.1049");
        BigDecimal c = b.setScale(4,BigDecimal.ROUND_HALF_DOWN);

        DecimalFormat format = new DecimalFormat("#,##0.00");
        String o = format.format(c);

        BigDecimalRounder g = new BigDecimalRounder("-1232323222.1049","Y");
        c = g.roundUpToScale(2, BigDecimal.ROUND_HALF_UP);
    }
}

import java.math.BigDecimal;
import java.util.Enumeration;
import org.apache.log4j.Appender;
import org.apache.log4j.Logger;

public class BigDecimalRounder extends BigDecimal
{
    private Logger log = null;
    public BigDecimalRounder(String decimal, String name)
    {
        super(decimal);
        log = Logger.getLogger(name);
    }

    public BigDecimal roundUpToScale(int scale, int roundingMode)
    {
        BigDecimal returnDecimal = null;
        if (super.scale() >= scale)
        {
            int j = super.scale();
            while (j >= scale)
            {
                returnDecimal = super.setScale(j, roundingMode);
                log.debug("log to file: " + returnDecimal.toString());
                j--;
            }
        }
        return returnDecimal;
    }
}



June 24, 2009

Temporary Tablespaces

What are Temporary Tablespaces: (reference: http://www.orafaq.com/node/2)

Temporary tablespaces are used to manage space for database sort operations and for storing global temporary tables. For example, if you join two large tables, and Oracle cannot do the sort in memory (see SORT_AREA_SIZE initialisation parameter), space will be allocated in a temporary tablespace for doing the sort operation. Other SQL operations that might require disk sorting are: CREATE INDEX, ANALYZE, Select DISTINCT, ORDER BY, GROUP BY, UNION, INTERSECT, MINUS, Sort-Merge joins, etc.

The DBA should assign a temporary tablespace to each user in the database to prevent them from allocating sort space in the SYSTEM tablespace. This can be done with one of the following commands:

SQL> CREATE USER scott DEFAULT TABLESPACE data TEMPORARY TABLESPACE temp;
SQL> ALTER USER scott TEMPORARY TABLESPACE temp;

Note that a temporary tablespace cannot contain permanent objects and therefore doesn't need to be backed up.

What are TEMPFILES?

Unlike normal data files, TEMPFILEs are not fully initialised (sparse). When you create a TEMPFILE, Oracle only writes to the header and last block of the file. This is why it is much quicker to create a TEMPFILE than to create a normal database file.

TEMPFILEs are not recorded in the database's control file. This implies that one can just recreate them whenever you restore the database, or after deleting them by accident. This opens interesting possibilities like having different TEMPFILE configurations between permanent and standby databases, or configure TEMPFILEs to be local instead of shared in a RAC environment.

One cannot remove datafiles from a tablespace until you drop the entire tablespace. However, one can remove a TEMPFILE from a database. Look at his example:

SQL> ALTER DATABASE TEMPFILE '/oradata/temp02.dbf' DROP INCLUDING DATAFILES;

If you remove all tempfiles from a temporary tablespace, you may encounter error: ORA-25153: Temporary Tablespace is Empty. Use the following statement to add a TEMPFILE to a temporary tablespace:

SQL> ALTER TABLESPACE temp ADD TEMPFILE '/oradata/temp03.dbf' SIZE 100M;

Except for adding a tempfile, as illustrated in the above example, you cannot use the ALTER TABLESPACE statement for a locally managed temporary tablespace (operations like rename, set to read only, recover, etc. will fail).

How does one create Temporary Tablespaces?

Oracle provides various ways of creating TEMPORARY tablespaces (mainly to provide backward compatibility). One should use the most recent method available:

- Prior to Oracle 7.3 - CREATE TABLESPACE temp DATAFILE ...;
- Oracle 7.3 & 8.0 - CREATE TABLESPACE temp DATAFILE ... TEMPORARY;
- Oracle 8i and above - CREATE TEMPORARY TABLESPACE temp TEMPFILE ...;

Oracle 8i and 9i example:

SQL> CREATE TEMPORARY TABLESPACE temp
TEMPFILE '/oradata/mytemp_01.tmp' SIZE 20M
EXTENT MANAGEMENT LOCAL UNIFORM SIZE 16M;

For best performance, the UNIFORM SIZE must be a multiple of the SORT_AREA_SIZE parameter.

Oracle 9i example using OMF (Oracle Managed Files):

SQL> CREATE TEMPORARY TABLESPACE temp;

Default Temporary Tablespaces:

In Oracle 9i and above, one can define a Default Temporary Tablespace at database creation time, or by issuing an "ALTER DATABASE" statement:

ALTER DATABASE DEFAULT TEMPORARY TABLESPACE temp;

The default Default Temporary Tablespace is SYSTEM. Each database can be assigned one and only one Default Temporary Tablespace. Using this feature, a Temporary Tablespace is automatically assigned to users. The following restrictions apply to default temporary tablespaces:

- The Default Temporary Tablespace must be of type TEMPORARY
- The DEFAULT TEMPORARY TABLESPACE cannot be taken off-line
- The DEFAULT TEMPORARY TABLESPACE cannot be dropped until you create another one.

To see the default temporary tablespace for a database, execute the following query:

SQL> SELECT * FROM DATABASE_PROPERTIES where PROPERTY_NAME='DEFAULT_TEMP_TABLESPACE';

All new users that are not explicitly assigned a TEMPORARY TABLESPACE, will get the Default Temporary Tablespace as its TEMPORARY TABLESPACE. Also, when you assign a TEMPORARY tablespace to a user, Oracle will not change this value next time you change the Default Temporary Tablespace for the database.

Other Considerations:

Some performance considerations for temporary tablespaces:

- Always use temporary tablespaces instead of permanent content tablespaces for sorting (no logging and uses one large sort segment to reduce recursive SQL and ST space management enqueue contention).
- Ensure that you create your temporary tablespaces as locally managed instead of dictionary managed (Use sort space bitmap instead of sys.fet$ and sys.uet$ for allocating space).
- Always use TEMPFILEs instead of DATAFILEs (reduce backup and recovery time + other advantages as described above)
- Stripe your temporary tablespaces over multiple disks to alleviate possible disk contention and to speed-up sorting operations (user processes can read/write to it directly).

Monitoring Temporary Tablespaces and Sorting:

Unlike datafiles, tempfiles are not listed in V$DATAFILE and DBA_DATA_FILES. Use V$TEMPFILE and DBA_TEMP_FILES instead.

One can monitor temporary segments from V$SORT_SEGMENT and V$SORT_USAGE

DBA_FREE_SPACE does not record free space for temporary tablespaces. Use V$TEMP_SPACE_HEADER instead:

SQL> select TABLESPACE_NAME, BYTES_USED, BYTES_FREE from V$TEMP_SPACE_HEADER;

TABLESPACE_NAME BYTES_USED BYTES_FREE
------------------------------ ---------- ----------
TEMP 52428800 52428800

SQL> select sum(free_blocks) from V$SORT_SEGMENT where tablespace_name = 'TEMP';
SQL> select inst_id, tablespace_name, total_blocks, used_blocks, free_blocks
from gv$sort_segment;

June 12, 2009

Good Design Thoughts


1. Encapsulate what varies --> identify the sections that vary and separate them from what stays the same
2. Favour composition over inheritance --> use "has-a" it is better than "is-a"
3. program to interface not implementations
4. Strive for loosely coupled designs between objects that interact (think mediator/observer)
5. Classes should be open for extension but closed for modification (think decorator pattern wrap around to extend)
6. Depend on abstracts not on concrete classes (an example would be factory method)
7. only talk to your friends (avoid having large number of classes coupled together)
8. dont call us, we will call you (template method - let superclass re-direct to subclasses)
9. A class should have only 1 reason to change

Inheritance vs Aggregation vs Composition


Inheritance - "Is A" Strongest Relationship

We depend on the functionalities of a Super Class

Aggregation - "Has A / Is Part Of" - Weaker Relationship

As shown in the example Aggregation occurs when the part of outlives the whole. e.g the listener instance could be alive even after WebServer instance is garbage collected


Aggregation Example ("has a"):



Composition - "Uses A" - Stronger Relationship

In a composition relationship the listener instance lifespan lasts till the WebServer instance is garbage collected.


Composition Example ("uses a"):







WSDL Styles Samples

==============================================
RPC LITERAL
==============================================








==============================================
RPC ENCODED
==============================================









==============================================
DOCUMENT LITERAL
==============================================