endpointcontroller.java
来自「开源的axis2框架的源码。用于开发WEBSERVER」· Java 代码 · 共 443 行 · 第 1/2 页
JAVA
443 行
*/
private Class loadServiceImplClass(String className, ClassLoader cl) {
if (log.isDebugEnabled()) {
log.debug("Attempting to load service impl class: " + className);
}
try {
//TODO: What should be done if the supplied ClassLoader is null?
Class _class = forName(className, true, cl);
return _class;
//Catch Throwable as ClassLoader can throw an NoClassDefFoundError that
//does not extend Exception, so lets catch everything that extends Throwable
//rather than just Exception.
} catch (Throwable cnf) {
throw ExceptionFactory.makeWebServiceException(Messages.getMessage(
"EndpointControllerErr4", className));
}
}
/**
* Return the class for this name
*
* @return Class
*/
private static Class forName(final String className, final boolean initialize,
final ClassLoader classloader) throws ClassNotFoundException {
// NOTE: This method must remain private because it uses AccessController
Class cl = null;
try {
cl = (Class)AccessController.doPrivileged(
new PrivilegedExceptionAction() {
public Object run() throws ClassNotFoundException {
return Class.forName(className, initialize, classloader);
}
}
);
} catch (PrivilegedActionException e) {
if (log.isDebugEnabled()) {
log.debug("Exception thrown from AccessController: " + e);
}
throw (ClassNotFoundException)e.getException();
}
return cl;
}
private String getServiceImplClassName(MessageContext mc) {
// The PARAM_SERVICE_CLASS property that is set on the AxisService
// will tell us what the service implementation class is.
org.apache.axis2.context.MessageContext axisMsgContext = mc.getAxisMessageContext();
AxisService as = axisMsgContext.getAxisService();
Parameter param = as.getParameter(PARAM_SERVICE_CLASS);
// If there was no implementation class, we should not go any further
if (param == null) {
throw ExceptionFactory.makeWebServiceException(Messages.getMessage(
"EndpointControllerErr2"));
}
String className = ((String)param.getValue()).trim();
return className;
}
/*
* Gets the ServiceDescription associated with the request that is currently
* being processed.
*/
private EndpointDescription getEndpointDescription(MessageContext mc, Class implClass) {
AxisService axisSvc = mc.getAxisMessageContext().getAxisService();
//Check to see if we've already created a ServiceDescription for this
//service before trying to create a new one.
if (axisSvc.getParameter(EndpointDescription.AXIS_SERVICE_PARAMETER) != null) {
Parameter param = axisSvc.getParameter(EndpointDescription.AXIS_SERVICE_PARAMETER);
EndpointDescription ed = (EndpointDescription)param.getValue();
return ed;
} else {
// TODO: This is using a deprecated factory method to create the ServiceDescription.
// The correct way to fix this is to create the ServiceDescriptions (and the AxisService
// and associated descritpion hierahcy) at startup. However, that is currently not done
// in the Axis2 testing environment. So, for testing, we create a Description hierachy
// on the fly and attach the AxisService to it. This should be changed to not used the
// deprecated factory method. HOWEVER doing so currently causes testcase failures in
// JAXWS and or Metadata
// ServiceDescription sd = DescriptionFactory.createServiceDescription(implClass);
ServiceDescription sd =
DescriptionFactory.createServiceDescriptionFromServiceImpl(implClass, axisSvc);
EndpointDescription ed = sd.getEndpointDescriptions_AsCollection().iterator().next();
return ed;
}
}
private EndpointLifecycleManager createEndpointlifecycleManager() {
EndpointLifecycleManagerFactory elmf = (EndpointLifecycleManagerFactory)FactoryRegistry
.getFactory(EndpointLifecycleManagerFactory.class);
return elmf.createEndpointLifecycleManager();
}
private boolean bindingTypesMatch(MessageContext requestMsgCtx,
ServiceDescription serviceDesc) {
// compare soap versions and respond appropriately under SOAP 1.2 Appendix 'A'
Collection<EndpointDescription> eds = serviceDesc.getEndpointDescriptions_AsCollection();
// dispatch endpoints do not have SEIs, so watch out for null or empty array
if ((eds != null) && (eds.size() > 0)) {
EndpointDescription ed = eds.iterator().next();
Protocol protocol = requestMsgCtx.getMessage().getProtocol();
String endpointBindingType = ed.getBindingType();
if (protocol.equals(Protocol.soap11)) {
return (SOAPBinding.SOAP11HTTP_BINDING.equalsIgnoreCase(endpointBindingType)) ||
(SOAPBinding.SOAP11HTTP_MTOM_BINDING.equalsIgnoreCase(endpointBindingType));
} else if (protocol.equals(Protocol.soap12)) {
return (SOAPBinding.SOAP12HTTP_BINDING.equalsIgnoreCase(endpointBindingType)) ||
(SOAPBinding.SOAP12HTTP_MTOM_BINDING.equalsIgnoreCase(endpointBindingType));
} else if (protocol.equals(Protocol.rest)) {
return HTTPBinding.HTTP_BINDING.equalsIgnoreCase(endpointBindingType);
}
}
// safe to assume?
return true;
}
private MessageContext createMismatchFaultMsgCtx(MessageContext requestMsgCtx,
String errorMsg) {
try {
XMLFault xmlfault =
new XMLFault(XMLFaultCode.VERSIONMISMATCH, new XMLFaultReason(errorMsg));
Message msg = ((MessageFactory)FactoryRegistry.getFactory(MessageFactory.class))
.create(Protocol.soap11); // always soap11 according to the spec
msg.setXMLFault(xmlfault);
MessageContext responseMsgCtx =
MessageContextUtils.createFaultMessageContext(requestMsgCtx);
responseMsgCtx.setMessage(msg);
return responseMsgCtx;
} catch (XMLStreamException e) {
// Need to fix this ! At least provide logging
// TODO for now, throw it. We probably should try to make an XMLFault object and set it on the message
throw ExceptionFactory.makeWebServiceException(e);
}
}
/**
* Save the request message if indicated by the SAVE_REQUEST_MSG property
*
* @param requestMsgContext
*/
private void saveRequestMessage(MessageContext requestMsgContext) {
// TODO: TESTING...FORCE SAVING THE REQUEST MESSAGE
// requestMsgContext.getAxisMessageContext().setProperty(Constants.SAVE_REQUEST_MSG, Boolean.TRUE);
// END TESTING
Boolean value = (Boolean)
requestMsgContext.getAxisMessageContext().getProperty(Constants.SAVE_REQUEST_MSG);
if (value != null && value == Boolean.TRUE) {
// REVIEW: This does not properly account for attachments.
Message m = requestMsgContext.getMessage();
String savedMsg = m.getAsOMElement().toString();
requestMsgContext.getAxisMessageContext()
.setProperty(Constants.SAVED_REQUEST_MSG_TEXT, savedMsg);
}
}
/**
* Restore the request message from the saved message text
*
* @param requestMsgContext
*/
private void restoreRequestMessage(MessageContext requestMsgContext) {
Boolean value = (Boolean)
requestMsgContext.getAxisMessageContext().getProperty(Constants.SAVE_REQUEST_MSG);
if (value != null && value == Boolean.TRUE) {
// REVIEW: This does not properly account for attachments.
String savedMsg = (String)requestMsgContext.getAxisMessageContext()
.getProperty(Constants.SAVED_REQUEST_MSG_TEXT);
if (savedMsg != null && savedMsg.length() > 0) {
try {
StringReader sr = new StringReader(savedMsg);
XMLStreamReader xmlreader = StAXUtils.createXMLStreamReader(sr);
MessageFactory mf = (MessageFactory)
FactoryRegistry.getFactory(MessageFactory.class);
Protocol protocol = requestMsgContext.getAxisMessageContext().isDoingREST() ?
Protocol.rest : null;
Message msg = mf.createFrom(xmlreader, protocol);
requestMsgContext.setMessage(msg);
} catch (Throwable e) {
ExceptionFactory.makeWebServiceException(e);
}
}
}
// TESTING....SIMULATE A PERSIST OF THE REQUEST MESSAGE
// String text = requestMsgContext.getMessage().getAsOMElement().toString();
// System.out.println("Persist Message" + text);
// END TESTING
}
/*
* Determine if this is a one-way invocation or not.
*/
public static boolean isOneWay(org.apache.axis2.context.MessageContext mc) {
if (mc != null) {
AxisOperation op = mc.getAxisOperation();
String mep = op.getMessageExchangePattern();
if (mep.equals(WSDL20_2004_Constants.MEP_URI_ROBUST_IN_ONLY) ||
mep.equals(WSDL20_2004_Constants.MEP_URI_IN_ONLY) ||
mep.equals(WSDL20_2006Constants.MEP_URI_ROBUST_IN_ONLY) ||
mep.equals(WSDL20_2006Constants.MEP_URI_IN_ONLY)||
mep.equals(WSDL2Constants.MEP_URI_ROBUST_IN_ONLY)||
mep.equals(WSDL2Constants.MEP_URI_IN_ONLY)) {
return true;
}
}
return false;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?