我是按照“Java Web 服务:启动和运行”一书开始学习 Java Web 服务的。在本书的某些部分,作者谈到了一些xsd
部分。问题是,当我尝试代码并生成 . 时WSDL
,我没有得到这些部分。
下面是一个 WS 实现的例子:
import java.awt.Image;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.imageio.ImageIO;
import javax.imageio.ImageReader;
import javax.imageio.stream.ImageInputStream;
import javax.jws.WebMethod;
import javax.jws.WebService;
@WebService(serviceName = "SkiImageService")
// @HandlerChain(file = "../handlers/handler-chain.xml")
public class SkiImageService {
private static final String[] names = {"nordic.jpg", "tele.jpg", "alpine.jpg"};
private String default_key;
private Map<String, String> photos;
public SkiImageService() {
photos = new HashMap<String, String>();
photos.put("nordic", "nordic.jpg");
photos.put("alpine", "alpine.jpg");
photos.put("telemk", "telemk.jpg");
default_key = "nordic";
}
// Create a named image from the raw bytes.
private Image createImage(String name) {
byte[] bytes = getRawBytes(name);
ByteArrayInputStream in = new ByteArrayInputStream(bytes);
Iterator iterators = ImageIO.getImageReadersByFormatName("jpeg");
ImageReader iterator = (ImageReader) iterators.next();
try {
ImageInputStream iis = ImageIO.createImageInputStream(in);
iterator.setInput(iis, true);
return iterator.read(0);
} catch (IOException e) {
System.err.println(e);
return null;
}
}
// Create a list of all available images.
private List<Image> createImageList() {
List<Image> list = new ArrayList<Image>();
Set<String> key_set = photos.keySet();
for (String key : key_set) {
Image image = createImage(key);
if (image != null) {
list.add(image);
}
}
return list;
}
// Returns one image given the image's name.
@WebMethod
public Image getImage(String name) {
return createImage(name);
}
// Returns a list of all available images.
@WebMethod
public List<Image> getImages() {
return createImageList();
}
// Read the bytes from the file for one image.
@SuppressWarnings("unused")
private byte[] getRawBytes(String name) {
ByteArrayOutputStream out = new ByteArrayOutputStream();
try {
String cwd = System.getProperty("user.dir");
String sep = System.getProperty("file.separator");
String base_name = cwd + sep + "jpegs" + sep;
String file_name = base_name + name + ".jpg";
FileInputStream in = new FileInputStream(file_name);
// Send default image if there's none with this name.
if (in == null) {
in = new FileInputStream(base_name + "nordic.jpg");
}
byte[] buffer = new byte[2048];
int n = 0;
while ((n = in.read(buffer)) != -1) {
out.write(buffer, 0, n); // append to ByteArrayOutputStream
}
in.close();
} catch (IOException e) {
System.err.println(e);
}
return out.toByteArray();
}
}
当我查看我的 WSDL 时,我没有找到以下内容:
<xs:complexType name="getImagesResponse">
<xs:sequence>
<xs:element name="return" type="xs:base64Binary" minOccurs="0" maxOccurs="unbounded"></xs:element>
</xs:sequence>
</xs:complexType>
<xs:complexType name="getImageResponse">
<xs:sequence>
<xs:element name="return" type="xs:base64Binary" minOccurs="0"></xs:element> </xs:sequence>
</xs:complexType>
我在哪里可以找到 XSD 文件/部分?
问候,
米克。