I am trying to make an API at WSO2 ESB 4.7.0 to process requests for a RESTful service. It seems that the URL-Mapping feature is not working or is working just like a filter, choosing what to send to the endpoint and what to drop. I have followed this tutorial: http://wso2.com/library/articles/2012/09/get-cup-coffee-wso2-way/. Here is my API configuration:
<api xmlns="http://ws.apache.org/ns/synapse" name="rest" context="/rest">
<resource methods="GET" url-mapping="/">
<inSequence>
<send>
<endpoint>
<http method="get" uri-template="http://myserver/REST"/>
</endpoint>
</send>
</inSequence>
</resource>
<resource methods="GET" url-mapping="/numbers">
<inSequence>
<send>
<endpoint>
<http method="get" uri-template="http://myserver/REST/allnumbers"/>
</endpoint>
</send>
</inSequence>
</resource>
</api>
There are three situations:
This URL works: http://esb/rest
This URL doesn't work: http://esb/rest/numbers
This URL works: http://myserver/REST/allnumbers
In situation 2, I got an Apache Tomcat error:
HTTP Status 404 - Not Found
type Status report
message Not Found
description The requested resource (Not Found) is not available.
Apache Tomcat/6.0.32
But if I try the endpoint address, it works. I thought that the URL-Mapping would route requests for "/numbers" to "/allnumbers". What am I doing wrong?
Solved! I had to remove the REST_URL_POSTFIX before sending to the endpoint:
<api xmlns="http://ws.apache.org/ns/synapse" name="rest" context="/rest">
<resource methods="GET" url-mapping="/">
<inSequence>
<send>
<endpoint>
<http method="get" uri-template="http://myserver/REST"/>
</endpoint>
</send>
</inSequence>
</resource>
<resource methods="GET" url-mapping="/numbers">
<inSequence>
<property name="REST_URL_POSTFIX" scope="axis2" action="remove"/>
<send>
<endpoint>
<http method="get" uri-template="http://myserver/REST/allnumbers"/>
</endpoint>
</send>
</inSequence>
</resource>
</api>
Now, http://esb/rest/numbers works too! :)
Related
proxy config:
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="person"
startOnLoad="true"
statistics="disable"
trace="disable"
transports="http,https">
<target>
<inSequence>
<send>
<endpoint>
<address format="pox" uri="http://localhost:8181/person/"/>
</endpoint>
</send>
<log level="full"/>
</inSequence>
<outSequence>
<log level="full"/>
<property name="messageType" scope="axis2" value="text/xml"/>
<send/>
</outSequence>
</target>
<description/>
</proxy>
Request message can not get response message template:
The template:
This is the console log output:
Can you try with this,
<endpoint name="IdentityDSSserviceEP" template="esbendpoint" uri="http://localhost:8181/person/"/>
Template (Sample template)
<template xmlns="http://ws.apache.org/ns/synapse" name="esbendpoint">
<endpoint name="$name">
<address uri="$uri">
<suspendOnFailure>
<errorCodes>-1</errorCodes>
<progressionFactor>1.0</progressionFactor>
</suspendOnFailure>
<markForSuspension>
<errorCodes>-1</errorCodes>
<retriesBeforeSuspension>0</retriesBeforeSuspension>
<retryDelay>0</retryDelay>
</markForSuspension>
<timeout>
<duration>60000</duration>
<responseAction>fault</responseAction>
</timeout>
</address>
</endpoint>
</template>
I'm using wso2ei 6.0.0 and I have a simple task - send specific xml message via POST to the endpoint.
I have API configured like this:
<api xmlns="http://ws.apache.org/ns/synapse" name="glisTest" context="/glisTest">
<resource methods="GET" uri-template="/{sampleid}">
<inSequence>
<property name="PRESERVE_WS_ADDRESSING" value="false"/>
<payloadFactory media-type="xml">
<format>
<register />
</format>
</payloadFactory>
<log level="full"/>
<property name="messageType" value="application/xml" scope="axis2" type="STRING"/>
<property name="HTTP_METHOD" value="post" scope="axis2" type="STRING"/>
<send>
<endpoint>
<address uri="https://localhost/manager" encoding="UTF-8" format="pox"/>
</endpoint>
</send>
</inSequence>
<outSequence>
<log level="full"/>
<send/>
</outSequence>
</resource>
</api>
But service is expected
<?xml version="1.0" encoding="UTF-8" ?>
to be inserted at the beginning and wso2 do not do it (I just added debug logging for org.apache.synapse.transport.http.wire and I see it simple send
<register/>
As result, it does not recognize message as an xml and returm me error.
Question - how to tell synapse to add this special xml header to the message?
I would like to expose an API (REST) on ESB that traslate the request to a SOAP service.
My Api is definined in this way :
<api xmlns="http://ws.apache.org/ns/synapse" name="__test" context="/mytest">
<resource methods="GET" uri-template="/{symbol}">
<inSequence>
<property name="symbol" expression="get-property('uri.var.symbol')"/>
<payloadFactory media-type="xml">
<format>
<ser:getQuote xmlns:ser="http://services.samples" xmlns:xsd="http://services.samples/xsd">
<ser:request>
<xsd:symbol>$1</xsd:symbol>
</ser:request>
</ser:getQuote>
</format>
<args>
<arg evaluator="xml" expression="get-property('symbol')"/>
</args>
</payloadFactory>
<log level="full"/>
<send>
<endpoint>
<wsdl service="SimpleStockQuoteService" port="SimpleStockQuoteServiceHttpEndpoint"
uri="http://localhost:9000/services/SimpleStockQuoteService?wsdl"/>
</endpoint>
</send>
</inSequence>
</resource>
</api>
But when i invoke the url with http://:8280/mytest/WSO2 I heve this error on console
<soapenv:Reason xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
<soapenv:Text xml:lang="en-US">
The endpoint reference (EPR) for the Operation not found is /services/SimpleStockQuoteService.SimpleStockQuoteServiceHttpEndpoint/WSO2?request= and the WSA Action = null. If this EPR was previously reachable, please contact the server administrator.
</soapenv:Text>
</soapenv:Reason>
Because the esb append the WSO2 part of the request to URL.
How I can solve this ?
Thanks
You can follow this guide for achieving this. Note that the soap action header should be added as follows and endpoint is different.
<header name="Action" value="urn:getQuote"/>
Find the complete solution API below,
<api xmlns="http://ws.apache.org/ns/synapse" name="__test" context="/mytest"><resource methods="GET" uri-template="/{symbol}">
<inSequence>
<property name="symbol" expression="get-property('uri.var.symbol')"/>
<payloadFactory media-type="xml">
<format>
<ser:getQuote xmlns:ser="http://services.samples" xmlns:xsd="http://services.samples/xsd">
<ser:request>
<xsd:symbol>$1</xsd:symbol>
</ser:request>
</ser:getQuote>
</format>
<args>
<arg evaluator="xml" expression="get-property('symbol')"/>
</args>
</payloadFactory>
<property name="REST_URL_POSTFIX" scope="axis2" action="remove"/>
<log level="full"/>
<header name="Action" value="urn:getQuote"/>
<send>
<endpoint>
<address uri="http://localhost:9000/services/SimpleStockQuoteService" format="soap11"/>
</endpoint>
</send>
</inSequence></resource></api>
If you want to use the WSDL url directly, you can achive this using WSO2 API Manager and it can be easily tried in WSO2 API Cloud. There is a similar question here.
Tried to create a non-secure WSO2 proxy service to send message to ActiveMQ JMS queue. The proxy service configuration xml file as listed below,
<?xml version="1.0" encoding="UTF-8"?>
<proxy name="StockQuoteProxy" startOnLoad="true" trace="disable"
transports="http" xmlns="http://ws.apache.org/ns/synapse">
<target>
<inSequence>
<property name="OUT_ONLY" scope="default" type="STRING" value="true"/>
<property name="FORCE_SC_ACCEPTED" scope="axis2" type="STRING" value="true"/>
<send>
<endpoint>
<address trace="disable" uri="jms:/JMSQueueConsumer?transport.jms.ConnectionFactoryJNDIName=QueueConnectionFactory&java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory&java.naming.provider.url=tcp://127.0.0.1:61616&transport.jms.DestinationType=queue"/>
</endpoint>
</send>
</inSequence>
<outSequence/>
<faultSequence/>
I also have followed WSO2 document to enable activeMQ Listener and Sender in axis2.xml.
I have also created a JMSQueueConsumer queue in activeMQ on local host. The activeMQ is
up, tcp 0 0 ::ffff:127.0.0.1:61616 :::* LISTEN
However, when I tried to send message to activeMQ, I got error
[PassThroughMessageProcessor-47] ERROR JMSSender Unable to create a JMSMessageSender for : null
javax.jms.JMSSecurityException: User name [null] or password is invalid.
and activeMQ shows no activity. Where should I configure the user name and password?
In your case you need to set username and password for sender using properties transport.jms.UserName and transport.jms.Password as follows
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="StockQuoteProxy"
transports="http"
statistics="disable"
trace="disable"
startOnLoad="true">
<target>
<inSequence>
<property name="OUT_ONLY" value="true" scope="default" type="STRING"/>
<property name="FORCE_SC_ACCEPTED"
value="true"
scope="axis2"
type="STRING"/>
<send>
<endpoint>
<address uri="jms:/JMSQueueConsumer?transport.jms.ConnectionFactoryJNDIName=QueueConnectionFactory&java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory&java.naming.provider.url=tcp://127.0.0.1:61616&transport.jms.DestinationType=queue&transport.jms.UserName=admin&transport.jms.Password=secret"
trace="disable"/>
</endpoint>
</send>
</inSequence>
<outSequence/>
<faultSequence/>
</target>
<description/>
</proxy>
I need to get a pdf from a request to my WSO2 esb. This is my scenario:
Request:
CMS -- Request ----> wso2 ESB ----> backend
Response:
CMS <--- (PDF) --- wso2 ESB <--- PDF Byte Array --- backend
I think that I need to use something like 'aplication/pdf' but when I try to do it, my ESB throws a java error. The following is my code:
<api xmlns="http://ws.apache.org/ns/synapse" name="test" context="/test">
<resource methods="GET" uri-template="/myService">
<inSequence>
<call>
<endpoint>
<http method="get" uri-template="http://backendService/getPDF""></http>
</endpoint>
</call>
<loopback/>
</inSequence>
<outSequence>
<property name="messageType" value="application/pdf" scope="axis2"/>
<property name="ContentType" value="application/pdf" scope="axis2" type="STRING"></property>
<send/>
</outSequence>
<faultSequence></faultSequence>
</resource>
</api>
Any idea?
--- SOLUTION ---
It was really easy and stupid, but I post my solution to avoid that someone waste time in the future:
<api xmlns="http://ws.apache.org/ns/synapse" name="test" context="/test">
<resource methods="GET" uri-template="/myService">
<inSequence>
<send>
<endpoint>
<http method="get" uri-template="http://backendService/getPDF""></http>
</endpoint>
</send>
</inSequence>
<faultSequence></faultSequence>
</resource>
</api>
With this code I just returns the same request that I do to the server, so I get my PDFs files :D