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 SOAPLoggingHandlerPersona implements SOAPHandler<SOAPMessageContext>
|
{
|
private String nifcif = null;
|
|
// change this to redirect output if desired
|
private static PrintStream out = System.out;
|
|
public SOAPLoggingHandlerPersona(String nifcif)
|
{
|
super();
|
this.nifcif = nifcif;
|
}
|
|
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());
|
bos.close();
|
}
|
catch (Exception exception)
|
{
|
System.out.println("Exception in handler: " + exception);
|
}
|
}
|
|
|
|
private void signature(SOAPMessageContext smc) throws Exception
|
{
|
String xml = RequestXML_SolicitudConsultaPersonaAtex.getXMLDocument(nifcif);
|
ByteArrayInputStream bis = new ByteArrayInputStream(xml.getBytes());
|
MessageFactory factory = MessageFactory.newInstance();
|
SOAPMessage message = factory.createMessage(new MimeHeaders(), bis);
|
message.saveChanges();
|
smc.setMessage(message);
|
}
|
|
|
|
}
|