Created
October 18, 2016 11:28
-
-
Save akkida746/5351ca285b89719ace7d1f5af19e79d4 to your computer and use it in GitHub Desktop.
SOAP Handler for tracking request type using SOAP Message
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class SoapHandler extends SpringBeanAutowiringSupport implements | |
SOAPHandler<SOAPMessageContext> { | |
@Resource | |
private OrderRequesDataBean OrderRequesDataBean; | |
@Override | |
public boolean handleMessage(SOAPMessageContext context) { | |
Boolean outboundProperty = (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY); | |
if (!outboundProperty) { | |
try { | |
Node firstChild = null; | |
Node nextSibiling = null; | |
String requestType = ""; | |
SOAPMessage soapMsg = context.getMessage(); | |
SOAPEnvelope soapEnv = soapMsg.getSOAPPart().getEnvelope(); | |
SOAPBody body = soapEnv.getBody(); | |
ByteArrayOutputStream out = new ByteArrayOutputStream(); | |
soapMsg.writeTo(out); | |
String strMsg = new String(out.toByteArray()); | |
OrderRequesDataBean.setSoapMsg(strMsg); | |
firstChild = body.getFirstChild(); | |
if(firstChild.getNextSibling() != null) | |
requestType = firstChild.getNextSibling().getLocalName(); | |
else | |
requestType = firstChild.getLocalName(); | |
OrderRequesDataBean.setRequestType(requestType); | |
/*** Store Id ***/ | |
Node store_location = body.getElementsByTagName("store_location").item(0); | |
if (store_location != null) { | |
Node node = store_location.getAttributes().getNamedItem("location_cd"); | |
if(node != null) | |
OrderRequesDataBean.setLocationCd(node.getNodeValue()); | |
} | |
/*** Order Id ***/ | |
Node order = body.getElementsByTagName("order").item(0); | |
if (order != null) { | |
Node node = order.getAttributes().getNamedItem("request_id"); | |
if(node != null) | |
OrderRequesDataBean.setRequestId(Integer.valueOf(node.getNodeValue())); | |
node = order.getAttributes().getNamedItem("order_id"); | |
if(node != null) | |
OrderRequesDataBean.setOrderId(order.getAttributes().getNamedItem("order_id").getNodeValue()); | |
} | |
/*** Item Status ***/ | |
Node item = body.getElementsByTagName("item").item(0); | |
if (item != null) { | |
Node node = item.getAttributes().getNamedItem("item_status"); | |
if(node != null){ | |
OrderRequesDataBean.setItemStatus(node.getNodeValue()); | |
} | |
} | |
/*** Order Id for Lookup Data ***/ | |
Node lookup_data = body.getElementsByTagName("lookup_data").item(0); | |
if (lookup_data != null) { | |
Node node = lookup_data.getAttributes().getNamedItem("order_id"); | |
if(node != null) | |
OrderRequesDataBean.setOrderId(node.getNodeValue()); | |
} | |
} catch (SOAPException | IOException e) { | |
e.printStackTrace(); | |
} | |
} | |
return true; | |
} | |
public SOAPMessage toMessage(InputStream is) throws IOException, SOAPException { | |
MessageFactory messageFactory = MessageFactory.newInstance(); | |
return messageFactory.createMessage(null, is); | |
} | |
@Override | |
public boolean handleFault(SOAPMessageContext context) { | |
// TODO Auto-generated method stub | |
return false; | |
} | |
@Override | |
public void close(MessageContext context) { | |
// TODO Auto-generated method stub | |
} | |
@Override | |
public Set<QName> getHeaders() { | |
// TODO Auto-generated method stub | |
return null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment