2017-04-26 2 views
0

Ich beginne gerade mit Cloud-Technologie und ich versuche, ein einfaches Hallo Welt Beispiel zu implementieren. Ich benutze den neuen wso2 Enterprise Integration Server. Ich versuche eine einfache API einzurichten.WSO2EI integriere Hallo Welt api

Ich habe 1 Endpunkt implementiert:

<endpoint xmlns="http://ws.apache.org/ns/synapse"> 
    <address uri="http://192.168.1.100:9191/v1/hello"> 
     <suspendOnFailure> 
     <progressionFactor>1.0</progressionFactor> 
     </suspendOnFailure> 
     <markForSuspension> 
     <retriesBeforeSuspension>0</retriesBeforeSuspension> 
      <retryDelay>0</retryDelay> 
     </markForSuspension> 
    </address> 
</endpoint> 

Ich habe Sequenzen implementiert 2:

<?xml version="1.0" encoding="UTF-8"?> 
<sequence name="HelloWorldIN" xmlns="http://ws.apache.org/ns/synapse"> 
    <send> 
     <endpoint key="gov:/HelloWorld"/> 
    </send> 
</sequence> 

und

<?xml version="1.0" encoding="UTF-8"?> 
<sequence name="HelloWorldOUT" xmlns="http://ws.apache.org/ns/synapse"> 
    <send/> 
</sequence> 

und schließlich die API selbst

<api xmlns="http://ws.apache.org/ns/synapse" name="HelloWorld" context="/helloworld" hostname="192.168.1.100" port="9191"> 
    <resource methods="GET" uri-template="/v1/hello" inSequence="HelloWorldIN" outSequence="HelloWorldOUT"/> 
</api> 

Wenn ich eine GET (http://192.168.1.162:8280/helloworld/v1/hello) Anfrage an diese API, bekomme ich eine 202 akzeptierte Antwort, keine Daten. Jede Hilfe wäre willkommen.

EDIT: Dies ist die komplette Konfiguration:

<?xml version="1.0" encoding="UTF-8"?> 
<definitions xmlns="http://ws.apache.org/ns/synapse"> 
    <registry provider="org.wso2.carbon.mediation.registry.WSO2Registry"> 
     <parameter name="cachableDuration">15000</parameter> 
    </registry> 
    <taskManager provider="org.wso2.carbon.mediation.ntask.NTaskTaskManager"/> 
    <sequence name="HelloWorldOUT"> 
     <send buildmessage="true"/> 
    </sequence> 
    <sequence name="fault"> 
     <!-- Log the message at the full log level with the ERROR_MESSAGE and the ERROR_CODE--> 
     <log level="full"> 
      <property name="MESSAGE" value="Executing default 'fault' sequence"/> 
      <property expression="get-property('ERROR_CODE')" name="ERROR_CODE"/> 
      <property expression="get-property('ERROR_MESSAGE')" name="ERROR_MESSAGE"/> 
      </log> 
     <!-- Drops the messages by default if there is a fault --> 
     <drop/> 
    </sequence> 
    <sequence name="main"> 
     <in> 
      <!-- Log all messages passing through --> 
      <log level="full"/> 
      <!-- ensure that the default configuration only sends if it is one of samples --> 
      <!-- Otherwise Synapse would be an open proxy by default (BAD!)    --> 
      <filter regex="http://localhost:9000.*" source="get-property('To')"> 
       <!-- Send the messages where they have been sent (i.e. implicit "To" EPR) --> 
       <send/> 
      </filter> 
     </in> 
     <out> 
      <send/> 
     </out> 
     <description>The main sequence for the message mediation</description> 
    </sequence> 
    <sequence name="HelloWorldIN"> 
     <send> 
      <endpoint name="gov//HelloWorld"> 
       <address uri="http://192.168.1.100:9191/v1/hello"/> 
      </endpoint> 
     </send> 
    </sequence> 
    <api context="/helloworld" hostname="192.168.1.100" 
    name="HelloWorld" port="9191" statistics="enable" trace="enable"> 
     <resource inSequence="HelloWorldIN" methods="GET" 
     outSequence="HelloWorldOUT" uri-template="*"/> 
    </api> 
    <!-- You can add any flat sequences, endpoints, etc.. to this synapse.xml file if you do 
*not* want to keep the artifacts in several files --> 

Antwort

0

Das erste, was zu tun ist, um die Hauptsequenz zu ändern. Ich habe es in Reihenfolge an meine geroutet:

<?xml version="1.0" encoding="UTF-8"?> 
<sequence name="main" xmlns="http://ws.apache.org/ns/synapse"> 
    <in> 
     <!-- Log all messages passing through --> 
     <log level="full"/> 
     <!-- ensure that the default configuration only sends if it is one of samples --> 
     <!-- Otherwise Synapse would be an open proxy by default (BAD!)    --> 
     <filter regex="http://localhost:9000.*" 
     source="get-property('To')" xmlns:ns="http://org.apache.synapse/xsd"> 
      <then> 
       <!-- Send the messages where they have been sent (i.e. implicit "To" EPR) --> 
       <send/> 
      </then> 
      <else> 
       <log/> 
       <sequence key="gov:/HelloWorldIN"/> 
      </else> 
     </filter> 
    </in> 
    <out> 
     <send/> 
    </out> 
    <description>The main sequence for the message mediation</description> 
</sequence> 

Stellen Sie sicher, dass Ihre API aussagekräftige Namen verwendet. Dies erleichtert die Konfiguration des esb. Wenn Ihr API auf dieselbe Subdomain zugreift, ist kein URL Rewrite Mediator erforderlich. Ich habe den Kontext meiner API geändert, um dies zu erreichen.

<api xmlns="http://ws.apache.org/ns/synapse" name="HelloWorld" context="/hello" hostname="192.168.1.100" port="9191"> 
    <resource methods="GET" inSequence="HelloWorldIN" outSequence="HelloWorldOUT"/> 
</api>