Код: Выделить всё
private String transformSoapToRest(String soapRequest) throws ParserConfigurationException, IOException, SAXException {
soapRequest = soapRequest.trim();
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
DocumentBuilder builder = factory.newDocumentBuilder();
Document document = builder.parse(new InputSource(new StringReader(soapRequest)));
String requestData = document.getElementsByTagName("arg0").item(0).getTextContent();
return "{ \"requestData\": \"" + requestData + "\" }";
}
private String transformRestToSoap(String restResponse) {
restResponse = restResponse.trim();
String soapResponse = "" +
"" +
"" +
"" + restResponse + "" +
"" +
"" +
"";
return soapResponse;
}
Код: Выделить всё
from("cxf:bean:soapCxfEndpoint")
.log("Received SOAP request: ${body}")
.process(exchange -> {
String soapRequest = exchange.getIn().getBody(String.class).trim();
exchange.getIn().setBody(soapRequest);
String restResponse = transformSoapToRest(soapRequest);
log.info("Transformed rest request: " + soapRequest);
exchange.getIn().setBody(restResponse.trim());
})
.log("Transformed to REST request: ${body}")
.to("http://localhost:8080/rest/api")
.log("Received REST response: ${body}")
.process(exchange -> {
String restRequest = exchange.getIn().getBody(String.class).trim();
String soapResponse = transformRestToSoap(restRequest);
log.info("Transformed rest request: " + restRequest);
exchange.getIn().setBody(soapResponse.trim());
})
.log("Transformed to SOAP response: ${body}")
.setHeader(Exchange.CONTENT_TYPE, constant("text/xml"))
.setHeader(Exchange.HTTP_METHOD, constant("POST"))
.to("direct:log");
from("direct:log")
.log("Log entry: ${body}");
}
Код: Выделить всё
Sample Request
Код: Выделить всё
2024-07-17T18:24:05.447+05:30 DEBUG 21736 --- [project] [nio-8080-exec-1] o.a.c.p.e.DefaultErrorHandler : Failed delivery for (MessageId: DEA1ACD506C7924-0000000000000000 on ExchangeId: DEA1ACD506C7924-0000000000000000). On delivery attempt: 0 caught: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1; Content is not allowed in prolog.
2024-07-17T18:24:05.449+05:30 INFO 21736 --- [project] [nio-8080-exec-1] route1 : Exception occurred: Content is not allowed in prolog.
Даже использовал такие инструменты, как текстовый редактор, который может отображать непечатаемые символы, решения все равно нет. .
Теперь я не понимаю, в чем может быть проблема, пожалуйста, помогите.
Подробнее здесь: https://stackoverflow.com/questions/787 ... and-apache