You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@cxf.apache.org by "James Carman (JIRA)" <ji...@apache.org> on 2016/11/04 14:58:58 UTC

[jira] [Commented] (CXF-7127) WebTarget Doesn't Set Origin Header

    [ https://issues.apache.org/jira/browse/CXF-7127?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15636577#comment-15636577 ] 

James Carman commented on CXF-7127:
-----------------------------------

The issue is HttpURLConnection.  It filters out headers that it doesn't like (including Origin).  You need to force it to use the HttpClient:

1.  Add a dependency to the cxf-rt-transports-http-hc module:

{code}
<dependency>
  <groupId>org.apache.cxf</groupId>
  <artifactId>cxf-rt-transports-http-hc</artifactId>
  <version>${cxf.version}</version>
</dependency>
{code}

2.  Set the "use.async.http.conduit" property:

{code}
WebTarget target = ClientBuilder.newClient().target("http://localhost:8080/");
String answer = target.path("hello").path("World")
                .property("use.async.http.conduit", true)
                .request(MediaType.TEXT_PLAIN)
                .header("Origin", "http://localhost/")
                .get(String.class);
{code}

> WebTarget Doesn't Set Origin Header
> -----------------------------------
>
>                 Key: CXF-7127
>                 URL: https://issues.apache.org/jira/browse/CXF-7127
>             Project: CXF
>          Issue Type: Bug
>          Components: JAX-RS
>    Affects Versions: 3.1.8
>            Reporter: James Carman
>
> When trying to execute a simple "hello world" GET request such as:
> {code}
> WebTarget target = ClientBuilder.newClient().target("http://localhost:8080/");
> String answer = target.path("hello").path("World")
>                 .request(MediaType.TEXT_PLAIN)
>                 .header("Origin", "http://localhost/")
>                 .get(String.class);
> {code}
> I do not see the "Origin" header on the server when the request gets there.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)