Rectangle 27 11

I think your issue is related to the Filter order of execution of your Web Context, i.e. some filters, in you web context, executes after your filter and override the header.

The Servlet Filter is an implementation of the Chain of Responsibility pattern

  • Set the headers after the call to chain.doFilter:
...

chain.doFilter(req,res);

HttpServletRequest req = (HttpServletRequest) request;
HttpServletResponse res = (HttpServletResponse) response;

//get the headers we placed in the request
//based on those request headers, set some response headers

if(req.getHeader("X-Wria-Download") != null){
    res.setHeader("Content-Type", "application/pdf");
    res.setHeader("Content-Disposition", "attachment; filename=success.pdf");
}

In this way your code will be executed after that the Servlet is called and, as explained below, if your filter is the first declared in web.xml, then the setHeader code will be the last executed (see image below).

  • make sure that your filter is the last to be executed after the Servlet is executed, i.e. it should be the first servlet Filter declared as explained here:

As you can see Filter1 (the first declared in web.xml) is the first one executed before the servlet is executed and the last one executed after the servlet is executed. So if you want to be sure to be the last Filter setting the header then declare it as Filter1.

The order of execution is determined by the order of declaration in your Deployment Descriptor (web.xml):

"The order the container uses in building the chain of filters to be applied for a particular request URI is as follows:

"1. First, the matching filter mappings in the same order that these elements appear in the deployment descriptor.

"2. Next, the matching filter mappings in the same order that these elements appear in the deployment descriptor."

So to be sure simply declare it as the first filter in your web.xml. In this way it will be the very last filter setting the header. And, of course, set the header in your code after calling chain.doFilter, as already said.

thanks! the key things that helped me from this is that 1) Make sure your filter is added first, so it will get called last, and 2) make sure you modify the response after calling chain.doFilter(req,res), not before, or your response may get overwritten.

Unfortunately this didn't work for me using Dropwizard 0.6 / Jetty 8. (I'm trying to modify cookie values.) For some reason, no matter where I add the chain.doFilter() call, my response comes back with the original values of the headers. I've had to solve my problem in a different, less desirable way, but I'm just commenting on this answer in case anyone else has had issues too.

Thanks for the good description. I've tried to do such a filter with Jetty 9.2 but unfortunately it also didn't work, seems to be the same issue as @DuffJ had. In my case the filter worked as expected only if I declared it as last filter in my web.xml.

servlets - Java filter failing to set response headers - Stack Overflo...

java servlets http-headers request servlet-filters
Rectangle 27 69

You can pass an Object as the parameter to your filter expression, as described in the API Reference. This object can selectively apply the properties you're interested in, like so:

<input ng-model="search.name">
<input ng-model="search.phone">
<input ng-model="search.secret">
<tr ng-repeat="user in users | filter:{name: search.name, phone: search.phone}">

Heads up...this example works great with AngularJS 1.1.5, but not always as well in 1.0.7. In this example 1.0.7 will initialize with everything filtered out, then work when you start using the inputs. It behaves like the inputs have non-matching values in them, even though they start out blank. If you want to stay on stable releases, go ahead and try this out for your situation, but some scenarios may want to use @maxisam's solution until 1.2.0 is released.

yeah, that is so weird how it initializes with everything filtered out..

Looking at your plunker how would the desired effect be achieved if you only had one search box. This is the challenge... the OR part.

How would you do it with only one input field like in this example in the table: datatables.net

Filtering by Multiple Specific Model Properties in AngularJS (in OR re...

angularjs
Rectangle 27 117

Angular filters can only be applied to arrays and not objects, from angular's API -

"Selects a subset of items from array and returns it as a new array."

You have two options here: 1) move $scope.items to an array or - 2) pre-filter the ng-repeat items, like this:

<div ng-repeat="(k,v) in filterSecId(items)">
    {{k}} {{v.pos}}
</div>
$scope.filterSecId = function(items) {
    var result = {};
    angular.forEach(items, function(value, key) {
        if (!value.hasOwnProperty('secId')) {
            result[key] = value;
        }
    });
    return result;
}

Note: This is a perf anti-pattern now. Angular 1.3 has stateless filters now (egghead.io/lessons/) so you'd definitely want to create a filter for this.

@kentcdodds don't post links which are not free!

Why not just add an ng-if on the repeated element?

javascript - How to filter (key, value) with ng-repeat in AngularJs? -...

javascript angularjs frameworks ng-repeat angular-filters
Rectangle 27 117

Angular filters can only be applied to arrays and not objects, from angular's API -

"Selects a subset of items from array and returns it as a new array."

You have two options here: 1) move $scope.items to an array or - 2) pre-filter the ng-repeat items, like this:

<div ng-repeat="(k,v) in filterSecId(items)">
    {{k}} {{v.pos}}
</div>
$scope.filterSecId = function(items) {
    var result = {};
    angular.forEach(items, function(value, key) {
        if (!value.hasOwnProperty('secId')) {
            result[key] = value;
        }
    });
    return result;
}

Note: This is a perf anti-pattern now. Angular 1.3 has stateless filters now (egghead.io/lessons/) so you'd definitely want to create a filter for this.

@kentcdodds don't post links which are not free!

Why not just add an ng-if on the repeated element?

javascript - How to filter (key, value) with ng-repeat in AngularJs? -...

javascript angularjs frameworks ng-repeat angular-filters
Rectangle 27 16

Here is the implementation of custom filter, which will filter the data using array of values.It will support multiple key object with both array and single value of keys. As mentioned inangularJS API AngularJS filter Doc supports multiple key filter with single value, but below custom filter will support same feature as angularJS and also supports array of values and combination of both array and single value of keys.Please find the code snippet below,

myApp.filter('filterMultiple',['$filter',function ($filter) {
return function (items, keyObj) {
    var filterObj = {
        data:items,
        filteredData:[],
        applyFilter : function(obj,key){
            var fData = [];
            if (this.filteredData.length == 0)
                this.filteredData = this.data;
            if (obj){
                var fObj = {};
                if (!angular.isArray(obj)){
                    fObj[key] = obj;
                    fData = fData.concat($filter('filter')(this.filteredData,fObj));
                } else if (angular.isArray(obj)){
                    if (obj.length > 0){
                        for (var i=0;i<obj.length;i++){
                            if (angular.isDefined(obj[i])){
                                fObj[key] = obj[i];
                                fData = fData.concat($filter('filter')(this.filteredData,fObj));    
                            }
                        }

                    }
                }
                if (fData.length > 0){
                    this.filteredData = fData;
                }
            }
        }
    };
    if (keyObj){
        angular.forEach(keyObj,function(obj,key){
            filterObj.applyFilter(obj,key);
        });
    }
    return filterObj.filteredData;
}
}]);
arrayOfObjectswithKeys | filterMultiple:{key1:['value1','value2','value3',...etc],key2:'value4',key3:[value5,value6,...etc]}

Here is a fiddle example with implementation of above "filterMutiple" custom filter. :::Fiddle Example:::

You seem to have the correct intention but your example doesn't seem to work as expected. The output in the table seems rather inconsistent.

This does not work with JSON's with nested objects. Would've been ideal if it did. also it fires a length property undefined error in the console.

It is working for me but it returns all the results if it doesn't find the searched attribute in the list, how can I do to invert this behavior and return no result if the value doesn't exist in the list?

if (fData.length > 0){      this.filteredData = fData; }
this.filteredData = fData;

javascript - How to filter multiple values (OR operation) in angularJS...

javascript angularjs angularjs-ng-repeat
Rectangle 27 16

Here is the implementation of custom filter, which will filter the data using array of values.It will support multiple key object with both array and single value of keys. As mentioned inangularJS API AngularJS filter Doc supports multiple key filter with single value, but below custom filter will support same feature as angularJS and also supports array of values and combination of both array and single value of keys.Please find the code snippet below,

myApp.filter('filterMultiple',['$filter',function ($filter) {
return function (items, keyObj) {
    var filterObj = {
        data:items,
        filteredData:[],
        applyFilter : function(obj,key){
            var fData = [];
            if (this.filteredData.length == 0)
                this.filteredData = this.data;
            if (obj){
                var fObj = {};
                if (!angular.isArray(obj)){
                    fObj[key] = obj;
                    fData = fData.concat($filter('filter')(this.filteredData,fObj));
                } else if (angular.isArray(obj)){
                    if (obj.length > 0){
                        for (var i=0;i<obj.length;i++){
                            if (angular.isDefined(obj[i])){
                                fObj[key] = obj[i];
                                fData = fData.concat($filter('filter')(this.filteredData,fObj));    
                            }
                        }

                    }
                }
                if (fData.length > 0){
                    this.filteredData = fData;
                }
            }
        }
    };
    if (keyObj){
        angular.forEach(keyObj,function(obj,key){
            filterObj.applyFilter(obj,key);
        });
    }
    return filterObj.filteredData;
}
}]);
arrayOfObjectswithKeys | filterMultiple:{key1:['value1','value2','value3',...etc],key2:'value4',key3:[value5,value6,...etc]}

Here is a fiddle example with implementation of above "filterMutiple" custom filter. :::Fiddle Example:::

You seem to have the correct intention but your example doesn't seem to work as expected. The output in the table seems rather inconsistent.

This does not work with JSON's with nested objects. Would've been ideal if it did. also it fires a length property undefined error in the console.

It is working for me but it returns all the results if it doesn't find the searched attribute in the list, how can I do to invert this behavior and return no result if the value doesn't exist in the list?

if (fData.length > 0){      this.filteredData = fData; }
this.filteredData = fData;

javascript - How to filter multiple values (OR operation) in angularJS...

javascript angularjs angularjs-ng-repeat
Rectangle 27 2

Due to the way GenericForeignKey is implemented, you cannot use such fields directly with filters (filter() and exclude(), for example) via the database API. Because a GenericForeignKey isnt a normal field object, these examples will not work:

You could follow what the error message is telling you, I think you'll have to add a GenericRelation relation to do that. I do not have experience doing that, and I'd have to study it but...

Personally I think this solution is too complex to what you're trying to achieve. If only the user model can follow a tag or authors, why not include a ManyToManyField on it. It would be something like this:

class Person(models.Model):
    user = models.ForeignKey(User)
    follow_tag = models.ManyToManyField('Tag')
    follow_author = models.ManyToManyField('Author')
Activity.objects.filter(tags__in=person.follow_tag.all())

And you could search 'persons' following a tag like this:

Person.objects.filter(follow_tag__in=[<tag_ids>])

The same would apply to authors and you could use querysets to do OR, AND, etc.. on your queries.

If you want more models to be able to follow a tag or author, say a System, maybe you could create a Following model that does the same thing Person is doing and then you could add a ForeignKey to Follow both in Person and System

Note that I'm using this Person to meet this recomendation.

What are you trying to achieve with the GenericRelation?

django - How to filter multiple fields with list of objects - Stack Ov...

django django-queryset
Rectangle 27 1

With respect to queries, you can treat Key<?>, Key (the native low level api version), Ref<?>, and the actual entity itself as interchangeable. You can pass any of those four things to your filter() call.

Update: You are correct - you cannot express a join in GAE queries. Which is not to say you can't do joins, you just have to do them yourself by hand in your own code - you're the query planner. The same rule also applies to aggregations. For simple joins and aggregations this works fine, but of course it has limits.

The datastore is great as a transactional store and authoritative source of truth but it is terrible for analytics. My advice is to replicate relevant bits of data into a real RDMBS, either Cloud SQL or Postgres (whose driver has been working for me on GAE out of the box). Use the task queue. This works quite well for me and provides best-of-both-worlds - the infinite scaling and zero maintenance of the datastore, plus the flexibility of an RDBMS.

Yes, I can pass I Ref<?> , Key<?> or Key to filter a property of my current Entity. In the example above, if I pass a Ref<?> to filter beerRef it will work perfectly. But what I am trying to do is go a little deeper, to filter a Ref<?> in the Entity BeerBrand returning the List of Entity Item. As I am reading(books and the docs) I am almost sure that it's not possible because it is similar to a JOIN in a SQL database. But I just want the confirmation from someone that knows more about it. Thanks for the reply stickfigure. I'm your fan.

Ah! I misunderstood. I'll update the answer.

java - Filter objects passing a property of a Ref of other object i...

java google-app-engine google-cloud-datastore objectify
Rectangle 27 0

Continuing the Comparator theme, you may also want to take a look at the Google Collections API. In particular, they have an interface called Predicate, which serves a similar role to Comparator, in that it is a simple interface that can be used by a filtering method, like Sets.filter). They include a whole bunch of composite predicate implementations, to do ANDs, ORs, etc.

Depending on the size of your data set, it may make more sense to use this approach than a SQL or external relational database approach.

How do you query object collections in Java (Criteria/SQL-like)? - Sta...

java sql collections
Rectangle 27 0

Apparently you can't "filter" on fields containing array, filtering on fields containing objects works as you sketched out. I don't think this is documented in the Facbook API docs.

I will accept that it can't be done by FQL query and use Graph API instead. Thanks.

Ok, but how do you filter via Graph API?

Parse the response Object data. Using nested for loops to create a flat Object for each field you are requesting (education, languages and work): languageName.push(friends[i].languages[j].name); createFlatObject(languages, languageName, friends[i].id);

Yeah, but that's filtering in your application and not the Graph API itself... But great that it works!

Facebook FQL query returns no results for language field - Stack Overf...

facebook facebook-fql
Rectangle 27 0

You can pass an Object as the parameter to your filter expression, as described in the API Reference here http://docs.angularjs.org/api/ng.filter%3afilter. This object can selectively apply the properties you're interested in, like so:

<input ng-model="search.name">
<input ng-model="search.phone">
<input ng-model="search.secret">
<tr ng-repeat="user in users | filter:{name: search.name, phone: search.phone}">

The plunker works for input tags, hence it will also work for select tags with few modifications.

Disclaimer : Plunker Not Created By Me

Thanks, I will have a look and get back

Selecting a dropdown options results in no search result. I cannot spoke issues, can anyone spot the obvious please? I have created a plunker: plnkr.co/edit/9fMV0hPfeYNKKTzJQhqg?p=preview

javascript - Multi Dropdown JSON Filter Search AngularJS - Stack Overf...

javascript jquery json angularjs
Rectangle 27 0

You could create a core queue (or a Subscription) with a filter and stop the queue using management API. Or if you are working embedded you could just cause pause at the Server Queue object.

As this would be a very custom feature, you could probably use it embedded, or make special adjustments at your own branch.

java - Temporary disable delivery of JMS message based on message prop...

java jms hornetq
Rectangle 27 0

I've been banging my head against a brick wall over this also. I tried contextUtil but kept getting a null reference exception. I found out how to call an actionFilter in this post N.B. The actionFilter wasn't being invoked when using a Mock instance of the filter, I had to use the real object. HTH

var httpActionContext = new HttpActionContext
    {
        ControllerContext = new HttpControllerContext
        {
            Request = requestMessage
        }
    };
//call filter
var filter = new FooFilter();
filter.OnActionExecuting(httpActionContext);

.net - How can you unit test an Action Filter in ASP.NET Web Api? - St...

.net unit-testing asp.net-web-api action-filter
Rectangle 27 0

Assuming "Product Description" is a custom field on Case and it is not a long test area (which are not allowed in WHERE clauses), the SOQL query would look something this this:

SELECT Id FROM Case WHERE Parent.Product_Description__c LIKE '%something%' AND Type__c = 'Engineering Escalation'

One thing I noticed in your query is that for parent relationships, you were prefixing Case (e.g. Case.ParentId) which is not really needed (i.e. just ParentId will do). This doesn't really matter, but just calling it out because it be what was leading to some confusion about traversing relationships.

Also, for the task at hand here, it might be solved better with a SOSL search, rather than a SOQL query. SOSL will allow you to find text in a long text area and can search across the whole object, which might work better and should be faster because the data is indexed. It might find a little too much, but it does allow you to filter records down and you do further filtering with SOQL or in your Java code.

WHERE
...FROM Case WHERE Parent.Product_Description__c...
SELECT Case.ParentId, CaseNumber, Subject FROM Case WHERE Parent.Product_Description__c LIKE '%Control C%'"  Output:  [InvalidFieldFault [ApiQueryFault [ApiFault  exceptionCode='INVALID_FIELD'  exceptionMessage=' case.Account.name FROM Case WHERE Parent.Product_Description__c LIKE                                   ^ ERROR at Row:1:Column:95 No such column 'Product_Description__c' on entity 'Case'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names.' ]

Ryan it would be great help if you could give me pointers. I am new with Salesforce API.

Thanks Ryan. I was able to resolve the issue. First I determined case table fields using describeSObjectsSample code given in SOAP API documentation. Then provided exact custom parameters as filter. Query was something like this SELECT CaseNumber, Subject FROM Case where Type__c ='Engineering Escalation' AND Parent_Case_Product_Description__c LIKE '%product name%'

java - How to filter salesforce case object using SQOP API based on pa...

java salesforce
Rectangle 27 0

This api is supposed to GET employee objects that satisfy the given criteria of belonging to a particular company, having particular job title and some other filter criteria.

Personally I would just design your URI as http://acme.com/employee/?company=X&title=Y&non-smoker=Z&T=U. I wouldn't write "in stone" that the company is mandatory: your API will be easier to change.

However, you should consider that few "big" requests are far faster than plenty of small ones. Moreover, URI representations can be effectively cached. Therefore it is often better to have URIs based on IDs (since there are more chances that they will be asked again). So you could get the complete employee list of a company (plus other data about the company itself) with http://acme.com/company/X and then filter it client-side.

rest - Is there a better restful interface for this? - Stack Overflow

rest restful-url restful-architecture
Rectangle 27 0

I am using this flag and am still getting videos that cannot be played on my site. The 2nd result for related videos to ID: SZoX6Q0UK8A is egYMZKpENCg. When I try to play it, I get the error: "This video contains content from SME. It is restricted from playback on certain sites. Watch on YouTube."

YouTube API v3 filtering embeddable videos - Stack Overflow

api youtube youtube-api
Rectangle 27 0

This is not what I'm looking for, I can already get the query and apply the options. I need to be able to limit the related data that comes back across navigation properties, and Javier's answer is correct.

asp.net web api - Filtering queries across $expands with WebApi2 OData...

asp.net-web-api odata
Rectangle 27 0

builder.RegisterWebApiFilterProvider(GlobalConfiguration.Configuration);

c# - How to do dependency injection to Action Filter on ASP.NET Web AP...

c# asp.net-web-api dependency-injection ioc-container asp.net-web-api-filters
Rectangle 27 0

Angular filters require an array and a filter object of some type to work. You can find more in https://docs.angularjs.org/api/ng/filter/filter. By default the $filter('filter') call will return the inbuilt generic/simple filter. Your first argument then needs to be an array of objects with properties. Your second arg can be an object like you've demonstrated.

var app = angular.module('app', []);

app.controller('ExampleCtrl', 
function ($scope, $filter)  {
        var x = [{name : 'Tim'}, {'name'  : 'Jim'}, {'name'  : 'Jeff'}];

        console.log($filter('filter')(x, {$ : 'Jeff'}));
});

Turns out this works... there was just problem with the object I was passing my results to. It is good to see a working example of this though as not a lot of web resources reference the $ based object filtering.

Sweet glad it works. BTW it's not really idiomatic to use the filter this way but I'm sure you know that..

javascript - Filtering by object using the special $ character in angu...

javascript json angularjs filter dataset
Rectangle 27 0

do you have any security constraints related to http methods configured in web.xml? i am not sure that why you go for a seperate api for filtering your request?

I am a newbie.. correct me if I am wrong. I've seen that if the requests come from anything other than browsers, if we don't define cross origin filter in the webservice, it won't service the request. All I want is being able to send GET and POST requests from another web server. Help me if there is a better way

I don't generally see the difference based on the client. it is mainly based upon the protocol in which they talk

CORs filter throws 403 error code when cors.allowOrigin doesn't have the domain sending the GET request.

java - GET requests are being forbidden while POST requests go through...

java rest cross-domain html5-canvas tomcat6