Package org.mule.api

Examples of org.mule.api.MuleSession


        // Serialize and deserialize session using default session handler
        new SerializeAndEncodeSessionHandler().storeSessionInfoToMessage(event.getSession(), message);
        message.setProperty(MuleProperties.MULE_SESSION_PROPERTY,
            message.getProperty(MuleProperties.MULE_SESSION_PROPERTY, PropertyScope.OUTBOUND),
            PropertyScope.INBOUND);
        MuleSession newSession = new SerializeAndEncodeSessionHandler().retrieveSessionInfoFromMessage(message);

        // Session after deserialization is a new instance that does not equal old
        // instance
        assertNotSame(newSession, event.getSession());
        assertFalse(newSession.equals(event.getSession()));

        // Session properties available before serialization are available after too
        assertEquals(1, newSession.getPropertyNamesAsSet().size());
        assertEquals("value", newSession.getProperty("key"));

        // Session properties set after deserialization are not available in message
        // processor
        // before serialization
        newSession.setProperty("newKey", "newValue");
        assertEquals(2, newSession.getPropertyNamesAsSet().size());
        assertEquals("newValue", newSession.getProperty("newKey"));
        assertEquals(1, event.getSession().getPropertyNamesAsSet().size());
        assertNull(event.getSession().getProperty("newKey"));
    }
View Full Code Here


        // Serialize and deserialize session using default session handler
        new SerializeAndEncodeSessionHandler().storeSessionInfoToMessage(event.getSession(), message);
        message.setProperty(MuleProperties.MULE_SESSION_PROPERTY,
            message.getProperty(MuleProperties.MULE_SESSION_PROPERTY, PropertyScope.OUTBOUND),
            PropertyScope.INBOUND);
        MuleSession newSession = new SerializeAndEncodeSessionHandler().retrieveSessionInfoFromMessage(message);

        // Session after deserialization is a new instance that does not equal old
        // instance
        assertNotSame(newSession, event.getSession());
        assertFalse(newSession.equals(event.getSession()));
        assertEquals(nonSerializable, event.getSession().getProperty("key"));
        assertEquals("value2", event.getSession().getProperty("key2"));

        // Non-serilizable session properties available before serialization are not
        // available after too
        assertEquals(1, newSession.getPropertyNamesAsSet().size());
        assertNull(newSession.getProperty("key"));
        assertEquals("value2", newSession.getProperty("key2"));
    }
View Full Code Here

    @Test
    @SuppressWarnings(value = {"deprecation"})
    public void serializationWithNonSerializableProperty() throws MuleException
    {
        MuleSession before = new DefaultMuleSession();
        Object nonSerializable = new Object();
        before.setProperty("foo", nonSerializable);
        before.setProperty("foo2", "bar2");

        MuleSession after = (DefaultMuleSession) SerializationUtils.deserialize(
                SerializationUtils.serialize(before), getClass().getClassLoader());

        assertNotNull(after);
        assertNotSame(after, before);
        assertEquals("bar2", after.getProperty("foo2"));
        assertNull(after.getProperty("foo"));
    }
View Full Code Here

    }

    @Test
    public void concurrentPropertiesAccess() throws InterruptedException
    {
        final MuleSession session = new DefaultMuleSession();
        session.setProperty("p1", "v1");
        session.setProperty("p2", "v2");
        session.setProperty("p3", "v3");
        session.setProperty("p4", "v4");

        final CountDownLatch concurrentAccess = new CountDownLatch(2);
        final CountDownLatch executionComplete = new CountDownLatch(2);
        final AtomicBoolean failed = new AtomicBoolean(false);

        Runnable r = new Runnable()
        {
            @Override
            public void run()
            {
                try
                {
                    int i = 0;
                    for (String propertyName : session.getPropertyNamesAsSet())
                    {
                        if (i == 2)
                        {
                            concurrentAccess.countDown();
                            concurrentAccess.await(LATCH_TIMEOUT, TimeUnit.MILLISECONDS);
                        }
                        session.removeProperty(propertyName);
                        i++;
                    }
                }
                catch (Exception e)
                {
View Full Code Here

    private static Transformer encoder = new Base64Encoder();
    private static Transformer decoder = new Base64Decoder();

    public MuleSession retrieveSessionInfoFromMessage(MuleMessage message) throws MuleException
    {
         MuleSession session = new DefaultMuleSession();

         String sessionId = message.getInboundProperty(MuleProperties.MULE_SESSION_ID_PROPERTY);
         Object sessionHeader = message.getInboundProperty(MuleProperties.MULE_SESSION_PROPERTY);

         if (sessionId != null)
         {
             throw new IllegalStateException(
                 "This session handler does not know how to look up session information for session id: "
                                 + sessionId);
         }
         if (sessionHeader != null)
         {
             String sessionString;
             try
             {
                 sessionString = new String((byte[]) decoder.transform(sessionHeader), message.getEncoding());
             }
             catch (UnsupportedEncodingException e)
             {
                 sessionString = new String((byte[]) decoder.transform(sessionHeader));
             }
             if (logger.isDebugEnabled())
             {
                 logger.debug("Parsing session header: " + sessionString);
             }
             String pair;
             String name;
             String value;
             for (StringTokenizer stringTokenizer = new StringTokenizer(sessionString, ";"); stringTokenizer.hasMoreTokens();)
             {
                 pair = stringTokenizer.nextToken();
                 int i = pair.indexOf("=");
                 if (i == -1)
                 {
                     throw new IllegalArgumentException(
                         CoreMessages.sessionValueIsMalformed(pair).toString());
                 }
                 name = pair.substring(0, i).trim();
                 value = pair.substring(i + 1).trim();
                 session.setProperty(name, value);
                 if (logger.isDebugEnabled())
                 {
                     logger.debug("Added MuleSession variable: " + pair);
                 }
             }
View Full Code Here

{
    protected transient Log logger = LogFactory.getLog(getClass());

    public MuleSession retrieveSessionInfoFromMessage(MuleMessage message) throws MuleException
    {
        MuleSession session = null;
        byte[] serializedSession = message.getInboundProperty(MuleProperties.MULE_SESSION_PROPERTY);

        if (serializedSession != null)
        {
            session = (MuleSession) SerializationUtils.deserialize(serializedSession, message.getMuleContext());
View Full Code Here

public class SerializeAndEncodeSessionHandler extends SerializeOnlySessionHandler
{
    @Override
    public MuleSession retrieveSessionInfoFromMessage(MuleMessage message) throws MuleException
    {
        MuleSession session = null;
        String serializedEncodedSession = message.getInboundProperty(MuleProperties.MULE_SESSION_PROPERTY);
       
        if (serializedEncodedSession != null)
        {
            byte[] serializedSession = Base64.decode(serializedEncodedSession);           
View Full Code Here

            else
            {
                ros = new ResponseOutputStream(outputStream);
            }
        }
        MuleSession session;
        try
        {
            session = connector.getSessionHandler().retrieveSessionInfoFromMessage(message);
        }
        catch (SerializationException se)
        {
            try
            {
                // EE-1820 Support message headers generated by previous Mule versions
                session = new LegacySessionHandler().retrieveSessionInfoFromMessage(message);
            }
            catch (Exception e)
            {
                // If the LegacySessionHandler didn't work either, just bubble up the original SerializationException (see MULE-5487)
                throw se;
            }
        }
        if (session == null)
        {
            session = new DefaultMuleSession();
        }
        if (message.getReplyTo() != null)
        {
            event = new DefaultMuleEvent(message, getEndpoint(), flowConstruct, session, replyToHandler, message.getReplyTo(), ros);
            message.setReplyTo(null);
        }
        else
        {
            event = new DefaultMuleEvent(message, getEndpoint(), flowConstruct, session, null, null, ros);
        }
        event = OptimizedRequestContext.unsafeSetEvent(event);
        if (session.getSecurityContext() != null && session.getSecurityContext().getAuthentication() != null)
        {
            session.getSecurityContext().getAuthentication().setEvent(event);
        }
        return event;
    }
View Full Code Here

        if (endpoint.getExchangePattern().hasResponse() && resultEvent != null
            && !VoidMuleEvent.getInstance().equals(resultEvent))
        {
            // Do not propagate security context back to caller
            MuleSession resultSession = new DefaultMuleSession(resultEvent.getSession());
            resultSession.setSecurityContext(null);
            connector.getSessionHandler().storeSessionInfoToMessage(resultSession, resultEvent.getMessage());

            if (resultEvent.getMessage() != null && !endpoint.isDisableTransportTransformer())
            {
                applyResponseTransformers(resultEvent);
View Full Code Here

    @Test
    public void testSessionProperties() throws Exception
    {
        DefaultMuleMessage message = new DefaultMuleMessage("Test Message", muleContext);
        SessionHandler handler = new SerializeAndEncodeSessionHandler();
        MuleSession session = new DefaultMuleSession();

        String string = "bar";
        session.setProperty("fooString", string);

        Date date = new Date(0);
        session.setProperty("fooDate", date);

        List<String> list = createList();
        session.setProperty("fooList", list);

        handler.storeSessionInfoToMessage(session, message);
        // store save session to outbound, move it to the inbound
        // for retrieve to deserialize
        Object s = message.removeProperty(MuleProperties.MULE_SESSION_PROPERTY);
        message.setInboundProperty(MuleProperties.MULE_SESSION_PROPERTY, s);
        session = handler.retrieveSessionInfoFromMessage(message);

        Object obj = session.getProperty("fooString");
        assertTrue(obj instanceof String);
        assertEquals(string, obj);

        obj = session.getProperty("fooDate");
        assertTrue("Object should be a Date but is " + obj.getClass().getName(), obj instanceof Date);
        assertEquals(date, obj);

        obj = session.getProperty("fooList");
        assertTrue("Object should be a List but is " + obj.getClass().getName(), obj instanceof List);
        assertEquals(list, obj);
    }
View Full Code Here

TOP

Related Classes of org.mule.api.MuleSession

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.