Apache CXF自动生成WebService客户端java代码并调用介绍
$ source .zshrc
2、文件:访问wsdl接口,下载页面内容。然后根据需要的接口数据定义,
去掉一些无用的接口定义。不然生成无用的对象。
得到 ChinaStockSmallImageWS.asmx?wsdl
3.Mac修改JDK路径
a. 查看jdk安装路径,举个栗子
/Library/Java/JavaVirtualMachines/jdk1.8.0_101.jdk/Contents/Home
b. 找到并修改 bin/wsdl2java 中的变量JAVA_HOME和CXF_HOME为本地环境路径
…
#!/bin/sh
cygwin=false;
darwin=false;
JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home
#case “uname
” in
#esac
DIR=" ( c d " ( cd " (cd"( dirname KaTeX parse error: Expected 'EOF', got '&' at position 19: …" >/dev/null 2>&̲1 && pwd )" . "{DIR}/inc"
checkJvmVersion
me=basename $0
CXF_HOME=/Users/qiuzhiqing/2-my-tools/apache-cxf-3.3.6
cxf_home=$CXF_HOME
if [ ! -f $cxf_home/lib/cxf-manifest.jar ]; then
cxf_home=dirname $0
/…
fi
cxf_jar=$cxf_home/lib/cxf-manifest.jar
if [ ! -f $cxf_jar ]; then
if [ ! -f ${cxf_home}/…/…/…/target/srcbuild_env ]; then
echo “ERROR: Unable to find cxf-manifest.jar in $cxf_home/lib”
exit 1
else
.
c
x
f
h
o
m
e
/
.
.
/
.
.
/
.
.
/
t
a
r
g
e
t
/
s
r
c
b
u
i
l
d
e
n
v
c
x
f
j
a
r
=
{cxf_home}/../../../target/srcbuild_env cxf_jar=
cxfhome/../../../target/srcbuildenvcxfjar={CXF_CLASSPATH}
fi
fi
log_config=$cxf_home/etc/logging.properties
if
c
y
g
w
i
n
;
t
h
e
n
i
f
[
"
cygwin; then if [ "
cygwin;thenif["OS" = “Windows_NT” ] && cygpath -m .>/dev/null 2>/dev/null ; then
format=mixed
else
format=windows
fi
cxf_classpath=cygpath --$format "${cxf_jar}"
if [ ! -z "
C
L
A
S
S
P
A
T
H
"
]
;
t
h
e
n
c
x
f
c
l
a
s
s
p
a
t
h
=
{CLASSPATH}" ]; then cxf_classpath=
CLASSPATH"];thencxfclasspath={cxf_classpath};cygpath --$format --path "${CLASSPATH}"
fi
if [ ! -z "
s
u
n
t
o
o
l
p
a
t
h
"
]
;
t
h
e
n
c
x
f
c
l
a
s
s
p
a
t
h
=
{sun_tool_path}" ] ; then cxf_classpath=
suntoolpath"];thencxfclasspath={cxf_classpath};cygpath --$format "${sun_tool_path}"
fi
log_config=cygpath --$format "$log_config"
else
cxf_classpath=
c
x
f
j
a
r
:
{cxf_jar}:
cxfjar:{CLASSPATH}{sun_tool_path}
fi
if [ “x${JAVA_MAX_MEM}” = “x” ]; then
JAVA_MAX_MEM=512M
export JAVA_MAX_MEM
fi
if [ “${VERSION}” -gt “8” ]; then
J
A
V
A
H
O
M
E
/
b
i
n
/
j
a
v
a
−
X
m
x
JAVA_HOME/bin/java -Xmx
JAVAHOME/bin/java−Xmx{JAVA_MAX_MEM} -cp “
c
x
f
c
l
a
s
s
p
a
t
h
"
−
D
j
a
v
a
.
u
t
i
l
.
l
o
g
g
i
n
g
.
c
o
n
f
i
g
.
f
i
l
e
=
{cxf_classpath}" -Djava.util.logging.config.file=
cxfclasspath"−Djava.util.logging.config.file=log_config org.apache.cxf.tools.wsdlto.WSDLToJava “$@”
else
J
A
V
A
H
O
M
E
/
b
i
n
/
j
a
v
a
−
X
m
x
JAVA_HOME/bin/java -Xmx
JAVAHOME/bin/java−Xmx{JAVA_MAX_MEM} -Djava.endorsed.dirs=”
c
x
f
h
o
m
e
/
l
i
b
/
e
n
d
o
r
s
e
d
"
−
c
p
"
{cxf_home}/lib/endorsed" -cp "
cxfhome/lib/endorsed"−cp"{cxf_classpath}" -Djava.util.logging.config.file=
l
o
g
c
o
n
f
i
g
o
r
g
.
a
p
a
c
h
e
.
c
x
f
.
t
o
o
l
s
.
w
s
d
l
t
o
.
W
S
D
L
T
o
J
a
v
a
"
log_config org.apache.cxf.tools.wsdlto.WSDLToJava "
logconfigorg.apache.cxf.tools.wsdlto.WSDLToJava"@"
fi
b. 方式1:uri生成
wsdl2java -d ./src -client ‘http://www.webxml.com.cn/webservices/ChinaStockSmallImageWS.asmx?wsdl’
c. 方式2:file生成
wsdl2java -d ./src -client ./ChinaStockSmallImageWS.asmx?wsdl
d. 生成代码目录
-rw-r–r-- 1 qiuzhiqing staff 1947 4 24 10:47 GetSmallImage.java
-rw-r–r-- 1 qiuzhiqing staff 1955 4 24 10:47 GetSmallImageByte.java
-rw-r–r-- 1 qiuzhiqing staff 1496 4 24 10:47 GetSmallImageByteResponse.java
-rw-r–r-- 1 qiuzhiqing staff 725 4 24 10:47 GetSmallImageResponse.java
-rw-r–r-- 1 qiuzhiqing staff 2390 4 24 10:47 ObjectFactory.java
-rw-r–r-- 1 qiuzhiqing staff 165 4 24 10:47 package-info.java
-rw-r–r-- 1 qiuzhiqing staff 2362 4 24 10:47 ChinaStockSmallImageWSSoap_ChinaStockSmallImageWSSoap12_Client.java
-rw-r–r-- 1 qiuzhiqing staff 2356 4 24 10:47 ChinaStockSmallImageWSSoap_ChinaStockSmallImageWSSoap_Client.java
-rw-r–r-- 1 qiuzhiqing staff 2320 4 24 10:47 ChinaStockSmallImageWSHttpGet_ChinaStockSmallImageWSHttpGet_Client.java
-rw-r–r-- 1 qiuzhiqing staff 2326 4 24 10:47 ChinaStockSmallImageWSHttpPost_ChinaStockSmallImageWSHttpPost_Client.java
-rw-r–r-- 1 qiuzhiqing staff 2545 4 24 10:47 ChinaStockSmallImageWSSoap.java
-rw-r–r-- 1 qiuzhiqing staff 2026 4 24 10:47 ChinaStockSmallImageWSHttpGet.java
-rw-r–r-- 1 qiuzhiqing staff 2028 4 24 10:47 ChinaStockSmallImageWSHttpPost.java
-rw-r–r-- 1 qiuzhiqing staff 7438 4 24 10:47 ChinaStockSmallImageWS.java
package cn.com.webxml;
/**
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import javax.xml.namespace.QName;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;
import javax.xml.bind.annotation.XmlSeeAlso;
import javax.xml.ws.RequestWrapper;
import javax.xml.ws.ResponseWrapper;
/**
*/
public final class ChinaStockSmallImageWSSoap_ChinaStockSmallImageWSSoap_Client {
private static final QName SERVICE_NAME = new QName("http://WebXml.com.cn/", "ChinaStockSmallImageWS");
private ChinaStockSmallImageWSSoap_ChinaStockSmallImageWSSoap_Client() {
}
public static void main(String args[]) throws java.lang.Exception {
URL wsdlURL = ChinaStockSmallImageWS.WSDL_LOCATION;
if (args.length > 0 && args[0] != null && !"".equals(args[0])) {
File wsdlFile = new File(args[0]);
try {
if (wsdlFile.exists()) {
wsdlURL = wsdlFile.toURI().toURL();
} else {
wsdlURL = new URL(args[0]);
}
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
ChinaStockSmallImageWS ss = new ChinaStockSmallImageWS(wsdlURL, SERVICE_NAME);
ChinaStockSmallImageWSSoap port = ss.getChinaStockSmallImageWSSoap();
{
System.out.println("Invoking getSmallImage...");
java.lang.String _getSmallImage_theStockCode = "";
short _getSmallImage_theImageType = Short.parseShort("0");
port.getSmallImage(_getSmallImage_theStockCode, _getSmallImage_theImageType);
}
{
System.out.println("Invoking getSmallImageByte...");
java.lang.String _getSmallImageByte_theStockCode = "";
short _getSmallImageByte_theImageType = Short.parseShort("0");
byte[] _getSmallImageByte__return = port.getSmallImageByte(_getSmallImageByte_theStockCode, _getSmallImageByte_theImageType);
System.out.println("getSmallImageByte.result=" + _getSmallImageByte__return);
}
System.exit(0);
}
}