Solved

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

911 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

25 Experts available now in Live!

Get 1:1 Help Now