大木槌 2016-03-08 11:46 采纳率: 0%
浏览 4181

求助:无法使用JAX-WS开发webservice项目

问题:

在使用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时,仍然报错

求助:

哪位前辈对此类问题有解决方案,求指导啊

  • 写回答

2条回答

  • 大木槌 2016-03-08 13:58
    关注

    把SOSOpenAPI类的getResponse()方法中的throws IOException 去掉,应该是JAX-WS要求webmethod不能抛出异常。

    评论

报告相同问题?

悬赏问题

  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 arduino控制ps2手柄一直报错
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 求chat4.0解答一道线性规划题,用lingo编程运行,第一问要求写出数学模型和lingo语言编程模型,第二问第三问解答就行,我的ddl要到了谁来求了
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题