خرید بک لینک

Vote count: 0

When I invoke my service via Angular2 using http.post request, I get

Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access.

My JAX-RS service

@Override
    @POST
    @Path("/getWsCallReports")
    @Produces(MediaType.APPLICATION_JSON)
    public Response getWsCallReports(Query query) {
        try {
            LOG.info("getWsCallReports called for " + query);
            return Response.status(200)
                .header("Access-Control-Allow-Origin", "*")
                .header("Access-Control-Allow-Headers", "origin, content-type, accept, authorization")
                .header("Access-Control-Allow-Credentials", "true")
                .header("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS, HEAD")
                .header("Access-Control-Max-Age", "1209600").entity(wsCallReportDao.getReports(query)).build();
        } catch (Exception e) {
            return Response.serverError().build();
        }
    }

Also I've tried to add simple HTTP filter that defines all necessary headers for all requests

public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        HttpServletResponse response = (HttpServletResponse)  servletResponse;

        // TODO: development only
        response.addHeader("Access-Control-Allow-Origin", "*");

        response.addHeader("Access-Control-Allow-Headers", "origin, content-type, accept, authorization");
        response.addHeader("Access-Control-Allow-Credentials", "true");
        response.addHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS, HEAD");
        response.addHeader("Access-Control-Max-Age", "1209600");
        filterChain.doFilter(servletRequest, servletResponse);
    }

but it didn't help. What am I doing wrong?

asked 44 secs ago

برچسب: could not enable file history,could not enable s3 event source,could not enable skill,could not enable or disable the constraint,could not enable wbf interface,could not enable audit log 9237,could not enable integration features,could not enable,net for windowsactivationservice,could not enable database for publishing,could not enable any backends, نویسنده: استخدام کار تاريخ: دوشنبه 25 مرداد 1395 ساعت: 2:10

صفحه بندی