|
@ -3,12 +3,13 @@ package camel.api7.processor;
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
|
|
|
import org.apache.camel.Exchange;
|
|
|
import org.apache.camel.Processor;
|
|
|
import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory;
|
|
|
import org.apache.cxf.message.MessageContentsList;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
import org.w3c.dom.Document;
|
|
|
import org.xml.sax.InputSource;
|
|
|
|
|
|
import javax.xml.namespace.QName;
|
|
|
import javax.xml.parsers.DocumentBuilder;
|
|
|
import javax.xml.parsers.DocumentBuilderFactory;
|
|
|
import javax.xml.soap.*;
|
|
@ -17,46 +18,20 @@ import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
|
@Component("toWsProcessor")
|
|
|
public class ToWsProcessor {
|
|
|
|
|
|
public SOAPMessage processSOAP(Exchange exchange) {
|
|
|
// Since the Camel-CXF endpoint uses a list to store the parameters
|
|
|
// and bean component uses the bodyAs expression to get the value
|
|
|
// we'll need to deal with the parameters ourself
|
|
|
List list = exchange.getIn().getBody(List.class);
|
|
|
if (list == null) {
|
|
|
System.out.println("Incoming null message detected...");
|
|
|
return createDefaultSoapMessage("null");
|
|
|
}
|
|
|
|
|
|
SOAPMessage soapMessage = null;
|
|
|
try {
|
|
|
if (list.isEmpty()){
|
|
|
soapMessage = (SOAPMessage) list.get(0);
|
|
|
}
|
|
|
SOAPPart sp = soapMessage.getSOAPPart();
|
|
|
SOAPEnvelope se = sp.getEnvelope();
|
|
|
SOAPBody sb = se.getBody();
|
|
|
String requestText = sb.getFirstChild().getNextSibling().getTextContent();
|
|
|
System.out.println(requestText);
|
|
|
return createDefaultSoapMessage(requestText);
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
return createDefaultSoapMessage(e.getClass().getName());
|
|
|
}
|
|
|
public class ToWsProcessor implements Processor {
|
|
|
|
|
|
public void process(Exchange exchange) throws Exception {
|
|
|
MessageContentsList args = exchange.getIn().getBody(MessageContentsList.class);
|
|
|
exchange.getOut().setHeader("api", args.get(0));
|
|
|
exchange.getOut().setHeader("param", args.get(1));
|
|
|
exchange.getOut().setHeader("timestamp", args.get(2));
|
|
|
exchange.getOut().setHeader("v", args.get(3));
|
|
|
exchange.getOut().setHeader("appKey", args.get(4));
|
|
|
exchange.getOut().setHeader("sign", args.get(5));
|
|
|
}
|
|
|
|
|
|
|
|
|
public SOAPMessage test(Exchange exchange) {
|
|
|
// String wsdl = "http://127.0.0.1:8001/esb/ws?wsdl";
|
|
|
// List soapMessage = exchange.getIn().getBody(List.class);
|
|
|
// if (soapMessage == null ) {
|
|
|
// System.out.println("Incoming null message detected...");
|
|
|
// return createDefaultSoapMessage("null");
|
|
|
// }
|
|
|
|
|
|
public SOAPBody responseWs(Exchange exchange) {
|
|
|
try {
|
|
|
// String requestText = requestWs(exchange, wsdl, "test");
|
|
|
XmlMapper xmlMapper = new XmlMapper();
|
|
|
ObjectMapper objectMapper = new ObjectMapper();
|
|
|
Map<String,Object> map = objectMapper.readValue(exchange.getIn().getBody().toString(),Map.class);
|
|
@ -68,7 +43,7 @@ public class ToWsProcessor {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public SOAPMessage plus(Exchange exchange) {
|
|
|
public SOAPBody request(Exchange exchange) {
|
|
|
String wsdl = "http://127.0.0.1:8001/esb/ws?wsdl";
|
|
|
SOAPMessage soapMessage = (SOAPMessage) exchange.getIn().getBody(List.class).get(0);
|
|
|
if (soapMessage == null) {
|
|
@ -111,21 +86,26 @@ public class ToWsProcessor {
|
|
|
* @param requestMessage
|
|
|
* @return
|
|
|
*/
|
|
|
public static SOAPMessage createDefaultSoapMessage(String requestMessage) {
|
|
|
public static SOAPBody createDefaultSoapMessage(String requestMessage) {
|
|
|
try {
|
|
|
SOAPMessage soapMessage = MessageFactory.newInstance().createMessage();
|
|
|
SOAPBody body = soapMessage.getSOAPPart().getEnvelope().getBody();
|
|
|
QName payloadName = new QName("http://gateway.api", "test", "ns1");
|
|
|
SOAPBodyElement payload = body.addBodyElement(payloadName);
|
|
|
SOAPElement message = payload.addChildElement("body");
|
|
|
// QName payloadName = new QName("http://gateway.api", "test", "ns1");
|
|
|
// SOAPBodyElement payload = body.addBodyElement(payloadName);
|
|
|
// SOAPElement message = payload.addChildElement("body");
|
|
|
body.addDocument(parseXMLDocument(requestMessage));
|
|
|
return soapMessage;
|
|
|
return body;
|
|
|
} catch (SOAPException e) {
|
|
|
e.printStackTrace();
|
|
|
throw new RuntimeException(e);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 解析XML字符串
|
|
|
* @param xmlString
|
|
|
* @return
|
|
|
*/
|
|
|
public static Document parseXMLDocument(String xmlString) {
|
|
|
if (xmlString == null) {
|
|
|
throw new IllegalArgumentException();
|