Solved

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

Posted on 2016-08-25
5
20 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
  • 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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

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…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
The viewer will learn how to implement Singleton Design Pattern in Java.

705 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now