You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@wink.apache.org by sushil <sr...@in.ibm.com> on 2010/05/13 07:48:43 UTC

REST Client failed to upload file

I have the following handler: 
{Code}
@POST
@Produces(MediaType.TEXT_PLAIN)
@Consumes(MediaTypeUtils.MULTIPART_FORM_DATA)
public String uploadFiles(@Context HttpServletRequest request,	InMultiPart
inMP) {
...
}

I have created REST Client using JacksonJaxbJsonProvider.class
{Code}
protected RestClient getClient() {
	BasicAuthSecurityHandler handler = new BasicAuthSecurityHandler();
	handler.setUserName(username);
	handler.setPassword(password);
	ClientConfig config = new ClientConfig();
	config.handlers(handler);
	config.applications(new Application() {
		@Override
		public Set<Class<?>> getClasses() {
			HashSet<Class<?>> s = new HashSet<Class<?>>();
			s.add(JacksonJaxbJsonProvider.class);// by default the wink
			return s;
		}
	});

	return new RestClient(config);
}
But while trying to upload the file I am getting error,
{ERROR}

java.lang.RuntimeException: No javax.ws.rs.ext.MessageBodyWriter found for
type class org.apache.wink.common.model.multipart.InMultiPart and media type
multipart/form-data

Do you have a suggestion how to resolve the issue? 
-- 
View this message in context: http://apache-wink-dev.3470905.n2.nabble.com/REST-Client-failed-to-upload-file-tp5044819p5044819.html
Sent from the Apache Wink Dev mailing list archive at Nabble.com.

Re: REST Client failed to upload file

Posted by sushil <sr...@in.ibm.com>.
Hi Nicholas,

I have created OutMulti which extends OutMultiPart class and implemented
required method.

{CODE}
			
OutMulti outMulti = new OutMulti();
List<OutPart> list = new ArrayList<OutPart>();
OutPart outPart = new OutPart();
outPart.addHeader("accept", "text/plain");
outPart.setContentType("multipart/form-data");
outPart.writePart(
		new FileOutputStream("c:/ProvisioningPolicy.xml"), getProviders());
//outPart.setBody(">>>>>>>>>Sushil");
list.add(outPart);
outMulti.setIterator(list.iterator());
resource.post(outMulti);

Now, at server side, I am getting the object of InMulitPart, but its an
empty object. There is no value in the object.

Am I doing something wrong? or any suggestion?  
-- 
View this message in context: http://apache-wink-dev.3470905.n2.nabble.com/REST-Client-failed-to-upload-file-tp5044819p5074097.html
Sent from the Apache Wink Dev mailing list archive at Nabble.com.

Re: REST Client failed to upload file

Posted by Nicholas L Gallardo <nl...@us.ibm.com>.
Hi Sushil,

Is the error you posted (no MessageBodyWriter) happening on the client
side?  If so, that makes sense.

On the server side, you want to use the InMulitPart.  On the client side,
you need to use the OutMultiPart.  The writer only knows how to write out
OutParts and the reader can only read and create InParts.

Hope that helps.






                                                                           
             sushil                                                        
             <srakhond@in.ibm.                                             
             com>                                                       To 
                                       wink-dev@incubator.apache.org       
             05/13/2010 12:48                                           cc 
             AM                                                            
                                                                   Subject 
                                       REST Client failed to upload file   
             Please respond to                                             
             wink-dev@incubato                                             
               r.apache.org                                                
                                                                           
                                                                           
                                                                           





I have the following handler:
{Code}
@POST
@Produces(MediaType.TEXT_PLAIN)
@Consumes(MediaTypeUtils.MULTIPART_FORM_DATA)
public String uploadFiles(@Context HttpServletRequest request,
InMultiPart
inMP) {
...
}

I have created REST Client using JacksonJaxbJsonProvider.class
{Code}
protected RestClient getClient() {
		 BasicAuthSecurityHandler handler = new
BasicAuthSecurityHandler();
		 handler.setUserName(username);
		 handler.setPassword(password);
		 ClientConfig config = new ClientConfig();
		 config.handlers(handler);
		 config.applications(new Application() {
		 		 @Override
		 		 public Set<Class<?>> getClasses() {
		 		 		 HashSet<Class<?>> s = new
HashSet<Class<?>>();
		 		 		 s.add
(JacksonJaxbJsonProvider.class);// by default the wink
		 		 		 return s;
		 		 }
		 });

		 return new RestClient(config);
}
But while trying to upload the file I am getting error,
{ERROR}

java.lang.RuntimeException: No javax.ws.rs.ext.MessageBodyWriter found for
type class org.apache.wink.common.model.multipart.InMultiPart and media
type
multipart/form-data

Do you have a suggestion how to resolve the issue?
--
View this message in context:
http://apache-wink-dev.3470905.n2.nabble.com/REST-Client-failed-to-upload-file-tp5044819p5044819.html

Sent from the Apache Wink Dev mailing list archive at Nabble.com.