添加runner ,启动时发送获取日航班计划的消息
This commit is contained in:
@@ -6,23 +6,59 @@ import java.util.Map;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParseException;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.JsonMappingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.ObjectWriter;
|
||||
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
|
||||
import com.gzzn.omms.msgexchangeapi.exception.ExchangeServiceException;
|
||||
|
||||
@Service
|
||||
public class ExchangeServiceImpl implements IExchangeService {
|
||||
|
||||
@Override
|
||||
public String xmlToJson(String xml) throws JsonParseException, JsonMappingException, IOException {
|
||||
|
||||
ObjectMapper xmlMapper = new XmlMapper();
|
||||
Map map = xmlMapper.readValue(xml, Map.class);
|
||||
|
||||
ObjectMapper jsonMapper = new ObjectMapper();
|
||||
String json = jsonMapper.writeValueAsString(map);
|
||||
|
||||
return json;
|
||||
}
|
||||
public String xmlToJson(String xml) throws ExchangeServiceException {
|
||||
try {
|
||||
Map map;
|
||||
ObjectMapper xmlMapper = new XmlMapper();
|
||||
map = xmlMapper.readValue(xml, Map.class);
|
||||
|
||||
ObjectMapper jsonMapper = new ObjectMapper();
|
||||
String json = jsonMapper.writeValueAsString(map);
|
||||
return json;
|
||||
} catch (JsonParseException e) {
|
||||
throw new ExchangeServiceException(e.getMessage(),e);
|
||||
} catch (JsonMappingException e) {
|
||||
throw new ExchangeServiceException(e.getMessage(),e);
|
||||
} catch (IOException e) {
|
||||
throw new ExchangeServiceException(e.getMessage(),e);
|
||||
}
|
||||
} //end function
|
||||
|
||||
@Override
|
||||
public <T> T xmlstrToObject(String xml,Class<T> valueType) throws ExchangeServiceException {
|
||||
try {
|
||||
ObjectMapper xmlMapper = new XmlMapper();
|
||||
return xmlMapper.readValue(xml,valueType);
|
||||
} catch (JsonParseException e) {
|
||||
throw new ExchangeServiceException(e.getMessage(),e);
|
||||
} catch (JsonMappingException e) {
|
||||
throw new ExchangeServiceException(e.getMessage(),e);
|
||||
} catch (IOException e) {
|
||||
throw new ExchangeServiceException(e.getMessage(),e);
|
||||
}
|
||||
} //end function
|
||||
|
||||
@Override
|
||||
public String objectToXmlstr(Object object) throws ExchangeServiceException {
|
||||
|
||||
try {
|
||||
String xml;
|
||||
ObjectMapper xmlMapper = new XmlMapper();
|
||||
xml = xmlMapper.writeValueAsString(object);
|
||||
return xml;
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new ExchangeServiceException(e.getMessage(),e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
package com.gzzn.omms.msgexchangeapi.service;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParseException;
|
||||
import com.fasterxml.jackson.databind.JsonMappingException;
|
||||
import com.gzzn.omms.msgexchangeapi.exception.ExchangeServiceException;
|
||||
|
||||
/**
|
||||
* 消息转换服务
|
||||
@@ -11,6 +8,7 @@ import com.fasterxml.jackson.databind.JsonMappingException;
|
||||
*
|
||||
*/
|
||||
public interface IExchangeService {
|
||||
|
||||
public String xmlToJson(String xml)throws JsonParseException, JsonMappingException, IOException;
|
||||
public String xmlToJson(String xml) throws ExchangeServiceException;
|
||||
public <T> T xmlstrToObject(String xml,Class<T> valueType) throws ExchangeServiceException;
|
||||
public String objectToXmlstr(Object object) throws ExchangeServiceException;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user