本文整理汇总了Java中org.switchyard.Context.setProperty方法的典型用法代码示例。如果您正苦于以下问题:Java Context.setProperty方法的具体用法?Java Context.setProperty怎么用?Java Context.setProperty使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.switchyard.Context
的用法示例。
在下文中一共展示了Context.setProperty方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
}
}
示例2: 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));
}
示例3: 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);
}
}
}
}
示例4: 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"));
}
示例5: mapFrom
import org.switchyard.Context; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public void mapFrom(IndexedRecordBindingData source, Context context) throws Exception {
super.mapFrom(source, context);
IndexedRecord record = source.getRecord();
String recordName = record.getRecordName();
if (recordName != null) {
context.setProperty(JCAConstants.CCI_RECORD_NAME_KEY, recordName).addLabels(INDEXED_RECORD_LABELS);
}
String recordDescription = record.getRecordShortDescription();
if (recordDescription != null) {
context.setProperty(JCAConstants.CCI_RECORD_SHORT_DESC_KEY, recordDescription).addLabels(INDEXED_RECORD_LABELS);
}
for (int i = 0; i < record.size(); i++) {
Object o = record.get(i);
if (o instanceof String) {
String element = (String) o;
if (element.contains("=")) {
String[] strings = element.split("=");
if (strings.length >= 2) {
String key = strings[0];
String value = strings[1];
if (matches(key, getIncludeRegexes(), new ArrayList<Pattern>())) {
context.setProperty(key, value, Scope.EXCHANGE);
}
}
}
}
}
}
示例6: testInject
import org.switchyard.Context; //导入方法依赖的package包/类
@Test
public void testInject() {
Invoker invoker = _testKit.newInvoker("InjectService.doSomething");
SynchronousInOutHandler handler = new SynchronousInOutHandler();
Exchange exchange = invoker.createExchange(handler);
Message message = exchange.createMessage();
Context context = exchange.getContext(message);
context.setProperty("someProp", "somePropVal");
message.setContent("blah");
DataSource attach = new TestDataSource("someAttach", "text/plain", "someAttachData");
message.addAttachment(attach.getName(), attach);
exchange.send(message);
Exchange outExchange = handler.waitForOut();
Assert.assertEquals("true, true, true", outExchange.getMessage().getContent());
}
示例7: testInjectAfterAnotherBeanInvocation
import org.switchyard.Context; //导入方法依赖的package包/类
@Test
public void testInjectAfterAnotherBeanInvocation() {
Invoker invoker = _testKit.newInvoker("InjectService.doSomethingAfterAnotherBeanInvocation");
SynchronousInOutHandler handler = new SynchronousInOutHandler();
Exchange exchange = invoker.createExchange(handler);
Message message = exchange.createMessage();
Context context = exchange.getContext(message);
context.setProperty("someProp", "somePropVal");
message.setContent("blah");
exchange.send(message);
Exchange outExchange = handler.waitForOut();
Assert.assertEquals("true, true, true, true", outExchange.getMessage().getContent());
}
示例8: mapFrom
import org.switchyard.Context; //导入方法依赖的package包/类
@Override
public void mapFrom(JMSBindingData source, Context context) throws Exception {
super.mapFrom(source, context);
context.setProperty("testProp", "testVal", Scope.EXCHANGE);
}
示例9: mapFrom
import org.switchyard.Context; //导入方法依赖的package包/类
@Override
public void mapFrom(CamelBindingData source, Context context) throws Exception {
super.mapFrom(source, context);
context.setProperty(PROPERTY, VALUE);
}
示例10: invoke
import org.switchyard.Context; //导入方法依赖的package包/类
/**
* Invokes the request and returns the response.
* @param request the request
* @return the response
*/
public SwitchYardServiceResponse invoke(SwitchYardServiceRequest request) {
Map<String, Object> contextOut = new HashMap<String, Object>();
Object contentOut = null;
Object fault = null;
try {
QName serviceName = request.getServiceName();
if (serviceName == null) {
throw CommonKnowledgeMessages.MESSAGES.serviceNameNull();
} else if (Strings.trimToNull(serviceName.getNamespaceURI()) == null) {
String tns = getTargetNamespace();
if (tns != null) {
serviceName = XMLHelper.createQName(tns, serviceName.getLocalPart());
}
}
ServiceDomain serviceDomain = getServiceDomain();
if (serviceDomain == null) {
throw CommonKnowledgeMessages.MESSAGES.serviceDomainNull();
}
ServiceReference serviceReference = serviceDomain.getServiceReference(serviceName);
if (serviceReference == null) {
throw CommonKnowledgeMessages.MESSAGES.serviceReferenceNull(serviceName.toString());
}
final Exchange exchangeIn;
FaultHandler handler = new FaultHandler();
String operationName = request.getOperationName();
if (operationName != null) {
exchangeIn = serviceReference.createExchange(operationName, handler);
} else {
exchangeIn = serviceReference.createExchange(handler);
}
Message messageIn = exchangeIn.createMessage();
Context contextIn = exchangeIn.getContext(messageIn);
for (Map.Entry<String,Object> entry : request.getContext().entrySet()) {
contextIn.setProperty(entry.getKey(), entry.getValue());
}
Object contentIn = request.getContent();
if (contentIn != null) {
messageIn.setContent(contentIn);
}
exchangeIn.send(messageIn);
if (ExchangePattern.IN_OUT.equals(exchangeIn.getContract().getConsumerOperation().getExchangePattern())) {
Exchange exchangeOut = handler.waitForOut();
Message messageOut = exchangeOut.getMessage();
contentOut = messageOut.getContent();
for (Property property : exchangeOut.getContext(messageOut).getProperties()) {
contextOut.put(property.getName(), property.getValue());
}
}
fault = handler.getFault();
} catch (Throwable t) {
fault = t;
}
return new SwitchYardServiceResponse(contentOut, contextOut, fault);
}
示例11: invoke
import org.switchyard.Context; //导入方法依赖的package包/类
/** Invokes the request and returns the response.
*
* @param request the request
* @return the response */
public SwitchYardServiceResponse invoke(SwitchYardServiceRequest request) {
Map<String, Object> contextOut = new HashMap<String, Object>();
Object contentOut = null;
Object fault = null;
try {
QName serviceName = request.getServiceName();
if (serviceName == null) {
throw CommonKnowledgeMessages.MESSAGES.serviceNameNull();
} else if (Strings.trimToNull(serviceName.getNamespaceURI()) == null) {
String tns = getTargetNamespace();
if (tns != null) {
serviceName = XMLHelper.createQName(tns, serviceName.getLocalPart());
}
}
ServiceDomain serviceDomain = getServiceDomain();
if (serviceDomain == null) {
throw CommonKnowledgeMessages.MESSAGES.serviceDomainNull();
}
ServiceReference serviceReference = serviceDomain.getServiceReference(serviceName);
if (serviceReference == null) {
throw CommonKnowledgeMessages.MESSAGES.serviceReferenceNull(serviceName.toString());
}
final Exchange exchangeIn;
FaultHandler handler = new FaultHandler();
String operationName = request.getOperationName();
if (operationName != null) {
exchangeIn = serviceReference.createExchange(operationName, handler);
} else {
exchangeIn = serviceReference.createExchange(handler);
}
Message messageIn = exchangeIn.createMessage();
Context contextIn = exchangeIn.getContext(messageIn);
for (Map.Entry<String, Object> entry : request.getContext().entrySet()) {
contextIn.setProperty(entry.getKey(), entry.getValue());
}
Object contentIn = request.getContent();
if (contentIn != null) {
messageIn.setContent(contentIn);
}
exchangeIn.send(messageIn);
if (ExchangePattern.IN_OUT.equals(exchangeIn.getContract().getConsumerOperation().getExchangePattern())) {
Exchange exchangeOut = handler.waitForOut();
Message messageOut = exchangeOut.getMessage();
contentOut = messageOut.getContent();
for (Property property : exchangeOut.getContext(messageOut).getProperties()) {
contextOut.put(property.getName(), property.getValue());
}
}
fault = handler.getFault();
} catch (Throwable t) {
fault = t;
}
return new SwitchYardServiceResponse(contentOut, contextOut, fault);
}
示例12: map
import org.switchyard.Context; //导入方法依赖的package包/类
private void map(HttpRequestInfo requestInfo, Context context) {
context.setProperty(org.apache.camel.Exchange.HTTP_METHOD, requestInfo.getMethod());
context.setProperty(org.apache.camel.Exchange.HTTP_URI, REFERENCE_BASE_URL + requestInfo.getPathInfo());
context.setProperty(org.apache.camel.Exchange.HTTP_QUERY, requestInfo.getQueryString());
}