Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8520291
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T06:29:34+00:00 2026-06-11T06:29:34+00:00

How can I add http header to soap webservice using netbeans and glassfish? My

  • 0

How can I add http header to soap webservice using netbeans and glassfish?

My webservice class:

package com.service;

import com.model.Contact;
import com.model.Phonebook;
import java.util.ArrayList;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;


@WebService(serviceName = "PhonebookService")
public class PhonebookService {

    private Phonebook phonebook = new Phonebook();

    @WebMethod(operationName = "insert")
    public String insert(@WebParam(name = "contact") Contact contact) {

        phonebook.add(contact);
        return contact.getName() + " inserted";

    }

    @WebMethod(operationName = "update")
    public String update(@WebParam(name = "contact") Contact contact) {

        phonebook.update(contact);
        return contact.getName() + " updated";

    }

    @WebMethod(operationName = "remove")
    public String remove(@WebParam(name = "contact") Contact contact) {

        phonebook.remove(contact);
        return contact.getName() + " removed";

    }

    @WebMethod(operationName = "list")
    public ArrayList<Contact> list() {

        return phonebook.list();

    }

}

I would like to add “Access-Control-Allow-Origin: *” header

How can I do it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T06:29:36+00:00Added an answer on June 11, 2026 at 6:29 am

    Searching over internet for hours, I ended up coding the following code which allow to add extra http headers. I am using it with netbeans generated webservice and built-in glassfish 3 server

    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.annotation.WebFilter;
    import javax.servlet.http.*;
    
    @WebFilter(urlPatterns = { "/*" })
    public class CrossOriginResourceSharingFilter implements Filter {
    
        public CrossOriginResourceSharingFilter() { }
    
        @Override
        public void init(FilterConfig fConfig) throws ServletException { }
    
        @Override
        public void destroy() { }
    
        @Override
        public void doFilter(
            ServletRequest request, ServletResponse response,
            FilterChain chain) throws IOException, ServletException {
    
            ((HttpServletResponse)response).addHeader(
                "Access-Control-Allow-Origin", "*"
            );
                    ((HttpServletResponse)response).addHeader(
                "Access-Control-Allow-Headers", "Content-Type, Authorization, Accept"
            );
                    ((HttpServletResponse)response).addHeader(
                            "Access-Control-Allow-Methods", "GET, POST, OPTIONS"
                    );
    
            chain.doFilter(request, response);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I add http://facebook.com to relative URL's contained within #facebook_urls ? Eg: <a
I've notice that StackOverflow use this url: http://stackoverflow.com/posts/123123/revisions How can I add such routing
I am using the jquery validation plugin from: http://bassistance.de/jquery-plugins/jquery-plugin-validation/ How can I add a
using this http://bl.ocks.org/950642 we can see how to add images to nodes, the question
How can i add DataID and password in an HTTP header. something like shown
How can I add an object into the soap header of a org.springframework.ws.WebServiceMessage This
I can't add the tag <meta http-equiv=X-UA-Compatible content=IE=EmulateIE7 /> to the <header-content> section in
I need to add to my message something like this: <soap:Header> <wsse:Security xmlns:wsse=http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd soap:mustUnderstand=1>
http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/app/TextToSpeechActivity.html I was going to add this but how can i add it if
We can add an image to an photo album using UIImage *img = [UIImage

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.