Solved

RestFul Service: Uploading a file to a server through a web service

Posted on 2016-08-25
5
43 Views
Last Modified: 2016-09-27
Hi,
I am trying to upload a file to a server without success. I got this error message, and noticed it refers to SimpleDateFormat processing exception while I didn't use any date formatting classes. Attached are my 3 web services classes (AppConfig, Client, and Webservice).
Please, assist.
Exception in thread "main" javax.ws.rs.ProcessingException: org.glassfish.jersey.message.internal.HttpDateFormat.getPreferredDateFormat()Ljava/text/SimpleDateFormat;
	at org.glassfish.jersey.client.ClientRuntime.invoke(ClientRuntime.java:236)
	at org.glassfish.jersey.client.JerseyInvocation$1.call(JerseyInvocation.java:655)
	at org.glassfish.jersey.client.JerseyInvocation$1.call(JerseyInvocation.java:652)
	at org.glassfish.jersey.internal.Errors.process(Errors.java:315)
	at org.glassfish.jersey.internal.Errors.process(Errors.java:297)
	at org.glassfish.jersey.internal.Errors.process(Errors.java:228)
	at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:422)
	at org.glassfish.jersey.client.JerseyInvocation.invoke(JerseyInvocation.java:652)
	at org.glassfish.jersey.client.JerseyInvocation$Builder.method(JerseyInvocation.java:412)
	at org.glassfish.jersey.client.JerseyInvocation$Builder.post(JerseyInvocation.java:321)
	at com.uploadfile.UploadClient.main(UploadClient.java:27)
Caused by: java.lang.NoSuchMethodError: org.glassfish.jersey.message.internal.HttpDateFormat.getPreferredDateFormat()Ljava/text/SimpleDateFormat;
	at org.glassfish.jersey.media.multipart.ContentDisposition.addDateParameter(ContentDisposition.java:196)
	at org.glassfish.jersey.media.multipart.ContentDisposition.toStringBuffer(ContentDisposition.java:181)
	at org.glassfish.jersey.media.multipart.FormDataContentDisposition.toStringBuffer(FormDataContentDisposition.java:117)
	at org.glassfish.jersey.media.multipart.ContentDisposition.toString(ContentDisposition.java:172)
	at org.glassfish.jersey.media.multipart.internal.MultiPartWriter.writeTo(MultiPartWriter.java:185)
	at org.glassfish.jersey.media.multipart.internal.MultiPartWriter.writeTo(MultiPartWriter.java:79)
	at org.glassfish.jersey.message.internal.WriterInterceptorExecutor$TerminalWriterInterceptor.invokeWriteTo(WriterInterceptorExecutor.java:243)
	at org.glassfish.jersey.message.internal.WriterInterceptorExecutor$TerminalWriterInterceptor.aroundWriteTo(WriterInterceptorExecutor.java:230)
	at org.glassfish.jersey.message.internal.WriterInterceptorExecutor.proceed(WriterInterceptorExecutor.java:149)
	at org.glassfish.jersey.message.internal.MessageBodyFactory.writeTo(MessageBodyFactory.java:1139)
	at org.glassfish.jersey.client.ClientRequest.writeEntity(ClientRequest.java:495)
	at org.glassfish.jersey.client.HttpUrlConnector._apply(HttpUrlConnector.java:270)
	at org.glassfish.jersey.client.HttpUrlConnector.apply(HttpUrlConnector.java:182)
	at org.glassfish.jersey.client.ClientRuntime.invoke(ClientRuntime.java:227)
	... 10 more

Open in new window

UploadClient.java
RestAppConfig.java
UploadService.java
0
Comment
Question by:Omer-Pitou
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 35

Expert Comment

by:mccarl
ID: 41771109
It looks like you have a library version issue, lines 13 and 14 of the above is the clue. On line 14, it tells you that that particular method of a class was trying to call the method of the class detailed in line 13. So, the method ContentDisposition.addDateParameter() is trying to call the method HttpDateFormat.getPreferredDateFormat() but it is not there. It must have been there originally when the jersey devs compiled ContentDisposition but now (at runtime) it is not there. Which usually means that the jar that contains ContentDisposition is a different version to the one that contains HttpDateFormat.

Are you using Maven? If so, can you post your pom.xml. If not, can you list out all the JAR's that you Client program is using and their versions?
0
 

Author Comment

by:Omer-Pitou
ID: 41771134
Thanks MCCARL for your reply,
I tried with MAVEN without success, as I couldn't run my project properly. I used the pom to download necessary libs and took those libs to a non-maven project, since I couldn't find a link to download those libraries.
Attached is picture of libs that I used.
Screenshot-2016-08-25-17.36.01.png
Screenshot-2016-08-25-17.35.26.png
0
 
LVL 35

Accepted Solution

by:
mccarl earned 500 total points (awarded by participants)
ID: 41771151
Ok, so yeah, you have 2.5.1 AND 2.23.1 versions on your class path. ContentDisposition is a class in your jersey-media-multipart-2.23.1.jar file and it is probably picking up the HttpDateFormat from the Jersey 2.5.1 (JAX-RS RI) - jersey-common.jar. At some point, in the 2.5.1 version HttpDateFormat had a method called getPreferedDateFormat() and then at some point between that and the 2.23.1 version, they fixed the typo and the method is now called getPreferredDateFormat().

Anyway, you need to be using just ONE version of Jersey and you should be ok.
0
 
LVL 35

Expert Comment

by:mccarl
ID: 41790617
@Omer-Pitou,

Are you happy with the above responses or do you need any further assistance?
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
tomcat startup error 5 136
CSV file parsing thru Java 13 40
Fast way to search item into Java Array (Rhino compatible) 2 39
Html split(text) 2 32
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question