I have made api documention with the help of swagger-editor. Now I want see it graphically with the help of swagger-ui. I have deployed my json here https://powerful-escarpment-92284.herokuapp.com/swagger.json
Now When I am trying to access it then I am getting an error
Failed to load spec.
I solved this by setting this header in the response of swagger.json file.
app.get('/:file(*)', function(req, res, next){
var file = req.params.file, path = __dirname + '/' + file;
console.log('.');
res.header('Access-Control-Allow-Origin', '*');
res.download(path);
});
I was getting this error in a c# project, due to a problem with a controller I added.
I could get more information by trying to browse to the swagger.json
It turned out I was missing the routing attribute on a controller action.
After many exercises for me apparently, it helped just to serve a file with flask server [How to serve static files in Flask. and (important) add "?" to the end of the url, i.e. http://127.0.0.1/js/swagger.json?
The URL is not shown, so I assume if you access the swagger directly via "index.html" or any other way, the URL format must be like this.
http://<host>:<port>/<project_name>/_swagger-ui/index.html?url=http://<host>:<port>/<project_name>/<path>/swagger.json
like:
http://localhost:8080/counter/_swagger-ui/index.html?url=http://localhost:8080/counter/webapi/swagger.json
I hope, it helps :)
Related
I use spring unit test with spring-restdocs.
this is my mockmvc code:
mockMvc.perform(fileUpload("/api/enterprise/uploadImage")
.file(imageFile)
.with(csrf().asHeader())
.params(params)
).andExpect(status().isOk());
but when use spring-restdocs I don't how to write the snippet of file filed.
this is my snippets create code:
document.snippets(
requestParameters(
parameterWithName("file").description("upload file"),
parameterWithName("imageType").description("image type")
)
);
in this way I get an error:
org.springframework.restdocs.snippet.SnippetException: Request parameters with the following names were not found in the request: [file]
at org.springframework.restdocs.request.RequestParametersSnippet.verificationFailed(RequestParametersSnippet.java:79)
at org.springframework.restdocs.request.AbstractParametersSnippet.verifyParameterDescriptors(AbstractParametersSnippet.java:93)
at org.springframework.restdocs.request.AbstractParametersSnippet.createModel(AbstractParametersSnippet.java:70)
at org.springframework.restdocs.snippet.TemplatedSnippet.document(TemplatedSnippet.java:64)
at org.springframework.restdocs.mockmvc.RestDocumentationResultHandler.handle(RestDocumentationResultHandler.java:101)
at org.springframework.test.web.servlet.MockMvc.applyDefaultResultActions(MockMvc.java:195)
at org.springframework.test.web.servlet.MockMvc.perform(MockMvc.java:163)
at com.athena.edge.enterprise.controller.UploadImageTest.uploadImage(UploadImageTest.java:108)
You're sending a multi-part request so the file that's being uploaded isn't a request parameter. Instead, it's one of the parts in the request and
your test is failing because you're trying to document a request parameter that doesn't exist.
Spring REST Docs doesn't have support for documenting parts in a multipart request at the moment. There is an open issue for it. I haven't implemented anything yet as request parts can be quite complex. For example, in some cases the part name and a description may be sufficient but in others it may be useful to document the part's headers, the structure of its content, etc.
Please comment on the issue linked to above, particularly if support for the simplest case would be useful.
Since the release of version 1.1.0.RELEASE of spring-restdocs you can use RequestPartsSnippet.
You can now write spring-restdocs snippets with MockMultipartFile as the following:
mockMvc.perform(multipart("/upload").file("file", "example".getBytes()))
.andExpect(status().isOk())
.andDo(document("upload", RequestPartsSnippet.requestParts(
RequestPartDescriptor.partWithName("file").description("The file to upload"))
));
This example is taken from the official documentation here.
I have a URL shortner that should sendRedirect(URL) to URLs specified by users.
Sometimes URL contain curly braces like this: http://example.com?someparam={something}.
Instead of sending response 302 to client browser, my Spring MVC app at Tomcat server gives error 404 with no text.
Apparently it's some sort of URL variable evaluation taking place, can I disable it? I could not find docs regarding this feature.
I know this is an old question but I think the OP was looking for a way to prevent Spring from doing variable replacement in redirect URL
I faced the exact same issue and the fix was using RedirectView
and in RedirectView you can set setExpandUriTemplateVariables(false)
that made it redirect to the url given exactly without Spring trying to replace anything in it
here is how the code looks like
RedirectView redirect = new RedirectView(redirectUrl);
redirect.setExpandUriTemplateVariables(false);
return new ModelAndView(redirect);
Hope that helps
This is not valid Google search URL http://google.com/{something}. It should have been https://www.google.ca/search?q=http{302}
Emphasis is on search?q. After domain name you have specify your service name and then query string if you want to pass some inputs.
When you do http://google.com/{something} then you really do not have any resource or service as {something} so 404 is the expected output.
HTTP 302 is for redirection, I am not sure why you were expecting redirection.
URL encoding will also not help because issue is related to resource/service, if it is not present then you will get 404. URL encoding is not meant to solve problem related to 404.
Sorry if this is a duplicate question but google isn't smart enough to understand me or I'm too dumb to express my question simple enough for it to understand.
I don't know if this is my problem but I'm 90% sure this is it.
I'd like to know how to represent a Unix path within a GET request so that my web service doesn't return a 404. I think it's because one of my JSON fields in the query is a Unix path and because of the slashes, the webservice thinks it's part of the URL and not a part of my query.
For example, I'm using a RESTClient that's an add-on to Mozilla to test my web service. For the POST request, I enter as the url
http://mytestserver:8080/mydir/
and in the body, I put in my JSON object
{"filename":"obit.jpg", "Path":"test/2/1"}
This method works fine. I get a status code 200 and a return JSON object with the expected output.
When I use the same string for a GET request, I get a status code 404 and no return JSON object. I put as the url in the RESTClient
http://mytestserver:8080/mydir/{"filename":"obit.jpg", "Path":"test/2/1"}
and I get a status code 404 and the response body just says 404 - Not found
To further test my theory, I entered the following url in a GET request, removing the /2/1 from the path, which works.
http://mytestserver:8080/mydir/{"filename":"obit.jpg", "Path":"test"}
I've tried encapsulating the whole JSON string in quotes but that didn't work either so I've run out of things to try.
Thanks in advance for any help you can give me. If I need to show some code, please let me know, although, I don't think it's a code problem, I think it's a representation problem. Thanks.
Found out that JSON objects are usually sent via POST, not GET. Since I appended it to the URL via GET, it gave me problems. Per How to send a GET request with a "/" in the query
I want to fetch current URL with free marker.
Also i need to split the url href part.Is there any method similar to JavaScript method location.href.
Ex: http://www.barcamp.com/homepage/overview.go.
Here i need to fetch the url & also to the split the url and get its as /homepage/overview.go
Please help us on this issue
Getting the current URL falls outside FreeMarker's jurisdiction, since it's independent of Servlets and HTTP. It's up to the Web application framework if and how it exposes that information for the templates, so check the documentation of the framework.
I want to allow the user to save file using mvc portlet. In my code i am making an ajax call hence it has to be a resource response.
response.setContentType( "application/octet-stream" );
response.setProperty("Content-Disposition","attachment; filename=\""+fname+"\"");
response.setContentLength(b.length);
OutputStream po= response.getPortletOutputStream();
po.write(b,0,b.length);
po.flush();
po.close();
In ajax response when i do alert(resp), I am getting the whole content of my file in alert but still not getting any option for download.
Please help and thanks in advance ;)
Well, since you get the response, you need to allow the user to download it. You can for example use the HTML data: protocol and redirect the browser to smt. like
data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAyAA...
for a PNG image.
Anyway, can't you use a normal request to a portlet? It's trivial then.