Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8423193
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T03:39:35+00:00 2026-06-10T03:39:35+00:00

I’m testing out Jersey and I can’t seem to figure out why I get

  • 0

I’m testing out Jersey and I can’t seem to figure out why I get a 405 Method Not Allowed when I call PUT:

@Singleton @Path("images")
public class ImageResource {
    private static final String IMAGE_ID_PATH_PARAM = "{imageId : [A-Za-z0-9_\\-]+}";
    private static final String EXTENSION_PATH_PARAM = "{extension : (\\.[A-Za-z]+)?}";

    @GET @Path(IMAGE_ID_PATH_PARAM + EXTENSION_PATH_PARAM)
    @Produces("image/*")
    public Response getImage(@PathParam("imageId") String imageId,
        @PathParam("extension") String extension, @QueryParam("mods") String mods) {
        ...
    }

    @PUT @Path(IMAGE_ID_PATH_PARAM)
    @Consumes("image/*")
    public Response putImage(@PathParam("imageId") String imageId, File image) {
        ...
    }
}

PUT only works if I set the @GET path to @Path(IMAGE_ID_PATH_PARAM). When I add the extension part, I am getting a 405 status code. GET seems to work in both cases. Here’s the output from a failed PUT:

$ curl -v --header "Content-Type: image/jpeg" --upload-file /Users/andy/Desktop/test.jpg http://localhost:9090/images/abcde
* About to connect() to localhost port 9090 (#0)
*   Trying 127.0.0.1... connected
* Connected to localhost (127.0.0.1) port 9090 (#0)
> PUT /images/abcde HTTP/1.1
> User-Agent: curl/7.21.4 (universal-apple-darwin11.0) libcurl/7.21.4 OpenSSL/0.9.8r zlib/1.2.5
> Host: localhost:9090
> Accept: */*
> Content-Type: image/jpeg
> Content-Length: 48198
> Expect: 100-continue
> 
< HTTP/1.1 100 Continue
< HTTP/1.1 405 Method Not Allowed
< Content-Type: text/html; charset=iso-8859-1
< Date: Mon, 20 Aug 2012 18:35:59 GMT
< Allow: GET,OPTIONS,HEAD
< Transfer-Encoding: chunked

I’ve also tried testing without the @Produces and @Consumes annotations and it did not work either.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T03:39:37+00:00Added an answer on June 10, 2026 at 3:39 am

    Let’s take a look at what happens when you send the request.

    Situation 1: no extension

    Your methods look like this:

        @GET @Path(IMAGE_ID_PATH_PARAM)
        @Produces("image/*")
        public Response getImage(@PathParam("imageId") String imageId,
            @PathParam("extension") String extension, @QueryParam("mods") String mods) {
            ...
        }
    
        @PUT @Path(IMAGE_ID_PATH_PARAM)
        @Consumes("image/*")
        public Response putImage(@PathParam("imageId") String imageId, File image) {
            ...
        }
    

    When you send the following request:

    PUT http://localhost:9090/images/abcde

    first of all, Jersey looks for resources with the URI in question:
    http://localhost:9090/images/abcde

    After the resource is found, it checks what methods can be used to access it.
    In this case, you have a single resource with the path defined by IMAGE_ID_PATH_PARAM. This resource can be accessed by either GET or PUT requests. Just like you specified with the annotations.

    Situation 2: extension added to getImage

    You methods now look like this:

    @GET @Path(IMAGE_ID_PATH_PARAM + EXTENSION_PATH_PARAM)
    @Produces("image/*")
    public Response getImage(@PathParam("imageId") String imageId,
        @PathParam("extension") String extension, @QueryParam("mods") String mods) {
        ...
    }
    
    @PUT @Path(IMAGE_ID_PATH_PARAM)
    @Consumes("image/*")
    public Response putImage(@PathParam("imageId") String imageId, File image) {
        ...
    }
    

    Again, you send the same request:
    PUT http://localhost:9090/images/abcde

    And yet again, Jersey finds the first resource matching the URL. The resource is represented by your getImage method, just like the first time. This time again, the @GET annotation does not match your request. And just like before, Jersey tries to find another method available for the resource, in order to match your request.

    This time, however, no such method is found so it returns a 405.

    The reason why this happens is that the methods getImage and putImage now represent different resources. If you look carefully, the paths can be read like this (I’ll omit the regex for clarity):

    @Path({imageId}{extension}) for getImage

    and

    @Path({imageId}) for putImage

    While these two paths, considering the regex, can become the same thing, Jersey still sees them as identifiers of separate resources.

    If you take a look at the WADL (feel free to look here if you’re not familiar with the standard) file generated by Jersey (it should be available at http://localhost:9090/application.wadl), you’ll notice that this is exactly what’s happening.

    <application xmlns="http://research.sun.com/wadl/2006/10">
    <resources base="http://localhost:9090/">
    <resource path="images">
      <resource path="{imageId : [A-Za-z0-9_\-]+}">
        <param xmlns:xs="http://www.w3.org/2001/XMLSchema" name="imageId" style="template" type="xs:string"/>
        <method id="putImage" name="PUT">
          <request>
            <representation mediaType="image/*"/>
          </request>
          <response>
            <representation mediaType="*/*"/>
          </response>
        </method>
      </resource>
      <resource path="{imageId : [A-Za-z0-9_\-]+}{extension : (\.[A-Za-z]+)?}">
        <param xmlns:xs="http://www.w3.org/2001/XMLSchema" name="extension" style="template" type="xs:string"/>
        <param xmlns:xs="http://www.w3.org/2001/XMLSchema" name="imageId" style="template" type="xs:string"/>
        <method id="getImage" name="GET">
          <request>
            <param xmlns:xs="http://www.w3.org/2001/XMLSchema" name="mods" style="query" type="xs:string"/>
          </request>
          <response>
            <representation mediaType="image/*"/>
          </response>
        </method>
      </resource>
    </resource>
    </resources>
    </application>
    

    Notice how images has two, separate sub-resources, each one with a single method.

    Solution

    Adding the EXTENSION_PATH_PARAM segment to putImage‘s @Path annotation causes these two methods to be mapped to a single resource again, so the problem disappears. Since the regex makes this part optional, you are free to omit it and pretend it doesn’t exist.

    The difference can be clearly seen in the generated WADL.

    <application xmlns="http://research.sun.com/wadl/2006/10">
      <resources base="http://localhost:9090/">
        <resource path="images">
          <resource path="{imageId : [A-Za-z0-9_\-]+}{extension : (\.[A-Za-z]+)?}">
            <param xmlns:xs="http://www.w3.org/2001/XMLSchema" name="extension" style="template" type="xs:string"/>
            <param xmlns:xs="http://www.w3.org/2001/XMLSchema" name="imageId" style="template" type="xs:string"/>
            <method id="putImage" name="PUT">
              <request>
                <representation mediaType="image/*"/>
              </request>
              <response>
                <representation mediaType="*/*"/>
              </response>
            </method>
            <method id="getImage" name="GET">
             <request>
               <param xmlns:xs="http://www.w3.org/2001/XMLSchema" name="mods" style="query" type="xs:string"/>
             </request>
             <response>
               <representation mediaType="image/*"/>
             </response>
            </method>
          </resource>
        </resource>
      </resources>
    </application>
    

    In this case, images has exactly one sub-resource, which in turn has two available methods.

    Personally, I find the automatic generation of WADL a fantastic feature of Jersey. It’s a great way to see what’s happening with your resource methods without spending too much time with curl or other REST client.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I know there's a lot of other questions out there that deal with this
Does anyone know how can I replace this 2 symbol below from the string
I need a function that will clean a strings' special characters. I do NOT
I am trying to loop through a bunch of documents I have to put

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.