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 3283346
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T20:01:52+00:00 2026-05-17T20:01:52+00:00

So, I’ve got a pretty simple RESTful jersey webservice, and I’m wanting to call

  • 0

So, I’ve got a pretty simple RESTful jersey webservice, and I’m wanting to call it from my javascript code. I have no problem executing a GET request, but for some reason, when I execute a PUT, I get back a “415 Unsupported Media Type” error. Any idea what I’m doing wrong?

Here’s my webservice :

package servlet;

import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.xml.bind.JAXBElement;

import com.mycompany.www.hudsonsemaphore.HudsonResult;
import com.mycompany.www.hudsonsemaphore.SemaphoreConstants;

@Path("/HudsonSemaphore")
public class HudsonSemaphore {
    static private HudsonResult lastResult;
    static private Object RESULT_LOCK = new Object();       

    @PUT
    @Consumes({MediaType.APPLICATION_JSON})
    static public void setResult(JAXBElement<HudsonResult> result) {        
        synchronized(RESULT_LOCK) {
            lastResult=result.getValue();
        }       
    }   

    @GET
    @Produces({MediaType.APPLICATION_JSON})
    public HudsonResult getLastResult() {
        HudsonResult toReturn;

        if(lastResult!=null) {
            synchronized(RESULT_LOCK) {
                toReturn = lastResult;
                lastResult=null;
            }
        }
        else {
            toReturn = SemaphoreConstants.NULL_HUDSON_RESULT;
        }

        return toReturn;
    }       
}

Here’s my annotated JAXBElement :

package com.mycompany.www.hudsonsemaphore;

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;

@XmlRootElement(name="hudsonResult")
@XmlType(propOrder = { 
    "message", "success"
})
public class HudsonResult {
    private boolean success;
    private String message; 

    public HudsonResult() {
        success=false;
        message=null;
    }

    public HudsonResult(String message, boolean success) {
        this.success = success;
        this.message = message;     
    }

    @XmlElement
    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message=message;
    }

    public void setSuccess(boolean success) {
        this.success=success;
    }

    @XmlElement
    public boolean isSuccess() {
        return success;
    }

    public boolean equals(HudsonResult result) {
        return(result.success == success && result.message.equals(message));
    }

    public String toString() {
        return "Success : [" + String.valueOf(success) + "] Message : [" + message + "]";
    }
}

And finally, here’s my javascript code :

<script type="text/javascript" src="/system/workplace/resources/ext/ext-base.js"></script>
<script type="text/javascript" src="/system/workplace/resources/ext/ext-all.js"></script>

<script type="text/javascript">

function pollSemaphore() {
    Ext.Ajax.request({
        url : 'http://localhost:8081/leadcapture/rest/HudsonSemaphore',
        method: 'GET',
        success: 
            function(result, request) {
                var jsonData = Ext.util.JSON.decode(result.responseText);

                if(jsonData.success=='true') {
                    alert('SUCCESS : ' + jsonData.message);
                }
                else {
                    alert('NOT SUCCESS : ' + result.responseText);  
                }
            },
        failure: 
            function(result, request) {
                alert('Teh fail : ' + result.responseText);
            }
    });
}

function pushSemaphore() {
    Ext.Ajax.request({
        url : 'http://localhost:8081/leadcapture/rest/HudsonSemaphore',
        method: 'PUT',
        params: {message : 'Brand new car!', success : 'true'},
        success: 
            function(result, request) {
                alert('YOU RULE!');
            },
        failure: 
            function(result, request) {
                alert('Teh fail : ' + result.responseText);
            }
    });
}

</script>

<input type="button" onclick="pushSemaphore()" value="Push"/> <br/>
<input type="button" onclick="pollSemaphore()" value="Poll"/> <br/>

Thanks for taking a look!

  • 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-05-17T20:01:53+00:00Added an answer on May 17, 2026 at 8:01 pm

    Since your web service code expecting JSON —@Consumes({MediaType.APPLICATION_JSON})—-
    that’s why it failed when your request comes through with different media type format. Your fixed works because you did set your request content type to JSON data.

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

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
I have a small JavaScript validation script that validates inputs based on Regex. I
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a text area in my form which accepts all possible characters from
I have been unable to fix a problem with Java Unicode and encoding. The
I have a view passing on information from a database: def serve_article(request, id): served_article
I have a bunch of posts stored in text files formatted in yaml/textile (from
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function

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.