Server-side logging using BlazeDS API

  1. Configuring server-side logging

    Configure server-side logging in the logging section of the Flex services-config.xml configuration file. After you edit services-config.xml, restart the BlazeDS server.

    The following example shows a configuration that sets the logging level to Debug:

  2. <logging>
        <target class="flex.messaging.log.ConsoleTarget" level="Debug">
            <properties>
                <prefix>[BlazeDS]</prefix>
                <includeDate>true</includeDate>
                <includeTime>true</includeTime>
                <includeLevel>true</includeLevel>
                <includeCategory>true</includeCategory>
            </properties>
            <filters>
                <pattern>Endpoint.*</pattern>
                <pattern>Service.*</pattern>
                <pattern>Configuration</pattern>
  3.             <pattern>Client.*</pattern>
            </filters>
        </target>
    </logging>



The available levels include All, Debug, Error, Info, None, and Warn.



you can specify flex.messaging.log.ConsoleTarget (default) to log

messages to the standard output,or the flex.messaging.log.ServletLogTarget 
to log messages to the default logging mechanism for servlets for 
your application server.

 


  1. Thanks
  2. Neeraj




How to get session and httpheader info using BlazeDS

 BlazeDS api has flex.messaging.FlexContext utility class that exposes the current execution context on the BlazeDS server. It provides access to FlexSession and FlexClient instances associated with the current message being processed. It also provides global context by accessing MessageBroker, ServletContext, and ServletConfig instances.

The following example shows a Java class that calls FlexContext.getHttpRequest() to get an HTTPServletRequest object and calls FlexContext.getFlexSession() to get a FlexSession object.

 

import flex.messaging.*;
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class SessionRO {

public HttpServletRequest request;
public FlexSession session;

public SessionRO() {
request = FlexContext.getHttpRequest();
session = FlexContext.getFlexSession();
}

public String getSessionId() throws Exception {
String s = new String();
s = (String) session.getId();
return s;
}

public String getHeader(String h) throws Exception {
String s = new String();
s = (String) request.getHeader(h);
return h + "=" + s;
}
}



 




  1. Thanks


  2. Neeraj smile_regular

Export Datagrid to CVS/Excel

Althought we can export datagrid to Excel sheet using as3xls library, but if
datagrid column length is more then 256 character then it will get truncate.
so I deside to export in cvs formate.I have created custom AS class, to export
datagrid you have to create object of that class by passing datagrid id and
dataprovider as a contructor argument.and call createCSV()method.

package
{
import com.as3xls.xls.ExcelFile;
import com.as3xls.xls.Sheet;

import flash.events.*;
import flash.net.*;
import flash.utils.*;

import mx.collections.ArrayCollection;
import mx.controls.Alert;
import mx.controls.DataGrid;
import mx.controls.dataGridClasses.DataGridColumn;

public class ExportToExcelorCVS
{
private var _grid:DataGrid;
private var _dataProvider:ArrayCollection;

public function ExportToExcelorCVS(grid_:DataGrid, dataProvider_:ArrayCollection)
{
_grid = grid_;
_dataProvider = dataProvider_;
}


protected function handleIOError(event:Event):void {
Alert.show("Cannot write to file.please make sure the file is closed", "Export Error");
}

public function createCSV(filename_:String = "export.csv"):void
{
var finalCSVString:String = "";
var csvLine:String = "";
var column:DataGridColumn;
var cellString:String = "";
var isCellExist:Boolean = false;
for each (column in _grid.columns) {
if (column.visible) {
cellString = column.headerText;
csvLine += (csvLine == "" ? "" : ",") + "\"" + cellString + "\"";
}
}
finalCSVString += (finalCSVString == "" ? "" : "\n") + csvLine;

for each(var rowItem:Object in _dataProvider)
{
csvLine = "";

for each (column in _grid.columns)
{
isCellExist = false;
if(column.visible)
{
if(column.dataField && rowItem.hasOwnProperty(column.dataField) && rowItem[column.dataField] != null)
{
cellString = rowItem[column.dataField];
isCellExist = true;

}
// add cell to row line
if(isCellExist){
csvLine += (csvLine == "" ? "" : ",") + "\"" + cellString + "\"";
}
}
}
finalCSVString += (finalCSVString == "" ? "" : "\n") + csvLine;
}

var csvBytes:ByteArray = new ByteArray();
csvBytes.writeUTFBytes(finalCSVString);

var csvFile:FileReference = new FileReference();
csvFile.addEventListener(IOErrorEvent.IO_ERROR, handleIOError);
csvFile.save(csvBytes,filename_);
}

}
}

Neeraj

Create SWF without “-service” compiler argument

I found many flex blazeDs Example on net.every example use -service complie time argument,where we have to pass service-config.xml file path.
basically using this file we are setting channels.
here you can find alternative way to set channels.

 

 

package com

{
     import mx.messaging.ChannelSet;
     import mx.messaging.channels.AMFChannel;
     import mx.messaging.channels.SecureAMFChannel;

     public class ChannelUtil
     {
           private static var myAmf:AMFChannel;
           private static var mySecureAmf:SecureAMFChannel;
           private static var myPollingAmf:AMFChannel;
           private static var myChannelSet:ChannelSet;

          public static function getChannelSet():ChannelSet{
          if(!myChannelSet){
                   myChannelSet = new ChannelSet();

                   myAmf = new AMFChannel();
                   myAmf.uri = "/webapp/messagebroker/amf";
                  
                  mySecureAmf = new SecureAMFChannel();
                  mySecureAmf.uri = "/webapp/messagebroker/amfsecure";

                  myPollingAmf = new AMFChannel();
                  myPollingAmf.pollingEnabled = true;
                  myPollingAmf.pollingInterval = 4;
                  myPollingAmf.uri = "/webapp/messagebroker/amfpolling";

                  

                  myChannelSet.addChannel(myAmf);
                  myChannelSet.addChannel(mySecureAmf);
                  myChannelSet.addChannel(myPollingAmf);
        }
       return myChannelSet;
    }
}
}

 

Remoteobject.channelSet = ChannelUtil.getChannelSet();

 

Neeraj

ProgressBar using TitleWindow popup

 

 

<?xml version="1.0" encoding="utf-8"?>
<mx:titlewindow title="Progressing .... " width="420" height="100" mx="http://www.adobe.com/2006/mxml" alpha="1" cornerradius="6" horizontalalign="center" verticalalign="middle">
                  <mx:progressbar width="360" height="20" indeterminate="true" trackheight="20" label="" barcolor="#326CB4"/>
</mx:titlewindow>