0

问题和堆栈跟踪

本文档(来自 w3.org)描述了 jaxws 对“tns”前缀的常规用法:

“this namespace” (tns) 前缀用作引用当前文档的约定。


我的问题主要集中在这个tns前缀是否实际上被 jaxws 保留。我有一些使用下面包含的模式从 XJC 生成的 POJO。除了这些生成的 POJO,我将现有的package-info.java文件替换为如下所示的文件。这个包裹信息。java文件本质上保留了以 XML 模式编写的命名空间和前缀信息。在 tomcat 中启动我的 Web 服务时,我收到以下错误,这似乎表明 jaxws 想要使用tns,并且由于它已被命名空间使用http://www.offender.com,因此引发了 IllegalArgumentException。请注意,它tns已声明,但从未使用过。有没有其他人遇到过这个问题?我想tns是一个常用的命名空间,所以我tnspackage-info.java中明确使用某种失礼?

SEVERE: WSSERVLET11: failed to parse runtime descriptor: java.lang.IllegalArgumentException: Prefix 'tns' is already bound to 'http://www.offender.com'
java.lang.IllegalArgumentException: Prefix 'tns' is already bound to 'http://www.offender.com'
        at com.sun.xml.txw2.StartTag.addNamespaceDecl(StartTag.java:171)
        at com.sun.xml.txw2.ContainerElement._namespace(ContainerElement.java:313)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:616)
        at com.sun.xml.txw2.ContainerElement.invoke(ContainerElement.java:114)
        at sun.proxy.$Proxy92._namespace(Unknown Source)
        at com.sun.xml.bind.v2.schemagen.XmlSchemaGenerator$Namespace.writeTo(XmlSchemaGenerator.java:636)
        at com.sun.xml.bind.v2.schemagen.XmlSchemaGenerator$Namespace.access$700(XmlSchemaGenerator.java:493)
        at com.sun.xml.bind.v2.schemagen.XmlSchemaGenerator.write(XmlSchemaGenerator.java:475)
        at com.sun.xml.bind.v2.runtime.JAXBContextImpl.generateSchema(JAXBContextImpl.java:826)
        at com.sun.xml.ws.db.glassfish.JAXBRIContextWrapper.generateSchema(JAXBRIContextWrapper.java:103)
        at com.sun.xml.ws.wsdl.writer.WSDLGenerator.generateTypes(WSDLGenerator.java:457)
        at com.sun.xml.ws.wsdl.writer.WSDLGenerator.generateDocument(WSDLGenerator.java:433)
        at com.sun.xml.ws.wsdl.writer.WSDLGenerator.doGeneration(WSDLGenerator.java:330)
        at com.sun.xml.ws.db.DatabindingImpl.generateWSDL(DatabindingImpl.java:230)
        at com.sun.xml.ws.server.EndpointFactory.generateWSDL(EndpointFactory.java:553)
        at com.sun.xml.ws.server.EndpointFactory.create(EndpointFactory.java:278)
        at com.sun.xml.ws.server.EndpointFactory.createEndpoint(EndpointFactory.java:147)
        at com.sun.xml.ws.api.server.WSEndpoint.create(WSEndpoint.java:574)
        at com.sun.xml.ws.api.server.WSEndpoint.create(WSEndpoint.java:557)
        at com.sun.xml.ws.transport.http.DeploymentDescriptorParser.parseAdapters(DeploymentDescriptorParser.java:260)
        at com.sun.xml.ws.transport.http.DeploymentDescriptorParser.parse(DeploymentDescriptorParser.java:152)
        at com.sun.xml.ws.transport.http.servlet.WSServletContextListener.parseAdaptersAndCreateDelegate(WSServletContextListener.java:131)
        at com.sun.xml.ws.transport.http.servlet.WSServletContextListener.contextInitialized(WSServletContextListener.java:152)
        at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4206)
        at org.apache.catalina.core.StandardContext.start(StandardContext.java:4705)
        at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:799)
        at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:779)
        at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:601)
        at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:943)
        at org.apache.catalina.startup.HostConfig.deployWARs(HostConfig.java:778)
        at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:504)
        at org.apache.catalina.startup.HostConfig.check(HostConfig.java:1385)
        at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:306)
        at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:142)
        at org.apache.catalina.core.ContainerBase.backgroundProcess(ContainerBase.java:1389)
        at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1653)
        at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1662)

用于我的 Web 服务部署的文件

使用 xjc 创建 POJO 的模式:

<?xml version="1.0" encoding="UTF-8"?>
<!-- edited with XMLSpy v2013 rel. 2 (x64) (http://www.altova.com) by Allen Strand (FAIR ISAAC & COMPANY) -->
<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://www.offender.com" xmlns:ns1="http://www.example.com" targetNamespace="http://www.example.com" elementFormDefault="qualified">
    <element name="Example">
        <complexType>
            <sequence>
                <element name="ExampleElement" type="ns1:ExampleType"/>
            </sequence>
        </complexType>
    </element>
    <complexType name="ExampleType">
        <sequence>
            <element name="ExampleProperty" type="string"/>
        </sequence>
    </complexType>
</schema>

太阳jaxws.xml

<?xml version="1.0" encoding="UTF-8"?>
<endpoints
  xmlns="http://java.sun.com/xml/ns/jax-ws/ri/runtime"
  version="2.0">
  <endpoint
      name="ExampleEndpoint"
      implementation="com.example.soap.ExampleEndpointImpl"
      url-pattern="/ws/runtime/eval"/>
</endpoints>

包信息.java

@javax.xml.bind.annotation.XmlSchema(
    namespace = "http://www.example.com",
    elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED,
    xmlns = {
        @XmlNs(prefix = "ns1",namespaceURI = "http://www.example.com"),
        @XmlNs(prefix = "tns",namespaceURI = "http://www.offender.com")
    })
package com.some.package;
import javax.xml.bind.annotation.XmlNs;

ExampleEndpoint.java 接口

package com.example.soap;

import com.example.soap.SOAPFaultException;

import javax.jws.HandlerChain;
import javax.jws.soap.SOAPBinding;
import javax.jws.soap.SOAPBinding.Style;
import javax.jws.soap.SOAPBinding.Use;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;

import com.example.Example;

//Service Endpoint Interface
@WebService
@SOAPBinding(style = Style.DOCUMENT, use=Use.LITERAL) //optional
@HandlerChain(file="handler-chain.xml")
public interface ExampleEndpoint
{
    @WebMethod
    @WebResult(name="Example", targetNamespace = "http://www.example.com")
    Example eval(@WebParam(name="Example", mode=WebParam.Mode.IN, targetNamespace="http://www.example.com")
    Example in) throws SOAPFaultException;
}
4

1 回答 1

0

xmlns:tns="http://www.offender.com" 从架构 xml中删除并尝试。它应该工作。

拥有 targetnamespace 就可以了。如果您想在模式文件中包含 xmlns:tns,它 (xmlns:tns) 应该与 targetNamespace 相同。

于 2013-09-06T05:31:43.463 回答