Search in sources :

Example 31 with Message

use of org.apache.axis2.transport.msmq.util.Message in project wso2-axis2-transports by wso2.

the class TCPTransportSender method writeMessageOut.

/**
 * Writing the message to the output stream of the TCP socket after applying correct message formatter
 * This method is synchronized because there will be issue when formatter write to same output stream which causes
 * to mixed messages
 *
 * @param msgContext the message context
 * @param outputStream the socket output stream
 * @throws AxisFault if error occurred
 * @throws IOException if IO exception occurred
 */
private synchronized void writeMessageOut(MessageContext msgContext, OutputStream outputStream, String delimiter, String delimiterType) throws AxisFault, IOException {
    MessageFormatter messageFormatter = BaseUtils.getMessageFormatter(msgContext);
    OMOutputFormat format = BaseUtils.getOMOutputFormat(msgContext);
    messageFormatter.writeTo(msgContext, format, outputStream, true);
    if (delimiter != null && !delimiter.isEmpty()) {
        if (TCPConstants.BYTE_DELIMITER_TYPE.equalsIgnoreCase(delimiterType)) {
            outputStream.write((char) Integer.parseInt(delimiter.split("0x")[1], 16));
        } else {
            outputStream.write(delimiter.getBytes());
        }
    }
    outputStream.flush();
}
Also used : MessageFormatter(org.apache.axis2.transport.MessageFormatter) OMOutputFormat(org.apache.axiom.om.OMOutputFormat)

Example 32 with Message

use of org.apache.axis2.transport.msmq.util.Message in project wso2-axis2-transports by wso2.

the class PlainTextFormatter method writeTo.

public void writeTo(MessageContext messageContext, OMOutputFormat format, OutputStream outputStream, boolean preserve) throws AxisFault {
    // preserve boolean is not used because new implementation doesn't need it. However, it's there to
    // to have backward compatibility.
    OMElement textElt = messageContext.getEnvelope().getBody().getFirstElement();
    if (BaseConstants.DEFAULT_TEXT_WRAPPER.equals(textElt.getQName())) {
        try {
            Writer out = new OutputStreamWriter(outputStream, format.getCharSetEncoding());
            out.write(textElt.getFirstElement() == null ? textElt.getText() : textElt.getFirstElement().toString());
            out.flush();
        } catch (IOException e) {
            throw new AxisFault("Error writing text message to stream", e);
        } catch (Exception e) {
            throw new AxisFault("Error extracting the text payload from the message", e);
        }
    }
}
Also used : AxisFault(org.apache.axis2.AxisFault) OMElement(org.apache.axiom.om.OMElement) OutputStreamWriter(java.io.OutputStreamWriter) IOException(java.io.IOException) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter) IOException(java.io.IOException) XMLStreamException(javax.xml.stream.XMLStreamException)

Example 33 with Message

use of org.apache.axis2.transport.msmq.util.Message in project wso2-axis2-transports by wso2.

the class AbstractTransportListener method createMessageContext.

/**
 * Create a new axis MessageContext for an incoming message through this transport
 * @return the newly created message context
 */
public MessageContext createMessageContext() {
    MessageContext msgCtx = new MessageContext();
    msgCtx.setConfigurationContext(cfgCtx);
    msgCtx.setIncomingTransportName(getTransportName());
    msgCtx.setTransportOut(transportOut);
    msgCtx.setTransportIn(transportIn);
    msgCtx.setServerSide(true);
    msgCtx.setMessageID(UUIDGenerator.getUUID());
    // There is a discrepency in what I thought, Axis2 spawns a nes threads to
    // send a message is this is TRUE - and I want it to be the other way
    msgCtx.setProperty(MessageContext.CLIENT_API_NON_BLOCKING, Boolean.valueOf(!isNonBlocking));
    return msgCtx;
}
Also used : MessageContext(org.apache.axis2.context.MessageContext)

Example 34 with Message

use of org.apache.axis2.transport.msmq.util.Message in project wso2-axis2-transports by wso2.

the class AbstractTransportListener method init.

/**
 * Initialize the generic transport. Sets up the transport and the thread pool to be used
 * for message processing. Also creates an AxisObserver that gets notified of service
 * life cycle events for the transport to act on
 * @param cfgCtx the axis configuration context
 * @param transportIn the transport-in description
 * @throws AxisFault on error
 */
public void init(ConfigurationContext cfgCtx, TransportInDescription transportIn) throws AxisFault {
    this.cfgCtx = cfgCtx;
    this.transportIn = transportIn;
    this.transportOut = cfgCtx.getAxisConfiguration().getTransportOut(getTransportName());
    this.config = TransportConfiguration.getConfiguration(getTransportName());
    if (useAxis2ThreadPool) {
        // this.workerPool = cfgCtx.getThreadPool(); not yet implemented
        throw new AxisFault("Unsupported thread pool for task execution - Axis2 thread pool");
    } else {
        if (this.workerPool == null) {
            // FIXME <-- workaround for AXIS2-4552
            this.workerPool = WorkerPoolFactory.getWorkerPool(config.getServerCoreThreads(), config.getServerMaxThreads(), config.getServerKeepalive(), config.getServerQueueLen(), getTransportName() + "Server Worker thread group", getTransportName() + "-Worker");
        }
    }
    // register to receive updates on services for lifetime management
    serviceTracker = new AxisServiceTracker(cfgCtx.getAxisConfiguration(), new AxisServiceFilter() {

        public boolean matches(AxisService service) {
            return // these are "private" services
            !service.getName().startsWith("__") && BaseUtils.isUsingTransport(service, getTransportName());
        }
    }, new AxisServiceTrackerListener() {

        public void serviceAdded(AxisService service) {
            internalStartListeningForService(service);
        }

        public void serviceRemoved(AxisService service) {
            internalStopListeningForService(service);
        }
    });
    // register with JMX
    if (mbeanSupport == null) {
        // FIXME <-- workaround for AXIS2-4552
        mbeanSupport = new TransportMBeanSupport(this, getTransportName());
        mbeanSupport.register();
    }
}
Also used : AxisFault(org.apache.axis2.AxisFault) AxisServiceTracker(org.apache.axis2.transport.base.tracker.AxisServiceTracker) AxisServiceFilter(org.apache.axis2.transport.base.tracker.AxisServiceFilter) AxisServiceTrackerListener(org.apache.axis2.transport.base.tracker.AxisServiceTrackerListener)

Example 35 with Message

use of org.apache.axis2.transport.msmq.util.Message in project wso2-axis2-transports by wso2.

the class JMSMessageReceiver method processThoughEngine.

/**
 * Process the new message through Axis2
 *
 * @param message the JMS message
 * @param ut      the UserTransaction used for receipt
 * @return true if the caller should commit
 * @throws JMSException, on JMS exceptions
 * @throws AxisFault     on Axis2 errors
 */
private boolean processThoughEngine(Message message, UserTransaction ut) throws JMSException, AxisFault {
    MessageContext msgContext = endpoint.createMessageContext();
    // set the JMS Message ID as the Message ID of the MessageContext
    try {
        msgContext.setMessageID(message.getJMSMessageID());
        String jmsCorrelationID = message.getJMSCorrelationID();
        if (jmsCorrelationID != null && jmsCorrelationID.length() > 0) {
            msgContext.setProperty(JMSConstants.JMS_COORELATION_ID, jmsCorrelationID);
        } else {
            msgContext.setProperty(JMSConstants.JMS_COORELATION_ID, message.getJMSMessageID());
        }
    } catch (JMSException ignore) {
    }
    String soapAction = JMSUtils.getProperty(message, BaseConstants.SOAPACTION);
    ContentTypeInfo contentTypeInfo = endpoint.getContentTypeRuleSet().getContentTypeInfo(message);
    if (contentTypeInfo == null) {
        throw new AxisFault("Unable to determine content type for message " + msgContext.getMessageID());
    }
    // set the message property OUT_TRANSPORT_INFO
    // the reply is assumed to be over the JMSReplyTo destination, using
    // the same incoming connection factory, if a JMSReplyTo is available
    Destination replyTo = message.getJMSReplyTo();
    if (replyTo == null) {
        // does the service specify a default reply destination ?
        String jndiReplyDestinationName = endpoint.getJndiReplyDestinationName();
        if (jndiReplyDestinationName != null) {
            replyTo = jmsConnectionFactory.getDestination(jndiReplyDestinationName, endpoint.getReplyDestinationType());
        }
    }
    if (replyTo != null) {
        msgContext.setProperty(Constants.OUT_TRANSPORT_INFO, new JMSOutTransportInfo(jmsConnectionFactory, replyTo, contentTypeInfo.getPropertyName()));
    }
    // Setting JMSXDeliveryCount header on the message context
    try {
        int deliveryCount = message.getIntProperty(JMS_MESSAGE_DELIVERY_COUNT_HEADER);
        msgContext.setProperty(JMSConstants.DELIVERY_COUNT, deliveryCount);
    } catch (NumberFormatException nfe) {
        if (log.isDebugEnabled()) {
            log.debug("JMSXDeliveryCount is not set in the received message");
        }
    }
    JMSUtils.setSOAPEnvelope(message, msgContext, contentTypeInfo.getContentType());
    if (ut != null) {
        msgContext.setProperty(BaseConstants.USER_TRANSACTION, ut);
    }
    msgContext.setProperty(JMSConstants.PARAM_JMS_HYPHEN_MODE, endpoint.getHyphenSupport());
    jmsListener.handleIncomingMessage(msgContext, JMSUtils.getTransportHeaders(message, msgContext), soapAction, contentTypeInfo.getContentType());
    Object o = msgContext.getProperty(BaseConstants.SET_ROLLBACK_ONLY);
    if (o != null) {
        if ((o instanceof Boolean && ((Boolean) o)) || (o instanceof String && Boolean.valueOf((String) o))) {
            return false;
        }
    }
    return true;
}
Also used : AxisFault(org.apache.axis2.AxisFault) ContentTypeInfo(org.apache.axis2.transport.jms.ctype.ContentTypeInfo) MessageContext(org.apache.axis2.context.MessageContext)

Aggregations

AxisFault (org.apache.axis2.AxisFault)25 MessageContext (org.apache.axis2.context.MessageContext)20 IOException (java.io.IOException)9 OMOutputFormat (org.apache.axiom.om.OMOutputFormat)8 MessageFormatter (org.apache.axis2.transport.MessageFormatter)8 ContentType (javax.mail.internet.ContentType)7 OMElement (org.apache.axiom.om.OMElement)7 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)6 IncomingMessage (org.apache.axis2.transport.testkit.message.IncomingMessage)6 UnsupportedEncodingException (java.io.UnsupportedEncodingException)5 UnsupportedCharsetException (java.nio.charset.UnsupportedCharsetException)5 AxisOperation (org.apache.axis2.description.AxisOperation)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 OutputStream (java.io.OutputStream)4 XMLStreamException (javax.xml.stream.XMLStreamException)4 XMPPConnection (org.jivesoftware.smack.XMPPConnection)4 XMPPException (org.jivesoftware.smack.XMPPException)4 Message (org.jivesoftware.smack.packet.Message)4 AMQP (com.rabbitmq.client.AMQP)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3