@Override
    public void execute(Exchange exchange) throws SmppException {
        DataSm dataSm = createDataSm(exchange);

        if (log.isDebugEnabled()) {
            log.debug("Sending a data short message for exchange id '{}'...", exchange.getExchangeId());
        }

        DataSmResult result;
        try {
            result = session.dataShortMessage(
                    dataSm.getServiceType(),
                    TypeOfNumber.valueOf(dataSm.getSourceAddrTon()),
                    NumberingPlanIndicator.valueOf(dataSm.getSourceAddrNpi()),
                    dataSm.getSourceAddr(),
                    TypeOfNumber.valueOf(dataSm.getDestAddrTon()),
                    NumberingPlanIndicator.valueOf(dataSm.getDestAddrNpi()),
                    dataSm.getDestAddress(),
                    new ESMClass(dataSm.getEsmClass()),
                    new RegisteredDelivery(dataSm.getRegisteredDelivery()),
                    DataCodings.newInstance(dataSm.getDataCoding()),
                    dataSm.getOptionalParameters());
        } catch (Exception e) {
            throw new SmppException(e);
        }

        if (log.isDebugEnabled()) {
            log.debug("Sent a data short message for exchange id '{}' and message id '{}'",
                    exchange.getExchangeId(), result.getMessageId());
        }

        Message message = ExchangeHelper.getResultMessage(exchange);
        message.setHeader(SmppConstants.ID, result.getMessageId());
        message.setHeader(SmppConstants.OPTIONAL_PARAMETERS, createOptionalParameterByName(result.getOptionalParameters()));
        message.setHeader(SmppConstants.OPTIONAL_PARAMETER, createOptionalParameterByCode(result.getOptionalParameters()));
    }
@SuppressWarnings("unchecked")
    @Test
    public void executeWithOptionalParameterNewStyle() throws Exception {
        Exchange exchange = new DefaultExchange(new DefaultCamelContext(), ExchangePattern.InOut);
        exchange.getIn().setHeader(SmppConstants.COMMAND, "DataSm");
        Map<Short, Object> optionalParameters = new LinkedHashMap<>();
        // standard optional parameter
        optionalParameters.put((short) 0x0202, "1292".getBytes("UTF-8"));
        optionalParameters.put((short) 0x001D, "urgent");
        optionalParameters.put((short) 0x0005, Byte.valueOf("4"));
        optionalParameters.put((short) 0x0008, (short) 2);
        optionalParameters.put((short) 0x0017, 3600000);
        optionalParameters.put((short) 0x130C, null);
        // vendor specific optional parameter
        optionalParameters.put((short) 0x2150, "0815".getBytes("UTF-8"));
        optionalParameters.put((short) 0x2151, "0816");
        optionalParameters.put((short) 0x2152, Byte.valueOf("6"));
        optionalParameters.put((short) 0x2153, (short) 9);
        optionalParameters.put((short) 0x2154, 7400000);
        optionalParameters.put((short) 0x2155, null);
        exchange.getIn().setHeader(SmppConstants.OPTIONAL_PARAMETER, optionalParameters);
        when(session.dataShortMessage(eq("CMT"), eq(TypeOfNumber.UNKNOWN), eq(NumberingPlanIndicator.UNKNOWN), eq("1616"),
                eq(TypeOfNumber.UNKNOWN), eq(NumberingPlanIndicator.UNKNOWN), eq("1717"), eq(new ESMClass()),
                eq(new RegisteredDelivery((byte) 1)), eq(DataCodings.newInstance((byte) 0)),
                eq(new OptionalParameter.OctetString(Tag.SOURCE_SUBADDRESS, "1292")),
                eq(new OptionalParameter.COctetString(Tag.ADDITIONAL_STATUS_INFO_TEXT.code(), "urgent")),
                eq(new OptionalParameter.Byte(Tag.DEST_ADDR_SUBUNIT, (byte) 4)),
                eq(new OptionalParameter.Short(Tag.DEST_TELEMATICS_ID.code(), (short) 2)),
                eq(new OptionalParameter.Int(Tag.QOS_TIME_TO_LIVE, 3600000)),
                eq(new OptionalParameter.Null(Tag.ALERT_ON_MESSAGE_DELIVERY)),
                eq(new OptionalParameter.OctetString((short) 0x2150, "1292", "UTF-8")),
                eq(new OptionalParameter.COctetString((short) 0x2151, "0816")),
                eq(new OptionalParameter.Byte((short) 0x2152, (byte) 6)),
                eq(new OptionalParameter.Short((short) 0x2153, (short) 9)),
                eq(new OptionalParameter.Int((short) 0x2154, 7400000)),
                eq(new OptionalParameter.Null((short) 0x2155))))
                .thenReturn(new DataSmResult(
                        new MessageId("1"), new OptionalParameter[] {
                                new OptionalParameter.Source_subaddress("1292".getBytes()),
                                new OptionalParameter.Additional_status_info_text("urgent"),
                                new OptionalParameter.Dest_addr_subunit((byte) 4),
                                new OptionalParameter.Dest_telematics_id((short) 2),
                                new OptionalParameter.Qos_time_to_live(3600000),
                                new OptionalParameter.Alert_on_message_delivery((byte) 0) }));

        command.execute(exchange);

        assertEquals(3, exchange.getMessage().getHeaders().size());
        assertEquals("1", exchange.getMessage().getHeader(SmppConstants.ID));

        Map<String, String> optParamMap = exchange.getMessage().getHeader(SmppConstants.OPTIONAL_PARAMETERS, Map.class);
        assertEquals(6, optParamMap.size());
        assertEquals("1292", optParamMap.get("SOURCE_SUBADDRESS"));
        assertEquals("urgent", optParamMap.get("ADDITIONAL_STATUS_INFO_TEXT"));
        assertEquals("4", optParamMap.get("DEST_ADDR_SUBUNIT"));
        assertEquals("2", optParamMap.get("DEST_TELEMATICS_ID"));
        assertEquals("3600000", optParamMap.get("QOS_TIME_TO_LIVE"));
        assertEquals("0", optParamMap.get("ALERT_ON_MESSAGE_DELIVERY"));

        Map<Short, Object> optionalResultParameter
                = exchange.getMessage().getHeader(SmppConstants.OPTIONAL_PARAMETER, Map.class);
        assertEquals(6, optionalResultParameter.size());
        assertArrayEquals("1292".getBytes("UTF-8"), (byte[]) optionalResultParameter.get((short) 0x0202));
        assertEquals("urgent", optionalResultParameter.get((short) 0x001D));
        assertEquals((byte) 4, optionalResultParameter.get((short) 0x0005));
        assertEquals((short) 2, optionalResultParameter.get((short) 0x0008));
        assertEquals(3600000, optionalResultParameter.get((short) 0x0017));
        assertEquals((byte) 0, optionalResultParameter.get((short) 0x130C));
    }