You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by mschipperheyn <m....@gmail.com> on 2010/12/02 17:35:45 UTC

jaxrs: proxy always returns null

Hi,

Newbie question: I keep getting the proxy return null, e.g. in the test
below when I call importProxy.ping() or importContent. If I call the ping()
method in the browser, everything work ok. I have the following
configuration.

Any suggestions on this one?

Thanks!

Marc

@Test
public void testStandardInsertValidation(){
	MyVO vo = new MyVO();
	importProxy = (ContentImport)
JAXRSClientFactory.create("http://www.mysite.com.br:90/services/v1",ContentImportServiceImpl.class,"user","pass","file:H:/java/projects/META-INF/spring/applicationContext.xml");
	String res = importProxy.ping();
	ResponseObject response = importProxy.importContent(vo);
	[...]
}

@Service("contentImport")
@Secured({"ROLE_WS","ROLE_ADMIN"})
@Path("/v1")
public class ContentImportServiceImpl extends AbstractContentImport
implements ContentImport{
	
	private static final Log log =
LogFactory.getLog(ContentImportServiceImpl.class);
	
	@POST
	@Path("/import/standard")
	@Secured({"ROLE_WS","ROLE_ADMIN"})
	@Produces("text/xml")
	public ResponseObject importContent(BaseOfferVO vo){
		BindingResult result = new BeanPropertyBindingResult(vo,"offer");
		ResponseObject response = validate(vo,null,result);

		if(!result.hasErrors()){
			//proceed with insert
		}
		
		return response;
	}
	
	@GET
	@Path("/ping")
	@Produces("text/plain")
	public String ping(){
		return "Hello";
	}
}

@XmlRootElement
public class ResponseObject {
	//Map<fieldname,error>
	private Map<String,String> errors = new HashMap<String,String>();
	private List<Long> ids = new ArrayList<Long>();
	private int status;
	
	@XmlElement
	public Map<String, String> getErrors() {
		return errors;
	}

	public void setErrors(Map<String, String> errors) {
		this.errors = errors;
	}
	
	public void addFieldError(String field,String error){
		errors.put(field,error);
	}
	
	public void addGeneralError(String error){
		errors.put("general",error);
	}
	
	@XmlElement
	public List<Long> getIds() {
		return ids;
	}

	public void setIds(List<Long> ids) {
		this.ids = ids;
	}
	
	public void addId(Long id){
		ids.add(id);
	}
	
	@XmlAttribute
	public int getStatus() {
		return status;
	}

	public void setStatus(int status) {
		this.status = status;
	}
}
-- 
View this message in context: http://cxf.547215.n5.nabble.com/jaxrs-proxy-always-returns-null-tp3289652p3289652.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: jaxrs: proxy always returns null

Posted by mschipperheyn <m....@gmail.com>.
Thanks! BTW, Spring Security 3.1 is coming out in December and it will
support mixing multiple http security configurations. Allowing you to have a
form login security for regular web pages and also having a webservice that
responds to a basic authentication.
-- 
View this message in context: http://cxf.547215.n5.nabble.com/jaxrs-proxy-always-returns-null-tp3289652p3289829.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: jaxrs: proxy always returns null

Posted by Sergey Beryozkin <sb...@gmail.com>.
Just FYI, when working with proxies you can do :

if (response == null) {
   Client client = WebClient.client(proxy);
   if (client.getResponse().getStatus() == 302) {
       String location =
client.getResponse().getMetadata().getFirst("Location").toString();
       // create new proxy/webclient, etc
   }
}

On Thu, Dec 2, 2010 at 6:07 PM, mschipperheyn <m....@gmail.com>wrote:

>
> I'm using Spring 3.0.5 and Spring security 3.0.5.
>
> Ok, I see that I get a status of 302 back, because I'm being redirected to
> the login page by Spring Security. However, I did provide the correct
> user/pass on the JAXRSClientFactory. So, it's most likely Spring Security
> that's not getting the user/pass injected properly. I'll investigate some
> more there.
>
>
> --
> View this message in context:
> http://cxf.547215.n5.nabble.com/jaxrs-proxy-always-returns-null-tp3289652p3289765.html
> Sent from the cxf-user mailing list archive at Nabble.com.
>

Re: jaxrs: proxy always returns null

Posted by mschipperheyn <m....@gmail.com>.
I'm using Spring 3.0.5 and Spring security 3.0.5.

Ok, I see that I get a status of 302 back, because I'm being redirected to
the login page by Spring Security. However, I did provide the correct
user/pass on the JAXRSClientFactory. So, it's most likely Spring Security
that's not getting the user/pass injected properly. I'll investigate some
more there.


-- 
View this message in context: http://cxf.547215.n5.nabble.com/jaxrs-proxy-always-returns-null-tp3289652p3289765.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: jaxrs: proxy always returns null

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

I think you need to remove 'v1' in the initial address  you're passing in to
the JAXRSClientFactory, the proxy will get it from ContentImportServiceImpl.

I'm not sure why 'null' is returned though - perhaps because the target
server returns 200 or 204 with the empty body ? Is it a CXF server ? You may
want to capture the payload on the wire just to verify...

cheers, Sergey

On Thu, Dec 2, 2010 at 4:35 PM, mschipperheyn <m....@gmail.com>wrote:

>
> Hi,
>
> Newbie question: I keep getting the proxy return null, e.g. in the test
> below when I call importProxy.ping() or importContent. If I call the ping()
> method in the browser, everything work ok. I have the following
> configuration.
>
> Any suggestions on this one?
>
> Thanks!
>
> Marc
>
> @Test
> public void testStandardInsertValidation(){
>        MyVO vo = new MyVO();
>        importProxy = (ContentImport)
> JAXRSClientFactory.create("http://www.mysite.com.br:90/services/v1
> ",ContentImportServiceImpl.class,"user","pass","file:H:/java/projects/META-INF/spring/applicationContext.xml");
>        String res = importProxy.ping();
>        ResponseObject response = importProxy.importContent(vo);
>        [...]
> }
>
> @Service("contentImport")
> @Secured({"ROLE_WS","ROLE_ADMIN"})
> @Path("/v1")
> public class ContentImportServiceImpl extends AbstractContentImport
> implements ContentImport{
>
>        private static final Log log =
> LogFactory.getLog(ContentImportServiceImpl.class);
>
>        @POST
>        @Path("/import/standard")
>        @Secured({"ROLE_WS","ROLE_ADMIN"})
>        @Produces("text/xml")
>        public ResponseObject importContent(BaseOfferVO vo){
>                BindingResult result = new
> BeanPropertyBindingResult(vo,"offer");
>                ResponseObject response = validate(vo,null,result);
>
>                if(!result.hasErrors()){
>                        //proceed with insert
>                }
>
>                return response;
>        }
>
>        @GET
>        @Path("/ping")
>        @Produces("text/plain")
>        public String ping(){
>                return "Hello";
>        }
> }
>
> @XmlRootElement
> public class ResponseObject {
>        //Map<fieldname,error>
>        private Map<String,String> errors = new HashMap<String,String>();
>        private List<Long> ids = new ArrayList<Long>();
>        private int status;
>
>        @XmlElement
>        public Map<String, String> getErrors() {
>                return errors;
>        }
>
>        public void setErrors(Map<String, String> errors) {
>                this.errors = errors;
>        }
>
>        public void addFieldError(String field,String error){
>                errors.put(field,error);
>        }
>
>        public void addGeneralError(String error){
>                errors.put("general",error);
>        }
>
>        @XmlElement
>        public List<Long> getIds() {
>                return ids;
>        }
>
>        public void setIds(List<Long> ids) {
>                this.ids = ids;
>        }
>
>        public void addId(Long id){
>                ids.add(id);
>        }
>
>        @XmlAttribute
>        public int getStatus() {
>                return status;
>        }
>
>        public void setStatus(int status) {
>                this.status = status;
>        }
> }
> --
> View this message in context:
> http://cxf.547215.n5.nabble.com/jaxrs-proxy-always-returns-null-tp3289652p3289652.html
> Sent from the cxf-user mailing list archive at Nabble.com.
>