当前位置: 首页>>代码示例>>Java>>正文


Java Context类代码示例

本文整理汇总了Java中org.switchyard.Context的典型用法代码示例。如果您正苦于以下问题:Java Context类的具体用法?Java Context怎么用?Java Context使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Context类属于org.switchyard包,在下文中一共展示了Context类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testCopy

import org.switchyard.Context; //导入依赖的package包/类
@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"));
}
 
开发者ID:jboss-switchyard,项目名称:switchyard,代码行数:23,代码来源:DefaultContextTest.java

示例2: setProperties

import org.switchyard.Context; //导入依赖的package包/类
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);
        }
    }
}
 
开发者ID:jboss-switchyard,项目名称:switchyard,代码行数:17,代码来源:Invoker.java

示例3: testCopyFromExchange

import org.switchyard.Context; //导入依赖的package包/类
@Test
public void testCopyFromExchange() throws Exception {
    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));
}
 
开发者ID:jboss-switchyard,项目名称:switchyard,代码行数:22,代码来源:CamelCompositeContextTest.java

示例4: mapFrom

import org.switchyard.Context; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public void mapFrom(RESTEasyBindingData source, Context context) throws Exception {
    super.mapFrom(source, context);

    Iterator<Map.Entry<String, List<String>>> entries = source.getHeaders().entrySet().iterator();
    while (entries.hasNext()) {
        Map.Entry<String, List<String>> entry = entries.next();
        String name = entry.getKey();
        if (matches(name)) {
            List<String> values = entry.getValue();
            if ((values != null) && (values.size() == 1)) {
                context.setProperty(name, values.get(0)).addLabels(RESTEASY_LABELS);
            } else if ((values != null) && (values.size() > 1)) {
                context.setProperty(name, values).addLabels(RESTEASY_LABELS);
            }
        }
    }
    if (source.getStatusCode() != null) {
        context.setProperty(HTTP_RESPONSE_STATUS, source.getStatusCode()).addLabels(RESTEASY_LABELS);
    }
}
 
开发者ID:jboss-switchyard,项目名称:switchyard,代码行数:25,代码来源:RESTEasyContextMapper.java

示例5: mapTo

import org.switchyard.Context; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
@SuppressWarnings("unchecked")
@Override
public void mapTo(Context context, IndexedRecordBindingData target) throws Exception {
    super.mapTo(context, target);

    IndexedRecord record = target.getRecord();
    for (Property property : context.getProperties()) {
        String name = property.getName();
        Object value = property.getValue();
        if (value == null) {
            continue;
        }
        if (name.equals(JCAConstants.CCI_RECORD_NAME_KEY)) {
            record.setRecordName(value.toString());
        } else if (name.equals(JCAConstants.CCI_RECORD_SHORT_DESC_KEY)) {
            record.setRecordShortDescription(value.toString());
        } else if (matches(name)) {
            record.add(name + "=" + value);
        }  else if (matches(name, getIncludeRegexes(), new ArrayList<Pattern>())) {
            record.add(name + "=" + value);
        }
    }
}
 
开发者ID:jboss-switchyard,项目名称:switchyard,代码行数:27,代码来源:IndexedRecordContextMapper.java

示例6: mapTo

import org.switchyard.Context; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public void mapTo(Context context, StreamableRecordBindingData target) throws Exception {
    StreamableRecord record = target.getRecord();
    for (Property property : context.getProperties()) {
        String name = property.getName();
        Object value = property.getValue();
        if (value == null) {
            continue;
        }
        if (name.equals(JCAConstants.CCI_RECORD_NAME_KEY)) {
            record.setRecordName(value.toString());
        } else if (name.equals(JCAConstants.CCI_RECORD_SHORT_DESC_KEY)) {
            record.setRecordShortDescription(value.toString());
        }
    }
}
 
开发者ID:jboss-switchyard,项目名称:switchyard,代码行数:20,代码来源:StreamableRecordContextMapper.java

示例7: mapFrom

import org.switchyard.Context; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public void mapFrom(MappedRecordBindingData source, Context context) throws Exception {
    super.mapFrom(source, context);

    MappedRecord record = source.getRecord();
    String recordName = record.getRecordName();
    if (recordName != null) {
        context.setProperty(JCAConstants.CCI_RECORD_NAME_KEY, recordName).addLabels(MAPPED_RECORD_LABELS);
    }
    String recordDescription = record.getRecordShortDescription();
    if (recordDescription != null) {
        context.setProperty(JCAConstants.CCI_RECORD_SHORT_DESC_KEY, recordDescription).addLabels(MAPPED_RECORD_LABELS);
    }

    for (Object obj : record.keySet()) {
        if (obj instanceof String) {
            String key = (String) obj;
            if (matches(key, getIncludeRegexes(), new ArrayList<Pattern>())) {
                context.setProperty(key, record.get(key), Scope.EXCHANGE);
            }
        }
    }
}
 
开发者ID:jboss-switchyard,项目名称:switchyard,代码行数:27,代码来源:MappedRecordContextMapper.java

示例8: mapTo

import org.switchyard.Context; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
@SuppressWarnings("unchecked")
@Override
public void mapTo(Context context, MappedRecordBindingData target) throws Exception {
    super.mapTo(context, target);

    MappedRecord record = target.getRecord();
    for (Property property : context.getProperties()) {
        String name = property.getName();
        Object value = property.getValue();
        if (value == null) {
            continue;
        }
        if (name.equals(JCAConstants.CCI_RECORD_NAME_KEY)) {
            record.setRecordName(value.toString());
        } else if (name.equals(JCAConstants.CCI_RECORD_SHORT_DESC_KEY)) {
            record.setRecordShortDescription(value.toString());
        } else if (matches(name)) {
            record.put(name, value);
        } else if (matches(name, getIncludeRegexes(), new ArrayList<Pattern>())) {
            record.put(name, value);
        }
    }
}
 
开发者ID:jboss-switchyard,项目名称:switchyard,代码行数:27,代码来源:MappedRecordContextMapper.java

示例9: testStringContextMapping

import org.switchyard.Context; //导入依赖的package包/类
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());
}
 
开发者ID:jboss-switchyard,项目名称:switchyard,代码行数:17,代码来源:SOAPContextMapperTest.java

示例10: testXmlContextMapping

import org.switchyard.Context; //导入依赖的package包/类
@Test
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();
    sourceContext.setProperty("bar", "bar", Scope.EXCHANGE);
    sourceContext.setProperty("foo", "foo", Scope.MESSAGE);
    SOAPMessage targetMessage = newTargetMessage();
    SOAPBindingData target = new SOAPBindingData(targetMessage);
    mapper.mapTo(sourceContext, target);
    Assert.assertEquals("John", getChildElement(targetMessage, FIRST_NAME).getTextContent());
    Assert.assertEquals("Doe", getChildElement(targetMessage, LAST_NAME).getTextContent());

    Assert.assertTrue(target.getHttpHeaders().containsKey("foo"));
    List<String> value = (List<String>) target.getHttpHeaders().get("foo");
    Assert.assertTrue(value.get(0).equals("foo"));

    Assert.assertFalse(target.getHttpHeaders().containsKey("bar"));
}
 
开发者ID:jboss-switchyard,项目名称:switchyard,代码行数:27,代码来源:SOAPContextMapperTest.java

示例11: testConfigContextMapping

import org.switchyard.Context; //导入依赖的package包/类
@Test
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());
}
 
开发者ID:jboss-switchyard,项目名称:switchyard,代码行数:18,代码来源:SOAPContextMapperTest.java

示例12: testDomContextMapping

import org.switchyard.Context; //导入依赖的package包/类
@Test
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());
}
 
开发者ID:jboss-switchyard,项目名称:switchyard,代码行数:18,代码来源:SOAPContextMapperTest.java

示例13: setRegexPropagationList

import org.switchyard.Context; //导入依赖的package包/类
/**
 * Set the list of regexes of properties that need to be propagated.
 *
 * @param context context
 */
protected void setRegexPropagationList(Context context) {
    // ENTESB-6525: Ensure thread safe access to this list
    if(_includeRegexes!=null) {
       return;
    } else {
       _includeRegexes = new ArrayList<Pattern>();

       if (!_prefixPropagationSet) {
           if (context.getProperty(SERVICE_REFERENCE_PROPERTY) != null) {
               ServiceDomain domain = ((ServiceReference)context.getProperty(SERVICE_REFERENCE_PROPERTY).getValue()).getDomain();

               if (domain.getProperty(PropertyConstants.DOMAIN_PROPERTY_PROPAGATE_REGEX) != null) {
                   String regexList = (String) domain.getProperty(PropertyConstants.DOMAIN_PROPERTY_PROPAGATE_REGEX);
                   setPatternList(regexList, _includeRegexes);
               }
           }
           _prefixPropagationSet = true;
       }
       Pattern rtGovResubmissionPattern = Pattern.compile(PropertyConstants.RTGOV_HEADER_RESUBMITTED_ID_PATTERN);
       _includeRegexes.add(rtGovResubmissionPattern);
   }
}
 
开发者ID:jboss-switchyard,项目名称:switchyard,代码行数:28,代码来源:BaseRegexContextMapper.java

示例14: getContextProperty

import org.switchyard.Context; //导入依赖的package包/类
private String getContextProperty(Context context, String name) {
    Object p = context.getPropertyValue(name);
    if (p instanceof SOAPHeaderElement) {
        return ((SOAPHeaderElement)p).getValue();
    } else if (p != null) {
        return p.toString();
    }
    return null;
}
 
开发者ID:jboss-switchyard,项目名称:switchyard,代码行数:10,代码来源:AddressingInterceptor.java

示例15: copyProperties

import org.switchyard.Context; //导入依赖的package包/类
private void copyProperties(Context context, Exchange exchange) {
    for (Property property : context.getProperties()) {
        if (property.hasLabel(BehaviorLabel.TRANSIENT.label()) 
                || ContextPropertyUtil.isReservedProperty(property.getName(), property.getScope())) {
            continue;
        }

        if (Scope.EXCHANGE.equals(property.getScope())) {
            exchange.setProperty(property.getName(), property.getValue());
        } else {
            exchange.getIn().setHeader(property.getName(), property.getValue());
        }
    }
}
 
开发者ID:jboss-switchyard,项目名称:switchyard,代码行数:15,代码来源:CamelTransformer.java


注:本文中的org.switchyard.Context类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。