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

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript