pojodeployer.java
来自「开源的axis2框架的源码。用于开发WEBSERVER」· Java 代码 · 共 350 行 · 第 1/2 页
JAVA
350 行
jclass.getAnnotation(AnnotationConstants.WEB_SERVICE);
if (annotation != null) {
AxisService axisService;
axisService = createAxisService(classLoader,
className,deploymentFileData.getFile().toURL());
axisServiceList.add(axisService);
}
}
}
}
if (axisServiceList.size() >0 ) {
AxisServiceGroup serviceGroup = new AxisServiceGroup();
serviceGroup.setServiceGroupName(deploymentFileData.getName());
for (int i = 0; i < axisServiceList.size(); i++) {
AxisService axisService = (AxisService) axisServiceList.get(i);
serviceGroup.addService(axisService);
}
configCtx.getAxisConfiguration().addServiceGroup(serviceGroup);
} else {
log.info("No annotated class found in the jar: " + deploymentFileData.getFile().getName());
}
}
} catch (Exception e) {
StringWriter errorWriter = new StringWriter();
PrintWriter error_ptintWriter = new PrintWriter(errorWriter);
e.printStackTrace(error_ptintWriter);
String serviceStatus = "Error:\n" + errorWriter.toString();
configCtx.getAxisConfiguration().getFaultyServices().put(
deploymentFileData.getFile().getAbsolutePath(),
serviceStatus);
}catch (Throwable t) {
StringWriter errorWriter = new StringWriter();
PrintWriter error_ptintWriter = new PrintWriter(errorWriter);
t.printStackTrace(error_ptintWriter);
String serviceStatus = "Error:\n" + errorWriter.toString();
configCtx.getAxisConfiguration().getFaultyServices().put(
deploymentFileData.getFile().getAbsolutePath(),
serviceStatus);
} finally {
if (threadClassLoader != null) {
Thread.currentThread().setContextClassLoader(threadClassLoader);
}
}
}
private AxisService createAxisService(ClassLoader classLoader,
String className,
URL serviceLocation) throws ClassNotFoundException,
InstantiationException,
IllegalAccessException,
AxisFault {
AxisService axisService;
try {
Class claxx = Class.forName(
"org.apache.axis2.jaxws.description.DescriptionFactory");
Method mthod = claxx.getMethod(
"createAxisService",
new Class[]{Class.class});
Class pojoClass = Loader.loadClass(classLoader, className);
axisService =
(AxisService) mthod.invoke(claxx, new Object[]{pojoClass});
Utils.fillAxisService(axisService,
configCtx.getAxisConfiguration(),
new ArrayList(),
new ArrayList());
setMessageReceivers(axisService);
} catch (Exception e) {
// Seems like the jax-ws jars missin in the class path .
// lets tryu annogen
axisService = createAxisServiceUsingAnnogen(className, classLoader, serviceLocation);
}
return axisService;
}
private AxisService createAxisServiceUsingAnnogen(String className,
ClassLoader classLoader,
URL serviceLocation)
throws ClassNotFoundException,
InstantiationException,
IllegalAccessException,
AxisFault {
HashMap messageReciverMap = new HashMap();
Class inOnlyMessageReceiver = Loader.loadClass(
"org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver");
MessageReceiver messageReceiver =
(MessageReceiver) inOnlyMessageReceiver.newInstance();
messageReciverMap.put( WSDL2Constants.MEP_URI_IN_ONLY,
messageReceiver);
Class inoutMessageReceiver = Loader.loadClass(
"org.apache.axis2.rpc.receivers.RPCMessageReceiver");
MessageReceiver inOutmessageReceiver =
(MessageReceiver) inoutMessageReceiver.newInstance();
messageReciverMap.put(WSDL2Constants.MEP_URI_IN_OUT,
inOutmessageReceiver);
messageReciverMap.put(WSDL2Constants.MEP_URI_ROBUST_IN_ONLY,
inOutmessageReceiver);
AxisService axisService =
AxisService.createService(className,
configCtx.getAxisConfiguration(),
messageReciverMap,
null, null,
classLoader);
axisService.setFileName(serviceLocation);
return axisService;
}
public void setMessageReceivers(AxisService service) {
Iterator iterator = service.getOperations();
while (iterator.hasNext()) {
AxisOperation operation = (AxisOperation) iterator.next();
String MEP = operation.getMessageExchangePattern();
if (MEP != null) {
try {
if (WSDLConstants.WSDL20_2006Constants.MEP_URI_IN_ONLY.equals(MEP)
|| WSDLConstants.WSDL20_2004_Constants.MEP_URI_IN_ONLY.equals(MEP)
|| WSDL2Constants.MEP_URI_IN_ONLY.equals(MEP)) {
Class inOnlyMessageReceiver = Loader.loadClass(
"org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver");
MessageReceiver messageReceiver =
(MessageReceiver) inOnlyMessageReceiver.newInstance();
operation.setMessageReceiver(messageReceiver);
} else {
Class inoutMessageReceiver = Loader.loadClass(
"org.apache.axis2.rpc.receivers.RPCMessageReceiver");
MessageReceiver inOutmessageReceiver =
(MessageReceiver) inoutMessageReceiver.newInstance();
operation.setMessageReceiver(inOutmessageReceiver);
}
} catch (ClassNotFoundException e) {
log.error(e.getMessage(), e);
} catch (InstantiationException e) {
log.error(e.getMessage(), e);
} catch (IllegalAccessException e) {
log.error(e.getMessage(), e);
}
}
}
}
public void setDirectory(String directory) {
}
public void setExtension(String extension) {
}
public void unDeploy(String fileName) {
if(fileName.endsWith(".class")){
String className = fileName.replaceAll(".class", "");
try {
AxisServiceGroup serviceGroup =
configCtx.getAxisConfiguration().removeServiceGroup(className);
configCtx.removeServiceGroupContext(serviceGroup);
log.info(Messages.getMessage(DeploymentErrorMsgs.SERVICE_REMOVED,
fileName));
} catch (AxisFault axisFault) {
//May be a faulty service
configCtx.getAxisConfiguration().removeFaultyService(fileName);
}
} else if (fileName.endsWith(".jar")){
try {
AxisServiceGroup serviceGroup =
configCtx.getAxisConfiguration().removeServiceGroup(fileName);
configCtx.removeServiceGroupContext(serviceGroup);
log.info(Messages.getMessage(DeploymentErrorMsgs.SERVICE_REMOVED,
fileName));
} catch (AxisFault axisFault) {
//May be a faulty service
configCtx.getAxisConfiguration().removeFaultyService(fileName);
}
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?