Solved

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

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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Suggested Solutions

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

777 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