简体   繁体   中英

How to set additional authentication properties in apache camel DSL or inside the camel Processor?

Here I am trying to convert Json data to CSV format and finally send this file to Ofbiz server api but the api endpoint require some authentication content when I send parameter in URL I got the output below.

{"_ERROR_MESSAGE_":"Error calling event: org.apache.ofbiz.webapp.event.EventHandlerException: Found URL parameter [configId] passed to secure (https) request-map with uri [uploadAndImportFileFromCSVFile] with an event that calls service [uploadAndImportFile]; this is not allowed for security reasons! The data should be encrypted by making it part of the request body (a form field) instead of the request URL. Moreover it would be kind if you could create a Jira sub-task of https://issues.apache.org/jira/browse/OFBIZ-2330 (check before if a sub-task for this error does not exist). If you are not sure how to create a Jira issue please have a look before at https://cwiki.apache.org/confluence/display/OFBIZ/OFBiz+Contributors+Best+Practices Thank you in advance for your help.","sessionId":" someId .jvm1","removePathAlias":false,"loggedIn":true,"USERNAME":"__","_LOGIN_PASSED_":"TRUE","webSiteId":"API"}

After that I used MultipartBuilder to send request below.

exchange.getIn().setHeader("bearer",token);         
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
File file =new File("//home/r2/Desktop/ofBizFile/orderFile.csv");
builder.addPart("configId",new StringBody("CON_ID"));
builder.addPart("fileTypeEnumId",new StringBody("CSV_FILE"));
builder.addPart("_uploadedFile_contentType",new StringBody("text/csv"));
builder.addPart("uploadedFile",new FileBody(file));
exchange.getIn().setBody(builder.build());

I also tried something like this.

exchange.setProperty(Exchange.CHARSET_NAME, "ISO-8859-1");
exchange.getIn().setHeader(Exchange.HTTP_QUERY,"USERNAME=abc&PASSWORD=bc69");
exchange.getIn().setBody("configId=CON_ID&fileTypeEnumId=CSV_FILE");

Here is my camel route

//Route 1  
 from("couchdb:http://localhost:5984/order")
        .process(new JsonToCsvProcessor())
         //Storing file into local directory 
        .to("file:/home/r2/Desktop/ofBizFile?fileExist=append&fileName=order-${date:now:yyyyMMdd}.csv");

     .to("direct:jsonToCsv");
//Route 2
   from("direct:jsonToCsv")
    .setHeader(Exchange.HTTP_QUERY,constant("USERNAME=__&PASSWORD=__"))
    //For get token
    .to("https4://SomeAddress.com/centerAPI/getAuthenticationToken")
    //Get the token and set required parameter for route 3
    .process(new ProcessorGetToken())
    .to("direct:hold");       
//Route 3
   from("direct:hold")
   .setHeader(Exchange.HTTP_QUERY,constant("USERNAME=__&PASSWORD=__"))
   .to("https4://SomeAddress.com/centerAPI/uploadAndImportFileFromCSVFile?throwExceptionOnFailure=false")
   //How I know the file is submited successfuly ?
   .to("stream:out").end();

So the problem is how I can send data inside the body in Route2 ProcessorGetToken for next Route3 ?

I'll give a shot into the dark here. Reading your error message:

The data should be encrypted by making it part of the request body (a form field) instead of the request URL

Don't you have a documentation about this integration? I think you need more clarification about this process and what's need to encrypt your data before sending it.

Also, try to set the Exchange.HTTP_METHOD to POST into your route, like this:

exchange.setProperty(Exchange.CHARSET_NAME, "ISO-8859-1");
exchange.getIn().setHeader(Exchange.HTTP_METHOD, "POST");
exchange.getIn().setHeader(Exchange.HTTP_QUERY,"USERNAME=abc&PASSWORD=bc69");
exchange.getIn().setBody("configId=CON_ID&fileTypeEnumId=CSV_FILE");

Take a look into this unit test to see more examples sending data over HTTP . There's also many other tests there.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM