To send multipart/form-data from ESB to APIM - wso2-api-manager

I am using WSO2 ESB 6.4.0 and APIM 2.6.0
I am working on adding certificate in APIM server using rest API of APIM application.
In the request of adding a new certificate, the post request should be form-data.
So, to automate the process, I am using ESB server. I have written a proxy which will pick the certificate file and process it. Below is my proxy code
<?xml version="1.0" encoding="UTF-8"?>
<proxy name="ClientSslCertificateAdd-APIM" startOnLoad="true" transports="http https vfs" xmlns="http://ws.apache.org/ns/synapse">
<target>
<inSequence>
<!-- <enrich>
<source clone="true" type="body"/>
<target property="originalBody" type="property" />
</enrich>
<property expression="get-property('originalBody')"
name="payloadposttexttransformation"
scope="default"
type="STRING"/> -->
<property expression="$body/*" name="payload" scope="default" type="STRING"/>
<property expression="get-property('payload')" name="xml form certificate captured ===" scope="default" type="STRING"/>
<xslt description="" key="xmltotext"/>
<property expression="$body/*" name="payloadpostmapping" scope="default" type="STRING"/>
<property name="filename" scope="default" type="STRING" value="filename_certifiate"/>
<property name="alias" scope="default" type="STRING" value="alias_certifiate"/>
<property name="endpoint" scope="default" type="STRING" value="endpoint_certifiate"/>
<property name="uri.var.host" scope="default" type="STRING" value="http://apimserver.com/"/>
<property name="uri.var.context" scope="default" type="STRING" value="certificates"/>
<property expression="get-property('alias')" name="uri.var.resourcepath" scope="default" type="STRING"/>
<property name="Authorization" scope="transport" type="STRING" value="Bearer token"/>
<call>
<endpoint>
<http method="get" uri-template="{uri.var.host}/{uri.var.context}/{uri.var.resourcepath}"/>
</endpoint>
</call>
<property expression="json-eval($.status)" name="currentstatusoftobeaddedalias" scope="default" type="STRING"/>
<filter regex="Expired" source="get-property('currentstatusoftobeaddedalias')">
<then>
<property expression="get-property('alias')" name="alias" scope="default" type="STRING"/>
<property expression="get-property('endpoint')" name="endpoint" scope="default" type="STRING"/>
<property name="Authorization" scope="transport" type="STRING" value="Bearer token"/>
<property name="messageType" scope="axis2" type="STRING" value="multipart/form-data"/>
<payloadFactory media-type="xml">
<format>
<root xmlns="">
<certificate charset="UTF-8" contentType="text/plain" xmlns="http://org.apache.axis2/xsd/form-data">$3</certificate>
<alias xmlns="http://org.apache.axis2/xsd/form-data">$1</alias>
<endpoint xmlns="http://org.apache.axis2/xsd/form-data">$2</endpoint>
</root>
</format>
<args>
<arg evaluator="xml" expression="$ctx:alias"/>
<arg evaluator="xml" expression="$ctx:endpoint"/>
<arg evaluator="xml" expression="$ctx:payloadpostmapping"/>
</args>
</payloadFactory>
<property name="DISABLE_CHUNKING" scope="axis2" type="STRING" value="true"/>
<!-- <property name="ContentType" scope="axis2" value="multipart/form-data" type="STRING"/> -->
<property name="messageType" scope="axis2" type="STRING" value="multipart/form-data"/>
<!-- <call>
<endpoint>
<http format="rest" method="post" uri-template="http://apimserver.com"/>
</endpoint>
</call> -->
<send>
<endpoint>
<http method="POST" format="rest"
uri-template="http://apimserver.com"/>
</endpoint>
</send>
</then>
<else>
<log>
<property name="alreadypresent" value="with entered alias name, certificate is active"/>
</log>
</else>
</filter>
</inSequence>
<outSequence/>
<faultSequence/>
</target>
<parameter name="transport.PollInterval">5</parameter>
<parameter name="transport.vfs.FileURI">file:///opt/new/esb/clientSSLcertificate_repo/</parameter>
<parameter name="transport.vfs.ContentType">application/xml;charset=UTF-8</parameter>
<parameter name="transport.vfs.ActionAfterProcess">MOVE</parameter>
<parameter name="transport.vfs.MoveAfterFailure">file:///opt/new/esb/clientSSLcertificate_repo/failed_clientSSLcertificate</parameter>
<parameter name="transport.vfs.ActionAfterFailure">MOVE</parameter>
<parameter name="transport.vfs.FileNamePattern">.*.xml</parameter>
<parameter name="transport.vfs.MoveAfterProcess">file:///opt/new/esb/clientSSLcertificate_repo/updated_clientSSLcertificate</parameter>
</proxy>
I am first checking what is the status of the alias present in APIM server, if its expired then it should add the certificate.
also, I am picking the file from ESB local directory in xml form and converting the same in text/plain format in order to remove any residues and ensure that I am sending proper message to APIM server.
Once the request is hit to APIM server, I am getting below error in ESB server
DEBUG - wire HTTP-Sender I/O dispatcher-2 >> "{"code":500,"message":"Internal server error","description":"The server encountered an internal error. Please contact administrator.","moreInfo":"","error":[]}[\r][\n]"
DEBUG - wire HTTP-Sender I/O dispatcher-2 >> "0[\r][\n]"
DEBUG - wire HTTP-Sender I/O dispatcher-2 >> "[\r][\n]"
DEBUG - headers http-outgoing-6 << HTTP/1.1 500 Internal Server Error
DEBUG - headers http-outgoing-6 << Server: nginx/1.16.1
DEBUG - headers http-outgoing-6 << Date: Wed, 06 Nov 2019 22:06:41 GMT
DEBUG - headers http-outgoing-6 << Content-Type: application/json
DEBUG - headers http-outgoing-6 << Transfer-Encoding: chunked
DEBUG - headers http-outgoing-6 << Connection: keep-alive
and error from APIM server is
ERROR - GlobalThrowableMapper An Unknown exception has been captured by global exception mapper.
org.apache.cxf.interceptor.Fault: Couldn't find MIME boundary: --MIMEBoundary_4a754414be212aae0a86dd7fe9ddbf07662811acf9d618ec
at org.apache.cxf.interceptor.AttachmentInInterceptor.handleMessage(AttachmentInInterceptor.java:60)
at org.apache.cxf.jaxrs.ext.MessageContextImpl.createAttachments(MessageContextImpl.java:284)
at org.apache.cxf.jaxrs.ext.MessageContextImpl.get(MessageContextImpl.java:79)
at org.apache.cxf.jaxrs.impl.tl.ThreadLocalMessageContext.get(ThreadLocalMessageContext.java:42)
at org.apache.cxf.jaxrs.utils.multipart.AttachmentUtils.getMultipartBody(AttachmentUtils.java:143)
at org.apache.cxf.jaxrs.utils.multipart.AttachmentUtils.getAttachments(AttachmentUtils.java:155)
at org.apache.cxf.jaxrs.provider.MultipartProvider.readFrom(MultipartProvider.java:149)
at org.apache.cxf.jaxrs.utils.JAXRSUtils.readFromMessageBodyReader(JAXRSUtils.java:1355)
at org.apache.cxf.jaxrs.utils.JAXRSUtils.readFromMessageBody(JAXRSUtils.java:1307)
at org.apache.cxf.jaxrs.utils.JAXRSUtils.processParameter(JAXRSUtils.java:836)
at org.apache.cxf.jaxrs.utils.JAXRSUtils.processParameters(JAXRSUtils.java:795)
at org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor.processRequest(JAXRSInInterceptor.java:214)
at org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor.handleMessage(JAXRSInInterceptor.java:78)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:308)
at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121)
at org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:267)
at org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:234)
at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:208)
at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:160)
at org.apache.cxf.transport.servlet.CXFNonSpringServlet.invoke(CXFNonSpringServlet.java:191)
at org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:301)
at org.apache.cxf.transport.servlet.AbstractHTTPServlet.doPost(AbstractHTTPServlet.java:220)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:650)
at org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTTPServlet.java:276)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:110)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.wso2.carbon.identity.context.rewrite.valve.TenantContextRewriteValve.invoke(TenantContextRewriteValve.java:80)
at org.wso2.carbon.identity.authz.valve.AuthorizationValve.invoke(AuthorizationValve.java:91)
at org.wso2.carbon.identity.auth.valve.AuthenticationValve.invoke(AuthenticationValve.java:65)
at org.wso2.carbon.tomcat.ext.valves.CompositeValve.continueInvocation(CompositeValve.java:99)
at org.wso2.carbon.tomcat.ext.valves.CarbonTomcatValve$1.invoke(CarbonTomcatValve.java:47)
at org.wso2.carbon.webapp.mgt.TenantLazyLoaderValve.invoke(TenantLazyLoaderValve.java:57)
at org.wso2.carbon.event.receiver.core.internal.tenantmgt.TenantLazyLoaderValve.invoke(TenantLazyLoaderValve.java:48)
at org.wso2.carbon.tomcat.ext.valves.TomcatValveContainer.invokeValves(TomcatValveContainer.java:47)
at org.wso2.carbon.tomcat.ext.valves.CompositeValve.invoke(CompositeValve.java:62)
at org.wso2.carbon.tomcat.ext.valves.CarbonStuckThreadDetectionValve.invoke(CarbonStuckThreadDetectionValve.java:159)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:962)
at org.wso2.carbon.tomcat.ext.valves.CarbonContextCreatorValve.invoke(CarbonContextCreatorValve.java:57)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:445)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1115)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:637)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1775)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1734)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.io.IOException: Couldn't find MIME boundary: --MIMEBoundary_4a754414be212aae0a86dd7fe9ddbf07662811acf9d618ec
at org.apache.cxf.attachment.AttachmentDeserializer.initializeRootMessage(AttachmentDeserializer.java:140)
at org.apache.cxf.attachment.AttachmentDeserializer.initializeAttachments(AttachmentDeserializer.java:109)
at org.apache.cxf.interceptor.AttachmentInInterceptor.handleMessage(AttachmentInInterceptor.java:58)
... 54 more
From the error log it seems that APIM server is unable to get the attach files from ESB and which is why it is unable to process the request.
Does APIM 2.6.0 support multipart/form-data
Thanks

We had similar issue and we had to update messageFormatters and messageBuilders in axis2/axis2.xml file (in both ESB and APIM):
update messageFormatters:
<!-- <messageFormatter contentType="multipart/form-data"
class="org.apache.axis2.transport.http.MultipartFormDataFormatter"/ -->
<messageFormatter contentType="multipart/form-data"
class="org.wso2.carbon.relay.ExpandingMessageFormatter"/>
update messageBuilders
<!-- messageBuilder contentType="multipart/form-data"
class="org.apache.axis2.builder.MultipartFormDataBuilder"/ -->
<messageBuilder contentType="multipart/form-data"
class="org.wso2.carbon.relay.BinaryRelayBuilder"/>
These updates should change the transport to stream the payload without parsing and rebuilding it

Related

how to add mediation for get token of WSO2 API Manager?

I Have This API And I Used the Message Mediation Below to Authenticate and Get the Token:
curl -X POST "URL" -H "accept: /" -H "Content-Type: application/x-www-form-urlencoded" -d "username=user&password=password"
result is:
enter image description here
<payloadFactory media-type="x-www-form-urlencoded">
<format>
{
"username":"user",
"password":"password"
}
</format>
<args>
</args>
</payloadFactory>
<header name="Content-Type" value="application/x-www-form-urlencoded" scope="transport" />
<property name="messageType" value="application/json" scope="axis2" type="STRING" />
<property name="REST_URL_POSTFIX" value="" scope="axis2" type="STRING" />
<call blocking="true">
<endpoint>
<http method="POST" uri-template="URL" />
</endpoint>
</call>
<property name="bearer-token" expression="json-eval($..token)" scope="default" type="STRING" />
<property name="REST_URL_POSTFIX" expression="get-property('resource')" scope="axis2" type="STRING" />
<header name="Authorization" expression="fn:concat('Bearer ', get-property('bearer-token'))" scope="transport" />
<payloadFactory media-type="x-www-form-urlencoded">
<format>$1</format>
<args>
<arg evaluator="xml" expression="get-property('request-body')" />
</args>
</payloadFactory>
But i have this error:
enter image description here
WSO2 API Manager Logs
INFO - LogMediator STATUS = Message dispatched to the main sequence. Invalid URL., RESOURCE = url, HEALTH CHECK URL = url
[2021-07-28 16:22:39,696] INFO - LogMediator STATUS = Message dispatched to the main sequence. Invalid URL., RESOURCE = url, HEALTH CHECK URL = url
Make sure that, you have provided the correct token endpoint url for the Call mediator
<call blocking="true">
<endpoint>
<http method="POST" uri-template="https://your-token-endpoint/oauth" />
</endpoint>
</call>

Can't access WSO2 ESB proxy service thru its http endpoint URL

We have this WSO2 ESB proxy service that's accessible thru its https endpoint. I want to configure this service so that it will also be accessible via http.
I checked the service configuration in the carbon management console and confirmed that both https and http endpoint were already enabled:
https://10.20.0.20:8245/services/<service_name>
http://10.20.0.20:8282/services/<service_name>
Also, the axis2.xml file in ESB_HOME}/repository/conf/axis2/ seems to be configured just fine.
<!-- ================================================= -->
<!-- Transport Ins (Listeners) -->
<!-- ================================================= -->
<!-- the non blocking http transport based on HttpCore + NIO extensions -->
<transportReceiver name="http" class="org.apache.synapse.transport.nhttp.HttpCoreNIOListener">
<parameter name="port" locked="false">8280</parameter>
<parameter name="non-blocking" locked="false">true</parameter>
<!--parameter name="bind-address" locked="false">hostname or IP address</parameter-->
<!--parameter name="WSDLEPRPrefix" locked="false">https://apachehost:port/somepath</parameter-->
<parameter name="httpGetProcessor" locked="false">org.wso2.carbon.transport.nhttp.api.NHttpGetProcessor</parameter>
<!--<parameter name="priorityConfigFile" locked="false">location of priority configuration file</parameter>-->
<parameter name="disableRestServiceDispatching" locked="false">true</parameter>
</transportReceiver>
<!-- the non blocking https transport based on HttpCore + SSL-NIO extensions -->
<transportReceiver name="https" class="org.apache.synapse.transport.nhttp.HttpCoreNIOSSLListener">
<parameter name="port" locked="false">8243</parameter>
<parameter name="non-blocking" locked="false">true</parameter>
<!--parameter name="bind-address" locked="false">hostname or IP address</parameter-->
<!--parameter name="WSDLEPRPrefix" locked="false">https://apachehost:port/somepath</parameter-->
<!--<parameter name="priorityConfigFile" locked="false">location of priority configuration file</parameter>-->
<parameter name="httpGetProcessor" locked="false">org.wso2.carbon.transport.nhttp.api.NHttpGetProcessor</parameter>
<parameter name="disableRestServiceDispatching" locked="false">true</parameter>
<parameter name="keystore" locked="false">
<KeyStore>
<Location>repository/resources/security/iaascol.jks</Location>
<Type>JKS</Type>
<Password>***</Password>
<KeyPassword>rotcelloc</KeyPassword>
</KeyStore>
</parameter>
<parameter name="truststore" locked="false">
<TrustStore>
<Location>repository/resources/security/client-truststore.jks</Location>
<Type>JKS</Type>
<Password>***</Password>
</TrustStore>
</parameter>
<!--<parameter name="SSLVerifyClient">require</parameter>
supports optional|require or defaults to none -->
</transportReceiver>
Port offset in ESB_HOME}/repository/conf/carbon.xml is set to 2.
<Offset>2</Offset>
I can't seem to access this proxy service thru its http endpoint URL. The version of WSO2 ESB is 4.5.0. Please let me know which configuration do I have to check / set. Thanks in advance.
Edit: Below is the proxy service config as well as netstat result.
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="disbursement" statistics="disable"
trace="enable" transports="https,http">
<target>
<inSequence>
<property action="set" name="EXECUTION_CONTEXT"
scope="default" type="STRING" value="disbursement"/>
<property action="set"
expression="fn:concat(//*[local-name()='Header']/*[local-name()='TrackingID'], '.xml')"
name="DumpFileName" scope="default" type="STRING"/>
<log category="INFO" level="full" separator=",">
<property name="EVENT_TYPE" value="PROCESSING_STARTED"/>
<property expression="get-property('DumpFileName')" name="FILENAME"/>
</log>
<property action="set" name="DumpFilePath" scope="default"
type="STRING" value="/home/user1/data/disbursement/incoming"/>
<class name="se.seman.wso2.mediator.WriteFile"/>
<property action="set" name="TopicName" scope="default"
type="STRING" value="VirtualTopic.seman.iaas.user1.topic.disbursement.out"/>
<property action="set" name="ResultCode" scope="default"
type="STRING" value="0"/>
<!--
TODO correct problem with xpath
validate source="/default/xpath">
<on-fail>
<property action="set" name="ResultCode"
scope="default" type="STRING" value="100"/>
<property action="set"
expression="get-property('ERROR_MESSAGE')"
name="ResultMessage" scope="default"
type="STRING"
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:Namespaces.user1.se:Cmf:InfoModel:FinancialManagement:Payment:Disbursment:0002"/>
<log category="INFO" level="full" separator=",">
<property name="MESSAGE" value="Schema validation failed"/>
<property
expression="get-property('ERROR_CODE')"
name="ERROR_CODE"
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:Namespaces.user1.se:Cmf:InfoModel:FinancialManagement:Payment:Disbursment:0002"/>
<property
expression="get-property('ERROR_MESSAGE')"
name="ERROR_MESSAGE"
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:Namespaces.user1.se:Cmf:InfoModel:FinancialManagement:Payment:Disbursment:0002"/>
</log>
<property action="set" name="RESPONSE"
scope="default" type="STRING" value="true"/>
</on-fail>
<schema key="conf:user1/ESBConfig/Common/NetPosti/resources/Disbursement_0002.xsd"/>
</validate -->
<log category="INFO" level="headers" separator=",">
<property name="MESSAGE" value="Before Topic"/>
<property expression="get-property('ERROR')" name="ERROR"/>
</log>
<filter xpath="get-property('ResultCode') = '0'">
<then>
<property action="set" name="ResultMessage"
scope="default" type="STRING" value="OK"/>
<class name="se.seman.wso2.mediator.WriteActiveMQTopic"/>
</then>
<else/>
</filter>
<header action="remove" name="To"/>
<property action="remove" name="NO_ENTITY_BODY" scope="axis2"/>
<property action="set" name="RESPONSE" scope="default"
type="STRING" value="true"/>
<payloadFactory>
<format>
<disr:DisbursementResponse xmlns:disr="urn:Namespaces.user1.se:Service:FinancialManagement:Payment:Disbursement:Response:0001">
<disr:ResponseCode>$1</disr:ResponseCode>
<disr:Message>$2</disr:Message>
</disr:DisbursementResponse>
</format>
<args>
<arg expression="get-property('ResultCode')"/>
<arg expression="get-property('ResultMessage')"/>
</args>
</payloadFactory>
<log category="INFO" level="full" separator=","/>
<send/>
</inSequence>
<outSequence>
<log category="INFO" level="full" separator=",">
<property name="MESSAGE" value="On the way back.."/>
</log>
<send/>
</outSequence>
<faultSequence>
<log category="INFO" level="full" separator=",">
<property name="MESSAGE" value="Error in Call!"/>
</log>
<property action="set" name="RESPONSE" scope="default"
type="STRING" value="true"/>
<enrich>
<source clone="true" type="inline">
<disr:DisbursementResponse xmlns:disr="urn:Namespaces.user1.se:Service:FinancialManagement:Payment:Disbursement:0001">
<disr:ResponseCode>900</disr:ResponseCode>
<disr:Message>General error</disr:Message>
</disr:DisbursementResponse>
</source>
<target action="replace" type="body"/>
</enrich>
</faultSequence>
</target>
<publishWSDL key="conf:user1/ESBConfig/Common/NetPosti/resources/DisbursementService0002.wsdl">
<resource
key="conf:user1/ESBConfig/Common/NetPosti/resources/Disbursement_0002.xsd" location="Disbursement_0002.xsd"/>
</publishWSDL>
[user1#ip-10-20-0-20 ~]$ netstat -pnlt
Proto Recv-Q Send-Q Local Address Foreign Address
State PID/Program name
tcp 0 0 :::8245 :::*
LISTEN 2454/java
tcp 0 0 :::8282 :::*
LISTEN 2454/java
turned out this was only a firewall issue. port 8282 was blocked in wso2 firewall (iptables). thanks for all answers!

getting "org.apache.http.nohttpresponseexception the target server failed to respond" while calling wso2 http endpoint

I am getting below error while calling http endpoint:-
The endpoint is HTTP endpoint which I am using.
Also added timeout parameters in axis2.xml and axis2.blocking.xml.
But it did not work.
Can anyone provide any solution to it?
HTTPSender Unable to sendViaPost to url[http://*********]
org.apache.commons.httpclient.NoHttpResponseException: The server ****** failed to respond
at org.apache.commons.httpclient.HttpMethodBase.readStatusLine(HttpMethodBase.java:1976)
at org.apache.commons.httpclient.HttpMethodBase.readResponse(HttpMethodBase.java:1735)
at org.apache.commons.httpclient.HttpMethodBase.execute(HttpMethodBase.java:1098)
the esb proxy looks like below:--
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="mqListener"
startOnLoad="true"
statistics="disable"
trace="disable"
transports="http,https">
<target>
<inSequence>
<log description="print message" level="full">
<property name="message" value=""In listenAbc1Mq""/>
</log>
<payloadFactory media-type="json">
<format>
{
"orderId": ""
}
</format>
<args>
<arg evaluator="xml" expression="//verkkopvc/text()"/>
</payloadFactory>
<log description="print message" level="full">
<property name="message" value=""after payload factory""/>
</log>
<property name="OUT_ONLY" value="true"/>
<property name="DISABLE_CHUNKING"
scope="axis2"
type="STRING"
value="true"/>
<call blocking="true">
<endpoint key="abc"/>
</call>
<log description="print message" level="full">
<property name="message" value=""Out sequence""/>
</log>
</inSequence>
<outSequence/>
<description/>
</proxy>
I believe the error is printed by your http client. To fix it, do these.
1) Remove <property name="OUT_ONLY" value="true"/>
2) Add <respond/> mediator at the end of inSequence.

WSO2 APIM The system cannot infer the transport information from the /devtest/1.0/users/admin

Hi I have an API with a custom sequence (dblookup & switch sequence) that will verify if a user is existing on the database, if not it should send a http status 401: Unauthorized, below is the case code but I always get an error cannot infer the transport information. What is the correct way of sending the back the response message.
THanks,
Drew
<case regex="0">
<log level="custom">
<property name="ucount" expression="fn:concat('User login - ', get-property('employee_count'))"/>
</log>
<send>
<property name="RESPONSE" value="true" scope="default"/>
<property name="NO_ENTITY_BODY" action="remove" scope="axis2"/>
<property name="HTTP_SC" value="401" scope="axis2"/>
<header name="To" action="remove"/>
<payloadFactory media-type="xml">
<format>
<response>
<result>Unauthorized</result>
</response>
</format>
<args/>
</payloadFactory>
<send/>
</case>
ERROR:
TID: [0] [AM] [2014-12-02 08:16:30,852] ERROR {org.apache.synapse.core.axis2.Axis2Sender} - Unexpected error during sending message out {org.apache.synapse.core.axis2.Axis2Sender}
org.apache.axis2.AxisFault: The system cannot infer the transport information from the /devtest/1.0/users/admin URL.
at org.apache.axis2.description.ClientUtils.inferOutTransport(ClientUtils.java:81)
at org.apache.synapse.core.axis2.DynamicAxisOperation$DynamicOperationClient.executeImpl(DynamicAxisOperation.java:115)
at org.apache.axis2.client.OperationClient.execute(OperationClient.java:149)
at org.apache.synapse.core.axis2.Axis2FlexibleMEPClient.send(Axis2FlexibleMEPClient.java:482)
at org.apache.synapse.core.axis2.Axis2Sender.sendOn(Axis2Sender.java:59)
at org.apache.synapse.core.axis2.Axis2SynapseEnvironment.send(Axis2SynapseEnvironment.java:338)
at org.apache.synapse.mediators.builtin.SendMediator.mediate(SendMediator.java:94)
at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:77)
at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:47)
at org.apache.synapse.config.xml.AnonymousListMediator.mediate(AnonymousListMediator.java:30)
at org.apache.synapse.config.xml.SwitchCase.mediate(SwitchCase.java:66)
at org.apache.synapse.mediators.filters.SwitchMediator.mediate(SwitchMediator.java:123)
at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:77)
at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:47)
at org.apache.synapse.mediators.base.SequenceMediator.mediate(SequenceMediator.java:131)
at org.wso2.carbon.apimgt.gateway.handlers.ext.APIManagerExtensionHandler.mediate(APIManagerExtensionHandler.java:64)
at org.wso2.carbon.apimgt.gateway.handlers.ext.APIManagerExtensionHandler.handleRequest(APIManagerExtensionHandler.java:180)
at org.apache.synapse.rest.API.process(API.java:285)
at org.apache.synapse.rest.RESTRequestHandler.dispatchToAPI(RESTRequestHandler.java:83)
at org.apache.synapse.rest.RESTRequestHandler.process(RESTRequestHandler.java:64)
at org.apache.synapse.core.axis2.Axis2SynapseEnvironment.injectMessage(Axis2SynapseEnvironment.java:220)
at org.apache.synapse.core.axis2.SynapseMessageReceiver.receive(SynapseMessageReceiver.java:83)
at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:180)
at org.apache.synapse.transport.passthru.ServerWorker.processNonEntityEnclosingRESTHandler(ServerWorker.java:344)
at org.apache.synapse.transport.passthru.ServerWorker.run(ServerWorker.java:168)
at org.apache.axis2.transport.base.threads.NativeWorkerPool$1.run(NativeWorkerPool.java:172)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:744)
TID: [0] [AM] [2014-12-02 08:16:30,853] INFO {org.apache.synapse.mediators.builtin.LogMediator} - STATUS = Executing default 'fault' sequence, ERROR_CODE = 0, ERROR_MESSAGE = Unexpected error during sending message out {org.apache.synapse.mediators.builtin.LogMediator}
Within send mediator you can not define other mediators.
Correct like this;
<property name="RESPONSE" value="true" scope="default"/>
<property name="NO_ENTITY_BODY" action="remove" scope="axis2"/>
<property name="HTTP_SC" value="401" scope="axis2"/>
<header name="To" action="remove"/>
<payloadFactory media-type="xml">
<format>
<response>
<result>Unauthorized</result>
</response>
</format>
<args/>
</payloadFactory>
<send>
endpoint>
<address uri="ADDRESS OF YOUR ENDPOINT"/>
</endpoint>
</send>
In my case there were invisible characters prepended to otherwise correct (Production/Sandbox) URL.
WSO2 seems very strict and didn't manage to interpret such definition, resulting in vague error:
The system cannot infer the transport information from the https://...
Notice the two spaces between the and https. It may have been a tabulator character.

Unable to get http header

Hi I have the source view of my api from APIM and modified it to get the the htttp header "Authorization" and log it to the log file I added 2 entries in code one for insequence and one for outsequence. In the insequence I added the line
<property name="AuthHeader" expression="$trp:Authorization"/>
In order to get the header and assign it to a property. In the out sequence I added
<log level="custom">
<property name="AuthHeader value" expression="get-property('AuthHeader')"/>
</log>
To determine if the AuthHeader property will display and get the header, however inside the log file it was said that
TID: [0] [AM] [2014-11-19 04:23:01,997] INFO {org.apache.synapse.mediators.builtin.LogMediator} - AuthHeader value = null {org.apache.synapse.mediators.builtin.LogMediator}
TID: [0] [AM] [2014-11-19 04:23:07,335] INFO {org.apache.synapse.mediators.builtin.LogMediator} - AuthHeader value = null {org.apache.synapse.mediators.builtin.LogMediator}
TID: [0] [AM] [2014-11-19 04:56:17,177] INFO {org.apache.synapse.mediators.builtin.LogMediator} - AuthHeader value = null {org.apache.synapse.mediators.builtin.LogMediator}
Which means I'm not getting the correct http header value, is there something wrong with the code? Please help, the complete API code is below.
Thanks,
Drew
<api name="admin--fte" context="/fte">
<resource methods="POST GET DELETE OPTIONS PUT" url-mapping="/*">
<inSequence>
<property name="AuthHeader" expression="$trp:Authorization"/>
<property name="isDefault" expression="get-property('transport', 'WSO2_AM_API_DEFAULT_VERSION')"/>
<filter source="get-property('isDefault')" regex="true">
<then>
<log level="custom">
<property name="STATUS" value="Faulty invoking through default API.Dropping message to avoid recursion.."/>
</log>
<payloadFactory media-type="xml">
<format>
<am:fault xmlns:am="http://wso2.org/apimanager">
<am:code>500</am:code>
<am:type>Status report</am:type>
<am:message>Internal Server Error</am:message>
<am:description>Faulty invoking through default API</am:description>
</am:fault>
</format>
<args/>
</payloadFactory>
<property name="HTTP_SC" value="500" scope="axis2"/>
<property name="RESPONSE" value="true"/>
<header name="To" action="remove"/>
<property name="NO_ENTITY_BODY" scope="axis2" action="remove"/>
<property name="ContentType" scope="axis2" action="remove"/>
<property name="Authorization" scope="transport" action="remove"/>
<property name="Host" scope="transport" action="remove"/>
<property name="Accept" scope="transport" action="remove"/>
<send/>
</then>
<else>
<header name="WSO2_AM_API_DEFAULT_VERSION" scope="transport" value="true"/>
<property name="uri.var.portnum" expression="get-property('http.nio.port')"/>
<send>
<endpoint>
<http uri-template="http://localhost:{uri.var.portnum}/fte/1.0">
<timeout>
<duration>30000</duration>
<responseAction>fault</responseAction>
</timeout>
<suspendOnFailure>
<errorCodes>-1</errorCodes>
<initialDuration>0</initialDuration>
<progressionFactor>1.0</progressionFactor>
<maximumDuration>0</maximumDuration>
</suspendOnFailure>
<markForSuspension>
<errorCodes>-1</errorCodes>
</markForSuspension>
</http>
</endpoint>
</send>
</else>
</filter>
</inSequence>
<outSequence>
<property name="messageType" value="application/json" scope="axis2" type="STRING"/>
<log level="custom">
<property name="AuthHeader value" expression="get-property('AuthHeader')"/>
</log>
<send/>
</outSequence>
</resource>
<handlers>
<handler class="org.wso2.carbon.apimgt.gateway.handlers.common.SynapsePropertiesHandler"/>
</handlers>
</api>
By default, the Authorization header is removed by the Authentication handler. That's why you cant' seem to access it or log it. Handlers act before the mediation inSequence.
The Authentication header can be preserved by editing the api-manager.xml config file in /repository/conf. Simply uncomment the following node and change the value to false:
<RemoveOAuthHeadersFromOutMessage>false</RemoveOAuthHeadersFromOutMessage>

Resources