public void decode(AsnInputStream ais) throws ParseException { try { AsnInputStream localAis = ais.readSequenceStream(); while (true) { if (localAis.available() == 0) return; int tag = localAis.readTag(); if (localAis.isTagPrimitive() || localAis.getTagClass() != Tag.CLASS_APPLICATION) throw new ParseException( PAbortCauseType.IncorrectTxPortion, null, "Error decoding TC-Uni: DialogPortion and Component portion must be constructive and has " + "tag class CLASS_APPLICATION"); switch (tag) { case DialogPortion._TAG: this.dp = TcapFactory.createDialogPortion(localAis); break; case Component._COMPONENT_TAG: AsnInputStream compAis = localAis.readSequenceStream(); List<Component> cps = new ArrayList<Component>(); // its iterator :) while (compAis.available() > 0) { Component c = TcapFactory.createComponent(compAis); if (c == null) { break; } cps.add(c); } this.component = new Component[cps.size()]; this.component = cps.toArray(this.component); break; default: throw new ParseException( PAbortCauseType.IncorrectTxPortion, null, "Error decoding TC-Uni: DialogPortion and Componebt parsing: bad tag - " + tag); } } } catch (IOException e) { throw new ParseException( PAbortCauseType.BadlyFormattedTxPortion, null, "IOException while decoding " + "TC-Uni: " + e.getMessage(), e); } catch (AsnException e) { throw new ParseException( PAbortCauseType.BadlyFormattedTxPortion, null, "AsnException while decoding " + "TC-Uni: " + e.getMessage(), e); } }
@Test(groups = {"functional.decode"}) public void testDecodeWithParaSequ() throws IOException, ParseException { byte[] b = this.getData(); AsnInputStream asnIs = new AsnInputStream(b); Component comp = TcapFactory.createComponent(asnIs); assertEquals(ComponentType.Invoke, comp.getType()); Invoke invokeComp = (Invoke) comp; assertTrue(12L == invokeComp.getInvokeId()); OperationCode oc = invokeComp.getOperationCode(); assertNotNull(oc); assertTrue(59 == oc.getLocalOperationCode()); assertEquals(OperationCodeType.Local, oc.getOperationType()); Parameter p = invokeComp.getParameter(); assertEquals(Tag.CLASS_UNIVERSAL, p.getTagClass()); assertEquals(false, p.isPrimitive()); assertEquals(Tag.SEQUENCE, p.getTag()); assertTrue( Arrays.equals( new byte[] { 0x04, 0x01, 0x0f, 0x04, 0x10, (byte) 0xaa, (byte) 0x98, (byte) 0xac, (byte) 0xa6, 0x5a, (byte) 0xcd, 0x62, 0x36, 0x19, 0x0e, 0x37, (byte) 0xcb, (byte) 0xe5, 0x72, (byte) 0xb9, 0x11 }, p.getData())); Parameter[] params = invokeComp.getParameter().getParameters(); assertEquals(2, params.length); p = params[0]; assertEquals(Tag.CLASS_UNIVERSAL, p.getTagClass()); assertEquals(true, p.isPrimitive()); assertEquals(Tag.STRING_OCTET, p.getTag()); assertTrue(Arrays.equals(new byte[] {0x0f}, p.getData())); p = params[1]; assertEquals(Tag.CLASS_UNIVERSAL, p.getTagClass()); assertEquals(true, p.isPrimitive()); assertEquals(Tag.STRING_OCTET, p.getTag()); assertTrue( Arrays.equals( new byte[] { (byte) 0xaa, (byte) 0x98, (byte) 0xac, (byte) 0xa6, 0x5a, (byte) 0xcd, 0x62, 0x36, 0x19, 0x0e, 0x37, (byte) 0xcb, (byte) 0xe5, 0x72, (byte) 0xb9, 0x11 }, p.getData())); b = this.getDataFull(); asnIs = new AsnInputStream(b); comp = TcapFactory.createComponent(asnIs); assertEquals(ComponentType.Invoke, comp.getType()); invokeComp = (Invoke) comp; assertEquals(-5L, (long) invokeComp.getInvokeId()); assertEquals(2L, (long) invokeComp.getLinkedId()); oc = invokeComp.getOperationCode(); assertNotNull(oc); assertEquals(OperationCodeType.Global, oc.getOperationType()); assertTrue(Arrays.equals(new long[] {1, 0, 0, 1}, oc.getGlobalOperationCode())); p = invokeComp.getParameter(); assertEquals(Tag.CLASS_UNIVERSAL, p.getTagClass()); assertEquals(true, p.isPrimitive()); assertEquals(Tag.STRING_OCTET, p.getTag()); assertTrue(Arrays.equals(new byte[] {11, 22, 33}, p.getData())); }