标签: jax-ws

JAX-WS - 如何从服务器端代码创建类型为 xs:any 的元素?

我为我的 Web 服务创建了一个 XML 模式,ServerResponse 的元素包含一个无限制的 xs:any 类型元素序列。

我正在从我的模式生成类(使用 xjc),因此这个序列在生成的 ServerResponse 类中被转换为 List。

ServerResponse 类有一个方法 getAny(),它返回这个 List 并允许我对其进行更改......但我无法确切地弄清楚如何做到这一点。

假设我想向响应中任何对象的序列添加几个元素,以便响应的 XML 将包含它。

<someelement1>sometext</someelement1>
<someelement2>somemoretext</someelement2>
Run Code Online (Sandbox Code Playgroud)

从 Java 服务器端代码,我将如何将这两个元素添加到 getAny() 对象?我认为可以这样做:

Object element = new Object();
((Element)element).setNodeValue("someelement1");
((Element)element).setTextContent("sometext");
requestobject.getAny().add(element);
Run Code Online (Sandbox Code Playgroud)

但是这不起作用,因为它会抛出一个错误,指出“java.lang.object cannot be cast to org.w3.dom.Element”。

谁能帮我做到这一点?我相信有一个非常简单的解决方案!

谢谢你的帮助 :)

java xml xsd web-services jax-ws

4
推荐指数
1
解决办法
5005
查看次数

Maven忽略执行配置

我正在尝试在具有单独配置的maven插件中包含两个执行块,但是maven似乎忽略了执行块内部的配置块,而仅使用执行块外部的配置块。

因此,为了缩小问题的范围,我打开了一个有效的插件部分,将工作配置稍微移到了执行块的内部,然后停止了工作(wsdl仍然被拾取(实际上两个都被拾取)),但这很简单因为它位于默认目录中,所以当配置部分位于执行块内部时,将拾取绑定文件和其他配置中的非配置文件,实际上,它甚至不应该知道第二个wsdl,因为我没有在任何地方指定它):

<build>
    <pluginManagement>
        <plugins>
            <plugin> 
                <groupId>org.jvnet.jax-ws-commons</groupId> 
                <artifactId>jaxws-maven-plugin</artifactId> 
                <version>2.1</version> 
                <executions>
                    <execution> 
                        <id>wsdla</id>
                        <phase>generate-sources</phase>
                        <configuration> 
                            <packageName>com.mycee.project.model</packageName> 
                            <sourceDestDir>src/main/java</sourceDestDir>
                            <wsdlFiles>
                                <wsdlFile>
                                  ${basedir}/src/wsdl/a.wsdl
                                </wsdlFile>            
                            </wsdlFiles>
                            <bindingDirectory>
                                ${basedir}/src/wsdl/binding
                            </bindingDirectory>
                            <verbose>true</verbose>
                        </configuration>
                        <goals> 
                            <goal>wsimport</goal> 
                        </goals>            
                    </execution> 
                </executions>
            </plugin> 
        </plugins>  
    </pluginManagement>
</build>
Run Code Online (Sandbox Code Playgroud)

这是我需要解决的Maven问题,还是下颌问题,我该如何解决?

如果将版本更改为2.3,则会出现以下错误:

[错误]无法在项目mycee-project上执行目标org.jvnet.jax-ws-commons:jaxws-maven-plugin:2.3:wsimport(default-cli):目标org.jvnet.jax-ws的执行default-cli -commons:jaxws-maven-plugin:2.3:wsimport失败:字符串索引超出范围:-1-> [帮助1]

运行mvn clean jaxws:wsimport -X我可以在调试输出中看到它正在使用默认值:

[DEBUG] -----------------------------------------------------------------------
[DEBUG] Goal:          org.jvnet.jax-ws-commons:jaxws-maven-plugin:2.3:wsimport (default-cli)
[DEBUG] Style:         Regular
[DEBUG] Configuration: <?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <bindingDirectory default-value="${basedir}/src/jaxws"/>
  <destDir default-value="${project.build.outputDirectory}"/>
  <encoding>${project.build.sourceEncoding}</encoding>
  <extension default-value="false"/>
  <genJWS default-value="false"/>
  <implDestDir default-value="${project.build.sourceDirectory}"/>
  <keep default-value="true"/>
  <localRepository default-value="${localRepository}"/>
  <pluginArtifactMap>${plugin.artifactMap}</pluginArtifactMap>
  <quiet default-value="false"/>
  <remoteRepositories default-value="${project.pluginArtifactRepositories}"/>
  <settings>${settings}</settings> …
Run Code Online (Sandbox Code Playgroud)

jax-ws maven

4
推荐指数
1
解决办法
3万
查看次数

不是 JAX-WS 中的有效服务异常

我正在参考http://www.mkyong.com/webservices/jax-ws/jax-ws-hello-world-example/

这是我的 HelloWorldClient

package WebService;


import java.net.URL;
import javax.xml.namespace.QName;
import javax.xml.ws.Service;



public class HelloWorldClient{

    public static void main(String[] args) throws Exception {

    URL url = new URL("http://localhost:8099/dummy1/dummy2?wsdl");

        //1st argument service URI, refer to wsdl document above
    //2nd argument is service name, refer to wsdl document above
        QName qname = new QName("http://localhost:8099/dummy1/dummy2?wsdl", "HelloWorldImplService");


        Service service = Service.create(url, qname);

        HelloWorld hello = service.getPort(HelloWorld.class);

        System.out.println(hello.getHelloWorldAsString("mkyong"));

    }

}
Run Code Online (Sandbox Code Playgroud)

运行这个类时,我从下面的代码行收到错误

Service service = Service.create(url, qname);
Run Code Online (Sandbox Code Playgroud)

错误是

Exception in thread "main" javax.xml.ws.WebServiceException: {http://localhost:8099/dummy1/dummy2?wsdl}HelloWorldImplService is …
Run Code Online (Sandbox Code Playgroud)

java soap jax-ws

4
推荐指数
1
解决办法
1万
查看次数

如何在客户端记录SOAP消息?

美好的一天.我正在学习如何编写连接到外部SOAP RCP样式的服务.我正在使用jaxws-maven-plugin插件从WSDL文件生成Java类.我正在使用Spring来创建Web服务客户端bean:

@Configuration
public class StoreServiceConfig {

    @Bean
    public StoreWS storeWS() throws IOException {
        JaxWsPortProxyFactoryBean factoryBean = new JaxWsPortProxyFactoryBean();
        factoryBean.setServiceInterface(StoreWS.class);
        factoryBean.setWsdlDocumentUrl(new ClassPathResource("/wsdl/StoreWS.wsdl").getURL());
        factoryBean.setNamespaceUri("urn_store");
        factoryBean.setServiceName("StoreWSService");
        factoryBean.setEndpointAddress("https://10.34.45.82/storeservice/services/StoreWS");
        factoryBean.setUsername("testuser");
        factoryBean.setPassword("testpassword");
        factoryBean.afterPropertiesSet();
        return (StoreWS) factoryBean.getObject();
    }
}
Run Code Online (Sandbox Code Playgroud)

为了测试客户端,我使用JUnit编写了一个测试类.我用这种方式打电话给客户:

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = StoreServiceTestConfig.class)
public class StoreServiceImplTest {
    @Autowired
    private StoreWS storeWS;
    ...
    @Test
    public void testExecuteQuery() throws Exception {
        ...
        StoreResponseType response = storeWS.executeQuery(storeRequest);
        ...
    }
}
Run Code Online (Sandbox Code Playgroud)

现在,我需要测试将完整的传出和传入SOAP消息记录到控制台中.请问怎么做?越简单越好.

我找到了使用以下系统参数的建议,但它们都不适用于我:

com.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.dump=true
com.sun.xml.ws.transport.http.client.HttpTransportPipe.dump=true
com.sun.xml.ws.transport.local.LocalTransportPipe.dump=true
com.sun.xml.ws.transport.http.HttpAdapter.dump=true
Run Code Online (Sandbox Code Playgroud)

我正在使用Spring配置类(没有XML)和所有依赖项的最新版本.

我找到了这个答案,但我不知道如何在我的场景中使用它.

提前谢谢了!Vojtech

编辑: 我的logback.xml看起来像这样,但我仍然看不到控制台中的任何肥皂消息:

<?xml version="1.0" encoding="UTF-8"?> …
Run Code Online (Sandbox Code Playgroud)

java spring-ws jax-ws soap-client java-ws

4
推荐指数
1
解决办法
2万
查看次数

如何在JAX-WS Java Web服务中使用Log4j2

正如之前的StackOverflow问题中所述,我正在学习如何使用JAX-WS(用于XML Web服务的Java API).我在之前的可执行Java程序中使用了Log4j2,我想用它来记录Web服务请求.如何在此JAX-WS教程中将Log4j2添加到基本代码中?

java configuration web-services jax-ws log4j2

4
推荐指数
1
解决办法
1674
查看次数

AEM上的RESTful服务

我试图在AEM上公开一些RESTfull Web服务.我已按照此博客中的说明操作.以下是我的服务类.像/ helloservice/sayhi这样的简单请求工作得很好,但是采用路径参数和查询参数的方法(/withparameter/{userid}/query?q=xyz&prod=abc)返回404错误页面.请帮我解决一下这个.

我正在使用AEM 5.6和Java 7

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Service;
import com.foo.bar.service.SampleResource;

@Service
@Component(metatype=true)
@Path("/helloservice")
public class SampleResourceImpl implements SampleResource{

    @GET
    @Path("/sayhi")
    @Produces({MediaType.APPLICATION_JSON})
    public String helloWorld(){
        return "Hello World";
    }

    @GET
    @Path("/getoperation")
    @Produces({MediaType.TEXT_PLAIN})
    public String getServiceOperation(){
        return "Hello getoperation!";
    }

    @GET
    @Path("/withparameter/{userid}")
    @Produces({MediaType.TEXT_PLAIN})
    public String getWithParameter(@PathParam("userid") String userid){
        return "Path parameter : "+userid;
    }

    @GET
    @Path("/query")
    @Produces({MediaType.TEXT_PLAIN})
    public String getURLParameters(@QueryParam("q") String q, …
Run Code Online (Sandbox Code Playgroud)

java rest jax-ws aem

4
推荐指数
1
解决办法
2192
查看次数

使用 XJC 生成 Java 源代码时使用 JAXWS enableWrapperStyle

我正在尝试从 XSD 生成 Java 源代码,并且必须使用 JAXWS 禁用包装器样式。我已经编写了自定义绑定,但 JAXWS 似乎不适用于 XJC。我使用的绑定非常简单。

<jaxb:bindings xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:jaxws="http://java.sun.com/xml/ns/jaxws" xmlns="http://java.sun.com/xml/ns/jaxws"
version="2.1" jaxb:extensionBindingPrefixes="xjc">

<jaxb:bindings>
    <jaxb:globalBindings typesafeEnumMaxMembers="2000" generateElementProperty="false" >
         <jaxws:enableWrapperStyle>false</jaxws:enableWrapperStyle>
    </jaxb:globalBindings>
</jaxb:bindings>
Run Code Online (Sandbox Code Playgroud)

如果我尝试运行 ant 脚本,我会收到以下错误消息。

 [xjc] [ERROR] Unsupported binding namespace "http://java.sun.com/xml/ns/jaxws". Perhaps you meant "http://java.sun.com/xml/ns/jaxb/xjc"?
  [xjc]   line 2 of file:/D:/xxxxxxxxxx/xxxxx/xxxx.xsd
  [xjc] [ERROR] cvc-complex-type.2.4.a: Invalid content was found starting with element 'jaxws:enableWrapperStyle'. One of '{"http://java.sun.com/xml/ns/jaxb":javaType, "http://java.sun.com/xml/ns/jaxb":serializable, "http://java.sun.com/xml/ns/jaxb/xjc":serializable, "http://java.sun.com/xml/ns/jaxb/xjc":superClass, "http://java.sun.com/xml/ns/jaxb/xjc":superInterface, "http://java.sun.com/xml/ns/jaxb/xjc":typeSubstitution, "http://java.sun.com/xml/ns/jaxb/xjc":smartWildcardDefaultBinding, "http://java.sun.com/xml/ns/jaxb/xjc":simple, "http://java.sun.com/xml/ns/jaxb/xjc":treatRestrictionLikeNewType, "http://java.sun.com/xml/ns/jaxb/xjc":javaType, "http://java.sun.com/xml/ns/jaxb/xjc":generateElementProperty, "http://java.sun.com/xml/ns/jaxb/xjc":noMarshaller, "http://java.sun.com/xml/ns/jaxb/xjc":noUnmarshaller, "http://java.sun.com/xml/ns/jaxb/xjc":noValidator, "http://java.sun.com/xml/ns/jaxb/xjc":noValidatingUnmarshaller}' is expected.
  [xjc]   line 8 of file:/D:/xxxxxxxxxx/xxxxx/xxxx/xsd/xsd-binding.xml
Run Code Online (Sandbox Code Playgroud)

我已经尝试仅使用 …

java jax-ws jaxb xjc

4
推荐指数
1
解决办法
9454
查看次数

为什么我得到Method CacheXXXX 被暴露为WebMethod,但是没有相应的wsdl 操作如果wsdl 没有改变?

我希望你做得很好,

我正在使用 jax-ws 并且我使用 cxf 3.1.6 和 SOAP UI 生成了客户端,但是当我调用一个方法时出现了这个错误,我到处找,问题似乎 wsdl 已经改变了,但是不是我的问题,我已经生成了数千次客户端。顺便说一句,我正在调用的方法不是我收到错误的方法。

服务器:Liberty Profile 8

这是错误跟踪

[ERROR   ] Error occurred during error handling, give up!
Method CacheXXXX is exposed as WebMethod, but there is no corresponding wsdl operation with name {[this is not a link]http://company.com/GeographicalDesignStructure/wsdl/1.0/_MM/}CacheXXXX in the wsdl:portType{[this is not a link]http://company.com/GeographicalDesignStructure/wsdl/1.0/_MM/}GeographicalDesignStructure
[ERROR   ] SRVE0777E: Excepción lanzada por la clase de aplicación 'org.apache.cxf.interceptor.AbstractFaultChainInitiatorObserver.onMessage:116'
java.lang.RuntimeException: org.apache.cxf.interceptor.Fault: Method CacheXXXX is exposed as WebMethod, but there is no corresponding wsdl operation with name …
Run Code Online (Sandbox Code Playgroud)

java soap wsdl cxf jax-ws

4
推荐指数
1
解决办法
6942
查看次数

RESTful:Jersey 中的 ClientProperties.CONNECT_TIMEOUT 和 ClientProperties.READ_TIMEOUT 有什么区别?

为了在进行 REST 调用时设置超时,我们应该同时指定这两个参数,但我不确定为什么这两个参数以及它们的用途究竟有何不同。另外,如果我们只设置其中一个或两个具有不同的值怎么办?

java jax-rs jax-ws jersey-client jersey-2.0

4
推荐指数
1
解决办法
3179
查看次数

如何让 JAX-WS 端点接受 SOAP1.2 消息

我有一个基于 Spring Boot 的项目,它使用 CXF 来构建 SOAP Web 服务。

发送 SOAP 1.1 消息(使用 SOAPUI)工作正常,但是当我尝试发送 SOAP 1.2 消息(当然使用相同的 WSDL)时,我收到了消息"A SOAP 1.2 message is not valid when sent to a SOAP 1.1 only endpoint"。该消息是自我解释的,但我不明白为什么我的端点不接受 1.2 消息。

我的 WSDL 包含soap12 的正确绑定和命名空间。

在我的 spring @Configuration 类中,我将它添加到 CXF 端点 bean:

    endpoint.setBindingConfig(new BindingConfiguration()
    {
        @Override
        public String getBindingId()
        {
            return SOAPBinding.SOAP12HTTP_MTOM_BINDING;
        }
    });
Run Code Online (Sandbox Code Playgroud)

那没有帮助。当我变得更加绝望时,我尝试了@BindingType@SOAPBinding注释当然不起作用,然后我尝试SaajSoapMessageFactorySoapVersion.SOAP_12. 没用。我<extension>true</extension><protocol>Xsoap1.2</protocol>在我的jaxws-maven-plugin. 失败的。

端点显然没有配置为接收 SOAP 1.2 消息。我如何实现这一目标?

soap wsdl cxf jax-ws spring-boot

4
推荐指数
1
解决办法
3984
查看次数