This week's giveaway is in the JDBC forum.
We're giving away four copies of Java Database Connections & Transactions (e-book only) and have Marco Behler on-line!
See this thread for details.
Win a copy of Java Database Connections & Transactions (e-book only) this week in the JDBC forum!

Yellapa Adepu

Ranch Hand
+ Follow
since Jan 17, 2006
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Yellapa Adepu

Hello All,
I am trying save an excel sheeting using apache POI from a groovy class. But I getting a type casting exception not sure how to resolve it. Your help is much appreciated.


I am trying to add conditional formatting to the excel sheet, per apache POI here is the code. Here is my code snippet in groovy (because of this issue, am trying to as near as possible to Java in this logic)




While executing when it comes 'CellRangeAddress[] regions = {CellRangeAddress.valueOf("E2:E32")};' it throws

[java] 2012-08-09 22:52:13,487 ERROR GroovyTaskWrapper - Error occured while :[EXECUTE] Cannot cast object 'Excel$_addDataBars_closure9@1f635484' with class 'Excel$_addDataBars_closure9' to class 'org.apache.poi.hssf.util.CellRangeAddress'

For additional information: Here is the example form Apache POI http://svn.apache.org/repos/asf/poi/trunk/src/examples/src/org/apache/poi/ss/examples/ConditionalFormats.java
I am trying to follow the below snippet



Thanks,
YA
6 years ago
I am also beginning with Groovy, I liked this. It may help you as well..

http://www.ibm.com/developerworks/java/tutorials/j-groovy/

Thanks
YA
8 years ago
Where is your applicationContext.xml located. If it is not there under WEB-INF, you may encounter the described error.

1. Try to move the applicationContext.xml under WEB-INF folder.
OR
2. Use classpath expression from where your loading the applicationContext.xml. eg.


Let me know if I can be more helpful.

Thanks
Friends,
I though it may useful to some body who is looking for such information...
Introduction
As most of us well aware of Hibernate and Spring frameworks, I am not getting into much of introduction part. However in short,

Hibernate
� A popular & successful ORM tool
� Abstracting the underlining JDBC programming
� Portable to any supported database with minor configuration changes
� Provides Transaction Management etc�.

Spring
� Implementation Inversion of Control (IOC) design pattern.
� Abstraction to Aspect Oriented Programming (AOP).
� Creates the java object beans from an application context xml (spring configuration file)
I would like to walk you through a running example how they both work together� Please take a look at the below xml..

Header part of spring configuration xml includes spring-bean.dtd


Loading Hibernate properties: Hibernate properties can be loaded using Spring�s PropertyPlaceholderConfigurer class. Provide hibernate.properties file location as value. If the file placed under any other directory other than WEB-INF directory, use classpath: expression to let the Spring to look for the file in available classpath.



Defining a DataSource: Use JndiObjectFactoryBean class to define the data source by providing JNDI binding name.



Defining a Session Factory: Hibernate session factory can be defined using LocalSessionFactoryBean class, provides an integration point to Hibernate from Spring.
Here we need to provide data source information and hibernate mapping files (.hbm.xml).
Transaction factory class, hibernate supports
org.hibernate.transaction.JDBCTransactionFactory - delegates to database (JDBC) transactions (default)
org.hibernate.transaction.JTATransactionFactory - delegates to container-managed transaction if an existing transaction is underway in this context (e.g. EJB session bean method), otherwise a new transaction is started and bean-managed transaction are used.
org.hibernate.transaction.CMTTransactionFactory - delegates to container-managed JTA transactions

Transaction Lookup class: It depends on application server on which the application is running, here I am using WebSphere Application Server related one.
Special columns if there are any column defined CLOBs, those can handled using default implementation provided spring. Here as an example I am using CLOB handler.



Defining a Transaction Manager: By providing the above defined session factory, a transaction manager needs to be defined as below.



It might be a quick, not much detailed enough as I covered only basic configuration. Please let write your inputs/comments, I will try to add some more details�..
[ June 26, 2008: Message edited by: Yellappa Adepu ]
when I try to select the NEXTVAL from a DB Sequence entity. Hibernate is appending the logged in user id as a schema rather the schema defined in hibernate.properties.

Any ideas on why it is doing so. Please suggest.

Thanks,
any clue... i am in same situation where I need help..
Friends,
What would be the good start for upgrade exam.. I am thinking to go for it...

thanks
Hi Pinik
Did you get a solution for the problem. I am in need of same kind of solution. If you can you please share.

Thanks,
Incase of HttpClient, it is adding some escape characters in the request. That is causing the problem. Please help how to avoid this.. here is the request info..

with HttpConnection:
<?xml version="1.0" encoding="UTF-8"?> <binderRequest> <source>MyApp</source> <requestID>5555555551177436669446</requestID> <agencyAgent>5442-015</agencyAgent> <demographic> <ssn>555555555</ssn> <dob>1972-05-04</dob> <firstName>aa</firstName> <lastName>bb</lastName> <address1>asdf</address1> <address2>sdf</address2> <city>sdf</city>
</demographic> </binderRequest>.

with HttpClient:
SWEExtData=%3C%3Fxml+version%3D%221.0%22+encoding%3D%22UTF-8%22%3F%3E%0A%3CbinderRequest
%3E%3Csource%3EISS%3C%2Fsource%3E%3CrequestID%3E5555555551177436670087%3C%2FrequestID%3E%3C
agencyAgent%3E5442-015%3C%2FagencyAgent%3E%3Cdemographic%3E%3Cssn%3E555555555%3C%2Fssn%3E%3C
dob%3E1972-05-04%3C%2Fdob%3E%3CfirstName%3Eaa%3C%2FfirstName%3E%3ClastName%3Ebb%3C%2FlastName%3E%3C
address1%3Easdf%3C%2Faddress1%3E%3Caddress2%3Esdf%3C%2Faddress2%3E%3Ccity%3Esdf%3C
%2Fcity%3E%2Fdemographic%3E%2FbinderRequest%3E&S WEExtSource=ProcessCBPPPayment&SWEExtCmd=Execute

It is adding %3E (something) in place of < and >

Thanks,
[ April 24, 2007: Message edited by: Ulf Dittmer ]
Hi Friends,
I am trying to communicate with another application from our application based on XML request and response scenario.

Initially, I sent a XML request using HttpConnection (open connection, write a stream and flush it) and go successfull response back.. But when I tried to send the same request using HttpClient ( post method) am getting XML Malformed error message. I am guessing, will HttpClient (common's) implementation may add some kind of HTTP enevlope the XML request.
1. Is my guess correct?
2. Please explain what is happening there?? (it is working with HttpConnection but not with HttpClient)

Thanks,
Hi,
Here is some more information. I am able to connect to the other system using below implementation.

// Create a trust manager that does not validate certificate chains
TrustManager[] trustAllCerts = new TrustManager[]{
new X509TrustManager() {
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
return null;
}
public void checkClientTrusted(
java.security.cert.X509Certificate[] certs, String authType) {
}
public void checkServerTrusted(
java.security.cert.X509Certificate[] certs, String authType) {
}
public boolean isClientTrusted(X509Certificate[] arg0) {
return true;
}
public boolean isServerTrusted(X509Certificate[] arg0) {
return true;
}
}
};

// Install the all-trusting trust manager
try {
SSLContext sc = SSLContext.getInstance("SSL");
sc.init(null, trustAllCerts, new java.security.SecureRandom());
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
} catch (Exception e) {
e.printStackTrace();
}


StringBuffer result = new StringBuffer();

try {

// Send data
URL urlM = new URL(url);
URLConnection conn = urlM.openConnection();
conn.setDoOutput(true);
OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
String xmlResult = Utils.generateXMLForPaymentGateway(app);

wr.write(xmlResult);

wr.flush();

// Get the response
BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line;

while ((line = rd.readLine()) != null)
{
result.append(line);
}
wr.close();
rd.close();
} catch (Exception e) {
e.printStackTrace();
}

I can send request and get the response. But same thing I am trying to achieve using HttpClient. This is how I am creating HttpClient.
try{
HttpConnectionManagerParams connectionManagerParms = new HttpConnectionManagerParams();
connectionManagerParms.setDefaultMaxConnectionsPerHost(maxHostConnections);
connectionManagerParms.setMaxTotalConnections(maxTotalConnections);
connectionManagerParms.setSoTimeout(socketTimeout);
connectionManagerParms.setConnectionTimeout(connectionTimeout);
connectionManager = new MultiThreadedHttpConnectionManager();
connectionManager.setParams(connectionManagerParms);

Protocol easyhttps = new Protocol("https", new MySSLProtocolSocketFactory(), 9443);

httpClient = new HttpClient(connectionManager);
httpClient.getHostConfiguration().setHost(PropertyUtil.getHostname(), 9443, easyhttps);
} catch (Exception e){
clientCreated=false;
clientCreatedMessage = "Init HTTPUtil call Problem: Problem creating MultiThreadedHttpConnectionManager " + e.getMessage();
Log.error(clientCreatedMessage);
}

where as MySSLProtocolSocketFactory is extending SSLProtocolSocketFactory.

Please help,
Thanks,
Thanks for your reply. But I tried it earlier, here is the exception I am getting... however the same implementation is working fine in talking to other systems using https and username, password authentication...

The problem is when I use certificates... please help..

[4/23/07 10:50:54:558 EDT] 257ba6b7 HttpMethodDir I org.apache.commons.httpclient.HttpMethodDirector I/O exception (java.net.SocketException) caught when processing request: Socket is not connected
[4/23/07 10:50:54:558 EDT] 257ba6b7 HttpMethodDir I org.apache.commons.httpclient.HttpMethodDirector Retrying request
[4/23/07 10:50:54:558 EDT] 257ba6b7 HttpMethodDir I org.apache.commons.httpclient.HttpMethodDirector I/O exception (java.net.SocketException) caught when processing request: Socket is not connected
[4/23/07 10:50:54:558 EDT] 257ba6b7 HttpMethodDir I org.apache.commons.httpclient.HttpMethodDirector Retrying request
[4/23/07 10:50:54:574 EDT] 257ba6b7 HttpMethodDir I org.apache.commons.httpclient.HttpMethodDirector I/O exception (java.net.SocketException) caught when processing request: Socket is not connected
[4/23/07 10:50:54:574 EDT] 257ba6b7 HttpMethodDir I org.apache.commons.httpclient.HttpMethodDirector Retrying request

Thanks,

Originally posted by Yellappa Adepu:
Hi Friends,
I am trying to connect another application from our application using HttpClient connection. It requires a security certificate though it is an internal application and does not pass through a proxy.

I am not clear how to establish HttpClient connection with a security SSL certificate. Could you please help me in doing this.

Note: I am able to establish the connectivity using UrlConnection with SSL Context. It is working fine.

Thanks,

Hi Friends,
I am trying to connect another application from our application using HttpClient connection. It requires a security certificate though it is an internal application and does not pass through a proxy.

I am not clear how to establish HttpClient connection with a security SSL certificate. Could you please help me in doing this.

Note: I am able to establish the connectivity using UrlConnection with SSL Context. It is working fine.

Thanks,
[ April 22, 2007: Message edited by: Yellappa Adepu ]