archivereader.java
来自「开源的axis2框架的源码。用于开发WEBSERVER」· Java 代码 · 共 531 行 · 第 1/2 页
JAVA
531 行
}
processFilesInFolder(metaInfFolder, servicesMap);
} catch (FileNotFoundException e) {
throw new DeploymentException(e);
} catch (IOException e) {
throw new DeploymentException(e);
} catch (XMLStreamException e) {
throw new DeploymentException(e);
}
} else {
ZipInputStream zin;
FileInputStream fin;
try {
fin = new FileInputStream(serviceFile);
zin = new ZipInputStream(fin);
//TODO Check whether this WSDL is empty
ZipEntry entry;
byte[] buf = new byte[1024];
int read;
ByteArrayOutputStream out;
while ((entry = zin.getNextEntry()) != null) {
String entryName = entry.getName().toLowerCase();
if (entryName.startsWith(META_INF.toLowerCase())
&& entryName.endsWith(SUFFIX_WSDL)) {
out = new ByteArrayOutputStream();
// we do not want to generate the services for the
// imported wsdl of one file.
if ((entryName.indexOf("/") != entryName.lastIndexOf("/"))
|| (entryName.indexOf("wsdl_") != -1)) {
//only care abt the toplevel wsdl
continue;
}
while ((read = zin.read(buf)) > 0) {
out.write(buf, 0, read);
}
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
// now the question is which version of WSDL file this archive contains.
// lets check the namespace of the root element and decide. But since we are
// using axiom (dude, you are becoming handy here :)), we will not build the
// whole thing.
OMNamespace documentElementNS =
((OMElement) XMLUtils.toOM(in)).getNamespace();
if (documentElementNS != null) {
WSDLToAxisServiceBuilder wsdlToAxisServiceBuilder;
if (WSDL2Constants.WSDL_NAMESPACE
.equals(documentElementNS.getNamespaceURI())) {
// we have a WSDL 2.0 document here.
wsdlToAxisServiceBuilder = new WSDL20ToAllAxisServicesBuilder(
new ByteArrayInputStream(out.toByteArray()));
wsdlToAxisServiceBuilder.setBaseUri(entryName);
} else if (Constants.NS_URI_WSDL11.
equals(documentElementNS.getNamespaceURI())) {
wsdlToAxisServiceBuilder = new WSDL11ToAllAxisServicesBuilder(
new ByteArrayInputStream(out.toByteArray()));
} else {
throw new DeploymentException(Messages.getMessage("invalidWSDLFound"));
}
List services = processWSDLFile(wsdlToAxisServiceBuilder,
serviceFile, true,
new ByteArrayInputStream(
out.toByteArray()),
entry.getName());
if (services != null) {
for (int i = 0; i < services.size(); i++) {
AxisService axisService = (AxisService) services.get(i);
if (axisService != null) {
servicesMap.put(axisService.getName(), axisService);
}
}
}
}
}
}
try {
zin.close();
} catch (IOException e) {
log.info(e);
}
try {
fin.close();
} catch (IOException e) {
log.info(e);
}
} catch (FileNotFoundException e) {
throw new DeploymentException(e);
} catch (IOException e) {
throw new DeploymentException(e);
} catch (XMLStreamException e) {
throw new DeploymentException(e);
}
}
return servicesMap;
}
public List getAxisServiceFromWsdl(InputStream in,
ClassLoader loader, String wsdlUrl) throws Exception {
// ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
// now the question is which version of WSDL file this archive contains.
// lets check the namespace of the root element and decide. But since we are
// using axiom (dude, you are becoming handy here :)), we will not build the
// whole thing.
OMElement element = (OMElement) XMLUtils.toOM(in);
OMNamespace documentElementNS = element.getNamespace();
if (documentElementNS != null) {
WSDL11ToAllAxisServicesBuilder wsdlToAxisServiceBuilder;
ByteArrayOutputStream out = new ByteArrayOutputStream();
element.serialize(out);
if (Constants.NS_URI_WSDL11.
equals(documentElementNS.getNamespaceURI())) {
wsdlToAxisServiceBuilder = new WSDL11ToAllAxisServicesBuilder(
new ByteArrayInputStream(out.toByteArray()));
wsdlToAxisServiceBuilder.setCustomWSLD4JResolver(new WarBasedWSDLLocator(wsdlUrl,
loader,
new ByteArrayInputStream(
out.toByteArray())));
wsdlToAxisServiceBuilder.setCustomResolver(
new WarFileBasedURIResolver(loader));
return wsdlToAxisServiceBuilder.populateAllServices();
} else {
throw new DeploymentException(Messages.getMessage("invalidWSDLFound"));
}
}
return null;
}
public void processFilesInFolder(File folder, HashMap servicesMap)
throws FileNotFoundException, XMLStreamException, DeploymentException {
File files[] = folder.listFiles();
for (int i = 0; i < files.length; i++) {
File file1 = files[i];
if (file1.getName().toLowerCase().endsWith(SUFFIX_WSDL)) {
InputStream in = new FileInputStream(file1);
FileInputStream in2;
// now the question is which version of WSDL file this archive contains.
// lets check the namespace of the root element and decide. But since we are
// using axiom (dude, you are becoming handy here :)), we will not build the
// whole thing.
OMNamespace documentElementNS = ((OMElement) XMLUtils.toOM(in)).getNamespace();
if (documentElementNS != null) {
WSDLToAxisServiceBuilder wsdlToAxisServiceBuilder;
if (WSDL2Constants.WSDL_NAMESPACE
.equals(documentElementNS.getNamespaceURI())) {
// we have a WSDL 2.0 document here.
in2 = new FileInputStream(file1);
wsdlToAxisServiceBuilder = new WSDL20ToAllAxisServicesBuilder(in2);
} else if (Constants.NS_URI_WSDL11.
equals(documentElementNS.getNamespaceURI())) {
in2 = new FileInputStream(file1);
wsdlToAxisServiceBuilder = new WSDL11ToAllAxisServicesBuilder(in2);
} else {
throw new DeploymentException(Messages.getMessage("invalidWSDLFound"));
}
FileInputStream in3 = new FileInputStream(file1);
List services = processWSDLFile(wsdlToAxisServiceBuilder, file1, false,
in2, file1.toURI().toString());
if (services != null) {
for (int j = 0; j < services.size(); j++) {
AxisService axisService = (AxisService) services.get(j);
if (axisService != null) {
servicesMap.put(axisService.getName(), axisService);
}
}
}
try {
in2.close();
in3.close();
} catch (IOException e) {
log.info(e);
}
}
try {
in.close();
} catch (IOException e) {
log.info(e);
}
}
}
}
public void readModuleArchive(DeploymentFileData deploymentFile,
AxisModule module, boolean explodedDir,
AxisConfiguration axisConfig)
throws DeploymentException {
// get attribute values
boolean moduleXMLFound = false;
String shortFileName = DescriptionBuilder.getShortFileName(deploymentFile.getName());
if (!explodedDir) {
ZipInputStream zin;
FileInputStream fin;
try {
fin = new FileInputStream(deploymentFile.getAbsolutePath());
zin = new ZipInputStream(fin);
ZipEntry entry;
while ((entry = zin.getNextEntry()) != null) {
if (entry.getName().equalsIgnoreCase(MODULE_XML)) {
moduleXMLFound = true;
ModuleBuilder builder = new ModuleBuilder(zin, module, axisConfig);
// setting module name
module.setName(Utils.getModuleName(shortFileName));
module.setVersion(Utils.getModuleVersion(shortFileName));
builder.populateModule();
break;
}
}
zin.close();
fin.close();
if (!moduleXMLFound) {
throw new DeploymentException(
Messages.getMessage(
DeploymentErrorMsgs.MODULE_XML_MISSING,
deploymentFile.getAbsolutePath()));
}
} catch (Exception e) {
throw new DeploymentException(e);
}
} else {
File file = new File(deploymentFile.getAbsolutePath(), MODULE_XML);
if (file.exists() ||
(file = new File(deploymentFile.getAbsolutePath(), MODULE_XML.toLowerCase()))
.exists()) {
InputStream in = null;
try {
in = new FileInputStream(file);
ModuleBuilder builder = new ModuleBuilder(in, module, axisConfig);
// setting module name
module.setName(Utils.getModuleName(shortFileName));
module.setVersion(Utils.getModuleVersion(shortFileName));
builder.populateModule();
} catch (FileNotFoundException e) {
throw new DeploymentException(
Messages.getMessage(DeploymentErrorMsgs.FILE_NOT_FOUND,
e.getMessage()));
} finally {
if (in != null) {
try {
in.close();
} catch (IOException e) {
log.info(Messages.getMessage("errorininputstreamclose"));
}
}
}
} else {
throw new DeploymentException(
Messages.getMessage(
DeploymentErrorMsgs.MODULE_XML_MISSING,
deploymentFile.getAbsolutePath()));
}
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?