Search in sources :

Example 21 with DiameterMessage

use of net.java.slee.resource.diameter.base.events.DiameterMessage in project jain-slee.diameter by RestComm.

the class CCAActivityAnswerCreationTest method testCCAServerActivityAnswerCreation.

@Test
public void testCCAServerActivityAnswerCreation() throws Exception {
    CCASessionFactoryImpl ccaSF = new CCASessionFactoryImpl();
    ServerCCASessionImpl session = new ServerCCASessionImpl(new ICCASessionDataImpl(), ccaSF, (ISessionFactory) stack.getSessionFactory(), new LocalServerCCASessionListenerImpl(), ccaSF, ccaSF);
    CreditControlMessageFactoryImpl ccaMessageFactory = new CreditControlMessageFactoryImpl(baseMessageFactory, session.getSessions().get(0), stack, ccaAvpFactory);
    ArrayList<DiameterMessage> list = new ArrayList<DiameterMessage>();
    list.add(ccaMessageFactory.createCreditControlRequest());
    CreditControlServerSessionImpl activity = new CreditControlServerSessionImpl(ccaMessageFactory, ccaAvpFactory, session, null, null);
    DiameterActivityAnswerCreationHelper.testAnswerCreation(activity, "lastRequest", list);
}
Also used : CreditControlMessageFactoryImpl(org.mobicents.slee.resource.diameter.cca.CreditControlMessageFactoryImpl) ArrayList(java.util.ArrayList) DiameterMessage(net.java.slee.resource.diameter.base.events.DiameterMessage) CCASessionFactoryImpl(org.jdiameter.common.impl.app.cca.CCASessionFactoryImpl) CreditControlServerSessionImpl(org.mobicents.slee.resource.diameter.cca.CreditControlServerSessionImpl) ServerCCASessionImpl(org.jdiameter.server.impl.app.cca.ServerCCASessionImpl) Test(org.junit.Test) BaseFactoriesTest(org.mobicents.slee.resource.diameter.base.tests.factories.BaseFactoriesTest)

Example 22 with DiameterMessage

use of net.java.slee.resource.diameter.base.events.DiameterMessage in project jain-slee.diameter by RestComm.

the class DiameterBaseResourceAdaptor method fireEvent.

/*
   * (non-Javadoc)
   * @see org.mobicents.slee.resource.diameter.base.handlers.BaseSessionCreationListener#fireEvent(java.lang.String, org.jdiameter.api.Request, org.jdiameter.api.Answer)
   */
public void fireEvent(String sessionId, Message message) {
    DiameterMessage event = (DiameterMessage) createEvent(message);
    FireableEventType eventId = eventIdCache.getEventId(eventLookup, message);
    this.fireEvent(event, getActivityHandle(sessionId), eventId, null, true, message.isRequest());
}
Also used : DiameterMessage(net.java.slee.resource.diameter.base.events.DiameterMessage) FireableEventType(javax.slee.resource.FireableEventType)

Example 23 with DiameterMessage

use of net.java.slee.resource.diameter.base.events.DiameterMessage in project jain-slee.diameter by RestComm.

the class DiameterActivityAnswerCreationHelper method testAnswerCreation.

public static void testAnswerCreation(DiameterActivity activity, String messageListFieldName, ArrayList<DiameterMessage> requestList) {
    try {
        Field f = activity.getClass().getDeclaredField(messageListFieldName);
        assertNotNull("There is no such field: " + messageListFieldName, f);
        f.setAccessible(true);
        boolean setOnIterate = false;
        if (f.get(activity) instanceof Collection) {
            f.set(activity, requestList);
        } else {
            setOnIterate = true;
        }
        for (DiameterMessage request : requestList) {
            if (setOnIterate) {
                f.set(activity, request);
            }
            DiameterMessageImpl requestImpl = (DiameterMessageImpl) request;
            // This is cause some of them are zeros :)
            ((MessageImpl) requestImpl.getGenericData()).setEndToEndIdentifier((long) (Math.random() * 10000));
            ((MessageImpl) requestImpl.getGenericData()).setHopByHopIdentifier((long) (Math.random() * 10000));
            Class<? extends DiameterActivity> activityClass = activity.getClass();
            String className = request.getClass().getName();
            String packageName = request.getClass().getPackage().getName();
            String methodName = "create" + (className.replace(packageName + ".", "").replace("RequestImpl", "Answer"));
            Method[] methods = activityClass.getMethods();
            for (Method createAnswerMethod : methods) {
                if (!createAnswerMethod.getName().equals(methodName)) {
                    // System.err.println("Skipping: "+createAnswerMethod.getName());
                    continue;
                }
                // System.err.println("Doing magic for: "+createAnswerMethod.getName());
                // here we can have 3 types of methods:
                // #1 without parameters
                // #2 with long, boolean parameters
                // #3 with different param!!
                Object[] args = null;
                Class<?>[] parameters = createAnswerMethod.getParameterTypes();
                if (parameters.length == 0) {
                    args = new Object[] {};
                // params are null
                } else {
                    args = new Object[parameters.length];
                    for (int i = 0; i < parameters.length; i++) {
                        args[i] = instantiate(parameters[i]);
                    }
                }
                // we only want to see that code matches and answer is not zero? do we want to test AVPs ?
                DiameterMessage answer = (DiameterMessage) createAnswerMethod.invoke(activity, args);
                assertNotNull("Answer is null for method name: " + methodName, answer);
                if (answer == null)
                    return;
                // some basic tests, we don't test values passed, maybe we should ?
                assertEquals("Command code is not equal", request.getCommand().getCode(), answer.getCommand().getCode());
                assertFalse("Answer should have R flag set to false.", answer.getCommand().isRequest());
                assertEquals("E2E is not equal", request.getHeader().getEndToEndId(), answer.getHeader().getEndToEndId());
                assertEquals("HBH is not equal", request.getHeader().getHopByHopId(), answer.getHeader().getHopByHopId());
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : DiameterMessage(net.java.slee.resource.diameter.base.events.DiameterMessage) Method(java.lang.reflect.Method) Field(java.lang.reflect.Field) Collection(java.util.Collection) DiameterMessageImpl(org.mobicents.slee.resource.diameter.base.events.DiameterMessageImpl) MessageImpl(org.jdiameter.client.impl.parser.MessageImpl) DiameterMessageImpl(org.mobicents.slee.resource.diameter.base.events.DiameterMessageImpl)

Example 24 with DiameterMessage

use of net.java.slee.resource.diameter.base.events.DiameterMessage in project jain-slee.diameter by RestComm.

the class CreditControlSessionImpl method sendSyncMessage.

@Override
public DiameterMessage sendSyncMessage(DiameterMessage message) {
    DiameterMessage answer = null;
    Message receivedMessage = doSendMessage(message);
    if (receivedMessage != null) {
        if (!receivedMessage.isRequest()) {
            if (receivedMessage.isError()) {
                answer = new ErrorAnswerImpl(receivedMessage);
            } else {
                switch(receivedMessage.getCommandCode()) {
                    case CreditControlRequest.commandCode:
                        answer = new CreditControlAnswerImpl(receivedMessage);
                        break;
                    default:
                        logger.error("Received an unknown type of Message for Credit-Control Activity: " + receivedMessage);
                        break;
                }
            }
        } else {
            logger.error("Received a REQUEST message when expecting an ANSWER.");
        }
    } else {
        logger.debug("No answer received. Returning null.");
    }
    return answer;
}
Also used : DiameterMessage(net.java.slee.resource.diameter.base.events.DiameterMessage) Message(org.jdiameter.api.Message) DiameterMessage(net.java.slee.resource.diameter.base.events.DiameterMessage) CreditControlAnswerImpl(org.mobicents.slee.resource.diameter.cca.events.CreditControlAnswerImpl) ErrorAnswerImpl(org.mobicents.slee.resource.diameter.base.events.ErrorAnswerImpl)

Example 25 with DiameterMessage

use of net.java.slee.resource.diameter.base.events.DiameterMessage in project jain-slee.diameter by RestComm.

the class DiameterActivityImpl method doSendMessage.

protected Message doSendMessage(DiameterMessage message) {
    Message receivedMessage = null;
    try {
        if (message instanceof DiameterMessageImpl) {
            Future<Message> future = this.session.send(((DiameterMessageImpl) message).getGenericData());
            receivedMessage = future.get();
        } else {
            throw new OperationNotSupportedException("Trying to send wrong type of message? [" + message.getClass() + "] \n" + message);
        }
    } catch (org.jdiameter.api.validation.AvpNotAllowedException e) {
        throw new AvpNotAllowedException("Message validation failed.", e, e.getAvpCode(), e.getVendorId());
    } catch (Exception e) {
        logger.error("Failure sending sync request.", e);
    }
    return receivedMessage;
}
Also used : OperationNotSupportedException(javax.naming.OperationNotSupportedException) Message(org.jdiameter.api.Message) DiameterMessage(net.java.slee.resource.diameter.base.events.DiameterMessage) DiameterMessageImpl(org.mobicents.slee.resource.diameter.base.events.DiameterMessageImpl) AvpNotAllowedException(net.java.slee.resource.diameter.base.events.avp.AvpNotAllowedException) AvpNotAllowedException(net.java.slee.resource.diameter.base.events.avp.AvpNotAllowedException) IOException(java.io.IOException) OperationNotSupportedException(javax.naming.OperationNotSupportedException)

Aggregations

DiameterMessage (net.java.slee.resource.diameter.base.events.DiameterMessage)34 Message (org.jdiameter.api.Message)14 FireableEventType (javax.slee.resource.FireableEventType)12 ErrorAnswerImpl (org.mobicents.slee.resource.diameter.base.events.ErrorAnswerImpl)7 ArrayList (java.util.ArrayList)6 Test (org.junit.Test)4 ExtensionDiameterMessageImpl (org.mobicents.slee.resource.diameter.base.events.ExtensionDiameterMessageImpl)4 OperationNotSupportedException (javax.naming.OperationNotSupportedException)3 DiameterMessageImpl (org.mobicents.slee.resource.diameter.base.events.DiameterMessageImpl)3 IOException (java.io.IOException)2 AvpNotAllowedException (net.java.slee.resource.diameter.base.events.avp.AvpNotAllowedException)2 DiameterAvp (net.java.slee.resource.diameter.base.events.avp.DiameterAvp)2 UserDataRequest (net.java.slee.resource.diameter.sh.events.UserDataRequest)2 ServerShSession (org.jdiameter.api.sh.ServerShSession)2 ShServerSessionDataLocalImpl (org.jdiameter.server.impl.app.sh.ShServerSessionDataLocalImpl)2 ShServerSessionImpl (org.jdiameter.server.impl.app.sh.ShServerSessionImpl)2 DiameterMessageFactoryImpl (org.mobicents.slee.resource.diameter.base.DiameterMessageFactoryImpl)2 AbortSessionAnswerImpl (org.mobicents.slee.resource.diameter.base.events.AbortSessionAnswerImpl)2 AccountingAnswerImpl (org.mobicents.slee.resource.diameter.base.events.AccountingAnswerImpl)2 CapabilitiesExchangeAnswerImpl (org.mobicents.slee.resource.diameter.base.events.CapabilitiesExchangeAnswerImpl)2