如何创建和CXF Messgae发送的Apache CXF的SOAPMessage? [英] How to create and send apache cxf SoapMessage with cxf Messgae?

查看:433
本文介绍了如何创建和CXF Messgae发送的Apache CXF的SOAPMessage?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用IntellijIDEA,我有测试SOAP WS项目。我对XML和味精文件发送。我怎样才能施放此文件到CXF信息和CXF的SOAPMessage发送?这是我的方法,该方法返回的SOAPMessage:

I'm using IntellijIDEA and I have project for testing SOAP WS. I have xml and msg file for sending. How can I cast this file into cxf Message and cxf SoapMessage for sending? This is my method, which return SoapMessage:

public SoapMessage getMessage(File file) throws Exception{
 Message msg;
 msg.setContent(File.class, file);
 SoapMessage message = new SoapMessage(msg);
 return message;
}

但是,如果我尝试调用这个方法,我看到:

But if I try call this method, I see this:

显示java.lang.NullPointerException

java.lang.NullPointerException

我试图发送此信息:

<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
schemaLocation="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header/>
<soapenv:Body>
    <Test>
      <msg>Test</msg>
    </Test>
</soapenv:Body>
</soapenv:Envelope>

UPD:
有什么需要味精initiallistion?

UPD: What need to msg initiallistion?

Message msg = new Message(){...}?

它用于投我的* .msg文件到的SOAPMessage,并将它发送到SOAP WS

It use for cast my *.msg file into SoapMessage and send it into SOAP WS

推荐答案

有两种方法可以测试基于SOAP的Web服务

Two ways you can test SOAP based web service


  1. 使用SOAP UI客户端 - 这将是很容易

  2. 我们可以使用Maven插件生成Java code和消费开始从主类的服务。

  3. 使用的Java的wsimport命令

  1. Using SOAP UI client - it will be easy
  2. We can generate the java code using Maven plugin and start consuming the service from main class.
  3. Use wsimport command of Java

的wsimport -keep 的http://本地主机:9090 / WS /你好WSDL

wsimport -keep http://localhost:9090/ws/hello?wsdl

URL url = new URL("http://localhost:9090/ws/hello?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://ws.service.com/", "HelloWorldImplService");
Service service = Service.create(url, qname);

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


使用OBJ调用适当的方法。

Using obj call appropriate method.

我们无需手动构造SOAP消息。

We no need to construct the SOAP message manually.

这篇关于如何创建和CXF Messgae发送的Apache CXF的SOAPMessage?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆