javaee / metro-jax-ws

https://javaee.github.io/metro-jax-ws/
Other
132 stars 68 forks source link

Strange error when throwing HTTPException from Provider<Source> invoke() method #1229

Open LanceAndersen opened 6 years ago

LanceAndersen commented 6 years ago

Previously tracked via: https://bugs.openjdk.java.net/browse/JDK-7068897

FULL PRODUCT VERSION : java version "1.7.0" Java(TM) SE Runtime Environment (build 1.7.0-b147) Java HotSpot(TM) Client VM (build 21.0-b17, mixed mode, sharing)

ADDITIONAL OS VERSION INFORMATION : Windows XP SP3

A DESCRIPTION OF THE PROBLEM : I've created a JAX-WS-based RESTful web service using JDK 7. When my Provider's invoke() method throws javax.xml.ws.http.HTTPException and I try to read XML content via my client, I obtain an error message (on the web service's console) such as the message shown below:

Jul 20, 2011 2:22:39 PM com.sun.xml.internal.ws.server.provider.SyncProviderInvokerTube processRequest SEVERE: null javax.xml.ws.http.HTTPException at Service.invoke(Service.java:27) at Service.invoke(Service.java:17) at com.sun.xml.internal.ws.api.server.InstanceResolver$1.invokeProvider(InstanceResolver.java:245) at com.sun.xml.internal.ws.server.InvokerTube$2.invokeProvider(InvokerTube.java:145) at com.sun.xml.internal.ws.server.provider.SyncProviderInvokerTube.processRequest(SyncProviderInvokerTube.java:68) at com.sun.xml.internal.ws.api.pipe.Fiber.__doRun(Fiber.java:626) at com.sun.xml.internal.ws.api.pipe.Fiber._doRun(Fiber.java:585) at com.sun.xml.internal.ws.api.pipe.Fiber.doRun(Fiber.java:570) at com.sun.xml.internal.ws.api.pipe.Fiber.runSync(Fiber.java:467) at com.sun.xml.internal.ws.server.WSEndpointImpl$2.process(WSEndpointImpl.java:299) at com.sun.xml.internal.ws.transport.http.HttpAdapter$HttpToolkit.handle(HttpAdapter.java:593) at com.sun.xml.internal.ws.transport.http.HttpAdapter.handle(HttpAdapter.java:244) at com.sun.xml.internal.ws.transport.http.server.WSHttpHandler.handleExchange(WSHttpHandler.java:95) at com.sun.xml.internal.ws.transport.http.server.WSHttpHandler.handle(WSHttpHandler.java:80) at com.sun.net.httpserver.Filter$Chain.doFilter(Filter.java:77) at sun.net.httpserver.AuthFilter.doFilter(AuthFilter.java:83) at com.sun.net.httpserver.Filter$Chain.doFilter(Filter.java:80) at sun.net.httpserver.ServerImpl$Exchange$LinkHandler.handle(ServerImpl.java:665) at com.sun.net.httpserver.Filter$Chain.doFilter(Filter.java:77) at sun.net.httpserver.ServerImpl$Exchange.run(ServerImpl.java:637) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603) at java.lang.Thread.run(Thread.java:722)

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :

  1. Compile the following Service.java source code:

import javax.annotation.Resource;

import javax.xml.transform.Source;

import javax.xml.ws.BindingType; import javax.xml.ws.Endpoint; import javax.xml.ws.Provider; import javax.xml.ws.ServiceMode; import javax.xml.ws.WebServiceContext; import javax.xml.ws.WebServiceProvider;

import javax.xml.ws.handler.MessageContext;

import javax.xml.ws.http.HTTPBinding; import javax.xml.ws.http.HTTPException;

@WebServiceProvider @ServiceMode(value = javax.xml.ws.Service.Mode.MESSAGE) @BindingType(value = HTTPBinding.HTTP_BINDING) public class Service implements Provider { @Resource private WebServiceContext wsContext; @Override public Source invoke(Source request) { throw new HTTPException(405); } public static void main(String[] args) { Endpoint.publish("http://localhost:9902/service", new Service()); } }

  1. Run this application in one command window.

  2. Compile the following Client.java Source code:

import java.io.BufferedReader; import java.io.InputStreamReader;

import java.net.HttpURLConnection; import java.net.URL;

public class Client { final static String LIBURI = "http://localhost:9902/service"; public static void main(String[] args) throws Exception { doGet(); } static void doGet() throws Exception { URL url = new URL(LIBURI); HttpURLConnection httpurlc = (HttpURLConnection) url.openConnection(); httpurlc.setRequestMethod("GET"); httpurlc.setDoInput(true);

  InputStreamReader isr;
  isr = new InputStreamReader(httpurlc.getInputStream());
  BufferedReader br = new BufferedReader(isr);
  StringBuilder xml = new StringBuilder();
  String line;
  while ((line = br.readLine()) != null)
     xml.append(line);
  System.out.println(xml);
  System.out.println();

} }

  1. Run this application in another command window.

EXPECTED VERSUS ACTUAL BEHAVIOR : EXPECTED - I did not expect to see the invokertube error message in the Service's command window. ACTUAL - Jul 20, 2011 2:22:39 PM com.sun.xml.internal.ws.server.provider.SyncProviderInvokerTube processRequest SEVERE: null javax.xml.ws.http.HTTPException at Service.invoke(Service.java:27) at Service.invoke(Service.java:17) at com.sun.xml.internal.ws.api.server.InstanceResolver$1.invokeProvider(InstanceResolver.java:245) at com.sun.xml.internal.ws.server.InvokerTube$2.invokeProvider(InvokerTube.java:145) at com.sun.xml.internal.ws.server.provider.SyncProviderInvokerTube.processRequest(SyncProviderInvokerTube.java:68) at com.sun.xml.internal.ws.api.pipe.Fiber.__doRun(Fiber.java:626) at com.sun.xml.internal.ws.api.pipe.Fiber._doRun(Fiber.java:585) at com.sun.xml.internal.ws.api.pipe.Fiber.doRun(Fiber.java:570) at com.sun.xml.internal.ws.api.pipe.Fiber.runSync(Fiber.java:467) at com.sun.xml.internal.ws.server.WSEndpointImpl$2.process(WSEndpointImpl.java:299) at com.sun.xml.internal.ws.transport.http.HttpAdapter$HttpToolkit.handle(HttpAdapter.java:593) at com.sun.xml.internal.ws.transport.http.HttpAdapter.handle(HttpAdapter.java:244) at com.sun.xml.internal.ws.transport.http.server.WSHttpHandler.handleExchange(WSHttpHandler.java:95) at com.sun.xml.internal.ws.transport.http.server.WSHttpHandler.handle(WSHttpHandler.java:80) at com.sun.net.httpserver.Filter$Chain.doFilter(Filter.java:77) at sun.net.httpserver.AuthFilter.doFilter(AuthFilter.java:83) at com.sun.net.httpserver.Filter$Chain.doFilter(Filter.java:80) at sun.net.httpserver.ServerImpl$Exchange$LinkHandler.handle(ServerImpl.java:665) at com.sun.net.httpserver.Filter$Chain.doFilter(Filter.java:77) at sun.net.httpserver.ServerImpl$Exchange.run(ServerImpl.java:637) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603) at java.lang.Thread.run(Thread.java:722)

In addition to the aforementioned error message, the Client application displays the following output:

Exception in thread "main" java.io.IOException: Server returned HTTP response code: 405 for URL: http://localhost:9902/service at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1612) at Client.doGet(Client.java:22) at Client.main(Client.java:12)

REPRODUCIBILITY : This bug can be reproduced always.

---------- BEGIN SOURCE ---------- // 1: Service.java

import javax.annotation.Resource;

import javax.xml.transform.Source;

import javax.xml.ws.BindingType; import javax.xml.ws.Endpoint; import javax.xml.ws.Provider; import javax.xml.ws.ServiceMode; import javax.xml.ws.WebServiceContext; import javax.xml.ws.WebServiceProvider;

import javax.xml.ws.handler.MessageContext;

import javax.xml.ws.http.HTTPBinding; import javax.xml.ws.http.HTTPException;

@WebServiceProvider @ServiceMode(value = javax.xml.ws.Service.Mode.MESSAGE) @BindingType(value = HTTPBinding.HTTP_BINDING) public class Service implements Provider { @Resource private WebServiceContext wsContext; @Override public Source invoke(Source request) { throw new HTTPException(405); } public static void main(String[] args) { Endpoint.publish("http://localhost:9902/service", new Service()); } }

// 2: Client.java

import java.io.BufferedReader; import java.io.InputStreamReader;

import java.net.HttpURLConnection; import java.net.URL;

public class Client { final static String LIBURI = "http://localhost:9902/service"; public static void main(String[] args) throws Exception { doGet(); } static void doGet() throws Exception { URL url = new URL(LIBURI); HttpURLConnection httpurlc = (HttpURLConnection) url.openConnection(); httpurlc.setRequestMethod("GET"); httpurlc.setDoInput(true);

  InputStreamReader isr;
  isr = new InputStreamReader(httpurlc.getInputStream());
  BufferedReader br = new BufferedReader(isr);
  StringBuilder xml = new StringBuilder();
  String line;
  while ((line = br.readLine()) != null)
     xml.append(line);
  System.out.println(xml);
  System.out.println();

} }

  1. Run this application in another command window.

In addition to the aforementioned error message, the Client application displays the following output:

---------- END SOURCE ----------