public void enqueue(MessageContext messageContext) { if (shutdown) { log.warn("The queue is shutting down... Not accepting the new events..."); return; } messageContext.getEnvelope().build(); boolean queued = serverQueue.offer(messageContext); if (queued) { if (serverQueue.size() > 0) { exec.submit(new ServerWorker()); } } else { log.warn("Queue filled up. Event rejected"); if (log.isDebugEnabled()) { log.debug("Event rejected : " + messageContext.getEnvelope().toString()); } } }
/** * This is to create a separate thread to process business logic invocation. We create a AsyncMessageReceiverWorker * which internally calls the message receiver specified for the operation. * * We send the ACK through the incoming transport and reply through the address specified in replyTo address. * @param messageCtx msgContext the current MessageContext */ private void processAsAsync(MessageContext messageCtx) { AsyncMessageReceiverWorker worker = new AsyncMessageReceiverWorker( messageCtx); if (messageCtx.isDoingMTOM() || messageCtx.isDoingSwA()) { // If we are doing MTOM or SWA then we need to build with attachment, because we are going to close the incoming connection messageCtx.getEnvelope().buildWithAttachments(); } else { // We need to build the envelop since we are going to close the input stream messageCtx.getEnvelope().build(); } messageCtx.getConfigurationContext().getThreadPool().execute( worker); }
/** * Converts a given AXIOM {@link org.apache.axiom.soap.SOAPEnvelope} to a {@link Document}. * * @param envelope the SOAP envelope to be converted * @return the converted document * @throws IllegalArgumentException in case of errors * @see org.apache.rampart.util.Axis2Util.getDocumentFromSOAPEnvelope(SOAPEnvelope, boolean) */ public static Document toDocument(SOAPEnvelope envelope) { try { if (envelope instanceof Element) { return ((Element) envelope).getOwnerDocument(); } else { ByteArrayOutputStream bos = new ByteArrayOutputStream(); envelope.build(); envelope.serialize(bos); ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray()); DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); documentBuilderFactory.setNamespaceAware(true); return documentBuilderFactory.newDocumentBuilder().parse(bis); } } catch (Exception ex) { throw new IllegalArgumentException("Error in converting SOAP Envelope to Document", ex); } }
/** * This is to create a separate thread to process business logic invocation. We create a AsyncMessageReceiverWorker * which internally calls the message receiver specified for the operation. * * We send the ACK through the incoming transport and reply through the address specified in replyTo address. * @param messageCtx msgContext the current MessageContext */ private void processAsAsync(MessageContext messageCtx) { AsyncMessageReceiverWorker worker = new AsyncMessageReceiverWorker( messageCtx); if (messageCtx.isDoingMTOM() || messageCtx.isDoingSwA()) { // If we are doing MTOM or SWA then we need to build with attachment, because we are going to close the incoming connection messageCtx.getEnvelope().buildWithAttachments(); } else { // We need to build the envelop since we are going to close the input stream messageCtx.getEnvelope().build(); } messageCtx.getConfigurationContext().getThreadPool().execute( worker); }
/** * Converts a given AXIOM {@link org.apache.axiom.soap.SOAPEnvelope} to a {@link Document}. * * @param envelope the SOAP envelope to be converted * @return the converted document * @throws IllegalArgumentException in case of errors */ public static Document toDocument(SOAPEnvelope envelope) { try { if (envelope instanceof Element) { return ((Element) envelope).getOwnerDocument(); } else { ByteArrayOutputStream bos = new ByteArrayOutputStream(); envelope.build(); envelope.serialize(bos); ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray()); DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactoryUtils.newInstance(); documentBuilderFactory.setNamespaceAware(true); return documentBuilderFactory.newDocumentBuilder().parse(bis); } } catch (Exception ex) { throw new IllegalArgumentException("Error in converting SOAP Envelope to Document", ex); } }
/** * Converts a given AXIOM {@link org.apache.axiom.soap.SOAPEnvelope} to a {@link Document}. * * @param envelope the SOAP envelope to be converted * @return the converted document * @throws IllegalArgumentException in case of errors */ public static Document toDocument(SOAPEnvelope envelope) { try { if (envelope instanceof Element) { return ((Element) envelope).getOwnerDocument(); } else { ByteArrayOutputStream bos = new ByteArrayOutputStream(); envelope.build(); envelope.serialize(bos); ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray()); DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactoryUtils.newInstance(); documentBuilderFactory.setNamespaceAware(true); return documentBuilderFactory.newDocumentBuilder().parse(bis); } } catch (Exception ex) { throw new IllegalArgumentException("Error in converting SOAP Envelope to Document", ex); } }
public boolean offer(MessageContext messageContext) { lock.lock(); try { if (messageContext != null) { messageContext.getEnvelope().build(); messageList.offer(messageContext); // Notify observers notifyMessageAddition(messageContext.getMessageID()); if (log.isDebugEnabled()) { log.debug("Message with id " + messageContext.getMessageID() + " stored"); } } } finally { lock.unlock(); } return true; }
/** * Create a DOM Document using the org.apache.axiom.soap.SOAPEnvelope * * @param env An org.apache.axiom.soap.SOAPEnvelope instance * @return the DOM Document of the given SOAP Envelope */ public static Document getDocumentFromSOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope env) { env.build(); //Check the namespace and find SOAP version and factory String nsURI; OMMetaFactory metaFactory = OMAbstractFactory.getMetaFactory(OMAbstractFactory.FEATURE_DOM); SOAPFactory factory; if (env.getNamespace().getNamespaceURI() .equals(SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI)) { nsURI = SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI; factory = metaFactory.getSOAP11Factory(); } else { nsURI = SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI; factory = metaFactory.getSOAP12Factory(); } StAXSOAPModelBuilder stAXSOAPModelBuilder = new StAXSOAPModelBuilder(env.getXMLStreamReader(), factory, nsURI); SOAPEnvelope envelope = (stAXSOAPModelBuilder).getSOAPEnvelope(); envelope.build(); Element envElem = (Element)envelope; return envElem.getOwnerDocument(); }
/** * Create a DOM Document using the org.apache.axiom.soap.SOAPEnvelope * * @param env An org.apache.axiom.soap.SOAPEnvelope instance * @return the org.apache.axis2.soap.impl.dom.SOAPEnvelopeImpl of the given SOAP Envelope */ public static Element toDOOMSOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope env) { env.build(); //Check the namespace and find SOAP version and factory String nsURI; OMMetaFactory metaFactory = OMAbstractFactory.getMetaFactory(OMAbstractFactory.FEATURE_DOM); SOAPFactory factory; if (env.getNamespace().getNamespaceURI() .equals(SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI)) { nsURI = SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI; factory = metaFactory.getSOAP11Factory(); } else { nsURI = SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI; factory = metaFactory.getSOAP11Factory(); } StAXSOAPModelBuilder stAXSOAPModelBuilder = new StAXSOAPModelBuilder(env.getXMLStreamReader(), factory, nsURI); SOAPEnvelope envelope = (stAXSOAPModelBuilder).getSOAPEnvelope(); envelope.build(); return (Element)envelope; }
/** * Prepare the message in the given message context so that the underlying input stream can be * closed. * * @param msgContext */ public static void detachInputStream(MessageContext msgContext) throws AxisFault { if (msgContext != null) { OMXMLParserWrapper builder = (OMXMLParserWrapper)msgContext.getProperty(Constants.BUILDER); if (builder != null) { builder.detach(); } else { Attachments attachments = msgContext.getAttachmentMap(false); if (attachments != null) { attachments.getAllContentIDs(); } else { SOAPEnvelope envelope = msgContext.getEnvelope(); if (envelope != null) { envelope.build(); } } } } }
private SOAPEnvelope getSoapEnvelope(String soapEnvelpe) throws PersistenceException { try { XMLStreamReader xmlReader = StAXUtils.createXMLStreamReader(new ByteArrayInputStream(soapEnvelpe.getBytes())); StAXBuilder builder = new StAXSOAPModelBuilder(xmlReader); SOAPEnvelope soapEnvelope = (SOAPEnvelope) builder.getDocumentElement(); soapEnvelope.build(); String soapNamespace = soapEnvelope.getNamespace().getNamespaceURI(); if (soapEnvelope.getHeader() == null){ SOAPFactory soapFactory = null; if (soapNamespace.equals(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI)) { soapFactory = OMAbstractFactory.getSOAP12Factory(); } else { soapFactory = OMAbstractFactory.getSOAP11Factory(); } soapFactory.createSOAPHeader(soapEnvelope); } return soapEnvelope; } catch (XMLStreamException e) { log.error("Problem with the stored message", e); throw new PersistenceException("Problem with the stored message", e); } }
private SOAPEnvelope getSoapEnvelope(String soapEnvelpe) throws PersistenceException { try { XMLStreamReader xmlReader = StAXUtils.createXMLStreamReader(new ByteArrayInputStream(soapEnvelpe.getBytes())); StAXBuilder builder = new StAXSOAPModelBuilder(xmlReader); SOAPEnvelope soapEnvelope = (SOAPEnvelope) builder.getDocumentElement(); soapEnvelope.build(); String soapNamespace = soapEnvelope.getNamespace().getNamespaceURI(); if (soapEnvelope.getHeader() == null) { SOAPFactory soapFactory = null; if (soapNamespace.equals(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI)) { soapFactory = OMAbstractFactory.getSOAP12Factory(); } else { soapFactory = OMAbstractFactory.getSOAP11Factory(); } soapFactory.createSOAPHeader(soapEnvelope); } return soapEnvelope; } catch (XMLStreamException e) { log.error("Problem with the stored message", e); throw new PersistenceException("Problem with the stored message", e); } }
private static MessageContext sendReceive(OMElement llomElement, ServiceClient serviceClient) throws AxisFault { MessageContext messageContext = new MessageContext(); fillSOAPEnvelope(messageContext, llomElement, serviceClient); OperationClient operationClient = serviceClient.createClient(ServiceClient.ANON_OUT_IN_OP); operationClient.addMessageContext(messageContext); operationClient.execute(true); MessageContext response = operationClient .getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE); if (serviceClient.getOptions().isCallTransportCleanup()) { response.getEnvelope().build(); serviceClient.cleanupTransport(); return response; } else { return response; } }
/** * Directly invoke a named operationQName with an In-Out MEP. This method sends your supplied * XML and receives a response. For more control, you can instead create a client for the * operationQName and use that client to execute the exchange. * <p> * Unless the <code>callTransportCleanup</code> property on the {@link Options} object has been * set to <code>true</code>, the caller must invoke {@link #cleanupTransport()} after * processing the response. * * @param operationQName name of operationQName to be invoked (non-<code>null</code>) * @param xmlPayload the data to send (becomes the content of SOAP body) * @return response OMElement * @throws AxisFault in case of error * @see #cleanupTransport() */ public OMElement sendReceive(QName operationQName, OMElement xmlPayload) throws AxisFault { MessageContext messageContext = new MessageContext(); fillSOAPEnvelope(messageContext, xmlPayload); OperationClient operationClient = createClient(operationQName); operationClient.addMessageContext(messageContext); operationClient.execute(true); MessageContext response = operationClient .getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE); if (options.isCallTransportCleanup()) { response.getEnvelope().build(); cleanupTransport(); } return response.getEnvelope().getBody().getFirstElement(); }
public AxisMessage(MessageContext msgContext) throws Exception { envelope = msgContext.getEnvelope(); // If possible, build the parent (i.e. the OMDocument) to make sure that the entire message is read. // If the transport doesn't handle the end of the message properly, then this problem // will show up here. OMDocument document = (OMDocument)envelope.getParent(); if (document != null) { document.build(); } else { envelope.build(); } // TODO: quick & dirty hack to force expansion of OMSourceElement payloads OMElement content = envelope.getBody().getFirstElement(); if (content instanceof OMSourcedElement) { ((OMSourcedElement)content).getFirstOMChild(); ((OMSourcedElement)content).build(); } if (msgContext.isDoingSwA()) { // Make sure that all attachments are read attachments = msgContext.getAttachmentMap(); attachments.getAllContentIDs(); } messageType = (String)msgContext.getProperty(Constants.Configuration.MESSAGE_TYPE); }
public AxisMessage(MessageContext msgContext) throws Exception { envelope = msgContext.getEnvelope(); // If possible, build the parent (i.e. the OMDocument) to make sure that the entire message is read. // If the transport doesn't handle the end of the message properly, then this problem // will show up here. OMDocument document = (OMDocument)envelope.getParent(); if (document != null) { document.build(); } else { envelope.build(); } // TODO: quick & dirty hack to force expansion of OMSourceElement payloads OMElement content = envelope.getBody().getFirstElement(); if (content instanceof OMSourcedElement) { ((OMSourcedElement)content).getFirstOMChild(); ((OMSourcedElement)content).build(); } if (msgContext.isDoingSwA()) { // Make sure that all attachments are read attachments = msgContext.getAttachmentMap(); attachments.getAllContentIDs(); } messageType = (String)msgContext.getProperty(Constants.Configuration.MESSAGE_TYPE); }
public AxisMessage(MessageContext msgContext) throws Exception { envelope = msgContext.getEnvelope(); // If possible, build the parent (i.e. the OMDocument) to make sure that the entire message is read. // If the transport doesn't handle the end of the message properly, then this problem // will show up here. OMDocument document = (OMDocument)envelope.getParent(); if (document != null) { document.build(); } else { envelope.build(); } // TODO: quick & dirty hack to force expansion of OMSourceElement payloads OMElement content = envelope.getBody().getFirstElement(); if (content instanceof OMSourcedElement) { ((OMSourcedElement)content).getFirstOMChild(); ((OMSourcedElement)content).build(); } if (msgContext.isDoingSwA()) { // Make sure that all attachments are read attachments = msgContext.getAttachmentMap(); attachments.getAllContentIDs(); } messageType = (String)msgContext.getProperty(Constants.Configuration.MESSAGE_TYPE); }
@Override public OMElement sendReceive(QName operationQName, OMElement xmlPayload) throws AxisFault { MessageContext messageContext = new MessageContext(); fillSOAPEnvelope(messageContext, xmlPayload); OperationClient operationClient = createClient(operationQName); operationClient.addMessageContext(messageContext); operationClient.execute(true); MessageContext response = operationClient .getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE); if (super.getOptions().isCallTransportCleanup()) { response.getEnvelope().build(); cleanupTransport(); } return response.getEnvelope().getBody(); }
private void sendMessageOnNewSession(MessageContext synCtx) { // there is no endpoint associated with this session. get a new endpoint using the // load balance policy. Endpoint endpoint = getNextChild(synCtx); if (endpoint == null) { informFailure(synCtx, SynapseConstants.ENDPOINT_LB_NONE_READY, "SLALoadbalance endpoint : " + getName() + " - no ready child endpoints"); } else { prepareEndPointSequence(synCtx, endpoint); // this is the first request. so an endpoint has not been bound to this session and we // are free to failover if the currently selected endpoint is not working. but for // failover to work, we have to build the soap envelope. synCtx.getEnvelope().build(); // we should also indicate that this is the first message in the session. so that // onFault(...) method can resend only the failed attempts for the first message. synCtx.setProperty(SynapseConstants.PROP_SAL_ENDPOINT_FIRST_MESSAGE_IN_SESSION, Boolean.TRUE); synCtx.pushFaultHandler(this); endpoint.send(synCtx); } }
private void sendMessageOnNewSession(MessageContext synCtx) { // there is no endpoint associated with this session. get a new endpoint using the // load balance policy. Endpoint endpoint = getNextChild(synCtx); if (endpoint == null) { informFailure(synCtx, SynapseConstants.ENDPOINT_LB_NONE_READY, "SLALoadbalance endpoint : " + getName() + " - no ready child endpoints"); } else { prepareEndPointSequence(synCtx, endpoint); // this is the first request. so an endpoint has not been bound to this session and we // are free to failover if the currently selected endpoint is not working. but for // failover to work, we have to build the soap envelope. synCtx.getEnvelope().build(); // we should also indicate that this is the first message in the session. so that // onFault(...) method can resend only the failed attempts for the first message. synCtx.setProperty(SynapseConstants.PROP_SAL_ENDPOINT_FIRST_MESSAGE_IN_SESSION, Boolean.TRUE); synCtx.pushFaultHandler(this); endpoint.send(synCtx); } }