use of net.java.slee.resource.diameter.base.events.avp.AvpNotAllowedException in project jain-slee.diameter by RestComm.
the class CxDxServerSessionImpl method sendMultimediaAuthenticationAnswer.
/*
* (non-Javadoc)
* @see net.java.slee.resource.diameter.cxdx.CxDxServerSession#sendMultimediaAuthenticationAnswer(net.java.slee.resource.diameter.cxdx.events.MultimediaAuthenticationAnswer)
*/
public void sendMultimediaAuthenticationAnswer(MultimediaAuthenticationAnswer multimediaAuthenticationAnswer) throws IOException {
DiameterMessageImpl msg = (DiameterMessageImpl) multimediaAuthenticationAnswer;
JMultimediaAuthAnswerImpl answer = new JMultimediaAuthAnswerImpl((Answer) msg.getGenericData());
try {
appSession.sendMultimediaAuthAnswer(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());
}
}
use of net.java.slee.resource.diameter.base.events.avp.AvpNotAllowedException in project jain-slee.diameter by RestComm.
the class ExpectedAvp method testOperationsAddWithValidatorOnAndRemovalNotAllowed.
/* ammendonca: removal allowed is gone...
@Test
public void testOperationsAddWithValidatorOnAndRemovalAllowed() {
instance.configure(this.getClass().getClassLoader().getResourceAsStream(validatorOnFile));
instance.setEnabled(true);
// It has session id
AccountingRequestImpl request = (AccountingRequestImpl) baseFactory.createAccountingRequest();
// <avp name="Session-Id" code="263" vendor="0" multiplicity="1" index="0"/>
AvpUtilities.setAvpAsUTF8String(request.getGenericData(), 263, request.getGenericData().getAvps(), "1346ferg5y");
// <avp name="Origin-Host" code="264" vendor="0" multiplicity="1" index="-1"/>
AvpUtilities.setAvpAsOctetString(request.getGenericData(), 264, request.getGenericData().getAvps(), clientURI);
// <avp name="Origin-Realm" code="296" vendor="0" multiplicity="1" index="-1"/>
AvpUtilities.setAvpAsOctetString(request.getGenericData(), 296, request.getGenericData().getAvps(), realmName);
AvpUtilities.setAvpAsOctetString(request.getGenericData(), 296, request.getGenericData().getAvps(), realmName);
// <avp name="Destination-Realm" code="283" vendor="0" multiplicity="1" index="-1"/>
AvpUtilities.setAvpAsOctetString(request.getGenericData(), 283, request.getGenericData().getAvps(), realmName);
// <avp name="Destination-Host" code="293" vendor="0" multiplicity="0-1" index="-1"/>
// AvpUtilities.setAvpAsOctetString(request.getGenericData(), 293, request.getGenericData().getAvps(), serverURI);
AvpUtilities.setAvpAsOctetString(request.getGenericData(), 293, request.getGenericData().getAvps(), serverHost);
// <avp name="Accounting-Record-Type" code="480" vendor="0" multiplicity="1" index="-1"/>
AvpUtilities.setAvpAsUnsigned32(request.getGenericData(), 480, request.getGenericData().getAvps(), 1);
String sessionId = AvpUtilities.getAvpAsUTF8String(263, request.getGenericData().getAvps());
Session localSession = null;
try {
localSession = stack.getSessionFactory().getNewSession(sessionId);
sendMessage(localSession, request);
System.out.println(request);
fail("Should not send this message. Message MUST contain Accounting-Record-Number AVP (485), and it is not present.");
}
catch (org.jdiameter.api.validation.AvpNotAllowedException e) {
if (e.getAvpCode() != 485 && e.getVendorId() != 0) {
fail("Message Validation failed with wrong AVP Code/Vendor-Id in Exception. Expected (485:0), Received (" + e.getAvpCode() + ":" + e.getVendorId()
+ ").");
}
}
catch (Exception e) {
Throwable cause = e;
boolean wasAvpNotAllowed = false;
while ((cause = cause.getCause()) != null) {
if (cause instanceof org.jdiameter.api.validation.AvpNotAllowedException) {
wasAvpNotAllowed = true;
org.jdiameter.api.validation.AvpNotAllowedException exc = (org.jdiameter.api.validation.AvpNotAllowedException) cause;
if (exc.getAvpCode() != 485 && exc.getVendorId() != 0) {
fail("Message Validation failed with wrong AVP Code/Vendor-Id in Exception. Expected (485:0), Received (" + exc.getAvpCode() + ":"
+ exc.getVendorId() + ").");
}
}
}
if (!wasAvpNotAllowed) {
fail("Message failed to be sent for wrong reason. Expected AvpNotAllowedException, Received " + e);
}
}
// <avp name="Accounting-Record-Number" code="485" vendor="0" multiplicity="1" index="-1"/>
AvpUtilities.setAvpAsUnsigned32(request.getGenericData(), 485, request.getGenericData().getAvps(), 1);
// In here we send the message actually. It is OK!
try {
sendMessage(localSession, request);
}
catch (Exception e) {
fail("Failed to send message when it should succeed! Exception: " + e);
}
// <avp name="Acct-Application-Id" code="259" vendor="0" multiplicity="0-1" index="-1"/>
AvpUtilities.setAvpAsUnsigned32(request.getGenericData(), 259, request.getGenericData().getAvps(), 1);
// Again, in here we send the message actually. It is OK!
try {
sendMessage(localSession, request);
}
catch (Exception e) {
fail("Failed to send message when it should succeed! Exception: " + e);
}
// <!-- FORBBIDEN -->
// <avp name="Auth-Application-Id" code="258" vendor="0" multiplicity="0" index="-1"/>
try {
AvpUtilities.setAvpAsUnsigned32(request.getGenericData(), 258, request.getGenericData().getAvps(), 1);
// Now send should fail. Message has AVP "Auth-Application-Id", not valid in ACR.
sendMessage(localSession, request);
fail("Should not send this message. Message MUST NOT contain Auth-Application-Id AVP (258), and it is present.");
}
catch (AvpNotAllowedException e) {
if (e.getAvpCode() != 258 && e.getVendorId() != 0) {
fail("Message Validation failed with wrong AVP Code/Vendor-Id in Exception. Expected (258:0), Received (" + e.getAvpCode() + ":" + e.getVendorId()
+ ").");
}
}
catch (Exception e) {
fail("Message failed to be sent for wrong reason. Expected AvpNotAllowedException, Received " + e);
}
// This is just in case
Map<ExpectedAvp, ExpectedAvp> expectedAvps = new HashMap<ExpectedAvp, ExpectedAvp>();
ExpectedAvp a = new ExpectedAvp();
a.code = 263;
a.count = 1;
expectedAvps.put(a, a);
a = new ExpectedAvp();
a.code = 264;
a.count = 1;
expectedAvps.put(a, a);
a = new ExpectedAvp();
a.code = 296;
a.count = 1;
expectedAvps.put(a, a);
a = new ExpectedAvp();
a.code = 283;
a.count = 1;
expectedAvps.put(a, a);
a = new ExpectedAvp();
a.code = 480;
a.count = 1;
expectedAvps.put(a, a);
a = new ExpectedAvp();
a.code = 485;
a.count = 1;
expectedAvps.put(a, a);
a = new ExpectedAvp();
a.code = 259;
a.count = 1;
expectedAvps.put(a, a);
a = new ExpectedAvp();
a.code = 293;
a.count = 1;
expectedAvps.put(a, a);
testPresentAvps(request.getGenericData().getAvps(), expectedAvps);
}
*/
@Test
public void testOperationsAddWithValidatorOnAndRemovalNotAllowed() {
instance.configure(this.getClass().getClassLoader().getResourceAsStream(validatorOnFile));
instance.setEnabled(true);
// It has session id
AccountingRequestImpl request = (AccountingRequestImpl) baseFactory.createAccountingRequest(new DiameterAvpImpl[] { new DiameterAvpImpl(263, 0L, 0, 1, "xxx".getBytes(), DiameterAvpType.UTF8_STRING) });
// <avp name="Session-Id" code="263" vendor="0" multiplicity="1" index="0"/>
try {
AvpUtilities.setAvpAsUTF8String(request.getGenericData(), 263, request.getGenericData().getAvps(), "1346ferg5y");
fail("Session-Id can not be set twice.");
} catch (AvpNotAllowedException e) {
if (e.getAvpCode() != 258 && e.getVendorId() != 0) {
fail("Message Validation failed with wrong AVP Code/Vendor-Id in Exception. Expected (258:0), Received (" + e.getAvpCode() + ":" + e.getVendorId() + ").");
}
} catch (Exception e) {
fail("Message failed to be sent for wrong reason. Expected AvpNotAllowedException, Received " + e);
}
// <avp name="Origin-Host" code="264" vendor="0" multiplicity="1" index="-1"/>
if (!request.hasOriginHost())
AvpUtilities.setAvpAsOctetString(request.getGenericData(), 264, request.getGenericData().getAvps(), clientURI);
// <avp name="Origin-Realm" code="296" vendor="0" multiplicity="1" index="-1"/>
if (!request.hasOriginRealm())
AvpUtilities.setAvpAsOctetString(request.getGenericData(), 296, request.getGenericData().getAvps(), realmName);
// <avp name="Destination-Host" code="293" vendor="0" multiplicity="0-1" index="-1"/>
AvpUtilities.setAvpAsOctetString(request.getGenericData(), 293, request.getGenericData().getAvps(), serverURI);
// <avp name="Destination-Realm" code="283" vendor="0" multiplicity="1" index="-1"/>
AvpUtilities.setAvpAsOctetString(request.getGenericData(), 283, request.getGenericData().getAvps(), realmName);
// <avp name="Accounting-Record-Type" code="480" vendor="0" multiplicity="1" index="-1"/>
AvpUtilities.setAvpAsUnsigned32(request.getGenericData(), 480, request.getGenericData().getAvps(), 1);
String sessionId = AvpUtilities.getAvpAsUTF8String(263, request.getGenericData().getAvps());
Session localSession = null;
try {
localSession = stack.getSessionFactory().getNewSession(sessionId);
sendMessage(localSession, request);
fail("Should not send this message. Message MUST contain Accounting-Record-Number AVP (485), and it is not present.");
} catch (org.jdiameter.api.validation.AvpNotAllowedException e) {
if (e.getAvpCode() != 485 && e.getVendorId() != 0) {
fail("Message Validation failed with wrong AVP Code/Vendor-Id in Exception. Expected (485:0), Received (" + e.getAvpCode() + ":" + e.getVendorId() + ").");
}
} catch (Exception e) {
Throwable cause = e;
boolean wasAvpNotAllowed = false;
while ((cause = cause.getCause()) != null) {
if (cause instanceof org.jdiameter.api.validation.AvpNotAllowedException) {
wasAvpNotAllowed = true;
org.jdiameter.api.validation.AvpNotAllowedException exc = (org.jdiameter.api.validation.AvpNotAllowedException) cause;
if (exc.getAvpCode() != 485 && exc.getVendorId() != 0) {
fail("Message Validation failed with wrong AVP Code/Vendor-Id in Exception. Expected (485:0), Received (" + exc.getAvpCode() + ":" + exc.getVendorId() + ").");
}
}
}
if (!wasAvpNotAllowed) {
fail("Message failed to be sent for wrong reason. Expected AvpNotAllowedException, Received " + e);
}
}
// <avp name="Accounting-Record-Number" code="485" vendor="0" multiplicity="1" index="-1"/>
AvpUtilities.setAvpAsUnsigned32(request.getGenericData(), 485, request.getGenericData().getAvps(), 1);
// In here we send the message actually. It is OK!
try {
sendMessage(localSession, request);
} catch (Exception e) {
fail("Failed to send message when it should succeed! Exception: " + e);
}
// Message should already come with Acct-Application-Id.. but still..
try {
// <avp name="Acct-Application-Id" code="259" vendor="0" multiplicity="0-1" index="-1"/>
AvpUtilities.setAvpAsUnsigned32(request.getGenericData(), 259, request.getGenericData().getAvps(), 1);
} catch (AvpNotAllowedException e) {
if (e.getAvpCode() != 259 && e.getVendorId() != 0) {
fail("Message Validation failed with wrong AVP Code/Vendor-Id in Exception. Expected (259:0), Received (" + e.getAvpCode() + ":" + e.getVendorId() + ").");
}
}
// Again, in here we send the message actually. It is OK!
try {
sendMessage(localSession, request);
} catch (Exception e) {
fail("Failed to send message when it should succeed! Exception: " + e);
}
// <avp name="Auth-Application-Id" code="258" vendor="0" multiplicity="0" index="-1"/>
try {
AvpUtilities.setAvpAsUnsigned32(request.getGenericData(), 258, request.getGenericData().getAvps(), 1);
// Now send should fail. Message has AVP "Auth-Application-Id", not valid in ACR.
sendMessage(localSession, request);
fail("Should not send this message. Message MUST NOT contain Auth-Application-Id AVP (258), and it is present.");
} catch (AvpNotAllowedException e) {
if (e.getAvpCode() != 258 && e.getVendorId() != 0) {
fail("Message Validation failed with wrong AVP Code/Vendor-Id in Exception. Expected (258:0), Received (" + e.getAvpCode() + ":" + e.getVendorId() + ").");
}
} catch (Exception e) {
fail("Message failed to be sent for wrong reason. Expected AvpNotAllowedException, Received " + e);
}
// Just in case.
Map<ExpectedAvp, ExpectedAvp> expectedAvps = new HashMap<ExpectedAvp, ExpectedAvp>();
ExpectedAvp a = new ExpectedAvp();
a.code = 263;
a.count = 1;
expectedAvps.put(a, a);
a = new ExpectedAvp();
a.code = 264;
a.count = 1;
expectedAvps.put(a, a);
a = new ExpectedAvp();
a.code = 296;
a.count = 1;
expectedAvps.put(a, a);
a = new ExpectedAvp();
a.code = 283;
a.count = 1;
expectedAvps.put(a, a);
a = new ExpectedAvp();
a.code = 480;
a.count = 1;
expectedAvps.put(a, a);
a = new ExpectedAvp();
a.code = 485;
a.count = 1;
expectedAvps.put(a, a);
a = new ExpectedAvp();
a.code = 259;
a.count = 1;
expectedAvps.put(a, a);
a = new ExpectedAvp();
a.code = 293;
a.count = 1;
expectedAvps.put(a, a);
testPresentAvps(request.getGenericData().getAvps(), expectedAvps);
}
use of net.java.slee.resource.diameter.base.events.avp.AvpNotAllowedException in project jain-slee.diameter by RestComm.
the class CreditControlClientSessionImpl method sendInitialCreditControlRequest.
/*
* (non-Javadoc)
*
* @seenet.java.slee.resource.diameter.cca.CreditControlClientSession#
* sendInitialCreditControlRequest
* (net.java.slee.resource.diameter.cca.events.CreditControlRequest)
*/
public void sendInitialCreditControlRequest(CreditControlRequest ccr) throws IOException {
// FIXME: should this affect FSM ?
ccr.setCcRequestType(CcRequestType.INITIAL_REQUEST);
validateState(ccr);
DiameterMessageImpl msg = (DiameterMessageImpl) ccr;
try {
session.sendCreditControlRequest(new JCreditControlRequestImpl((Request) msg.getGenericData()));
} catch (org.jdiameter.api.validation.AvpNotAllowedException e) {
throw new AvpNotAllowedException("Message validation failed.", e, e.getAvpCode(), e.getVendorId());
} catch (Exception e) {
throw new IOException("Failed to send message, due to: " + e);
}
}
use of net.java.slee.resource.diameter.base.events.avp.AvpNotAllowedException in project jain-slee.diameter by RestComm.
the class CreditControlClientSessionImpl method sendTerminationCreditControlRequest.
/*
* (non-Javadoc)
*
* @seenet.java.slee.resource.diameter.cca.CreditControlClientSession#
* sendTerminationCreditControlRequest
* (net.java.slee.resource.diameter.cca.events.CreditControlRequest)
*/
public void sendTerminationCreditControlRequest(CreditControlRequest ccr) throws IOException {
// This should not be used to terminate sub-sessions!
// FIXME: Should this come already in the CCR?
ccr.setCcRequestType(CcRequestType.TERMINATION_REQUEST);
validateState(ccr);
DiameterMessageImpl msg = (DiameterMessageImpl) ccr;
try {
session.sendCreditControlRequest(new JCreditControlRequestImpl((Request) msg.getGenericData()));
} catch (org.jdiameter.api.validation.AvpNotAllowedException e) {
throw new AvpNotAllowedException("Message validation failed.", e, e.getAvpCode(), e.getVendorId());
} catch (Exception e) {
throw new IOException("Failed to send message, due to: " + e);
}
}
use of net.java.slee.resource.diameter.base.events.avp.AvpNotAllowedException in project jain-slee.diameter by RestComm.
the class CreditControlServerSessionImpl method sendCreditControlAnswer.
/*
* (non-Javadoc)
*
* @see net.java.slee.resource.diameter.cca.CreditControlServerSession#sendCreditControlAnswer(net.java.slee.resource.diameter.cca.events.CreditControlAnswer)
*/
public void sendCreditControlAnswer(CreditControlAnswer cca) throws IOException {
fetchCurrentState(cca);
DiameterMessageImpl msg = (DiameterMessageImpl) cca;
try {
session.sendCreditControlAnswer(new JCreditControlAnswerImpl((Answer) msg.getGenericData()));
} catch (org.jdiameter.api.validation.AvpNotAllowedException e) {
AvpNotAllowedException anae = new AvpNotAllowedException("Message validation failed.", e, e.getAvpCode(), e.getVendorId());
throw anae;
} catch (Exception e) {
e.printStackTrace();
IOException ioe = new IOException("Failed to send message, due to: " + e);
throw ioe;
}
}
Aggregations