You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Jose Escobar <eb...@gmail.com> on 2012/10/30 16:01:17 UTC

UriInfo error apache cxf 2.5.3 and Spring

Hello to all,

I used apache cxf to implement a restFul Server, everything is working
correctly except one thing. I have to get inside the methods of a
@Service if the request was made by HTTP or HTTPS, so I inject a
UriInfo to get the scheme, but It always return the value of the first
request to the service. Scheme, server name and port doesn't change
but path do.

I tried also with SecurityContext, but I've got the same problem, it
looks like it doesn't get updated in different requests.

My Tomcat configuration have 2 connectors on 2 different ports, one
for http and other for https.

My Service class looks like:

@Service("timeService")
public class TimeService {

...

@POST @Path("{url}")
@Produces("*/*")
@Consumes("*/*")
public Response getAS2from(byte[] content, @Context HttpHeaders
headers, @Context UriInfo uri)
{
	boolean sc=false;
	logger.info("Scheme: {}", uri.getAbsolutePath().toString());
	logger.info("Scheme3: {}",uri.getAbsolutePath().getScheme());
	if(((uri.getAbsolutePath().getScheme())!= null) &&
(uri.getAbsolutePath().getScheme()).equalsIgnoreCase("https")){
		logger.info("Recibiendo POST por HTTPS...");
		sc=true;
	}
	else{
		logger.info("Recibiendo POST por HTTP...");
	}
    ...
}


@POST
@Produces("*/*")
@Consumes("*/*")
public Response getAS2fromR(byte[] content, @Context HttpHeaders
headers, @Context UriInfo uri)
{
	boolean sc=false;
	logger.info("Scheme: {}", uri.getAbsolutePath().toString());
	logger.info("Scheme3: {}",uri.getAbsolutePath().getScheme());
	//Tratar mensaje AS2
	if(((uri.getAbsolutePath().getScheme())!= null) &&
(uri.getAbsolutePath().getScheme()).equalsIgnoreCase("https")){
		logger.info("Recibiendo POST por HTTPS...");
		sc=true;
	}
	else{
		logger.info("Recibiendo POST por HTTP...");
	}
    ...
}



Any suggestions about this???


Thank you very much!

Re: UriInfo error apache cxf 2.5.3 and Spring

Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi Jose
On 30/10/12 16:54, Jose Escobar wrote:
> Hi Sergey,
>
> It works, thank you very much!
>
great,
> Do you know if there's any adversal effect that should I care when
> changing "disable-address-updates" to true?
>
not that I'm aware of, this will probably be faster too...
I recall we were very close to completely block the overriding, probably 
some more tests are needed to make sure JAX-WS endpoints are not 
affected (specifically, WSDL generation), it will probably work fine, 
difficult to find the time :-)

Sergey

> 2012/10/30 Sergey Beryozkin<sb...@gmail.com>:
>> Hi
>>
>>
>> On 30/10/12 15:01, Jose Escobar wrote:
>>>
>>> Hello to all,
>>>
>>> I used apache cxf to implement a restFul Server, everything is working
>>> correctly except one thing. I have to get inside the methods of a
>>> @Service if the request was made by HTTP or HTTPS, so I inject a
>>> UriInfo to get the scheme, but It always return the value of the first
>>> request to the service. Scheme, server name and port doesn't change
>>> but path do.
>>>
>>> I tried also with SecurityContext, but I've got the same problem, it
>>> looks like it doesn't get updated in different requests.
>>>
>>> My Tomcat configuration have 2 connectors on 2 different ports, one
>>> for http and other for https.
>>>
>>> My Service class looks like:
>>>
>>> @Service("timeService")
>>> public class TimeService {
>>>
>>> ...
>>>
>>> @POST @Path("{url}")
>>> @Produces("*/*")
>>> @Consumes("*/*")
>>> public Response getAS2from(byte[] content, @Context HttpHeaders
>>> headers, @Context UriInfo uri)
>>> {
>>>          boolean sc=false;
>>>          logger.info("Scheme: {}", uri.getAbsolutePath().toString());
>>>          logger.info("Scheme3: {}",uri.getAbsolutePath().getScheme());
>>>          if(((uri.getAbsolutePath().getScheme())!= null)&&
>>> (uri.getAbsolutePath().getScheme()).equalsIgnoreCase("https")){
>>>                  logger.info("Recibiendo POST por HTTPS...");
>>>                  sc=true;
>>>          }
>>>          else{
>>>                  logger.info("Recibiendo POST por HTTP...");
>>>          }
>>>       ...
>>> }
>>>
>>>
>>> @POST
>>> @Produces("*/*")
>>> @Consumes("*/*")
>>> public Response getAS2fromR(byte[] content, @Context HttpHeaders
>>> headers, @Context UriInfo uri)
>>> {
>>>          boolean sc=false;
>>>          logger.info("Scheme: {}", uri.getAbsolutePath().toString());
>>>          logger.info("Scheme3: {}",uri.getAbsolutePath().getScheme());
>>>          //Tratar mensaje AS2
>>>          if(((uri.getAbsolutePath().getScheme())!= null)&&
>>> (uri.getAbsolutePath().getScheme()).equalsIgnoreCase("https")){
>>>                  logger.info("Recibiendo POST por HTTPS...");
>>>                  sc=true;
>>>          }
>>>          else{
>>>                  logger.info("Recibiendo POST por HTTP...");
>>>          }
>>>       ...
>>> }
>>>
>>>
>>>
>>> Any suggestions about this???
>>
>>
>> I think it is to do with the default address overwriting, can you please set
>> CXFServlet "disable-address-updates" parameter to "true" and see if it helps
>> ?
>>
>> Cheers, Sergey
>>
>>>
>>>
>>> Thank you very much!
>>
>>
>>


Re: UriInfo error apache cxf 2.5.3 and Spring

Posted by Jose Escobar <eb...@gmail.com>.
Hi Sergey,

It works, thank you very much!

Do you know if there's any adversal effect that should I care when
changing "disable-address-updates" to true?

2012/10/30 Sergey Beryozkin <sb...@gmail.com>:
> Hi
>
>
> On 30/10/12 15:01, Jose Escobar wrote:
>>
>> Hello to all,
>>
>> I used apache cxf to implement a restFul Server, everything is working
>> correctly except one thing. I have to get inside the methods of a
>> @Service if the request was made by HTTP or HTTPS, so I inject a
>> UriInfo to get the scheme, but It always return the value of the first
>> request to the service. Scheme, server name and port doesn't change
>> but path do.
>>
>> I tried also with SecurityContext, but I've got the same problem, it
>> looks like it doesn't get updated in different requests.
>>
>> My Tomcat configuration have 2 connectors on 2 different ports, one
>> for http and other for https.
>>
>> My Service class looks like:
>>
>> @Service("timeService")
>> public class TimeService {
>>
>> ...
>>
>> @POST @Path("{url}")
>> @Produces("*/*")
>> @Consumes("*/*")
>> public Response getAS2from(byte[] content, @Context HttpHeaders
>> headers, @Context UriInfo uri)
>> {
>>         boolean sc=false;
>>         logger.info("Scheme: {}", uri.getAbsolutePath().toString());
>>         logger.info("Scheme3: {}",uri.getAbsolutePath().getScheme());
>>         if(((uri.getAbsolutePath().getScheme())!= null)&&
>> (uri.getAbsolutePath().getScheme()).equalsIgnoreCase("https")){
>>                 logger.info("Recibiendo POST por HTTPS...");
>>                 sc=true;
>>         }
>>         else{
>>                 logger.info("Recibiendo POST por HTTP...");
>>         }
>>      ...
>> }
>>
>>
>> @POST
>> @Produces("*/*")
>> @Consumes("*/*")
>> public Response getAS2fromR(byte[] content, @Context HttpHeaders
>> headers, @Context UriInfo uri)
>> {
>>         boolean sc=false;
>>         logger.info("Scheme: {}", uri.getAbsolutePath().toString());
>>         logger.info("Scheme3: {}",uri.getAbsolutePath().getScheme());
>>         //Tratar mensaje AS2
>>         if(((uri.getAbsolutePath().getScheme())!= null)&&
>> (uri.getAbsolutePath().getScheme()).equalsIgnoreCase("https")){
>>                 logger.info("Recibiendo POST por HTTPS...");
>>                 sc=true;
>>         }
>>         else{
>>                 logger.info("Recibiendo POST por HTTP...");
>>         }
>>      ...
>> }
>>
>>
>>
>> Any suggestions about this???
>
>
> I think it is to do with the default address overwriting, can you please set
> CXFServlet "disable-address-updates" parameter to "true" and see if it helps
> ?
>
> Cheers, Sergey
>
>>
>>
>> Thank you very much!
>
>
>

Re: UriInfo error apache cxf 2.5.3 and Spring

Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi

On 30/10/12 15:01, Jose Escobar wrote:
> Hello to all,
>
> I used apache cxf to implement a restFul Server, everything is working
> correctly except one thing. I have to get inside the methods of a
> @Service if the request was made by HTTP or HTTPS, so I inject a
> UriInfo to get the scheme, but It always return the value of the first
> request to the service. Scheme, server name and port doesn't change
> but path do.
>
> I tried also with SecurityContext, but I've got the same problem, it
> looks like it doesn't get updated in different requests.
>
> My Tomcat configuration have 2 connectors on 2 different ports, one
> for http and other for https.
>
> My Service class looks like:
>
> @Service("timeService")
> public class TimeService {
>
> ...
>
> @POST @Path("{url}")
> @Produces("*/*")
> @Consumes("*/*")
> public Response getAS2from(byte[] content, @Context HttpHeaders
> headers, @Context UriInfo uri)
> {
> 	boolean sc=false;
> 	logger.info("Scheme: {}", uri.getAbsolutePath().toString());
> 	logger.info("Scheme3: {}",uri.getAbsolutePath().getScheme());
> 	if(((uri.getAbsolutePath().getScheme())!= null)&&
> (uri.getAbsolutePath().getScheme()).equalsIgnoreCase("https")){
> 		logger.info("Recibiendo POST por HTTPS...");
> 		sc=true;
> 	}
> 	else{
> 		logger.info("Recibiendo POST por HTTP...");
> 	}
>      ...
> }
>
>
> @POST
> @Produces("*/*")
> @Consumes("*/*")
> public Response getAS2fromR(byte[] content, @Context HttpHeaders
> headers, @Context UriInfo uri)
> {
> 	boolean sc=false;
> 	logger.info("Scheme: {}", uri.getAbsolutePath().toString());
> 	logger.info("Scheme3: {}",uri.getAbsolutePath().getScheme());
> 	//Tratar mensaje AS2
> 	if(((uri.getAbsolutePath().getScheme())!= null)&&
> (uri.getAbsolutePath().getScheme()).equalsIgnoreCase("https")){
> 		logger.info("Recibiendo POST por HTTPS...");
> 		sc=true;
> 	}
> 	else{
> 		logger.info("Recibiendo POST por HTTP...");
> 	}
>      ...
> }
>
>
>
> Any suggestions about this???

I think it is to do with the default address overwriting, can you please 
set CXFServlet "disable-address-updates" parameter to "true" and see if 
it helps ?

Cheers, Sergey

>
>
> Thank you very much!