use of org.apache.cxf.endpoint.EndpointImpl in project cxf by apache.
the class AbstractWSDLBasedEndpointFactory method createEndpoint.
protected Endpoint createEndpoint() throws BusException, EndpointException {
serviceFactory.setFeatures(getFeatures());
if (serviceName != null) {
serviceFactory.setServiceName(serviceName);
}
if (endpointName != null) {
serviceFactory.setEndpointName(endpointName);
}
Service service = serviceFactory.getService();
if (service == null) {
initializeServiceFactory();
service = serviceFactory.create();
}
if (endpointName == null) {
endpointName = serviceFactory.getEndpointName();
}
EndpointInfo ei = service.getEndpointInfo(endpointName);
if (ei != null) {
if ((transportId != null && !ei.getTransportId().equals(transportId)) || (bindingId != null && !ei.getBinding().getBindingId().equals(bindingId))) {
ei = null;
} else {
BindingFactoryManager bfm = getBus().getExtension(BindingFactoryManager.class);
bindingFactory = bfm.getBindingFactory(ei.getBinding().getBindingId());
}
}
if (ei == null) {
if (getAddress() == null) {
ei = ServiceModelUtil.findBestEndpointInfo(serviceFactory.getInterfaceName(), service.getServiceInfos());
}
if (ei == null && !serviceFactory.isPopulateFromClass()) {
ei = ServiceModelUtil.findBestEndpointInfo(serviceFactory.getInterfaceName(), service.getServiceInfos());
if (ei != null) {
BindingFactoryManager bfm = getBus().getExtension(BindingFactoryManager.class);
bindingFactory = bfm.getBindingFactory(ei.getBinding().getBindingId());
}
if (ei == null) {
LOG.warning("Could not find endpoint/port for " + endpointName + " in wsdl. Creating default.");
} else if (!ei.getName().equals(endpointName)) {
LOG.warning("Could not find endpoint/port for " + endpointName + " in wsdl. Using " + ei.getName() + ".");
}
}
if (ei == null) {
ei = createEndpointInfo(null);
} else if (transportId != null && !ei.getTransportId().equals(transportId)) {
LOG.warning("Transport for endpoint/port " + endpointName + " in wsdl doesn't match " + transportId + ".");
BindingInfo bi = ei.getBinding();
ei = createEndpointInfo(bi);
} else if (bindingId != null && !ei.getBinding().getBindingId().equals(bindingId) && // consider SoapBinding has multiple default namespace
!(SoapBindingFactory.DEFAULT_NAMESPACES.contains(bindingId) && SoapBindingFactory.DEFAULT_NAMESPACES.contains(ei.getBinding().getBindingId()))) {
LOG.warning("Binding for endpoint/port " + endpointName + " in wsdl doesn't match " + bindingId + ".");
ei = createEndpointInfo(null);
} else if (getAddress() != null) {
ei.setAddress(getAddress());
if (ei.getAddress().startsWith("camel") || ei.getAddress().startsWith("local")) {
modifyTransportIdPerAddress(ei);
}
}
} else if (getAddress() != null) {
ei.setAddress(getAddress());
}
if (publishedEndpointUrl != null && !"".equals(publishedEndpointUrl)) {
ei.setProperty("publishedEndpointUrl", publishedEndpointUrl);
}
if (endpointReference != null) {
ei.setAddress(endpointReference);
}
Endpoint ep = service.getEndpoints().get(ei.getName());
if (ep == null) {
ep = serviceFactory.createEndpoint(ei);
((EndpointImpl) ep).initializeActiveFeatures(getFeatures());
} else {
serviceFactory.setEndpointName(ei.getName());
if (ep.getActiveFeatures() == null) {
((EndpointImpl) ep).initializeActiveFeatures(getFeatures());
}
}
if (properties != null) {
ep.putAll(properties);
}
service.getEndpoints().put(ep.getEndpointInfo().getName(), ep);
if (getInInterceptors() != null) {
ep.getInInterceptors().addAll(getInInterceptors());
ep.getInInterceptors().add(WSDLGetInterceptor.INSTANCE);
}
if (getOutInterceptors() != null) {
ep.getOutInterceptors().addAll(getOutInterceptors());
}
if (getInFaultInterceptors() != null) {
ep.getInFaultInterceptors().addAll(getInFaultInterceptors());
}
if (getOutFaultInterceptors() != null) {
ep.getOutFaultInterceptors().addAll(getOutFaultInterceptors());
}
serviceFactory.sendEvent(FactoryBeanListener.Event.ENDPOINT_SELECTED, ei, ep, serviceFactory.getServiceClass(), getServiceClass());
return ep;
}
use of org.apache.cxf.endpoint.EndpointImpl in project cxf by apache.
the class ManagedRMManagerTest method createTestEndpoint.
private Endpoint createTestEndpoint() throws Exception {
ServiceInfo svci = new ServiceInfo();
svci.setName(new QName(TEST_URI, "testService"));
Service svc = new ServiceImpl(svci);
SoapBindingInfo binding = new SoapBindingInfo(svci, WSDLConstants.NS_SOAP11);
binding.setTransportURI(WSDLConstants.NS_SOAP_HTTP_TRANSPORT);
EndpointInfo ei = new EndpointInfo();
ei.setAddress(TEST_URI);
ei.setName(new QName(TEST_URI, "testPort"));
ei.setBinding(binding);
ei.setService(svci);
return new EndpointImpl(bus, svc, ei);
}
use of org.apache.cxf.endpoint.EndpointImpl in project cxf by apache.
the class ServiceModelUtilsTest method getService.
private Service getService(URL wsdl, Class<?> implClz, QName port) throws EndpointException {
assertNotNull(wsdl);
bean.setWsdlURL(wsdl.toString());
bean.setServiceClass(implClz);
Service service = bean.create();
EndpointInfo endpointInfo = service.getServiceInfos().get(0).getEndpoint(port);
Endpoint endpoint = new EndpointImpl(getBus(), service, endpointInfo);
exchange.put(Service.class, service);
exchange.put(Endpoint.class, endpoint);
return service;
}
use of org.apache.cxf.endpoint.EndpointImpl in project cxf by apache.
the class AbstractSTSClient method configureViaEPR.
public void configureViaEPR(EndpointReferenceType ref, boolean useEPRWSAAddrAsMEXLocation) {
if (client != null) {
return;
}
location = EndpointReferenceUtils.getAddress(ref);
if (location != null) {
location = location.trim();
}
if (LOG.isLoggable(Level.FINE)) {
LOG.fine("EPR address: " + location);
}
final QName sName = EndpointReferenceUtils.getServiceName(ref, bus);
if (sName != null) {
serviceName = sName;
final QName epName = EndpointReferenceUtils.getPortQName(ref, bus);
if (epName != null) {
endpointName = epName;
}
if (LOG.isLoggable(Level.FINE)) {
LOG.fine("EPR endpoint: " + serviceName + " " + endpointName);
}
}
final String wsdlLoc = EndpointReferenceUtils.getWSDLLocation(ref);
if (wsdlLoc != null) {
wsdlLocation = wsdlLoc;
}
String mexLoc = findMEXLocation(ref, useEPRWSAAddrAsMEXLocation);
if (LOG.isLoggable(Level.FINE)) {
LOG.fine("WS-MEX location: " + mexLoc);
}
if (mexLoc != null) {
try {
JaxWsProxyFactoryBean proxyFac = new JaxWsProxyFactoryBean();
proxyFac.setBindingId(soapVersion);
proxyFac.setAddress(mexLoc);
MetadataExchange exc = proxyFac.create(MetadataExchange.class);
Metadata metadata = exc.get2004();
Definition definition = null;
List<Schema> schemas = new ArrayList<>();
// Parse the MetadataSections into WSDL definition + associated schemas
for (MetadataSection s : metadata.getMetadataSection()) {
if ("http://schemas.xmlsoap.org/wsdl/".equals(s.getDialect())) {
definition = bus.getExtension(WSDLManager.class).getDefinition((Element) s.getAny());
} else if ("http://www.w3.org/2001/XMLSchema".equals(s.getDialect())) {
Element schemaElement = (Element) s.getAny();
if (schemaElement == null) {
String schemaLocation = s.getLocation();
LOG.info("XSD schema location: " + schemaLocation);
schemaElement = downloadSchema(schemaLocation);
}
QName schemaName = new QName(schemaElement.getNamespaceURI(), schemaElement.getLocalName());
WSDLManager wsdlManager = bus.getExtension(WSDLManager.class);
ExtensibilityElement exElement = wsdlManager.getExtensionRegistry().createExtension(Types.class, schemaName);
((Schema) exElement).setElement(schemaElement);
schemas.add((Schema) exElement);
}
}
if (definition != null) {
// Add any extra schemas to the WSDL definition
for (Schema schema : schemas) {
definition.getTypes().addExtensibilityElement(schema);
}
WSDLServiceFactory factory = new WSDLServiceFactory(bus, definition);
SourceDataBinding dataBinding = new SourceDataBinding();
factory.setDataBinding(dataBinding);
Service service = factory.create();
service.setDataBinding(dataBinding);
// Get the endpoint + service names by matching the 'location' to the
// address in the WSDL. If the 'location' is 'anonymous' then just fall
// back to the first service + endpoint name in the WSDL, if the endpoint
// name is not defined in the Metadata
List<ServiceInfo> services = service.getServiceInfos();
String anonymousAddress = "http://www.w3.org/2005/08/addressing/anonymous";
if (!anonymousAddress.equals(location)) {
for (ServiceInfo serv : services) {
for (EndpointInfo ei : serv.getEndpoints()) {
if (ei.getAddress().equals(location)) {
endpointName = ei.getName();
serviceName = serv.getName();
LOG.fine("Matched endpoint to location");
}
}
}
}
EndpointInfo ei = service.getEndpointInfo(endpointName);
if (ei == null && anonymousAddress.equals(location) && !services.isEmpty() && !services.get(0).getEndpoints().isEmpty()) {
LOG.fine("Anonymous location so taking first endpoint");
serviceName = services.get(0).getName();
endpointName = services.get(0).getEndpoints().iterator().next().getName();
ei = service.getEndpointInfo(endpointName);
}
if (ei == null) {
throw new TrustException(LOG, "ADDRESS_NOT_MATCHED", location);
}
if (location != null && !anonymousAddress.equals(location)) {
ei.setAddress(location);
}
Endpoint endpoint = new EndpointImpl(bus, service, ei);
client = new ClientImpl(bus, endpoint);
}
} catch (Exception ex) {
throw new TrustException("WS_MEX_ERROR", ex, LOG);
}
}
}
use of org.apache.cxf.endpoint.EndpointImpl in project cxf by apache.
the class STSUtils method createSTSEndpoint.
// CHECKSTYLE:OFF
private static Endpoint createSTSEndpoint(Bus bus, String namespace, String transportId, String location, String soapVersion, Policy policy, QName epName, boolean sc) throws BusException, EndpointException {
// CHECKSTYLE:ON
String ns = namespace + "/wsdl";
ServiceInfo si = new ServiceInfo();
QName iName = new QName(ns, sc ? "SecureConversationTokenService" : "SecurityTokenService");
si.setName(iName);
InterfaceInfo ii = new InterfaceInfo(si, iName);
OperationInfo ioi = addIssueOperation(ii, namespace, ns);
OperationInfo coi = addCancelOperation(ii, namespace, ns);
OperationInfo roi = addRenewOperation(ii, namespace, ns);
si.setInterface(ii);
Service service = new ServiceImpl(si);
BindingFactoryManager bfm = bus.getExtension(BindingFactoryManager.class);
BindingFactory bindingFactory = bfm.getBindingFactory(soapVersion);
BindingInfo bi = bindingFactory.createBindingInfo(service, soapVersion, null);
si.addBinding(bi);
if (transportId == null) {
ConduitInitiatorManager cim = bus.getExtension(ConduitInitiatorManager.class);
ConduitInitiator ci = cim.getConduitInitiatorForUri(location);
transportId = ci.getTransportIds().get(0);
}
EndpointInfo ei = new EndpointInfo(si, transportId);
ei.setBinding(bi);
ei.setName(epName == null ? iName : epName);
ei.setAddress(location);
si.addEndpoint(ei);
if (policy != null) {
ei.addExtensor(policy);
}
BindingOperationInfo boi = bi.getOperation(ioi);
SoapOperationInfo soi = boi.getExtensor(SoapOperationInfo.class);
if (soi == null) {
soi = new SoapOperationInfo();
boi.addExtensor(soi);
}
soi.setAction(namespace + (sc ? "/RST/SCT" : "/RST/Issue"));
boi = bi.getOperation(coi);
soi = boi.getExtensor(SoapOperationInfo.class);
if (soi == null) {
soi = new SoapOperationInfo();
boi.addExtensor(soi);
}
soi.setAction(namespace + (sc ? "/RST/SCT/Cancel" : "/RST/Cancel"));
boi = bi.getOperation(roi);
soi = boi.getExtensor(SoapOperationInfo.class);
if (soi == null) {
soi = new SoapOperationInfo();
boi.addExtensor(soi);
}
soi.setAction(namespace + (sc ? "/RST/SCT/Renew" : "/RST/Renew"));
service.setDataBinding(new SourceDataBinding());
return new EndpointImpl(bus, service, ei);
}
Aggregations