I try to get referer in action.class.php
public function executeIndex()
{
$this->setTemplate('index');
$this->referer = $this->getRequest()->getReferer();
}
but without any result:( Anybody now how to solve this problem?
symfony version 1.0.17
Related
Recently, i upgraded the cloud version from Edgware.RELEASE to Hoxton.SR1,and encounter some problems.
here comes the feign client code :
#FeignClient(name = "system-service)
public interface IHelloProxy{
#RequestMapping(value = "/sysinfo/now", method = RequestMethod.GET)
public void hello(#RequestParam String content);
}
when invoked IHelloProxy and pass the one param "content" with "https://www.oschina.net/?a=1&b=2",the feign debug log print:
---> GET http://system-service/sysinfo/now?content=https:%2F%2Fwww.oschina.net%2F%3Fa=1&b=2 HTTP/1.1
and the receiver got two params:“content”,"b".
the expectation should be :
--> GET http://system-service/sysinfo/now?content=https%3A%2F%2Fwww.oschina.net%2F%3Fa%3D1%26b%3D2
and the receiver also got only one param :"content"
I think the problem is at feign client side which do the wrong query map parsing. is that anyway to solve this ?
thanks.
the problem had solved by upgrade the cloud version to Hoxton.SR1 and Boot verion to 2.2.5.
and the issue is from open feign side, can track by for more detail
https://github.com/OpenFeign/feign/issues/1190
I'm trying to integrate swagger in MYcommercewebservices.
I read post and done all steps listed on it, but still having this error.
https://localhost:9002/mycommercewebservices/v2/v2/api-docs working fine. https://localhost:9002/mycommercewebservices/v2/swagger-ui.html - return UnknownResourceError.
Furthermore - if I navigate to https://localhost:9002/mycommercewebservices/swagger-ui.html (without 'v2') it'll show me this message (javascript alert):
Unable to infer base URL. This is common when using dynamic servlet
registration or when the API is behind an API Gateway. The base URL is
the root of where all the swagger resources are served. For e.g. if
the API is available at http://example.org/api/v2/api-docs then the
base URL is http://example.org/api/. Please enter the location
manually:
I found this controller, and probably part of the problem was in it because it was throwing an exception when I navigated to https://localhost:9002/mycommercewebservices/v2/swagger-ui.html
#Controller
public class DefaultController
{
#RequestMapping
public void defaultRequest(final HttpServletRequest request)
{
throw new UnknownResourceException("There is no resource for path " + YSanitizer.sanitize(request.getRequestURI()));
}
}
Now I disabled controller, but still having the same exception, but now it's in json format instead of .xml.
Thank you!
The main problem was in DefaultController (in MYcommercewebservices)
#Controller
public class DefaultController
{
#RequestMapping
public void defaultRequest(final HttpServletRequest request)
{
throw new UnknownResourceException("There is no resource for path " + YSanitizer.sanitize(request.getRequestURI()));
}
}
It was catching my request and throwing the exception.
When I disabled this controller, I continued to receive an exception, but now it was in json format(before it was in xml).
Than I added this to springmvc-v2-servlet.xml
<mvc:default-servlet-handler/>
<mvc:resources mapping="swagger-ui.html" location="classpath:/META-INF/resources/"/>
<mvc:resources mapping="/webjars/**" location="classpath:/META-INF/resources/webjars/"/>
Now UI works fine!
Also there were another manipulation before all this, but you can find them in hybris experts(quite big post).
I have a 'Create Account' view that I am starting to work on. Backbone 1.1.2 (typescript) front-end, Rails 4.2 beta 1 web service back-end.
Account Model
export class Account extends Backbone.Model {
public urlRoot: string;
public validation:any;
constructor(attributes?: any, options?: any){
this.urlRoot = 'http://domain.fake/accounts';
this.validation = {
email: {
required: true,
pattern: 'email'
},
password: {
required: true,
minLength: 6
}
};
super(attributes, options);
}
}
Create Account View:
export class CreateAccountView extends Backbone.View {
public template: string;
public events: any;
public model: accountModelImport.Account;
constructor(options?: Backbone.ViewOptions){
this.el = '#modal';
this.template = createAccountViewTemplate;
this.model = new accountModelImport.Account();
this.events = {
'click #create-account-submit' : 'create'
};
super(options);
}
public render(): CreateAccountView {
this.$el.html(_.template(this.template));
Backbone.Validation.bind(this);
this.$el.modal('show');
return this;
}
public create(){
var email:string = $('#create-account-email').val(), password:string = $('#create-account-password').val(), passconf:string = $('#create-account-password-confirmation').val();
this.model.set({email: email, password: password, password_confirmation: passconf});
this.model.save(null, {success: this.success, error: this.error});
}
public success(){
alert('Success');
}
public error(){
alert('error');
}
}
Rails output on model.save() from above:
ActionController::RoutingError (No route matches [OPTIONS] "/accounts"):
I have seen many questions about what to pass as the first argument to .save() and I have tried them all with the same result each time: null, false, {}
I have tried searching for a question with the same issue but haven't been able to find one. I would like to try to get this to work natively before I go down the road of overriding the .sync() method.
Why is .save() trying to use OPTIONS instead of POST?
Why is .save() trying to use OPTIONS instead of POST?
It's not. This is the CORS "preflight request" at work. If the OPTIONS request is successful, the POST request will follow.
...The preflight request is made as an HTTP OPTIONS request (so be
sure your server is able to respond to this method). It also contains
a few additional headers:
Access-Control-Request-Method - The HTTP method of the actual request.
This request header is always included, even if the HTTP method is a
simple HTTP method as defined earlier (GET, POST, HEAD).
Access-Control-Request-Headers - A comma-delimited list of non-simple
headers that are included in the request.
The preflight request is a way of asking permissions for the actual
request, before making the actual request. The server should inspect
the two headers above to verify that both the HTTP method and the
requested headers are valid and accepted.
See http://www.html5rocks.com/en/tutorials/cors/
As pointed out by #meagar in his answer to this question this was not anything that backbone was trying to do wrong. It was a CORS issue. I had the headers set up manually using config.action_dispatch.default_headers.merge! but apparently that wasn't enough.
A little more googling reveled this little gem of an answer to me (get it, 'gem')...
Rails RoutingError (No route matches [OPTIONS]
Which the answer there lead me to https://github.com/cyu/rack-cors
After installing the gem and configuring per their instructions, the POST request went through as expected.
Hope this helps others in the future, and be sure to give credit to #meagar for helping me down the right path.
I'm using Grails 2.2.3 and the Spring Security ACL plugin 1.1.1, and I'd like to have a URL that is open to the public and the service layer using the #PostAuthorize annotation secures the resource. We're doing it this way because to determine whether a user has access to a particular object we need to look at the object first.
What I'd like to be able to do is in the controller layer catch the AccessDeniedException, then have the browser ask for credentials and try again. I've tried the naive approach of setting the response status to 401 and redirecting back to itself to try again. The problem I ran into is that the browser never asked for credentials.
To put this into code what I'd like to do is in the controller layer:
#Secured(['IS_AUTHENTICATED_ANONYMOUSLY'])
def controllerAction() {
try {
someService.action()
} catch (AccessDeniedException ade) {
// if logged in show FORBIDDEN, if not ask for credentials and try again
}
}
And the service layer would simply have:
#PostAuthorize("""returnObject.availability == 'ALL'""")
def action() {
PersistedObject.findById(1)
}
Thanks for any help!
I ended up solving the problem, and it turns out I was missing a header that I needed to send along with the 401 status code.
To correct what I have above what you want to do is:
#Secured(['IS_AUTHENTICATED_ANONYMOUSLY'])
def controllerAction() {
try {
someService.action()
} catch (AccessDeniedException ade) {
if (!springSecurityService.isLoggedIn()) {
response.setHeader 'WWW-Authenticate', 'Basic realm="Grails Realm"' // the missing line
response.sendError HttpServletResponse.SC_UNAUTHORIZED
}
}
The "redirect" I was looking for happens automatically within the browser after credentials are submitted. I was mistaken about needing something specific for the redirect.
I use JSF 2.1.7 Mojarra.
If I write an incorrect URL (a page that doesn't exist) in the address bar of the browser, in order to test that I'm redirected to my custom error page for http error 404, I get instead the following exception (error 500):
com.sun.faces.context.FacesFileNotFoundException
I've found that this is a bug. See the following issue in Jira:
http://java.net/jira/browse/JAVASERVERFACES-1762
And that it has been already fixed (modifying the code of some JSF classes). See:
http://java.net/projects/mojarra/lists/commits/archive/2010-12/message/18
But I haven't found any patch.
Where can I get the patch that fix this bug? Is it possible to get or do I have to override the JSF code myself?
Thank you very much.
I suppose JSF is trying to be independent of Servlets/HTTP with this exception. I just catch it in a filter:
try {
chain.doFilter(request, response);
} catch (FacesFileNotFoundException e) {
response.sendError(404, e.getMessage());
}