How to force UTF-8 encoding in Mule4 - anypoint-studio

When we started implementing Mulesoft as a pilot in our company, we noticed that mulesoft would inherit the system codepage (windows-1252) at seemingly random moments. Despite setting the Anypoint studio (7.2.0) preference, and runtime (4.2.1 EE) defaults to UTF-8. Therefore the outgoing connectors (and default http connectors) would send their http requests in this encoding. Any API we write then gave the following error:
Message : HTTP PUT on resource 'https://mocksvc-proxy.anypoint.mulesoft.com:443/exchange/*********/1.0.2/subscription' failed: media type application/json; charset=windows-1252 not supported (415).
We found that the solution for this was to set the encoding on a message transform right before the connector to force it to UTF-8 like this:
<ee:transform doc:name="Transform Message" doc:id="-redacted-">
<ee:message>
<ee:set-payload><![CDATA[%dw 2.0
output application/json encoding="UTF-8"
---
{
"applicatie": "-redacted-",
"clientid": vars."-redacted-" as Number
}]]></ee:set-payload>
</ee:message>
</ee:transform>
However since anypoint studio 7.2.1 this fix no longer works.
I can't find anything we've changed, and all settings are still set to UTF-8.
Project setting set to UTF-8 image
Does anyone know of a method we can try to force the encoding, or get the api's we build to accept windows-1252? (which would be acceptable but not preferable, if at all possible)
Or do you think that this is a bug we need to report to mulesoft?
This problem is occuring on Mule Standalone EE Version: 4.1.2 Build: 41de9970 on
Windows server 2016 Datacenter.
Anypoint studio embedded Mule 4.1.2
on Windows 7.

The code and sollutions tried above are correct, it was a bug in mule runtime 4.2.1(.2).
It is fixed in version 4.1.3(.2), if you encounter this problem, update to fix it.

Related

Weblogic.wsee.jaxrpc.soapfault.WLSOAPFaultException: Old Format Work Area Header Is Disabled Exception Post WebLogic Upgrade

After the upgrade of weblogic to newer version I started facing an error with different application conectivity.
RequestDumpingFilter Response; Content=<?xml version="1.0" encoding="UTF-8" standalone="yes"?><StatusBadGateway xmlns="http://types.xxx"><BackendSystem>Infomatica</BackendSystem><BackendServiceCall>getUsage</BackendServiceCall><ErrorMessage>RuntimeException when calling getUsage. javax.xml.ws.WebServiceException: Old format work area header is disabled.</ErrorMessage></StatusBadGateway>
Does anyone knows the solution? How to fix this?
Issue is caused due to old headers in use even after upgrade, no common soap header format is in use. See below.
APPLIES TO:
Oracle WebLogic Server - Version 12.2.1.0.0 and later
Information in this document applies to any platform.
SYMPTOMS
WebLogic has recently been upgraded to WebLogic 12.2.1.2 from 9.2. Post upgrade, the webservice request is not working with
below header format exception.
Jun 12, 2017 7:04:03 AM CDT> - [Error in invoking service : java.rmi.RemoteException:
SOAPFaultException - FaultCode [{http://schemas.xmlsoap.org/soap/envelope/}Server] FaultString [Old
format work area header is disabled.
] FaultActor [null] Detail [javax.xml.rpc.JAXRPCException: Old format work area header is disabled.
]; nested exception is:
weblogic.wsee.jaxrpc.soapfault.WLSOAPFaultException: Old format work area header is disabled.
SOLUTION
Make sure common same SOAP header format is in use between webservice communications, else disable the work area header
validation using the flag below:
-Dweblogic.wsee.workarea.skipWorkAreaHeader=true

Spring Boot, Apache CXF 3.2.5 with MTOM sends empty attachment

I'm having a weird issue with Apache CXF and large (375MB) MTOM attachments are empty.
Running it locally in Eclipse produces the desired results, but deploying it to our server just gives an empty attachment.
The server is written in .NET and doesn't support chunking. With Chunking enabled the client works, but when i disable cunking it fails.
Sadly i'm unable to debug on the server, so i'm restricted to trace logging.
I've tried every trick i've been able to google.
Disable schema validation (CXF-4551) (CXF-7758)
Manually copying the file to java.io.tmpdir before sending, to ensure it can be read.
Custom DataSource
Disable WS-Security
Disable logging interceptor
Nothing seems to make a difference.
Every run i just get something like the following
</soap:Body></soap:Envelope>
--uuid:40ef745b-ac3c-4013-bbe7-a9cc28880423
Content-Type: application/xml
Content-Transfer-Encoding: binary
Content-ID: <7611ca0a-22f8-4637-b4f7-a5dfe7f20b81-3#www.somewhere.dk>
Content-Disposition: attachment;name="32_2018-03-28_output.xml"
--uuid:40ef745b-ac3c-4013-bbe7-a9cc28880423
Trying with a smaller (2KB) file on the server works just fine. A 75MB file gets attached correctly, but results in a HTTP 400 from the receiver (which i suspect is because the file is not fully transferred)
Does anyone have any ideas as to what might be causing this ?
After much trial & error, i finally managed to "solve" this. I enabled schema validation, and the data now appears. This is the exact issue that both bugs in my original question claims to fix.
Client client = ClientProxy.getClient(port);
BindingProvider bp = ((BindingProvider) port);
bp.getRequestContext().put("schema-validation-enabled", "true");
I can't add a comment so I'm posting this as an answer.
Jimmy could you perhaps comment on the latest CXF issue and provide some more details? Which version of CXF, what kind of client you are using, real code samples ideally, client logs?

Openshift origin application with JBoss developer studio

I am using openshift origin and JBoss developer studio 9
When i am trying to create new application using oc new-app in open shift command it working well but when i tried to create any project with jboss studio it give me the following error
"the body of the request was in an unknown format - accepted media types include: application/json, application/yaml
Could not create resource res in namespace '': {"kind":"Status","apiVersion":"v1","metadata":{},"status":"Failure","message":"the body of the request was in an unknown format - accepted media types include: application/json, application/yaml","reason":"UnsupportedMediaType","code":415}"
Please note that this error occurred also when i tried to deploy an image from openshift and i am using all in one openshift origin vm
Any help highly appreciated.
You may need to update your release of developer studio which relies upon the openshift-restclient-java. https://github.com/openshift/openshift-restclient-java/pull/112 resolved an issue where the content-type was not being set.

Why would my Mule project suddenly start complaining about "Invalid keystore format"

While trying to learn how to use the Imap connector in Mule studio, I came across this tutorial. I downloaded it and imported it into AnyPoint studio as a project, and as it were in that tutorial, it worked great (after sending the connector to the right host/port etc.) I then did a quick edit to change the flow to something like this:
IMAP response -> Email to String transormer -> Log this string in the console
And all was well and good. I then went in to the properties of the connector configuration, and changed it so that emails would not be deleted after they're read in, and everything broke. When trying to run the Mule project, I get a long list of errors, starting with:
java.io.IOException: Invalid keystore format
And later down the list:
org.mule.module.launcher.DeploymentInitException: IOException: Invalid keystore format
Which is relentlessly frustrating because really I didn't do anything to the connector's configuration aside from allowing it to keep emails in the inbox of the email that is being used in the IMAP connector. Even if doing something like that were to throw this kind of exception, after changing the configuration back to the way it was when the tutorial was working fine, I still get the same errors and the project fails to deploy.
I suspect that you edited the flow in visual mode instead of XML and that Studio has transformed this (which came from the download):
<imaps:connector checkFrequency="100" doc:name="IMAP" name="imapsConnector" validateConnections="true">
</imaps:connector>
into that:
<imaps:connector checkFrequency="100" doc:name="IMAP" name="imapsConnector" validateConnections="true">
<imaps:tls-client path="" storePassword="" />
<imaps:tls-trust-store path="" storePassword="password" />
</imaps:connector>
i.e. empty tls element(s) got injected thus messing your configuration up.

Mule SFTP credentials

Mule 3.3.1 CE
The SFTP endpoint appears to have problems with user names with the '#' character in them. For example, both of the following fail although the address works in other tools.
<sftp:outbound-endpoint address="sftp://test04#caqa.com:Test1234#testftpdev.caqa.com" outputPattern="#[function:datestamp].xml"/>
<sftp:outbound-endpoint exchange-pattern="one-way" outputPattern="#[function:datestamp].xml" host="testftpdev.caqa.com" port="22" path="/" user="test04#caqa.com" password="Test1234" responseTimeout="10000"/>
The error message is:
Error during login to null#null
com.jcraft.jsch.JSchException: username must not be null.
...etc.
Trying against a site that allows user names without the '#' (e.g., 'test04') seems to work fine through the connector.
Since I have no control over the user names at some of the required target sites, does anyone know of a workaround for this? It needs to run in 3.3.1 CE as we won't be onto 3.4 Enterprise for another couple of months.
You need to URL encode the name and password to take care of this situation.