Search in sources :

Example 6 with PushNotificationAnswer

use of net.java.slee.resource.diameter.sh.events.PushNotificationAnswer in project jain-slee.diameter by RestComm.

the class ShClientFactoriesTest method testClientSessionApplicationIdChangePNA.

@Test
public void testClientSessionApplicationIdChangePNA() throws Exception {
    long vendor = 10415L;
    ApplicationId originalAppId = ((ShClientMessageFactoryImpl) shClientFactory).getApplicationId();
    boolean isAuth = originalAppId.getAuthAppId() != org.jdiameter.api.ApplicationId.UNDEFINED_VALUE;
    boolean isAcct = originalAppId.getAcctAppId() != org.jdiameter.api.ApplicationId.UNDEFINED_VALUE;
    boolean isVendor = originalAppId.getVendorId() != 0L;
    assertTrue("Invalid Application-Id (" + originalAppId + "). Should only, and at least, contain either Auth or Acct value.", (isAuth && !isAcct) || (!isAuth && isAcct));
    System.out.println("Default VENDOR-ID for Sh is " + originalAppId.getVendorId());
    // let's create a message and see how it comes...
    PushNotificationRequest pnr = createPushNotificationRequest();
    UserIdentityAvp uiAvp = shAvpFactory.createUserIdentity();
    uiAvp.setPublicIdentity("alexandre@mobicents.org");
    pnr.setUserIdentity(uiAvp);
    pnr.setAuthSessionState(AuthSessionStateType.NO_STATE_MAINTAINED);
    clientSubsSession.fetchSessionData(pnr, true);
    PushNotificationAnswer originalPNA = clientSubsSession.createPushNotificationAnswer();
    BaseFactoriesTest.checkCorrectApplicationIdAVPs(isVendor, isAuth, isAcct, originalPNA);
    // now we switch..
    originalPNA = null;
    isVendor = !isVendor;
    ((ShClientMessageFactoryImpl) shClientFactory).setApplicationId(isVendor ? vendor : 0L, isAuth ? originalAppId.getAuthAppId() : originalAppId.getAcctAppId());
    // create a new message and see how it comes...
    PushNotificationAnswer changedPNA = clientSubsSession.createPushNotificationAnswer();
    BaseFactoriesTest.checkCorrectApplicationIdAVPs(isVendor, isAuth, isAcct, changedPNA);
    // revert back to default
    ((ShClientMessageFactoryImpl) shClientFactory).setApplicationId(originalAppId.getVendorId(), isAuth ? originalAppId.getAuthAppId() : originalAppId.getAcctAppId());
}
Also used : ShClientMessageFactoryImpl(org.mobicents.slee.resource.diameter.sh.client.ShClientMessageFactoryImpl) PushNotificationRequest(net.java.slee.resource.diameter.sh.events.PushNotificationRequest) UserIdentityAvp(net.java.slee.resource.diameter.sh.events.avp.UserIdentityAvp) ApplicationId(org.jdiameter.api.ApplicationId) PushNotificationAnswer(net.java.slee.resource.diameter.sh.events.PushNotificationAnswer) Test(org.junit.Test) BaseFactoriesTest(org.mobicents.slee.resource.diameter.base.tests.factories.BaseFactoriesTest)

Example 7 with PushNotificationAnswer

use of net.java.slee.resource.diameter.sh.events.PushNotificationAnswer in project jain-slee.diameter by RestComm.

the class ShClientSubscriptionActivityImpl method sendPushNotificationAnswer.

/*
   * (non-Javadoc)
   * @see net.java.slee.resource.diameter.sh.ShClientSubscriptionActivity#sendPushNotificationAnswer(net.java.slee.resource.diameter.sh.server.events.PushNotificationAnswer)
   */
public void sendPushNotificationAnswer(PushNotificationAnswer answer) throws IOException {
    try {
        DiameterMessageImpl msg = (DiameterMessageImpl) answer;
        this.clientSession.sendPushNotificationAnswer(new PushNotificationAnswerImpl((Answer) msg.getGenericData()));
        clean((DiameterShMessageImpl) answer);
        fetchSessionData(answer, false);
    } catch (org.jdiameter.api.validation.AvpNotAllowedException e) {
        throw new AvpNotAllowedException("Message validation failed.", e, e.getAvpCode(), e.getVendorId());
    } catch (Exception e) {
        // FIXME: extent this exception to add trace....
        throw new IOException("Failed to send message, due to: " + e.getLocalizedMessage());
    }
}
Also used : Answer(org.jdiameter.api.Answer) PushNotificationAnswer(net.java.slee.resource.diameter.sh.events.PushNotificationAnswer) 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) PushNotificationAnswerImpl(org.jdiameter.common.impl.app.sh.PushNotificationAnswerImpl)

Example 8 with PushNotificationAnswer

use of net.java.slee.resource.diameter.sh.events.PushNotificationAnswer in project jain-slee.diameter by RestComm.

the class ShClientSubscriptionActivityImpl method createPushNotificationAnswer.

/*
   * (non-Javadoc)
   * @see net.java.slee.resource.diameter.sh.ShClientSubscriptionActivity#createPushNotificationAnswer()
   */
public PushNotificationAnswer createPushNotificationAnswer() {
    PushNotificationAnswer pna = null;
    for (int index = 0; index < stateMessages.size(); index++) {
        if (stateMessages.get(index).getCommand().getCode() == PushNotificationAnswer.commandCode) {
            PushNotificationRequest msg = (PushNotificationRequest) stateMessages.get(index);
            pna = this.messageFactory.createPushNotificationAnswer(msg);
            if (pna.getAuthSessionState() == null && this.authSessionState != null) {
                pna.setAuthSessionState(this.authSessionState);
            }
            ((DiameterShMessageImpl) pna).setData(msg);
            break;
        }
    }
    return pna;
}
Also used : PushNotificationRequest(net.java.slee.resource.diameter.sh.events.PushNotificationRequest) DiameterShMessageImpl(org.mobicents.slee.resource.diameter.sh.events.DiameterShMessageImpl) PushNotificationAnswer(net.java.slee.resource.diameter.sh.events.PushNotificationAnswer)

Example 9 with PushNotificationAnswer

use of net.java.slee.resource.diameter.sh.events.PushNotificationAnswer in project jain-slee.diameter by RestComm.

the class ShClientFactoriesTest method hasDestinationHostPNA.

@Test
public void hasDestinationHostPNA() throws Exception {
    PushNotificationAnswer pna = shClientFactory.createPushNotificationAnswer(createPushNotificationRequest());
    assertNull("The Destination-Host and Destination-Realm AVPs MUST NOT be present in the answer message. [RFC3588/6.2]", pna.getDestinationHost());
}
Also used : PushNotificationAnswer(net.java.slee.resource.diameter.sh.events.PushNotificationAnswer) Test(org.junit.Test) BaseFactoriesTest(org.mobicents.slee.resource.diameter.base.tests.factories.BaseFactoriesTest)

Example 10 with PushNotificationAnswer

use of net.java.slee.resource.diameter.sh.events.PushNotificationAnswer in project jain-slee.diameter by RestComm.

the class ShClientFactoriesTest method testMessageFactoryApplicationIdChangePNA.

@Test
public void testMessageFactoryApplicationIdChangePNA() throws Exception {
    long vendor = 10415L;
    ApplicationId originalAppId = ((ShClientMessageFactoryImpl) shClientFactory).getApplicationId();
    boolean isAuth = originalAppId.getAuthAppId() != org.jdiameter.api.ApplicationId.UNDEFINED_VALUE;
    boolean isAcct = originalAppId.getAcctAppId() != org.jdiameter.api.ApplicationId.UNDEFINED_VALUE;
    boolean isVendor = originalAppId.getVendorId() != 0L;
    assertTrue("Invalid Application-Id (" + originalAppId + "). Should only, and at least, contain either Auth or Acct value.", (isAuth && !isAcct) || (!isAuth && isAcct));
    System.out.println("Default VENDOR-ID for Sh is " + originalAppId.getVendorId());
    // let's create a message and see how it comes...
    PushNotificationRequest pnr = createPushNotificationRequest();
    PushNotificationAnswer originalPNA = shClientFactory.createPushNotificationAnswer(pnr);
    BaseFactoriesTest.checkCorrectApplicationIdAVPs(isVendor, isAuth, isAcct, originalPNA);
    // now we switch..
    originalPNA = null;
    isVendor = !isVendor;
    ((ShClientMessageFactoryImpl) shClientFactory).setApplicationId(isVendor ? vendor : 0L, isAuth ? originalAppId.getAuthAppId() : originalAppId.getAcctAppId());
    // create a new message and see how it comes...
    PushNotificationAnswer changedPNA = shClientFactory.createPushNotificationAnswer(pnr);
    BaseFactoriesTest.checkCorrectApplicationIdAVPs(isVendor, isAuth, isAcct, changedPNA);
    // revert back to default
    ((ShClientMessageFactoryImpl) shClientFactory).setApplicationId(originalAppId.getVendorId(), isAuth ? originalAppId.getAuthAppId() : originalAppId.getAcctAppId());
}
Also used : ShClientMessageFactoryImpl(org.mobicents.slee.resource.diameter.sh.client.ShClientMessageFactoryImpl) PushNotificationRequest(net.java.slee.resource.diameter.sh.events.PushNotificationRequest) ApplicationId(org.jdiameter.api.ApplicationId) PushNotificationAnswer(net.java.slee.resource.diameter.sh.events.PushNotificationAnswer) Test(org.junit.Test) BaseFactoriesTest(org.mobicents.slee.resource.diameter.base.tests.factories.BaseFactoriesTest)

Aggregations

PushNotificationAnswer (net.java.slee.resource.diameter.sh.events.PushNotificationAnswer)11 Test (org.junit.Test)9 BaseFactoriesTest (org.mobicents.slee.resource.diameter.base.tests.factories.BaseFactoriesTest)9 PushNotificationRequest (net.java.slee.resource.diameter.sh.events.PushNotificationRequest)5 ApplicationId (org.jdiameter.api.ApplicationId)2 ShClientMessageFactoryImpl (org.mobicents.slee.resource.diameter.sh.client.ShClientMessageFactoryImpl)2 IOException (java.io.IOException)1 AvpNotAllowedException (net.java.slee.resource.diameter.base.events.avp.AvpNotAllowedException)1 UserIdentityAvp (net.java.slee.resource.diameter.sh.events.avp.UserIdentityAvp)1 Answer (org.jdiameter.api.Answer)1 PushNotificationAnswerImpl (org.jdiameter.common.impl.app.sh.PushNotificationAnswerImpl)1 DiameterMessageImpl (org.mobicents.slee.resource.diameter.base.events.DiameterMessageImpl)1 DiameterShMessageImpl (org.mobicents.slee.resource.diameter.sh.events.DiameterShMessageImpl)1