Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/rest/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我希望能够使用java.xml发送通用xml_Java_Rest - Fatal编程技术网

我希望能够使用java.xml发送通用xml

我希望能够使用java.xml发送通用xml,java,rest,Java,Rest,我需要一个可以接受任意xml字符串的Web服务。 我试图使用使用xmAnyElement标记的代码,但它不起作用。 代码如下: @XmlRootElement(name="root") @XmlType(propOrder={"header","body"}) public class TieHornetqRequest { private String header; private String body; @XmlAnyElement public Str

我需要一个可以接受任意xml字符串的Web服务。 我试图使用使用xmAnyElement标记的代码,但它不起作用。 代码如下:

@XmlRootElement(name="root")
@XmlType(propOrder={"header","body"})
public class TieHornetqRequest {
    private String header;
    private String body;

    @XmlAnyElement
    public String getHeader() {
        return header;
    }
    public void setHeader(String header) {
        this.header = header;
    }

    @XmlAnyElement(lax=true)
    public String getBody() {
        return body;
    }
    public void setBody(String body) {
        this.body = body;
    }
}
但是,当我尝试运行stacktrace时,它会出现以下情况:

16:17:44,372 WARN  [org.jboss.resteasy.core.SynchronousDispatcher] (http-127.0.0.1/127.0.0.1:8080-1) Failed executing POST /tieHornetQ/getTieHornetqData: org.jboss.resteasy.spi.UnsupportedMediaTypeException: Cannot consume content type
    at org.jboss.resteasy.core.registry.Segment.match(Segment.java:117) [resteasy-jaxrs-2.3.3.Final.jar:]
    at org.jboss.resteasy.core.registry.SimpleSegment.matchSimple(SimpleSegment.java:33) [resteasy-jaxrs-2.3.3.Final.jar:]
    at org.jboss.resteasy.core.registry.RootSegment.matchChildren(RootSegment.java:327) [resteasy-jaxrs-2.3.3.Final.jar:]
    at org.jboss.resteasy.core.registry.SimpleSegment.matchSimple(SimpleSegment.java:44) [resteasy-jaxrs-2.3.3.Final.jar:]
    at org.jboss.resteasy.core.registry.RootSegment.matchChildren(RootSegment.java:327) [resteasy-jaxrs-2.3.3.Final.jar:]
    at org.jboss.resteasy.core.registry.RootSegment.matchRoot(RootSegment.java:374) [resteasy-jaxrs-2.3.3.Final.jar:]
    at org.jboss.resteasy.core.registry.RootSegment.matchRoot(RootSegment.java:367) [resteasy-jaxrs-2.3.3.Final.jar:]
    at org.jboss.resteasy.core.ResourceMethodRegistry.getResourceInvoker(ResourceMethodRegistry.java:315) [resteasy-jaxrs-2.3.3.Final.jar:]
    at org.jboss.resteasy.core.SynchronousDispatcher.getInvoker(SynchronousDispatcher.java:173) [resteasy-jaxrs-2.3.3.Final.jar:]
    at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:118) [resteasy-jaxrs-2.3.3.Final.jar:]
    at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:208) [resteasy-jaxrs-2.3.3.Final.jar:]
    at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:55) [resteasy-jaxrs-2.3.3.Final.jar:]
    at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:50) [resteasy-jaxrs-2.3.3.Final.jar:]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) [jboss-servlet-api_3.0_spec-1.0.1.Final.jar:1.0.1.Final]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329) [jbossweb-7.0.16.Final.jar:]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.16.Final.jar:]
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) [jbossweb-7.0.16.Final.jar:]
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161) [jbossweb-7.0.16.Final.jar:]
    at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:153) [jboss-as-web-7.1.2.Final.jar:7.1.2.Final]
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155) [jbossweb-7.0.16.Final.jar:]
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [jbossweb-7.0.16.Final.jar:]
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [jbossweb-7.0.16.Final.jar:]
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368) [jbossweb-7.0.16.Final.jar:]
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) [jbossweb-7.0.16.Final.jar:]
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:679) [jbossweb-7.0.16.Final.jar:]
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:931) [jbossweb-7.0.16.Final.jar:]
    at java.lang.Thread.run(Thread.java:662) [rt.jar:1.6.0_27]

在发送请求时,我没有传递xml,而是传递了一个字符串:

public class TieHornetqLookup {
//  private static final Log log = LogFactory.getLog(CreateOrderLookup.class.getName());
    private String request;
    private TieHornetqResponse response;

    public TieHornetqLookup(String request) {
        this.request = request;
    }

    public TieHornetqResponse getResponse() throws Exception {

        try{

            SendRequest.sender(request);

            return response;
        } catch(Exception e) {
            //log.error("Exception while attempting to get a response: ", e);
            throw e;
        }
    }
}

您是否调查过
@消费
?我不知道这是否是答案,但它可以工作。是的,我在接受XML的类中有@Consumes。我现在将它改为接受字符串,看起来它可以工作了。这是最好的解决办法吗?