Package org.switchyard

Examples of org.switchyard.Context


                QName firstBodyElement = SOAPUtil.getFirstBodyElement(request);
                action = WSDLUtil.getSoapAction(_wsdlPort, firstBodyElement, _documentStyle);
                oneWay = WSDLUtil.isOneWay(_wsdlPort, firstBodyElement, _documentStyle);

                if (_feature.isAddressingEnabled()) {
                    Context context = exchange.getContext();
                    _dispatcher.getRequestContext().put(SOAPUtil.SWITCHYARD_CONTEXT, context);
                    // It is a one way if a replyto address is set
                    String toAddress = SOAPUtil.getToAddress(exchange.getContext());
                    if (toAddress != null) {
                        _dispatcher.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, toAddress);
View Full Code Here


    private void testStringContextMapping(SOAPHeadersType soapHeadersType) throws Exception {
        SOAPContextMapper mapper = new SOAPContextMapper();
        mapper.setSOAPHeadersType(soapHeadersType);
        // test mapFrom
        SOAPMessage sourceMessage = newSourceMessage();
        Context targetContext = newContext();
        mapper.mapFrom(new SOAPBindingData(sourceMessage), targetContext);
        Assert.assertEquals("John", getPropertyValue(targetContext, FIRST_NAME));
        Assert.assertEquals("Doe", getPropertyValue(targetContext, LAST_NAME));
        // test mapTo
        Context sourceContext = newSourceContext();
        SOAPMessage targetMessage = newTargetMessage();
        mapper.mapTo(sourceContext, new SOAPBindingData(targetMessage));
        Assert.assertEquals("John", getChildElement(targetMessage, FIRST_NAME).getTextContent());
        Assert.assertEquals("Doe", getChildElement(targetMessage, LAST_NAME).getTextContent());
    }
View Full Code Here

    public void testXmlContextMapping() throws Exception {
        SOAPContextMapper mapper = new SOAPContextMapper();
        mapper.setSOAPHeadersType(SOAPHeadersType.XML);
        // test mapFrom
        SOAPMessage sourceMessage = newSourceMessage();
        Context targetContext = newContext();
        mapper.mapFrom(new SOAPBindingData(sourceMessage), targetContext);
        Assert.assertEquals("<first xmlns=\"urn:names:1.0\">John</first>", getPropertyValue(targetContext, FIRST_NAME));
        Assert.assertEquals("<last xmlns=\"urn:names:1.0\">Doe</last>", getPropertyValue(targetContext, LAST_NAME));
        // test mapTo
        Context sourceContext = newSourceContext();
        SOAPMessage targetMessage = newTargetMessage();
        mapper.mapTo(sourceContext, new SOAPBindingData(targetMessage));
        Assert.assertEquals("John", getChildElement(targetMessage, FIRST_NAME).getTextContent());
        Assert.assertEquals("Doe", getChildElement(targetMessage, LAST_NAME).getTextContent());
    }
View Full Code Here

    public void testConfigContextMapping() throws Exception {
        SOAPContextMapper mapper = new SOAPContextMapper();
        mapper.setSOAPHeadersType(SOAPHeadersType.CONFIG);
        // test mapFrom
        SOAPMessage sourceMessage = newSourceMessage();
        Context targetContext = newContext();
        mapper.mapFrom(new SOAPBindingData(sourceMessage), targetContext);
        Assert.assertEquals(newConfiguration("<first xmlns=\"urn:names:1.0\">John</first>"), getPropertyValue(targetContext, FIRST_NAME));
        Assert.assertEquals(newConfiguration("<last xmlns=\"urn:names:1.0\">Doe</last>"), getPropertyValue(targetContext, LAST_NAME));
        // test mapTo
        Context sourceContext = newSourceContext();
        SOAPMessage targetMessage = newTargetMessage();
        mapper.mapTo(sourceContext, new SOAPBindingData(targetMessage));
        Assert.assertEquals("John", getChildElement(targetMessage, FIRST_NAME).getTextContent());
        Assert.assertEquals("Doe", getChildElement(targetMessage, LAST_NAME).getTextContent());
    }
View Full Code Here

    public void testDomContextMapping() throws Exception {
        SOAPContextMapper mapper = new SOAPContextMapper();
        mapper.setSOAPHeadersType(SOAPHeadersType.DOM);
        // test mapFrom
        SOAPMessage sourceMessage = newSourceMessage();
        Context targetContext = newContext();
        mapper.mapFrom(new SOAPBindingData(sourceMessage), targetContext);
        Assert.assertEquals("<first xmlns=\"urn:names:1.0\">John</first>", toString((Element)getPropertyValue(targetContext, FIRST_NAME)));
        Assert.assertEquals("<last xmlns=\"urn:names:1.0\">Doe</last>", toString((Element)getPropertyValue(targetContext, LAST_NAME)));
        // test mapTo
        Context sourceContext = newSourceContext();
        SOAPMessage targetMesssage = newTargetMessage();
        mapper.mapTo(sourceContext, new SOAPBindingData(targetMesssage));
        Assert.assertEquals("John", getChildElement(targetMesssage, FIRST_NAME).getTextContent());
        Assert.assertEquals("Doe", getChildElement(targetMesssage, LAST_NAME).getTextContent());
    }
View Full Code Here

    /**
     * Gets the {@link Context} for the current thread.
     * @return the context
     */
    private static Context getContext() {
        Context context = CONTEXT.get();
        if (context == null) {
            throw BeanMessages.MESSAGES.illegalCallToGetTheSwitchYardContextMustBeCalledWithinTheExecutionOfAnExchangeHandlerChain();
        }
        return context;
    }
View Full Code Here

        ServiceReference inOnly = new ServiceReferenceImpl(
            new QName("exchange-copy"), new InOnlyService(), _domain, null);
        ExchangeDispatcher dispatch = _provider.createDispatcher(inOnly);
       
        Exchange ex = dispatch.createExchange(null, ExchangePattern.IN_ONLY);
        Context ctx = ex.getContext();
        ctx.setProperty("message-prop", "message-val", Scope.MESSAGE);
        ctx.setProperty("exchange-prop", "exchange-val", Scope.EXCHANGE).addLabels(BehaviorLabel.TRANSIENT.label());
        Assert.assertEquals(ctx.getProperty("message-prop", Scope.MESSAGE).getValue(), "message-val");
        Assert.assertEquals(ctx.getProperty("exchange-prop", Scope.EXCHANGE).getValue(), "exchange-val");
        Assert.assertTrue(ctx.getProperty("exchange-prop", Scope.EXCHANGE).getLabels().contains(BehaviorLabel.TRANSIENT.label()));
       
        // Merge the context from ex into the context for ex2
        Exchange ex2 = dispatch.createExchange(null, ExchangePattern.IN_ONLY);
        Context ctx2 = ex2.getContext();
        ctx.mergeInto(ctx2);
        Assert.assertNotNull(ctx2.getProperty("message-prop", Scope.MESSAGE));
        Assert.assertNull(ctx2.getProperty("exchange-prop", Scope.EXCHANGE));
    }
View Full Code Here

    public void testCopyClean() {
        _context.setProperty("a", "a").addLabels(TRANSIENT);
        _context.setProperty("b", "b");
        _context.setProperty("c", "c").addLabels(TRANSIENT);
       
        Context newCtx = new DefaultContext(Scope.EXCHANGE);
        _context.mergeInto(newCtx);
        Assert.assertEquals(0, newCtx.getProperties(TRANSIENT).size());
        Assert.assertEquals(1, newCtx.getProperties().size());
    }
View Full Code Here

    @Test
    public void testCopy() {
        _context.setProperty("exchange", "val");
        _context.setProperty("in", "val");
        _context.setProperty("out", "val");
        Context ctx = new DefaultContext(Scope.EXCHANGE);
        _context.mergeInto(ctx);
        // verify that all fields were copied
        Assert.assertEquals(
                _context.getProperty("exchange"),
                ctx.getProperty("exchange"));
        Assert.assertEquals(
                _context.getProperty("in"),
                ctx.getProperty("in"));
        Assert.assertEquals(
                _context.getProperty("out"),
                ctx.getProperty("out"));
        // verify that mods to one context do not impact the other
        _context.removeProperties();
        Assert.assertNull(_context.getProperty("exchange"));
        Assert.assertNotNull(ctx.getProperty("exchange"));
    }
View Full Code Here

        }
        return this;
    }

    private void setProperties(Exchange exchange, Message message) {
        Context exchangeContext = exchange.getContext();
        Map<String, Object> exchangeProperties = _properties.get(Scope.EXCHANGE);
        if (exchangeProperties != null) {
            for (Map.Entry<String, Object> exchangeProperty : exchangeProperties.entrySet()) {
                exchangeContext.setProperty(exchangeProperty.getKey(), exchangeProperty.getValue(), Scope.EXCHANGE);
            }
        }
        Context messageContext = exchange.getContext(message);
        Map<String, Object> messageProperties = _properties.get(Scope.MESSAGE);
        if (messageProperties != null) {
            for (Map.Entry<String, Object> messageProperty : messageProperties.entrySet()) {
                messageContext.setProperty(messageProperty.getKey(), messageProperty.getValue(), Scope.MESSAGE);
            }
        }
    }
View Full Code Here

TOP

Related Classes of org.switchyard.Context

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.