本帖最後由 idler 於 2018-1-22 17:37 編輯
https://www.ec-ship.hk/API-portal/EC-Ship_API_client.zip
佢都幾玩野, 要人run 個 createOrder 個api, 同getAddressPack 個api, 要 gen D 野出來再upload去佢個網先可以processo個申請
--------------------------------------------------------------------
Samples for calling EC-Ship (java)
--------------------------------------------------------------------
jdk 1.7 was used for testing.
When new wsdls are available, you will have to re-create the java files in the stub package for each sample project.
1. Download axis files (this is a one-time step)
----------------------------------------------------------------------
You will need to download Axis 1.4 components from www.apache.org at http://archive.apache.org/dist/ws/axis/1_4/
Download axis-bin-1_4.zip or axis-src-1_4.zip. Unzip it into any folder on your drive.
Add the following jar files from the "axis-1_4\lib" folder into your CLASSPATH
(for best results with your IDE, follow the one-time procedure shown right after the list of jar files below):
axis.jar,
commons-discovery-0.2.jar,
commons-logging-1.0.4.jar,
jaxrpc.jar,
log4j-1.2.8.jar,
saaj.jar,
wsdl4j-1.5.1.jar
The following files are not provided with axis but can be obtained from the web. Without these you may get some compilation warnings/errors.
It is more convenient if you also copy them into "axis-1_4\lib".
activation.jar,
mailapi.jar
2. Set CLASSPATH (this is a one-time step)
--------------------------------------------------------------------
On Eclipse-based IDEs, go to Window, Preferences, Java, Build Path,
Classpath variables, add "New" variable. Call this "AXIS_HOME",
and point it to where you unzipped axis components (the folder "axis-1_4", or similar if you use a different version).
(Doing this one-time procedure will automatically take care of classpath references for axis jars in each of the sample projects,
when you open each project as shown below).
3. How to make use of the sample projects
--------------------------------------------------------------------
For testing, you do not have to create a new project from scratch for any of the sample projects.
Each of the projects provided here has an associated ".project" file with it.
This can be used to directly import all existing project files into a new project on Eclipse-based IDEs.
In the IDE, click on File, Import, Existing projects into workspace. Select "Root Directory", then point to the folder containing a ".project" file.
The corresponding project name shows up. Select it and click OK. This will create the project in the IDE, with all required and referenced files.
4. How to re-create the java files in the "stub" package for each project
---------------------------------------------------------------------------------------------------------
WSDL2Java is contained in axis.jar. This is needed to (re)generate the files in the "stub" package - i.e. create java files from a wsdl.
This will be more convenient if you first add axis.jar to your system classpath.
*The following is a one-time step:*
On windows, go to control panel, system, advanced, environment variables, system variables, new -
create a variable called CLASSPATH and add "<full path>\axis.jar" to it.
If you had any command prompt open before doing this, you will have to close it and start a new one to be able to recognize the jar files mentioned above.
*End of one-time step*
Now, start a command prompt, and use the command:
java org.apache.axis.wsdl.WSDL2Java -w -p com.hkpost.integrator.webservice <full_path>/myfile1.wsdl
example:
java org.apache.axis.wsdl.WSDL2Java -w -p com.hkpost.integrator.webservice http://www.ec-ship.hk/API-trial/posting?wsdl
depending on your environment, you may have to use a "?" instead of "." just before "wsdl"
see the command below:
java org.apache.axis.wsdl.WSDL2Java -w -p com.hkpost.integrator.webservice http://www.ec-ship.hk/API-trial/posting?wsdl
or
java org.apache.axis.wsdl.WSDL2Java -w -p com.hkpost.integrator.webservice C:\projects\wsdl\posting.wsdl
or similar.
This will create all files in the stub package, and place them in the folder where you are running the command prompt.
You can then copy the newly created "com" folder and its contents into the appropriate sample project root directory.
----
Now, for each project, make sure there are no compile errors in the web service client main class, and run the project to get the desired output.
5. Date format
----------------
Axis 1.4 maps all xsd:dateTime WSDL/Schema types to Calendar class. The default serialized format of Calendar is:
"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"
Some web services may generate warning with the above format. To override this format each project has a client-config.wsdd file which defines custom type mapping for Calendar. Using this, the Axis client will serialize the Calendar objects in the following format:
"yyyy-MM-dd'T'HH:mm:ss.SSS(+|-)HH:mm"
6. Update Security Credential
----------------
Modify Java File "PWCallback.java" and replace the parameter listed below. The parameter would be your testing key shown in "My Profile" page
"pc.setPassword("UTUb5TCnA5eOQCVJ1X0n7xn3Z"); "
7. Update Account Information
----------------
Besides, you need to update Java File "TestClient.java" with section highlighted below. You need to replace the values with your own user information.
String integratorUsername = "api_demo_account";
String ecshipUsername = "tapi_demo_account";
8. Run the java program
----------------
Compile and Run the java program namely "TestClient.java"
用elicpse 出呢個error
log4j:WARN No appenders could be found for logger (org.apache.axis.i18n.ProjectResourceBundle).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
AxisFault
faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Server.userException
faultSubcode:
faultString: javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
faultActor:
faultNode:
faultDetail:
{http://xml.apache.org/axis/}stackTrace:javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
at sun.security.ssl.Alerts.getSSLException(Unknown Source)
at sun.security.ssl.SSLSocketImpl.fatal(Unknown Source)
at sun.security.ssl.Handshaker.fatalSE(Unknown Source)
at sun.security.ssl.Handshaker.fatalSE(Unknown Source)
at sun.security.ssl.ClientHandshaker.serverCertificate(Unknown Source)
at sun.security.ssl.ClientHandshaker.processMessage(Unknown Source)
at sun.security.ssl.Handshaker.processLoop(Unknown Source)
at sun.security.ssl.Handshaker.process_record(Unknown Source)
at sun.security.ssl.SSLSocketImpl.readRecord(Unknown Source)
at sun.security.ssl.SSLSocketImpl.performInitialHandshake(Unknown Source)
at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source)
at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source)
at org.apache.axis.components.net.JSSESocketFactory.create(JSSESocketFactory.java:186)
at org.apache.axis.transport.http.HTTPSender.getSocket(HTTPSender.java:191)
at org.apache.axis.transport.http.HTTPSender.writeToSocket(HTTPSender.java:404)
at org.apache.axis.transport.http.HTTPSender.invoke(HTTPSender.java:138)
at org.apache.axis.strategies.InvocationStrategy.visit(InvocationStrategy.java:32)
at org.apache.axis.SimpleChain.doVisiting(SimpleChain.java:118)
at org.apache.axis.SimpleChain.invoke(SimpleChain.java:83)
at org.apache.axis.client.AxisClient.invoke(AxisClient.java:165)
at org.apache.axis.client.Call.invokeEngine(Call.java:2784)
at org.apache.axis.client.Call.invoke(Call.java:2767)
at org.apache.axis.client.Call.invoke(Call.java:2443)
at org.apache.axis.client.Call.invoke(Call.java:2366)
at org.apache.axis.client.Call.invoke(Call.java:1812)
at com.hkpost.integrator.webservice.PostingSoapBindingStub.createOrder(PostingSoapBindingStub.java:340)
at com.hkpost.integrator.client.TestClient.addPostingOrder(TestClient.java:441)
at com.hkpost.integrator.client.TestClient.main(TestClient.java:80)
Caused by: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
at sun.security.validator.PKIXValidator.doBuild(Unknown Source)
at sun.security.validator.PKIXValidator.engineValidate(Unknown Source)
at sun.security.validator.Validator.validate(Unknown Source)
at sun.security.ssl.X509TrustManagerImpl.validate(Unknown Source)
at sun.security.ssl.X509TrustManagerImpl.checkTrusted(Unknown Source)
at sun.security.ssl.X509TrustManagerImpl.checkServerTrusted(Unknown Source)
... 24 more
Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
at sun.security.provider.certpath.SunCertPathBuilder.build(Unknown Source)
at sun.security.provider.certpath.SunCertPathBuilder.engineBuild(Unknown Source)
at java.security.cert.CertPathBuilder.build(Unknown Source)
... 30 more
{http://xml.apache.org/axis/}hostname:idler-pc-2018
javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
at org.apache.axis.AxisFault.makeFault(AxisFault.java:101)
at org.apache.axis.transport.http.HTTPSender.invoke(HTTPSender.java:154)
at org.apache.axis.strategies.InvocationStrategy.visit(InvocationStrategy.java:32)
at org.apache.axis.SimpleChain.doVisiting(SimpleChain.java:118)
at org.apache.axis.SimpleChain.invoke(SimpleChain.java:83)
at org.apache.axis.client.AxisClient.invoke(AxisClient.java:165)
at org.apache.axis.client.Call.invokeEngine(Call.java:2784)
at org.apache.axis.client.Call.invoke(Call.java:2767)
at org.apache.axis.client.Call.invoke(Call.java:2443)
at org.apache.axis.client.Call.invoke(Call.java:2366)
at org.apache.axis.client.Call.invoke(Call.java:1812)
at com.hkpost.integrator.webservice.PostingSoapBindingStub.createOrder(PostingSoapBindingStub.java:340)
at com.hkpost.integrator.client.TestClient.addPostingOrder(TestClient.java:441)
at com.hkpost.integrator.client.TestClient.main(TestClient.java:80)
Caused by: javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
at sun.security.ssl.Alerts.getSSLException(Unknown Source)
at sun.security.ssl.SSLSocketImpl.fatal(Unknown Source)
at sun.security.ssl.Handshaker.fatalSE(Unknown Source)
at sun.security.ssl.Handshaker.fatalSE(Unknown Source)
at sun.security.ssl.ClientHandshaker.serverCertificate(Unknown Source)
at sun.security.ssl.ClientHandshaker.processMessage(Unknown Source)
at sun.security.ssl.Handshaker.processLoop(Unknown Source)
at sun.security.ssl.Handshaker.process_record(Unknown Source)
at sun.security.ssl.SSLSocketImpl.readRecord(Unknown Source)
at sun.security.ssl.SSLSocketImpl.performInitialHandshake(Unknown Source)
at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source)
at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source)
at org.apache.axis.components.net.JSSESocketFactory.create(JSSESocketFactory.java:186)
at org.apache.axis.transport.http.HTTPSender.getSocket(HTTPSender.java:191)
at org.apache.axis.transport.http.HTTPSender.writeToSocket(HTTPSender.java:404)
at org.apache.axis.transport.http.HTTPSender.invoke(HTTPSender.java:138)
... 12 more
Caused by: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
at sun.security.validator.PKIXValidator.doBuild(Unknown Source)
at sun.security.validator.PKIXValidator.engineValidate(Unknown Source)
at sun.security.validator.Validator.validate(Unknown Source)
at sun.security.ssl.X509TrustManagerImpl.validate(Unknown Source)
at sun.security.ssl.X509TrustManagerImpl.checkTrusted(Unknown Source)
at sun.security.ssl.X509TrustManagerImpl.checkServerTrusted(Unknown Source)
... 24 more
Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
at sun.security.provider.certpath.SunCertPathBuilder.build(Unknown Source)
at sun.security.provider.certpath.SunCertPathBuilder.engineBuild(Unknown Source)
at java.security.cert.CertPathBuilder.build(Unknown Source)
... 30 more |