Tuesday, October 26, 2010

invalid element "{http://schemas.xmlsoap.org/wsdl/}definitions" in configuration file (line 2)



Problem:
This is one of the Common Exceptions which we come across daily in our lives. When i was trying to run wscompile command to generate java client classes from a WSDL file.

Exception i encountered was:
"invalid element "{http://schemas.xmlsoap.org/wsdl/}definitions" in configuration file (line 2)"

Solution:
The real culprit for this exception was config.xml file. I just copy pasted the complete WSDL file into the config.xml file instead of just refering WSDL file.

For example:
Syntax for Config.xml file:

*******************************************************************************************************************************************************************

The wscompile command reads the config.xml file, which has the information about web service. This is how config.xml file looks:

<?xml version="1.0" encoding="UTF-8"?>
<configuration
xmlns="http://java.sun.com/xml/ns/jax-rpc/ri/config">
<service> or <wsdl> or <modelfile>
</configuration>
The <configuration> element may contain exactly one <service>, <wsdl>, or <modelfile> element.

The <service> Element

If you specify this element, wscompile reads the service endpoint interface that describes the service and generates a WSDL file. In the <interface> subelement, the name attribute specifies the service endpoint interface, and the servantName attribute specifies the class that implements the interface. For example:

<service name="CollectionIF_Service"
targetNamespace="http://echoservice.org/wsdl"
typeNamespace="http://echoservice.org/types"
packageName="stub_tie_generator_test">
<interface name="stub_tie_generator_test.CollectionIF"
servantName="stub_tie_generator_test.CollectionImpl"/>
</service>
The <wsdl> Element

If you specify this element, wscompile reads the service's WSDL file and generates the service endpoint interface. The location attribute specifies the URL of the WSDL file, and the packageName attribute specifies the package of the classes generated by wscompile. For example:

<wsdl
location="http://tempuri.org/sample.wsdl"
packageName="org.tempuri.sample" />

The <modelfile> Element

This element is for advanced users.

If config.xml contains a <service> or <wsdl> element, wscompile generates a model file that contains the internal data structures that describe the service. If you've already generated a model file in this manner, then you can reuse it the next time you run wscompile. For example:

<modelfile location="mymodel.xml.gz"/>

*******************************************************************************************************************************************************************

Command:
java com.sun.xml.rpc.tools.wscompile.Main -gen:client -d <<Give the destination folder>> <<config.xml>> C:\Rahamat\Axis\wscompile\config.xml

Similar Exceptions:
     - Exception Occured invalid element "{http://schemas.xmlsoap.org/wsdl/}definitions" in configuration file (line 2)

Wednesday, May 5, 2010

java.sql.SQLException: Invalid Oracle URL specified: OracleDataSource.makeURL



Problem :
We come across this exception when DB connection is involved. This is the issue when we migrate DB from Oracle 9i to 10g.

Exception I Encountered Was :

============================================================================================
<May 5, 2010 9:43:16 AM GMT> <Notice> <StdErr> <BEA-000000> <java.sql.SQLException: Invalid Oracle URL specified: OracleDataSource.makeURL>
<May 5, 2010 9:43:16 AM GMT> <Notice> <StdErr> <BEA-000000> <at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)>
<May 5, 2010 9:43:16 AM GMT> <Notice> <StdErr> <BEA-000000> <at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:146)>
<May 5, 2010 9:43:16 AM GMT> <Notice> <StdErr> <BEA-000000> <at oracle.jdbc.pool.OracleDataSource.makeURL(OracleDataSource.java:1353)>
<May 5, 2010 9:43:16 AM GMT> <Notice> <StdErr> <BEA-000000> <at oracle.jdbc.pool.OracleDataSource.getConnection(OracleDataSource.java:195)>
<May 5, 2010 9:43:16 AM GMT> <Notice> <StdErr> <BEA-000000> <at oracle.jdbc.pool.OracleDataSource.getConnection(OracleDataSource.java:165)>
<May 5, 2010 9:43:16 AM GMT> <Notice> <StdErr> <BEA-000000> <at com.hp.smartquote.standalone.SQStandaloneConnectionFactory.getConnection(SQStandaloneConnectionFactory.java:54)>
<May 5, 2010 9:43:16 AM GMT> <Notice> <StdErr> <BEA-000000> <at com.hp.smartquote.standalone.SQStandaloneUtil.getConnection(SQStandaloneUtil.java:155)>
<May 5, 2010 9:43:16 AM GMT> <Notice> <StdErr> <BEA-000000> <at com.hp.smartquote.standalone.SQStandaloneUtil.getUserRecord(SQStandaloneUtil.java:88)>
============================================================================================

Solution:

In my code after setting all the default connection properties i was setting caching properties. This was causing the exception. When i deleted this part from code it started working fine. Hope it works for you too. For detailed explanation see the example too.

Example:
My Java file for connection was SQStandaloneConnectionFactory.java.
In this file i was setting the cache properties as:
===================================================================
dataSource.setConnectionCachingEnabled(true);
Properties cacheProps = new Properties();
cacheProps.setProperty("MinLimit", "1");
cacheProps.setProperty("MaxLimit", "6");
cacheProps.setProperty("InitialLimit", "1");
cacheProps.setProperty("ConnectionWaitTimeout", "6");
cacheProps.setProperty("ValidateConnection", "true");
dataSource.setConnectionCacheProperties(cacheProps);
====================================================================
I Just removed this properties from my code and it started working fine.

Similar Exception:
- Invalid Oracle URL specified error during startup
- ORA-17067: Invalid Oracle URL specified

Wednesday, June 24, 2009

HTTP Error 404 - File or directory not found. Internet Information Services (IIS)

HTTP Error 404 - File or directory not found. Internet Information Services (IIS)

Problem :


We come across this common exception when we try to open a file in IIS 6.0 or later web server for which MIME TYPE is not defined for the file extension.

Exception I Encountered Was :


#########################################################################################
HTTP Error 404 – File or Directory not found
#########################################################################################

Solution :



Define a wildcard "MIME Type" within the roaming user profile directory of the IIS server. Steps to define the wildcard "MIME Type" :
  • Click "Start > Control Panel > Administrative Tools".
  • Double-click on "Internet Information Services (IIS) Manager".
  • Right-click on the roaming user profile directory that has been created.
  • Select "Properties".
  • Select the "HTTP Headers" tab.
  • Click the "MIME Types" button.
  • Click the "New" button.
  • Type "*" in the "Extension" field:
  • Type "application/octet-stream" in the "MIME type" field:
  • Click "OK" to apply the new MIME type.
  • Click "OK" again to apply the new settings.
Note:
  • In the example above, IIS now serves files of all file extensions.
  • In order for the changes to take effect, the "World Wide Web Publishing Service" must be restarted, or just wait for the worker process to recycle.
  • This information can also be referenced within the "Dragon NaturallySpeaking IT Administrators Guide" under "HTTP Roaming Settings".



Similar Exception :

     
- HTTP Error 404 - File or directory not found. Internet Information Services (IIS)

Sunday, May 24, 2009

org.xml.sax.SAXException: Invalid element in

org.xml.sax.SAXException: Invalid element in

Problem :


We come across this common exception when the values in classes generated by the wsdl's are not matching with what the values of web service returns.

Exception I Encountered Was :


#########################################################################################

org.xml.sax.SAXException: Invalid element in org.tempuri.esws.Event -  BMSL_KOL
at org.apache.axis.encoding.ser.BeanDeserializer.onStartChild(BeanDeserializer.java:296)
AxisFault
faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Server.userException
faultSubcode: 
faultString: org.xml.sax.SAXException: Invalid element in org.tempuri.esws.Event -  BMSL_KOL
faultActor: 
faultNode: 
faultDetail: 
{http://xml.apache.org/axis/}stackTrace: org.xml.sax.SAXException: Invalid element in org.tempuri.esws.Event -  BMSL_KOL
at org.apache.axis.encoding.ser.BeanDeserializer.onStartChild(BeanDeserializer.jav a:296)
at org.apache.axis.encoding.DeserializationContextImpl.startElement(Deserializatio nContextImpl.java:845)
at org.apache.axis.message.SAX2EventRecorder.replay(SAX2EventRecorder.java:232)
at org.apache.axis.message.MessageElement.publishToHandler(MessageElement.java:354 )
at org.apache.axis.message.RPCElement.deserialize(RPCElement.java:834)
at org.apache.axis.message.RPCElement.getParams(RPCElement.java:526)
at org.apache.axis.client.Call.invoke(Call.java:3856)
at org.apache.axis.client.Call.invoke(Call.java:9238)
at org.apache.axis.client.Call.invoke(Call.java:3245)
at org.tempuri.esws.ServiceSoapStub.fetchEvents(ServiceSoapStub.java:522)
#########################################################################################

Solution :


This exception was caused when the values in classes generated by the wsdl's are not matching with what the values of web service returns. Please look the solution as explained below.



Example :


- Solution 1 : 

WSDL generated file for the WS (Web service) request object, i.e Event, there is an attribute typeDesc and a static body following initialising typeDesc.

For each element added to typeDesc, you will see the following similar code :
elemField.setFieldName("eventFormID");
elemField.setXmlName(new javax.xml.namespace.QName("", "EventFormID"));

make sure the string literals are of the same case, as above they should be "EventFormID"

- Solution 2 :

Say our code is something like this:

elementField = new org.apache.axis.description.ElementDesc();
elementField.setFieldName("bMSL_LOK");
elementField.setXmlName(new javax.xml.namespace.QName("urn:/crmondemand/xml/contact", "bMSL_LOK"));
elementField.setXmlType(new javax.xml.namespace.QName("http://www.w3.org/2001/XMLSchema", "string"));
elementField.setMinOccurs(0);
elementField.setNillable(false);
typeDesc.addFieldDesc(elemmentField);

And this is the response coming in:-

<Event object="Contact" name="someName" operation="update">
     <SiebelMessage>
          <ListOfContact xmlns="urn:/crmondemand/xml/contact">
               <Contact>
                    <ContactFirstName>someFirstName</ContactFirstName>
                    <ContactId>someContactId</ContactId>
                    <ContactLastName>someLastName</ContactLastName>
                    <AlternateAddressId>someAddress</AlternateAddressId>
                    <ExternalSystemId/>
                    <IntegrationId>someIntegrationId</IntegrationId>
                    <bMSL_LOK></bMSL_LOK>
                    <ModId>someModId</ModId>
                    <CreatedDate>someCreatedDate</CreatedDate>
                    <ModifiedById>someModifiedById</ModifiedById>
                    <ModifiedDate>someModifiedDate</Mo difiedDate>
                    <CreatedById>someCreatedById</CreatedById>
               </Contact>
          </ListOfContact>
     </SiebelMessage>
</Event>


What really happens in that page is:-
The field name coming in is bMSL_LOK and NOT BMSL_LOK.
Note the case of the first-letter. And what happens next is the word "set" is appended to this and the corresponding setter called ! So when we create setters for bMSL_LOK, this is what we have in the pojo:

public String getBMSL_LOK() {
return bMSL_LOK;
}

public void setBMSL_LOK(String bmsl_lok) {
bMSL_LOK = bmsl_lok;
}
Change this to :-
public String getbMSL_LOK() {
return bMSL_LOK;
}

public void setbMSL_KOL(String bmsl_kol) {
bMSL_KOL = bmsl_kol;
}




Similar Exception :

     

- org.xml.sax.SAXException: Invalid element in



Thursday, May 21, 2009

java.sql.DataTruncation: Data truncation



Problem :
We come across this common exception when we are using Database. While we are inserting or updating a table field with data which is longer than the actual data which the field can hold.

Exception I Encountered Was :
#########################################################################################
java.sql.DataTruncation: Data truncation
at net.sourceforge.jtds.jdbc.SQLDiagnostic.addDiagnostic(SQLDiagnostic.java:382)
at net.sourceforge.jtds.jdbc.TdsCore.tdsErrorToken(TdsCore.java:2816)
at net.sourceforge.jtds.jdbc.TdsCore.nextToken(TdsCore.java:2254)
at net.sourceforge.jtds.jdbc.TdsCore.getMoreResults(TdsCore.java:631)
at net.sourceforge.jtds.jdbc.JtdsStatement.processResults(JtdsStatement.java:584)
at net.sourceforge.jtds.jdbc.JtdsStatement.executeSQL(JtdsStatement.java:546)
at net.sourceforge.jtds.jdbc.JtdsPreparedStatement.executeUpdate(JtdsPreparedStatement.java:505)
at CSV2DBadaptor.readExcel(CSV2DBadaptor.java:176)
at CSV2DBadaptor.main(CSV2DBadaptor.java:325)
#########################################################################################

Solution :
As said above in Problem section we face this common exception when we are inserting data which exceeds the table field size. We need to log the actual field name and then compare the data size with the field size. If the data size is more than the table field size then you can either truncate the data of the field to fit into the table field or increase the table field size to accomodate the data. Think appropriately before designing your solution.

Example :
Say i am using:
DB : TestLibrary (MySql DB)
Table Name: TestTable
Field Name: Object_id (Size varchar(20))
Actual Data: "5983-0020NOE5983-0020ITE"

In my case the data was important so i coud'nt truncate the data, instead i increased the Field size to varchar(30) and was able to resolve the issue.

Similar Exception :
     - java.sql.BatchUpdateException: Data truncation
- java.sql.SQLException: Data truncation

Friday, May 15, 2009

Exception Occured :java.io.IOException: Invalid header signature; read ..... , expected ...............



Problem:
This is one of the Common Exceptions which we come across daily in our lives. When i was trying to read a csv (Excel) file in my java code i was not able to read the file. My task was to read the csv file and upate database.

Exception i encountered was:
"Exception Occured :java.io.IOException: Invalid header signature; read 0x6E5F7463656A626F, expected 0xE11AB1A1E011CFD0"

Solution:
If we are using MS Office 2003 we generally face this issue. If we are trying to open a file that contains more than 65,536 rows or 256 columns. To fix this problem, open the source file in a text editor such as Microsoft Word. Save the source file as several smaller files that conform to this row and column limit, and then open the smaller files in Excel.

For example:
We are using MS office 2003 and trying to read a file called testing.csv through java code. Our testing.csv file has 75,000 rows. Since it is crossing 65,536 rows we were facing this issue. so what we can do is create two new csv files with names as testing1.csv file and other as testing2.csv file. Copy first 37,500 rows of testing.csv file and paste them in testing1.csv file and now copy remaining 37,500 rows from testing.csv file and paste them in testing2.csv. Now try to read testing1.csv and testing2.csv file separately in your java code. This process should resolve the exception.

Similar Exceptions:
     - Exception Occured :org.apache.poi.hssf.record.RecordFormatException: Unable to construct record instance