use of org.apache.cxf.transport.DestinationFactory in project cxf by apache.
the class MAPAggregatorTest method testGetReplyToUsingBaseAddress.
@Test
public void testGetReplyToUsingBaseAddress() throws Exception {
Message message = new MessageImpl();
Exchange exchange = new ExchangeImpl();
message.setExchange(exchange);
final String localReplyTo = "/SoapContext/decoupled";
final String decoupledEndpointBase = "http://localhost:8181/cxf";
final String replyTo = decoupledEndpointBase + localReplyTo;
ServiceInfo s = new ServiceInfo();
Service svc = new ServiceImpl(s);
EndpointInfo ei = new EndpointInfo();
InterfaceInfo ii = s.createInterface(new QName("FooInterface"));
s.setInterface(ii);
ii.addOperation(new QName("fooOp"));
SoapBindingInfo b = new SoapBindingInfo(s, "http://schemas.xmlsoap.org/soap/", Soap11.getInstance());
b.setTransportURI("http://schemas.xmlsoap.org/soap/http");
ei.setBinding(b);
ei.setAddress("http://nowhere.com/bar/foo");
ei.setName(new QName("http://nowhere.com/port", "foo"));
Bus bus = new ExtensionManagerBus();
DestinationFactoryManager dfm = control.createMock(DestinationFactoryManager.class);
DestinationFactory df = control.createMock(DestinationFactory.class);
Destination d = control.createMock(Destination.class);
bus.setExtension(dfm, DestinationFactoryManager.class);
EasyMock.expect(dfm.getDestinationFactoryForUri(localReplyTo)).andReturn(df);
EasyMock.expect(df.getDestination(EasyMock.anyObject(EndpointInfo.class), EasyMock.anyObject(Bus.class))).andReturn(d);
EasyMock.expect(d.getAddress()).andReturn(EndpointReferenceUtils.getEndpointReference(localReplyTo));
Endpoint ep = new EndpointImpl(bus, svc, ei);
exchange.put(Endpoint.class, ep);
exchange.put(Bus.class, bus);
exchange.setOutMessage(message);
setUpMessageProperty(message, REQUESTOR_ROLE, Boolean.TRUE);
message.getContextualProperty(WSAContextUtils.REPLYTO_PROPERTY);
message.put(WSAContextUtils.REPLYTO_PROPERTY, localReplyTo);
message.put(WSAContextUtils.DECOUPLED_ENDPOINT_BASE_PROPERTY, decoupledEndpointBase);
AddressingProperties maps = new AddressingProperties();
AttributedURIType id = ContextUtils.getAttributedURI("urn:uuid:12345");
maps.setMessageID(id);
maps.setAction(ContextUtils.getAttributedURI(""));
setUpMessageProperty(message, CLIENT_ADDRESSING_PROPERTIES, maps);
control.replay();
aggregator.mediate(message, false);
AddressingProperties props = (AddressingProperties) message.get(JAXWSAConstants.ADDRESSING_PROPERTIES_OUTBOUND);
assertEquals(replyTo, props.getReplyTo().getAddress().getValue());
control.verify();
}
use of org.apache.cxf.transport.DestinationFactory in project cxf by apache.
the class WSDLServiceBuilder method buildEndpoint.
public EndpointInfo buildEndpoint(ServiceInfo service, BindingInfo bi, Port port) {
List<?> elements = port.getExtensibilityElements();
String ns = null;
DestinationFactory factory = null;
EndpointInfo ei = null;
if (null != elements && !elements.isEmpty()) {
for (ExtensibilityElement el : CastUtils.cast(elements, ExtensibilityElement.class)) {
ns = el.getElementType().getNamespaceURI();
try {
factory = bus.getExtension(DestinationFactoryManager.class).getDestinationFactory(ns);
} catch (BusException e) {
// do nothing
}
if (factory != null) {
break;
}
}
if (factory == null) {
ns = ((ExtensibilityElement) elements.get(0)).getElementType().getNamespaceURI();
}
}
if (factory == null) {
// get the transport id from bindingInfo
elements = port.getBinding().getExtensibilityElements();
if (null != elements && !elements.isEmpty()) {
for (ExtensibilityElement el : CastUtils.cast(elements, ExtensibilityElement.class)) {
if (el instanceof SOAPBinding) {
ns = ((SOAPBinding) el).getTransportURI();
break;
} else if (el instanceof SOAP12Binding) {
ns = ((SOAP12Binding) el).getTransportURI();
break;
// TODO: this is really ugly, but how to link between
// this binding and this transport ?
}
}
}
if (ns == null) {
if (ignoreUnknownBindings) {
return null;
}
org.apache.cxf.common.i18n.Message msg = new org.apache.cxf.common.i18n.Message("MISSING_DESTINATION_FACTORY", LOG, port.getName());
throw new WSDLRuntimeException(msg);
}
try {
factory = bus.getExtension(DestinationFactoryManager.class).getDestinationFactory(ns);
} catch (BusException e) {
// do nothing
}
}
if (factory instanceof WSDLEndpointFactory) {
WSDLEndpointFactory wFactory = (WSDLEndpointFactory) factory;
ei = wFactory.createEndpointInfo(bus, service, bi, port.getExtensibilityElements());
}
if (ei == null) {
ei = new EndpointInfo(service, ns);
}
copyDocumentation(ei, port);
ei.setName(new QName(service.getName().getNamespaceURI(), port.getName()));
ei.setBinding(bi);
copyExtensors(ei, port.getExtensibilityElements());
copyExtensionAttributes(ei, port);
service.addEndpoint(ei);
DescriptionInfo d = service.getDescription();
if (null != d) {
d.getDescribed().add(ei);
}
return ei;
}
use of org.apache.cxf.transport.DestinationFactory in project cxf by apache.
the class ServiceWSDLBuilderTest method setupWSDL.
private void setupWSDL(String wsdlPath, boolean doXsdImports) throws Exception {
String wsdlUrl = getClass().getResource(wsdlPath).toString();
LOG.info("the path of wsdl file is " + wsdlUrl);
WSDLFactory wsdlFactory = WSDLFactory.newInstance();
WSDLReader wsdlReader = wsdlFactory.newWSDLReader();
wsdlReader.setFeature("javax.wsdl.verbose", false);
def = wsdlReader.readWSDL(wsdlUrl);
control = EasyMock.createNiceControl();
bus = control.createMock(Bus.class);
bindingFactoryManager = control.createMock(BindingFactoryManager.class);
destinationFactoryManager = control.createMock(DestinationFactoryManager.class);
destinationFactory = control.createMock(DestinationFactory.class);
wsdlServiceBuilder = new WSDLServiceBuilder(bus, false);
for (Service serv : CastUtils.cast(def.getServices().values(), Service.class)) {
if (serv != null) {
service = serv;
break;
}
}
EasyMock.expect(bus.getExtension(WSDLManager.class)).andReturn(new WSDLManagerImpl()).anyTimes();
EasyMock.expect(bus.getExtension(BindingFactoryManager.class)).andReturn(bindingFactoryManager);
EasyMock.expect(bus.getExtension(DestinationFactoryManager.class)).andReturn(destinationFactoryManager);
EasyMock.expect(destinationFactoryManager.getDestinationFactory("http://schemas.xmlsoap.org/wsdl/soap/")).andReturn(destinationFactory);
control.replay();
serviceInfo = wsdlServiceBuilder.buildServices(def, service).get(0);
ServiceWSDLBuilder builder = new ServiceWSDLBuilder(bus, serviceInfo);
builder.setUseSchemaImports(doXsdImports);
builder.setBaseFileName("HelloWorld");
newDef = builder.build(new HashMap<String, SchemaInfo>());
}
use of org.apache.cxf.transport.DestinationFactory in project cxf by apache.
the class WSDLServiceBuilderTest method buildService.
private void buildService(QName endpointName) throws Exception {
control = EasyMock.createNiceControl();
bus = control.createMock(Bus.class);
bindingFactoryManager = control.createMock(BindingFactoryManager.class);
destinationFactoryManager = control.createMock(DestinationFactoryManager.class);
DestinationFactory destinationFactory = control.createMock(DestinationFactory.class);
WSDLServiceBuilder wsdlServiceBuilder = new WSDLServiceBuilder(bus);
EasyMock.expect(bus.getExtension(BindingFactoryManager.class)).andReturn(bindingFactoryManager).anyTimes();
EasyMock.expect(bus.getExtension(DestinationFactoryManager.class)).andReturn(destinationFactoryManager).atLeastOnce();
EasyMock.expect(destinationFactoryManager.getDestinationFactory("http://schemas.xmlsoap.org/wsdl/soap/")).andReturn(destinationFactory).anyTimes();
control.replay();
serviceInfos = wsdlServiceBuilder.buildServices(def, service, endpointName);
if (!serviceInfos.isEmpty()) {
serviceInfo = serviceInfos.get(0);
} else {
serviceInfo = null;
}
}
use of org.apache.cxf.transport.DestinationFactory in project cxf by apache.
the class AbstractJAXRSFactoryBean method createEndpointInfo.
/*
* EndpointInfo contains information form WSDL's physical part such as
* endpoint address, binding, transport etc. For JAX-RS based EndpointInfo,
* as there is no WSDL, these information are set manually, eg, default
* transport is http, binding is JAX-RS binding, endpoint address is from
* server mainline.
*/
protected EndpointInfo createEndpointInfo(Service service) throws BusException {
String transportId = getTransportId();
if (transportId == null && getAddress() != null) {
DestinationFactory df = getDestinationFactory();
if (df == null) {
DestinationFactoryManager dfm = getBus().getExtension(DestinationFactoryManager.class);
df = dfm.getDestinationFactoryForUri(getAddress());
super.setDestinationFactory(df);
}
if (df != null) {
transportId = df.getTransportIds().get(0);
}
}
// default to http transport
if (transportId == null) {
transportId = "http://cxf.apache.org/transports/http";
}
setTransportId(transportId);
EndpointInfo ei = new EndpointInfo();
ei.setTransportId(transportId);
ei.setName(serviceFactory.getService().getName());
ei.setAddress(getAddress());
BindingInfo bindingInfo = createBindingInfo();
ei.setBinding(bindingInfo);
if (!StringUtils.isEmpty(publishedEndpointUrl)) {
ei.setProperty("publishedEndpointUrl", publishedEndpointUrl);
}
ei.setName(service.getName());
serviceFactory.sendEvent(FactoryBeanListener.Event.ENDPOINTINFO_CREATED, ei);
return ei;
}
Aggregations