下面的类将读取参数的输入并读取相应的excel表,最后它将从excel返回数据集。
@WebService
public class ReadExcelData {
@SuppressWarnings( { })
public String nameDisplay(String date, String shiftNo, String userName,
String pwd) throws IOException, PropertyException, JAXBException {
String xmlValues = null;
System.out.println("Inside the webservice call");
String filename = "D:\\final.xls";
String dateToCheck = date;
String shiftNumber = shiftNo;
System.out.println("Date-->" + dateToCheck + "Shift number-->"
+ shiftNumber);
String userNameLogin = userName;
String password = pwd;
if ((userNameLogin.equalsIgnoreCase("DEVA"))
&& (password.equalsIgnoreCase("DEVA"))) {
FileInputStream file = new FileInputStream(new File(filename));
HSSFWorkbook workbook = new HSSFWorkbook(file);
HSSFSheet sheet = workbook.getSheetAt(0);
Iterator<Row> rowItr = sheet.iterator();
while (rowItr.hasNext()) {
HSSFRow row = (HSSFRow) rowItr.next();
String dateToCheckExcel = row.getCell(0).getStringCellValue();
String shiftNumberExcel = row.getCell(1).getStringCellValue();
if (dateToCheckExcel.equalsIgnoreCase(dateToCheck)) {
if (shiftNumberExcel.equalsIgnoreCase(shiftNumber)) {
StAnomaliaUTE StAnomaliaUTE = new StAnomaliaUTE();
StAnomaliaUTE.setCodStabilimento(row.getCell(2).getStringCellValue());
StAnomaliaUTE.setCodModello(row.getCell(3).getStringCellValue());
StAnomaliaUTE.setCodVersione(row.getCell(4).getStringCellValue());
StAnomaliaUTE.setCodSerie(row.getCell(5).getStringCellValue());
StAnomaliaUTE.setCodAreaUnita(row.getCell(6).getStringCellValue());
StAnomaliaUTE.setNumUte(row.getCell(7).getStringCellValue());
StAnomaliaUTE.setNumLinea(row.getCell(8).getStringCellValue());
StAnomaliaUTE.setNumDominio(row.getCell(9).getStringCellValue());
StAnomaliaUTE.setCodComponente(row.getCell(10).getStringCellValue());
StAnomaliaUTE.setCodColore(row.getCell(11).getStringCellValue());
StAnomaliaUTE.setCodAnomalia(row.getCell(12).getStringCellValue());
StAnomaliaUTE.setCodPosizione(row.getCell(13).getStringCellValue());
StAnomaliaUTE.setCodTipologia(row.getCell(14).getStringCellValue());
StAnomaliaUTE.setDataRilevamento(row.getCell(15).getStringCellValue());
StAnomaliaUTE.setDataRisoluzione(row.getCell(16).getStringCellValue());
StAnomaliaUTE.setNumeroCasi(Integer.parseInt(row.getCell(17).getStringCellValue()));
StAnomaliaUTE.setTotaleVetture(Integer.parseInt(row.getCell(18).getStringCellValue()));
DataSet dataSet = new DataSet();
dataSet.setDataset(new ArrayList<StAnomaliaUTE>());
dataSet.getDataset().add(StAnomaliaUTE);
xmlValues = DataSetXmlGenerator.getSerializedDataSet(dataSet);
}
}
}
}
return xmlValues;
}
}
这是发布网络服务的主要方法
package com.chrysler.main;
import java.io.IOException;
import javax.xml.bind.JAXBException;
import javax.xml.bind.PropertyException;
import javax.xml.ws.Endpoint;
import com.chrysler.helper.ReadExcelData;
public class GenerateDataSet {
/**
* @param args
*/
private static final String WEBSERVICE_PUBLISHED = "Webservice Published";
public static void main(String[] args) throws PropertyException, IOException, JAXBException {
System.out.println("Hello");
Endpoint.publish("http://localhost:9111/PFSWebServices/ReadExcel",
new ReadExcelData());
//String finalXml=readExcel.nameDisplay("19900627","2","deva","deva");
//System.out.println("Final Xml is -->>>" +finalXml);
System.out.println(WEBSERVICE_PUBLISHED);
}
}
Published URL : http://localhost:9111/PFSWebServices/ReadExcel?wsdl
当我点击浏览器中的URL时,我得到了以下XML架构
<?xml version="1.0" encoding="UTF-8" ?>
- <!--
Published by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.1.6 in JDK 6.
-->
- <!--
Generated by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.1.6 in JDK 6.
-->
- <definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://helper.chrysler.com/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://helper.chrysler.com/" name="ReadExcelDataService">
- <types>
- <xsd:schema>
<xsd:import namespace="http://helper.chrysler.com/" schemaLocation="http://localhost:9111/PFSWebServices/ReadExcel?xsd=1" />
</xsd:schema>
</types>
- <message name="nameDisplay">
<part name="parameters" element="tns:nameDisplay" />
</message>
- <message name="nameDisplayResponse">
<part name="parameters" element="tns:nameDisplayResponse" />
</message>
- <message name="IOException">
<part name="fault" element="tns:IOException" />
</message>
- <message name="PropertyException">
<part name="fault" element="tns:PropertyException" />
</message>
- <message name="JAXBException">
<part name="fault" element="tns:JAXBException" />
</message>
- <portType name="ReadExcelData">
- <operation name="nameDisplay">
<input message="tns:nameDisplay" />
<output message="tns:nameDisplayResponse" />
<fault message="tns:IOException" name="IOException" />
<fault message="tns:PropertyException" name="PropertyException" />
<fault message="tns:JAXBException" name="JAXBException" />
</operation>
</portType>
- <binding name="ReadExcelDataPortBinding" type="tns:ReadExcelData">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document" />
- <operation name="nameDisplay">
<soap:operation soapAction="" />
- <input>
<soap:body use="literal" />
</input>
- <output>
<soap:body use="literal" />
</output>
- <fault name="IOException">
<soap:fault name="IOException" use="literal" />
</fault>
- <fault name="PropertyException">
<soap:fault name="PropertyException" use="literal" />
</fault>
- <fault name="JAXBException">
<soap:fault name="JAXBException" use="literal" />
</fault>
</operation>
</binding>
- <service name="ReadExcelDataService">
- <port name="ReadExcelDataPort" binding="tns:ReadExcelDataPortBinding">
<soap:address location="http://localhost:9111/PFSWebServices/ReadExcel" />
</port>
</service>
</definitions>
现在我在浏览器中传递了URL以获取Excel数据
http://localhost:9111/PFSWebServices/ReadExcel/nameDisplay?date="19900627"&shiftNo="2"&userName="deva"&pwd="deva"
但我的 400服务器错误
让我知道我是否错误地传递参数???
请帮我解决此错误。
答案 0 :(得分:0)
这是一个SOAP服务。您必须创建客户端或发送如下所示的SOAP消息。 SOAP Body将包含实际文档w.r.t到XML Schema
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:bal="http://www.i2c.com/mcpws/BalanceInquiry/">
<soapenv:Header/>
<soapenv:Body>
<nameDisplay>
..........
</nameDisplay>
</soapenv:Body>
</soapenv:Envelope>
对于测试,您可以使用SOAP UI工具http://www.soapui.org/。下载后创建一个新的SOAP UI项目并提供上面的WSDL文件路径。它会为您生成样本请求,您也可以执行这些请求