首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >设置处理聚合的HTTP输出标头参数

设置处理聚合的HTTP输出标头参数
EN

Stack Overflow用户
提问于 2019-02-04 20:57:26
回答 2查看 52关注 0票数 2

我试图从聚合操作的响应中更改contentType,下面是我的示例代码。

代码语言:javascript
运行
复制
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的返回格式。

EN

Stack Overflow用户

回答已采纳

发布于 2019-02-04 21:59:14

我试着回答你的问题

我们需要定义您的op1响应类型

代码语言:javascript
运行
复制
type typeOp1Response:any{
  .format?:string
}

或者如果你愿意

代码语言:javascript
运行
复制
type typeOp1Response:undefined

我个人更喜欢第一个,这样您就可以在聚合服务中决定mime。

现在您需要添加一个信使会话。

代码语言:javascript
运行
复制
courier MyInputPortHttp {
   [interface MyAggregateInterface( request )( response )]{

   forward( request )( response );
    if (is_defined(response.format)){
         mime = response.format;
         undef(response.format);
      }
    } 

这个实现有一个限制,可以返回根节点中的平面数据,另一种方法是使用inputType来定义输出格式。

代码语言:javascript
运行
复制
type typeOp1Request:void{
  .otherParameter1:string
  .format?:string
}

然后你的信使

信使MyInputPortHttp {接口MyAggregateInterface(请求)(响应){

代码语言:javascript
运行
复制
   forward( request )( response );
    if (request.format=="json"){
         mime = "application/json"
      };
    if (request.format=="xml"){
         mime = "application/xml"
      };

    } 

不确定这是否能回答你的问题

票数 2
EN
查看全部 2 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54524207

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档