Skip to content

Instantly share code, notes, and snippets.

View aziz781's full-sized avatar

Abdul Aziz (A575072) aziz781

View GitHub Profile
@aziz781
aziz781 / TemperatureServiceImple.java
Created October 26, 2011 14:05
Developing Web Services using jax-ws, spring and maven
//TemperatureServiceImple .java
package uk.co.mo.training.ws;
import javax.jws.WebService;
import org.springframework.stereotype.Service;
@SuppressWarnings("restriction")
@WebService(endpointInterface = "uk.co.mo.training.ws.TemperatureService",serviceName="temperatureService")
@Service
public class TemperatureServiceImple implements TemperatureService {
@aziz781
aziz781 / gist:1321958
Created October 28, 2011 09:32
The following example shows how we can test application component that has DAO (heavy weight) dependency using jmock objects and web layer (Controller) using spring mock api
@RunWith(JMock.class)
public class HomeControllerTest {
Mockery context = new JUnit4Mockery();
//mock object : ContactDAO (using JMock)
ContactDAOInterface contactDAO = context.mock(ContactDAOInterface.class);
// Spring MVC controller
HomeController cc = new HomeController();
// mock objects (using spring mock)
private MockHttpServletRequest request;
@aziz781
aziz781 / gist:1321971
Created October 28, 2011 09:38
Data Source configuration for JBOSS
<!--(1) In web.xml (\WEB-INF\web.xml) add the following -->
<resource-ref>
<description>
Resource reference to a factory for java.sql.Connection
instances that may be used for talking to the database
that is configured in server.xml in TOMCAT.
For JBOSS- jboss-web.xml and *-ds.xml
</description>
<res-ref-name>jdbc/SampleDB</res-ref-name>
@aziz781
aziz781 / gist:1321979
Created October 28, 2011 09:42
SPRING: Datasource Configurations
<!-- Spring provides several options for making a DataSource available to your application.
(1) Getting a DataSource from JNDI -->
<bean id=”dataSource”
class=”org.springframework.jndi.JndiObjectFactoryBean“>
<property name=”jndiName”>
<value>java:comp/env/jdbc/myDatasource</value>
</property>
</bean>
@aziz781
aziz781 / gist:1336413
Created November 3, 2011 12:53
Convert Java Throwable exception stack trace into String
public static String getStackTrace(Throwable aThrowable) {
final Writer result = new StringWriter();
final PrintWriter printWriter = new PrintWriter(result);
aThrowable.printStackTrace(printWriter);
return result.toString();
}
@aziz781
aziz781 / gist:1336418
Created November 3, 2011 12:58
java: how to Call Stored Procedure and DB connection from JNDI
public static void processData(int param1, int param2)
{
CallableStatement cs=null;
Connection conn=null;
try{
// get JNDI JDBC connection
InitialContext ctxt = new InitialContext();
DataSource ds = (DataSource) ctxt.lookup("java:/myAppDS");
@aziz781
aziz781 / gist:1336420
Created November 3, 2011 13:01
java: Hibernate String How to execute named query
public boolean dealerExists(String agentNumber) {
return getSessionFactory().getCurrentSession()
.getNamedQuery("myapp.namedquery").setParameter(0, agentNumber)
.list().get(0) != null;
}
@aziz781
aziz781 / gist:1336459
Created November 3, 2011 13:21
Java, Spring JDBC : How to call Stored Procedure with IN and OUT parameters
import java.util.Date;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.object.StoredProcedure;
public class MyStoredProcedure extends StoredProcedure{
public MyStoredProcedure(String procedureName,DataSource dataSource) {
super(new JdbcTemplate(dataSource), procedureName);
@aziz781
aziz781 / gist:1336475
Created November 3, 2011 13:27
Running a Spring Batch Job in The Spring framework Application
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.quartz.JobExecutionContext;
import org.springframework.batch.core.JobExecutionException;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.JobParametersBuilder;
import org.springframework.batch.core.configuration.JobLocator;
import org.springframework.batch.core.launch.JobLauncher;
import org.springframework.scheduling.quartz.QuartzJobBean;
@aziz781
aziz781 / gist:1336483
Created November 3, 2011 13:30
Java Spring Batch: Running a Spring Batch Job
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobExecutionException;