public static BindingTemplate registerBinding(UDDIClient client, String cfg_node_name, BindingTemplate bt, SignatureBehavior behavior) throws ServiceAlreadyStartedException, SecurityException, ConfigurationException, TransportException, DispositionReportFaultMessage, RemoteException, UnexpectedException, RegistrationAbortedException, UnableToSignException {
UDDIClerk clerk = client.getClerk(cfg_node_name);
Transport tp = client.getTransport(cfg_node_name);
UDDIInquiryPortType uddiInquiryService = tp.getUDDIInquiryService();
UDDIPublicationPortType uddiPublishService = tp.getUDDIPublishService();
String token = clerk.getAuthToken(clerk.getUDDINode().getSecurityUrl());
switch (behavior) {
case AbortIfSigned:
if (CheckExistingBindingForSignature(bt.getBindingKey(), uddiInquiryService, token, behavior)) {
throw new RegistrationAbortedException("Aborting, Either the item exists and is signed");
}
if (CheckServiceAndParentForSignature(bt.getServiceKey(), uddiInquiryService, token)) {
throw new RegistrationAbortedException("Aborting, Either the service or busness is signed");
}
break;
case DoNothing:
break;
case SignAlways:
try {
DigSigUtil ds = new DigSigUtil(client.getClientConfig().getDigitalSignatureConfiguration());
bt = ds.signUddiEntity(bt);
} catch (Exception ex) {
log.error("Unable to sign", ex);
throw new UnableToSignException(ex);
}
break;
case SignOnlyIfParentIsntSigned:
if (!CheckServiceAndParentForSignature(bt.getServiceKey(), uddiInquiryService, token)) {
try {
DigSigUtil ds = new DigSigUtil(client.getClientConfig().getDigitalSignatureConfiguration());
bt = ds.signUddiEntity(bt);
} catch (Exception ex) {
log.error("Unable to sign", ex);
throw new UnableToSignException(ex);
}
}
break;
}
SaveBinding sb = new SaveBinding();
sb.setAuthInfo(token);
sb.getBindingTemplate().add(bt);
BindingDetail saveBinding = uddiPublishService.saveBinding(sb);
if (saveBinding.getBindingTemplate().isEmpty() || saveBinding.getBindingTemplate().size() > 1) {
throw new UnexpectedResponseException("The number of binding templates returned was unexpected, count=" + saveBinding.getBindingTemplate().size());
}
return saveBinding.getBindingTemplate().get(0);
}