portName = "";
}
// Check if the same endpoint is already defined in webservices.xml
WebServicesDescriptor wsDesc = bundleDesc.getWebServices();
WebServiceEndpoint endpoint = wsDesc.getEndpointByName(portComponentName);
WebService newWS;
if(endpoint == null) {
// Check if a service with the same name is already present
// If so, add this endpoint to the existing service
if (svcName.length()!=0) {
newWS = wsDesc.getWebServiceByName(svcName);
} else {
newWS = wsDesc.getWebServiceByName(((Class)annElem).getSimpleName()+"Service");
}
if(newWS==null) {
newWS = new WebService();
// service name from annotation
if (svcName.length()!=0) {
newWS.setName(svcName);
} else {
newWS.setName(((Class)annElem).getSimpleName()+"Service");
}
wsDesc.addWebService(newWS);
}
endpoint = new WebServiceEndpoint();
// port-component-name is fully qualified class name
endpoint.setEndpointName(portComponentName);
newWS.addEndpoint(endpoint);
wsDesc.setSpecVersion(com.sun.enterprise.deployment.node.WebServicesDescriptorNode.SPEC_VERSION);
} else {
newWS = endpoint.getWebService();
}
// If wsdl-service is specified in the descriptor, then the targetnamespace
// in wsdl-service should match the @WebService.targetNameSpace, if any.
// make that assertion here - and the targetnamespace in wsdl-service, if
// present overrides everything else
if(endpoint.getWsdlService() != null) {
if( (targetNameSpace != null) && (targetNameSpace.length() != 0 ) &&
(!endpoint.getWsdlService().getNamespaceURI().equals(targetNameSpace)) ) {
throw new AnnotationProcessorException(
"Target Namespace inwsdl-service element does not match @WebService.targetNamespace",
annInfo);
}
targetNameSpace = endpoint.getWsdlService().getNamespaceURI();
}
// Set binding id id @BindingType is specified by the user in the impl class
if((!endpoint.hasUserSpecifiedProtocolBinding()) &&
(userSpecifiedBinding != null) &&
(userSpecifiedBinding.length() != 0)){
endpoint.setProtocolBinding(userSpecifiedBinding);
}
// Use annotated values only if the deployment descriptor equivalent has not been specified
if(newWS.getWsdlFileUri() == null) {
// take wsdl location from annotation
if (ann.wsdlLocation()!=null && ann.wsdlLocation().length()!=0) {
newWS.setWsdlFileUri(ann.wsdlLocation());
}
}
annElem = annInfo.getAnnotatedElement();
// we checked that the endpoint implements the provider interface above
Class clz = (Class) annElem;
Class serviceEndpointIntf = null;
for (Class intf : clz.getInterfaces()) {
if (javax.xml.ws.Provider.class.isAssignableFrom(intf)) {
serviceEndpointIntf = intf;
break;
}
}
if (serviceEndpointIntf==null) {
endpoint.setServiceEndpointInterface("javax.xml.ws.Provider");
} else {
endpoint.setServiceEndpointInterface(serviceEndpointIntf.getName());
}
if (XModuleType.WAR.equals(bundleDesc.getModuleType())) {
if(endpoint.getServletImplClass() == null) {
// Set servlet impl class here
endpoint.setServletImplClass(((Class)annElem).getName());
}
// Servlet link name
WebBundleDescriptor webBundle = (WebBundleDescriptor) bundleDesc;
if(endpoint.getWebComponentLink() == null) {
endpoint.setWebComponentLink(portComponentName);
}
if(endpoint.getWebComponentImpl() == null) {
WebComponentDescriptor webComponent = (WebComponentDescriptor) webBundle.
getWebComponentByCanonicalName(endpoint.getWebComponentLink());
// if servlet is not known, we should add it now
if (webComponent == null) {
webComponent = new WebComponentDescriptor();
webComponent.setServlet(true);
webComponent.setWebComponentImplementation(((Class) annElem).getCanonicalName());
webComponent.setName(endpoint.getEndpointName());
webComponent.addUrlPattern("/"+newWS.getName());
webBundle.addWebComponentDescriptor(webComponent);
}
endpoint.setWebComponentImpl(webComponent);
}
} else {
if(endpoint.getEjbLink() == null) {
EjbDescriptor[] ejbDescs = ((EjbBundleDescriptor) bundleDesc).getEjbByClassName(((Class)annElem).getName());
if(ejbDescs.length != 1) {
throw new AnnotationProcessorException(
"Unable to find matching descriptor for EJB endpoint",
annInfo);
}
endpoint.setEjbComponentImpl(ejbDescs[0]);
ejbDescs[0].setWebServiceEndpointInterfaceName(endpoint.getServiceEndpointInterface());
endpoint.setEjbLink(ejbDescs[0].getName());
}
}
if(endpoint.getWsdlPort() == null) {
endpoint.setWsdlPort(new QName(targetNameSpace, portName, "ns1"));
}
if(endpoint.getWsdlService() == null) {
endpoint.setWsdlService(new QName(targetNameSpace, svcName, "ns1"));
}
return HandlerProcessingResultImpl.getDefaultResult(getAnnotationType(), ResultType.PROCESSED);
}