Showing posts with label Spring. Show all posts
Showing posts with label Spring. Show all posts

Monday, 10 November 2008

[Restlet with Spring DM]

How you can create restlet with Spring DM

1. need update 6 files
- web.xml
- applicationContext-osgi.xml
- applicationContext.xml
- MANIFEST.MF
- TestApplication.java
- TestDefaultResource.java

2. main point

use "org.restlet.component" as context-param

in web.xml add below line


3.
[context-param]
[param-name]org.restlet.component[/param-name]
[param-value]component[/param-value]
[/context-param]

4. "component is from "applicationContext.xml" file

[bean id="component" class="org.restlet.ext.spring.SpringComponent" ]
[property name="defaultTarget" ref="application" /]
[/bean]

5. "application" is from same file "applicationContext.xml" file

[bean id="application" class="applicationPackage.TestApplication"][/bean]

6. TestApplication.java
import TestDefaultResouce;
import org.restlet.Application;
import org.restlet.Context;
import org.restlet.Restlet;
import org.restlet.Router;

public class EamApplication extends Application {

public EamApplication() {
super();
// TODO Auto-generated constructor stub
}

public EamApplication(Context context) {
super(context);
}

@Override
public Restlet createRoot() {
Router router = new Router(getContext());
router.attachDefault(TestDefaultResouce.class);
return router;
}
}

7. TestDefaultResouce.java

import org.restlet.Context;
import org.restlet.data.MediaType;
import org.restlet.data.Request;
import org.restlet.data.Response;
import org.restlet.resource.Representation;
import org.restlet.resource.Resource;
import org.restlet.resource.StringRepresentation;
import org.restlet.resource.Variant;

public class EamDefaultResouce extends Resource {

public EamDefaultResouce() {
super();
// TODO Auto-generated constructor stub
}

public EamDefaultResouce(Context context, Request request, Response response) {
super(context, request, response);
getVariants().add(new Variant(MediaType.TEXT_PLAIN));
}

@Override
public Representation getRepresentation(Variant variant){
Representation representation = new StringRepresentation("index page", MediaType.TEXT_PLAIN);
return representation;
}
}

Wednesday, 8 October 2008

[Spring] file upload example

you need two jar file library.

- commons-io-1.4.jar
- commons-fileupload-1.2.jar

=== HTML ====
[form method="post" action="uploadFile.htm" enctype="multipart/form-data"]
[input type="file" name="file1"/]
[input type="submit"/]
[/form]

============ dispatcher-servlet.xml ====================

[bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver"]
[property name="maxUploadSize" value="100000"/]
[property name="uploadTempDir" ref="uploadDirResource"/]
[/bean]

[bean id="uploadDirResource"
class="org.springframework.core.io.FileSystemResource"]
[constructor-arg]
[value]C:/test111[/value]
[/constructor-arg]
[/bean]


==================== Controller =====
@Override
protected ModelAndView onSubmit(HttpServletRequest request,
HttpServletResponse response, Object command, BindException errors)throws ServletException, IOException {


MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest)request;

MultipartFile filea = multipartRequest.getFile("file1");


InputStream inputStream = null;
OutputStream outputStream = null;
if (filea.getSize() > 0) {


inputStream = filea.getInputStream();
File realUpload = new File("C:/");
outputStream = new FileOutputStream("C:/test111/"+filea.getOriginalFilename());
System.out.println("====22=========");
System.out.println(filea.getOriginalFilename());
System.out.println("=============");
int readBytes = 0;
byte[] buffer = new byte[8192];
while ((readBytes = inputStream.read(buffer, 0 , 8192))!=-1){
System.out.println("===ddd=======");
outputStream.write(buffer, 0, readBytes);
}
outputStream.close();
inputStream.close();
}

return new ModelAndView("fileupload");
}

Thursday, 28 August 2008

Error : interface org.hibernate.jdbc.ConnectionWrapper is not visible from class loader

Error Message : interface org.hibernate.jdbc.ConnectionWrapper is not visible from class loader

Full Error Message

Caused by: java.lang.IllegalArgumentException: interface org.hibernate.jdbc.ConnectionWrapper is not visible from class loader
at java.lang.reflect.Proxy.getProxyClass(Unknown Source)
at java.lang.reflect.Proxy.newProxyInstance(Unknown Source)
at org.hibernate.jdbc.BorrowedConnectionProxy.generateProxy(BorrowedConnectionProxy.java:67)
at org.hibernate.jdbc.ConnectionManager.borrowConnection(ConnectionManager.java:163)
at org.hibernate.jdbc.JDBCContext.borrowConnection(JDBCContext.java:111)
at org.hibernate.impl.SessionImpl.connection(SessionImpl.java:359)
at org.springframework.orm.hibernate3.HibernateTransactionManager.doBegin(HibernateTransactionManager.java:510)
... 31 more


In this case, your manifest file is not correctly.
Please check it, you might miss "org.hibernate.jdbc;version="3.2.6.ga" bundle
or check with below example mainifest file bundle list

org.aopalliance.aop;version="1.0.0",
org.apache.commons.dbcp;version="1.2.2.osgi",
org.apache.log4j;version="1.2.15",
org.hibernate;version="3.2.6.ga",
org.hibernate.classic;version="3.2.6.ga",
org.hibernate.criterion;version="3.2.6.ga",
org.hibernate.hql.ast;version="3.2.6.ga",
org.hibernate.jdbc;version="3.2.6.ga",
org.hibernate.proxy;version="3.2.6.ga",
org.hibernate.usertype;version="3.2.6.ga",
org.springframework.aop;version="2.5.4",
org.springframework.aop.framework;version="2.5.4",
org.springframework.beans;version="2.5.4",
org.springframework.beans.factory.config;version="2.5.4",
org.springframework.core;version="2.5.4",
org.springframework.jmx.export;version="2.5.4",
org.springframework.orm.hibernate3;version="2.5.4",
org.springframework.orm.hibernate3.support;version="2.5.4",
org.springframework.transaction;version="2.5.4",
org.springframework.transaction.annotation;version="2.5.4",
org.springframework.transaction.interceptor;version="2.5.4",
org.springframework.transaction.support;version="2.5.4"

Tuesday, 5 August 2008

org.hibernate.HibernateException: No Hibernate Session bound to thread

error message : org.hibernate.HibernateException: No Hibernate Session bound to thread

You did not insert "annotation" in the source.
such as

"@Transactional"
"@SuppressWarnings("unchecked")"
"@Transactional(readOnly = true)"

Tuesday, 22 July 2008

Spring osgi - good tutorial

http://springosgi.googlepages.com/

If you have the problem while you are following the example from the site, please
use different pom.xml file.


When you progress the sample from the tutorial site, please use another pom.xml file.

updated pom.xml file

Wednesday, 16 July 2008

Install SpringIDE or Maven in Eclipse 3.4 ( GANYMEDE )

1. Help
2. Software update
3. Add Site
4. Enter http://springide.org/updatesite
4-1. For Maven - http://m2eclipse.sonatype.org/update/
5. Click checkbox next to http://springide.org/updatesite to expand.
5-1 For Mave - http://m2eclipse.sonatype.org/update/ to expand
6. Check all sub option under SpringIDE (Maven)
7. Install
8. You will have below error message
======================================================
The software items you selected may not be valid with your current installation....
===================================================
9. Click Yes
10. Uncheck
"Spring IDE Dependencies (only for Eclipse 3.2.x)"
"Spring IDE Mylyn Integration (optional)"
10-1 "Subclipse Integration for Maven (Optional)"
11. Click Next

Friday, 4 July 2008

error : hibernate with Data type in DB

* Error Message
"java.sql.SQLException: Value '0000-00-00' can not be represented as java.sql.Date"

You might have data type column in DB table and read it with hibernate.
In this case , you should update "dataSource.xml" file
Add " p:zeroDateTimeBehavior="convertToNull" "

=== Pull xml file =====
[?xml version="1.0" encoding="UTF-8"?]

[beans xmlns="http://www.springframework.org/schema/beans"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"]

[bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource"
p:driverClassName="com.mysql.jdbc.Driver"
p:url="jdbc:mysql://localhost/test?useUnicode=true&characterEncoding=euckr&zeroDateTimeBehavior=convertToNull"
p:username="root" p:password="1111"]

[/beans]

Thursday, 26 June 2008

Spring , Hibernate Sample

This is Spring 2.0 + Hibernate3 sample source.

It is working with mysql + Eclipse

Simple BBS sample source.

add > view list > delete , update

sql file is in sql folder to create table

download sample source

Wednesday, 16 April 2008

[Spring] Simple MVC Web application Example 2

[Spring] Simple MVC Web application Example 2

- Display Current Time with parameter under MVC model
(* Developing and Configuring the Views and the Controller)

From http://www.springframework.org/docs/Spring-MVC-step-by-step/index.html

Click Here

[Spring] Basic Example 1

[Spring] Simple MVC Web application Example

Modify from Spring reference
http://www.springframework.org/docs/Spring-MVC-step-by-step/index.html

- Create Control and just display hello world
click here

Monday, 14 April 2008

Spring Eclipse IDE sample

- install Eclipse IDE for spring and simple demo

* http://www.javabeat.net/articles/2007/09/introduction-to-spring-ide-2-0/


- Sample source
click Here