1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.directory.api.ldap.codec.actions.ldapMessage;
21
22
23 import org.apache.directory.api.asn1.DecoderException;
24 import org.apache.directory.api.asn1.ber.grammar.GrammarAction;
25 import org.apache.directory.api.asn1.ber.tlv.BerValue;
26 import org.apache.directory.api.asn1.ber.tlv.IntegerDecoder;
27 import org.apache.directory.api.asn1.ber.tlv.IntegerDecoderException;
28 import org.apache.directory.api.asn1.ber.tlv.TLV;
29 import org.apache.directory.api.i18n.I18n;
30 import org.apache.directory.api.ldap.codec.api.LdapMessageContainer;
31 import org.apache.directory.api.ldap.codec.api.MessageDecorator;
32 import org.apache.directory.api.ldap.model.message.Message;
33 import org.apache.directory.api.util.Strings;
34 import org.slf4j.Logger;
35 import org.slf4j.LoggerFactory;
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54 public class StoreMessageId extends GrammarAction<LdapMessageContainer<MessageDecorator<? extends Message>>>
55 {
56
57 private static final Logger LOG = LoggerFactory.getLogger( StoreMessageId.class );
58
59
60 private static final boolean IS_DEBUG = LOG.isDebugEnabled();
61
62
63
64
65
66 public StoreMessageId()
67 {
68 super( "Store MessageID" );
69 }
70
71
72
73
74
75 public void action( LdapMessageContainer<MessageDecorator<? extends Message>> container ) throws DecoderException
76 {
77
78
79 TLV tlv = container.getCurrentTLV();
80
81
82 if ( tlv.getLength() == 0 )
83 {
84 LOG.error( I18n.err( I18n.ERR_04068 ) );
85
86
87 throw new DecoderException( I18n.err( I18n.ERR_04069 ) );
88 }
89
90 BerValue value = tlv.getValue();
91
92 try
93 {
94 int messageId = IntegerDecoder.parse( value, 0, Integer.MAX_VALUE );
95
96 container.setMessageId( messageId );
97
98 if ( IS_DEBUG )
99 {
100 LOG.debug( "Ldap Message Id has been decoded : " + messageId );
101 }
102 }
103 catch ( IntegerDecoderException ide )
104 {
105 LOG.error( I18n.err( I18n.ERR_04070, Strings.dumpBytes( value.getData() ), ide
106 .getLocalizedMessage() ) );
107
108
109 throw new DecoderException( ide.getMessage(), ide );
110 }
111 }
112 }