Commit 117c4d3a authored by Quxl's avatar Quxl

x

parent 236739a0
......@@ -19,7 +19,6 @@ import org.springframework.stereotype.Component;
import com.alibaba.fastjson.JSONObject;
import com.egolm.sso.clients.ServiceFactory;
import com.egolm.sso.clients.ServiceFactory.PasswordType;
import com.egolm.sso.config.XRException;
import com.egolm.sso.services.CommonService;
import com.egolm.sso.services.TraceService;
......@@ -59,6 +58,9 @@ public class SI004INVENTORYSyncOutServiceTask {
@Value("${xmlRoot}")
private String xmlRoot;
@Autowired
private ServiceFactory factory;
@Scheduled(cron="${cronSi004}")
public void execute() throws MalformedURLException {
this.runTask();
......@@ -70,7 +72,7 @@ public class SI004INVENTORYSyncOutServiceTask {
File folder = jarFile.getParentFile();
String absolutePath = folder.getAbsolutePath();
String wsdlLocation = "file:///" + absolutePath + "/" + WSDLPATH + "/SI_004_INVENTORY_SyncOutService.wsdl";
SI004INVENTORYSyncOut service = ServiceFactory.create(SI004INVENTORYSyncOut.class, wsdlLocation, SI004INVENTORYSyncOutService.SERVICE, SI004INVENTORYSyncOutService.HTTPPort, username, password, PasswordType.PasswordText);
SI004INVENTORYSyncOut service = factory.create(SI004INVENTORYSyncOut.class, wsdlLocation, SI004INVENTORYSyncOutService.SERVICE, SI004INVENTORYSyncOutService.HTTPPort);
this.sendData(service);
}
......
......@@ -18,7 +18,6 @@ import org.springframework.stereotype.Component;
import com.alibaba.fastjson.JSONObject;
import com.egolm.sso.clients.ServiceFactory;
import com.egolm.sso.clients.ServiceFactory.PasswordType;
import com.egolm.sso.config.XRException;
import com.egolm.sso.services.CommonService;
import com.egolm.sso.services.TraceService;
......@@ -58,6 +57,9 @@ public class SI011ACTUALSALESSyncOutServiceTask {
@Value("${xmlRoot}")
private String xmlRoot;
@Autowired
private ServiceFactory factory;
@Scheduled(cron="${cronSi011}")
public void execute() {
this.runTask();
......@@ -69,7 +71,7 @@ public class SI011ACTUALSALESSyncOutServiceTask {
File folder = jarFile.getParentFile();
String absolutePath = folder.getAbsolutePath();
String wsdlLocation = "file:///" + absolutePath + "/" + WSDLPATH + "/SI_011_ACTUAL_SALES_SyncOutService.wsdl";
SI011ACTUALSALESSyncOut service = ServiceFactory.create(SI011ACTUALSALESSyncOut.class, wsdlLocation, SI011ACTUALSALESSyncOutService.SERVICE, SI011ACTUALSALESSyncOutService.HTTPPort, username, password, PasswordType.PasswordText);
SI011ACTUALSALESSyncOut service = factory.create(SI011ACTUALSALESSyncOut.class, wsdlLocation, SI011ACTUALSALESSyncOutService.SERVICE, SI011ACTUALSALESSyncOutService.HTTPPort);
this.sendData(service);
}
......
......@@ -14,33 +14,46 @@ import org.apache.cxf.frontend.ClientProxy;
import org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor;
import org.apache.ws.security.handler.WSHandlerConstants;
import org.apache.wss4j.common.ext.WSPasswordCallback;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import com.egolm.sso.config.XRException;
@Component
public class ServiceFactory {
public static <T> T create(Class<T> requiredType, String wsdlLocation, QName serviceQName, QName portQName, String username, String password, PasswordType passwordType) {
@Value("${schneider.username}")
private String username;
@Value("${schneider.password}")
private String password;
public <T> T create(Class<T> requiredType, String wsdlLocation, QName serviceQName, QName portQName) {
assert requiredType != null : "WebService requiredType cannot be null";
assert wsdlLocation != null : "WebService wsdlLocation cannot be null";
assert serviceQName != null : "WebService serviceQName cannot be null";
try {
URL WSDL_URL = new URL(wsdlLocation);
Service dyService = Service.create(WSDL_URL, serviceQName);
T service = dyService.getPort(portQName, requiredType);
ClientProxy.getClient(service).getOutInterceptors().add(getWSS4JOutInterceptor(username, password, passwordType));
T service = portQName == null ? dyService.getPort(requiredType) : dyService.getPort(portQName, requiredType);
ClientProxy.getClient(service).getOutInterceptors().add(getWSS4JOutInterceptor());
return service;
} catch (MalformedURLException e) {
throw new XRException(e);
}
}
private static WSS4JOutInterceptor wss4JOutInterceptor = null;
private WSS4JOutInterceptor wss4JOutInterceptor = null;
public static WSS4JOutInterceptor getWSS4JOutInterceptor(String username, String password, PasswordType passwordType) {
public WSS4JOutInterceptor getWSS4JOutInterceptor() {
if(wss4JOutInterceptor == null) {
synchronized (wss4JOutInterceptor) {
if(wss4JOutInterceptor == null) {
Map<String, Object> pro = new HashMap<String, Object>();
pro.put(WSHandlerConstants.ACTION, WSHandlerConstants.USERNAME_TOKEN);
pro.put(WSHandlerConstants.USER, username);
pro.put(WSHandlerConstants.PASSWORD_TYPE, passwordType == null ? PasswordType.PasswordText.name() : passwordType.name());
pro.put(WSHandlerConstants.PASSWORD_TYPE, PasswordType.PasswordText.name());
pro.put(WSHandlerConstants.PW_CALLBACK_REF, new CallbackHandler() {
public void handle(Callback[] callbacks) {
for (int i = 0; i < callbacks.length; i++) {
......
......@@ -17,7 +17,6 @@ import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import com.egolm.sso.clients.ServiceFactory;
import com.egolm.sso.clients.ServiceFactory.PasswordType;
import com.egolm.sso.clients.Z_MI_SD_009_SO_CREATION.ZDTSD009SOCREATION.Header;
import com.egolm.sso.clients.Z_MI_SD_009_SO_CREATION.ZDTSD009SOCREATION.ITEM;
import com.egolm.sso.config.XRException;
......@@ -26,9 +25,9 @@ import com.egolm.sso.services.TraceService;
import com.egolm.sso.util.DateUtil;
import com.egolm.sso.util.FileUtil;
import com.egolm.sso.util.SqlUtil;
import com.egolm.sso.util.SqlUtil.Page;
import com.egolm.sso.util.ThrowableUtil;
import com.egolm.sso.util.XMLUtil;
import com.egolm.sso.util.SqlUtil.Page;
import com.google.gson.Gson;
@Component
......@@ -56,6 +55,9 @@ public class ZMISD009SOCREATIONServiceTask {
@Value("${xmlRoot}")
private String xmlRoot;
@Autowired
private ServiceFactory factory;
@Scheduled(cron="${cronSap009}")
public void execute() {
......@@ -68,7 +70,7 @@ public class ZMISD009SOCREATIONServiceTask {
File folder = jarFile.getParentFile();
String absolutePath = folder.getAbsolutePath();
String wsdlLocation = "file:///" + absolutePath + "/" + WSDLPATH + "/Z_MI_SD_009_SO_CREATION.wsdl";
ZMISD009SOCREATION service = ServiceFactory.create(ZMISD009SOCREATION.class, wsdlLocation, ZMISD009SOCREATIONService.SERVICE, ZMISD009SOCREATIONService.ZMISD009SOCREATIONPort, username, password, PasswordType.PasswordText);
ZMISD009SOCREATION service = factory.create(ZMISD009SOCREATION.class, wsdlLocation, ZMISD009SOCREATIONService.SERVICE, ZMISD009SOCREATIONService.ZMISD009SOCREATIONPort);
this.sendData(service);
}
......
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