servicedescriptionimpl.java
来自「开源的axis2框架的源码。用于开发WEBSERVER」· Java 代码 · 共 1,278 行 · 第 1/5 页
JAVA
1,278 行
// Use the SEI Class and its annotations to finish creating the Description hierachy. Note that EndpointInterface, Operations, Parameters, etc.
// are not created for dynamic ports. It would be an error to later do a getPort against a dynamic port (per the JAX-WS spec)
endpointDescription = new EndpointDescriptionImpl(sei, portQName, true, this);
addEndpointDescription(endpointDescription);
} else {
// All error check above passed, the EndpointDescription already exists and needs no updating
}
break;
case GET_PORT:
// try to find existing endpointDesc by SEI class if portQName was not specified
if (endpointDescription == null && portQName == null && sei != null) {
endpointDescription = getEndpointDescriptionImpl(sei);
}
// If an endpointDesc doesn't exist, and the port exists in the WSDL, create it
// If an endpointDesc already exists and has an associated SEI already, make sure they match
// If an endpointDesc already exists and was created for Dispatch (no SEI), update that with the SEI provided on the getPort
// Port must be declared (e.g. in WSDL or via annotations)
// TODO: Once isPortDeclared understands annotations and not just WSDL, the 2nd part of this check can possibly be removed.
// Although consider the check below that updates an existing EndpointDescritpion with an SEI.
if (!isPortDeclared ||
(endpointDescription != null && endpointDescription.isDynamicPort())) {
// This guards against the case where an addPort was done previously and now a getPort is done on it.
// TODO: RAS & NLS
throw ExceptionFactory.makeWebServiceException(
"ServiceDescription.updateEndpointDescription: Can not do a getPort on a port added via addPort(). PortQN: " +
(portQName != null ? portQName.toString() : "not specified"));
} else if (sei == null) {
// TODO: RAS & NLS
throw ExceptionFactory.makeWebServiceException(
"ServiceDescription.updateEndpointDescription: Can not do a getPort with a null SEI. PortQN: " +
(portQName != null ? portQName.toString() : "not specified"));
} else if (endpointDescription == null) {
// Use the SEI Class and its annotations to finish creating the Description hierachy: Endpoint, EndpointInterface, Operations, Parameters, etc.
// TODO: Need to create the Axis Description objects after we have all the config info (i.e. from this SEI)
endpointDescription = new EndpointDescriptionImpl(sei, portQName, this);
addEndpointDescription(endpointDescription);
/*
* We must reset the service runtime description after adding a new endpoint
* since the runtime description information could have references to old
* information. See MarshalServiceRuntimeDescriptionFactory and
* MarshalServiceRuntimeDescription.
*/
resetServiceRuntimeDescription();
} else
if (getEndpointSEI(portQName) == null && !endpointDescription.isDynamicPort()) {
// Existing endpointDesc from a declared port needs to be updated with an SEI
// Note that an EndpointDescritption created from an addPort (i.e. a dynamic port) can not do this.
endpointDescription.updateWithSEI(sei);
} else if (getEndpointSEI(portQName) != sei) {
// TODO: RAS & NLS
throw ExceptionFactory.makeWebServiceException(
"ServiceDescription.updateEndpointDescription: Can't do a getPort() specifiying a different SEI than the previous getPort(). PortQN: "
+ portQName + "; current SEI: " + sei + "; previous SEI: " +
getEndpointSEI(portQName));
} else {
// All error check above passed, the EndpointDescription already exists and needs no updating
}
break;
case CREATE_DISPATCH:
// Port may or may not exist in WSDL.
// If an endpointDesc doesn't exist and it is in the WSDL, it can be created
// Otherwise, it is an error.
if (DescriptionUtils.isEmpty(portQName)) {
throw ExceptionFactory
.makeWebServiceException(Messages.getMessage("createDispatchFail0"));
} else if (endpointDescription != null) {
// The EndpoingDescription already exists; nothing needs to be done
} else if (sei != null) {
// The Dispatch should not have an SEI associated with it on the update call.
// REVIEW: Is this a valid check?
throw ExceptionFactory.makeWebServiceException(
"ServiceDescription.updateEndpointDescription: Can not specify an SEI when creating a Dispatch. PortQN: " +
portQName);
} else if (getWSDLWrapper() != null && isPortDeclared) {
// EndpointDescription doesn't exist and this is a declared Port, so create one
// Use the SEI Class and its annotations to finish creating the Description hierachy. Note that EndpointInterface, Operations, Parameters, etc.
// are not created for Dipsatch-based ports, but might be updated later if a getPort is done against the same declared port.
// TODO: Need to create the Axis Description objects after we have all the config info (i.e. from this SEI)
endpointDescription = new EndpointDescriptionImpl(sei, portQName, this);
addEndpointDescription(endpointDescription);
} else {
// The port is not a declared port and it does not have an EndpointDescription, meaning an addPort has not been done for it
// This is an error.
throw ExceptionFactory.makeWebServiceException(
Messages.getMessage("createDispatchFail1", portQName.toString()));
}
break;
}
return endpointDescription;
}
private Class getEndpointSEI(QName portQName) {
Class endpointSEI = null;
EndpointDescription endpointDesc = getEndpointDescription(portQName);
if (endpointDesc != null) {
EndpointInterfaceDescription endpointInterfaceDesc =
endpointDesc.getEndpointInterfaceDescription();
if (endpointInterfaceDesc != null ) {
endpointSEI = endpointInterfaceDesc.getSEIClass();
}
}
return endpointSEI;
}
private boolean isPortDeclared(QName portQName) {
// TODO: This needs to account for declaration of the port via annotations in addition to just WSDL
// TODO: Add logic to check the portQN namespace against the WSDL Definition NS
boolean portIsDeclared = false;
if (!DescriptionUtils.isEmpty(portQName)) {
if (getWSDLWrapper() != null) {
Definition wsdlDefn = getWSDLWrapper().getDefinition();
Service wsdlService = wsdlDefn.getService(serviceQName);
Port wsdlPort = wsdlService.getPort(portQName.getLocalPart());
portIsDeclared = (wsdlPort != null);
} else {
// TODO: Add logic to determine if port is declared via annotations when no WSDL is present. For now, we have to assume it is declared
// so getPort(...) and createDispatch(...) calls work when there is no WSDL.
portIsDeclared = true;
}
} else {
// PortQName is null, so the runtime gets to choose which one to use. Since there's no WSDL
// we'll use annotations, so it is implicitly declared
portIsDeclared = true;
}
return portIsDeclared;
}
/* (non-Javadoc)
* @see org.apache.axis2.jaxws.description.ServiceDescription#getEndpointDescriptions()
*/
public EndpointDescription[] getEndpointDescriptions() {
return endpointDescriptions.values().toArray(new EndpointDescriptionImpl[0]);
}
public Collection<EndpointDescription> getEndpointDescriptions_AsCollection() {
return endpointDescriptions.values();
}
/* (non-Javadoc)
* @see org.apache.axis2.jaxws.description.ServiceDescription#getEndpointDescription(javax.xml.namespace.QName)
*/
public EndpointDescription getEndpointDescription(QName portQName) {
EndpointDescription returnDesc = null;
if (!DescriptionUtils.isEmpty(portQName)) {
returnDesc = endpointDescriptions.get(portQName);
}
return returnDesc;
}
EndpointDescriptionImpl getEndpointDescriptionImpl(QName portQName) {
return (EndpointDescriptionImpl)getEndpointDescription(portQName);
}
EndpointDescriptionImpl getEndpointDescriptionImpl(Class seiClass) {
for (EndpointDescription endpointDescription : endpointDescriptions.values()) {
EndpointInterfaceDescription endpointInterfaceDesc =
endpointDescription.getEndpointInterfaceDescription();
// Note that Dispatch endpoints will not have an endpointInterface because the do not have an associated SEI
if (endpointInterfaceDesc != null) {
Class endpointSEIClass = endpointInterfaceDesc.getSEIClass();
if (endpointSEIClass != null && endpointSEIClass.equals(seiClass)) {
return (EndpointDescriptionImpl)endpointDescription;
}
}
}
return null;
}
DescriptionBuilderComposite getDescriptionBuilderComposite() {
return composite;
}
/* (non-Javadoc)
* @see org.apache.axis2.jaxws.description.ServiceDescription#getEndpointDescription(java.lang.Class)
*/
public EndpointDescription[] getEndpointDescription(Class seiClass) {
EndpointDescription[] returnEndpointDesc = null;
ArrayList<EndpointDescriptionImpl> matchingEndpoints =
new ArrayList<EndpointDescriptionImpl>();
for (EndpointDescription endpointDescription : endpointDescriptions.values()) {
EndpointInterfaceDescription endpointInterfaceDesc =
endpointDescription.getEndpointInterfaceDescription();
// Note that Dispatch endpoints will not have an endpointInterface because the do not have an associated SEI
if (endpointInterfaceDesc != null) {
Class endpointSEIClass = endpointInterfaceDesc.getSEIClass();
if (endpointSEIClass != null && endpointSEIClass.equals(seiClass)) {
matchingEndpoints.add((EndpointDescriptionImpl)endpointDescription);
}
}
}
if (matchingEndpoints.size() > 0) {
returnEndpointDesc = matchingEndpoints.toArray(new EndpointDescriptionImpl[0]);
}
return returnEndpointDesc;
}
/*
* @return True - if we are processing with the DBC List instead of reflection
*/
boolean isDBCMap() {
if (dbcMap == null)
return false;
else
return true;
}
// END of public accessor methods
/*=======================================================================*/
/*=======================================================================*/
private void addEndpointDescription(EndpointDescriptionImpl endpoint) {
endpointDescriptions.put(endpoint.getPortQName(), endpoint);
}
private void setupWsdlDefinition() {
// Note that there may be no WSDL provided, for example when called from
// Service.create(QName serviceName).
if (isDBCMap()) {
// Currently, there is a bug which allows the wsdlDefinition to be placed
// on either the impl class composite or the sei composite, or both. We need to
// look in both places and find the correct one, if it exists.
if (((composite.getWebServiceAnnot() != null) &&
DescriptionUtils.isEmpty(composite.getWebServiceAnnot().endpointInterface()))
||
(!(composite.getWebServiceProviderAnnot() == null))) {
//This is either an implicit SEI, or a WebService Provider
if (composite.getWsdlDefinition() != null) {
this.wsdlURL = composite.getWsdlURL();
try {
this.wsdlWrapper = new WSDL4JWrapper(this.wsdlURL,
composite.getWsdlDefinition());
} catch (WSDLException e) {
throw ExceptionFactory.makeWebServiceException(
Messages.getMessage("wsdlException", e.getMessage()), e);
}
}
} else if (composite.getWebServiceAnnot() != null) {
//This impl class specifies an SEI...this is a special case. There is a bug
//in the tooling that allows for the wsdllocation to be specifed on either the
//impl. class, or the SEI, or both. So, we need to look for the wsdl as follows:
// 1. If the Wsdl exists on the SEI, then check for it on the impl.
// 2. If it is not found in either location, in that order, then generate
DescriptionBuilderComposite seic =
getDBCMap().get(composite.getWebServiceAnnot().endpointInterface());
try {
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?