0

I create custom proxy service in 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>

This simple proxy just create new restservice to GREG, it uses the GREG REST API. But when I run this proxy service, the GREG response 500 status code, and check GREG log, it seems Jackson error:

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

But I can create new restservice used by "Advanced Rest Client Application"(Chrome plugin) enter image description here

BTW, I test this by ESB 490 , GREG 510 and GREG 520 . How can I achive this used by ESB?

Community
  • 1
  • 1
yeahliu
  • 154
  • 1
  • 8

1 Answers1

0

After research the carbon-governace source code, I found that the method "isReadable" in class "org.wso2.carbon.governance.rest.api.internal.GenericArtifactMessageBodyReader"

@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;
}

When post the json to request, this method is called to determine the MediaType. The MediaType accept

application/json

But the proxy I wrote it sent the content-type

application/json; charset=UTF-8

They aren't the same, so the method return false, and not process the json post.

I try to reset the ESB proxy content type like this:

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

But the content-type still "application/json;charset=UTF-8"

I think this is the reson, but how can we fix it ?

yeahliu
  • 154
  • 1
  • 8
  • I change the method "isReadable" return true whatever mediatype it received, compile the code and generate governance.war, replace the origin war, and can create asset now. – yeahliu Mar 29 '16 at 08:32