RSS

Author Archives: ភិរម្យ

Spring security 3.0 with LDAP

In Web.xml we need to tell the spring security where is the context.

contextConfigLocation
/WEB-INF/security-context.xml

org.springframework.web.context.ContextLoaderListener

springSecurityFilterChain
org.springframework.web.filter.DelegatingFilterProxy

springSecurityFilterChain
/*

+ In pom file we need to put some code to download the security library
+ property

3.0.7.RELEASE

org.springframework.security
spring-security-ldap
${spring.security.version}

org.springframework.security
spring-security-core
${spring.security.version}

org.springframework.security
spring-security-config
${spring.security.version}

org.springframework.security
spring-security-web
${spring.security.version}

+ In security-context.xml I will copy the file in.

<security:user name="username" password="password"
authorities="ROLE_USER" /

// for ldap server

// for static user

 
បញ្ចេញមតិ

បានចុះផ្សាយដោយ ៖ ​នៅ ខែ​មីនា 2, 2012 in ចែករំលែក, JAVA

 

how to Calc Duration from DateTime to DateTime

Here is a function how to calc day, hours, minutes, second from dateStart to dateFinish

public String calculateDays(Date dateStarted, Date dateFinished) {
String dateTime = “”;

Calendar calStarted = Calendar.getInstance();
Calendar calFinished = Calendar.getInstance();
calStarted.setTime(dateStarted);
calFinished.setTime(dateFinished);

// This .getTimeInMillis() is return the millisecond for this specific DateTime
long dateStartedMili = calStarted.getTimeInMillis();
long dateFinishedMili = calFinished.getTimeInMillis();
long durationTest = dateFinishedMili – dateStartedMili;

long diffDays = durationTest / (24 * 60 * 60 * 1000);
if(diffDays>0){
dateTime += diffDays+”d “;
durationTest = durationTest % (24 * 60 * 60 * 1000);
}

long diffHours = durationTest / (60 * 60 * 1000);
if(diffHours>0){
dateTime += diffHours+”h “;
durationTest = durationTest % (60 * 60 * 1000);
}

long diffMinutes = durationTest / (60 * 1000);
if(diffMinutes>0){
dateTime += diffMinutes+”m “;
durationTest = durationTest % (60 * 1000);
}

long diffSeconds = durationTest / 1000;
if(diffSeconds>0){
dateTime += diffSeconds+”s “;
}
return dateTime;
}

Here I return DateTime as string because i want to show users about the duration.

 
បញ្ចេញមតិ

បានចុះផ្សាយដោយ ៖ ​នៅ ខែ​កុម្ភៈ 2, 2012 in ចែករំលែក, JAVA

 

Delete Join table

DELETE ab
FROM AuthorArticle AS ab, Authors AS a
WHERE ab.AuthID=a.AuthID AND authorsID=id;

this will delete a row from table AuthorArticle where authorsID= authorArticleID and authorsID=id

 
បញ្ចេញមតិ

បានចុះផ្សាយដោយ ៖ ​នៅ ខែធ្នូ 6, 2011 in ចែករំលែក, MySql

 

JAVA retrieve the Data from another server with PHP Web service

I have tried a lots with the solution and this help me to solve the problem, I have created one Web service in PHP Server and return back Json format.

then when I used the script of Java to access to get this back I need the fallowing code:

  • PHP

we just make one web service, that is return in Json format with json_encode($data);

  • JAVA


// try {
//
// String url = "http://yoururl.com/page/action/bla...";
// UsernamePasswordCredentials creds = new UsernamePasswordCredentials("username", "password");
// DefaultHttpClient httpclient = new DefaultHttpClient();
// HttpGet get = new HttpGet(url);
// get.addHeader("X-Requested-Auth", "Digest");
// String jsonResponse = "empty";
// try {
// httpclient.getCredentialsProvider().setCredentials(AuthScope.ANY, creds);
// HttpResponse responsePhone = httpclient.execute(get);
// jsonResponse = IOUtils.toString(responsePhone.getEntity().getContent(), "UTF-8");
// //Assert.assertTrue(content.contains("Opencast Matterhorn"));
// } finally {
// httpclient.getConnectionManager().shutdown();
// }
//
// mav.addObject("jsonResponse", "jsonResponse: " + jsonResponse);
// ObjectMapper mapper = new ObjectMapper();
// InventoryList inventoryList = mapper.readValue(jsonResponse, InventoryList.class);
// mav.addObject("inventoryList", inventoryList.inventories);
//
// }
// catch (Exception ex) {
// mav.addObject("exception", ex.getMessage());
// }
//

Note: I used Free market template in this project, so at the end we will add Arraylist of “inventoryList.inventories” to the page

not sure it is the correct and standard to do this but at less it help me 😉

 
បញ្ចេញមតិ

បានចុះផ្សាយដោយ ៖ ​នៅ ខែវិច្ឆិកា 24, 2011 in ចែករំលែក, JAVA

 

Convert Array to Json format using PHP

I have an array:

$arr = array('a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5);

// show the format
echo json_encode($arr);
?>

the return will be:

{"a":1,"b":2,"c":3,"d":4,"e":5}

 
បញ្ចេញមតិ

បានចុះផ្សាយដោយ ៖ ​នៅ ខែវិច្ឆិកា 19, 2011 in ចែករំលែក, PHP

 

Select the latest top 10 rows from mysql

I have many records, and I want to see only a few record, but I have no idea then I just select *, but this will take too much time for me,

after searching, I found this way let see:

Select * from tbl
where id >= (select max(id) from tbl) - $n

note: $n is the number of records you want to show.

 
បញ្ចេញមតិ

បានចុះផ្សាយដោយ ៖ ​នៅ ខែវិច្ឆិកា 17, 2011 in ចែករំលែក, MySql

 

studying at UP

Now start up about three week, every things start from beginner but some subject does start from beginner and so fast to advance.

What is need to focus on is the store 😉 the pass condition is 60%.

 
បញ្ចេញមតិ

បានចុះផ្សាយដោយ ៖ ​នៅ ខែវិច្ឆិកា 5, 2011 in សកម្មភាពជីវិត

 

QA Team Activity in Parkway resort

In the next mimutes we will go to have team activity in parkway resort and BBQ in Heng Heng II

 
បញ្ចេញមតិ

បានចុះផ្សាយដោយ ៖ ​នៅ ខែមិថុនា 30, 2011 in សកម្មភាពជីវិត

 

QA Team Activity in Parkway resort

In the next mimutes we will go to have team activity in parkway resort and BBQ in Heng Heng II

 
បញ្ចេញមតិ

បានចុះផ្សាយដោយ ៖ ​នៅ ខែមិថុនា 30, 2011 in សកម្មភាពជីវិត

 

Party with friend

Last night one friend from French come to visit us again in cambodia then have party together,

will be more drink 😛

 
បញ្ចេញមតិ

បានចុះផ្សាយដោយ ៖ ​នៅ ខែមិថុនា 7, 2011 in សកម្មភាពជីវិត

 
 
Design a site like this with WordPress.com
Get started