Hi

@Brad -
I don't think it is the Processor that is sent to the Endpoint but it is
the Exchange itself. I tried the other approach you suggested and below is
the code that am using

  String uuid = UUID.randomUUID().toString().replace("-", "");
  System.out.println("uuid = " + uuid);
  GenerateTestHeaders headerGenerator = new GenerateTestHeaders();
  Map outboundHeaderMap = headerGenerator.getOutboundHeaderMap();
  outboundHeaderMap.put(Exchange.AUTHENTICATION, subject);
  outboundHeaderMap.put("CamelCxfRsUsingHttpAPI", Boolean.TRUE);
  outboundHeaderMap.put("CamelHttpMethod", "POST");
  outboundHeaderMap.put("operationName", "login");
  outboundHeaderMap.put(Exchange.CONTENT_TYPE,"application/json");
  outboundHeaderMap.put("CamelAcceptContentType", "application/json");


  SecurityContextHolder.getContext().setAuthentication(authenticated);

  final CamelContext camelContext = producerTemplate.getCamelContext();
  final Endpoint coreEndPoint =
camelContext.getEndpoint("http4://localhost:9001/core/login");
  producerTemplate.setDefaultEndpoint(coreEndPoint);
  final String s = new ObjectMapper().writeValueAsString(bo);
  producerTemplate.sendBodyAndHeaders(coreEndPoint, s,outboundHeaderMap);


When i receive the exchange in my processor am getting both my
Exchange.AUTHENTICATION header and SecurityContext Null.

I am not able to retrieve and test the Security role because of which
everything else fails down the stream.

IS there anything else am missing?.


Regards,

Aravind



On Mon, Oct 24, 2016 at 4:32 PM, Brad Johnson <[email protected]>
wrote:

> In addition to trying the requestBodyHeader (or whatever the request name
> is) have you tried looking the results of the Exchange you get back by
> calling getException?
>
> On Mon, Oct 24, 2016 at 3:25 PM, Brad Johnson <
> [email protected]>
> wrote:
>
> > Are you  sending a Processor across?  I've really no idea if that would
> > work or not.  It's an object so I suppose if you cast the object on the
> > other side you'd end up with the Processor back(?)
> >
> >
> > Have you tried on of the methods like producerTemplate.request(
> endpointURI,body,
> > Map<String,String>) where the map contains the headers?
> >
> > On Mon, Oct 24, 2016 at 9:45 AM, aravind r <
> [email protected]>
> > wrote:
> >
> >> Hi All,
> >>
> >> Any help is appreciated as i am trying to solve this for 2 days now.
> >>
> >> Trying to unit test a CXF end point secured with Spring Authentication.
> I
> >> tried passing in as below the Authentication header however when it
> >> reaches
> >> my CXF Endpoint and down to route. The header is missing.
> >>
> >> I tried a lot of combinations and i did read some where that it doesn't
> >> pass it via CXF endpoint. Is this a bug?, that was a post from 2012
> >> though.
> >> any workarounds?.
> >>
> >> How should i test my whole integration flow?.
> >>
> >>
> >> Exchange responseExchange = producerTemplate.request("cxfrs://
> >> http://localhost:9001/";, new Processor() {
> >>
> >>
> >>     @Override
> >>     public void process(Exchange exchange) throws Exception {
> >>
> >>
> >>         exchange.setPattern(ExchangePattern.InOut);
> >>         Message inMessage = exchange.getIn();
> >>         inMessage.setHeader("CamelCxfRsUsingHttpAPI", Boolean.TRUE);
> >>         inMessage.setHeader("CamelHttpMethod", "POST");
> >>         inMessage.setHeader("operationName", "getAccounts");
> >>         inMessage.setHeader(Exchange.CONTENT_TYPE,"application/json");
> >>         inMessage.setHeader("CamelAuthentication",subject);
> >>         inMessage.setHeader("CamelHttpPath", "/v1/core/getAccounts");
> >>         inMessage.setBody( new ObjectMapper().writeValueAsString(bo));
> >>
> >>
> >> *exchange.getIn().setHeader(Exchange.AUTHENTICATION,subject);*
> >>     }
> >> });
> >>
> >> Regards,
> >> Aravind
> >>
> >
> >
>

Reply via email to