Getting CORS Issue when Connecting to Java FN from Angular UIHow to make CORS-enabled HTTP requests in Angular 2?How to add CORS request in header in Angular 5CORS ISSUE using angular4CORS Issue in AngularRest API call in angular 4 getting CORS errorAngular 6 HttpClient - Issues with CORS

Why is 6. Nge2 better, and 7. d5 a necessary push in this game?

If a spaceship ran out of fuel somewhere in space between Earth and Mars, does it slowly drift off to the Sun?

How can this Stack Exchange site have an animated favicon?

Is the iPhone's eSim for the home or roaming carrier?

I am not a pleasant sight

12 donuts split to 5 children

Align all symbols in a LaTeX equation

Is a PWM required for regenerative braking on a DC Motor?

Why does (inf + 0j)*1 evaluate to inf + nanj?

"I will not" or "I don't" in the following context?

New road bike: alloy dual pivot brakes work poorly

How to stop the death waves in my city?

Why did UK NHS pay for homeopathic treatments?

Beyond Futuristic Technology for an Alien Warship?

Why does my browser attempt to download pages from http://clhs.lisp.se instead of viewing them normally?

End a command question

Difference between "rip up" and "rip down"

I reverse the source code, you reverse the input!

How should I answer custom and border protection questions if I'm a returning citizen that hasn't been in the country for almost a decade?

I transpose the source code, you transpose the input!

Why is a road bike faster than a city bike with the same effort? How much faster it can be?

String whitespaces

What exactly did this mechanic sabotage on the American Airlines 737, and how dangerous was it?

Seventh degree polynomial



Getting CORS Issue when Connecting to Java FN from Angular UI


How to make CORS-enabled HTTP requests in Angular 2?How to add CORS request in header in Angular 5CORS ISSUE using angular4CORS Issue in AngularRest API call in angular 4 getting CORS errorAngular 6 HttpClient - Issues with CORS






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















I am currently trying to resolve a CORS issue that we are having when we query a database using a FN project function that is called from Angular. The FN function is written in Java (fnproject/fn-java-fdk:1.0.83), and the UI is in Angular 7. Essentially, we send a JSON query to the FN function as a byte array, which processes the JSON query into the appropriate query, and then sends it to the database. The database responds with the result of the query, which passes back through the FN function to the UI with the appropriate response.



I tried putting the CORS headers as htxc.setResponseHeader() and htxc.addResponseHeader(). I have also tried changing the func.yaml to include the CORS protocols there as opposed to inside the function, but this does not work. In addition, I tried changing the "*" in the Access-Control-Allow-Origin header to a specific URL that we were making the request from as well. We have also looked at adding many different headers to Access-Control-Allow-Headers in the hope that one of them would resolve the issue.




import com.fnproject.fn.api.httpgateway.HTTPGatewayContext;
...

public class query_database

/**
* @param input is a byte[] array with input, contains the request information
* @return List<dbObject> A list of DB Objects
*/
public List<dbObject> query(byte[] input, HTTPGatewayContext htxc)IOException




In the Angular 7 UI that we are making, the following error appears when we open it in Chrome/Firefox:



Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://server.com:8080/t/function/function-trigger. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing). (unknown)


This is despite the 'Access-Control-Allow-Origin' response header being set in the Java code. The function works properly other than this CORS error, so we are fairly confident that it is something with the headers. For instance, the JSON response is correct.



Any thoughts? There could potentially be something wrong with the current header approach, or perhaps it could be on the Angular side as well. Let me know if there is any need for clarification on the question as well.










share|improve this question
























  • Do you support the OPTIONS response? CORS requires that you answer with an OPTIONS response. More info here: developer.mozilla.org/en-US/docs/Web/HTTP/Methods/OPTIONS

    – Sam Vloeberghs
    Mar 28 at 18:41











  • Would that be something like this? htxc.addResponseHeader("Access-Control-Allow-Methods", "OPTIONS, POST, GET");

    – hravicha
    Mar 28 at 19:18












  • no, OPTIONS is like GET/POST. What you do is what you have to do in the OPTIONS request.

    – Sam Vloeberghs
    Mar 28 at 20:05











  • Wouldn't this line cover it? if (htxc.getMethod().equals("OPTIONS")) return Collections.emptyList();

    – hravicha
    Mar 28 at 20:09












  • No. I would suggest learning how CORS works first Here is a good example: howtodoinjava.com/servlets/java-cors-filter-example

    – Sam Vloeberghs
    Mar 29 at 6:24

















0















I am currently trying to resolve a CORS issue that we are having when we query a database using a FN project function that is called from Angular. The FN function is written in Java (fnproject/fn-java-fdk:1.0.83), and the UI is in Angular 7. Essentially, we send a JSON query to the FN function as a byte array, which processes the JSON query into the appropriate query, and then sends it to the database. The database responds with the result of the query, which passes back through the FN function to the UI with the appropriate response.



I tried putting the CORS headers as htxc.setResponseHeader() and htxc.addResponseHeader(). I have also tried changing the func.yaml to include the CORS protocols there as opposed to inside the function, but this does not work. In addition, I tried changing the "*" in the Access-Control-Allow-Origin header to a specific URL that we were making the request from as well. We have also looked at adding many different headers to Access-Control-Allow-Headers in the hope that one of them would resolve the issue.




import com.fnproject.fn.api.httpgateway.HTTPGatewayContext;
...

public class query_database

/**
* @param input is a byte[] array with input, contains the request information
* @return List<dbObject> A list of DB Objects
*/
public List<dbObject> query(byte[] input, HTTPGatewayContext htxc)IOException




In the Angular 7 UI that we are making, the following error appears when we open it in Chrome/Firefox:



Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://server.com:8080/t/function/function-trigger. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing). (unknown)


This is despite the 'Access-Control-Allow-Origin' response header being set in the Java code. The function works properly other than this CORS error, so we are fairly confident that it is something with the headers. For instance, the JSON response is correct.



Any thoughts? There could potentially be something wrong with the current header approach, or perhaps it could be on the Angular side as well. Let me know if there is any need for clarification on the question as well.










share|improve this question
























  • Do you support the OPTIONS response? CORS requires that you answer with an OPTIONS response. More info here: developer.mozilla.org/en-US/docs/Web/HTTP/Methods/OPTIONS

    – Sam Vloeberghs
    Mar 28 at 18:41











  • Would that be something like this? htxc.addResponseHeader("Access-Control-Allow-Methods", "OPTIONS, POST, GET");

    – hravicha
    Mar 28 at 19:18












  • no, OPTIONS is like GET/POST. What you do is what you have to do in the OPTIONS request.

    – Sam Vloeberghs
    Mar 28 at 20:05











  • Wouldn't this line cover it? if (htxc.getMethod().equals("OPTIONS")) return Collections.emptyList();

    – hravicha
    Mar 28 at 20:09












  • No. I would suggest learning how CORS works first Here is a good example: howtodoinjava.com/servlets/java-cors-filter-example

    – Sam Vloeberghs
    Mar 29 at 6:24













0












0








0








I am currently trying to resolve a CORS issue that we are having when we query a database using a FN project function that is called from Angular. The FN function is written in Java (fnproject/fn-java-fdk:1.0.83), and the UI is in Angular 7. Essentially, we send a JSON query to the FN function as a byte array, which processes the JSON query into the appropriate query, and then sends it to the database. The database responds with the result of the query, which passes back through the FN function to the UI with the appropriate response.



I tried putting the CORS headers as htxc.setResponseHeader() and htxc.addResponseHeader(). I have also tried changing the func.yaml to include the CORS protocols there as opposed to inside the function, but this does not work. In addition, I tried changing the "*" in the Access-Control-Allow-Origin header to a specific URL that we were making the request from as well. We have also looked at adding many different headers to Access-Control-Allow-Headers in the hope that one of them would resolve the issue.




import com.fnproject.fn.api.httpgateway.HTTPGatewayContext;
...

public class query_database

/**
* @param input is a byte[] array with input, contains the request information
* @return List<dbObject> A list of DB Objects
*/
public List<dbObject> query(byte[] input, HTTPGatewayContext htxc)IOException




In the Angular 7 UI that we are making, the following error appears when we open it in Chrome/Firefox:



Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://server.com:8080/t/function/function-trigger. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing). (unknown)


This is despite the 'Access-Control-Allow-Origin' response header being set in the Java code. The function works properly other than this CORS error, so we are fairly confident that it is something with the headers. For instance, the JSON response is correct.



Any thoughts? There could potentially be something wrong with the current header approach, or perhaps it could be on the Angular side as well. Let me know if there is any need for clarification on the question as well.










share|improve this question














I am currently trying to resolve a CORS issue that we are having when we query a database using a FN project function that is called from Angular. The FN function is written in Java (fnproject/fn-java-fdk:1.0.83), and the UI is in Angular 7. Essentially, we send a JSON query to the FN function as a byte array, which processes the JSON query into the appropriate query, and then sends it to the database. The database responds with the result of the query, which passes back through the FN function to the UI with the appropriate response.



I tried putting the CORS headers as htxc.setResponseHeader() and htxc.addResponseHeader(). I have also tried changing the func.yaml to include the CORS protocols there as opposed to inside the function, but this does not work. In addition, I tried changing the "*" in the Access-Control-Allow-Origin header to a specific URL that we were making the request from as well. We have also looked at adding many different headers to Access-Control-Allow-Headers in the hope that one of them would resolve the issue.




import com.fnproject.fn.api.httpgateway.HTTPGatewayContext;
...

public class query_database

/**
* @param input is a byte[] array with input, contains the request information
* @return List<dbObject> A list of DB Objects
*/
public List<dbObject> query(byte[] input, HTTPGatewayContext htxc)IOException




In the Angular 7 UI that we are making, the following error appears when we open it in Chrome/Firefox:



Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://server.com:8080/t/function/function-trigger. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing). (unknown)


This is despite the 'Access-Control-Allow-Origin' response header being set in the Java code. The function works properly other than this CORS error, so we are fairly confident that it is something with the headers. For instance, the JSON response is correct.



Any thoughts? There could potentially be something wrong with the current header approach, or perhaps it could be on the Angular side as well. Let me know if there is any need for clarification on the question as well.







angular fn






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 28 at 18:36









hravichahravicha

1




1















  • Do you support the OPTIONS response? CORS requires that you answer with an OPTIONS response. More info here: developer.mozilla.org/en-US/docs/Web/HTTP/Methods/OPTIONS

    – Sam Vloeberghs
    Mar 28 at 18:41











  • Would that be something like this? htxc.addResponseHeader("Access-Control-Allow-Methods", "OPTIONS, POST, GET");

    – hravicha
    Mar 28 at 19:18












  • no, OPTIONS is like GET/POST. What you do is what you have to do in the OPTIONS request.

    – Sam Vloeberghs
    Mar 28 at 20:05











  • Wouldn't this line cover it? if (htxc.getMethod().equals("OPTIONS")) return Collections.emptyList();

    – hravicha
    Mar 28 at 20:09












  • No. I would suggest learning how CORS works first Here is a good example: howtodoinjava.com/servlets/java-cors-filter-example

    – Sam Vloeberghs
    Mar 29 at 6:24

















  • Do you support the OPTIONS response? CORS requires that you answer with an OPTIONS response. More info here: developer.mozilla.org/en-US/docs/Web/HTTP/Methods/OPTIONS

    – Sam Vloeberghs
    Mar 28 at 18:41











  • Would that be something like this? htxc.addResponseHeader("Access-Control-Allow-Methods", "OPTIONS, POST, GET");

    – hravicha
    Mar 28 at 19:18












  • no, OPTIONS is like GET/POST. What you do is what you have to do in the OPTIONS request.

    – Sam Vloeberghs
    Mar 28 at 20:05











  • Wouldn't this line cover it? if (htxc.getMethod().equals("OPTIONS")) return Collections.emptyList();

    – hravicha
    Mar 28 at 20:09












  • No. I would suggest learning how CORS works first Here is a good example: howtodoinjava.com/servlets/java-cors-filter-example

    – Sam Vloeberghs
    Mar 29 at 6:24
















Do you support the OPTIONS response? CORS requires that you answer with an OPTIONS response. More info here: developer.mozilla.org/en-US/docs/Web/HTTP/Methods/OPTIONS

– Sam Vloeberghs
Mar 28 at 18:41





Do you support the OPTIONS response? CORS requires that you answer with an OPTIONS response. More info here: developer.mozilla.org/en-US/docs/Web/HTTP/Methods/OPTIONS

– Sam Vloeberghs
Mar 28 at 18:41













Would that be something like this? htxc.addResponseHeader("Access-Control-Allow-Methods", "OPTIONS, POST, GET");

– hravicha
Mar 28 at 19:18






Would that be something like this? htxc.addResponseHeader("Access-Control-Allow-Methods", "OPTIONS, POST, GET");

– hravicha
Mar 28 at 19:18














no, OPTIONS is like GET/POST. What you do is what you have to do in the OPTIONS request.

– Sam Vloeberghs
Mar 28 at 20:05





no, OPTIONS is like GET/POST. What you do is what you have to do in the OPTIONS request.

– Sam Vloeberghs
Mar 28 at 20:05













Wouldn't this line cover it? if (htxc.getMethod().equals("OPTIONS")) return Collections.emptyList();

– hravicha
Mar 28 at 20:09






Wouldn't this line cover it? if (htxc.getMethod().equals("OPTIONS")) return Collections.emptyList();

– hravicha
Mar 28 at 20:09














No. I would suggest learning how CORS works first Here is a good example: howtodoinjava.com/servlets/java-cors-filter-example

– Sam Vloeberghs
Mar 29 at 6:24





No. I would suggest learning how CORS works first Here is a good example: howtodoinjava.com/servlets/java-cors-filter-example

– Sam Vloeberghs
Mar 29 at 6:24












0






active

oldest

votes














Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);














draft saved

draft discarded
















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55404702%2fgetting-cors-issue-when-connecting-to-java-fn-from-angular-ui%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid …


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55404702%2fgetting-cors-issue-when-connecting-to-java-fn-from-angular-ui%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

How to preserve electronics (computers, tablets and phones) for hundreds of years Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) The network's official Twitter account is up and running again. What content…How might modern humans leave a message for 50,000 years?How would an aquatic race develop computers?How do we make computers care for human life?Keeping supplies for 1000 yearsWhat will cell phones become in 100 years?What body armor protects against a laser?Could a society attain 1800s technology if limited to using copper and bronze?Electricity power (magic) and electronicsScavenging metal resources in post-apocalypse after 100 yearsWhy would precursors create devices that can survive and still work after hundreds of years?

155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해

Convert JSON to MapSimplest way to convert a string representing JSON array into Java array List of key value pairsHow to take String JSON values into HashMapConvert a JSON String to a HashMapCreating BSON object from JSON stringJSONObject - How to get a value ?Better Map ConstructorReading JSON from Url javaUpdate columns if input values are not null otherwise ignore and keep the existing values of column in databaseHow to store object represented as Json string into Couchbase Lite?Go JSON into MapHow do I efficiently iterate over each entry in a Java Map?Sort a Map<Key, Value> by valuesHow to round a number to n decimal places in JavaCan comments be used in JSON?How do I read / convert an InputStream into a String in Java?How can I pretty-print JSON in a shell script?What is the correct JSON content type?How can I deserialize JSON to a simple Dictionary<string,string> in ASP.NET?Why does Google prepend while(1); to their JSON responses?Parse JSON in JavaScript?