我试图从聚合操作的响应中更改contentType,下面是我的示例代码。
interface MyAggregateInterface {
 RequestResponse:
 op1(typeOp1Request)(typeOp1Response)
}    
outputPort MyAggregatePort {
      Interfaces: MyAggregateInterface
    }
embedded {
      Jolie:
         "MyAggratedCode.ol" in MyAggregatePort
  }
 inputPort MyInputPortHttp {
    Protocol: http {
            .debug= 1;
            .debug.showContent =1;
            .format -> format;
            .contentType -> mime;
             .charset ="UTF-8";
            .default = "default";
            .compression = false
        }
        Location: "socket://localhost:8081"
        Interfaces: DefaultHttpInterface 
        Aggregates: MyAggregatePort
        }我想更改op1的返回格式。
发布于 2019-02-04 21:59:14
我试着回答你的问题
我们需要定义您的op1响应类型
type typeOp1Response:any{
  .format?:string
}或者如果你愿意
type typeOp1Response:undefined我个人更喜欢第一个,这样您就可以在聚合服务中决定mime。
现在您需要添加一个信使会话。
courier MyInputPortHttp {
   [interface MyAggregateInterface( request )( response )]{
   forward( request )( response );
    if (is_defined(response.format)){
         mime = response.format;
         undef(response.format);
      }
    } 这个实现有一个限制,可以返回根节点中的平面数据,另一种方法是使用inputType来定义输出格式。
type typeOp1Request:void{
  .otherParameter1:string
  .format?:string
}然后你的信使
信使MyInputPortHttp {接口MyAggregateInterface(请求)(响应){
   forward( request )( response );
    if (request.format=="json"){
         mime = "application/json"
      };
    if (request.format=="xml"){
         mime = "application/xml"
      };
    } 不确定这是否能回答你的问题
https://stackoverflow.com/questions/54524207
复制相似问题