org.apache.axis2.AxisFault: Transport error: 415 Error: Unsupported Media Type - rest

I have created a proxy service in wso2, while try accessing the proxy service it shows error as Unsupported Media Type, but I have set Content-Type: application/xml .payload is in xml format, so am setting it to application/xml in the source view ,still am getting the same error, Please help me to resolve this issue
**Proxy Service:**
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="test"
transports="http,https"
statistics="enable"
trace="enable"
startOnLoad="true">
<target>
<outSequence>
<property name="Content-Type" value="application/xml"/>
<send/>
</outSequence>
<endpoint>
<address uri="http://192.35.72.369:8080/ESB_Services/DRAM/service/CreateCustomer"/>
</endpoint>
</target>
<description/>
</proxy>
**Payload:**
<customer>
<name>admin</name>
<email>admin#gmail.com</email>
<mobile_number>9904324234</mobile_number>
<address>Bangalore</address>
<zipcode>574515</zipcode>
</customer>
**ERROR:**
<TryitProxyError h:status="SOAP envelope error" xmlns:h="http://wso2.org/ns/TryitProxy">org.apache.axis2.AxisFault: Transport error: 415 Error: Unsupported Media Type</TryitProxyError>

When you need to choose the appropriate messageFormatter, used to format a message going out from the ESB, you use the property 'messageType' : <property name="messageType" value="application/xml" scope="axis2" />

Related

WSO2 EI 6.5.0 Send email with attachment

I have a need to send pdf/png/jpeg files to emails via WSO2 EI 6.5.0
I have a proxy:
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="EmailService"
startOnLoad="true"
statistics="disable"
trace="disable"
transports="http,https">
<target>
<inSequence>
<log level="custom">
<property name="[EmailService] Initialize" value="SendMailSequence"/>
</log>
<property name="Subject" scope="transport" value="WSO2 EI Testing"/>
<property name="transport.mail.bodyWhenAttached"
scope="axis2"
value="This text will appear in body"/>
<property name="enableMTOM" scope="axis2" type="STRING" value="true"/>
<log level="custom">
<property expression="/" name="[EmailService] Before Send"/>
</log>
<property name="FORCE_SC_ACCEPTED" scope="axis2" value="true"/>
<property name="OUT_ONLY" value="true"/>
<property name="messageType"
scope="axis2"
type="STRING"
value="multipart/form-data"/>
<send>
<endpoint name="FileEpr">
<address optimize="mtom" uri="mailtoOwn:listopadov_as#kk.bank"/>
</endpoint>
</send>
</inSequence>
<outSequence/>
</target>
<description/>
</proxy>
I am trying to send a file (a cachier cheque) using Fiddler:
POST http://localhost:8280/services/EmailService HTTP/1.1
Content-Type: multipart/form-data; boundary=NewBoundary
--NewBoundary
Content-Disposition: form-data; name="attachment"; filename="cheque.png"
Content-Type: image/png
<...binary data...>
--NewBoundary--
And I get this in the WSO2 EI 6.5.0 console:
[2020-09-07 16:24:19,136] [] INFO - LogMediator [EmailService] Initialize = sendMailSequence
[2020-09-07 16:24:19,138] [] INFO - LogMediator [EmailService] Before Send = <?xml version='1.0' encoding='utf-8'?><soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope"><soapenv:Body><mediate><attachment filename="cheque.png">iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAFwUlEQVR42rWWaWxUVRTHz3nLvJl5nZkuTBcoVHYqixpMUBCDRgUpoEBcQkICo2DZGmyjCRqEgKBWC9awFdLGhJCoIahoUBMNGjYDJBIRKpCCNKW0pdN2On2zvveO591SLKQf/KA3uTNz37v
3/M4593/PHYT/uaHz0ZSXJ8l5ebPNWGy6nUpJfS/pnsk0wPN7n6Gq2m6v9xiFw0cKm5ttAbhRXDxX37z5q87mZslKp/vmY7+12M9g31h80z1zGEDZBQVkbNjw/LCLF78RD//IyfmQysoqaPDg/yYtiQQkN26sejgcfkMATsvyNlixYq0yapQYW0RU39WFI3w+8CrKXRHAPRHETBOuRqNUnJmJMop
pRLEYRtev3z7DssrFk1Oy/DEtXVomDx+ONo/bcnPpkXnz8PeTJ0G7cIE0xAEBSSJMjh8Pk6ZOpV8PH8bctjbgDSQ0TYxs2lT9tGWtFQuPSdIn9qJFq6WiIkDu4xYsAEVR2BWCc8ePc4inQbHtu9KQZiZOmQIPTJsGkiSByZHUHzoEcP06KPwusnXrjlm2XSYARyVph71w4U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db6u4AhjLALi4IGQ03Uec98PlUGhsqxehPn4HLuEW
sKtRcAKrcG0HaAkyyNFkxmPIGwffUy3Spbg9Go2kweJO9o/IxXd9Sm3YAWxyAqu6BSYXLOs5dEwBHRY5RIVn+7WHJOgdP7r1MybLZcPq29pO90nRgjoocQOaEQkxfuLk3ZVqlojR8qbkWp2ZP/zTR1IASn1AuE3d1hT3nsuOUENFs3iGGgGlx2Tb/6SnuJnCZ92eR/8SFJS+a1n6x5AeuCoamvtQ
F9JiZNuWBLvqB/gQM1GRZsgIEx/2m/fksZva/qWCro5x/aWjAu9gplNzf6mfib96T0koiuIbpAAAAAElFTkSuQmCC</attachment></mediate></soapenv:Body></soapenv:Envelope>
And in result I get the cheque.png file but it is corrupted because the data inside is base64 encoded and even if I decode it manually and insert decoded data back into the file the file is still corrupted so there is no way I can view it.
I tried several other options and tried placing base64Decode in the payload:
<payloadFactory media-type="xml">
<format>
<root>
<file filename="cheque.png">$1</file>
</root>
</format>
<args>
<arg evaluator="xml" expression="base64Decode(//*[local-name()='attachment']/text())"/>
</args>
</payloadFactory>
But still nothing helps.
Please help me with a working example of how to send a file over email in WSO2 EI 6.5.0
My axis2 messageBuilders are set and the MailTransportSender is uncommented and works fine.

WSO2 ESB 5.0 How to recover value xml element into cdata section?

Hello WSO2 ESB community,
We are new in WSO2. We need help to resolve this question.
We've developed a proxy which receives a soap message like this.
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:es="http://es.ata">
<soapenv:Header></soapenv:Header>
<soapenv:Body>
<es:rc>
<es:xml><![CDATA[<message date="2017-03-02" id="ATA001">.....</message>]]></es:xml>
<es:rc>
</soapenv:Body>
</soapenv:Envelope>
How can we recover the attribute value "id"??
Anyone can help us??
Thanks in advance.
Extract es:xml content in a property type OM (XML) and use XPath inside this content.
Send your payload to this sample proxy and have a look to wso2-esb-service.log, you will find "id = ATA001"
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse" name="TestSOF" transports="http" startOnLoad="true" trace="disable">
<description/>
<target>
<inSequence>
<property xmlns:es="http://es.ata" name="CDATAPAYLOAD" expression="$body/es:rc/es:xml" type="OM"/>
<property name="ID_VALUE" expression="get-property('CDATAPAYLOAD')/#id"/>
<log level="custom">
<property name="id" expression="get-property('ID_VALUE')"/>
</log>
</inSequence>
</target>
</proxy>

Restore task class in WSO2 ESB

When i use a task in WSO2 ESB it always returns the same error with every web service:
"Unable to handle request. The action '(mySoapAction)' was not recognized"
where (mySoapAction) is every SOAP action used, for EVERY action, for EVERY proxy service i use for task implementation.
What could i do in order to fix this error? I thought a task class error in org.apache.synapse.startup.tasks.MessageInjector.
Obvoiusly the task implementation is correct, because the same tasks some day ago were perfectly working. Suggestions?
Here come a sample with the weather webservice (http://wsf.cdyne.com/WeatherWS/Weather.asmx?WSDL)
Proxy service :
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="TestSOF"
transports="https http"
startOnLoad="true"
trace="disable">
<target>
<endpoint>
<wsdl service="Weather"
port="WeatherSoap12"
uri="http://wsf.cdyne.com/WeatherWS/Weather.asmx?WSDL"/>
</endpoint>
<outSequence>
<log level="full"/>
<property name="OUT_ONLY" value="true"/>
<property name="transport.vfs.ReplyFileName" value="weather.xml" scope="transport"/>
<send>
<endpoint>
<address uri="vfs:file:///E:/temp"/>
</endpoint>
</send>
</outSequence>
</target>
<publishWSDL uri="http://wsf.cdyne.com/WeatherWS/Weather.asmx?WSDL"/>
</proxy>
Task :
<?xml version="1.0" encoding="UTF-8"?>
<task xmlns="http://ws.apache.org/ns/synapse"
name="TestSOFTask"
class="org.apache.synapse.startup.tasks.MessageInjector"
group="synapse.simple.quartz">
<trigger count="1" interval="1"/>
<property xmlns:task="http://www.wso2.org/products/wso2commons/tasks"
name="proxyName"
value="TestSOF"/>
<property xmlns:task="http://www.wso2.org/products/wso2commons/tasks"
name="soapAction"
value="http://ws.cdyne.com/WeatherWS/GetCityWeatherByZIP"/>
<property xmlns:task="http://www.wso2.org/products/wso2commons/tasks" name="message">
<weat:GetCityWeatherByZIP xmlns:weat="http://ws.cdyne.com/WeatherWS/">
<weat:ZIP>11010</weat:ZIP>
</weat:GetCityWeatherByZIP>
</property>
<property xmlns:task="http://www.wso2.org/products/wso2commons/tasks"
name="format"
value="soap12"/>
<property xmlns:task="http://www.wso2.org/products/wso2commons/tasks"
name="injectTo"
value="proxy"/>
</task>
Schedule the task and you will find the service response in a file name weather.xml
If you want to change from soap12 to soap11 :
Change the value of property "format" in the task def to : soap11
Change the endpoint def in the proxy service using port "WeatherSoap" rather than "WeatherSoap12"
Hope it will help you to find what is going wrong with your conf...

The endpoint reference (EPR) for the Operation not found using glassfish n wso2esb

I am new to wso2 esb.
I am trying a simple web service program.
package testmart;
import javax.jws.WebService;
#WebService
public class testone {
public String testMethod()
{
return "success";
}
}
I am using glassfish server, created a proxy on wso2 esb by giving following details:
web service url: http://localhost:8080/testmart/testoneService
wsdl url :http://localhost:8080/testmart/testoneService?wsdl
After creating its showing "success" msg. But when I test it, the following error comes up:
<soapenv:Fault xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope" xmlns:axis2ns7="http://www.w3.org/2003/05/soap-envelope">
<soapenv:Code>
<soapenv:Value>axis2ns7:Client</soapenv:Value>
</soapenv:Code>
<soapenv:Reason>
<soapenv:Text xml:lang="en-US" xmlns:xml="http://www.w3.org/XML/1998/namespace">
The endpoint reference (EPR) for the Operation not found is /services/testmart1.testmart1HttpSoap12Endpoint and the WSA Action = null. If this EPR was previously reachable, please contact the server administrator.
</soapenv:Text>
</soapenv:Reason>
<soapenv:Detail/>
</soapenv:Fault>
Below is my esb source view code:
<?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>
<proxy name="testmart1"
transports="https http local"
startOnLoad="true"
trace="disable">
<description/>
<target>
<endpoint>
<address uri="http://localhost:8080/testmart/testoneService"/>
</endpoint>
<outSequence>
<send/>
</outSequence>
</target>
<publishWSDL uri="http://localhost:8080/testmart/testoneService?wsdl"/>
</proxy>
<sequence name="fault">
<log level="full">
<property name="MESSAGE" value="Executing default 'fault' sequence"/>
<property name="ERROR_CODE" expression="get-property('ERROR_CODE')"/>
<property name="ERROR_MESSAGE" expression="get-property('ERROR_MESSAGE')"/>
</log>
<drop/>
</sequence>
<sequence name="main">
<in>
<log level="full"/>
<filter source="get-property('To')" regex="http://localhost:9000.*">
<send/>
</filter>
</in>
<out>
<send/>
</out>
<description>The main sequence for the message mediation</description>
</sequence>
</definitions>
I read all post about this error but could not solve this problem.
Any sort of help would be highly appreciated as this was the first example I tried and stuck from hours.
Thanks in advance.
When you send the request check if the SOAPAction is set. If not, you can specify it in two ways:
ESB level
Set the property before the send mediator
<property name="SOAPAction" value="urn:SOAPAction" scope="transport"/>
Client level
You can specify the SOAPAction in the client side code. Specify it in the options as shown below.
options.setAction("urn:SOAPAction");
in web interface from WSO2 ESB click "Source View" for your proxy and put this lines:
...
<parameter name="serviceType">proxy</parameter>
<parameter name="disableOperationValidation">true</parameter>
...
before the tag:<description/>
On Websphere Application Server, in the same situation, it helped deleting the Temp folders while the server was stopped.
You are using Wso2ESB, so you must need to specify like this:
#WebMethod(action = "testMethod", operationName = "testMethod")
public String testMethod()
The above annotation has to be used in the Web service implementation class.

WSO2 ESB mediate SOAP services

I am struggling to make work my message flow in the wso2 esb so I would need some help to implement a basic communication:
Service1 wants to receive an integer number
Service2 Generates random numbers
Service1 has InSequence: log, send (to addresspoint specified). OutSequence: log, send
this looks like:
<proxy name="ClientAskNumber" transports="https http" startOnLoad="true"
trace="disable">
<target faultSequence="fault">
<inSequence>
<log level="full">
<property name="Insequence" value="***" />
</log>
<send>
<endpoint>
<address uri="http://localhost:8280/services/RandomNumbers" />
</endpoint>
</send>
</inSequence>
<outSequence>
<log level="full">
<property name="Outsequence" value="***" />
</log>
<send />
</outSequence>
</target>
</proxy>
I have this response: <faultstring>System.Web.Services.Protocols.SoapException: Server did not recognize the value of HTTP Header SOAPAction: urn:mediate. at System.Web.Services.Protocols.Soap11ServerProtocolHelper.RouteRequest()....etc
What it means? Am I missing something else? Please help. Thank you
EDIT:
I am studying the Wso2 ESB and I just need to understand how to make work a message communication, after it I will try to add different kind of mediation. I am just breaking down the problem, because I am new to this technology and as you can see I am really struggling to make it work...
EDIT2:*
<proxy xmlns="http://ws.apache.org/ns/synapse" name="ClientAskNumber" transports="https,http" statistics="disable" trace="disable" startOnLoad="true">
<target endpoint="RandomNumbers">
<inSequence>
<log>
<property name="CLIENTASKS" value="******C_ASKS" />
</log>
<send>
<endpoint key="RandomNumbers" />
</send>
</inSequence>
<outSequence>
<log>
<property name="CLIENTRECEIVES" value="*******C_RECEIVES" />
</log>
</outSequence>
</target>
</proxy>
In the case this helps someone else: the problem with "Server did not recognize the value of HTTP Header SOAPAction: urn:mediate..." is that I needed to add an Header mediator in order to call my webservice method "getNumbers", into my InSequence as follows:
<inSequence>
<log>
<property name="CLIENTASKS" value="******C_ASKS" />
</log>
<header name="Action" value="http://tempuri.org/getNumbers" />
<send>
<endpoint key="RandomNumbers" />
</send>
</inSequence>
and send this request via soapUI:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<Numbers xmlns="http://tempuri.org/" />
</soap:Body>
</soap:Envelope>
I hope this can be useful to other persons who are using .Net Solutions with WSO2ESB (unfortunately there are not many examples out there...)
P.S. thanks to Ratha for his help
This is the flow i can tell you..
You have to point your 2nd service as the endpoint of your fist service..In the above configuration
http://localhost:8280/services/RandomNumbers --->2nd service url
ClientAskNumber -->1st service..
Now you can send the request which is needed to execute the 2nd service(ie:to retrive the random number)
So the proxy will forwrad to that endpoint and return the response to the outsequence..You should see that in the console/log since you used a log mediator.
In the error response you are getting i hope you are getting that from your second service. Check whether you are sending correct request to your endpoint