use of org.apache.cxf.binding.corba.wsdl.AddressType in project cxf by apache.
the class CorbaConduit method prepare.
public void prepare(Message message) throws IOException {
try {
prepareOrb();
String address = null;
if (target != null) {
address = target.getAddress().getValue();
}
if (address == null) {
AddressType ad = endpointInfo.getExtensor(AddressType.class);
if (ad != null) {
address = ad.getLocation();
}
}
String ref = (String) message.get(Message.ENDPOINT_ADDRESS);
if (ref != null) {
// A non-null endpoint address from the message means that we want to invoke on a particular
// object reference specified by the endpoint reference type. If the reference is null, then
// we want to invoke on the default location as specified in the WSDL.
address = ref;
}
if (address == null) {
LOG.log(Level.SEVERE, "Unable to locate a valid CORBA address");
throw new CorbaBindingException("Unable to locate a valid CORBA address");
}
org.omg.CORBA.Object targetObject;
targetObject = CorbaUtils.importObjectReference(orb, address);
message.put(CorbaConstants.ORB, orb);
message.put(CorbaConstants.CORBA_ENDPOINT_OBJECT, targetObject);
message.setContent(OutputStream.class, new CorbaOutputStream(message));
if (message instanceof CorbaMessage) {
((CorbaMessage) message).setCorbaTypeMap(typeMap);
}
} catch (java.lang.Exception ex) {
LOG.log(Level.SEVERE, "Could not resolve target object");
throw new CorbaBindingException(ex);
}
}
use of org.apache.cxf.binding.corba.wsdl.AddressType in project cxf by apache.
the class CorbaDestination method getAddressWithId.
public EndpointReferenceType getAddressWithId(String id) {
EndpointReferenceType ref = null;
if (bindingPOA == null) {
throw new CorbaBindingException("getAddressWithId failed because the poa is null");
}
try {
Servant servant = bindingPOA.id_to_servant(objectId);
org.omg.CORBA.Object objRef = bindingPOA.create_reference_with_id(id.getBytes(), servant._all_interfaces(bindingPOA, objectId)[0]);
AddressType addr = new AddressType();
orbConfig.exportObjectReference(orb, objRef, address.getLocation(), addr);
ref = EndpointReferenceUtils.getEndpointReference(addr.getLocation());
EndpointInfo ei = getEndPointInfo();
if (ei.getService() != null) {
EndpointReferenceUtils.setServiceAndPortName(ref, ei.getService().getName(), ei.getName().getLocalPart());
}
} catch (Exception e) {
throw new CorbaBindingException("Failed to getAddressWithId, reason:" + e.toString(), e);
}
return ref;
}
use of org.apache.cxf.binding.corba.wsdl.AddressType in project cxf by apache.
the class WSDLToCorbaBindingTypeTest method testSetCorbaAddress.
@Test
public void testSetCorbaAddress() throws Exception {
try {
String fileName = getClass().getResource("/wsdl/datetime.wsdl").toString();
generator.setWsdlFile(fileName);
generator.addInterfaceName("BasePortType");
Definition model = generator.generateCORBABinding();
QName name = new QName("http://schemas.apache.org/idl/datetime.idl", "BaseCORBAService", "tns");
Service service = model.getService(name);
Port port = service.getPort("BaseCORBAPort");
AddressType addressType = (AddressType) port.getExtensibilityElements().get(0);
String address = addressType.getLocation();
assertEquals("file:./Base.ref", address);
generator.setAddress("corbaloc::localhost:40000/hw");
model = generator.generateCORBABinding();
service = model.getService(name);
port = service.getPort("BaseCORBAPort");
addressType = (AddressType) port.getExtensibilityElements().get(0);
address = addressType.getLocation();
assertEquals("corbaloc::localhost:40000/hw", address);
} finally {
new File("datetime-corba.wsdl").deleteOnExit();
}
}
use of org.apache.cxf.binding.corba.wsdl.AddressType in project cxf by apache.
the class WSDLToCorbaBinding method generateCORBAServiceForBinding.
private void generateCORBAServiceForBinding(Definition definition, PortType portType, Binding binding) throws Exception {
if (extReg == null) {
extReg = def.getExtensionRegistry();
}
String interfaceName = portType.getQName().getLocalPart();
interfaceName = mangleInterfaceName(interfaceName);
String serviceName = interfaceName + "CORBAService";
String portName = interfaceName + "CORBAPort";
String prefix = definition.getPrefix(definition.getTargetNamespace());
if (prefix == null) {
prefix = "";
}
String corbaPrefix = definition.getPrefix(CorbaConstants.NU_WSDL_CORBA);
if (corbaPrefix == null) {
corbaPrefix = "corba";
def.addNamespace(corbaPrefix, CorbaConstants.NU_WSDL_CORBA);
}
// Build the service and port information and add it to the wsdl
Service service = def.createService();
Port servicePort = def.createPort();
servicePort.setName(portName);
servicePort.setBinding(binding);
try {
AddressType addressType = (AddressType) def.getExtensionRegistry().createExtension(Port.class, CorbaConstants.NE_CORBA_ADDRESS);
String addr = null;
if (getAddressFile() != null) {
BufferedReader bufferedReader = null;
try {
File addrFile = new File(getAddressFile());
FileReader fileReader = new FileReader(addrFile);
bufferedReader = new BufferedReader(fileReader);
addr = bufferedReader.readLine();
} catch (Exception ex) {
throw new ToolException(ex.getMessage(), ex);
} finally {
if (bufferedReader != null) {
bufferedReader.close();
}
}
} else {
addr = getAddress();
}
if (addr == null) {
addr = "file:./" + interfaceName + ".ref";
}
addressType.setLocation(addr);
servicePort.addExtensibilityElement((ExtensibilityElement) addressType);
} catch (WSDLException ex) {
throw new Exception("Failed to create CORBA address for service", ex);
}
QName serviceQName = new QName(definition.getTargetNamespace(), serviceName, prefix);
service.setQName(serviceQName);
service.addPort(servicePort);
definition.addService(service);
}
use of org.apache.cxf.binding.corba.wsdl.AddressType in project cxf by apache.
the class IDLToWSDLProcessor method generateCORBAService.
public void generateCORBAService(Definition def, Binding[] bindings, boolean isDefaultMapping) throws Exception {
Map<String, Service> serviceMap = new HashMap<>();
Map<String, String> serviceNames = getServiceNames(bindings, isDefaultMapping);
for (int i = 0; i < bindings.length; i++) {
QName portTypeName = bindings[i].getPortType().getQName();
Service service;
if (isDefaultMapping) {
service = def.createService();
service.setQName(new QName(def.getTargetNamespace(), portTypeName.getLocalPart() + "CORBAService"));
def.addService(service);
} else {
String ns = portTypeName.getNamespaceURI();
String serviceName = serviceNames.get(ns);
service = serviceMap.get(ns);
if (service == null) {
service = def.createService();
serviceMap.put(ns, service);
String[] serviceTokens = serviceName.split("\\.");
String serviceToken = serviceTokens[serviceTokens.length - 1];
QName serviceQName = new QName(def.getTargetNamespace(), serviceToken);
Service existingService = def.getService(serviceQName);
if (existingService != null) {
String existingServiceNS = ((Port) existingService.getPorts().values().iterator().next()).getBinding().getPortType().getQName().getNamespaceURI();
existingService.setQName(new QName(def.getTargetNamespace(), serviceNames.get(existingServiceNS)));
serviceMap.put(existingServiceNS, existingService);
service.setQName(new QName(def.getTargetNamespace(), serviceName));
} else {
service.setQName(serviceQName);
}
def.addService(service);
}
}
Port port = def.createPort();
port.setName(portTypeName.getLocalPart() + "CORBAPort");
AddressType address = (AddressType) def.getExtensionRegistry().createExtension(Port.class, CorbaConstants.NE_CORBA_ADDRESS);
String addr = null;
String addrFileName = (String) env.get(ToolCorbaConstants.CFG_ADDRESSFILE);
if (addrFileName != null) {
BufferedReader bufferedReader = null;
try {
File addrFile = new File(addrFileName);
FileReader fileReader = new FileReader(addrFile);
bufferedReader = new BufferedReader(fileReader);
addr = bufferedReader.readLine();
} catch (Exception ex) {
throw new ToolException(ex.getMessage(), ex);
} finally {
if (bufferedReader != null) {
bufferedReader.close();
}
}
} else {
addr = (String) env.get(ToolCorbaConstants.CFG_ADDRESS);
}
if (addr == null) {
addr = "IOR:";
}
address.setLocation(addr);
port.addExtensibilityElement((ExtensibilityElement) address);
service.addPort(port);
port.setBinding(bindings[i]);
}
}
Aggregations