May. 6th, 2011


import java.util.Enumeration;
import java.util.concurrent.TimeUnit;

import org.jdiameter.api.ApplicationId;
import org.jdiameter.api.Configuration;
import org.jdiameter.api.InternalException;
import org.jdiameter.api.Message;
import org.jdiameter.api.Stack;
import org.jdiameter.api.StackManager;
import org.jdiameter.api.cca.ClientCCASession;
import org.jdiameter.api.validation.AvpRepresentation;
import org.jdiameter.client.api.ISessionFactory;
import org.jdiameter.client.impl.StackImpl;
import org.jdiameter.client.impl.helpers.XMLConfiguration;
import org.jdiameter.common.impl.app.cca.CCASessionFactoryImpl;
import org.jdiameter.common.impl.app.cca.JCreditControlRequestImpl;
import org.jdiameter.common.impl.validation.DictionaryImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* date: 21.04.11
* time: 13:31
* makedoc
*
* @version $Id$
*/
public class StackController {
private static Logger LOG = LoggerFactory.getLogger(StackController.class);

public static void main(String[] args) {
TicSessionID ticSessionID = new TicSessionID(SessionIDGenerator.getNewSessionID());
final String DEBUG_STR = ticSessionID + ":main: ";
LOG.debug("{} start", DEBUG_STR);

Stack s = new StackImpl();
try {
StackManager.registerStack(s);
} catch (InternalException e) {
LOG.error(DEBUG_STR, e);
}


Enumeration<Stack> stacks = StackManager.getStacks();
LOG.info("{} stacks {}", DEBUG_STR, stacks);
while (stacks.hasMoreElements()) {
Stack stack = stacks.nextElement();
LOG.info("{} stack {}", DEBUG_STR, stack);
}

try {
LOG.info("{} stack is active {}", DEBUG_STR, s.isActive());

Configuration c = new XMLConfiguration(StackController.class.getClassLoader().getResourceAsStream("diameter-client.xml"));
ISessionFactory sessionFactory = (ISessionFactory) s.init(c);
s.start();

LOG.info("{} stack is active {}", DEBUG_STR, s.isActive());

DictionaryImpl dictionary = (DictionaryImpl) s.getDictionary();
dictionary.configure(StackController.class.getClassLoader().getResourceAsStream("dictionary.xml"));
dictionary.setEnabled(true);
LOG.info("{} configured {}", DEBUG_STR, dictionary.isConfigured());
LOG.info("{} enabled {}", DEBUG_STR, dictionary.isEnabled());

sessionFactory.registerAppFacory(ClientCCASession.class, new CCASessionFactoryImpl(sessionFactory));

ApplicationId appId = ApplicationId.createByAccAppId(4);
ClientCCASession session = sessionFactory.getNewAppSession(SessionIDGenerator.getNewSessionID(), appId, ClientCCASession.class);
LOG.info("{} session {}", DEBUG_STR, session);
LOG.info("{} session class {}", DEBUG_STR, session.getClass());

ApplicationId sessionAppId = session.getSessionAppId();
LOG.info("{} application id {}", DEBUG_STR, sessionAppId);

JCreditControlRequestImpl event = new JCreditControlRequestImpl(session, "jDiameter", "127.0.0.1");

Message message;
// message = session.getSessions().get(0).createRequest(272, appId, "jDiameter");

AvpRepresentation avpr = CcaDictionary.CCRequestType.avp(dictionary);
message = event.getMessage();

message.getAvps().addAvp(avpr.getCode(), 1, avpr.getVendorId(), avpr.isMandatory(), avpr.isProtected());
LOG.info("{} message {} {} {}", new Object[]{DEBUG_STR, message,message,message});
session.sendCreditControlRequest(event);

s.stop(10, TimeUnit.MILLISECONDS);
} catch (Exception e) {
LOG.error(DEBUG_STR, e);
}

LOG.debug("{} stop", DEBUG_STR);
}
}

Profile

kds

December 2012

S M T W T F S
      1
2345678
9101112131415
1617181920 2122
23242526272829
3031     

Most Popular Tags

Page Summary

Style Credit

Expand Cut Tags

No cut tags
Page generated Jun. 16th, 2025 05:37 am
Powered by Dreamwidth Studios