use of jakarta.xml.ws.WebServiceException in project metro-jax-ws by eclipse-ee4j.
the class LocalAsyncTransportTube method processRequest.
@NotNull
@Override
public NextAction processRequest(@NotNull Packet request) {
try {
// Set up WSConnection with tranport headers, request content
// get transport headers from message
reqHeaders.clear();
Map<String, List<String>> rh = (Map<String, List<String>>) request.invocationProperties.get(MessageContext.HTTP_REQUEST_HEADERS);
// assign empty map if its null
if (rh != null) {
reqHeaders.putAll(rh);
}
MyClosedCallback callback = new MyClosedCallback(request);
LocalConnectionImpl con = new LocalConnectionImpl(baseURI, reqHeaders, callback);
callback.setConnection(con);
// Calling getStaticContentType sets some internal state in the codec
// TODO : need to fix this properly in Codec
ContentType contentType = codec.getStaticContentType(request);
String requestContentType;
if (contentType != null) {
requestContentType = contentType.getContentType();
codec.encode(request, con.getOutput());
} else {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
contentType = codec.encode(request, baos);
requestContentType = contentType.getContentType();
baos.writeTo(con.getOutput());
}
callback.setContentType(contentType);
reqHeaders.put("Content-Type", Collections.singletonList(requestContentType));
String requestAccept = contentType.getAcceptHeader();
if (contentType.getAcceptHeader() != null) {
reqHeaders.put("Accept", Collections.singletonList(requestAccept));
}
if (dump) {
dump(con, "request", reqHeaders);
}
// Packet serverReq = adapter.decodePacket(con, codec);
adapter.invokeAsync(con);
return doSuspend();
} catch (IOException ioe) {
throw new WebServiceException(ioe);
}
}
use of jakarta.xml.ws.WebServiceException in project metro-jax-ws by eclipse-ee4j.
the class LocalTransportTube method process.
public Packet process(Packet request) {
try {
// Set up WSConnection with tranport headers, request content
// get transport headers from message
reqHeaders.clear();
Map<String, List<String>> rh = (Map<String, List<String>>) request.invocationProperties.get(MessageContext.HTTP_REQUEST_HEADERS);
// assign empty map if its null
if (rh != null) {
reqHeaders.putAll(rh);
}
LocalConnectionImpl con = new LocalConnectionImpl(baseURI, reqHeaders);
// Calling getStaticContentType sets some internal state in the codec
// TODO : need to fix this properly in Codec
ContentType contentType = codec.getStaticContentType(request);
String requestContentType;
if (contentType != null) {
requestContentType = contentType.getContentType();
codec.encode(request, con.getOutput());
} else {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
contentType = codec.encode(request, baos);
requestContentType = contentType.getContentType();
baos.writeTo(con.getOutput());
}
reqHeaders.put("Content-Type", Collections.singletonList(requestContentType));
String requestAccept = contentType.getAcceptHeader();
if (contentType.getAcceptHeader() != null) {
reqHeaders.put("Accept", Collections.singletonList(requestAccept));
}
writeSOAPAction(reqHeaders, contentType.getSOAPActionHeader(), request);
if (dump)
dump(con, "request", reqHeaders);
adapter.handle(con);
if (dump)
dump(con, "response", con.getResponseHeaders());
String responseContentType = getResponseContentType(con);
if (con.getStatus() == WSHTTPConnection.ONEWAY) {
// one way. no response given.
return request.createClientResponse(null);
}
// TODO: check if returned MIME type is the same as that which was sent
// or is acceptable if an Accept header was used
checkFIConnegIntegrity(request.contentNegotiation, requestContentType, requestAccept, responseContentType);
Packet reply = request.createClientResponse(null);
codec.decode(con.getInput(), responseContentType, reply);
return reply;
} catch (IOException ex) {
throw new WebServiceException(ex);
}
}
use of jakarta.xml.ws.WebServiceException in project metro-jax-ws by eclipse-ee4j.
the class WSSPIContextListener method contextInitialized.
public void contextInitialized(ServletContextEvent event) {
if (logger.isLoggable(Level.INFO)) {
logger.info("JAX-WS context listener initializing");
}
ServletContext context = event.getServletContext();
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
if (classLoader == null) {
classLoader = getClass().getClassLoader();
}
try {
// Parse the descriptor file and build endpoint infos
DeploymentDescriptorParser<EndpointAdapter> parser = new DeploymentDescriptorParser<>(classLoader, new ServletResourceLoader(context), new EndpointAdapterFactory());
URL sunJaxWsXml = context.getResource(JAXWS_RI_RUNTIME);
if (sunJaxWsXml == null)
throw new WebServiceException("Runtime descriptor " + JAXWS_RI_RUNTIME + " is mising");
List<EndpointAdapter> adapters = parser.parse(sunJaxWsXml.toExternalForm(), sunJaxWsXml.openStream());
for (EndpointAdapter adapter : adapters) {
adapter.publish();
}
delegate = createDelegate(adapters, context);
context.setAttribute(WSSPIServlet.JAXWS_RI_RUNTIME_INFO, delegate);
} catch (Throwable e) {
logger.log(Level.SEVERE, "failed to parse runtime descriptor", e);
context.removeAttribute(WSSPIServlet.JAXWS_RI_RUNTIME_INFO);
throw new WebServiceException("failed to parse runtime descriptor", e);
}
}
use of jakarta.xml.ws.WebServiceException in project metro-jax-ws by eclipse-ee4j.
the class WSServletDelegate method doPut.
/**
* Handles HTTP PUT for XML/HTTP binding based endpoints
*
* @param request the HTTP request object
* @param response the HTTP response object
* @param context servlet context
*/
public void doPut(HttpServletRequest request, HttpServletResponse response, ServletContext context) {
// TODO: unify this into doGet.
try {
EndpointAdapter target = getTarget(request);
if (target != null) {
if (logger.isLoggable(Level.FINEST)) {
logger.log(Level.FINEST, "Got request for endpoint {0}", target.getUrlPattern());
}
} else {
writeNotFoundErrorPage(response, "Invalid request");
return;
}
Binding binding = target.getEndpoint().getBinding();
if (binding instanceof HTTPBinding) {
target.handle(context, request, response);
} else {
response.setStatus(HttpServletResponse.SC_METHOD_NOT_ALLOWED);
}
} catch (WebServiceException e) {
logger.log(Level.SEVERE, e.getLocalizedMessage(), e);
response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
} catch (Throwable e) {
logger.log(Level.SEVERE, "caught throwable", e);
response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
}
}
use of jakarta.xml.ws.WebServiceException in project metro-jax-ws by eclipse-ee4j.
the class HttpAdapter method encodePacket.
private void encodePacket(@NotNull Packet packet, @NotNull WSHTTPConnection con, @NotNull Codec codec) throws IOException {
if (isNonAnonymousUri(packet.endpointAddress) && packet.getMessage() != null) {
try {
// Message is targeted to non-anonymous response endpoint.
// After call to non-anonymous processor, typically, packet.getMessage() will be null
// however, processors could use this pattern to modify the response sent on the back-channel,
// e.g. send custom HTTP headers with the HTTP 202
packet = getNonAnonymousResponseProcessor().process(packet);
} catch (RuntimeException re) {
// if processing by NonAnonymousResponseProcessor fails, new SOAPFaultMessage is created to be sent
// to back-channel client
SOAPVersion soapVersion = packet.getBinding().getSOAPVersion();
Message faultMsg = SOAPFaultBuilder.createSOAPFaultMessage(soapVersion, null, re);
packet = packet.createServerResponse(faultMsg, packet.endpoint.getPort(), null, packet.endpoint.getBinding());
}
}
if (con.isClosed()) {
// Connection is already closed
return;
}
Message responseMessage = packet.getMessage();
addStickyCookie(con);
addReplicaCookie(con, packet);
if (responseMessage == null) {
if (!con.isClosed()) {
// for example, 415 may have been set earlier for Unsupported Content-Type
if (con.getStatus() == 0) {
con.setStatus(WSHTTPConnection.ONEWAY);
}
OutputStream os = con.getProtocol().contains("1.1") ? con.getOutput() : new Http10OutputStream(con);
if (dump || LOGGER.isLoggable(Level.FINER)) {
ByteArrayBuffer buf = new ByteArrayBuffer();
codec.encode(packet, buf);
dump(buf, "HTTP response " + con.getStatus(), con.getResponseHeaders());
buf.writeTo(os);
} else {
codec.encode(packet, os);
}
// close the response channel now
try {
// no payload
os.close();
} catch (IOException e) {
throw new WebServiceException(e);
}
}
} else {
if (con.getStatus() == 0) {
// if the appliation didn't set the status code,
// set the default one.
con.setStatus(responseMessage.isFault() ? HttpURLConnection.HTTP_INTERNAL_ERROR : HttpURLConnection.HTTP_OK);
}
if (isClientErrorStatus(con.getStatus())) {
OutputStream os = con.getOutput();
if (dump || LOGGER.isLoggable(Level.FINER)) {
ByteArrayBuffer buf = new ByteArrayBuffer();
writeClientError(con.getStatus(), buf, packet);
dump(buf, "HTTP response " + con.getStatus(), con.getResponseHeaders());
buf.writeTo(os);
} else {
writeClientError(con.getStatus(), os, packet);
}
os.close();
return;
}
ContentType contentType = codec.getStaticContentType(packet);
if (contentType != null) {
con.setContentTypeResponseHeader(contentType.getContentType());
OutputStream os = con.getProtocol().contains("1.1") ? con.getOutput() : new Http10OutputStream(con);
if (dump || LOGGER.isLoggable(Level.FINER)) {
ByteArrayBuffer buf = new ByteArrayBuffer();
codec.encode(packet, buf);
dump(buf, "HTTP response " + con.getStatus(), con.getResponseHeaders());
buf.writeTo(os);
} else {
codec.encode(packet, os);
}
os.close();
} else {
ByteArrayBuffer buf = new ByteArrayBuffer();
contentType = codec.encode(packet, buf);
con.setContentTypeResponseHeader(contentType.getContentType());
if (dump || LOGGER.isLoggable(Level.FINER)) {
dump(buf, "HTTP response " + con.getStatus(), con.getResponseHeaders());
}
OutputStream os = con.getOutput();
buf.writeTo(os);
os.close();
}
}
}
Aggregations