I have ASP.NET WebApi configured with Swashbuckle to show swagger ui. I run it from within VS in IIS Express.
The solution was in VS 2013 and it worked fine. After migration to VS 2015 the swagger shows no methods. There's no error, just empty list. The response returned is:
{"swagger":"2.0","info":{"version":"v4","title":"Swashbuckle Dummy API V4"},"host":"localhost:35622","schemes":["http"],"paths":{},"definitions":{}}
I checked the troubleshooting chapter in documentation but based on it the configuration is ok.
What can I try next?
I have found the problem. I briefly describe the situation:
We have versioned API and use custom ControllerSelector (derived from DefaultHttpControllerSelector) to select the right version of the controller. (The API version is taken from Http header.) There are subfolders in Controllers folder (like V1, V2, ..) and the controller classes are placed in those subfolders.
Generally, for documentation generation it is used ApiExplorer class fed by DefaultHttpControllerSelector, which internally manages list of HttpControllerDescriptors keyed by controller name (the short name without 'Controller' suffix). When it builds this list it checks if the controller name has already been added to the list and if yes, it not only does not add the other one but also removes the one already added.
In our case it means there are no descriptors for controllers that have multiple versions.
I was able to fix it by overriding IHttpControllerSelector.GetControllerMapping() in our custom controller selector and passing in the controller name prefixed with version, which is also a valid route. Our custom ControllerSelector accepts also version passed in URL.
I have an application with Spring 3 and struts 2. I have my own properties files with custom messages. These files are loaded dynamically with spring while startup. And I use PropertyCache.getMessage() from any where in my code to get those custom messages. These message resources are fully controlled by my application and spring.
Now I have a scenario of file upload. The upload limit is configured in global struts constants and with "fileUpload" interceptors. As per the theory, when a user tries to upload big files the framework will show up its message (i know how to customize it with struts).
Since I am using my own resources, I want to show up my custom message (not going to use "struts.messages.error.file.too.large") using my own "PropertyCache.getMessage()" method.
How is it possible to override struts error message so that the framework will pick up the message from my own resource instead of struts constant/struts global properties?
Well i do not see any direct solutions to your problem as the above message is being set under the fileUploader interceptor,its quite possible that there might be some more flexible and best solution out there.
For now i can suggest you to create a FileUploaderInterceptor and you can use your Spring message reader functionality to read message from your custom message file and replace Struts2 getTextMessage() method
FileUploadInterceptor
I am using Struts 1.x for an application.
I want to know when the ActionForm instantiated.
The ActionServlet actually delegates the request processing job to it's RequestProcessor.
When a request arrives, either the doGet or the doPost method of the action servlet is invoked. Any of these method will call the action servlet's process method which inturn calls the request processor's process method. And that's where everything happen, roughly as follows -
Find the ActionMapping for current request.
Get (may be also create) the ActionForm instance.
Populate the form.
Validate the form.
Get (create) the Action instance.
Execute the action.
And finally either forward or redirect.
If you want (or need) to know in detail then you can always take a look at the source code. Followings are the links to the source codes for Struts 1.3.10 (you can also find sources for other versions of struts if that's not your version) -
org.apache.struts.action.ActionServlet
org.apache.struts.action.RequestProcessor
Well I want to study Struts so I am going to begin with Struts 1,
I would like to know the general flow. What files are required?
Whats the function of struts-config.xml? validation.xml? validation-rules.xml
When you visit your JSP page, and an action gets fired, what happens? What does the Action and Form class do? Which class is called first when an action gets fired.
I just downloaded a sample form, and all these files are confusing at first. I would like to know whats going on to get a better idea of Struts.
You should start with a tutorial on Struts, that will make it easy to understand :D. You can find plenty on the web, especially for Struts 1. Here is a starting point for example.
But just for the sake of it, here is a high view presentation.
First you add the Struts ActionServlet into your web.xml file and you configure it to accept requests that match a certain mapping. For Struts this is *.do (you can have whatever you want for this, *.do is just a convention in the Struts community).
Now, whatever arrives on the server with such a *.do URL pattern is sent to the ActionServlet.
Now, the content of struts-config.xml file comes into play. The ActionServlet is a front controller which just dispatches to other more appropriate resources for specific processing. Those specific resources are the Action classes.
You can have for example a LoginAction that must process requests that arrive on the login.do path. In the struts-config.xml you specify this: everything that comes on the login path must be sent to LoginAction class.
And you can have as many declarations as you want, for path x call XAction, for y call YAction etc etc.
Normally your client submits data to the server, data that he inputs into a HTML form. This data you need to process in your Action class. Now enter ActionForm.
The ActionForm is a bean that the Struts framework fills with the data from the HTML form. Instead of doing request.getParameter("foo") you can work with objects like formBean.getFoo() for example.
Once you do your processing in the Action class using the ActionForm, you then must present the results in some view (by the way, Struts is a MVC framework so you must know a stuff or two about this also).
The views are normally JSP files. When you return from your Action, you specify a "forward" location by name (i.e. to what view to go). Now again the information is in the struts-config.xml file where the name of the view is mapped to a JSP location.
The framework will then forward control to that JSP, the JSP presents the data which is then sent to the client as HTML (the client will no longer need to access JSPs directly - they must be hidden by the Struts framework).
In the new page the client again performs some requests and the process repeats.
Well, that's about as high presentation as it can get. Off course there is more than this, but you will discover them while learning about Struts.
As for the validator-rules.xml and validation.xml, those are used by the Validator framework which you can integrate with Struts by the use of a plugin (Struts has plugins you can use to add new stuff to it) to also add validation to the user's input.
Well, that is about it. You can find plenty of tutorials on the web offering more details but hope helps you get a better start.
Good luck!
When a user submitted a jsp page. that page having (attribute of
)action="login.do". the container will call to web.xml. in that
web.xml there are two sections servlet And servlet mapping
In servlet mapping it find *.do in the url-pattern. if it found to
take the name of servlet. and check the corresponding class. in the
servlet section. that class is ActionServlet.
ActionServlet is the controller of Struts module architecture. in
Action servlet having the service method. in that method we create
RequestPrecessor class instance
Service(req,res) RequestPrecessor rp = new RequestPrecessor();
We call a process method of RequestProcessor class through the
instance rp.process(req,res)
In the request processor class have the process method with the
parameter of req,res. then it has 1 if condition in this class.
that condition return always true. because that is dummy method.
Inside that condition there are 6 steps are processing
Create a action mapping instance in the Struts- Config.xml. it
will keep all details of the action mapping path, value, type
forward, validation=true/false, input
="*.jsp" etc these r created instance
Then it will create Form class instance before it check the name of
action mapping and form name are coincidence or not if it same it
will create form instance
Then it will go to ActionMapping instance the ris mention or not the
validate =true/false if false it will not execute the this step else
it will execute this step.
Then it will create action instance
Next it will take four parameters of execute Method it will return
ActionErrors instance. if it is not empty. it will go to error page
other wise it will got to corresponding page. else if it is empty
if will go further and display corresponding value of page in jsp
view.This is struts flow.
Model
Struts doesn't support Model directly. However, the Struts actions and configuration file provide you ability to implement it by your own.
View
1) Form bean that extends org.apache.struts.action.ActionForm, that is used in two ways at run time:
When a JSP page prepares the related HTML form for display, the JSP
page accesses the bean, which holds values to be placed into the
form. Those values are provided from business logic or from previous
user input.
When user input is returned from a web browser, the bean
validates and holds that input either for use by business logic or
(if validation failed) for subsequent redisplay.
2) Struts tag libraries such as bean, logic, html & tiles plugin
Controller
The Struts action servlet handles runtime events in accordance with a set of rules that are provided at deployment time. Those rules are contained in a Struts configuration file and specify how the servlet responds to every outcome received from the business logic. Changes to the flow of control require changes only to the configuration file.
Struts action extends org.apache.struts.action.Action. At run time, the action servlet is said to "execute actions," which means that the servlet invokes the execute method of each of the instantiated action classes. The object returned from the execute method directs the action servlet as to what action or JSP file to access next.
To facilitate reuse, invoke business logic from the action class rather than including business logic in that class.
See the Struts 1.3 example
For your comparison & reference, here's Struts 2.3 demo
I am looking to extend existing services and add Authorization to every call being made. The problem I have is that I don't know how to do this in the best possible manner. What I need to do is to send the name of the module calling the WCF service. I already send the username and password for the service and now I need to extend that with the name of the module calling the service. This is because we might allow a user to open a module and display data from another module but not from a third.
If we would have used message contracts I would just add a MessageHeader for this and set that header when I create the request. That is unfortunately not an option with DataContracts so I was considering the following two alternatives.
Adding a DataMember in a base class with Order=1000 or something like that. I don't know what will happen if we add another DataMember before that though?
Create the property for the module name and set a header in the transport instead. Not really fond of this one though. It's pretty abstract and hard to follow.
Which one is the least evil or do you have a better suggestion?
EDIT 1: The problem is not how to send a header to the service the problem is how to send a header with a specific value to the server. In the message inspector I can only create generic instances with message.GetBody<DataContract>(); this means I have to know the type which I don't know how to.
EDIT 2: The issue here is that in our application we want to restrict access to a call based on from where the call is made so I need to pass this information. Let's say I make the call to MyService from FindUserModule then I need to add the id of that module in a header so that the AuthorizationManager can check if that user really should be authorized. This is due to service calls being used from many modules.
Handle this as SOAP header in custom message inspector.