18.12. VMDK 모드에서 iPXE 헤더를 가져오고 설정하는 방법
CloudEvent 는 camel-cxf 엔드포인트에서 Camel exchange를 생성하거나 사용할 때 데이터 형식이 "Java 개체 목록"임을 나타냅니다. Camel이 이 모드에서 메시지 본문을 10.0.0.1s로 노출하지만 camel-cxf는 여전히 읽기 및 쓰기 headers에 대한 액세스를 제공합니다. 그러나 CXF 인터셉터가 처리된 후 헤더 목록에서 대역 내 CHAP 헤더를 제거하므로 대역 외 iPXE 헤더만 generated 모드에서 camel-cxf를 사용할 수 있습니다.
다음 예제에서는 CHAP 헤더를 가져오고 설정하는 방법을 보여줍니다. 하나의 Camel-cxf 끝점에서 다른 endpoint로 전달되는 경로가 있다고 가정합니다. 즉, iPXE 클라이언트
from("cxf:bean:routerRelayEndpointWithInsertion")
.process(new InsertRequestOutHeaderProcessor())
.to("cxf:bean:serviceRelayEndpointWithInsertion")
.process(new InsertResponseOutHeaderProcessor());
iPXE routerRelayEndpointWithInsertion 및 serviceRelayEndpointWithInsertion 은 다음과 같이 정의됩니다.
@Bean
public CxfEndpoint routerRelayEndpointWithInsertion() {
CxfSpringEndpoint cxfEndpoint = new CxfSpringEndpoint();
cxfEndpoint.setServiceClass(org.apache.camel.component.cxf.soap.headers.HeaderTester.class);
cxfEndpoint.setAddress("/CxfMessageHeadersRelayTest/HeaderService/routerRelayEndpointWithInsertion");
cxfEndpoint.setWsdlURL("soap_header.wsdl");
cxfEndpoint.setEndpointNameAsQName(
QName.valueOf("{http://apache.org/camel/component/cxf/soap/headers}SoapPortRelayWithInsertion"));
cxfEndpoint.setServiceNameAsQName(SERVICENAME);
cxfEndpoint.getFeatures().add(new LoggingFeature());
return cxfEndpoint;
}
@Bean
public CxfEndpoint serviceRelayEndpointWithInsertion() {
CxfSpringEndpoint cxfEndpoint = new CxfSpringEndpoint();
cxfEndpoint.setServiceClass(org.apache.camel.component.cxf.soap.headers.HeaderTester.class);
cxfEndpoint.setAddress("http://localhost:" + port + "/services/CxfMessageHeadersRelayTest/HeaderService/routerRelayEndpointWithInsertionBackend");
cxfEndpoint.setWsdlURL("soap_header.wsdl");
cxfEndpoint.setEndpointNameAsQName(
QName.valueOf("{http://apache.org/camel/component/cxf/soap/headers}SoapPortRelayWithInsertion"));
cxfEndpoint.setServiceNameAsQName(SERVICENAME);
cxfEndpoint.getFeatures().add(new LoggingFeature());
return cxfEndpoint;
}
CloudEvent 헤더는 Camel Message 헤더로 또는 에서 전파됩니다. Camel 메시지 헤더 이름은 CXF(org.apache.cxf.headers.Header.HEADER_LIST)에 정의된 상수인 "org.apache.cxf.headers.Header.list"입니다. 헤더 값은 CXF SoapHeader 오브젝트 목록(org.apache.cxf.binding.soap.SoapHeader)입니다. 다음 스니펫은 InsertResponseOutHeaderProcessor(응답 메시지에 새 iPXE 헤더를 삽입함)입니다. InsertResponseOutHeaderProcessor 및 InsertRequestOutHeaderProcessor 모두에서 iPXE 헤더에 액세스하는 방법은 실제로 동일합니다. 두 프로세서의 유일한 차이점은 삽입된 CHAP 헤더의 방향을 설정하는 것입니다.
CxfMessageHeadersRelayTest 에서 InsertResponseOutHeaderProcessor 예제를 찾을 수 있습니다.
public static class InsertResponseOutHeaderProcessor implements Processor {
public void process(Exchange exchange) throws Exception {
List<SoapHeader> soapHeaders = CastUtils.cast((List<?>)exchange.getIn().getHeader(Header.HEADER_LIST));
// Insert a new header
String xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?><outofbandHeader "
+ "xmlns=\"http://cxf.apache.org/outofband/Header\" hdrAttribute=\"testHdrAttribute\" "
+ "xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" soap:mustUnderstand=\"1\">"
+ "<name>New_testOobHeader</name><value>New_testOobHeaderValue</value></outofbandHeader>";
SoapHeader newHeader = new SoapHeader(soapHeaders.get(0).getName(),
DOMUtils.readXml(new StringReader(xml)).getDocumentElement());
// make sure direction is OUT since it is a response message.
newHeader.setDirection(Direction.DIRECTION_OUT);
//newHeader.setMustUnderstand(false);
soapHeaders.add(newHeader);
}
}