Commit d60ca77d authored by 曲欣红's avatar 曲欣红

c

parent c9a730e2
package sso;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import javax.security.auth.callback.Callback;
import javax.security.auth.callback.CallbackHandler;
import org.apache.cxf.endpoint.Client;
import org.apache.cxf.endpoint.ClientImpl;
import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory;
import org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor;
import org.apache.ws.security.WSConstants;
import org.apache.ws.security.handler.WSHandlerConstants;
import org.apache.wss4j.common.ext.WSPasswordCallback;
import org.junit.Before;
import org.junit.Test;
import com.alibaba.fastjson.JSON;
public class TestClient {
private final String username = "test";
private final String password = "78258c537d6e4d5fb210a57d05619fb6";
private Client wsClient;
@Before
public void init() {
JaxWsDynamicClientFactory factory = JaxWsDynamicClientFactory.newInstance();
ClientImpl client = (ClientImpl) factory.createClient("http://localhost:8080/sso/services/xsip?wsdl");
Map<String, Object> properties = new HashMap<String, Object>();
properties.put(WSHandlerConstants.ACTION, WSHandlerConstants.USERNAME_TOKEN);
properties.put(WSHandlerConstants.USER, username);
properties.put(WSHandlerConstants.PASSWORD_TYPE, WSConstants.PW_DIGEST);
properties.put(WSHandlerConstants.PW_CALLBACK_REF, new CallbackHandler() {
public void handle(Callback[] callbacks) {
for (int i = 0; i < callbacks.length; i++) {
WSPasswordCallback pc = (WSPasswordCallback) callbacks[i];
pc.setPassword(password);
}
}
});
WSS4JOutInterceptor interceptor = new WSS4JOutInterceptor();
interceptor.setProperties(properties);
client.setOutInterceptors(Arrays.asList(interceptor));
wsClient = client;
}
private String readText(String path) throws IOException {
BufferedReader br = null;
try {
br = new BufferedReader(new InputStreamReader(new FileInputStream(path)));
String line = null;
StringBuffer sb = new StringBuffer();
while ((line = br.readLine()) != null) {
sb.append(line);
}
return sb.toString();
} finally {
br.close();
}
}
@Test
public void test001() throws Exception {
String xml = this.readText("D:/data/sso/001.XML");
System.out.println(JSON.toJSONString(wsClient.invoke("pushMaterialMaster", xml)));
}
@Test
public void test002() throws Exception {
String xml = this.readText("D:/data/sso/002.XML");
System.out.println(JSON.toJSONString(wsClient.invoke("pushPriceList", xml)));
}
@Test
public void test005() throws Exception {
String xml = this.readText("D:/data/sso/005.XML");
System.out.println(JSON.toJSONString(wsClient.invoke("pushProFormaInvoice", xml)));
}
@Test
public void test007() throws Exception {
String xml = this.readText("D:/data/sso/007.XML");
System.out.println(JSON.toJSONString(wsClient.invoke("pushShippingNotfirmation", xml)));
}
@Test
public void test008() throws Exception {
String xml1 = this.readText("D:/data/sso/008-1.XML");
String xml2 = this.readText("D:/data/sso/008-2.XML");
System.out.println(JSON.toJSONString(wsClient.invoke("pushSoConfirmQuotation", xml1)));
System.out.println(JSON.toJSONString(wsClient.invoke("pushSoConfirmQuotation", xml2)));
}
@Test
public void test010() throws Exception {
// String xml = this.readText("D:/data/sso/010.XML");
String xml = "文件样例暂时没有";
System.out.println(JSON.toJSONString(wsClient.invoke("pushSoDnDeletion", xml)));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment