Forum Discussion

irene_smile's avatar
irene_smile
Occasional Contributor
16 years ago

Exception when sending REST request

I created my first REST project in SOAPUI. When executed, I see an exception about MediaType. I added MediaType for Response as text/xml in representation.  Any clues on what I should set in SOAPUI?

java.lang.IllegalArgumentException: Failure parsing MediaType string:
    org.jboss.resteasy.plugins.delegates.MediaTypeHeaderDelegate.parse(MediaTypeHeaderDelegate.java:39)
    org.jboss.resteasy.plugins.delegates.MediaTypeHeaderDelegate.fromString(MediaTypeHeaderDelegate.java:16)
    javax.ws.rs.core.MediaType.valueOf(MediaType.java:173)
    org.jboss.resteasy.plugins.server.servlet.ServletUtil.extractHttpHeaders(ServletUtil.java:79)
    org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:82)
    org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:68)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    com.intuit.spc.bhp.logging.LoggingFilter.doFilter(LoggingFilter.java:32)
    org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)

7 Replies

  • omatzura's avatar
    omatzura
    Super Contributor
    Hi!

    If you are using POST or PUT you should enter a media-type in the media-type dropdown under the list of parameters, the value of course depending on the content of the request. So if you are sending xml set it to "text/xml"

    Hope this helps!

    regards,

    /Ole
    eviware.com
  • irene_smile's avatar
    irene_smile
    Occasional Contributor
    Thanks for the reply. The request is a POST with zero input parameters.

    Please elaborate where to find media-type drop-down? I did not see a drop-down in Request Params tab
  • omatzura's avatar
    omatzura
    Super Contributor
    Hi!

    it's on top of the content-area for the post-content, I've attached a screenshot with it high-lighted.. hope it helps!

    regards,

    /Ole
    eviware.com
  • irene_smile's avatar
    irene_smile
    Occasional Contributor
    Thank you for the help! I was able to set the Media type to application/xml and send the request that had no input params.

    I am now looking to send a request that input parameters. Here is what I did: the same service exists in both SOAP and REST. I have a SOAPUI request that works for SOAP. I cut and past the SOAP request into the body of Rest Request, removed the
    tag and tags. But I am seeing exceptions that indicate inability to parse contents.

    15:30:45,145 ERROR [STDERR] Wed 2009/01/28 15:30:45.145|***|http-0.0.0.0-8080-1|
    SynchronousDispatcher|org.jboss.resteasy.spi.LoggableFailure: Failure extracting
    body
    org.jboss.resteasy.spi.LoggableFailure: Failure extracting body
            at org.jboss.resteasy.core.MessageBodyParameterInjector.inject(MessageBo
    dyParameterInjector.java:81)
            at org.jboss.resteasy.core.MethodInjectorImpl.injectArguments(MethodInje
    ctorImpl.java:93)
            at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.
    java:114)
            at org.jboss.resteasy.core.ResourceMethod.invokeOnTarget(ResourceMethod.
    java:260)
            at org.jboss.resteasy.core.ResourceMethod.invoke(ResourceMethod.java:232
    )
            at org.jboss.resteasy.core.ResourceMethod.invoke(ResourceMethod.java:166
    )
            at org.jboss.resteasy.core.DispatcherUtilities.getJaxrsResponse(Dispatch
    erUtilities.java:142)
            at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispa
    tcher.java:356)
            at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispa
    tcher.java:173)
            at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.servi
    ce(HttpServletDispatcher.java:93)
            at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.servi
    ce(HttpServletDispatcher.java:68)
            at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
            at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
    icationFilterChain.java:290)
            at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
    ilterChain.java:206)


    If I have a request in that works for SOAP, how do I send the same request in REST?

    Thanks!
  • omatzura's avatar
    omatzura
    Super Contributor
    Hi!

    I'm sorry, but I don't know how your server expects this to be done, as far as I know there is no standard way of doing this. Have you made sure the namespace declarations are present in the root element of your xml request? (in the SOAP request they were probably defined at the Envelope level)

    regards!

    /Ole
    eviware.com
  • irene_smile's avatar
    irene_smile
    Occasional Contributor
    Thanks for your response.

    1) If I have an XML that works in SOAP, where is the place to copy that XML for Rest? Is it in the space below Media Type in Request Form? Or is there any other area where I could paste the XML?

    2) Do you know about a sample Rest Service that has XML body?

    Thanks!
  • omatzura's avatar
    omatzura
    Super Contributor
    Hi,

    Unfortunately there is no general answer here, maybe the REST counterpart of your SOAP service uses parameters instead of the message body, maybe a totally different xml body format is required. It's really hard to know, please post this on the REST/SOAP forum of your server-software so they can tell you!

    regards!

    /Ole
    eviware.com