0

我在 WSO2 ESB 490 中创建自定义代理服务:

<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
       name="write_2_greg"
       transports="https,http"
       statistics="disable"
       trace="enable"
       startOnLoad="true">
   <target>
      <inSequence>
         <payloadFactory media-type="json">
            <format>
		{"name":"2rest_test","context":"/ressttest2","type":"restservice","version":"1.0.0"}
	</format>
            <args/>
         </payloadFactory>
         <property name="DISABLE_CHUNKING"
                   value="true"
                   scope="axis2"
                   type="STRING"/>
         <property name="Accept"
                   expression="$trp:Accept"
                   scope="default"
                   type="STRING"/>
         <property name="messageType"
                   value="application/json"
                   scope="axis2"
                   type="STRING"/>
         <property name="Authorization"
                   expression="fn:concat('Basic ',base64Encode('admin:admin'))"
                   scope="transport"
                   type="STRING"/>
         <call>
            <endpoint>
               <http trace="enable"
                     method="POST"
                     uri-template="https://localhost:9443/governance/restservices"/>
            </endpoint>
         </call>
         <property xmlns:ns="http://org.apache.synapse/xsd"
                   name="__Status"
                   expression="$axis2:HTTP_SC"
                   scope="default"
                   type="STRING"/>
         <enrich>
            <source type="body" clone="true"/>
            <target type="property" property="res_body"/>
         </enrich>
         <log level="custom">
            <property name="__Status" expression="$ctx:__Status"/>
            <property name="res_body--" expression="get-property('res_body')"/>
         </log>
      </inSequence>
      <outSequence/>
      <faultSequence/>
   </target>
   <description/>
</proxy>

这个简单的代理只是为 GREG 创建新的 restservice,它使用 GREG REST API。但是当我运行这个代理服务时,GREG 响应 500 状态码,并检查 GREG 日志,似乎是 Jackson 错误:

Caused by: org.codehaus.jackson.map.JsonMappingException: Can not construct instance of org.wso2.carbon.governance.api.generic.dataobjects.GenericArtifact, problem: abstract types can only be instantiated with additional type information
 at [Source: org.apache.cxf.transport.http.AbstractHTTPDestination$1@4d4489c7; line: 1, column: 1]
	at org.codehaus.jackson.map.JsonMappingException.from(JsonMappingException.java:163)
	at org.codehaus.jackson.map.deser.StdDeserializationContext.instantiationException(StdDeserializationContext.java:212)
	at org.codehaus.jackson.map.deser.AbstractDeserializer.deserialize(AbstractDeserializer.java:97)
	at org.codehaus.jackson.map.ObjectMapper._readValue(ObjectMapper.java:2376)
	at org.codehaus.jackson.map.ObjectMapper.readValue(ObjectMapper.java:1166)
	at org.codehaus.jackson.jaxrs.JacksonJsonProvider.readFrom(JacksonJsonProvider.java:410)
	at org.apache.cxf.jaxrs.utils.JAXRSUtils.readFromMessageBodyReader(JAXRSUtils.java:1262)
	at org.apache.cxf.jaxrs.utils.JAXRSUtils.readFromMessageBody(JAXRSUtils.java:1209)
	at org.apache.cxf.jaxrs.utils.JAXRSUtils.processParameter(JAXRSUtils.java:757)
	at org.apache.cxf.jaxrs.utils.JAXRSUtils.processParameters(JAXRSUtils.java:716)
	at org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor.processRequest(JAXRSInInterceptor.java:253)
	... 40 more

但我可以创建“高级休息客户端应用程序”(Chrome插件)使用的新休息服务 在此处输入图像描述

顺便说一句,我通过 ESB 490 、 GREG 510 和 GREG 520 对此进行了测试。我怎样才能实现 ESB 使用的这个?

4

1 回答 1

0

在研究了碳治理源代码后,我发现“org.wso2.carbon.governance.rest.api.internal.GenericArtifactMessageBodyReader”类中的方法“isReadable”

@Override
public boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
    if (GenericArtifact.class.getName().equals(type.getName()) || GovernanceArtifact.class.getName().
            equals(type.getName())) {
        if (MediaType.APPLICATION_JSON_TYPE.equals(mediaType) || MediaType.APPLICATION_XML_TYPE.equals(mediaType)) {
            return true;
        }
    }
    return false;
}

将 json 发送到请求时,会调用此方法来确定 MediaType。MediaType 接受

application/json

但是我写的代理发送了内容类型

application/json; charset=UTF-8

它们不一样,因此该方法返回 false,并且不处理 json 帖子。

我尝试像这样重置 ESB 代理内容类型:

<property name="messageType" value="application/json" scope="axis2" type="STRING"/>
<property name="ContentType" scope="default" type="STRING" value="application/json"/>

但内容类型仍然是“application/json;charset=UTF-8”

我认为这是原因,但我们该如何解决呢?

于 2016-03-29T08:26:40.867 回答