Search in sources :

Example 41 with DiameterMessageImpl

use of org.mobicents.slee.resource.diameter.base.events.DiameterMessageImpl in project jain-slee.diameter by RestComm.

the class RxServerSessionActivityImpl method sendAAAnswer.

/**
 * {@inheritDoc}
 */
@Override
public void sendAAAnswer(final AAAnswer aaa) throws IOException {
    fetchCurrentState(aaa);
    final DiameterMessageImpl msg = (DiameterMessageImpl) aaa;
    try {
        session.sendAAAnswer(new RxAAAnswerImpl((Answer) msg.getGenericData()));
    } catch (org.jdiameter.api.validation.AvpNotAllowedException e) {
        final AvpNotAllowedException anae = new AvpNotAllowedException("Message validation failed.", e, e.getAvpCode(), e.getVendorId());
        throw anae;
    } catch (Exception e) {
        throw new IOException("Failed to send message.", e);
    }
}
Also used : AAAnswer(net.java.slee.resource.diameter.rx.events.AAAnswer) SessionTerminationAnswer(net.java.slee.resource.diameter.rx.events.SessionTerminationAnswer) Answer(org.jdiameter.api.Answer) RxAAAnswerImpl(org.jdiameter.common.impl.app.rx.RxAAAnswerImpl) IOException(java.io.IOException) 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)

Example 42 with DiameterMessageImpl

use of org.mobicents.slee.resource.diameter.base.events.DiameterMessageImpl in project jain-slee.diameter by RestComm.

the class S13ClientSessionImpl method sendMEIdentityCheckRequest.

public void sendMEIdentityCheckRequest(MEIdentityCheckRequest ecr) throws IOException {
    DiameterMessageImpl msg = (DiameterMessageImpl) ecr;
    JMEIdentityCheckRequestImpl request = new JMEIdentityCheckRequestImpl((Request) msg.getGenericData());
    try {
        appSession.sendMEIdentityCheckRequest(request);
    } catch (org.jdiameter.api.validation.AvpNotAllowedException anae) {
        throw new AvpNotAllowedException(anae.getMessage(), anae.getAvpCode(), anae.getVendorId());
    } catch (Exception e) {
        if (logger.isDebugEnabled()) {
            logger.debug("Failed to send message.", e);
        }
        throw new IOException(e.getMessage());
    }
}
Also used : IOException(java.io.IOException) DiameterMessageImpl(org.mobicents.slee.resource.diameter.base.events.DiameterMessageImpl) AvpNotAllowedException(net.java.slee.resource.diameter.base.events.avp.AvpNotAllowedException) IOException(java.io.IOException) AvpNotAllowedException(net.java.slee.resource.diameter.base.events.avp.AvpNotAllowedException) InternalException(org.jdiameter.api.InternalException) JMEIdentityCheckRequestImpl(org.jdiameter.common.impl.app.s13.JMEIdentityCheckRequestImpl)

Example 43 with DiameterMessageImpl

use of org.mobicents.slee.resource.diameter.base.events.DiameterMessageImpl in project jain-slee.diameter by RestComm.

the class S13ServerSessionImpl method sendMEIdentityCheckAnswer.

public void sendMEIdentityCheckAnswer(MEIdentityCheckAnswer eca) throws IOException {
    DiameterMessageImpl msg = (DiameterMessageImpl) eca;
    JMEIdentityCheckAnswerImpl answer = new JMEIdentityCheckAnswerImpl((Answer) msg.getGenericData());
    try {
        appSession.sendMEIdentityCheckAnswer(answer);
    } catch (org.jdiameter.api.validation.AvpNotAllowedException anae) {
        throw new AvpNotAllowedException(anae.getMessage(), anae.getAvpCode(), anae.getVendorId());
    } catch (Exception e) {
        if (logger.isDebugEnabled()) {
            logger.debug("Failed to send message.", e);
        }
        throw new IOException(e.getMessage());
    }
}
Also used : JMEIdentityCheckAnswerImpl(org.jdiameter.common.impl.app.s13.JMEIdentityCheckAnswerImpl) IOException(java.io.IOException) DiameterMessageImpl(org.mobicents.slee.resource.diameter.base.events.DiameterMessageImpl) AvpNotAllowedException(net.java.slee.resource.diameter.base.events.avp.AvpNotAllowedException) IOException(java.io.IOException) AvpNotAllowedException(net.java.slee.resource.diameter.base.events.avp.AvpNotAllowedException) InternalException(org.jdiameter.api.InternalException)

Example 44 with DiameterMessageImpl

use of org.mobicents.slee.resource.diameter.base.events.DiameterMessageImpl in project jain-slee.diameter by RestComm.

the class CxDxServerSessionImpl method sendUserAuthorizationAnswer.

/*
   * (non-Javadoc)
   * @see net.java.slee.resource.diameter.cxdx.CxDxServerSession#sendUserAuthorizationAnswer(net.java.slee.resource.diameter.cxdx.events.UserAuthorizationAnswer)
   */
public void sendUserAuthorizationAnswer(UserAuthorizationAnswer userAuthorizationAnswer) throws IOException {
    DiameterMessageImpl msg = (DiameterMessageImpl) userAuthorizationAnswer;
    JUserAuthorizationAnswerImpl answer = new JUserAuthorizationAnswerImpl((Answer) msg.getGenericData());
    try {
        appSession.sendUserAuthorizationAnswer(answer);
    } catch (org.jdiameter.api.validation.AvpNotAllowedException anae) {
        throw new AvpNotAllowedException(anae.getMessage(), anae.getAvpCode(), anae.getVendorId());
    } catch (Exception e) {
        if (logger.isDebugEnabled()) {
            logger.debug("Failed to send message.", e);
        }
        throw new IOException(e.getMessage());
    }
}
Also used : JUserAuthorizationAnswerImpl(org.jdiameter.common.impl.app.cxdx.JUserAuthorizationAnswerImpl) IOException(java.io.IOException) 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) InternalException(org.jdiameter.api.InternalException) IOException(java.io.IOException)

Example 45 with DiameterMessageImpl

use of org.mobicents.slee.resource.diameter.base.events.DiameterMessageImpl 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)

Aggregations

DiameterMessageImpl (org.mobicents.slee.resource.diameter.base.events.DiameterMessageImpl)70 AvpNotAllowedException (net.java.slee.resource.diameter.base.events.avp.AvpNotAllowedException)63 IOException (java.io.IOException)62 InternalException (org.jdiameter.api.InternalException)30 Request (org.jdiameter.api.Request)17 DiameterException (net.java.slee.resource.diameter.base.DiameterException)12 Answer (org.jdiameter.api.Answer)11 SubscribeNotificationsRequest (net.java.slee.resource.diameter.sh.events.SubscribeNotificationsRequest)6 GxCreditControlRequest (net.java.slee.resource.diameter.gx.events.GxCreditControlRequest)5 CreditControlRequest (net.java.slee.resource.diameter.cca.events.CreditControlRequest)4 GxReAuthRequest (net.java.slee.resource.diameter.gx.events.GxReAuthRequest)4 RoCreditControlRequest (net.java.slee.resource.diameter.ro.events.RoCreditControlRequest)4 Message (org.jdiameter.api.Message)4 JCreditControlRequestImpl (org.jdiameter.common.impl.app.cca.JCreditControlRequestImpl)4 RoCreditControlRequestImpl (org.jdiameter.common.impl.app.ro.RoCreditControlRequestImpl)4 ArrayList (java.util.ArrayList)3 OperationNotSupportedException (javax.naming.OperationNotSupportedException)3 DiameterMessage (net.java.slee.resource.diameter.base.events.DiameterMessage)3 DiameterAvp (net.java.slee.resource.diameter.base.events.avp.DiameterAvp)3 ProfileUpdateRequest (net.java.slee.resource.diameter.sh.events.ProfileUpdateRequest)3