Use Case:
A REST API will be defined to handle the files sent by clients called (Postman REST Client) as attachment.
The files sent as attachment will be sent to Zoho Task Creation Endpoint in order to create task with Document.
Note: When i tried with postman directly by calling Zoho task Creation API, It creates task with Document.
Can anyone please let me know how to achieve this in API of WSO2 EI 6.1.1
Postman:
When i put log level="full" inside api,getting below log.
When i decode it via Online Tool which gives base64 decoded content like below.
API Code:
<?xml version="1.0" encoding="UTF-8"?>
<api context="/uploadAttachment" name="AtatchmentAPI" xmlns="http://ws.apache.org/ns/synapse">
<resource methods="POST">
<inSequence>
<property name="messageType" scope="axis2" type="STRING" value="multipart/form-data"/>
<!-- <log level="full"/> -->
<log level="custom">
<property name="========UploadAttachment" value=" API Called=========="/>
<property name="========AttachmentName===" expression="get-property('transport', 'filename')"/>
</log>
<property expression="get-property('registry','gov:/ZohoConfig/ZohoAppConfigFile.txt')" name="accessToken" scope="default" type="STRING"/>
<!-- <log level="full"/> -->
<payloadFactory media-type="xml">
<format>
<ns:binary xmlns:ns="http://ws.apache.org/commons/ns/payload">$1</ns:binary>
</format>
<args>
<arg evaluator="xml" expression="//*[local-name()='binary']/text()"/>
</args>
</payloadFactory>
<script language="js">
<![CDATA[
var binaryNode =
mc.getEnvelope().getBody().getFirstElement().getFirstOMChild();
binaryNode.setBinary(true);
]]>
</script>
<property name="attachment_base64" expression="$body"/>
<log level="custom">
<property name="====attachment_base64====" expression="$body"></property>
</log>
<payloadFactory description="Form Response Payload" media-type="json">
<format>{"uploaddoc":$1}</format>
<args>
<arg evaluator="xml" expression="$ctx:attachment_base64"/>
</args>
</payloadFactory>
<log level="custom">
<property name="====uploaddoc_Payload====" expression="$body"></property>
</log>
<!-- <log level="full"/> -->
<property name="transport.vfs.ReplyFileName" value="ZohoTestFile.txt" scope="transport"/>
<property name="transport.vfs.Streaming" value="true" scope="transport"/>
<property name="ClientApiNonBlocking" action="remove" scope="axis2"/>
<property name="messageType" scope="axis2" value="application/binary"/>
<property name="HTTP_METHOD" value="POST" scope="axis2" type="STRING"/>
<header expression="fn:concat('Bearer ', '1000.CCCCCCCCCC.XXXXXXXXXXXXXXXXXX')" name="Authorization" scope="transport"/>
<call>
<endpoint>
<address uri="https://projectsapi.zoho.com/restapi/portal/36249112/projects/685798000000976352/tasks/685798000011774999/attachments/"/>
</endpoint>
</call>
<log>
<property expression="json-eval($.)" name="==API Response======"/>
</log>
<!-- <payloadFactory description="Form Response Payload" media-type="json">
<format>{"recipients":"Regularrrrrrrrrrrrr"}</format>
<args/>
</payloadFactory>
<log>
<property expression="json-eval($.)" name="==Final- CampaignBuilder_JsonRequest_ForCreation======"/>
</log> -->
<respond/>
<!-- <property expression="String(//mediate/file/#filename)" name="filename" scope="default" type="STRING"/> -->
<respond/>
</inSequence>
<outSequence/>
<faultSequence/>
</resource>
</api>
API Response:
{
"error": {
"code": 6831,
"message": "Input Parameter Missing"
}
}
Reason: need to pass attachment to the param called "uploaddoc" when calling Zoho API. here i don't know how to set attachment to that field
Wire Logs:
3:04:42,565] [] INFO - APIDeployer API named 'AtatchmentAPI' has been deployed from file : D:\ServerSetup 6.1.1\wso2ei-6.1.1\wso2\tmp\carbonapps\-1234\1602833682469Att
-CAR_1.0.0.car\AtatchmentAPI_1.0.0\AtatchmentAPI-1.0.0.xml
3:04:42,565] [] INFO - ApplicationManager Successfully Deployed Carbon Application : AttachmentUpload-CAR_1.0.0 {super-tenant}
3:05:04,362] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 >> "POST /uploadAttachment HTTP/1.1[\r][\n]"
3:05:04,363] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 >> "User-Agent: PostmanRuntime/7.26.5[\r][\n]"
3:05:04,363] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 >> "Accept: */*[\r][\n]"
3:05:04,363] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 >> "Postman-Token: 21c46ad2-19fc-46a6-aea8-8113ac70817e[\r][\n]"
3:05:04,363] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 >> "Host: localhost:8280[\r][\n]"
3:05:04,363] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 >> "Accept-Encoding: gzip, deflate, br[\r][\n]"
3:05:04,364] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 >> "Connection: keep-alive[\r][\n]"
3:05:04,364] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 >> "Content-Type: multipart/form-data; boundary=--------------------------623932778277436708655778[\r][\n]"
3:05:04,364] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 >> "Cookie: bf42f62d55=64dc75f94d2bd72d94493d263847c08c[\r][\n]"
3:05:04,364] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 >> "Content-Length: 376[\r][\n]"
3:05:04,365] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 >> "[\r][\n]"
3:05:04,365] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 >> "----------------------------623932778277436708655778[\r][\n]"
3:05:04,365] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 >> "Content-Disposition: form-data; name="uploaddoc"; filename="ZohoAttachment.txt"[\r][\n]"
3:05:04,365] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 >> "Content-Type: text/plain[\r][\n]"
3:05:04,366] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 >> "[\r][\n]"
3:05:04,370] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 >> "Hi,[\r][\n]"
3:05:04,371] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 >> "This is zoho Attachment task[\r][\n]"
3:05:04,371] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 >> "----------------------------623932778277436708655778[\r][\n]"
3:05:04,371] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 >> "Content-Disposition: form-data; name="name"[\r][\n]"
3:05:04,373] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 >> "[\r][\n]"
3:05:04,373] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 >> "TaskAttachment Demo[\r][\n]"
3:05:04,373] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 >> "----------------------------623932778277436708655778--[\r][\n]"
3:05:04,373] [] INFO - LogMediator ========UploadAttachment = API Called==========, ========AttachmentName=== = null
3:05:04,398] [] INFO - LogMediator ====attachment_base64==== = <soapenv:Body xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope"><ns:binary xmlns:ns="http://ws.apa
ns/ns/payload">LS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLTYyMzkzMjc3ODI3NzQzNjcwODY1NTc3OA0KQ29udGVudC1EaXNwb3NpdGlvbjogZm9ybS1kYXRhOyBuYW1lPSJ1cGxvYWRkb2MiOyBmaWxlbmFtZT0iW
1lbnQudHh0Ig0KQ29udGVudC1UeXBlOiB0ZXh0L3BsYWluDQoNCkhpLA0KVGhpcyBpcyB6b2hvIEF0dGFjaG1lbnQgdGFzaw0KLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLTYyMzkzMjc3ODI3NzQzNjcwODY1NTc3OA
EaXNwb3NpdGlvbjogZm9ybS1kYXRhOyBuYW1lPSJuYW1lIg0KDQpUYXNrQXR0YWNobWVudCBEZW1vDQotLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tNjIzOTMyNzc4Mjc3NDM2NzA4NjU1Nzc4LS0NCg==</ns:binary
dy>
3:05:04,402] [] INFO - LogMediator ====uploaddoc_Payload==== = <soapenv:Body xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope"><uploaddoc xmlns="http://ws.apache
se">LS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLTYyMzkzMjc3ODI3NzQzNjcwODY1NTc3OA0KQ29udGVudC1EaXNwb3NpdGlvbjogZm9ybS1kYXRhOyBuYW1lPSJ1cGxvYWRkb2MiOyBmaWxlbmFtZT0iWm9ob0F0dGFj
g0KQ29udGVudC1UeXBlOiB0ZXh0L3BsYWluDQoNCkhpLA0KVGhpcyBpcyB6b2hvIEF0dGFjaG1lbnQgdGFzaw0KLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLTYyMzkzMjc3ODI3NzQzNjcwODY1NTc3OA0KQ29udGVud
lvbjogZm9ybS1kYXRhOyBuYW1lPSJuYW1lIg0KDQpUYXNrQXR0YWNobWVudCBEZW1vDQotLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tNjIzOTMyNzc4Mjc3NDM2NzA4NjU1Nzc4LS0NCg==</uploaddoc></soapenv:
3:05:05,124] [] DEBUG - wire HTTPS-Sender I/O dispatcher-4 << "POST /restapi/portal/36249008/projects/685798000009576352/tasks/685798000011774013/attachments/ HTTP/1.1[
3:05:05,126] [] DEBUG - wire HTTPS-Sender I/O dispatcher-4 << "Authorization: Bearer 1000.9df1f22e7d16ba95f0553af9855d40b5.f81f2af95682c8b398d0bb4939190d10[\r][\n]"
3:05:05,127] [] DEBUG - wire HTTPS-Sender I/O dispatcher-4 << "Cookie: bf42f62d55=64dc75f94d2bd72d94493d263847c08c[\r][\n]"
3:05:05,127] [] DEBUG - wire HTTPS-Sender I/O dispatcher-4 << "transport.vfs.Streaming: true[\r][\n]"
3:05:05,127] [] DEBUG - wire HTTPS-Sender I/O dispatcher-4 << "Accept: */*[\r][\n]"
3:05:05,128] [] DEBUG - wire HTTPS-Sender I/O dispatcher-4 << "Postman-Token: 21c46ad2-19fc-46a6-aea8-8113ac70817e[\r][\n]"
3:05:05,128] [] DEBUG - wire HTTPS-Sender I/O dispatcher-4 << "Accept-Encoding: gzip, deflate, br[\r][\n]"
3:05:05,128] [] DEBUG - wire HTTPS-Sender I/O dispatcher-4 << "transport.vfs.ReplyFileName: ZohoTestFile.txt[\r][\n]"
3:05:05,129] [] DEBUG - wire HTTPS-Sender I/O dispatcher-4 << "Content-Type: application/binary[\r][\n]"
3:05:05,129] [] DEBUG - wire HTTPS-Sender I/O dispatcher-4 << "Transfer-Encoding: chunked[\r][\n]"
3:05:05,129] [] DEBUG - wire HTTPS-Sender I/O dispatcher-4 << "Host: projectsapi.zoho.com[\r][\n]"
3:05:05,130] [] DEBUG - wire HTTPS-Sender I/O dispatcher-4 << "Connection: Keep-Alive[\r][\n]"
3:05:05,130] [] DEBUG - wire HTTPS-Sender I/O dispatcher-4 << "User-Agent: Synapse-PT-HttpComponents-NIO[\r][\n]"
3:05:05,130] [] DEBUG - wire HTTPS-Sender I/O dispatcher-4 << "[\r][\n]"
3:05:05,131] [] DEBUG - wire HTTPS-Sender I/O dispatcher-4 << "237[\r][\n]"
3:05:05,131] [] DEBUG - wire HTTPS-Sender I/O dispatcher-4 << "<uploaddoc xmlns="http://ws.apache.org/ns/synapse">LS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLTYyMzkzMjc3ODI3Nz
3OA0KQ29udGVudC1EaXNwb3NpdGlvbjogZm9ybS1kYXRhOyBuYW1lPSJ1cGxvYWRkb2MiOyBmaWxlbmFtZT0iWm9ob0F0dGFjaG1lbnQudHh0Ig0KQ29udGVudC1UeXBlOiB0ZXh0L3BsYWluDQoNCkhpLA0KVGhpcyBpcyB
aG1lbnQgdGFzaw0KLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLTYyMzkzMjc3ODI3NzQzNjcwODY1NTc3OA0KQ29udGVudC1EaXNwb3NpdGlvbjogZm9ybS1kYXRhOyBuYW1lPSJuYW1lIg0KDQpUYXNrQXR0YWNobWVu
S0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tNjIzOTMyNzc4Mjc3NDM2NzA4NjU1Nzc4LS0NCg==</uploaddoc>[\r][\n]"
3:05:05,134] [] DEBUG - wire HTTPS-Sender I/O dispatcher-4 << "0[\r][\n]"
3:05:05,135] [] DEBUG - wire HTTPS-Sender I/O dispatcher-4 << "[\r][\n]"
3:05:05,905] [] DEBUG - wire HTTPS-Sender I/O dispatcher-4 >> "HTTP/1.1 400 [\r][\n]"
3:05:05,906] [] DEBUG - wire HTTPS-Sender I/O dispatcher-4 >> "Server: ZGS[\r][\n]"
3:05:05,906] [] DEBUG - wire HTTPS-Sender I/O dispatcher-4 >> "Date: Fri, 16 Oct 2020 07:35:06 GMT[\r][\n]"
3:05:05,906] [] DEBUG - wire HTTPS-Sender I/O dispatcher-4 >> "Content-Type: application/json;charset=utf-8[\r][\n]"
3:05:05,906] [] DEBUG - wire HTTPS-Sender I/O dispatcher-4 >> "Content-Length: 60[\r][\n]"
3:05:05,907] [] DEBUG - wire HTTPS-Sender I/O dispatcher-4 >> "Connection: keep-alive[\r][\n]"
3:05:05,907] [] DEBUG - wire HTTPS-Sender I/O dispatcher-4 >> "X-Content-Type-Options: nosniff[\r][\n]"
3:05:05,907] [] DEBUG - wire HTTPS-Sender I/O dispatcher-4 >> "X-XSS-Protection: 1[\r][\n]"
3:05:05,908] [] DEBUG - wire HTTPS-Sender I/O dispatcher-4 >> "Set-Cookie: zpct=24a027ad-3cd2-4edf-b641-b792d3ffede8;path=/;SameSite=None;Secure;priority=high[\r][\n]"
3:05:05,908] [] DEBUG - wire HTTPS-Sender I/O dispatcher-4 >> "Set-Cookie: _zcsr_tmp=24a027ad-3cd2-4edf-b641-b792d3ffede8;path=/;SameSite=Strict;Secure;priority=high[\r
3:05:05,908] [] DEBUG - wire HTTPS-Sender I/O dispatcher-4 >> "Pragma: no-cache[\r][\n]"
3:05:05,909] [] DEBUG - wire HTTPS-Sender I/O dispatcher-4 >> "Cache-Control: no-cache[\r][\n]"
3:05:05,909] [] DEBUG - wire HTTPS-Sender I/O dispatcher-4 >> "Expires: Thu, 01 Jan 1970 00:00:00 GMT[\r][\n]"
3:05:05,909] [] DEBUG - wire HTTPS-Sender I/O dispatcher-4 >> "Set-Cookie: JSESSIONID=9FD064E43DACD49060E958A34C2E0325; Path=/; Secure[\r][\n]"
3:05:05,909] [] DEBUG - wire HTTPS-Sender I/O dispatcher-4 >> "X-Frame-Options: SAMEORIGIN[\r][\n]"
3:05:05,910] [] DEBUG - wire HTTPS-Sender I/O dispatcher-4 >> "X-UA-Compatible: IE=9, IE=10[\r][\n]"
3:05:05,910] [] DEBUG - wire HTTPS-Sender I/O dispatcher-4 >> "Content-Disposition: attachment; filename=response.txt;[\r][\n]"
3:05:05,910] [] DEBUG - wire HTTPS-Sender I/O dispatcher-4 >> "X-Download-Options: noopen[\r][\n]"
3:05:05,910] [] DEBUG - wire HTTPS-Sender I/O dispatcher-4 >> "[\r][\n]"
3:05:05,910] [] DEBUG - wire HTTPS-Sender I/O dispatcher-4 >> "{"error":{"code":6831,"message":"Input Parameter Missing"}}[\n]"
3:05:05,921] [] INFO - LogMediator To: http://www.w3.org/2005/08/addressing/anonymous, WSAction: , SOAPAction: , MessageID: urn:uuid:49cdf6b1-0ac6-4728-bc92-f8658b4a88
: request, ==API Response====== = {"error":{"code":6831,"message":"Input Parameter Missing"}}
3:05:05,925] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 << "HTTP/1.1 400 [\r][\n]"
3:05:05,925] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 << "X-Frame-Options: SAMEORIGIN[\r][\n]"
3:05:05,925] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 << "X-UA-Compatible: IE=9, IE=10[\r][\n]"
3:05:05,926] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 << "Cache-Control: no-cache[\r][\n]"
3:05:05,927] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 << "X-Content-Type-Options: nosniff[\r][\n]"
3:05:05,927] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 << "Content-Disposition: attachment; filename=response.txt;[\r][\n]"
3:05:05,927] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 << "X-Download-Options: noopen[\r][\n]"
3:05:05,927] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 << "Set-Cookie: JSESSIONID=9FD064E43DACD49060E958A34C2E0325; Path=/; Secure[\r][\n]"
3:05:05,927] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 << "Set-Cookie: _zcsr_tmp=24a027ad-3cd2-4edf-b641-b792d3ffede8;path=/;SameSite=Strict;Secure;priority=high[\
3:05:05,928] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 << "Set-Cookie: zpct=24a027ad-3cd2-4edf-b641-b792d3ffede8;path=/;SameSite=None;Secure;priority=high[\r][\n]"
3:05:05,928] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 << "Expires: Thu, 01 Jan 1970 00:00:00 GMT[\r][\n]"
3:05:05,929] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 << "Pragma: no-cache[\r][\n]"
3:05:05,929] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 << "X-XSS-Protection: 1[\r][\n]"
3:05:05,929] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 << "Content-Type: application/json;charset=utf-8[\r][\n]"
3:05:05,930] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 << "Date: Fri, 16 Oct 2020 07:35:05 GMT[\r][\n]"
3:05:05,930] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 << "Transfer-Encoding: chunked[\r][\n]"
3:05:05,930] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 << "Connection: Close[\r][\n]"
3:05:05,930] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 << "[\r][\n]"
3:05:05,931] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 << "3c[\r][\n]"
3:05:05,931] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 << "{"error":{"code":6831,"message":"Input Parameter Missing"}}[\n]"
3:05:05,931] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 << "[\r][\n]"
3:05:05,931] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 << "0[\r][\n]"
3:05:05,932] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 << "[\r][\n]"
Can Anyone please give me a solution for this?
Looking at your code you are not doing anything with the incoming payload. so why are you trying to mediate the payload? just pass through it.
Mock zoho api (use any simple python, pip install web server) and dump request came from ESB and see what is missing in request. Some of the header most probably missing, Content-Disposition Content-Type
API states "name" parameter is mandatory.
Related
I am trying to implement Basic Auth in WSO2 EI 6.5.0.
Below mentioned Class Mediator code is bundled and placed it into <WSO2EI_HOME>/lib and product restart done.
Lib:
CustomBasicAuth:
package com.basic.auth.handler;
import org.apache.commons.codec.binary.Base64;
import org.apache.synapse.MessageContext;
import org.apache.synapse.core.axis2.Axis2MessageContext;
import org.apache.synapse.core.axis2.Axis2Sender;
import org.apache.synapse.rest.Handler;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import java.util.Map;
public class CustomBasicAuth implements Handler {
private static final Log log = LogFactory.getLog(CustomBasicAuth.class);
public void addProperty(String s, Object o) {
//To change body of implemented methods use File | Settings | File Templates.
}
public Map getProperties() {
return null; //To change body of implemented methods use File | Settings | File Templates.
}
public boolean handleRequest(MessageContext messageContext) {
log.info("Inside CustomBasicAuth Class **** " );
org.apache.axis2.context.MessageContext axis2MessageContext
= ((Axis2MessageContext) messageContext).getAxis2MessageContext();
Object headers = axis2MessageContext.getProperty(
org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS);
if (headers != null && headers instanceof Map) {
Map headersMap = (Map) headers;
if (headersMap.get("Authorization") == null) {
headersMap.clear();
axis2MessageContext.setProperty("HTTP_SC", "401");
headersMap.put("WWW-Authenticate", "Basic realm=\"WSO2 ESB\"");
axis2MessageContext.setProperty("NO_ENTITY_BODY", new Boolean("true"));
messageContext.setProperty("RESPONSE", "true");
messageContext.setTo(null);
Axis2Sender.sendBack(messageContext);
return false;
} else {
String authHeader = (String) headersMap.get("Authorization");
if (processSecurity(authHeader)) {
return true;
} else {
headersMap.clear();
axis2MessageContext.setProperty("HTTP_SC", "403");
axis2MessageContext.setProperty("NO_ENTITY_BODY", new Boolean("true"));
messageContext.setProperty("RESPONSE", "true");
messageContext.setTo(null);
Axis2Sender.sendBack(messageContext);
return false;
}
}
}
return false;
}
public boolean handleResponse(MessageContext messageContext) {
return true;
}
public boolean processSecurity(String credentials) {
log.info("encoded credentials**** " + credentials);
String decodedCredentials = new String(new Base64().decode(credentials.getBytes()));
log.info("decoded Credentials**** " + decodedCredentials);
String username = decodedCredentials.split(":")[0];
String password = decodedCredentials.split(":")[1];
if ("wso2user".equals(username) && "wso2user".equals(password)) {
return true;
} else {
return false;
}
}
}
When I invoke API, below ERROR found in wso2carbon log file
Wire Log:
[2023-01-16 17:21:26,873] [] DEBUG - wire HTTP-Listener I/O dispatcher-1 >> "POST /basicauthapi HTTP/1.1[\r][\n]"
[2023-01-16 17:21:26,873] [] DEBUG - wire HTTP-Listener I/O dispatcher-1 >> "Authorization: Basic d3NvMnVzZXI6d3NvMnVzZXI=[\r][\n]"
[2023-01-16 17:21:26,873] [] DEBUG - wire HTTP-Listener I/O dispatcher-1 >> "Content-Type: application/json[\r][\n]"
[2023-01-16 17:21:26,873] [] DEBUG - wire HTTP-Listener I/O dispatcher-1 >> "User-Agent: PostmanRuntime/7.30.0[\r][\n]"
[2023-01-16 17:21:26,873] [] DEBUG - wire HTTP-Listener I/O dispatcher-1 >> "Accept: */*[\r][\n]"
[2023-01-16 17:21:26,873] [] DEBUG - wire HTTP-Listener I/O dispatcher-1 >> "Cache-Control: no-cache[\r][\n]"
[2023-01-16 17:21:26,873] [] DEBUG - wire HTTP-Listener I/O dispatcher-1 >> "Postman-Token: 330c0efb-1ded-41ca-b078-81a0869604a5[\r][\n]"
[2023-01-16 17:21:26,873] [] DEBUG - wire HTTP-Listener I/O dispatcher-1 >> "Host: 192.168.43.128:8281[\r][\n]"
[2023-01-16 17:21:26,873] [] DEBUG - wire HTTP-Listener I/O dispatcher-1 >> "Accept-Encoding: gzip, deflate, br[\r][\n]"
[2023-01-16 17:21:26,873] [] DEBUG - wire HTTP-Listener I/O dispatcher-1 >> "Connection: keep-alive[\r][\n]"
[2023-01-16 17:21:26,873] [] DEBUG - wire HTTP-Listener I/O dispatcher-1 >> "Content-Length: 22[\r][\n]"
[2023-01-16 17:21:26,873] [] DEBUG - wire HTTP-Listener I/O dispatcher-1 >> "[\r][\n]"
[2023-01-16 17:21:26,873] [] DEBUG - wire HTTP-Listener I/O dispatcher-1 >> "{[\r][\n]"
[2023-01-16 17:21:26,873] [] DEBUG - wire HTTP-Listener I/O dispatcher-1 >> " "Test":"API"[\r][\n]"
[2023-01-16 17:21:26,873] [] DEBUG - wire HTTP-Listener I/O dispatcher-1 >> "}"
[2023-01-16 17:21:26,904] [] ERROR - ServerWorker Error processing POST request for : /basicauthapi.
java.lang.ArrayIndexOutOfBoundsException: 1
at com.basic.auth.handler.CustomBasicAuth.processSecurity(CustomBasicAuth.java:73)
at com.basic.auth.handler.CustomBasicAuth.handleRequest(CustomBasicAuth.java:47)
at org.apache.synapse.rest.API.process(API.java:357)
at org.apache.synapse.rest.RESTRequestHandler.apiProcess(RESTRequestHandler.java:135)
at org.apache.synapse.rest.RESTRequestHandler.dispatchToAPI(RESTRequestHandler.java:113)
at org.apache.synapse.rest.RESTRequestHandler.process(RESTRequestHandler.java:71)
at org.apache.synapse.core.axis2.Axis2SynapseEnvironment.injectMessage(Axis2SynapseEnvironment.java:325)
at org.apache.synapse.core.axis2.SynapseMessageReceiver.receive(SynapseMessageReceiver.java:92)
at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:180)
at org.apache.synapse.transport.passthru.ServerWorker.processNonEntityEnclosingRESTHandler(ServerWorker.java:338)
at org.apache.synapse.transport.passthru.ServerWorker.processEntityEnclosingRequest(ServerWorker.java:383)
at org.apache.synapse.transport.passthru.ServerWorker.run(ServerWorker.java:152)
at org.apache.axis2.transport.base.threads.NativeWorkerPool$1.run(NativeWorkerPool.java:172)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
[2023-01-16 17:21:26,920] [] DEBUG - wire HTTP-Listener I/O dispatcher-1 << "HTTP/1.1 500 Internal Server Error[\r][\n]"
[2023-01-16 17:21:26,920] [] DEBUG - wire HTTP-Listener I/O dispatcher-1 << "Content-Type: application/json; charset=UTF-8[\r][\n]"
[2023-01-16 17:21:26,920] [] DEBUG - wire HTTP-Listener I/O dispatcher-1 << "Date: Mon, 16 Jan 2023 11:51:26 GMT[\r][\n]"
[2023-01-16 17:21:26,920] [] DEBUG - wire HTTP-Listener I/O dispatcher-1 << "Transfer-Encoding: chunked[\r][\n]"
[2023-01-16 17:21:26,920] [] DEBUG - wire HTTP-Listener I/O dispatcher-1 << "Connection: keep-alive[\r][\n]"
[2023-01-16 17:21:26,920] [] DEBUG - wire HTTP-Listener I/O dispatcher-1 << "[\r][\n]"
[2023-01-16 17:21:26,920] [] DEBUG - wire HTTP-Listener I/O dispatcher-1 << "46[\r][\n]"
[2023-01-16 17:21:26,920] [] DEBUG - wire HTTP-Listener I/O dispatcher-1 << "{"Fault":{"faultcode":"soapenv:Server","faultstring":1,"detail":null}}[\r][\n]"
[2023-01-16 17:21:26,920] [] DEBUG - wire HTTP-Listener I/O dispatcher-1 << "0[\r][\n]"
[2023-01-16 17:21:26,920] [] DEBUG - wire HTTP-Listener I/O dispatcher-1 << "[\r][\n]"
WSO2 EI API:
<?xml version="1.0" encoding="UTF-8"?>
<api context="/basicauthapi" name="BasicAuthAPI" xmlns="http://ws.apache.org/ns/synapse">
<resource methods="POST">
<inSequence>
<log level="custom">
<property name="====BasicAuthAPI" value="caleed====="/>
</log>
<payloadFactory media-type="json">
<format>{"Status":"success"}</format>
<args/>
</payloadFactory>
<respond/>
</inSequence>
<outSequence/>
<faultSequence/>
</resource>
<handlers>
<handler class="com.basic.auth.handler.CustomBasicAuth"/>
</handlers>
</api>
POSTMAN HIT:
Referrence link
Please let me know why custom basic auth not working.
When you extract the Auth header like String authHeader = (String) headersMap.get("Authorization"); you will get the value as Basic d3NvMnVzZXI6d3NvMnVzZXI=. This is not a valid Base64 encoded value, hence when you try to decode the value (new Base64().decode(credentials.getBytes())) it's failing, eventually throwing an error when trying to split(decodedCredentials.split(":")[0]) the credentials string.
So from the Auth header, you need to extract the credentials part. Multiple ways to do this. Following is using substring. Update the credentials extraction part to following.
String authHeader = (String) headersMap.get("Authorization").substring(6).trim();
On a different note, this code needs improvements and better error handling. For example, what if the Header is invalid? What if the password/username is missing? What if the encoding is wrong?
Update
It seems the product already packs a Auth handler by default. Which authenticates using the connected userstore. Hence you should be able to use this as well.
<handlers>
<handler class="org.wso2.carbon.integrator.core.handler.RESTBasicAuthHandler"/>
</handlers>
As suggested by #ycr, I have created required User(ie wso2user) in WSO2 EI Management console and assign required Role(ie admin)
Added org.wso2.carbon.integrator.core.handler.RESTBasicAuthHandler as Auth Handler inside API.
API:
<?xml version="1.0" encoding="UTF-8"?>
<api context="/basicauthapi" name="BasicAuthAPI" xmlns="http://ws.apache.org/ns/synapse">
<resource methods="POST">
<inSequence>
<log level="custom">
<property name="====BasicAuthAPI" value="caleed====="/>
</log>
<payloadFactory media-type="json">
<format>{"Status":"success"}</format>
<args/>
</payloadFactory>
<respond/>
</inSequence>
<outSequence/>
<faultSequence/>
</resource>
<handlers>
<handler class="org.wso2.carbon.integrator.core.handler.RESTBasicAuthHandler"/>
</handlers>
</api>
Post above changes, API hits happen as expected shown below.
I am trying FileMerge Operation in WSO2 EI 6.6.0 using FileConnector 2.0.24.
The problem here is that it is generating an output file with empty content.
API Code:
<?xml version="1.0" encoding="UTF-8"?>
<api context="/mergefiles" name="FileMergeAPI" xmlns="http://ws.apache.org/ns/synapse">
<resource methods="POST">
<inSequence>
<log level="custom">
<property name="********FileMergeAPI" value="Called***********"/>
</log>
<property expression="json-eval($.source)" name="sourceDir" scope="default" type="STRING"/>
<property expression="json-eval($.destination)" name="destDir" scope="default" type="STRING"/>
<property expression="json-eval($.pattern)" name="pattern"/>
<property expression="fn:concat('file:///', $ctx:sourceDir)" name="sourceDir1" scope="default" type="STRING"/>
<property expression="fn:concat('file:///', $ctx:destDir)" name="destDir1" scope="default" type="STRING"/>
<fileconnector.mergeFiles>
<source>{$ctx:sourceDir1}</source>
<destination>{$ctx:destDir1}</destination>
<filePattern>{$ctx:pattern}</filePattern>
</fileconnector.mergeFiles>
<log level="full"/>
</inSequence>
<outSequence/>
<faultSequence>
<log level="custom">
<property name="text" value="An unexpected error occured"/>
<property expression="get-property('ERROR_MESSAGE')" name="message"/>
<property expression="get-property('ERROR_DETAIL')" name="errordetail"/>
</log>
<send description="Send Error Information"/>
</faultSequence>
</resource>
</api>
Input:
{
"source":"C://Development_Avecto//filemerge//input",
"destination":"C://Development_Avecto//filemerge//output//sample.csv",
"pattern":"//*.csv*"
}
wireLog:
[2022-05-02 13:13:13,417] DEBUG {org.apache.synapse.transport.http.wire} - HTTP-Listener I/O dispatcher-3 >> "POST /mergefiles HTTP/1.1[\r][\n]"
[2022-05-02 13:13:13,419] DEBUG {org.apache.synapse.transport.http.wire} - HTTP-Listener I/O dispatcher-3 >> "Content-Type: application/json[\r][\n]"
[2022-05-02 13:13:13,422] DEBUG {org.apache.synapse.transport.http.wire} - HTTP-Listener I/O dispatcher-3 >> "User-Agent: PostmanRuntime/7.29.0[\r][\n]"
[2022-05-02 13:13:13,423] DEBUG {org.apache.synapse.transport.http.wire} - HTTP-Listener I/O dispatcher-3 >> "Accept: */*[\r][\n]"
[2022-05-02 13:13:13,425] DEBUG {org.apache.synapse.transport.http.wire} - HTTP-Listener I/O dispatcher-3 >> "Cache-Control: no-cache[\r][\n]"
[2022-05-02 13:13:13,426] DEBUG {org.apache.synapse.transport.http.wire} - HTTP-Listener I/O dispatcher-3 >> "Postman-Token: dd7b1a25-b87e-4d64-b474-36b13159042a[\r][\n]"
[2022-05-02 13:13:13,427] DEBUG {org.apache.synapse.transport.http.wire} - HTTP-Listener I/O dispatcher-3 >> "Host: 192.168.43.128:8280[\r][\n]"
[2022-05-02 13:13:13,428] DEBUG {org.apache.synapse.transport.http.wire} - HTTP-Listener I/O dispatcher-3 >> "Accept-Encoding: gzip, deflate, br[\r][\n]"
[2022-05-02 13:13:13,429] DEBUG {org.apache.synapse.transport.http.wire} - HTTP-Listener I/O dispatcher-3 >> "Connection: keep-alive[\r][\n]"
[2022-05-02 13:13:13,433] DEBUG {org.apache.synapse.transport.http.wire} - HTTP-Listener I/O dispatcher-3 >> "Content-Length: 164[\r][\n]"
[2022-05-02 13:13:13,436] DEBUG {org.apache.synapse.transport.http.wire} - HTTP-Listener I/O dispatcher-3 >> "[\r][\n]"
[2022-05-02 13:13:13,438] DEBUG {org.apache.synapse.transport.http.wire} - HTTP-Listener I/O dispatcher-3 >> "{[\r][\n]"
[2022-05-02 13:13:13,438] DEBUG {org.apache.synapse.transport.http.wire} - HTTP-Listener I/O dispatcher-3 >> " "source":"C://Development_Avecto//filemerge//input",[\r][\n]"
[2022-05-02 13:13:13,439] DEBUG {org.apache.synapse.transport.http.wire} - HTTP-Listener I/O dispatcher-3 >> " "destination":"C://Development_Avecto//filemerge//output//sample.csv",[\r][\n]"
[2022-05-02 13:13:13,440] DEBUG {org.apache.synapse.transport.http.wire} - HTTP-Listener I/O dispatcher-3 >> " "pattern":"//*.csv*"[\r][\n]"
[2022-05-02 13:13:13,441] DEBUG {org.apache.synapse.transport.http.wire} - HTTP-Listener I/O dispatcher-3 >> "}"
[2022-05-02 13:13:13,444] INFO {org.apache.synapse.mediators.builtin.LogMediator} - ********FileMergeAPI = Called***********
[2022-05-02 13:13:13,464] INFO {org.apache.synapse.mediators.builtin.LogMediator} - To: /mergefiles, MessageID: urn:uuid:90d67ec1-2a3f-4f13-8389-049a24abbdab, Direction: request, Envelope: <?xml version='1.0' encoding='utf-8'?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><success>true</success></soapenv:Body></soapenv:Envelope>
[2022-05-02 13:13:13,478] DEBUG {org.apache.synapse.transport.http.wire} - HTTP-Listener I/O dispatcher-3 << "HTTP/1.1 202 Accepted[\r][\n]"
[2022-05-02 13:13:13,479] DEBUG {org.apache.synapse.transport.http.wire} - HTTP-Listener I/O dispatcher-3 << "Date: Mon, 02 May 2022 07:43:13 GMT[\r][\n]"
[2022-05-02 13:13:13,480] DEBUG {org.apache.synapse.transport.http.wire} - HTTP-Listener I/O dispatcher-3 << "Transfer-Encoding: chunked[\r][\n]"
[2022-05-02 13:13:13,481] DEBUG {org.apache.synapse.transport.http.wire} - HTTP-Listener I/O dispatcher-3 << "Connection: keep-alive[\r][\n]"
[2022-05-02 13:13:13,481] DEBUG {org.apache.synapse.transport.http.wire} - HTTP-Listener I/O dispatcher-3 << "[\r][\n]"
[2022-05-02 13:13:13,483] DEBUG {org.apache.synapse.transport.http.wire} - HTTP-Listener I/O dispatcher-3 << "0[\r][\n]"
[2022-05-02 13:13:13,483] DEBUG {org.apache.synapse.transport.http.wire} - HTTP-Listener I/O dispatcher-3 << "[\r][\n]"
if you noticed above wire log i got success response post mergefile operation like below
<?xml version='1.0' encoding='utf-8'?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><success>true</success></soapenv:Body></soapenv:Envelope>
I already looked this question which doesn't resolve my issue
File 1 content :
File 2 content:
PS: WSO2 EI 6.5.0 also tried the same. getting empty file
What is wrong with the above configuration?
I am trying to send Campaign by using Mailchimp. While calling this endpoint, i am getting ERROR like "Transport error: 404 Error: Not Found". Can anyone please help me out to resolve this?
Note: When i try in Postman by hitting direct mailchimp url it works fine.
Wire Log:
[2020-10-13 11:11:02,611] [] INFO - ApplicationManager Successfully Deployed Carbon Application : QRSagMailchimpIntegrator-CAR_1.0.0 {super-tenant}
[2020-10-13 11:11:14,590] [] DEBUG - wire HTTP-Listener I/O dispatcher-4 >> "POST /campaignSend/predict/sendCampaignId=d164a3989d?AuthKey=3216f54e-b6d9-11e6-80f5-76304dec7eb7 HTTP/1.1[\r][\n]"
[2020-10-13 11:11:14,591] [] DEBUG - wire HTTP-Listener I/O dispatcher-4 >> "User-Agent: PostmanRuntime/7.26.5[\r][\n]"
[2020-10-13 11:11:14,592] [] DEBUG - wire HTTP-Listener I/O dispatcher-4 >> "Accept: */*[\r][\n]"
[2020-10-13 11:11:14,594] [] DEBUG - wire HTTP-Listener I/O dispatcher-4 >> "Cache-Control: no-cache[\r][\n]"
[2020-10-13 11:11:14,595] [] DEBUG - wire HTTP-Listener I/O dispatcher-4 >> "Postman-Token: 5a44668a-6947-4958-ad24-76fef6ddb62e[\r][\n]"
[2020-10-13 11:11:14,597] [] DEBUG - wire HTTP-Listener I/O dispatcher-4 >> "Host: localhost:8280[\r][\n]"
[2020-10-13 11:11:14,598] [] DEBUG - wire HTTP-Listener I/O dispatcher-4 >> "Accept-Encoding: gzip, deflate, br[\r][\n]"
[2020-10-13 11:11:14,599] [] DEBUG - wire HTTP-Listener I/O dispatcher-4 >> "Connection: keep-alive[\r][\n]"
[2020-10-13 11:11:14,600] [] DEBUG - wire HTTP-Listener I/O dispatcher-4 >> "Content-Length: 0[\r][\n]"
[2020-10-13 11:11:14,601] [] DEBUG - wire HTTP-Listener I/O dispatcher-4 >> "[\r][\n]"
[2020-10-13 11:11:14,684] [] INFO - LogMediator To: /campaignSend/predict/sendCampaignId=d164a3989d?AuthKey=3216f54e-b6d9-11e6-80f5-76304dec7eb7, MessageID: urn:uuid:aa380541-04f4-4bae-8d8a-d727a7f
a45ba, Direction: request, Welcome Logger = === Send Campaigns ===, Campaign ID = d164a3989d
[2020-10-13 11:11:15,742] [] INFO - HTTPSender Unable to sendViaPost to url[https://us17.api.mailchimp.com/3.0/campaigns/d164a3989d/actions/send/predict/sendCampaignId=d164a3989d?AuthKey=3216f54e-b
6d9-11e6-80f5-76304dec7eb7]
org.apache.axis2.AxisFault: Transport error: 404 Error: Not Found
at org.apache.axis2.transport.http.HTTPSender.handleResponse(HTTPSender.java:326)
at org.apache.axis2.transport.http.HTTPSender.sendViaPost(HTTPSender.java:196)
at org.apache.axis2.transport.http.HTTPSender.send(HTTPSender.java:77)
at org.apache.axis2.transport.http.CommonsHTTPTransportSender.writeMessageWithCommons(CommonsHTTPTransportSender.java:451)
at org.apache.axis2.transport.http.CommonsHTTPTransportSender.invoke(CommonsHTTPTransportSender.java:278)
at org.apache.axis2.engine.AxisEngine.send(AxisEngine.java:442)
at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:430)
at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:225)
at org.apache.axis2.client.OperationClient.execute(OperationClient.java:149)
at org.apache.synapse.message.senders.blocking.BlockingMsgSender.sendReceive(BlockingMsgSender.java:302)
at org.apache.synapse.message.senders.blocking.BlockingMsgSender.send(BlockingMsgSender.java:211)
at org.apache.synapse.mediators.builtin.CallMediator.handleBlockingCall(CallMediator.java:150)
at org.apache.synapse.mediators.builtin.CallMediator.mediate(CallMediator.java:113)
at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:97)
at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:59)
at org.apache.synapse.mediators.base.SequenceMediator.mediate(SequenceMediator.java:158)
at org.apache.synapse.rest.Resource.process(Resource.java:343)
at org.apache.synapse.rest.API.process(API.java:399)
at org.apache.synapse.rest.RESTRequestHandler.apiProcess(RESTRequestHandler.java:123)
at org.apache.synapse.rest.RESTRequestHandler.dispatchToAPI(RESTRequestHandler.java:101)
at org.apache.synapse.rest.RESTRequestHandler.process(RESTRequestHandler.java:69)
at org.apache.synapse.core.axis2.Axis2SynapseEnvironment.injectMessage(Axis2SynapseEnvironment.java:304)
at org.apache.synapse.core.axis2.SynapseMessageReceiver.receive(SynapseMessageReceiver.java:78)
at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:180)
at org.apache.synapse.transport.passthru.ServerWorker.processNonEntityEnclosingRESTHandler(ServerWorker.java:326)
at org.apache.synapse.transport.passthru.ServerWorker.processEntityEnclosingRequest(ServerWorker.java:372)
at org.apache.synapse.transport.passthru.ServerWorker.run(ServerWorker.java:151)
at org.apache.axis2.transport.base.threads.NativeWorkerPool$1.run(NativeWorkerPool.java:172)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
[2020-10-13 11:11:15,778] [] INFO - LogMediator To: https://us17.api.mailchimp.com/3.0/campaigns/d164a3989d/actions/send/, MessageID: urn:uuid:aa380541-04f4-4bae-8d8a-d727a7fa45ba, Direction: reque
st, FAUALTYYYYYYYYYYYYYYYYYY************* = Transport error: 404 Error: Not Found
[2020-10-13 11:11:15,781] [] DEBUG - wire HTTP-Listener I/O dispatcher-4 << "HTTP/1.1 202 Accepted[\r][\n]"
[2020-10-13 11:11:15,782] [] DEBUG - wire HTTP-Listener I/O dispatcher-4 << "Date: Tue, 13 Oct 2020 05:41:15 GMT[\r][\n]"
[2020-10-13 11:11:15,783] [] DEBUG - wire HTTP-Listener I/O dispatcher-4 << "Transfer-Encoding: chunked[\r][\n]"
[2020-10-13 11:11:15,784] [] DEBUG - wire HTTP-Listener I/O dispatcher-4 << "Connection: keep-alive[\r][\n]"
[2020-10-13 11:11:15,785] [] DEBUG - wire HTTP-Listener I/O dispatcher-4 << "[\r][\n]"
[2020-10-13 11:11:15,785] [] DEBUG - wire HTTP-Listener I/O dispatcher-4 << "0[\r][\n]"
[2020-10-13 11:11:15,786] [] DEBUG - wire HTTP-Listener I/O dispatcher-4 << "[\r][\n]"
Postman: (Direct Mailchimp URL)
Mailchimp URL
API Code:
<api context="/campaignSend" name="campaign_send_v1" xmlns="http://ws.apache.org/ns/synapse">
<resource method="POST" uri-template="/predict/sendCampaignId={campaignId}?AuthKey={secKey}">
<inSequence>
<log>
<property name="Welcome Logger" value="=== Send Campaigns ==="/>
<property expression="get-property('uri.var.campaignId')" name="Campaign ID"/>
</log>
<property description="secKey" expression="get-property('uri.var.secKey')" name="secKey" scope="default" type="STRING"/>
<property description="ESB-Authentication" expression="get-property('QRSag-VBFeedsAuthKey')" name="authKey" scope="default" type="OM"/>
<property description="FeedsStoredAuthKey" expression="$ctx:authKey//*[local-name()='SecurityToken']" name="authenticatekey" scope="default" type="STRING"/>
<!-- ==================== Check authentication ==================== -->
<filter description="CheckUserAPIValidation" xpath="get-property('secKey') = get-property('authenticatekey')">
<then/>
<else>
<payloadFactory media-type="json">
<format>{"errorCode":"$1","errorTrace":"$2"}</format>
<args>
<arg value="QRSaG - 401"/>
<arg value="Invalid Authentication.Contact QRSagSupport"/>
</args>
</payloadFactory>
<log level="custom">
<property expression="json-eval($.)" name="===API Authentication Failed==="/>
</log>
<respond/>
</else>
</filter>
<property name="Authorization" scope="transport" type="STRING" value="Basic XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"/>
<call blocking="true">
<endpoint key="sendCampaign"/>
<timeout>
<duration>17000000</duration>
<responseAction>fault</responseAction>
</timeout>
</call>
<log>
<property expression="json-eval($.)" name="LoggerText_JsonResponse"/>
</log>
<respond/>
</inSequence>
<outSequence/>
<faultSequence>
<log>
<property expression="get-property('ERROR_MESSAGE')" name="FAUALTYYYYYYYYYYYYYYYYYY*************"/>
</log>
</faultSequence>
</resource>
Endpoint Value:
<?xml version="1.0" encoding="UTF-8"?>
<endpoint name="sendCampaign" xmlns="http://ws.apache.org/ns/synapse">
<http method="post" uri-template="https://us17.api.mailchimp.com/3.0/campaigns/{uri.var.campaignId}/actions/send/"/>
</endpoint>
Analyzing the provided information we can observe that for the postman request you are invoking the URL
https://us17.api.mailchimp.com/3.0/campaigns/d164a3989d/actions/send
But from the ESB server, you are invoking the following URL
https://us17.api.mailchimp.com/3.0/campaigns/d164a3989d/actions/send/predict/sendCampaignId=d164a3989d?AuthKey=3216f54e-b
6d9-11e6-80f5-76304dec7eb7
This is because the context path is appended for the backend call. You can remove this by adding the following property before the call mediator.
<property name="REST_URL_POSTFIX" action="remove" scope="axis2"/>
I have a strange problem while using clone - aggregate mediator. I put log in the onComplete and saw the data, but that data never sending back to the client.
Here is the code I used.
<?xml version="1.0" encoding="UTF-8"?>
<api context="/OneVinmec" name="OneVinmec" xmlns="http://ws.apache.org/ns/synapse">
<resource methods="GET" uri-template="/getPID?*">
...
<outSequence>
<property name="info" scope="default">
<ns:Information xmlns:ns="http://wso2.com"/>
</property>
<aggregate id="getPID">
<completeCondition timeout="10">
<messageCount max="-1" min="-1"/>
</completeCondition>
<onComplete enclosingElementProperty="info" expression="//*[local-name() = 'DSBenhNhan']">
<log description="DSBenhNhan" level="custom">
<property expression="//*[local-name() = 'DSBenhNhan']" name="DSBenhNhan"/>
</log>
<send/>
</onComplete>
</aggregate>
<send/>
</outSequence>
<faultSequence/>
</resource>
</api>
This is the log I got from console, as you can see, there is log INFO - LogMediator, but after that, the response is not sending back.
Edit: After remove the content-encoding header, the Log now show this
[2020-02-12 17:30:16,052] INFO - LogMediator DSBenhNhan = <DSBenhNhan xmlns="http://ws.wso2.org/dataservice/getPID"><BenhNhan><Source_System>OH</Source_System><PID>200380141</PID></BenhNhan></DSBenhNhan><DSBenhNhan xmlns="http://ws.wso2.org/dataservice/getPID"><BenhNhan><Source_System>eHOS</Source_System><PID>19006032</PID></BenhNhan><BenhNhan><Source_System>eHOS</Source_System><PID>19086413</PID></BenhNhan></DSBenhNhan>
[2020-02-12 17:30:16,052] DEBUG - wire HTTP-Listener I/O dispatcher-2 << "HTTP/1.1 200 OK[\r][\n]"
[2020-02-12 17:30:16,052] DEBUG - wire HTTP-Listener I/O dispatcher-2 << "X-Frame-Options: DENY[\r][\n]"
[2020-02-12 17:30:16,052] DEBUG - wire HTTPS-Sender I/O dispatcher-4 >> "0[\r][\n]"
[2020-02-12 17:30:16,052] DEBUG - wire HTTPS-Sender I/O dispatcher-4 >> "[\r][\n]"
[2020-02-12 17:30:16,052] DEBUG - wire HTTP-Listener I/O dispatcher-2 << "X-Content-Type-Options: nosniff[\r][\n]"
[2020-02-12 17:30:16,052] DEBUG - wire HTTP-Listener I/O dispatcher-2 << "Vary: Accept-Encoding[\r][\n]"
[2020-02-12 17:30:16,052] DEBUG - wire HTTP-Listener I/O dispatcher-2 << "X-XSS-Protection: 1; mode=block[\r][\n]"
[2020-02-12 17:30:16,052] DEBUG - wire HTTP-Listener I/O dispatcher-2 << "Content-Type: application/xml;charset=UTF-8[\r][\n]"
[2020-02-12 17:30:16,052] DEBUG - wire HTTP-Listener I/O dispatcher-2 << "Date: Wed, 12 Feb 2020 10:30:16 GMT[\r][\n]"
[2020-02-12 17:30:16,052] DEBUG - wire HTTP-Listener I/O dispatcher-2 << "Transfer-Encoding: chunked[\r][\n]"
[2020-02-12 17:30:16,052] DEBUG - wire HTTP-Listener I/O dispatcher-2 << "[\r][\n]"
[2020-02-12 17:30:16,052] DEBUG - wire HTTP-Listener I/O dispatcher-2 << "1aa[\r][\n]"
[2020-02-12 17:30:16,052] DEBUG - wire HTTP-Listener I/O dispatcher-2 << "<ns:Information xmlns:ns="http://wso2.com"><DSBenhNhan xmlns="http://ws.wso2.org/dataservice/getPID"><BenhNhan><Source_System>OH</Source_System><PID>200380141</PID></BenhNhan></DSBenhNhan><DSBenhNhan xmlns="http://ws.wso2.org/dataservice/getPID"><BenhNhan><Source_System>eHOS</Source_System><PID>19006032</PID></BenhNhan><BenhNhan><Source_System>eHOS</Source_System><PID>19086413</PID></BenhNhan></DSBenhNhan></ns:Information>[\r][\n]"
[2020-02-12 17:30:16,052] DEBUG - wire HTTP-Listener I/O dispatcher-2 << "0[\r][\n]"
[2020-02-12 17:30:16,052] DEBUG - wire HTTP-Listener I/O dispatcher-2 << "[\r][\n]"
Appreciate your help!
According to [2020-02-12 15:59:27,259] DEBUG - wire HTTP-Listener I/O dispatcher-4 << "Content-Encoding: gzip[\r][\n], it seems the content-encoding is in gzip format. Please skip that header from the client when invoking the API.
import java.util.ArrayList;
import java.util.List;
import javax.swing.plaf.synth.SynthSeparatorUI;
import javax.xml.namespace.QName;
import javax.xml.stream.FactoryConfigurationError;
import javax.xml.stream.XMLOutputFactory;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
import org.apache.axiom.om.OMAbstractFactory;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMFactory;
import org.apache.axiom.om.OMNamespace;
import org.apache.axis2.Constants;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.client.ServiceClient;
import org.apache.axis2.transport.http.HTTPConstants;
import org.apache.axis2.transport.http.HttpTransportProperties;
import org.apache.commons.httpclient.auth.AuthPolicy;
import com.custom.ntlm.CustomNTLMAuthScheme;
public class TestNTLMAxis {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("Start of test.");
String serviceURL = "xxxx";
String endpointReference = null;
AuthPolicy.registerAuthScheme(AuthPolicy.NTLM, CustomNTLMAuthScheme.class);
Options options = new Options();
options.setTo(new EndpointReference(serviceURL));
options.setTransportInProtocol(Constants.TRANSPORT_HTTP);
options.setProperty(HTTPConstants.CHUNKED, Boolean.FALSE);
options.setProperty(Constants.Configuration.ENABLE_REST, Constants.VALUE_TRUE);
options.setProperty(HTTPConstants.AUTHENTICATE,Constants.VALUE_TRUE);
List<String> authSchema = new ArrayList();
authSchema.add(HttpTransportProperties.Authenticator.NTLM);
HttpTransportProperties.Authenticator ntlmAuthentication = new HttpTransportProperties.Authenticator();
ntlmAuthentication.setAuthSchemes(authSchema);
ntlmAuthentication.setUsername("xxxxxx");
ntlmAuthentication.setPassword("xxxxxxx");
ntlmAuthentication.setHost("xxx.xxx.xxx.xxx");
ntlmAuthentication.setDomain("mydoamin");
ntlmAuthentication.setAllowedRetry(true);
options.setProperty(org.apache.axis2.transport.http.HTTPConstants.AUTHENTICATE, ntlmAuthentication);
options.setProperty(Constants.Configuration.HTTP_METHOD, Constants.Configuration.HTTP_METHOD_POST);
try {
ServiceClient sender = new ServiceClient();
sender.engageModule(Constants.MODULE_ADDRESSING);
sender.setOptions(options);
sender.cleanupTransport();
OMElement result = sender.sendReceive(getPayload());
XMLStreamWriter writer = XMLOutputFactory.newInstance()
.createXMLStreamWriter(System.out);
result.serialize(writer);
writer.flush();
} catch (XMLStreamException e) {
e.printStackTrace();
} catch (FactoryConfigurationError e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
} // I am getting a 415 unsupported media type
I am trying to connect to an endpoint secured with active directory authentication, I am using the CustomNtlm mediator suggested on the Nipuna's blog and I am getting a 401 unauthorized, I have followed all the steps in the blog post mentioned above.
Can anyone assist me.
I have tried the code specified on Nipuna's blog. I am trying to send a json message and I am expecting a json response message.
https://medium.com/#nipunadilhara/ntlm-authentication-for-wso2-esb-v6-2-0-9584c3e6713
<class name="com.custom.ntlm.NTLMMediator">
<property name="username" value="username"/>
<property name="host" value="xxx.xxx.xxx.xxx"/>
<property name="ntlmVersion" value="v2"/>
<property name="domain" value="mydomain"/>
<property name="password" value="xxxxxxxx"/>
</class>
<log level="full"/>
<class name="com.custom.ntlm.NTLMCalloutMediator">
<property name="serviceURL" value="http://myhostname:myhostport"/>
<property name="initAxis2ClientOptions" value="false"/>
</class>
<log level="full"/>
<header action="remove" name="To" scope="default"/>
<log level="full"/>
<property name="RESPONSE" scope="default" type="STRING" value="true"/>
<property action="remove" name="NO_ENTITY_BODY" scope="axis2"/>
<send/>
<class name="com.custom.ntlm.NTLMMediator">
<property name="username" value="username"/>
<property name="host" value="xxx.xxx.xxx.xxx"/>
<property name="ntlmVersion" value="v2"/>
<property name="domain" value="mydomain"/>
<property name="password" value="xxxxxxxx"/>
</class>
<log level="full"/>
<class name="com.custom.ntlm.NTLMCalloutMediator">
<property name="serviceURL" value="http://myhostname:myhostport"/>
<property name="initAxis2ClientOptions" value="false"/>
</class>
<log level="full"/>
<header action="remove" name="To" scope="default"/>
<log level="full"/>
<property name="RESPONSE" scope="default" type="STRING" value="true"/>
<property action="remove" name="NO_ENTITY_BODY" scope="axis2"/>
<send/>
Wire logs
[2019-05-29 09:15:05,963] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 >> "POST /solar/management/documentmanagement/savedocument HTTP/1.1[\r][\n]"
[2019-05-29 09:15:05,969] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 >> "Content-Type: application/json[\r][\n]"
[2019-05-29 09:15:05,979] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 >> "User-Agent: PostmanRuntime/7.13.0[\r][\n]"
[2019-05-29 09:15:05,980] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 >> "Accept: */*[\r][\n]"
[2019-05-29 09:15:05,981] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 >> "Cache-Control: no-cache[\r][\n]"
[2019-05-29 09:15:05,987] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 >> "Postman-Token: 03b5e8d9-06ab-4eae-98f4-c22085974d8e[\r][\n]"
[2019-05-29 09:15:05,995] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 >> "Host: 172.16.221.96:8280[\r][\n]"
[2019-05-29 09:15:06,000] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 >> "accept-encoding: gzip, deflate[\r][\n]"
[2019-05-29 09:15:06,002] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 >> "content-length: 532[\r][\n]"
[2019-05-29 09:15:06,007] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 >> "Connection: keep-alive[\r][\n]"
[2019-05-29 09:15:06,010] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 >> "[\r][\n]"
[2019-05-29 09:15:06,015] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 >> "{[\n]"
[2019-05-29 09:15:06,020] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 >> " "systemName": "Main",[\n]"
[2019-05-29 09:15:06,021] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 >> " "authenticatedAdDomain": "domain",[\n]"
[2019-05-29 09:15:06,022] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 >> " "authenticatedAdUser": "johns",[\n]"
[2019-05-29 09:15:06,029] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 >> " "parentNodeName": "LEGISLATION",[\n]"
[2019-05-29 09:15:06,031] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 >> " "childNodeName": "Policy",[\n]"
[2019-05-29 09:15:06,036] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 >> " "fileMetaData": {[\n]"
[2019-05-29 09:15:06,037] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 >> " "Document Title": "MyDocument",[\n]"
[2019-05-29 09:15:06,038] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 >> " "Document Date": "2019-04-18 14:04:00.000",[\n]"
[2019-05-29 09:15:06,046] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 >> " "Ref No": "REF000054-12",[\n]"
[2019-05-29 09:15:06,048] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 >> " "Document Author": "John Smith",[\n]"
[2019-05-29 09:15:06,053] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 >> " "Category": "50",[\n]"
[2019-05-29 09:15:06,053] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 >> " "Type": "Type1"[\n]"
[2019-05-29 09:15:06,054] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 >> " },[\n]"
[2019-05-29 09:15:06,056] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 >> " "fileName": "TestResults.pdf",[\n]"
[2019-05-29 09:15:06,065] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 >> " "fileType": "Adobe Pdf",[\n]"
[2019-05-29 09:15:06,069] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 >> " "fileContent": "VGhpcyBpcyBmaWxlIGNvbnRlbnQ="[\n]"
[2019-05-29 09:15:06,070] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 >> "}"
[2019-05-29 09:15:06,071] [] DEBUG - headers http-incoming-6 >> POST /solar/management/documentmanagement/savedocument HTTP/1.1
[2019-05-29 09:15:06,072] [] DEBUG - headers http-incoming-6 >> Content-Type: application/json
[2019-05-29 09:15:06,080] [] DEBUG - headers http-incoming-6 >> User-Agent: PostmanRuntime/7.13.0
[2019-05-29 09:15:06,082] [] DEBUG - headers http-incoming-6 >> Accept: */*
[2019-05-29 09:15:06,087] [] DEBUG - headers http-incoming-6 >> Cache-Control: no-cache
[2019-05-29 09:15:06,088] [] DEBUG - headers http-incoming-6 >> Postman-Token: 03b5e8d9-06ab-4eae-98f4-c22085974d8e
[2019-05-29 09:15:06,090] [] DEBUG - headers http-incoming-6 >> Host: 172.16.221.96:8280
[2019-05-29 09:15:06,099] [] DEBUG - headers http-incoming-6 >> accept-encoding: gzip, deflate
[2019-05-29 09:15:06,104] [] DEBUG - headers http-incoming-6 >> content-length: 532
[2019-05-29 09:15:06,105] [] DEBUG - headers http-incoming-6 >> Connection: keep-alive
[2019-05-29 09:15:06,252] [] DEBUG - NTLMMediator [NTLMMediator] mediate method Invoked.
[2019-05-29 09:15:06,255] [] DEBUG - NTLMMediator [NTLMMediator] NTLM version is: v2
[2019-05-29 09:15:06,278] [] INFO - LogMediator To: /solar/management/documentmanagement/savedocument, MessageID: urn:uuid:77031c2d-3b97-41fe-916e-f4784cad389e, Direction: request, Envelope: <?xml version='1.0' encoding='utf-8'?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><jsonObject><userCode>johns</userCode></jsonObject></soapenv:Body></soapenv:Envelope>
[2019-05-29 09:15:06,294] [] DEBUG - NTLMCalloutMediator [NTLMCalloutMediator] mediate method Invoked.
[2019-05-29 09:15:06,298] [] DEBUG - NTLMCalloutMediator [NTLMCalloutMediator] Message : <?xml version='1.0' encoding='utf-8'?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><jsonObject><userCode>johns</userCode></jsonObject></soapenv:Body></soapenv:Envelope>
[2019-05-29 09:15:06,304] [] INFO - NTLMCalloutMediator Inside Mediator initClientoption : false
[2019-05-29 09:15:06,310] [] DEBUG - NTLMCalloutMediator [NTLMCalloutMediator] About to invoke service : http://192.168.12.98:8081/api/HTTPORBSY110Api
[2019-05-29 09:15:06,322] [] DEBUG - NTLMCalloutMediator [NTLMCalloutMediator] Request message payload : <jsonObject><userCode>johns</userCode></jsonObject>
[2019-05-29 09:15:06,342] [] DEBUG - CustomNTLMAuthScheme [CustomNTLMAuthScheme] processChallenge Invoked.
[2019-05-29 09:15:06,345] [] DEBUG - CustomNTLMAuthScheme [CustomNTLMAuthScheme] NTLM Scheme Authentication Method Invoked.
[2019-05-29 09:15:06,352] [] DEBUG - CustomNTLMAuthScheme [CustomNTLMAuthScheme] The NTLM version going to use is: v2
[2019-05-29 09:15:06,359] [] DEBUG - CustomNTLMAuthScheme [CustomNTLMAuthScheme] Type1Message Generated.
[2019-05-29 09:15:06,369] [] DEBUG - CustomNTLMAuthScheme [CustomNTLMAuthScheme] processChallenge Invoked.
[2019-05-29 09:15:06,371] [] DEBUG - CustomNTLMAuthScheme [CustomNTLMAuthScheme] NTLM Scheme Authentication Method Invoked.
[2019-05-29 09:15:06,372] [] DEBUG - CustomNTLMAuthScheme [CustomNTLMAuthScheme] The NTLM version going to use is: v2
[2019-05-29 09:15:06,373] [] DEBUG - CustomNTLMAuthScheme [CustomNTLMAuthScheme] Type2Message Received.
[2019-05-29 09:15:06,381] [] DEBUG - CustomNTLMAuthScheme [CustomNTLMAuthScheme] Type3Message Generated.
[2019-05-29 09:15:06,724] [] DEBUG - headers http-incoming-6 << HTTP/1.1 202 Accepted
[2019-05-29 09:15:06,725] [] DEBUG - headers http-incoming-6 << Date: Wed, 29 May 2019 07:15:06 GMT
[2019-05-29 09:15:06,730] [] DEBUG - headers http-incoming-6 << Transfer-Encoding: chunked
[2019-05-29 09:15:06,732] [] DEBUG - headers http-incoming-6 << Connection: keep-alive
[2019-05-29 09:15:06,738] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 << "HTTP/1.1 202 Accepted[\r][\n]"
[2019-05-29 09:15:06,745] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 << "Date: Wed, 29 May 2019 07:15:06 GMT[\r][\n]"
[2019-05-29 09:15:06,747] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 << "Transfer-Encoding: chunked[\r][\n]"
[2019-05-29 09:15:06,752] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 << "Connection: keep-alive[\r][\n]"
[2019-05-29 09:15:06,754] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 << "[\r][\n]"
[2019-05-29 09:15:06,765] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 << "0[\r][\n]"
[2019-05-29 09:15:06,768] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 << "[\r][\n]"