30 เมษายน 2552

Asterisk SIP trunk with 2 server

การทำ Trunk โดยใช้ sip จะพบปัญหาในการ config แบบ 2 ทาง ซึ่งแนวทางการแก้ไขจะต้องทำการกำหนด

Server1
[trunk1]
type=peer
host=10.1.1.2
username=102
secret=102
fromuser=102

Server2
[trunk2]
type=peer
host=10.1.1.1
username=101
secret=101
fromuser=101



และ config extensions ใน extensions.conf ดังนี้
Server1
exten=>_9.,1,Dial(SIP/${EXTEN:3}@trunk1,30,r)

Server2
exten=>_9.,1,Dial(SIP/${EXTEN:3}@trunk2,30,r)

24 เมษายน 2552

Spring Scaffold

ทดลองเขียน Spring มาสักพักนึงแล้ว แต่ไม่รู้จะวางโครงยังไงให้ดูดีใช้งานง่าย ค้นไป ค้นมา จึงไปเจอ Tools ชื่อ SKYWAY BUILDER CE ครับ ใช้ในการทำ Scaffold ของ Spring ซึ่งมี แบบ Community ด้วยนะ ซึ่งจะมีทั้งแบบที่เป็น plugin บน Eclipse ด้วย ลองโหลดมาเล่นดูครับ

22 เมษายน 2552

Testing

นั่งทำ Grails Project มาซักพักนึงแล้วครับ แต่ยังไม่สมบูรณ์เลย ไม่รู็จะปิดโปรเจ็คยังไง ซึ่งเรื่องที่สำคัญเรื่องนึงที่พลาดไปคือ Concept เรื่องการทำ Test นี้แหละ เพราะตอนนี้ยังไม่สามารถมั่นใจว่า ระบบที่ทำนั้นถูกต้องหรือเปล่า ก็เลยลองหาข้อมูลเรื่อง test ดูก็เลยคิดจะลองทำ แต่ตอนนี้ยังวุ่นๆ อยู่ เอา Concept ไปก่อนแล้วกัน Testing Concept

01 เมษายน 2552

JasperReport Export Text File

วิธีการ export Jasper Report เป็น Text Format เขียนแบบนี้ครับ

def index = {
def reportFile = servletContext.getResource("/report/test_text.jasper")
def reportName = "testing"
def parameters = new HashMap();
createPdfFile(generateTextReport(reportFile, parameters).toByteArray(), reportName)
return null;
}

private generateTextReport(jasperFile, parameters) {
InputStream input = jasperFile.openStream()
JRTextExporter exporter = new JRTextExporter()
ByteArrayOutputStream byteArray = new ByteArrayOutputStream()

def env = grails.util.GrailsUtil.environment
def config = new ConfigSlurper(env).parse(new File('./grails-app/conf/DataSource.groovy').toURL())
def url = config.dataSource.url
def driverName = config.dataSource.driverClassName
def username = config.dataSource.username
def password = config.dataSource.password

Class.forName(driverName)
Connection connection = DriverManager.getConnection(url, username, password)
JasperPrint jasperPrint = JasperFillManager.fillReport(input, null, connection)
jasperPrint.setLocaleCode(Locale.getDefault().getCountry())

exporter.setParameter(JRTextExporterParameter.CHARACTER_ENCODING, "UTF-8");
exporter.setParameter(JRTextExporterParameter.PAGE_WIDTH, 76);
exporter.setParameter(JRTextExporterParameter.PAGE_HEIGHT, 80);
exporter.setParameter(JRTextExporterParameter.JASPER_PRINT, jasperPrint);
exporter.setParameter(JRTextExporterParameter.OUTPUT_STREAM, byteArray);
exporter.exportReport()
return byteArray
}

private createPdfFile(contentBinary, fileName) {
response.setHeader("Content-disposition", "attachment; filename=" + fileName + ".txt");
response.contentType = "text/plain"
response.outputStream << contentBinary
}