我在向java webservice发出请求时收到上述消息.
我们最初创建了一个Java控制台应用程序并手动提交了一个xml文件.将其作为Java应用程序运行时,将使用System.out.println成功创建并显示响应.我们通过选择包含方法的java文件并选择"create webservice"来指定要在其中创建Web服务的动态项目以及要公开的方法来创建Web服务.
应用程序正在做的是使用xml文件并使用以下方法将其解组为对象:
public static Object unmarshalToObject(Class classToBeBound,
String xmlRequest) {
Object obj = new Object();
try {
JAXBContext jc = JAXBContext.newInstance(classToBeBound);
Unmarshaller um = jc.createUnmarshaller();
obj = um.unmarshal(new StringReader(xmlRequest));
} catch (Exception e) {
e.printStackTrace()
}
return obj;
}
Run Code Online (Sandbox Code Playgroud)
对文件执行一些处理,然后将对象编组为xml,如下所示:
public static String marshalToXML(Object data) {
StringWriter sw = new StringWriter();
try {
logger.info("Create new Marshall");
JAXBContext jc = JAXBContext.newInstance("ContextPathName");
logger.info("Marshalled to xmlObjects");
Marshaller marshaller = jc.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
marshaller.setProperty(Marshaller.JAXB_FRAGMENT, true);
marshaller.marshal(data, sw);
} catch (Exception e) …Run Code Online (Sandbox Code Playgroud)