asd
Alejandro Acuña
2024-09-16 816cb391a192e357426312ab8e591fd49d1d242e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
package art.servers.gost.atex5;
 
import art.servers.gost.access.configuration.Configuration;
import art.servers.gost.access.configuration.ConfigurationDetail_ATEX5;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.util.Set;
 
import javax.xml.namespace.QName;
import javax.xml.soap.MessageFactory;
import javax.xml.soap.MimeHeaders;
import javax.xml.soap.SOAPMessage;
import javax.xml.ws.handler.MessageContext;
import javax.xml.ws.handler.soap.SOAPHandler;
import javax.xml.ws.handler.soap.SOAPMessageContext;
 
public class SOAPLoggingHandlerVehiculo implements SOAPHandler<SOAPMessageContext>
{
    private String plate = null;
 
    // change this to redirect output if desired
    private static PrintStream out = System.out;
 
    public SOAPLoggingHandlerVehiculo(String plate)
    {
        super();
        this.plate = plate;
    }
    
    public Set<QName> getHeaders()
    {
        return null;
    }
 
    public boolean handleMessage(SOAPMessageContext smc)
    {
        try
        {
            Boolean outboundProperty = (Boolean) smc.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
 
            if (outboundProperty == true)
            {
                signature(smc);
            }
        } 
        catch (Exception e) 
        {
            e.printStackTrace();
        }        
        
        Configuration configuration = ((Configuration)art.servers.gost.access.Shared.configuration);
        ConfigurationDetail_ATEX5 configurationATEX5 = configuration.detail.atex5;
        
        if (configurationATEX5.debug == true)
        {
            logToSystemOut(smc);
        }
        
        return true;
    }
 
    
    public boolean handleFault(SOAPMessageContext smc)
    {
        logToSystemOut(smc);
        return true;
    }
 
    // nothing to clean up
    
    public void close(MessageContext messageContext)
    {
    }
 
    /*
     * Check the MESSAGE_OUTBOUND_PROPERTY in the context
     * to see if this is an outgoing or incoming message.
     * Write a brief message to the print stream and
     * output the message. The writeTo() method can throw
     * SOAPException or IOException
     */
    private void logToSystemOut(SOAPMessageContext smc)
    {
        Boolean outboundProperty = (Boolean) smc.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
 
        if (outboundProperty.booleanValue())
        {
            out.println("\nOutbound message:");
        } 
        else
        {
            out.println("\nInbound message:");
        }
 
        try 
        {
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            smc.getMessage().writeTo(bos);
            String message = new String(bos.toByteArray());
            System.out.println(message.toString().replaceAll("&lt;", "<").replaceAll("&gt;", ">"));
            bos.close();
        } 
        catch (Exception exception) 
        {
            System.out.println("Exception in handler: " + exception);
        }
    }
    
 
    
    private void signature(SOAPMessageContext smc) throws Exception
    {
        String xml = RequestXML_SolicitudConsultaVehiculoAtex.getXMLDocument(plate);
        ByteArrayInputStream bis = new ByteArrayInputStream(xml.getBytes());
        MessageFactory factory = MessageFactory.newInstance();
        SOAPMessage message = factory.createMessage(new MimeHeaders(), bis);
        message.saveChanges();
        smc.setMessage(message);
    }
 
 
    
}