Not able to read response from file #159

Closed
opened 2025-12-29 08:23:04 +01:00 by adam · 12 comments
Owner

Originally created by @arpymastro on GitHub (Dec 17, 2018).

I am trying to read a .xml response kept in a separate file under my mappings folder.
I have two files under my mappings folder - MyJsonReq.json and MyXmlResponse.xml
MyJsonReq.json -

/// snip ///

If I check the logs it is showing - could not be read.This file will be skipped for both MyJsonReq.json and MyXmlResponse.xml

Originally created by @arpymastro on GitHub (Dec 17, 2018). I am trying to read a .xml response kept in a separate file under my mappings folder. I have two files under my mappings folder - `MyJsonReq.json` and `MyXmlResponse.xml` MyJsonReq.json - /// snip /// If I check the logs it is showing - `could not be read.This file will be skipped` for both MyJsonReq.json and MyXmlResponse.xml
adam added the bug label 2025-12-29 08:23:04 +01:00
adam closed this issue 2025-12-29 08:23:04 +01:00
Author
Owner

@StefH commented on GitHub (Dec 17, 2018):

I've fixed you example, the "Headers" where wrongly defined.

It should be:

{
	"Request": {
        "Path": {
            "Matchers": [
                {
                    "Name": "WildcardMatcher",
                    "Pattern": "/myreq",
                    "IgnoreCase": false
                }
            ]
        },
        "Methods": [
            "post"
        ]
	},
	"Response":	{
		"StatusCode": 201,
		"Headers": {"Content-Type": "application/xml"},
    	        "BodyDestination": "SameAsSource",
   		"BodyAsFile": "MyXmlResponse.xml",
                "UseTransformer": false	
	}
}

Can you try this?

@StefH commented on GitHub (Dec 17, 2018): I've fixed you example, the "Headers" where wrongly defined. It should be: ``` js { "Request": { "Path": { "Matchers": [ { "Name": "WildcardMatcher", "Pattern": "/myreq", "IgnoreCase": false } ] }, "Methods": [ "post" ] }, "Response": { "StatusCode": 201, "Headers": {"Content-Type": "application/xml"}, "BodyDestination": "SameAsSource", "BodyAsFile": "MyXmlResponse.xml", "UseTransformer": false } } ``` Can you try this?
Author
Owner

@arpymastro commented on GitHub (Dec 17, 2018):

@StefH - nope still it doesn't work and shows the same logs.
FYI - If I give full path (C://folder//folder//__admin/mappings//MyXmlResponse.xml) of my response file it works.
Is there a way to do it relatively? my response and request files both are in same mappings folder

@arpymastro commented on GitHub (Dec 17, 2018): @StefH - nope still it doesn't work and shows the same logs. FYI - If I give full path (C://folder//folder//__admin/mappings//MyXmlResponse.xml) of my response file it works. Is there a way to do it relatively? my response and request files both are in same mappings folder
Author
Owner

@StefH commented on GitHub (Dec 17, 2018):

The error message is like:

2018-12-17 07:41:17 [Info] : Reading Static MappingFile : 'c:\temp-wiremock\__admin\mappings\MyXmlResponse.xml'
2018-12-17 07:41:17 [Error] : Static MappingFile : 'c:\temp-wiremock\__admin\mappings\MyXmlResponse.xml' could not be read. This file will be skipped.

This is correct, however WireMock should only read .json files and not others.

And there is a problem reading files with no path.
For now you need to use full path "BodyAsFile": "C:\\temp-wiremock\\__admin\\mappings\\MyXmlResponse.xml",

I'll check if I can update this.

See also https://github.com/WireMock-Net/WireMock.Net/issues/56

@StefH commented on GitHub (Dec 17, 2018): The error message is like: ``` sh 2018-12-17 07:41:17 [Info] : Reading Static MappingFile : 'c:\temp-wiremock\__admin\mappings\MyXmlResponse.xml' 2018-12-17 07:41:17 [Error] : Static MappingFile : 'c:\temp-wiremock\__admin\mappings\MyXmlResponse.xml' could not be read. This file will be skipped. ``` This is correct, however WireMock should only read .json files and not others. And there is a problem reading files with no path. For now you need to use full path `"BodyAsFile": "C:\\temp-wiremock\\__admin\\mappings\\MyXmlResponse.xml",` I'll check if I can update this. See also https://github.com/WireMock-Net/WireMock.Net/issues/56
Author
Owner

@arpymastro commented on GitHub (Dec 17, 2018):

If I keep "BodyAsFile" : "MyXmlResponse.xml" in my MyJsonReq.json file then i get could not be read. This file will be skipped. for both files.

If I keep "BodyAsFile" : "C:/my_full_path_to/MyXmlResponse.xml" then i get could not be read. This file will be skipped. for MyXmlResponse.xml file, which is expected.

@arpymastro commented on GitHub (Dec 17, 2018): If I keep `"BodyAsFile" : "MyXmlResponse.xml"` in my MyJsonReq.json file then i get `could not be read. This file will be skipped.` for **both** files. If I keep `"BodyAsFile" : "C:/my_full_path_to/MyXmlResponse.xml"` then i get `could not be read. This file will be skipped.` for **MyXmlResponse.xml** file, which is expected.
Author
Owner

@StefH commented on GitHub (Dec 17, 2018):

@arpymastro

If you like, you can use the NuGet from MyGet 1.0.7-ci-1623 to test this fixed code.
(see https://github.com/WireMock-Net/WireMock.Net/wiki/MyGet-preview-versions)

@StefH commented on GitHub (Dec 17, 2018): @arpymastro If you like, you can use the NuGet from MyGet 1.0.7-ci-1623 to test this fixed code. (see https://github.com/WireMock-Net/WireMock.Net/wiki/MyGet-preview-versions)
Author
Owner

@StefH commented on GitHub (Dec 20, 2018):

@arpymastro Are you able to use the test version MyGet 1.0.7-ci-1623 ?

@StefH commented on GitHub (Dec 20, 2018): @arpymastro Are you able to use the test version `MyGet 1.0.7-ci-1623` ?
Author
Owner

@StefH commented on GitHub (Jan 9, 2019):

@arpymastro Did you have time to check?

@StefH commented on GitHub (Jan 9, 2019): @arpymastro Did you have time to check?
Author
Owner

@StefH commented on GitHub (Jan 19, 2019):

Code merged to master branch and a new NuGet will be created shortly.

@StefH commented on GitHub (Jan 19, 2019): Code merged to master branch and a new NuGet will be created shortly.
Author
Owner

@NoahLerner commented on GitHub (Dec 2, 2019):

I still have this issue. Logs show a perfect match but the file content is not being returned by the proxy.

I've tried setting absolute and relatives paths already.. neither worked.

@NoahLerner commented on GitHub (Dec 2, 2019): I still have this issue. Logs show a perfect match but the file content is not being returned by the proxy. I've tried setting absolute and relatives paths already.. neither worked.
Author
Owner

@StefH commented on GitHub (Dec 2, 2019):

@thewholuver94 Please create a full example project to show this error.

@StefH commented on GitHub (Dec 2, 2019): @thewholuver94 Please create a full example project to show this error.
Author
Owner

@NoahLerner commented on GitHub (Dec 2, 2019):

Just reading through some of the other issues -- specifically #179 -- I'm using the ReadStaticMappings and WatchStaticMappings features, but in the JSON I want to define BodyAsFile... is that allowed? Thanks

@NoahLerner commented on GitHub (Dec 2, 2019): Just reading through some of the other issues -- specifically #179 -- I'm using the ReadStaticMappings and WatchStaticMappings features, but in the JSON I want to define BodyAsFile... is that allowed? Thanks
Author
Owner

@NoahLerner commented on GitHub (Dec 2, 2019):

The issue was local... The xml format that I saved in added extra white space and the service I was proxying refused the entire response with the extra white space. Everything is working as it should. Thanks.

@NoahLerner commented on GitHub (Dec 2, 2019): The issue was local... The xml format that I saved in added extra white space and the service I was proxying refused the entire response with the extra white space. Everything is working as it should. Thanks.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WireMock.Net#159