[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 66
  • Last Modified:

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

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
Omer-Pitou
Asked:
Omer-Pitou
  • 3
1 Solution
 
mccarlIT Business Systems Analyst / Software DeveloperCommented:
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
 
Omer-PitouAuthor Commented:
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
 
mccarlIT Business Systems Analyst / Software DeveloperCommented:
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
 
mccarlIT Business Systems Analyst / Software DeveloperCommented:
@Omer-Pitou,

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

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now