use of org.apache.cxf.service.Service in project tesb-rt-se by Talend.
the class LocatorFeatureTest method initializeClient.
@Test
public void initializeClient() throws EndpointException {
LocatorClientEnabler enabler = new LocatorClientEnabler();
enabler.setLocatorSelectionStrategyMap(locatorSelectionStrategyMap);
enabler.setDefaultLocatorSelectionStrategy("evenDistributionSelectionStrategy");
ClientLifeCycleManager clcm = new ClientLifeCycleManagerImpl();
expect(busMock.getExtension(ClientLifeCycleManager.class)).andStubReturn(clcm);
replayAll();
EndpointInfo ei = new EndpointInfo();
Service service = new org.apache.cxf.service.ServiceImpl();
EndpointImpl endpoint = new EndpointImpl(busMock, service, ei);
Map<String, String> locatorProps = new HashMap<String, String>();
locatorProps.put("key1", "value1");
locatorProps.put("key2", "value2");
endpoint.put(LocatorFeature.LOCATOR_PROPERTIES, locatorProps);
endpoint.put(LocatorFeature.KEY_STRATEGY, "randomSelectionStrategy");
Client client = new ClientImpl(busMock, endpoint);
LocatorTargetSelector selector = new LocatorTargetSelector();
selector.setEndpoint(endpoint);
client.setConduitSelector(selector);
LocatorFeatureImpl lf = new LocatorFeatureImpl();
lf.setLocatorRegistrar(locatorRegistrarMock);
lf.setClientEnabler(enabler);
lf.initialize(client, busMock);
Assert.assertTrue(((LocatorTargetSelector) client.getConduitSelector()).getStrategy() instanceof RandomSelectionStrategy);
}
use of org.apache.cxf.service.Service in project tesb-rt-se by Talend.
the class LocatorFeatureTest method initializeInterceptorProvider.
@Test
public void initializeInterceptorProvider() throws EndpointException {
LocatorClientEnabler enabler = new LocatorClientEnabler();
enabler.setLocatorSelectionStrategyMap(locatorSelectionStrategyMap);
enabler.setDefaultLocatorSelectionStrategy("evenDistributionSelectionStrategy");
ClientLifeCycleManager clcm = new ClientLifeCycleManagerImpl();
expect(busMock.getExtension(ClientLifeCycleManager.class)).andStubReturn(clcm);
replayAll();
EndpointInfo ei = new EndpointInfo();
Service service = new org.apache.cxf.service.ServiceImpl();
Endpoint endpoint = new EndpointImpl(busMock, service, ei);
endpoint.put(LocatorFeature.KEY_STRATEGY, "randomSelectionStrategy");
ClientConfiguration client = new ClientConfiguration();
LocatorTargetSelector selector = new LocatorTargetSelector();
selector.setEndpoint(endpoint);
client.setConduitSelector(selector);
LocatorFeatureImpl lf = new LocatorFeatureImpl();
lf.setLocatorRegistrar(locatorRegistrarMock);
lf.setClientEnabler(enabler);
lf.initialize((InterceptorProvider) client, busMock);
Assert.assertTrue(((LocatorTargetSelector) client.getConduitSelector()).getStrategy() instanceof RandomSelectionStrategy);
}
use of org.apache.cxf.service.Service in project jbossws-cxf by jbossws.
the class JBossWSInvokerTest method getTestExchange.
// build up a fake exchange instance, the minimum required to let the flow proceed till the JBossWSInvoker
private Exchange getTestExchange() {
Exchange exchange = new ExchangeImpl();
Message message = new MessageImpl();
message.setExchange(exchange);
exchange.setInMessage(message);
exchange.put(BindingOperationInfo.class, new BindingOperationInfo());
Service service = new ServiceImpl();
MethodDispatcher md = new MethodDispatcher() {
@Override
public Method getMethod(BindingOperationInfo op) {
return this.getClass().getMethods()[0];
}
@Override
public BindingOperationInfo getBindingOperation(Method m, Endpoint endpoint) {
return null;
}
@Override
public void bind(OperationInfo o, Method... methods) {
}
};
service.put(MethodDispatcher.class.getName(), md);
exchange.put(Service.class, service);
return exchange;
}
use of org.apache.cxf.service.Service in project tomee by apache.
the class PhaseInterceptorChain method getServiceInfo.
private String getServiceInfo(Message message) {
StringBuilder description = new StringBuilder();
if (message.getExchange() != null) {
Exchange exchange = message.getExchange();
Service service = exchange.getService();
if (service != null) {
description.append('\'');
description.append(service.getName());
BindingOperationInfo boi = exchange.getBindingOperationInfo();
OperationInfo opInfo = boi != null ? boi.getOperationInfo() : null;
if (opInfo != null) {
description.append('#').append(opInfo.getName());
}
description.append("\' ");
}
}
return description.toString();
}
use of org.apache.cxf.service.Service in project cxf by apache.
the class AbstractOutDatabindingInterceptor method writeParts.
protected void writeParts(Message message, Exchange exchange, BindingOperationInfo operation, MessageContentsList objs, List<MessagePartInfo> parts) {
OutputStream out = message.getContent(OutputStream.class);
XMLStreamWriter origXmlWriter = message.getContent(XMLStreamWriter.class);
Service service = exchange.getService();
XMLStreamWriter xmlWriter = origXmlWriter;
CachingXmlEventWriter cache = null;
// configure endpoint and operation level schema validation
setOperationSchemaValidation(message);
// need to cache the events in case validation fails or buffering is enabled
if (shouldBuffer(message)) {
if (!(xmlWriter instanceof CachingXmlEventWriter)) {
cache = new CachingXmlEventWriter();
try {
cache.setNamespaceContext(origXmlWriter.getNamespaceContext());
} catch (XMLStreamException e) {
// ignorable, will just get extra namespace decls
}
xmlWriter = cache;
}
out = null;
}
if (out != null && writeToOutputStream(message, operation.getBinding(), service) && !MessageUtils.getContextualBoolean(message, DISABLE_OUTPUTSTREAM_OPTIMIZATION, false)) {
if (xmlWriter != null) {
try {
xmlWriter.writeCharacters("");
xmlWriter.flush();
} catch (XMLStreamException e) {
throw new Fault(e);
}
}
DataWriter<OutputStream> osWriter = getDataWriter(message, service, OutputStream.class);
for (MessagePartInfo part : parts) {
if (objs.hasValue(part)) {
Object o = objs.get(part);
osWriter.write(o, part, out);
}
}
} else {
DataWriter<XMLStreamWriter> dataWriter = getDataWriter(message, service, XMLStreamWriter.class);
for (MessagePartInfo part : parts) {
if (objs.hasValue(part)) {
NamespaceContext c = null;
if (!part.isElement() && xmlWriter instanceof CachingXmlEventWriter) {
try {
c = xmlWriter.getNamespaceContext();
xmlWriter.setNamespaceContext(new CachingXmlEventWriter.NSContext(null));
} catch (XMLStreamException e) {
// ignore
}
}
Object o = objs.get(part);
dataWriter.write(o, part, xmlWriter);
if (c != null) {
try {
xmlWriter.setNamespaceContext(c);
} catch (XMLStreamException e) {
// ignore
}
}
}
}
}
if (cache != null) {
try {
for (XMLEvent event : cache.getEvents()) {
StaxUtils.writeEvent(event, origXmlWriter);
}
} catch (XMLStreamException e) {
throw new Fault(e);
}
}
}
Aggregations