问题:
在使用JAX-WS以bottom-up方式开发webservice项目时,基于某一个java**类SOSOpenAPI**创建时,报错:An internal error occurred during: "Generating JAX-WS Web Services".
Unable to create JAXBContext
错误的详细信息如下:
javax.xml.ws.WebServiceException: Unable to create JAXBContext
at com.sun.xml.ws.model.AbstractSEIModelImpl.createJAXBContext(AbstractSEIModelImpl.java:158)
at com.sun.xml.ws.model.AbstractSEIModelImpl.postProcess(AbstractSEIModelImpl.java:87)
at com.sun.xml.ws.model.RuntimeModeler.buildRuntimeModel(RuntimeModeler.java:262)
at com.sun.tools.ws.wscompile.WsgenTool.buildModel(WsgenTool.java:225)
at com.sun.tools.ws.wscompile.WsgenTool.run(WsgenTool.java:124)
at com.genuitec.eclipse.ws.jaxws.JaxWSBUJob.wsGen(JaxWSBUJob.java:229)
at com.genuitec.eclipse.ws.jaxws.JaxWSBUJob.run(JaxWSBUJob.java:125)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:53)
Caused by: java.security.PrivilegedActionException: com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions
java.lang.StackTraceElement does not have a no-arg default constructor.
this problem is related to the following location:
at java.lang.StackTraceElement
at public java.lang.StackTraceElement[] java.lang.Throwable.getStackTrace()
at java.lang.Throwable
at private java.lang.Throwable[] jaxws.IOExceptionBean.suppressed
at jaxws.IOExceptionBean
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.xml.ws.model.AbstractSEIModelImpl.createJAXBContext(AbstractSEIModelImpl.java:148)
... 7 more
Caused by: com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions
java.lang.StackTraceElement does not have a no-arg default constructor.
this problem is related to the following location:
at java.lang.StackTraceElement
at public java.lang.StackTraceElement[] java.lang.Throwable.getStackTrace()
at java.lang.Throwable
at private java.lang.Throwable[] jaxws.IOExceptionBean.suppressed
at jaxws.IOExceptionBean
at com.sun.xml.bind.v2.runtime.IllegalAnnotationsException$Builder.check(IllegalAnnotationsException.java:102)
at com.sun.xml.bind.v2.runtime.JAXBContextImpl.getTypeInfoSet(JAXBContextImpl.java:438)
at com.sun.xml.bind.v2.runtime.JAXBContextImpl.<init>(JAXBContextImpl.java:286)
at com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:139)
at com.sun.xml.bind.api.JAXBRIContext.newInstance(JAXBRIContext.java:105)
at com.sun.xml.ws.model.AbstractSEIModelImpl$1.run(AbstractSEIModelImpl.java:153)
at com.sun.xml.ws.model.AbstractSEIModelImpl$1.run(AbstractSEIModelImpl.java:149)
... 9 more
** SOSOpenAPI.java**代码如下:
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.zip.GZIPOutputStream;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.TransformerException;
import org.w3c.dom.Document;
import org.xml.sax.SAXException;
import com.sensorweb.sos.request.RequestOperator;
import com.sensorweb.sos.response.ISosResponse;
/**
- WebService入口函数
-
*/
public class SOSOpenAPI {
private DocumentBuilderFactory docBuildFactory; //XML解析工厂类
private RequestOperator reop; //请求操作类/** 无参数构造函数 */
public SOSOpenAPI() {
this.docBuildFactory = DocumentBuilderFactory.newInstance();
this.docBuildFactory.setNamespaceAware(true);
this.reop = new RequestOperator();
}/** SOSService中的核心方法
- 该方法在使用SOSService中的功能时被调用
- 通过inputString返回相应的响应结果
- @param inputString String
- @return result byte[]
-
*/
public byte[] getResponse(String inputString) throws IOException {
ISosResponse sosResp = null; //存放响应结果
Document fullRequestDoc = null; //存储解析的XML请求
byte[] bytes = null; //以字节数组的形式存储最后结果
try {
synchronized (this.docBuildFactory) {
DocumentBuilder docBuilder = this.docBuildFactory
.newDocumentBuilder();
fullRequestDoc = docBuilder.parse(new ByteArrayInputStream(
inputString.getBytes()));
}
} catch (ParserConfigurationException pce) {
System.out.println("Error while parsing request!" + pce);} catch (SAXException saxe) {
System.out.println("Error while parsing request!" + saxe);}
fullRequestDoc.getDocumentElement().normalize();
sosResp = this.reop.doPostOperation(inputString);//调用全局变量reop的doPostOperation方法
OutputStream out = null;
GZIPOutputStream gzip = null;
ContentRs cr = new ContentRs();
try {
String contentType = sosResp.getContentType();
int contentLength = sosResp.getContentLength();
bytes = sosResp.getByteArray();//将响应结果转化为字节数据存储
} catch (IOException ioe) {} catch (TransformerException ioe) {
}
return bytes; //返回结果
}
}
而使用与SOSOpenAPI.java在同一包下的**ContentRs.java**作为基类就可以创建webservice,**ContentRs.java**的代码如下:
/**
该类是一个JavaBean,用于存储最后返回的结果
-
*/
public class ContentRs {
private String contentType; //返回结果的类型
private int contentLength; //返回结果的大小
private byte[] bytes; //返回的结果public String getContentType() {
return contentType;
}public void setContentType(String contentType) {
this.contentType = contentType;
}public int getContentLength() {
return contentLength;
}public void setContentLength(int contentLength) {
this.contentLength = contentLength;
}public byte[] getBytes() {
return bytes;
}public void setBytes(byte[] bytes) {
this.bytes = bytes;
}
}
已做的尝试:
更改项目的jdk为jdk1.8.0和jdk1.7.0时,仍然报错
求助:
哪位前辈对此类问题有解决方案,求指导啊