TOMEE-4057 - Remove CXF classes from our patch sources which do not contain any 'real' patches
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/annotations/Policy.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/annotations/Policy.java
deleted file mode 100644
index a0d4a75..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/annotations/Policy.java
+++ /dev/null
@@ -1,80 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.cxf.annotations;
-
-import java.lang.annotation.Documented;
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Inherited;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-/**
- * Attaches a Policy to a service or method
- */
-@Documented
-@Retention(RetentionPolicy.RUNTIME)
-@Target({ ElementType.TYPE, ElementType.METHOD })
-@Inherited
-public @interface Policy {
-
- String uri();
-
- boolean includeInWSDL() default true;
-
-
- /**
- * The place to put the PolicyReference. The Default depends on the
- * location of the annotation. On the method in the SEI, it would be
- * the binding/operation, on the SEI, it would be the binding, on the
- * service impl, the service element.
- * @return location
- */
- Placement placement() default Placement.DEFAULT;
-
- /**
- * If Placement is PORT_TYPE_OPERATION_FAULT, or BINDING_OPERATION_FAULT,
- * return the fault class associated with this documentation
- * @return the fault class
- */
- Class<?> faultClass() default DEFAULT.class;
-
- enum Placement {
- DEFAULT,
-
- PORT_TYPE,
- PORT_TYPE_OPERATION,
- PORT_TYPE_OPERATION_INPUT,
- PORT_TYPE_OPERATION_OUTPUT,
- PORT_TYPE_OPERATION_FAULT,
-
- BINDING,
- BINDING_OPERATION,
- BINDING_OPERATION_INPUT,
- BINDING_OPERATION_OUTPUT,
- BINDING_OPERATION_FAULT,
-
- SERVICE,
- SERVICE_PORT,
- }
-
- final class DEFAULT { }
-}
-
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/annotations/WSDLDocumentation.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/annotations/WSDLDocumentation.java
deleted file mode 100644
index 9116f1c..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/annotations/WSDLDocumentation.java
+++ /dev/null
@@ -1,88 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.cxf.annotations;
-
-
-import java.lang.annotation.Documented;
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Inherited;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-
-/**
- * Adds documentation nodes to the generated WSDL
- */
-@Documented
-@Retention(RetentionPolicy.RUNTIME)
-@Target({ ElementType.TYPE, ElementType.METHOD })
-@Inherited
-public @interface WSDLDocumentation {
- /**
- * The documentation to add
- * @return documentation string
- */
- String value();
-
- /**
- * The place to put the documentation. The Default depends on the
- * location of the annotation. On the method in the SEI, it would be
- * the portType/operation, on the SEI, it would be the portType, on the
- * service impl, the service element.
- * @return location
- */
- Placement placement() default Placement.DEFAULT;
-
- /**
- * If Placement is FAULT_MESSAGE, PORT_FAULT, or BINDING_FAULT,
- * return the fault class associated with this documentation
- * @return the fault class
- */
- Class<?> faultClass() default DEFAULT.class;
-
- enum Placement {
- DEFAULT,
- TOP,
-
- INPUT_MESSAGE,
- OUTPUT_MESSAGE,
- FAULT_MESSAGE,
-
- PORT_TYPE,
- PORT_TYPE_OPERATION,
- PORT_TYPE_OPERATION_INPUT,
- PORT_TYPE_OPERATION_OUTPUT,
- PORT_TYPE_OPERATION_FAULT,
-
- BINDING,
- BINDING_OPERATION,
- BINDING_OPERATION_INPUT,
- BINDING_OPERATION_OUTPUT,
- BINDING_OPERATION_FAULT,
-
- SERVICE,
- SERVICE_PORT,
-
- }
-
-
- final class DEFAULT { }
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/attachment/AttachmentDataSource.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/attachment/AttachmentDataSource.java
deleted file mode 100644
index 6e4fa1a..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/attachment/AttachmentDataSource.java
+++ /dev/null
@@ -1,107 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.cxf.attachment;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-
-import javax.activation.DataSource;
-
-import org.apache.cxf.helpers.IOUtils;
-import org.apache.cxf.io.CacheSizeExceededException;
-import org.apache.cxf.io.CachedOutputStream;
-import org.apache.cxf.message.Message;
-
-public class AttachmentDataSource implements DataSource {
-
- private final String ct;
- private CachedOutputStream cache;
- private InputStream ins;
- private DelegatingInputStream delegate;
- private String name;
-
- public AttachmentDataSource(String ctParam, InputStream inParam) {
- this.ct = ctParam;
- ins = inParam;
- }
-
- public boolean isCached() {
- return cache != null;
- }
- public void cache(Message message) throws IOException {
- if (cache == null) {
- cache = new CachedOutputStream();
- AttachmentUtil.setStreamedAttachmentProperties(message, cache);
- try {
- IOUtils.copyAndCloseInput(ins, cache);
- cache.lockOutputStream();
- if (delegate != null) {
- delegate.setInputStream(cache.getInputStream());
- }
- } catch (CacheSizeExceededException | IOException cee) {
- cache.close();
- cache = null;
- throw cee;
- } finally {
- ins = null;
- }
- }
- }
- public void hold(Message message) throws IOException {
- cache(message);
- cache.holdTempFile();
- }
- public void release() {
- if (cache != null) {
- cache.releaseTempFileHold();
- }
- }
-
- public String getContentType() {
- return ct;
- }
-
- public InputStream getInputStream() {
- try {
- if (cache != null) {
- return cache.getInputStream();
- }
- if (delegate == null) {
- delegate = new DelegatingInputStream(ins);
- }
- return delegate;
- } catch (IOException e) {
- return null;
- }
- }
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public OutputStream getOutputStream() throws IOException {
- throw new UnsupportedOperationException();
- }
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/attachment/AttachmentDeserializer.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/attachment/AttachmentDeserializer.java
deleted file mode 100644
index 55a1dcc..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/attachment/AttachmentDeserializer.java
+++ /dev/null
@@ -1,462 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.cxf.attachment;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.PushbackInputStream;
-import java.nio.charset.StandardCharsets;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.TreeMap;
-import java.util.logging.Logger;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-import javax.activation.DataSource;
-
-import org.apache.cxf.common.logging.LogUtils;
-import org.apache.cxf.common.util.StringUtils;
-import org.apache.cxf.common.util.SystemPropertyAction;
-import org.apache.cxf.helpers.HttpHeaderHelper;
-import org.apache.cxf.helpers.IOUtils;
-import org.apache.cxf.io.CachedOutputStream;
-import org.apache.cxf.message.Attachment;
-import org.apache.cxf.message.Message;
-import org.apache.cxf.message.MessageUtils;
-
-public class AttachmentDeserializer {
- public static final String ATTACHMENT_PART_HEADERS = AttachmentDeserializer.class.getName() + ".headers";
-
- /**
- * Allowed value is any instance of {@link File} or {@link String}.
- */
- public static final String ATTACHMENT_DIRECTORY = "attachment-directory";
-
- /**
- * The memory threshold of attachments. Allowed value is any instance of {@link Number} or {@link String}.
- * The default is {@link AttachmentDeserializer#THRESHOLD}.
- */
- public static final String ATTACHMENT_MEMORY_THRESHOLD = "attachment-memory-threshold";
-
- /**
- * The maximum size of the attachment. Allowed value is any of {@link Number} or {@link String}.
- */
- public static final String ATTACHMENT_MAX_SIZE = "attachment-max-size";
-
- /**
- * The maximum number of attachments permitted in a message. The default is 50.
- */
- public static final String ATTACHMENT_MAX_COUNT = "attachment-max-count";
-
- /**
- * The maximum MIME Header Length. The default is 300.
- */
- public static final String ATTACHMENT_MAX_HEADER_SIZE = "attachment-max-header-size";
- public static final int DEFAULT_MAX_HEADER_SIZE =
- SystemPropertyAction.getInteger("org.apache.cxf.attachment-max-header-size", 300);
-
- public static final int THRESHOLD = 1024 * 100; //100K (byte unit)
-
- private static final Pattern CONTENT_TYPE_BOUNDARY_PATTERN = Pattern.compile("boundary=\"?([^\";]*)");
-
- private static final Pattern INPUT_STREAM_BOUNDARY_PATTERN =
- Pattern.compile("^--(\\S*)$", Pattern.MULTILINE);
-
- private static final Logger LOG = LogUtils.getL7dLogger(AttachmentDeserializer.class);
-
- private static final int PUSHBACK_AMOUNT = 2048;
-
- private boolean lazyLoading = true;
-
- private PushbackInputStream stream;
- private int createCount;
- private int closedCount;
- private boolean closed;
-
- private byte[] boundary;
-
- private LazyAttachmentCollection attachments;
-
- private Message message;
-
- private InputStream body;
-
- private Set<DelegatingInputStream> loaded = new HashSet<>();
- private List<String> supportedTypes;
-
- private int maxHeaderLength = DEFAULT_MAX_HEADER_SIZE;
-
- public AttachmentDeserializer(Message message) {
- this(message, Collections.singletonList("multipart/related"));
- }
-
- public AttachmentDeserializer(Message message, List<String> supportedTypes) {
- this.message = message;
- this.supportedTypes = supportedTypes;
-
- // Get the maximum Header length from configuration
- maxHeaderLength = MessageUtils.getContextualInteger(message, ATTACHMENT_MAX_HEADER_SIZE,
- DEFAULT_MAX_HEADER_SIZE);
- }
-
- public void initializeAttachments() throws IOException {
- initializeRootMessage();
-
- Object maxCountProperty = message.getContextualProperty(AttachmentDeserializer.ATTACHMENT_MAX_COUNT);
- int maxCount = 50;
- if (maxCountProperty != null) {
- if (maxCountProperty instanceof Integer) {
- maxCount = (Integer)maxCountProperty;
- } else {
- maxCount = Integer.parseInt((String)maxCountProperty);
- }
- }
-
- attachments = new LazyAttachmentCollection(this, maxCount);
- message.setAttachments(attachments);
- }
-
- protected void initializeRootMessage() throws IOException {
- String contentType = (String) message.get(Message.CONTENT_TYPE);
-
- if (contentType == null) {
- throw new IllegalStateException("Content-Type can not be empty!");
- }
-
- if (message.getContent(InputStream.class) == null) {
- throw new IllegalStateException("An InputStream must be provided!");
- }
-
- if (AttachmentUtil.isTypeSupported(contentType.toLowerCase(), supportedTypes)) {
- String boundaryString = findBoundaryFromContentType(contentType);
- if (null == boundaryString) {
- boundaryString = findBoundaryFromInputStream();
- }
- // If a boundary still wasn't found, throw an exception
- if (null == boundaryString) {
- throw new IOException("Couldn't determine the boundary from the message!");
- }
- boundary = boundaryString.getBytes(StandardCharsets.UTF_8);
-
- stream = new PushbackInputStream(message.getContent(InputStream.class), PUSHBACK_AMOUNT);
- if (!readTillFirstBoundary(stream, boundary)) {
- throw new IOException("Couldn't find MIME boundary: " + boundaryString);
- }
-
- Map<String, List<String>> ih = loadPartHeaders(stream);
- message.put(ATTACHMENT_PART_HEADERS, ih);
- String val = AttachmentUtil.getHeader(ih, "Content-Type", "; ");
- if (!StringUtils.isEmpty(val)) {
- String cs = HttpHeaderHelper.findCharset(val);
- if (!StringUtils.isEmpty(cs)) {
- message.put(Message.ENCODING, HttpHeaderHelper.mapCharset(cs));
- }
- }
- val = AttachmentUtil.getHeader(ih, "Content-Transfer-Encoding");
-
- MimeBodyPartInputStream mmps = new MimeBodyPartInputStream(stream, boundary, PUSHBACK_AMOUNT);
- InputStream ins = AttachmentUtil.decode(mmps, val);
- if (ins != mmps) {
- ih.remove("Content-Transfer-Encoding");
- }
- body = new DelegatingInputStream(ins, this);
- createCount++;
- message.setContent(InputStream.class, body);
- }
- }
-
- private String findBoundaryFromContentType(String ct) {
- // Use regex to get the boundary and return null if it's not found
- Matcher m = CONTENT_TYPE_BOUNDARY_PATTERN.matcher(ct);
- return m.find() ? "--" + m.group(1) : null;
- }
-
- private String findBoundaryFromInputStream() throws IOException {
- InputStream is = message.getContent(InputStream.class);
- //boundary should definitely be in the first 2K;
- PushbackInputStream in = new PushbackInputStream(is, 4096);
- byte[] buf = new byte[2048];
- int i = in.read(buf);
- int len = i;
- while (i > 0 && len < buf.length) {
- i = in.read(buf, len, buf.length - len);
- if (i > 0) {
- len += i;
- }
- }
- String msg = IOUtils.newStringFromBytes(buf, 0, len);
- in.unread(buf, 0, len);
-
- // Reset the input stream since we'll need it again later
- message.setContent(InputStream.class, in);
-
- // Use regex to get the boundary and return null if it's not found
- Matcher m = INPUT_STREAM_BOUNDARY_PATTERN.matcher(msg);
- return m.find() ? "--" + m.group(1) : null;
- }
-
- public AttachmentImpl readNext() throws IOException {
- // Cache any mime parts that are currently being streamed
- cacheStreamedAttachments();
- if (closed) {
- return null;
- }
-
- int v = stream.read();
- if (v == -1) {
- return null;
- }
- stream.unread(v);
-
- Map<String, List<String>> headers = loadPartHeaders(stream);
- return (AttachmentImpl)createAttachment(headers);
- }
-
- private void cacheStreamedAttachments() throws IOException {
- if (body instanceof DelegatingInputStream
- && !((DelegatingInputStream) body).isClosed()) {
-
- cache((DelegatingInputStream) body);
- }
-
- List<Attachment> atts = new ArrayList<>(attachments.getLoadedAttachments());
- for (Attachment a : atts) {
- DataSource s = a.getDataHandler().getDataSource();
- if (s instanceof AttachmentDataSource) {
- AttachmentDataSource ads = (AttachmentDataSource)s;
- if (!ads.isCached()) {
- ads.cache(message);
- }
- } else if (s.getInputStream() instanceof DelegatingInputStream) {
- cache((DelegatingInputStream) s.getInputStream());
- } else {
- //assume a normal stream that is already cached
- }
- }
- }
-
- private void cache(DelegatingInputStream input) throws IOException {
- if (loaded.contains(input)) {
- return;
- }
- loaded.add(input);
- InputStream origIn = input.getInputStream();
- try (CachedOutputStream out = new CachedOutputStream()) {
- AttachmentUtil.setStreamedAttachmentProperties(message, out);
- IOUtils.copy(input, out);
- input.setInputStream(out.getInputStream());
- origIn.close();
- }
- }
-
- /**
- * Move the read pointer to the begining of the first part read till the end
- * of first boundary
- *
- * @param pushbackInStream
- * @param boundary
- * @throws IOException
- */
- private static boolean readTillFirstBoundary(PushbackInputStream pushbackInStream,
- byte[] boundary) throws IOException {
-
- // work around a bug in PushBackInputStream where the buffer isn't
- // initialized
- // and available always returns 0.
- int value = pushbackInStream.read();
- pushbackInStream.unread(value);
- while (value != -1) {
- value = pushbackInStream.read();
- if ((byte) value == boundary[0]) {
- int boundaryIndex = 0;
- while (value != -1 && (boundaryIndex < boundary.length) && ((byte) value == boundary[boundaryIndex])) {
-
- value = pushbackInStream.read();
- if (value == -1) {
- throw new IOException("Unexpected End while searching for first Mime Boundary");
- }
- boundaryIndex++;
- }
- if (boundaryIndex == boundary.length) {
- // boundary found, read the newline
- if (value == 13) {
- pushbackInStream.read();
- }
- return true;
- }
- }
- }
- return false;
- }
-
- /**
- * Create an Attachment from the MIME stream. If there is a previous attachment
- * that is not read, cache that attachment.
- *
- * @throws IOException
- */
- private Attachment createAttachment(Map<String, List<String>> headers) throws IOException {
- InputStream partStream =
- new DelegatingInputStream(new MimeBodyPartInputStream(stream, boundary, PUSHBACK_AMOUNT),
- this);
- createCount++;
-
- return AttachmentUtil.createAttachment(partStream, headers);
- }
-
- public boolean isLazyLoading() {
- return lazyLoading;
- }
-
- public void setLazyLoading(boolean lazyLoading) {
- this.lazyLoading = lazyLoading;
- }
-
- public void markClosed(DelegatingInputStream delegatingInputStream) throws IOException {
- closedCount++;
- if (closedCount == createCount && !attachments.hasNext(false)) {
- int x = stream.read();
- while (x != -1) {
- x = stream.read();
- }
- stream.close();
- closed = true;
- }
- }
- /**
- * Check for more attachment.
- *
- * @return whether there is more attachment or not. It will not deserialize the next attachment.
- * @throws IOException
- */
- public boolean hasNext() throws IOException {
- cacheStreamedAttachments();
- if (closed) {
- return false;
- }
-
- int v = stream.read();
- if (v == -1) {
- return false;
- }
- stream.unread(v);
- return true;
- }
-
-
-
- private Map<String, List<String>> loadPartHeaders(InputStream in) throws IOException {
- StringBuilder buffer = new StringBuilder(128);
- StringBuilder b = new StringBuilder(128);
- Map<String, List<String>> heads = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
-
- // loop until we hit the end or a null line
- while (readLine(in, b)) {
- // lines beginning with white space get special handling
- char c = b.charAt(0);
- if (c == ' ' || c == '\t') {
- if (buffer.length() != 0) {
- // preserve the line break and append the continuation
- buffer.append("\r\n");
- buffer.append(b);
- }
- } else {
- // if we have a line pending in the buffer, flush it
- if (buffer.length() > 0) {
- addHeaderLine(heads, buffer);
- buffer.setLength(0);
- }
- // add this to the accumulator
- buffer.append(b);
- }
- }
-
- // if we have a line pending in the buffer, flush it
- if (buffer.length() > 0) {
- addHeaderLine(heads, buffer);
- }
- return heads;
- }
-
- private boolean readLine(InputStream in, StringBuilder buffer) throws IOException {
- if (buffer.length() != 0) {
- buffer.setLength(0);
- }
- int c;
-
- while ((c = in.read()) != -1) {
- // a linefeed is a terminator, always.
- if (c == '\n') {
- break;
- } else if (c == '\r') {
- //just ignore the CR. The next character SHOULD be an NL. If not, we're
- //just going to discard this
- continue;
- } else {
- // just add to the buffer
- buffer.append((char)c);
- }
-
- if (buffer.length() > maxHeaderLength) {
- LOG.fine("The attachment header size has exceeded the configured parameter: " + maxHeaderLength);
- throw new HeaderSizeExceededException();
- }
- }
-
- // no characters found...this was either an eof or a null line.
- return buffer.length() != 0;
- }
-
- private void addHeaderLine(Map<String, List<String>> heads, StringBuilder line) {
- // null lines are a nop
- final int size = line.length();
- if (size == 0) {
- return;
- }
- int separator = line.indexOf(":");
- final String name;
- String value = "";
- if (separator == -1) {
- name = line.toString().trim();
- } else {
- name = line.substring(0, separator);
- // step past the separator. Now we need to remove any leading white space characters.
- separator++;
-
- while (separator < size) {
- char ch = line.charAt(separator);
- if (ch != ' ' && ch != '\t' && ch != '\r' && ch != '\n') {
- break;
- }
- separator++;
- }
- value = line.substring(separator);
- }
- List<String> v = heads.computeIfAbsent(name, k -> new ArrayList<>(1));
- v.add(value);
- }
-
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/attachment/AttachmentSerializer.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/attachment/AttachmentSerializer.java
deleted file mode 100644
index 3e65de3..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/attachment/AttachmentSerializer.java
+++ /dev/null
@@ -1,345 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.cxf.attachment;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.io.StringWriter;
-import java.io.Writer;
-import java.net.URLDecoder;
-import java.nio.charset.StandardCharsets;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-
-import javax.activation.DataHandler;
-
-import org.apache.cxf.common.util.Base64Utility;
-import org.apache.cxf.helpers.IOUtils;
-import org.apache.cxf.message.Attachment;
-import org.apache.cxf.message.Message;
-
-
-
-
-public class AttachmentSerializer {
- // http://tools.ietf.org/html/rfc2387
- private static final String DEFAULT_MULTIPART_TYPE = "multipart/related";
-
- private String contentTransferEncoding = AttachmentUtil.BINARY;
-
- private Message message;
- private String bodyBoundary;
- private OutputStream out;
- private String encoding;
-
- private String multipartType;
- private Map<String, List<String>> rootHeaders = Collections.emptyMap();
- private boolean xop = true;
- private boolean writeOptionalTypeParameters = true;
-
-
- public AttachmentSerializer(Message messageParam) {
- message = messageParam;
- }
-
- public AttachmentSerializer(Message messageParam,
- String multipartType,
- boolean writeOptionalTypeParameters,
- Map<String, List<String>> headers) {
- message = messageParam;
- this.multipartType = multipartType;
- this.writeOptionalTypeParameters = writeOptionalTypeParameters;
- this.rootHeaders = headers;
- }
-
- /**
- * Serialize the beginning of the attachment which includes the MIME
- * beginning and headers for the root message.
- */
- public void writeProlog() throws IOException {
- // Create boundary for body
- bodyBoundary = AttachmentUtil.getUniqueBoundaryValue();
-
- String bodyCt = (String) message.get(Message.CONTENT_TYPE);
- String bodyCtParams = null;
- String bodyCtParamsEscaped = null;
- // split the bodyCt to its head that is the type and its properties so that we
- // can insert the values at the right places based on the soap version and the mtom option
- // bodyCt will be of the form
- // soap11 -> text/xml
- // soap12 -> application/soap+xml; action="urn:ihe:iti:2007:RetrieveDocumentSet"
- if (bodyCt.indexOf(';') != -1) {
- int pos = bodyCt.indexOf(';');
- // get everything from the semi-colon
- bodyCtParams = bodyCt.substring(pos);
- bodyCtParamsEscaped = escapeQuotes(bodyCtParams);
- // keep the type/subtype part in bodyCt
- bodyCt = bodyCt.substring(0, pos);
- }
- // Set transport mime type
- String requestMimeType = multipartType == null ? DEFAULT_MULTIPART_TYPE : multipartType;
-
- StringBuilder ct = new StringBuilder(32);
- ct.append(requestMimeType);
-
- // having xop set to true implies multipart/related, but just in case...
- boolean xopOrMultipartRelated = xop
- || DEFAULT_MULTIPART_TYPE.equalsIgnoreCase(requestMimeType)
- || DEFAULT_MULTIPART_TYPE.startsWith(requestMimeType);
-
- // type is a required parameter for multipart/related only
- if (xopOrMultipartRelated
- && requestMimeType.indexOf("type=") == -1) {
- if (xop) {
- ct.append("; type=\"application/xop+xml\"");
- } else {
- ct.append("; type=\"").append(bodyCt).append('"');
- }
- }
-
- // boundary
- ct.append("; boundary=\"")
- .append(bodyBoundary)
- .append('"');
-
- String rootContentId = getHeaderValue("Content-ID", AttachmentUtil.BODY_ATTACHMENT_ID);
-
- // 'start' is a required parameter for XOP/MTOM, clearly defined
- // for simpler multipart/related payloads but is not needed for
- // multipart/mixed, multipart/form-data
- if (xopOrMultipartRelated) {
- ct.append("; start=\"<")
- .append(checkAngleBrackets(rootContentId))
- .append(">\"");
- }
-
- // start-info is a required parameter for XOP/MTOM, may be needed for
- // other WS cases but is redundant in simpler multipart/related cases
- // the parameters need to be included within the start-info's value in the escaped form
- if (writeOptionalTypeParameters || xop) {
- ct.append("; start-info=\"")
- .append(bodyCt);
- if (bodyCtParamsEscaped != null) {
- ct.append(bodyCtParamsEscaped);
- }
- ct.append('"');
- }
-
-
- message.put(Message.CONTENT_TYPE, ct.toString());
-
-
- // 2. write headers
- out = message.getContent(OutputStream.class);
- encoding = (String) message.get(Message.ENCODING);
- if (encoding == null) {
- encoding = StandardCharsets.UTF_8.name();
- }
- StringWriter writer = new StringWriter();
- writer.write("\r\n");
- writer.write("--");
- writer.write(bodyBoundary);
-
- StringBuilder mimeBodyCt = new StringBuilder();
- String bodyType = getHeaderValue("Content-Type", null);
- if (bodyType == null) {
- mimeBodyCt.append(xop ? "application/xop+xml" : bodyCt)
- .append("; charset=").append(encoding);
- if (xop) {
- mimeBodyCt.append("; type=\"").append(bodyCt);
- if (bodyCtParamsEscaped != null) {
- mimeBodyCt.append(bodyCtParamsEscaped);
- }
- mimeBodyCt.append('"');
- } else if (bodyCtParams != null) {
- mimeBodyCt.append(bodyCtParams);
- }
- } else {
- mimeBodyCt.append(bodyType);
- }
-
- writeHeaders(mimeBodyCt.toString(), rootContentId, rootHeaders, writer);
- out.write(writer.getBuffer().toString().getBytes(encoding));
- }
-
- private static String escapeQuotes(String s) {
- return s.indexOf('"') != 0 ? s.replace("\"", "\\\"") : s;
- }
-
- public void setContentTransferEncoding(String cte) {
- contentTransferEncoding = cte;
- }
-
- private String getHeaderValue(String name, String defaultValue) {
- List<String> value = rootHeaders.get(name);
- if (value == null || value.isEmpty()) {
- return defaultValue;
- }
- StringBuilder sb = new StringBuilder();
- for (int i = 0; i < value.size(); i++) {
- sb.append(value.get(i));
- if (i + 1 < value.size()) {
- sb.append(',');
- }
- }
- return sb.toString();
- }
-
- private void writeHeaders(String contentType, String attachmentId,
- Map<String, List<String>> headers, Writer writer) throws IOException {
- writer.write("\r\nContent-Type: ");
- writer.write(contentType);
- writer.write("\r\nContent-Transfer-Encoding: " + contentTransferEncoding + "\r\n");
-
- if (attachmentId != null) {
- attachmentId = checkAngleBrackets(attachmentId);
- writer.write("Content-ID: <");
- writer.write(URLDecoder.decode(attachmentId, StandardCharsets.UTF_8.name()));
- writer.write(">\r\n");
- }
- // headers like Content-Disposition need to be serialized
- for (Map.Entry<String, List<String>> entry : headers.entrySet()) {
- String name = entry.getKey();
- if ("Content-Type".equalsIgnoreCase(name) || "Content-ID".equalsIgnoreCase(name)
- || "Content-Transfer-Encoding".equalsIgnoreCase(name)) {
- continue;
- }
- writer.write(name);
- writer.write(": ");
- List<String> values = entry.getValue();
- for (int i = 0; i < values.size(); i++) {
- writer.write(values.get(i));
- if (i + 1 < values.size()) {
- writer.write(",");
- }
- }
- writer.write("\r\n");
- }
-
- writer.write("\r\n");
- }
-
- private static String checkAngleBrackets(String value) {
- if (value.charAt(0) == '<' && value.charAt(value.length() - 1) == '>') {
- return value.substring(1, value.length() - 1);
- }
- return value;
- }
-
- /**
- * Write the end of the body boundary and any attachments included.
- * @throws IOException
- */
- public void writeAttachments() throws IOException {
- if (message.getAttachments() != null) {
- for (Attachment a : message.getAttachments()) {
- StringWriter writer = new StringWriter();
- writer.write("\r\n--");
- writer.write(bodyBoundary);
-
- final Map<String, List<String>> headers;
- Iterator<String> it = a.getHeaderNames();
- if (it.hasNext()) {
- headers = new LinkedHashMap<>();
- while (it.hasNext()) {
- String key = it.next();
- headers.put(key, Collections.singletonList(a.getHeader(key)));
- }
- } else {
- headers = Collections.emptyMap();
- }
-
-
- DataHandler handler = a.getDataHandler();
- handler.setCommandMap(AttachmentUtil.getCommandMap());
-
- writeHeaders(handler.getContentType(), a.getId(),
- headers, writer);
- out.write(writer.getBuffer().toString().getBytes(encoding));
- if ("base64".equals(contentTransferEncoding)) {
- try (InputStream inputStream = handler.getInputStream()) {
- encodeBase64(inputStream, out, IOUtils.DEFAULT_BUFFER_SIZE);
- }
- } else {
- handler.writeTo(out);
- }
- }
- }
- StringWriter writer = new StringWriter();
- writer.write("\r\n--");
- writer.write(bodyBoundary);
- writer.write("--");
- out.write(writer.getBuffer().toString().getBytes(encoding));
- out.flush();
- }
-
- private int encodeBase64(InputStream input, OutputStream output, int bufferSize) throws IOException {
- int avail = input.available();
- if (avail > 262143) {
- //must be divisible by 3
- avail = 262143;
- }
- if (avail > bufferSize) {
- bufferSize = avail;
- }
- final byte[] buffer = new byte[bufferSize];
- int n = input.read(buffer);
- int total = 0;
- while (-1 != n) {
- if (n == 0) {
- throw new IOException("0 bytes read in violation of InputStream.read(byte[])");
- }
- //make sure n is divisible by 3
- int left = n % 3;
- n -= left;
- if (n > 0) {
- Base64Utility.encodeAndStream(buffer, 0, n, output);
- total += n;
- }
- if (left != 0) {
- for (int x = 0; x < left; ++x) {
- buffer[x] = buffer[n + x];
- }
- n = input.read(buffer, left, buffer.length - left);
- if (n == -1) {
- // we've hit the end, but still have stuff left, write it out
- Base64Utility.encodeAndStream(buffer, 0, left, output);
- total += left;
- }
- } else {
- n = input.read(buffer);
- }
- }
- return total;
- }
-
- public boolean isXop() {
- return xop;
- }
-
- public void setXop(boolean xop) {
- this.xop = xop;
- }
-
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/attachment/AttachmentUtil.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/attachment/AttachmentUtil.java
deleted file mode 100644
index 7c72f00..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/attachment/AttachmentUtil.java
+++ /dev/null
@@ -1,572 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.cxf.attachment;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.UnsupportedEncodingException;
-import java.net.MalformedURLException;
-import java.net.URI;
-import java.net.URL;
-import java.net.URLDecoder;
-import java.net.URLEncoder;
-import java.nio.charset.StandardCharsets;
-import java.util.AbstractMap;
-import java.util.AbstractSet;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Random;
-import java.util.Set;
-import java.util.UUID;
-import java.util.concurrent.atomic.AtomicInteger;
-import java.util.logging.Logger;
-
-import javax.activation.CommandInfo;
-import javax.activation.CommandMap;
-import javax.activation.DataContentHandler;
-import javax.activation.DataHandler;
-import javax.activation.DataSource;
-import javax.activation.FileDataSource;
-import javax.activation.MailcapCommandMap;
-import javax.activation.URLDataSource;
-
-import org.apache.cxf.common.logging.LogUtils;
-import org.apache.cxf.common.util.StringUtils;
-import org.apache.cxf.helpers.FileUtils;
-import org.apache.cxf.interceptor.Fault;
-import org.apache.cxf.io.CachedOutputStream;
-import org.apache.cxf.message.Attachment;
-import org.apache.cxf.message.Message;
-import org.apache.cxf.message.MessageUtils;
-
-public final class AttachmentUtil {
- public static final String BODY_ATTACHMENT_ID = "root.message@cxf.apache.org";
-
- static final String BINARY = "binary";
-
- private static final Logger LOG = LogUtils.getL7dLogger(AttachmentUtil.class);
-
- private static final AtomicInteger COUNTER = new AtomicInteger();
- private static final String ATT_UUID = UUID.randomUUID().toString();
-
- private static final Random BOUND_RANDOM = new Random();
- private static final CommandMap DEFAULT_COMMAND_MAP = CommandMap.getDefaultCommandMap();
- private static final MailcapCommandMap COMMAND_MAP = new EnhancedMailcapCommandMap();
-
-
- static final class EnhancedMailcapCommandMap extends MailcapCommandMap {
- @Override
- public synchronized DataContentHandler createDataContentHandler(
- String mimeType) {
- DataContentHandler dch = super.createDataContentHandler(mimeType);
- if (dch == null) {
- dch = DEFAULT_COMMAND_MAP.createDataContentHandler(mimeType);
- }
- return dch;
- }
-
- @Override
- public DataContentHandler createDataContentHandler(String mimeType,
- DataSource ds) {
- DataContentHandler dch = super.createDataContentHandler(mimeType);
- if (dch == null) {
- dch = DEFAULT_COMMAND_MAP.createDataContentHandler(mimeType, ds);
- }
- return dch;
- }
-
- @Override
- public synchronized CommandInfo[] getAllCommands(String mimeType) {
- CommandInfo[] commands = super.getAllCommands(mimeType);
- CommandInfo[] defaultCommands = DEFAULT_COMMAND_MAP.getAllCommands(mimeType);
- List<CommandInfo> cmdList = new ArrayList<>(Arrays.asList(commands));
-
- // Add CommandInfo which does not exist in current command map.
- for (CommandInfo defCmdInfo : defaultCommands) {
- String defCmdName = defCmdInfo.getCommandName();
- boolean cmdNameExist = false;
- for (CommandInfo cmdInfo : commands) {
- if (cmdInfo.getCommandName().equals(defCmdName)) {
- cmdNameExist = true;
- break;
- }
- }
- if (!cmdNameExist) {
- cmdList.add(defCmdInfo);
- }
- }
-
- CommandInfo[] allCommandArray = new CommandInfo[0];
- return cmdList.toArray(allCommandArray);
- }
-
- @Override
- public synchronized CommandInfo getCommand(String mimeType, String cmdName) {
- CommandInfo cmdInfo = super.getCommand(mimeType, cmdName);
- if (cmdInfo == null) {
- cmdInfo = DEFAULT_COMMAND_MAP.getCommand(mimeType, cmdName);
- }
- return cmdInfo;
- }
-
- /**
- * Merge current mime types and default mime types.
- */
- @Override
- public synchronized String[] getMimeTypes() {
- String[] mimeTypes = super.getMimeTypes();
- String[] defMimeTypes = DEFAULT_COMMAND_MAP.getMimeTypes();
- Set<String> mimeTypeSet = new HashSet<>();
- Collections.addAll(mimeTypeSet, mimeTypes);
- Collections.addAll(mimeTypeSet, defMimeTypes);
- String[] mimeArray = new String[0];
- return mimeTypeSet.toArray(mimeArray);
- }
- }
-
-
- private AttachmentUtil() {
-
- }
-
- static {
- COMMAND_MAP.addMailcap("image/*;;x-java-content-handler="
- + ImageDataContentHandler.class.getName());
- }
-
- public static CommandMap getCommandMap() {
- return COMMAND_MAP;
- }
-
- public static boolean isMtomEnabled(Message message) {
- return MessageUtils.getContextualBoolean(message, Message.MTOM_ENABLED, false);
- }
-
- public static void setStreamedAttachmentProperties(Message message, CachedOutputStream bos)
- throws IOException {
- Object directory = message.getContextualProperty(AttachmentDeserializer.ATTACHMENT_DIRECTORY);
- if (directory != null) {
- if (directory instanceof File) {
- bos.setOutputDir((File) directory);
- } else if (directory instanceof String) {
- bos.setOutputDir(new File((String) directory));
- } else {
- throw new IOException("The value set as " + AttachmentDeserializer.ATTACHMENT_DIRECTORY
- + " should be either an instance of File or String");
- }
- }
-
- Object threshold = message.getContextualProperty(AttachmentDeserializer.ATTACHMENT_MEMORY_THRESHOLD);
- if (threshold != null) {
- if (threshold instanceof Number) {
- long t = ((Number) threshold).longValue();
- if (t >= 0) {
- bos.setThreshold(t);
- } else {
- LOG.warning("Threshold value overflowed long. Setting default value!");
- bos.setThreshold(AttachmentDeserializer.THRESHOLD);
- }
- } else if (threshold instanceof String) {
- try {
- bos.setThreshold(Long.parseLong((String) threshold));
- } catch (NumberFormatException e) {
- throw new IOException("Provided threshold String is not a number", e);
- }
- } else {
- throw new IOException("The value set as " + AttachmentDeserializer.ATTACHMENT_MEMORY_THRESHOLD
- + " should be either an instance of Number or String");
- }
- } else if (!CachedOutputStream.isThresholdSysPropSet()) {
- // Use the default AttachmentDeserializer Threshold only if there is no system property defined
- bos.setThreshold(AttachmentDeserializer.THRESHOLD);
- }
-
- Object maxSize = message.getContextualProperty(AttachmentDeserializer.ATTACHMENT_MAX_SIZE);
- if (maxSize != null) {
- if (maxSize instanceof Number) {
- long size = ((Number) maxSize).longValue();
- if (size >= 0) {
- bos.setMaxSize(size);
- } else {
- LOG.warning("Max size value overflowed long. Do not set max size!");
- }
- } else if (maxSize instanceof String) {
- try {
- bos.setMaxSize(Long.parseLong((String) maxSize));
- } catch (NumberFormatException e) {
- throw new IOException("Provided threshold String is not a number", e);
- }
- } else {
- throw new IOException("The value set as " + AttachmentDeserializer.ATTACHMENT_MAX_SIZE
- + " should be either an instance of Number or String");
- }
- }
- }
-
- public static String createContentID(String ns) throws UnsupportedEncodingException {
- // tend to change
- String cid = "cxf.apache.org";
- if (ns != null && !ns.isEmpty()) {
- try {
- URI uri = new URI(ns);
- String host = uri.getHost();
- if (host != null) {
- cid = host;
- } else {
- cid = ns;
- }
- } catch (Exception e) {
- cid = ns;
- }
- }
- return ATT_UUID + '-' + Integer.toString(COUNTER.incrementAndGet()) + '@'
- + URLEncoder.encode(cid, StandardCharsets.UTF_8.name());
- }
-
- public static String getUniqueBoundaryValue() {
- //generate a random UUID.
- //we don't need the cryptographically secure random uuid that
- //UUID.randomUUID() will produce. Thus, use a faster
- //pseudo-random thing
- long leastSigBits;
- long mostSigBits;
- synchronized (BOUND_RANDOM) {
- mostSigBits = BOUND_RANDOM.nextLong();
- leastSigBits = BOUND_RANDOM.nextLong();
- }
-
- mostSigBits &= 0xFFFFFFFFFFFF0FFFL; //clear version
- mostSigBits |= 0x0000000000004000L; //set version
-
- leastSigBits &= 0x3FFFFFFFFFFFFFFFL; //clear the variant
- leastSigBits |= 0x8000000000000000L; //set to IETF variant
-
- UUID result = new UUID(mostSigBits, leastSigBits);
-
- return "uuid:" + result.toString();
- }
-
- public static Map<String, DataHandler> getDHMap(final Collection<Attachment> attachments) {
- Map<String, DataHandler> dataHandlers = null;
- if (attachments != null) {
- if (attachments instanceof LazyAttachmentCollection) {
- dataHandlers = ((LazyAttachmentCollection)attachments).createDataHandlerMap();
- } else {
- dataHandlers = new DHMap(attachments);
- }
- }
- return dataHandlers == null ? new LinkedHashMap<>() : dataHandlers;
- }
-
- static class DHMap extends AbstractMap<String, DataHandler> {
- final Collection<Attachment> list;
- DHMap(Collection<Attachment> l) {
- list = l;
- }
- public Set<Map.Entry<String, DataHandler>> entrySet() {
- return new AbstractSet<Map.Entry<String, DataHandler>>() {
- @Override
- public Iterator<Map.Entry<String, DataHandler>> iterator() {
- final Iterator<Attachment> it = list.iterator();
- return new Iterator<Map.Entry<String, DataHandler>>() {
- public boolean hasNext() {
- return it.hasNext();
- }
- public Map.Entry<String, DataHandler> next() {
- final Attachment a = it.next();
- return new Map.Entry<String, DataHandler>() {
- @Override
- public String getKey() {
- return a.getId();
- }
-
- @Override
- public DataHandler getValue() {
- return a.getDataHandler();
- }
-
- @Override
- public DataHandler setValue(DataHandler value) {
- return null;
- }
- };
- }
- @Override
- public void remove() {
- it.remove();
- }
- };
- }
-
- @Override
- public int size() {
- return list.size();
- }
- };
- }
-
- @Override
- public DataHandler put(String key, DataHandler value) {
- Iterator<Attachment> i = list.iterator();
- DataHandler ret = null;
- while (i.hasNext()) {
- Attachment a = i.next();
- if (a.getId().equals(key)) {
- i.remove();
- ret = a.getDataHandler();
- break;
- }
- }
- list.add(new AttachmentImpl(key, value));
- return ret;
- }
- }
-
- public static String cleanContentId(String id) {
- if (id != null) {
- if (id.startsWith("<")) {
- // strip <>
- id = id.substring(1, id.length() - 1);
- }
- // strip cid:
- if (id.startsWith("cid:")) {
- id = id.substring(4);
- }
- // urldecode. Is this bad even without cid:? What does decode do with malformed %-signs, anyhow?
- try {
- id = URLDecoder.decode(id, StandardCharsets.UTF_8.name());
- } catch (UnsupportedEncodingException e) {
- //ignore, keep id as is
- }
- }
- if (id == null) {
- //no Content-ID, set cxf default ID
- id = BODY_ATTACHMENT_ID;
- }
- return id;
- }
-
- static String getHeaderValue(List<String> v) {
- if (v != null && !v.isEmpty()) {
- return v.get(0);
- }
- return null;
- }
- static String getHeaderValue(List<String> v, String delim) {
- if (v != null && !v.isEmpty()) {
- return String.join(delim, v);
- }
- return null;
- }
- static String getHeader(Map<String, List<String>> headers, String h) {
- return getHeaderValue(headers.get(h));
- }
- static String getHeader(Map<String, List<String>> headers, String h, String delim) {
- return getHeaderValue(headers.get(h), delim);
- }
- public static Attachment createAttachment(InputStream stream, Map<String, List<String>> headers)
- throws IOException {
-
- String id = cleanContentId(getHeader(headers, "Content-ID"));
-
- AttachmentImpl att = new AttachmentImpl(id);
-
- final String ct = getHeader(headers, "Content-Type");
- String cd = getHeader(headers, "Content-Disposition");
- String fileName = getContentDispositionFileName(cd);
-
- String encoding = null;
-
- for (Map.Entry<String, List<String>> e : headers.entrySet()) {
- String name = e.getKey();
- if ("Content-Transfer-Encoding".equalsIgnoreCase(name)) {
- encoding = getHeader(headers, name);
- if (BINARY.equalsIgnoreCase(encoding)) {
- att.setXOP(true);
- }
- }
- att.setHeader(name, getHeaderValue(e.getValue()));
- }
- if (encoding == null) {
- encoding = BINARY;
- }
- InputStream ins = decode(stream, encoding);
- if (ins != stream) {
- headers.remove("Content-Transfer-Encoding");
- }
- DataSource source = new AttachmentDataSource(ct, ins);
- if (!StringUtils.isEmpty(fileName)) {
- ((AttachmentDataSource)source).setName(FileUtils.stripPath(fileName));
- }
- att.setDataHandler(new DataHandler(source));
- return att;
- }
-
- static String getContentDispositionFileName(String cd) {
- if (StringUtils.isEmpty(cd)) {
- return null;
- }
- ContentDisposition c = new ContentDisposition(cd);
- String s = c.getParameter("filename");
- if (s == null) {
- s = c.getParameter("name");
- }
- return s;
- }
-
- public static InputStream decode(InputStream in, String encoding) throws IOException {
- if (encoding == null) {
- return in;
- }
- encoding = encoding.toLowerCase();
-
- // some encodings are just pass-throughs, with no real decoding.
- if (BINARY.equals(encoding)
- || "7bit".equals(encoding)
- || "8bit".equals(encoding)) {
- return in;
- } else if ("base64".equals(encoding)) {
- return new Base64DecoderStream(in);
- } else if ("quoted-printable".equals(encoding)) {
- return new QuotedPrintableDecoderStream(in);
- } else {
- throw new IOException("Unknown encoding " + encoding);
- }
- }
- public static boolean isTypeSupported(String contentType, List<String> types) {
- if (contentType == null) {
- return false;
- }
- contentType = contentType.toLowerCase();
- for (String s : types) {
- if (contentType.indexOf(s) != -1) {
- return true;
- }
- }
- return false;
- }
-
- public static Attachment createMtomAttachment(boolean isXop, String mimeType, String elementNS,
- byte[] data, int offset, int length, int threshold) {
- if (!isXop || length <= threshold) {
- return null;
- }
- if (mimeType == null) {
- mimeType = "application/octet-stream";
- }
-
- ByteDataSource source = new ByteDataSource(data, offset, length);
- source.setContentType(mimeType);
- DataHandler handler = new DataHandler(source);
-
- String id;
- try {
- id = AttachmentUtil.createContentID(elementNS);
- } catch (UnsupportedEncodingException e) {
- throw new Fault(e);
- }
- AttachmentImpl att = new AttachmentImpl(id, handler);
- att.setXOP(isXop);
- return att;
- }
-
- public static Attachment createMtomAttachmentFromDH(
- boolean isXop, DataHandler handler, String elementNS, int threshold) {
- if (!isXop) {
- return null;
- }
-
- // The following is just wrong. Even if the DataHandler has a stream, we should still
- // apply the threshold.
- try {
- DataSource ds = handler.getDataSource();
- if (ds instanceof FileDataSource) {
- FileDataSource fds = (FileDataSource)ds;
- File file = fds.getFile();
- if (file.length() < threshold) {
- return null;
- }
- } else if (ds.getClass().getName().endsWith("ObjectDataSource")) {
- Object o = handler.getContent();
- if (o instanceof String
- && ((String)o).length() < threshold) {
- return null;
- } else if (o instanceof byte[] && ((byte[])o).length < threshold) {
- return null;
- }
- }
- } catch (IOException e1) {
- // ignore, just do the normal attachment thing
- }
-
- String id;
- try {
- id = AttachmentUtil.createContentID(elementNS);
- } catch (UnsupportedEncodingException e) {
- throw new Fault(e);
- }
- AttachmentImpl att = new AttachmentImpl(id, handler);
- if (!StringUtils.isEmpty(handler.getName())) {
- //set Content-Disposition attachment header if filename isn't null
- String file = handler.getName();
- File f = new File(file);
- if (f.exists() && f.isFile()) {
- file = f.getName();
- }
- att.setHeader("Content-Disposition", "attachment;name=\"" + file + "\"");
- }
- att.setXOP(isXop);
- return att;
- }
-
- public static DataSource getAttachmentDataSource(String contentId, Collection<Attachment> atts) {
- // Is this right? - DD
- if (contentId.startsWith("cid:")) {
- try {
- contentId = URLDecoder.decode(contentId.substring(4), StandardCharsets.UTF_8.name());
- } catch (UnsupportedEncodingException ue) {
- contentId = contentId.substring(4);
- }
- return loadDataSource(contentId, atts);
- } else if (contentId.indexOf("://") == -1) {
- return loadDataSource(contentId, atts);
- } else {
- try {
- return new URLDataSource(new URL(contentId));
- } catch (MalformedURLException e) {
- throw new Fault(e);
- }
- }
-
- }
-
- private static DataSource loadDataSource(String contentId, Collection<Attachment> atts) {
- return new LazyDataSource(contentId, atts);
- }
-
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/attachment/Base64DecoderStream.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/attachment/Base64DecoderStream.java
deleted file mode 100644
index 134553f..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/attachment/Base64DecoderStream.java
+++ /dev/null
@@ -1,196 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.cxf.attachment;
-
-import java.io.FilterInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-
-import org.apache.cxf.common.util.Base64Exception;
-import org.apache.cxf.common.util.Base64Utility;
-
-/**
- * An implementation of a FilterInputStream that decodes the
- * stream data in BASE64 encoding format. This version does the
- * decoding "on the fly" rather than decoding a single block of
- * data. Since this version is intended for use by the MimeUtilty class,
- * it also handles line breaks in the encoded data.
- */
-public class Base64DecoderStream extends FilterInputStream {
-
- static final String MAIL_BASE64_IGNOREERRORS = "mail.mime.base64.ignoreerrors";
-
- // number of decodeable units we'll try to process at one time. We'll attempt to read that much
- // data from the input stream and decode in blocks.
- static final int BUFFERED_UNITS = 2000;
-
- // can be overridden by a system property.
- protected boolean ignoreErrors;
-
- // buffer for reading in chars for decoding (which can support larger bulk reads)
- protected char[] encodedChars = new char[BUFFERED_UNITS * 4];
- // a buffer for one decoding unit's worth of data (3 bytes).
- protected byte[] decodedChars;
- // count of characters in the buffer
- protected int decodedCount;
- // index of the next decoded character
- protected int decodedIndex;
-
-
- public Base64DecoderStream(InputStream in) {
- super(in);
- }
-
- /**
- * Test for the existance of decoded characters in our buffer
- * of decoded data.
- *
- * @return True if we currently have buffered characters.
- */
- private boolean dataAvailable() {
- return decodedCount != 0;
- }
-
- /**
- * Decode a requested number of bytes of data into a buffer.
- *
- * @return true if we were able to obtain more data, false otherwise.
- */
- private boolean decodeStreamData() throws IOException {
- decodedIndex = 0;
-
- // fill up a data buffer with input data
- int readCharacters = fillEncodedBuffer();
-
- if (readCharacters > 0) {
- try {
- decodedChars = Base64Utility.decodeChunk(encodedChars, 0, readCharacters);
- } catch (Base64Exception e) {
- throw new IOException(e);
- }
- decodedCount = decodedChars.length;
- return true;
- }
- return false;
- }
-
-
- /**
- * Retrieve a single byte from the decoded characters buffer.
- *
- * @return The decoded character or -1 if there was an EOF condition.
- */
- private int getByte() throws IOException {
- if (!dataAvailable() && !decodeStreamData()) {
- return -1;
- }
- decodedCount--;
- // we need to ensure this doesn't get sign extended
- return decodedChars[decodedIndex++] & 0xff;
- }
-
- private int getBytes(byte[] data, int offset, int length) throws IOException {
-
- int readCharacters = 0;
- while (length > 0) {
- // need data? Try to get some
- if (!dataAvailable() && !decodeStreamData()) {
- // if we can't get this, return a count of how much we did get (which may be -1).
- return readCharacters > 0 ? readCharacters : -1;
- }
-
- // now copy some of the data from the decoded buffer to the target buffer
- int copyCount = Math.min(decodedCount, length);
- System.arraycopy(decodedChars, decodedIndex, data, offset, copyCount);
- decodedIndex += copyCount;
- decodedCount -= copyCount;
- offset += copyCount;
- length -= copyCount;
- readCharacters += copyCount;
- }
- return readCharacters;
- }
-
-
- /**
- * Fill our buffer of input characters for decoding from the
- * stream. This will attempt read a full buffer, but will
- * terminate on an EOF or read error. This will filter out
- * non-Base64 encoding chars and will only return a valid
- * multiple of 4 number of bytes.
- *
- * @return The count of characters read.
- */
- private int fillEncodedBuffer() throws IOException {
- int readCharacters = 0;
-
- while (true) {
- // get the next character from the stream
- int ch = in.read();
- // did we hit an EOF condition?
- if (ch == -1) {
- // now check to see if this is normal, or potentially an error
- // if we didn't get characters as a multiple of 4, we may need to complain about this.
- if ((readCharacters % 4) != 0) {
- throw new IOException("Base64 encoding error, data truncated: " + readCharacters + " "
- + new String(encodedChars, 0, readCharacters));
- }
- // return the count.
- return readCharacters;
- } else if (Base64Utility.isValidBase64(ch)) {
- // if this character is valid in a Base64 stream, copy it to the buffer.
- encodedChars[readCharacters++] = (char)ch;
- // if we've filled up the buffer, time to quit.
- if (readCharacters >= encodedChars.length) {
- return readCharacters;
- }
- }
-
- // we're filtering out whitespace and CRLF characters, so just ignore these
- }
- }
-
-
- // in order to function as a filter, these streams need to override the different
- // read() signature.
-
- @Override
- public int read() throws IOException {
- return getByte();
- }
-
-
- @Override
- public int read(byte [] buffer, int offset, int length) throws IOException {
- return getBytes(buffer, offset, length);
- }
-
-
- @Override
- public boolean markSupported() {
- return false;
- }
-
-
- @Override
- public int available() throws IOException {
- return ((in.available() / 4) * 3) + decodedCount;
- }
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/attachment/ContentDisposition.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/attachment/ContentDisposition.java
deleted file mode 100644
index f9d4524..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/attachment/ContentDisposition.java
+++ /dev/null
@@ -1,144 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.cxf.attachment;
-
-import java.io.UnsupportedEncodingException;
-import java.util.Collections;
-import java.util.LinkedHashMap;
-import java.util.Map;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-public class ContentDisposition {
- private static final String CD_HEADER_PARAMS_EXPRESSION =
- "[\\w-]++( )?\\*?=( )?((\"[^\"]++\")|([^;]+))";
- private static final Pattern CD_HEADER_PARAMS_PATTERN =
- Pattern.compile(CD_HEADER_PARAMS_EXPRESSION);
-
- private static final String CD_HEADER_EXT_PARAMS_EXPRESSION =
- "(?i)(UTF-8|ISO-8859-1)''((?:%[0-9a-f]{2}|\\S)+)";
- private static final Pattern CD_HEADER_EXT_PARAMS_PATTERN =
- Pattern.compile(CD_HEADER_EXT_PARAMS_EXPRESSION);
- private static final Pattern CODEPOINT_ENCODED_VALUE_PATTERN = Pattern.compile("&#[0-9]{4};|\\S");
-
- private static final String FILE_NAME = "filename";
-
- private String value;
- private String type;
- private Map<String, String> params = new LinkedHashMap<>();
-
- public ContentDisposition(String value) {
- this.value = value;
-
- String tempValue = value;
-
- int index = tempValue.indexOf(';');
- if (index > 0 && (tempValue.indexOf('=') >= index)) {
- type = tempValue.substring(0, index).trim();
- tempValue = tempValue.substring(index + 1);
- }
-
- String extendedFilename = null;
- Matcher m = CD_HEADER_PARAMS_PATTERN.matcher(tempValue);
- while (m.find()) {
- final String paramName;
- String paramValue = "";
-
- String groupValue = m.group().trim();
- int eqIndex = groupValue.indexOf('=');
- if (eqIndex > 0) {
- paramName = groupValue.substring(0, eqIndex).trim();
- if (eqIndex + 1 != groupValue.length()) {
- paramValue = groupValue.substring(eqIndex + 1).trim().replace("\"", "");
- }
- } else {
- paramName = groupValue;
- }
- // filename* looks like the only CD param that is human readable
- // and worthy of the extended encoding support. Other parameters
- // can be supported if needed, see the complete list below
- /*
- http://www.iana.org/assignments/cont-disp/cont-disp.xhtml#cont-disp-2
-
- filename name to be used when creating file [RFC2183]
- creation-date date when content was created [RFC2183]
- modification-date date when content was last modified [RFC2183]
- read-date date when content was last read [RFC2183]
- size approximate size of content in octets [RFC2183]
- name original field name in form [RFC2388]
- voice type or use of audio content [RFC2421]
- handling whether or not processing is required [RFC3204]
- */
- if ("filename*".equalsIgnoreCase(paramName)) {
- // try to decode the value if it matches the spec
- try {
- Matcher matcher = CD_HEADER_EXT_PARAMS_PATTERN.matcher(paramValue);
- if (matcher.matches()) {
- String encodingScheme = matcher.group(1);
- String encodedValue = matcher.group(2);
- paramValue = Rfc5987Util.decode(encodedValue, encodingScheme);
- extendedFilename = paramValue;
- }
- } catch (UnsupportedEncodingException e) {
- // would be odd not to support UTF-8 or 8859-1
- }
- } else if (FILE_NAME.equalsIgnoreCase(paramName) && paramValue.contains("&#")) {
- Matcher matcher = CODEPOINT_ENCODED_VALUE_PATTERN.matcher(paramValue);
- StringBuilder sb = new StringBuilder();
- while (matcher.find()) {
- String matched = matcher.group();
- if (matched.startsWith("&#")) {
- int codePoint = Integer.parseInt(matched.substring(2, 6));
- sb.append(Character.toChars(codePoint));
- } else {
- sb.append(matched.charAt(0));
- }
- }
- if (sb.length() > 0) {
- paramValue = sb.toString();
- }
- }
- params.put(paramName.toLowerCase(), paramValue);
- }
- if (extendedFilename != null) {
- params.put(FILE_NAME, extendedFilename);
- }
- }
-
- public String getType() {
- return type;
- }
-
- public String getFilename() {
- return params.get(FILE_NAME);
- }
-
- public String getParameter(String name) {
- return params.get(name);
- }
-
- public Map<String, String> getParameters() {
- return Collections.unmodifiableMap(params);
- }
-
- public String toString() {
- return value;
- }
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/attachment/LazyAttachmentCollection.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/attachment/LazyAttachmentCollection.java
deleted file mode 100644
index 8dd4ace..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/attachment/LazyAttachmentCollection.java
+++ /dev/null
@@ -1,362 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.cxf.attachment;
-
-import java.io.IOException;
-import java.util.AbstractCollection;
-import java.util.AbstractSet;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import javax.activation.DataHandler;
-
-import org.apache.cxf.message.Attachment;
-
-public class LazyAttachmentCollection
- implements Collection<Attachment> {
-
- private AttachmentDeserializer deserializer;
- private final List<Attachment> attachments = new ArrayList<>();
- private final int maxAttachmentCount;
-
- public LazyAttachmentCollection(AttachmentDeserializer deserializer, int maxAttachmentCount) {
- super();
- this.deserializer = deserializer;
- this.maxAttachmentCount = maxAttachmentCount;
- }
-
- public List<Attachment> getLoadedAttachments() {
- return attachments;
- }
-
- private void loadAll() {
- try {
- Attachment a = deserializer.readNext();
- int count = 0;
- while (a != null) {
- attachments.add(a);
- count++;
- if (count > maxAttachmentCount) {
- throw new IOException("The message contains more attachments than are permitted");
- }
- a = deserializer.readNext();
- }
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- }
- /**
- * Check for more attachments by attempting to deserialize the next attachment.
- *
- * @param shouldLoadNew if <i>false</i>, the "loaded attachments" List will not be changed.
- * @return there is more attachment or not
- * @throws IOException
- */
- public boolean hasNext(boolean shouldLoadNew) throws IOException {
- if (shouldLoadNew) {
- Attachment a = deserializer.readNext();
- if (a != null) {
- attachments.add(a);
- return true;
- }
- return false;
- }
- return deserializer.hasNext();
- }
-
- public boolean hasNext() throws IOException {
- return hasNext(true);
- }
- public Iterator<Attachment> iterator() {
- return new Iterator<Attachment>() {
- int current;
- boolean removed;
-
- public boolean hasNext() {
- if (attachments.size() > current) {
- return true;
- }
-
- // check if there is another attachment
- try {
- Attachment a = deserializer.readNext();
- if (a == null) {
- return false;
- }
- attachments.add(a);
- return true;
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- }
-
- @Override
- public Attachment next() {
- Attachment a = attachments.get(current);
- current++;
- removed = false;
- return a;
- }
-
- @Override
- public void remove() {
- if (removed) {
- throw new IllegalStateException();
- }
- attachments.remove(--current);
- removed = true;
- }
-
- };
- }
-
- public int size() {
- loadAll();
-
- return attachments.size();
- }
-
- public boolean add(Attachment arg0) {
- return attachments.add(arg0);
- }
-
- public boolean addAll(Collection<? extends Attachment> arg0) {
- return attachments.addAll(arg0);
- }
-
- public void clear() {
- attachments.clear();
- }
-
- public boolean contains(Object arg0) {
- return attachments.contains(arg0);
- }
-
- public boolean containsAll(Collection<?> arg0) {
- return attachments.containsAll(arg0);
- }
-
- public boolean isEmpty() {
- if (attachments.isEmpty()) {
- return !iterator().hasNext();
- }
- return attachments.isEmpty();
- }
-
- public boolean remove(Object arg0) {
- return attachments.remove(arg0);
- }
-
- public boolean removeAll(Collection<?> arg0) {
- return attachments.removeAll(arg0);
- }
-
- public boolean retainAll(Collection<?> arg0) {
- return attachments.retainAll(arg0);
- }
-
- public Object[] toArray() {
- loadAll();
-
- return attachments.toArray();
- }
-
- public <T> T[] toArray(T[] arg0) {
- loadAll();
-
- return attachments.toArray(arg0);
- }
-
- public Map<String, DataHandler> createDataHandlerMap() {
- return new LazyAttachmentMap(this);
- }
-
- private static class LazyAttachmentMap implements Map<String, DataHandler> {
- LazyAttachmentCollection collection;
-
- LazyAttachmentMap(LazyAttachmentCollection c) {
- collection = c;
- }
-
- public void clear() {
- collection.clear();
- }
-
- public boolean containsKey(Object key) {
- Iterator<Attachment> it = collection.iterator();
- while (it.hasNext()) {
- Attachment at = it.next();
- if (key.equals(at.getId())) {
- return true;
- }
- }
- return false;
- }
-
- public boolean containsValue(Object value) {
- Iterator<Attachment> it = collection.iterator();
- while (it.hasNext()) {
- Attachment at = it.next();
- if (value.equals(at.getDataHandler())) {
- return true;
- }
- }
- return false;
- }
-
- public DataHandler get(Object key) {
- Iterator<Attachment> it = collection.iterator();
- while (it.hasNext()) {
- Attachment at = it.next();
- if (key.equals(at.getId())) {
- return at.getDataHandler();
- }
- }
- return null;
- }
-
- public boolean isEmpty() {
- return collection.isEmpty();
- }
- public int size() {
- return collection.size();
- }
-
- public DataHandler remove(Object key) {
- Iterator<Attachment> it = collection.iterator();
- while (it.hasNext()) {
- Attachment at = it.next();
- if (key.equals(at.getId())) {
- collection.remove(at);
- return at.getDataHandler();
- }
- }
- return null;
- }
- public DataHandler put(String key, DataHandler value) {
- Attachment at = new AttachmentImpl(key, value);
- collection.add(at);
- return value;
- }
-
- public void putAll(Map<? extends String, ? extends DataHandler> t) {
- for (Map.Entry<? extends String, ? extends DataHandler> ent : t.entrySet()) {
- put(ent.getKey(), ent.getValue());
- }
- }
-
-
- public Set<Map.Entry<String, DataHandler>> entrySet() {
- return new AbstractSet<Map.Entry<String, DataHandler>>() {
- public Iterator<Map.Entry<String, DataHandler>> iterator() {
- return new Iterator<Map.Entry<String, DataHandler>>() {
- Iterator<Attachment> it = collection.iterator();
- public boolean hasNext() {
- return it.hasNext();
- }
- public Map.Entry<String, DataHandler> next() {
- return new Map.Entry<String, DataHandler>() {
- Attachment at = it.next();
- public String getKey() {
- return at.getId();
- }
- public DataHandler getValue() {
- return at.getDataHandler();
- }
- public DataHandler setValue(DataHandler value) {
- if (at instanceof AttachmentImpl) {
- DataHandler h = at.getDataHandler();
- ((AttachmentImpl)at).setDataHandler(value);
- return h;
- }
- throw new UnsupportedOperationException();
- }
- };
- }
- @Override
- public void remove() {
- it.remove();
- }
- };
- }
- public int size() {
- return collection.size();
- }
- };
- }
-
- public Set<String> keySet() {
- return new AbstractSet<String>() {
- public Iterator<String> iterator() {
- return new Iterator<String>() {
- Iterator<Attachment> it = collection.iterator();
- public boolean hasNext() {
- return it.hasNext();
- }
-
- public String next() {
- return it.next().getId();
- }
-
- @Override
- public void remove() {
- it.remove();
- }
- };
- }
-
- public int size() {
- return collection.size();
- }
- };
- }
-
-
- public Collection<DataHandler> values() {
- return new AbstractCollection<DataHandler>() {
- public Iterator<DataHandler> iterator() {
- return new Iterator<DataHandler>() {
- Iterator<Attachment> it = collection.iterator();
- public boolean hasNext() {
- return it.hasNext();
- }
- public DataHandler next() {
- return it.next().getDataHandler();
- }
- @Override
- public void remove() {
- it.remove();
- }
- };
- }
-
- public int size() {
- return collection.size();
- }
- };
- }
-
- }
-
-
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/attachment/MimeBodyPartInputStream.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/attachment/MimeBodyPartInputStream.java
deleted file mode 100644
index ab80b89..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/attachment/MimeBodyPartInputStream.java
+++ /dev/null
@@ -1,275 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.cxf.attachment;
-
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.PushbackInputStream;
-
-public class MimeBodyPartInputStream extends InputStream {
-
- PushbackInputStream inStream;
-
- boolean boundaryFound;
- int pbAmount;
- byte[] boundary;
- byte[] boundaryBuffer;
-
- private boolean closed;
-
- public MimeBodyPartInputStream(PushbackInputStream inStreamParam,
- byte[] boundaryParam,
- int pbsize) {
- super();
- this.inStream = inStreamParam;
- this.boundary = boundaryParam;
- this.pbAmount = pbsize;
- }
-
- @Override
- public int read(byte[] buf, int origOff, int origLen) throws IOException {
- byte[] b = buf;
- int off = origOff;
- int len = origLen;
- if (boundaryFound || closed) {
- return -1;
- }
- if ((off < 0) || (off > b.length) || (len < 0)
- || ((off + len) > b.length) || ((off + len) < 0)) {
-
- throw new IndexOutOfBoundsException();
- }
- if (len == 0) {
- return 0;
- }
- boolean bufferCreated = false;
- if (len < boundary.length * 2) {
- //buffer is too short to detect boundaries with it. We'll need to create a larger buffer
- bufferCreated = true;
- if (boundaryBuffer == null) {
- boundaryBuffer = new byte[boundary.length * 2];
- }
- b = boundaryBuffer;
- off = 0;
- len = boundaryBuffer.length;
- }
- if (len > pbAmount) {
- len = pbAmount; //can only pushback that much so make sure we can
- }
- int read = 0;
- int idx = 0;
- while (read >= 0 && idx < len && idx < (boundary.length * 2)) {
- //make sure we read enough to detect the boundary
- read = inStream.read(b, off + idx, len - idx);
- if (read != -1) {
- idx += read;
- }
- }
- if (read == -1 && idx == 0) {
- return -1;
- }
- len = idx;
-
- int i = processBuffer(b, off, len);
- if (bufferCreated && i > 0) {
- // read more than we need, push it back
- if (origLen >= i) {
- System.arraycopy(b, 0, buf, origOff, i);
- } else {
- System.arraycopy(b, 0, buf, origOff, origLen);
- inStream.unread(b, origLen, i - origLen);
- i = origLen;
- }
- } else if (i == 0 && boundaryFound) {
- return -1;
- }
-
- return i;
- }
-
- //Has Data after encountering CRLF
- private boolean hasData(byte[] b, int initialPointer, int pointer, int off, int len)
- throws IOException {
- if (pointer < (off + len)) {
- return true;
- } else if (pointer >= 1000000000) {
- inStream.unread(b, initialPointer, (off + len) - initialPointer);
- return false;
- } else {
- int x = inStream.read();
- if (x != -1) {
- inStream.unread(x);
- inStream.unread(b, initialPointer, (off + len) - initialPointer);
- return false;
- }
- return true;
- }
- }
-
- protected int processBuffer(byte[] buffer, int off, int len) throws IOException {
- for (int i = off; i < (off + len); i++) {
- boolean needUnread0d0a = false;
- int value = buffer[i];
- int initialI = i;
- if (value == 13) {
- if (!hasData(buffer, initialI, initialI + 1, off, len)) {
- return initialI - off;
- }
- value = buffer[initialI + 1];
- if (value != 10) {
- continue;
- }
- if (!hasData(buffer, initialI, initialI + 2, off, len)) {
- return initialI - off;
- }
- value = buffer[initialI + 2];
- if ((byte) value != boundary[0]) {
- i++;
- continue;
- }
- needUnread0d0a = true;
- i += 2; //i after this points to boundary[0] element
- } else if (value != boundary[0]) {
- continue;
- }
-
- int boundaryIndex = 0;
- while ((boundaryIndex < boundary.length) && (value == boundary[boundaryIndex])) {
- if (!hasData(buffer, initialI, i + 1, off, len)) {
- return initialI - off;
- }
- value = buffer[++i];
- boundaryIndex++;
- }
- if (boundaryIndex == boundary.length) {
- // read the end of line character
- if (initialI != off) {
- i = 1000000000;
- }
- if (initialI - off != 0
- && !hasData(buffer, initialI, i + 1, off, len)) {
- return initialI - off;
- }
- boundaryFound = true;
- int j = i + 1;
- if (j < len && buffer[j] == 45 && value == 45) {
- // Last mime boundary should have a succeeding "--"
- // as we are on it, read the terminating CRLF
- i += 2;
- //last mime boundary
- }
-
- //boundary matched (may or may not be last mime boundary)
- int processed = initialI - off;
- if ((len - ((i - off) + 2)) > 0) {
- inStream.unread(buffer, i + 2, len - (i + 2) + off);
- }
- return processed;
- }
-
- // Boundary not found. Restoring bytes skipped.
- // write first skipped byte, push back the rest
- if (value != -1) { //pushing back first byte of boundary
- // Stream might have ended
- i--;
- }
- if (needUnread0d0a) { //Pushing all, returning 13
- i = i - boundaryIndex;
- i--; //for 10
-// value = 13;
- } else {
- i = i - boundaryIndex;
- i++;
-// value = boundary[0];
- }
- }
- return len;
- }
-
- public int read() throws IOException {
- boolean needUnread0d0a = false;
- if (boundaryFound) {
- return -1;
- }
-
- // read the next value from stream
- int value = inStream.read();
- // A problem occurred because all the mime parts tends to have a /r/n
- // at the end. Making it hard to transform them to correct
- // DataSources.
- // This logic introduced to handle it
- if (value == 13) {
- value = inStream.read();
- if (value != 10) {
- inStream.unread(value);
- return 13;
- }
- value = inStream.read();
- if ((byte) value != boundary[0]) {
- inStream.unread(value);
- inStream.unread(10);
- return 13;
- }
- needUnread0d0a = true;
- } else if ((byte) value != boundary[0]) {
- return value;
- }
- // read value is the first byte of the boundary. Start matching the
- // next characters to find a boundary
- int boundaryIndex = 0;
- while ((boundaryIndex < boundary.length) && ((byte) value == boundary[boundaryIndex])) {
- value = inStream.read();
- boundaryIndex++;
- }
- if (boundaryIndex == boundary.length) {
- // boundary found
- boundaryFound = true;
- int dashNext = inStream.read();
- // read the end of line character
- if (dashNext == 45 && value == 45) {
- // Last mime boundary should have a succeeding "--"
- // as we are on it, read the terminating CRLF
- inStream.read();
- inStream.read();
- }
- return -1;
- }
- // Boundary not found. Restoring bytes skipped.
- // write first skipped byte, push back the rest
- if (value != -1) {
- // Stream might have ended
- inStream.unread(value);
- }
- if (needUnread0d0a) {
- inStream.unread(boundary, 0, boundaryIndex);
- inStream.unread(10);
- value = 13;
- } else {
- inStream.unread(boundary, 1, boundaryIndex - 1);
- value = boundary[0];
- }
- return value;
- }
-
- @Override
- public void close() throws IOException {
- this.closed = true;
- }
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/bus/CXFBusFactory.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/bus/CXFBusFactory.java
deleted file mode 100644
index fb3a833..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/bus/CXFBusFactory.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.cxf.bus;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import org.apache.cxf.Bus;
-import org.apache.cxf.BusFactory;
-import org.apache.cxf.bus.extension.ExtensionManagerBus;
-
-public class CXFBusFactory extends BusFactory {
-
- public Bus createBus() {
- return createBus(new HashMap<>());
- }
-
- public Bus createBus(Map<Class<?>, Object> e) {
- return createBus(e, new HashMap<>());
- }
-
- public Bus createBus(Map<Class<?>, Object> e, Map<String, Object> properties) {
- ExtensionManagerBus bus = new ExtensionManagerBus(e, properties);
- possiblySetDefaultBus(bus);
- initializeBus(bus);
- bus.initialize();
- return bus;
- }
-
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/bus/blueprint/BundleDelegatingClassLoader.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/bus/blueprint/BundleDelegatingClassLoader.java
deleted file mode 100644
index ff957c2..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/bus/blueprint/BundleDelegatingClassLoader.java
+++ /dev/null
@@ -1,134 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.cxf.bus.blueprint;
-
-import java.io.IOException;
-import java.net.URL;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
-import java.security.PrivilegedActionException;
-import java.security.PrivilegedExceptionAction;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Enumeration;
-
-import org.osgi.framework.Bundle;
-
-/**
- * A ClassLoader delegating to a given OSGi bundle.
- */
-public class BundleDelegatingClassLoader extends ClassLoader {
-
- private final Bundle bundle;
- private final ClassLoader classLoader;
-
- public BundleDelegatingClassLoader(Bundle bundle) {
- this(bundle, null);
- }
-
- public BundleDelegatingClassLoader(Bundle bundle, ClassLoader classLoader) {
- this.bundle = bundle;
- this.classLoader = classLoader;
- }
-
- @Override
- protected Class<?> findClass(final String name) throws ClassNotFoundException {
- try {
- return AccessController.doPrivileged(new PrivilegedExceptionAction<Class<?>>() {
- public Class<?> run() throws ClassNotFoundException {
- return bundle.loadClass(name);
- }
- });
- } catch (PrivilegedActionException e) {
- Exception cause = e.getException();
-
- if (cause instanceof ClassNotFoundException) {
- throw (ClassNotFoundException)cause;
- }
- throw (RuntimeException)cause;
- }
- }
-
- @Override
- protected URL findResource(final String name) {
- URL resource = AccessController.doPrivileged(new PrivilegedAction<URL>() {
- public URL run() {
- return bundle.getResource(name);
- }
- });
- if (classLoader != null && resource == null) {
- resource = classLoader.getResource(name);
- }
- return resource;
- }
-
- @Override
- protected Enumeration<URL> findResources(final String name) throws IOException {
- Enumeration<URL> urls;
- try {
- urls = AccessController.doPrivileged(new PrivilegedExceptionAction<Enumeration<URL>>() {
- public Enumeration<URL> run() throws IOException {
- return bundle.getResources(name);
- }
-
- });
- } catch (PrivilegedActionException e) {
- Exception cause = e.getException();
-
- if (cause instanceof IOException) {
- throw (IOException)cause;
- }
- throw (RuntimeException)cause;
- }
-
- if (urls == null) {
- urls = Collections.enumeration(new ArrayList<>());
- }
-
- return urls;
- }
-
- @Override
- protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException {
- Class<?> clazz;
- try {
- clazz = findClass(name);
- } catch (ClassNotFoundException cnfe) {
- if (classLoader != null) {
- try {
- clazz = classLoader.loadClass(name);
- } catch (ClassNotFoundException e) {
- throw new ClassNotFoundException(name + " from bundle " + bundle.getBundleId()
- + " (" + bundle.getSymbolicName() + ")", cnfe);
- }
- } else {
- throw new ClassNotFoundException(name + " from bundle " + bundle.getBundleId()
- + " (" + bundle.getSymbolicName() + ")", cnfe);
- }
- }
- if (resolve) {
- resolveClass(clazz);
- }
- return clazz;
- }
-
- public Bundle getBundle() {
- return bundle;
- }
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/bus/blueprint/BusDefinitionParser.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/bus/blueprint/BusDefinitionParser.java
deleted file mode 100644
index baf83b7..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/bus/blueprint/BusDefinitionParser.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.cxf.bus.blueprint;
-
-
-import org.w3c.dom.Element;
-
-import org.apache.aries.blueprint.ParserContext;
-import org.apache.aries.blueprint.mutable.MutableBeanMetadata;
-import org.apache.cxf.common.util.StringUtils;
-import org.apache.cxf.configuration.blueprint.AbstractBPBeanDefinitionParser;
-import org.osgi.service.blueprint.reflect.Metadata;
-
-public class BusDefinitionParser
- extends AbstractBPBeanDefinitionParser {
-
- public BusDefinitionParser() {
- }
-
- public Metadata parse(Element element, ParserContext context) {
- String bname = element.hasAttribute("bus") ? element.getAttribute("bus") : "cxf";
- String id = element.hasAttribute("id") ? element.getAttribute("id") : null;
- MutableBeanMetadata cxfBean = getBus(context, bname);
- parseAttributes(element, context, cxfBean);
- parseChildElements(element, context, cxfBean);
- context.getComponentDefinitionRegistry().removeComponentDefinition(bname);
- if (!StringUtils.isEmpty(id)) {
- cxfBean.addProperty("id", createValue(context, id));
- }
- return cxfBean;
- }
-
- @Override
- protected void processBusAttribute(Element element, ParserContext ctx,
- MutableBeanMetadata bean, String val) {
- //nothing
- }
-
- @Override
- protected boolean hasBusProperty() {
- return false;
- }
-
-
- @Override
- protected void mapElement(ParserContext ctx, MutableBeanMetadata bean, Element el, String name) {
- if ("inInterceptors".equals(name) || "inFaultInterceptors".equals(name)
- || "outInterceptors".equals(name) || "outFaultInterceptors".equals(name)
- || "features".equals(name)) {
- bean.addProperty(name, parseListData(ctx, bean, el));
- } else if ("properties".equals(name)) {
- bean.addProperty(name, parseMapData(ctx, bean, el));
- }
- }
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/bus/blueprint/ConfigurerImpl.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/bus/blueprint/ConfigurerImpl.java
deleted file mode 100644
index 37f82fe..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/bus/blueprint/ConfigurerImpl.java
+++ /dev/null
@@ -1,180 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.cxf.bus.blueprint;
-
-import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.TreeMap;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-import org.apache.aries.blueprint.services.ExtendedBlueprintContainer;
-import org.apache.cxf.common.logging.LogUtils;
-import org.apache.cxf.configuration.Configurable;
-import org.apache.cxf.configuration.Configurer;
-import org.osgi.service.blueprint.container.BlueprintContainer;
-import org.osgi.service.blueprint.container.NoSuchComponentException;
-import org.osgi.service.blueprint.reflect.BeanMetadata;
-import org.osgi.service.blueprint.reflect.ComponentMetadata;
-
-/**
- *
- */
-public class ConfigurerImpl implements Configurer {
- private static final Logger LOG = LogUtils.getL7dLogger(ConfigurerImpl.class);
- BlueprintContainer container;
-
- private final Map<String, List<MatcherHolder>> wildCardBeanDefinitions
- = new TreeMap<>();
-
- static class MatcherHolder implements Comparable<MatcherHolder> {
- Matcher matcher;
- String wildCardId;
- MatcherHolder(String orig, Matcher matcher) {
- wildCardId = orig;
- this.matcher = matcher;
- }
- @Override
- public int compareTo(MatcherHolder mh) {
- int literalCharsLen1 = this.wildCardId.replace("*", "").length();
- int literalCharsLen2 = mh.wildCardId.replace("*", "").length();
- // The expression with more literal characters should end up on the top of the list
- return Integer.compare(literalCharsLen1, literalCharsLen2) * -1;
- }
- }
-
- public ConfigurerImpl(BlueprintContainer con) {
- container = con;
- initializeWildcardMap();
- }
- private boolean isWildcardBeanName(String bn) {
- return bn.indexOf('*') != -1 || bn.indexOf('?') != -1
- || (bn.indexOf('(') != -1 && bn.indexOf(')') != -1);
- }
-
- private void initializeWildcardMap() {
- for (String s : container.getComponentIds()) {
- if (isWildcardBeanName(s)) {
- ComponentMetadata cmd = container.getComponentMetadata(s);
- Class<?> cls = BlueprintBeanLocator.getClassForMetaData(container, cmd);
- if (cls != null) {
- final String cid = s.charAt(0) != '*' ? s
- : "." + s.replaceAll("\\.", "\\."); //old wildcard
- Matcher matcher = Pattern.compile(cid).matcher("");
- List<MatcherHolder> m = wildCardBeanDefinitions.get(cls.getName());
- if (m == null) {
- m = new ArrayList<>();
- wildCardBeanDefinitions.put(cls.getName(), m);
- }
- MatcherHolder holder = new MatcherHolder(s, matcher);
- m.add(holder);
- }
- }
- }
- }
-
- public void configureBean(Object beanInstance) {
- configureBean(null, beanInstance, true);
- }
-
- public void configureBean(String bn, Object beanInstance) {
- configureBean(bn, beanInstance, true);
- }
- public synchronized void configureBean(String bn, Object beanInstance, boolean checkWildcards) {
- if (null == bn) {
- bn = getBeanName(beanInstance);
- }
-
- if (null == bn) {
- return;
- }
- if (checkWildcards) {
- configureWithWildCard(bn, beanInstance);
- }
-
- if (container instanceof ExtendedBlueprintContainer) {
- try {
- final ComponentMetadata cm = container.getComponentMetadata(bn);
- if (cm instanceof BeanMetadata) {
- ((ExtendedBlueprintContainer)container).injectBeanInstance((BeanMetadata)cm, beanInstance);
- }
- } catch (NoSuchComponentException nsce) {
- }
- }
- }
-
- private void configureWithWildCard(String bn, Object beanInstance) {
- if (!wildCardBeanDefinitions.isEmpty()) {
- Class<?> clazz = beanInstance.getClass();
- while (!Object.class.equals(clazz)) {
- String className = clazz.getName();
- List<MatcherHolder> matchers = wildCardBeanDefinitions.get(className);
- if (matchers != null) {
- for (MatcherHolder m : matchers) {
- synchronized (m.matcher) {
- m.matcher.reset(bn);
- if (m.matcher.matches()) {
- configureBean(m.wildCardId, beanInstance, false);
- return;
- }
- }
- }
- }
- clazz = clazz.getSuperclass();
- }
- }
- }
-
- protected String getBeanName(Object beanInstance) {
- if (beanInstance instanceof Configurable) {
- return ((Configurable)beanInstance).getBeanName();
- }
- String beanName = null;
- Method m = null;
- try {
- m = beanInstance.getClass().getDeclaredMethod("getBeanName", (Class[])null);
- } catch (NoSuchMethodException ex) {
- try {
- m = beanInstance.getClass().getMethod("getBeanName", (Class[])null);
- } catch (NoSuchMethodException e) {
- //ignore
- }
- }
- if (m != null) {
- try {
- beanName = (String)(m.invoke(beanInstance));
- } catch (Exception ex) {
- LogUtils.log(LOG, Level.WARNING, "ERROR_DETERMINING_BEAN_NAME_EXC", ex);
- }
- }
-
- if (null == beanName) {
- LogUtils.log(LOG, Level.FINE, "COULD_NOT_DETERMINE_BEAN_NAME_MSG",
- beanInstance.getClass().getName());
- }
-
- return beanName;
- }
-
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/bus/extension/Extension.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/bus/extension/Extension.java
deleted file mode 100644
index 03f0dc6..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/bus/extension/Extension.java
+++ /dev/null
@@ -1,291 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.cxf.bus.extension;
-
-import java.lang.reflect.Constructor;
-import java.lang.reflect.InvocationTargetException;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import org.apache.cxf.Bus;
-import org.apache.cxf.common.i18n.Message;
-import org.apache.cxf.common.logging.LogUtils;
-import org.apache.cxf.common.util.StringUtils;
-
-public class Extension {
- protected static final Logger LOG = LogUtils.getL7dLogger(Extension.class);
-
- private static final String PROBLEM_CREATING_EXTENSION_CLASS = "PROBLEM_CREATING_EXTENSION_CLASS";
-
- protected String className;
- protected ClassLoader classloader;
- protected volatile Class<?> clazz;
- protected volatile Class<?> intf;
- protected String interfaceName;
- protected boolean deferred;
- protected Collection<String> namespaces = new ArrayList<>();
- protected Object[] args;
- protected volatile Object obj;
- protected boolean optional;
- protected boolean notFound;
-
-
- public Extension() {
- }
-
- public Extension(Class<?> cls, Class<?> inf) {
- clazz = cls;
- intf = inf;
- interfaceName = inf.getName();
- className = cls.getName();
- classloader = cls.getClassLoader();
- }
- public Extension(Class<?> cls) {
- clazz = cls;
- className = cls.getName();
- classloader = cls.getClassLoader();
- }
- public Extension(ClassLoader loader) {
- classloader = loader;
- }
-
- public Extension(Extension ext) {
- className = ext.className;
- interfaceName = ext.interfaceName;
- deferred = ext.deferred;
- namespaces = ext.namespaces;
- obj = ext.obj;
- clazz = ext.clazz;
- intf = ext.intf;
- classloader = ext.classloader;
- args = ext.args;
- optional = ext.optional;
- }
-
- public void setOptional(boolean b) {
- optional = b;
- }
- public boolean isOptional() {
- return optional;
- }
-
- public String getName() {
- return StringUtils.isEmpty(interfaceName) ? className : interfaceName;
- }
- public Object getLoadedObject() {
- return obj;
- }
-
- public Extension cloneNoObject() {
- Extension ext = new Extension(this);
- ext.obj = null;
- ext.clazz = null;
- ext.intf = null;
- return ext;
- }
-
- public String toString() {
- StringBuilder buf = new StringBuilder(128);
- buf.append("class: ");
- buf.append(className);
- buf.append(", interface: ");
- buf.append(interfaceName);
- buf.append(", deferred: ");
- buf.append(deferred ? "true" : "false");
- buf.append(", namespaces: (");
- int n = 0;
- for (String ns : namespaces) {
- if (n > 0) {
- buf.append(", ");
- }
- buf.append(ns);
- n++;
- }
- buf.append(')');
- return buf.toString();
- }
-
- public String getClassname() {
- return className;
- }
-
- public void setClassname(String i) {
- clazz = null;
- notFound = false;
- className = i;
- }
-
- public String getInterfaceName() {
- return interfaceName;
- }
-
- public void setInterfaceName(String i) {
- interfaceName = i;
- notFound = false;
- }
-
- public boolean isDeferred() {
- return deferred;
- }
-
- public void setDeferred(boolean d) {
- deferred = d;
- }
-
- public Collection<String> getNamespaces() {
- return namespaces;
- }
-
- public void setArgs(Object[] a) {
- args = a;
- }
-
- protected Class<?> tryClass(String name, ClassLoader cl) {
- Throwable origEx = null;
- if (classloader != null) {
- try {
- return classloader.loadClass(name);
- } catch (Throwable nex) {
- //ignore, fall into the stuff below
- //save the exception though as this is likely the important one
- origEx = nex;
- }
- }
- try {
- return cl.loadClass(name);
- } catch (Throwable ex) {
- try {
- // using the extension classloader as a fallback
- return this.getClass().getClassLoader().loadClass(name);
- } catch (Throwable nex) {
- notFound = true;
- if (!optional) {
- throw new ExtensionException(new Message("PROBLEM_LOADING_EXTENSION_CLASS", LOG, name),
- origEx != null ? origEx : ex);
- }
- }
- }
- return null;
- }
-
- public Class<?> getClassObject(ClassLoader cl) {
- if (notFound) {
- return null;
- }
- if (clazz != null) {
- return clazz;
- }
- synchronized (this) {
- if (clazz == null) {
- clazz = tryClass(className, cl);
- }
- }
- return clazz;
- }
- public Object load(ClassLoader cl, Bus b) {
- if (obj != null) {
- return obj;
- }
- Class<?> cls = getClassObject(cl);
- try {
- if (notFound) {
- return null;
- }
- try {
- //if there is a Bus constructor, use it.
- if (b != null && args == null) {
- Constructor<?> con = cls.getConstructor(Bus.class);
- obj = con.newInstance(b);
- return obj;
- } else if (b != null && args != null) {
- try {
- obj = cls.getConstructor(Bus.class, Object[].class).newInstance(b, args);
- } catch (NoSuchMethodException ex) { // no bus
- obj = cls.getConstructor(Object[].class).newInstance(args);
- }
- return obj;
- } else if (args != null) {
- Constructor<?> con = cls.getConstructor(Object[].class);
- obj = con.newInstance(args);
- return obj;
- }
- } catch (InvocationTargetException ex) {
- throw new ExtensionException(new Message(PROBLEM_CREATING_EXTENSION_CLASS, LOG, cls.getName()),
- ex.getCause());
- } catch (InstantiationException | SecurityException ex) {
- throw new ExtensionException(new Message(PROBLEM_CREATING_EXTENSION_CLASS, LOG, cls.getName()), ex);
- } catch (NoSuchMethodException e) {
- //ignore
- }
- obj = cls.getConstructor().newInstance();
- } catch (ExtensionException ex) {
- notFound = true;
- if (!optional) {
- throw ex;
- }
- LOG.log(Level.FINE, "Could not load optional extension " + getName(), ex);
- } catch (InvocationTargetException ex) {
- notFound = true;
- if (!optional) {
- throw new ExtensionException(new Message(PROBLEM_CREATING_EXTENSION_CLASS, LOG, cls.getName()),
- ex.getCause());
- }
- LOG.log(Level.FINE, "Could not load optional extension " + getName(), ex);
- } catch (NoSuchMethodException ex) {
- notFound = true;
- List<Object> a = new ArrayList<>();
- if (b != null) {
- a.add(b);
- }
- if (args != null) {
- a.add(args);
- }
- if (!optional) {
- throw new ExtensionException(new Message("PROBLEM_FINDING_CONSTRUCTOR", LOG,
- cls.getName(), a), ex);
- }
- LOG.log(Level.FINE, "Could not load optional extension " + getName(), ex);
- } catch (Throwable e) {
- notFound = true;
- if (!optional) {
- throw new ExtensionException(new Message(PROBLEM_CREATING_EXTENSION_CLASS, LOG, cls.getName()), e);
- }
- LOG.log(Level.FINE, "Could not load optional extension " + getName(), e);
- }
- return obj;
- }
-
- public Class<?> loadInterface(ClassLoader cl) {
- if (intf != null || notFound) {
- return intf;
- }
- synchronized (this) {
- if (intf == null) {
- intf = tryClass(interfaceName, cl);
- }
- }
- return intf;
- }
-
-
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/bus/extension/ExtensionManagerImpl.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/bus/extension/ExtensionManagerImpl.java
deleted file mode 100644
index d4ce0be..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/bus/extension/ExtensionManagerImpl.java
+++ /dev/null
@@ -1,381 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.cxf.bus.extension;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.lang.reflect.Method;
-import java.net.URL;
-import java.security.AccessController;
-import java.security.PrivilegedActionException;
-import java.security.PrivilegedExceptionAction;
-import java.util.Collection;
-import java.util.Enumeration;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.CopyOnWriteArrayList;
-
-import org.apache.cxf.Bus;
-import org.apache.cxf.common.injection.ResourceInjector;
-import org.apache.cxf.configuration.ConfiguredBeanLocator;
-import org.apache.cxf.configuration.Configurer;
-import org.apache.cxf.resource.ObjectTypeResolver;
-import org.apache.cxf.resource.ResourceManager;
-import org.apache.cxf.resource.ResourceResolver;
-import org.apache.cxf.resource.SinglePropertyResolver;
-
-public class ExtensionManagerImpl implements ExtensionManager, ConfiguredBeanLocator {
- public static final String EXTENSIONMANAGER_PROPERTY_NAME = "extensionManager";
- public static final String ACTIVATION_NAMESPACES_PROPERTY_NAME = "activationNamespaces";
- public static final String ACTIVATION_NAMESPACES_SETTER_METHOD_NAME = "setActivationNamespaces";
- public static final String BUS_EXTENSION_RESOURCE = "META-INF/cxf/bus-extensions.txt";
-
- private final ClassLoader loader;
- private ResourceManager resourceManager;
- private Map<String, Extension> all = new ConcurrentHashMap<>();
- private List<Extension> ordered = new CopyOnWriteArrayList<>();
- private final Map<Class<?>, Object> activated;
- private final Bus bus;
-
- public ExtensionManagerImpl(ClassLoader cl, Map<Class<?>, Object> initialExtensions,
- ResourceManager rm, Bus b) {
- this(new String[] {BUS_EXTENSION_RESOURCE},
- cl, initialExtensions, rm, b);
- }
- public ExtensionManagerImpl(String resource,
- ClassLoader cl,
- Map<Class<?>, Object> initialExtensions,
- ResourceManager rm,
- Bus b) {
- this(new String[] {resource}, cl, initialExtensions, rm, b);
- }
- public ExtensionManagerImpl(String[] resources,
- ClassLoader cl,
- Map<Class<?>, Object> initialExtensions,
- ResourceManager rm,
- Bus b) {
-
- loader = cl;
- bus = b;
- activated = initialExtensions;
- resourceManager = rm;
-
- ResourceResolver extensionManagerResolver =
- new SinglePropertyResolver(EXTENSIONMANAGER_PROPERTY_NAME, this);
- resourceManager.addResourceResolver(extensionManagerResolver);
- resourceManager.addResourceResolver(new ObjectTypeResolver(this));
-
- load(resources);
- for (Map.Entry<String, Extension> ext : ExtensionRegistry.getRegisteredExtensions().entrySet()) {
- if (!all.containsKey(ext.getKey())) {
- all.put(ext.getKey(), ext.getValue());
- ordered.add(ext.getValue());
- }
- }
- }
-
- final void load(String[] resources) {
- if (resources == null) {
- return;
- }
- try {
- for (String resource : resources) {
- load(resource);
- }
- } catch (IOException ex) {
- throw new ExtensionException(ex);
- }
- }
- public void add(Extension ex) {
- all.put(ex.getName(), ex);
- ordered.add(ex);
- }
-
- public void initialize() {
- for (Extension e : ordered) {
- if (!e.isDeferred() && e.getLoadedObject() == null) {
- loadAndRegister(e);
- }
- }
- }
-
- public void removeBeansOfNames(List<String> names) {
- for (String s : names) {
- Extension ex = all.remove(s);
- if (ex != null) {
- ordered.remove(ex);
- }
- }
- }
- public void activateAll() {
- for (Extension e : ordered) {
- if (e.getLoadedObject() == null) {
- loadAndRegister(e);
- }
- }
- }
- public <T> void activateAllByType(Class<T> type) {
- for (Extension e : ordered) {
- if (e.getLoadedObject() == null) {
- Class<?> cls = e.getClassObject(loader);
- if (cls != null && type.isAssignableFrom(cls)) {
- synchronized (e) {
- loadAndRegister(e);
- }
- }
- }
- }
- }
-
- public boolean hasBeanOfName(String name) {
- return all.containsKey(name);
- }
-
- final void load(String resource) throws IOException {
- if (loader != getClass().getClassLoader()) {
- load(resource, getClass().getClassLoader());
- }
- load(resource, loader);
- }
- final synchronized void load(String resource, ClassLoader l) throws IOException {
-
- Enumeration<URL> urls = l.getResources(resource);
-
- while (urls.hasMoreElements()) {
- final URL url = urls.nextElement();
- try (InputStream is = AccessController.doPrivileged(new PrivilegedExceptionAction<InputStream>() {
- public InputStream run() throws Exception {
- return url.openStream();
- }
- })) {
- List<Extension> exts = new TextExtensionFragmentParser(loader).getExtensions(is);
- for (Extension e : exts) {
- if (loader != l) {
- e.classloader = l;
- }
- if (!all.containsKey(e.getName())) {
- all.put(e.getName(), e);
- ordered.add(e);
- }
- }
- } catch (PrivilegedActionException pae) {
- throw (IOException)pae.getException();
- }
- }
- }
-
- final void loadAndRegister(Extension e) {
- Class<?> cls;
- if (null != e.getInterfaceName() && !"".equals(e.getInterfaceName())) {
- cls = e.loadInterface(loader);
- } else {
- cls = e.getClassObject(loader);
- }
- if (null != activated && null != cls && null != activated.get(cls)) {
- return;
- }
-
- synchronized (e) {
- Object obj = e.load(loader, bus);
- if (obj == null) {
- return;
- }
-
- if (null != activated) {
- Configurer configurer = (Configurer)(activated.get(Configurer.class));
- if (null != configurer) {
- configurer.configureBean(obj);
- }
- }
-
- // let the object know for which namespaces it has been activated
- ResourceResolver namespacesResolver = null;
- if (null != e.getNamespaces()) {
- namespacesResolver = new SinglePropertyResolver(ACTIVATION_NAMESPACES_PROPERTY_NAME,
- e.getNamespaces());
- resourceManager.addResourceResolver(namespacesResolver);
- }
-
- // Since we need to support spring2.5 by removing @Resource("activationNamespaces")
- // Now we call the setActivationNamespaces method directly here
- if (e.getNamespaces() != null && !e.getNamespaces().isEmpty()) {
- invokeSetterActivationNSMethod(obj, e.getNamespaces());
- }
-
- ResourceInjector injector = new ResourceInjector(resourceManager);
-
- try {
- injector.inject(obj);
- injector.construct(obj);
- } finally {
- if (null != namespacesResolver) {
- resourceManager.removeResourceResolver(namespacesResolver);
- }
- }
-
- if (null != activated) {
- if (cls == null) {
- cls = obj.getClass();
- }
- activated.put(cls, obj);
- }
- }
- }
-
- public <T> T getExtension(String name, Class<T> type) {
- if (name == null) {
- return null;
- }
- Extension e = all.get(name);
- if (e != null) {
- Class<?> cls = e.getClassObject(loader);
- if (cls != null && type.isAssignableFrom(cls)) {
- synchronized (e) {
- if (e.getLoadedObject() == null) {
- loadAndRegister(e);
- }
- return type.cast(e.getLoadedObject());
- }
- }
- }
- return null;
- }
-
- private void invokeSetterActivationNSMethod(Object target, Object value) {
- Class<?> clazz = target.getClass();
- String methodName = ACTIVATION_NAMESPACES_SETTER_METHOD_NAME;
- while (clazz != Object.class) {
- Method[] methods = clazz.getMethods();
- for (int i = 0; i < methods.length; i++) {
- Method method = methods[i];
- Class<?>[] params = method.getParameterTypes();
- if (method.getName().equals(methodName) && params.length == 1) {
- Class<?> paramType = params[0];
- if (paramType.isInstance(value)) {
- try {
- method.invoke(target, new Object[] {value});
- } catch (Exception e) {
- // do nothing here
- }
- return;
- }
- }
- }
- clazz = clazz.getSuperclass();
- }
- }
- public List<String> getBeanNamesOfType(Class<?> type) {
- List<String> ret = new LinkedList<>();
- for (Extension ex : ordered) {
- Class<?> cls = ex.getClassObject(loader);
- if (cls != null && type.isAssignableFrom(cls)) {
- synchronized (ex) {
- ret.add(ex.getName());
- }
- }
- }
- return ret;
- }
- public <T> T getBeanOfType(String name, Class<T> type) {
- if (name == null) {
- return null;
- }
- Extension ex = all.get(name);
- if (ex != null) {
- if (ex.getLoadedObject() == null) {
- loadAndRegister(ex);
- }
- return type.cast(ex.getLoadedObject());
- }
- return null;
- }
- public <T> Collection<? extends T> getBeansOfType(Class<T> type) {
- List<T> ret = new LinkedList<>();
- Extension ext = all.get(type.getName());
- if (ext != null) {
- Class<?> cls = ext.getClassObject(loader);
- if (cls != null && type.isAssignableFrom(cls)) {
- synchronized (ext) {
- if (ext.getLoadedObject() == null) {
- loadAndRegister(ext);
- }
- if (ext.getLoadedObject() != null) {
- ret.add(type.cast(ext.getLoadedObject()));
- }
- }
- }
- }
- for (Extension ex : ordered) {
- if (ex != ext) {
- Class<?> cls = ex.getClassObject(loader);
- if (cls != null && type.isAssignableFrom(cls)) {
- synchronized (ex) {
- if (ex.getLoadedObject() == null) {
- loadAndRegister(ex);
- }
- if (ex.getLoadedObject() != null) {
- ret.add(type.cast(ex.getLoadedObject()));
- }
- }
- }
- }
- }
- return ret;
- }
- public <T> boolean loadBeansOfType(Class<T> type, BeanLoaderListener<T> listener) {
- boolean loaded = false;
- for (Extension ex : ordered) {
- Class<?> cls = ex.getClassObject(loader);
- if (cls != null
- && type.isAssignableFrom(cls)) {
- synchronized (ex) {
- if (listener.loadBean(ex.getName(), cls.asSubclass(type))) {
- if (ex.getLoadedObject() == null) {
- loadAndRegister(ex);
- }
- if (listener.beanLoaded(ex.getName(), type.cast(ex.getLoadedObject()))) {
- return true;
- }
- loaded = true;
- }
- }
- }
- }
- return loaded;
- }
- public boolean hasConfiguredPropertyValue(String beanName, String propertyName, String value) {
- if (beanName == null) {
- return false;
- }
- Extension ex = all.get(beanName);
- return ex != null && ex.getNamespaces() != null
- && ex.getNamespaces().contains(value);
- }
- public void destroyBeans() {
- for (Extension ex : ordered) {
- if (ex.getLoadedObject() != null) {
- ResourceInjector injector = new ResourceInjector(resourceManager);
- injector.destroy(ex.getLoadedObject());
- }
- }
- }
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/bus/managers/ServiceContractResolverRegistryImpl.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/bus/managers/ServiceContractResolverRegistryImpl.java
deleted file mode 100644
index a0f7af0..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/bus/managers/ServiceContractResolverRegistryImpl.java
+++ /dev/null
@@ -1,113 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.cxf.bus.managers;
-
-import java.net.URI;
-import java.util.List;
-import java.util.concurrent.CopyOnWriteArrayList;
-
-import javax.xml.namespace.QName;
-
-import org.apache.cxf.Bus;
-import org.apache.cxf.common.injection.NoJSR250Annotations;
-import org.apache.cxf.endpoint.ServiceContractResolver;
-import org.apache.cxf.endpoint.ServiceContractResolverRegistry;
-
-/**
- * A simple contract resolver registry. It maintains a list of contract resolvers in an
- * <code>ArrayList</code>.
- */
-@NoJSR250Annotations(unlessNull = "bus")
-public class ServiceContractResolverRegistryImpl implements ServiceContractResolverRegistry {
-
- private List<ServiceContractResolver> resolvers
- = new CopyOnWriteArrayList<>();
-
- public ServiceContractResolverRegistryImpl() {
-
- }
- public ServiceContractResolverRegistryImpl(Bus b) {
- setBus(b);
- }
-
-
- /**
- * Sets the bus with which the registry is associated.
- *
- * @param bus
- */
- public final void setBus(Bus bus) {
- if (bus != null) {
- bus.setExtension(this, ServiceContractResolverRegistry.class);
- }
- }
-
- /**
- * Calls each of the registered <code>ServiceContractResolver</code> instances
- * to resolve the location of the service's contract. It returns the location
- * from the first resolver that matches the QName to a location.
- *
- * @param qname QName to be resolved into a contract location
- * @return URI representing the location of the contract
- */
- public URI getContractLocation(QName qname) {
- for (ServiceContractResolver resolver : resolvers) {
- URI contractLocation = resolver.getContractLocation(qname);
- if (null != contractLocation) {
- return contractLocation;
- }
- }
- return null;
- }
-
- /**
- * Tests if a resolver is alreadey registered with this registry.
- *
- * @param resolver the contract resolver for which to searche
- * @return <code>true</code> if the resolver is registered
- */
- public boolean isRegistered(ServiceContractResolver resolver) {
- return resolvers.contains(resolver);
- }
-
- /**
- * Registers a contract resolver with this registry.
- *
- * @param resolver the contract resolver to register
- */
- public synchronized void register(ServiceContractResolver resolver) {
- resolvers.add(resolver);
- }
-
- /**
- * Removes a contract resolver from this registry.
- *
- * @param resolver the contract resolver to remove
- */
- public synchronized void unregister(ServiceContractResolver resolver) {
- resolvers.remove(resolver);
- }
-
-
- protected List<ServiceContractResolver> getResolvers() {
- return resolvers;
- }
-
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/bus/osgi/CXFActivator.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/bus/osgi/CXFActivator.java
deleted file mode 100644
index 6504276..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/bus/osgi/CXFActivator.java
+++ /dev/null
@@ -1,134 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.cxf.bus.osgi;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.cxf.bus.blueprint.BlueprintNameSpaceHandlerFactory;
-import org.apache.cxf.bus.blueprint.NamespaceHandlerRegisterer;
-import org.apache.cxf.bus.extension.Extension;
-import org.apache.cxf.bus.extension.ExtensionRegistry;
-import org.apache.cxf.common.util.CollectionUtils;
-import org.apache.cxf.internal.CXFAPINamespaceHandler;
-import org.osgi.framework.BundleActivator;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.Constants;
-import org.osgi.framework.ServiceRegistration;
-import org.osgi.service.cm.ConfigurationAdmin;
-import org.osgi.service.cm.ManagedServiceFactory;
-import org.osgi.util.tracker.ServiceTracker;
-
-/**
- * Is called in OSGi on start and stop of the cxf bundle.
- * Manages
- * - CXFBundleListener
- * - Attaching ManagedWorkqueues to config admin service
- * - OsgiBusListener
- * - Blueprint namespaces
- */
-public class CXFActivator implements BundleActivator {
-
- private List<Extension> extensions;
- private ManagedWorkQueueList workQueues;
- private ServiceTracker<ConfigurationAdmin, ConfigurationAdmin> configAdminTracker;
- private CXFExtensionBundleListener cxfBundleListener;
- private ServiceRegistration<ManagedServiceFactory> workQueueServiceRegistration;
-
-
-
- /** {@inheritDoc}*/
- public void start(BundleContext context) throws Exception {
- workQueues = new ManagedWorkQueueList();
- cxfBundleListener = new CXFExtensionBundleListener(context.getBundle().getBundleId());
- context.addBundleListener(cxfBundleListener);
- cxfBundleListener.registerExistingBundles(context);
-
- configAdminTracker = new ServiceTracker<>(context, ConfigurationAdmin.class, null);
- configAdminTracker.open();
- workQueues.setConfigAdminTracker(configAdminTracker);
- workQueueServiceRegistration = registerManagedServiceFactory(context,
- ManagedServiceFactory.class,
- workQueues,
- ManagedWorkQueueList.FACTORY_PID);
-
- extensions = new ArrayList<>();
- extensions.add(createOsgiBusListenerExtension(context));
- extensions.add(createManagedWorkQueueListExtension(workQueues));
- ExtensionRegistry.addExtensions(extensions);
-
- BlueprintNameSpaceHandlerFactory factory = new BlueprintNameSpaceHandlerFactory() {
-
- @Override
- public Object createNamespaceHandler() {
- return new CXFAPINamespaceHandler();
- }
- };
- NamespaceHandlerRegisterer.register(context, factory,
- "http://cxf.apache.org/blueprint/core",
- "http://cxf.apache.org/configuration/beans",
- "http://cxf.apache.org/configuration/parameterized-types",
- "http://cxf.apache.org/configuration/security",
- "http://schemas.xmlsoap.org/wsdl/",
- "http://www.w3.org/2005/08/addressing",
- "http://schemas.xmlsoap.org/ws/2004/08/addressing");
-
- }
-
- private <T> ServiceRegistration<T> registerManagedServiceFactory(BundleContext context,
- Class<T> serviceClass,
- T service,
- String servicePid) {
- return context.registerService(serviceClass, service,
- CollectionUtils.singletonDictionary(Constants.SERVICE_PID, servicePid));
- }
-
- private Extension createOsgiBusListenerExtension(BundleContext context) {
- Extension busListener = new Extension(OSGIBusListener.class);
- busListener.setArgs(new Object[] {context});
- return busListener;
- }
-
- private static Extension createManagedWorkQueueListExtension(final ManagedWorkQueueList workQueues) {
- return new Extension(ManagedWorkQueueList.class) {
-
- @Override
- public Object getLoadedObject() {
- return workQueues;
- }
-
- @Override
- public Extension cloneNoObject() {
- return this;
- }
- };
- }
-
- /** {@inheritDoc}*/
- public void stop(BundleContext context) throws Exception {
- context.removeBundleListener(cxfBundleListener);
- cxfBundleListener.shutdown();
- workQueues.shutDown();
- workQueueServiceRegistration.unregister();
- configAdminTracker.close();
- ExtensionRegistry.removeExtensions(extensions);
- }
-
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/bus/osgi/CXFExtensionBundleListener.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/bus/osgi/CXFExtensionBundleListener.java
deleted file mode 100644
index ee9bb15..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/bus/osgi/CXFExtensionBundleListener.java
+++ /dev/null
@@ -1,181 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.cxf.bus.osgi;
-
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.Enumeration;
-import java.util.List;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentMap;
-import java.util.concurrent.CopyOnWriteArrayList;
-import java.util.logging.Logger;
-
-import org.apache.cxf.Bus;
-import org.apache.cxf.bus.extension.Extension;
-import org.apache.cxf.bus.extension.ExtensionException;
-import org.apache.cxf.bus.extension.ExtensionRegistry;
-import org.apache.cxf.bus.extension.TextExtensionFragmentParser;
-import org.apache.cxf.common.i18n.Message;
-import org.apache.cxf.common.logging.LogUtils;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.BundleEvent;
-import org.osgi.framework.ServiceReference;
-import org.osgi.framework.SynchronousBundleListener;
-
-public class CXFExtensionBundleListener implements SynchronousBundleListener {
- private static final Logger LOG = LogUtils.getL7dLogger(CXFActivator.class);
- private long id;
- private ConcurrentMap<Long, List<OSGiExtension>> extensions
- = new ConcurrentHashMap<>(16, 0.75f, 4);
-
- public CXFExtensionBundleListener(long bundleId) {
- this.id = bundleId;
- }
-
- public void registerExistingBundles(BundleContext context) {
- for (Bundle bundle : context.getBundles()) {
- if ((bundle.getState() == Bundle.RESOLVED
- || bundle.getState() == Bundle.STARTING
- || bundle.getState() == Bundle.ACTIVE
- || bundle.getState() == Bundle.STOPPING)
- && bundle.getBundleId() != context.getBundle().getBundleId()) {
- register(bundle);
- }
- }
- }
-
- /** {@inheritDoc}*/
- public void bundleChanged(BundleEvent event) {
- if (event.getType() == BundleEvent.RESOLVED && id != event.getBundle().getBundleId()) {
- register(event.getBundle());
- } else if (event.getType() == BundleEvent.UNRESOLVED || event.getType() == BundleEvent.UNINSTALLED) {
- unregister(event.getBundle().getBundleId());
- }
- }
-
- protected void register(final Bundle bundle) {
- Enumeration<?> e = bundle.findEntries("META-INF/cxf/", "bus-extensions.txt", false);
- while (e != null && e.hasMoreElements()) {
- List<Extension> orig = new TextExtensionFragmentParser(null).getExtensions((URL)e.nextElement());
- addExtensions(bundle, orig);
- }
- }
-
- private boolean addExtensions(final Bundle bundle, List<Extension> orig) {
- if (orig.isEmpty()) {
- return false;
- }
-
- List<String> names = new ArrayList<>(orig.size());
- for (Extension ext : orig) {
- names.add(ext.getName());
- }
- LOG.info("Adding the extensions from bundle " + bundle.getSymbolicName()
- + " (" + bundle.getBundleId() + ") " + names);
- List<OSGiExtension> list = extensions.get(bundle.getBundleId());
- if (list == null) {
- list = new CopyOnWriteArrayList<>();
- List<OSGiExtension> preList = extensions.putIfAbsent(bundle.getBundleId(), list);
- if (preList != null) {
- list = preList;
- }
- }
- for (Extension ext : orig) {
- list.add(new OSGiExtension(ext, bundle));
- }
- ExtensionRegistry.addExtensions(list);
- return !list.isEmpty();
- }
-
- protected void unregister(final long bundleId) {
- List<OSGiExtension> list = extensions.remove(bundleId);
- if (list != null) {
- LOG.info("Removing the extensions for bundle " + bundleId);
- ExtensionRegistry.removeExtensions(list);
- }
- }
-
- public void shutdown() {
- while (!extensions.isEmpty()) {
- unregister(extensions.keySet().iterator().next());
- }
- }
-
- public class OSGiExtension extends Extension {
- final Bundle bundle;
- Object serviceObject;
- public OSGiExtension(Extension e, Bundle b) {
- super(e);
- bundle = b;
- }
-
- public void setServiceObject(Object o) {
- serviceObject = o;
- obj = o;
- }
-
- @Override
- public Object load(ClassLoader cl, Bus b) {
- if (interfaceName == null && bundle.getBundleContext() != null) {
- ServiceReference<?> ref = bundle.getBundleContext().getServiceReference(className);
- if (ref != null && ref.getBundle().getBundleId() == bundle.getBundleId()) {
- Object o = bundle.getBundleContext().getService(ref);
- serviceObject = o;
- obj = o;
- return obj;
- }
- }
- return super.load(cl, b);
- }
-
- @Override
- protected Class<?> tryClass(String name, ClassLoader cl) {
- Class<?> c = null;
- Throwable origExc = null;
- try {
- c = bundle.loadClass(className);
- } catch (Throwable e) {
- origExc = e;
- }
- if (c == null) {
- try {
- return super.tryClass(name, cl);
- } catch (ExtensionException ee) {
- if (origExc != null) {
- throw new ExtensionException(new Message("PROBLEM_LOADING_EXTENSION_CLASS",
- Extension.LOG, name),
- origExc);
- }
- throw ee;
- }
- }
- return c;
- }
-
- @Override
- public Extension cloneNoObject() {
- OSGiExtension ext = new OSGiExtension(this, bundle);
- ext.obj = serviceObject;
- return ext;
- }
-
- }
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/bus/osgi/OSGIBusListener.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/bus/osgi/OSGIBusListener.java
deleted file mode 100644
index aad270d..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/bus/osgi/OSGIBusListener.java
+++ /dev/null
@@ -1,224 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.cxf.bus.osgi;
-
-import java.util.Dictionary;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.regex.Pattern;
-
-import org.apache.cxf.Bus;
-import org.apache.cxf.bus.extension.ExtensionManagerImpl;
-import org.apache.cxf.buslifecycle.BusCreationListener;
-import org.apache.cxf.buslifecycle.BusLifeCycleListener;
-import org.apache.cxf.buslifecycle.BusLifeCycleManager;
-import org.apache.cxf.common.util.CollectionUtils;
-import org.apache.cxf.common.util.StringUtils;
-import org.apache.cxf.configuration.ConfiguredBeanLocator;
-import org.apache.cxf.endpoint.ClientLifeCycleListener;
-import org.apache.cxf.endpoint.ClientLifeCycleManager;
-import org.apache.cxf.endpoint.ServerLifeCycleListener;
-import org.apache.cxf.endpoint.ServerLifeCycleManager;
-import org.apache.cxf.feature.Feature;
-import org.apache.cxf.workqueue.WorkQueueManager;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.Constants;
-import org.osgi.framework.InvalidSyntaxException;
-import org.osgi.framework.ServiceReference;
-import org.osgi.framework.ServiceRegistration;
-import org.osgi.framework.Version;
-
-public class OSGIBusListener implements BusLifeCycleListener {
- public static final String CONTEXT_SYMBOLIC_NAME_PROPERTY = "cxf.context.symbolicname";
- public static final String CONTEXT_VERSION_PROPERTY = "cxf.context.version";
- public static final String CONTEXT_NAME_PROPERTY = "cxf.bus.id";
-
- private static final String SERVICE_PROPERTY_PRIVATE = "org.apache.cxf.bus.private.extension";
- private static final String SERVICE_PROPERTY_RESTRICTED = "org.apache.cxf.bus.restricted.extension";
- private static final String BUS_EXTENSION_BUNDLES_EXCLUDES = "bus.extension.bundles.excludes";
- Bus bus;
- ServiceRegistration<?> service;
- BundleContext defaultContext;
- private Pattern extensionBundlesExcludesPattern;
-
- public OSGIBusListener(Bus b) {
- this(b, null);
- }
- public OSGIBusListener(Bus b, Object[] args) {
- bus = b;
- if (args != null && args.length > 0
- && args[0] instanceof BundleContext) {
- defaultContext = (BundleContext)args[0];
- }
- String extExcludes = (String)bus.getProperty(BUS_EXTENSION_BUNDLES_EXCLUDES);
- if (!StringUtils.isEmpty(extExcludes)) {
- try {
- extensionBundlesExcludesPattern = Pattern.compile(extExcludes);
- } catch (IllegalArgumentException e) {
- // ignore
- }
- }
- BusLifeCycleManager manager = bus.getExtension(BusLifeCycleManager.class);
- manager.registerLifeCycleListener(this);
- registerConfiguredBeanLocator();
- registerClientLifeCycleListeners();
- registerServerLifecycleListeners();
- registerBusFeatures();
- sendBusCreatedToBusCreationListeners();
-
- }
- private void registerConfiguredBeanLocator() {
- final ConfiguredBeanLocator cbl = bus.getExtension(ConfiguredBeanLocator.class);
- if (cbl instanceof ExtensionManagerImpl) {
- // wire in the OSGi things
- bus.setExtension(new OSGiBeanLocator(cbl, defaultContext),
- ConfiguredBeanLocator.class);
- }
- }
-
- public void initComplete() {
- ManagedWorkQueueList wqList = bus.getExtension(ManagedWorkQueueList.class);
- if (wqList != null) {
- WorkQueueManager manager = bus.getExtension(WorkQueueManager.class);
- wqList.addAllToWorkQueueManager(manager);
- }
- registerBusAsService();
- }
-
-
- public void preShutdown() {
- }
-
- public void postShutdown() {
- if (service != null) {
- service.unregister();
- service = null;
- }
- }
-
- private static ServiceReference<?>[] getServiceReferences(BundleContext context, Class<?> serviceClass) {
- ServiceReference<?>[] refs = null;
- try {
- refs = context.getServiceReferences(serviceClass.getName(), null);
- } catch (InvalidSyntaxException e) {
- // ignore
- }
- if (refs == null) {
- refs = new ServiceReference<?>[]{};
- }
- return refs;
- }
-
- private void sendBusCreatedToBusCreationListeners() {
- ServiceReference<?>[] refs = getServiceReferences(defaultContext, BusCreationListener.class);
- for (ServiceReference<?> ref : refs) {
- if (!isPrivate(ref) && !isExcluded(ref)) {
- BusCreationListener listener = (BusCreationListener)defaultContext.getService(ref);
- listener.busCreated(bus);
- }
- }
- }
-
- private void registerServerLifecycleListeners() {
- ServiceReference<?>[] refs = getServiceReferences(defaultContext, ServerLifeCycleListener.class);
- ServerLifeCycleManager clcm = bus.getExtension(ServerLifeCycleManager.class);
- for (ServiceReference<?> ref : refs) {
- if (!isPrivate(ref) && !isExcluded(ref)) {
- ServerLifeCycleListener listener = (ServerLifeCycleListener)defaultContext.getService(ref);
- clcm.registerListener(listener);
- }
- }
- }
- private void registerClientLifeCycleListeners() {
- ServiceReference<?>[] refs = getServiceReferences(defaultContext, ClientLifeCycleListener.class);
- ClientLifeCycleManager clcm = bus.getExtension(ClientLifeCycleManager.class);
- for (ServiceReference<?> ref : refs) {
- if (!isPrivate(ref) && !isExcluded(ref)) {
- ClientLifeCycleListener listener = (ClientLifeCycleListener)defaultContext.getService(ref);
- clcm.registerListener(listener);
- }
- }
- }
-
- private void registerBusFeatures() {
- ServiceReference<?>[] refs = getServiceReferences(defaultContext, Feature.class);
- for (ServiceReference<?> ref : refs) {
- if (!isPrivate(ref) && !isExcluded(ref)) {
- Feature feature = (Feature)defaultContext.getService(ref);
- bus.getFeatures().add(feature);
- }
- }
- }
-
- private boolean isPrivate(ServiceReference<?> ref) {
- Object o = ref.getProperty(SERVICE_PROPERTY_PRIVATE);
-
- if (o == null) {
- return false;
- }
-
- Boolean pvt = Boolean.FALSE;
- if (o instanceof String) {
- pvt = Boolean.parseBoolean((String)o);
- } else if (o instanceof Boolean) {
- pvt = (Boolean)o;
- }
- return pvt.booleanValue();
- }
-
- private boolean isExcluded(ServiceReference<?> ref) {
- String o = (String)ref.getProperty(SERVICE_PROPERTY_RESTRICTED);
- if (!StringUtils.isEmpty(o)) {
- // if the service's restricted-regex is set, the service is excluded when the app not matching that regex
- BundleContext app = bus.getExtension(BundleContext.class);
- try {
- if (app != null && !app.getBundle().getSymbolicName().matches(o)) {
- return true;
- }
- } catch (IllegalArgumentException e) {
- // ignore
- }
- }
- // if the excludes-regex is set, the service is excluded when matching that regex.
- return extensionBundlesExcludesPattern != null
- && extensionBundlesExcludesPattern.matcher(ref.getBundle().getSymbolicName()).matches();
- }
-
- private Version getBundleVersion(Bundle bundle) {
- Dictionary<?, ?> headers = bundle.getHeaders();
- String version = (String) headers.get(Constants.BUNDLE_VERSION);
- return (version != null) ? Version.parseVersion(version) : Version.emptyVersion;
- }
-
-
-
- private void registerBusAsService() {
- BundleContext context = bus.getExtension(BundleContext.class);
- if (context != null) {
- Map<String, Object> props = new HashMap<>();
- props.put(CONTEXT_SYMBOLIC_NAME_PROPERTY, context.getBundle().getSymbolicName());
- props.put(CONTEXT_VERSION_PROPERTY, getBundleVersion(context.getBundle()));
- props.put(CONTEXT_NAME_PROPERTY, bus.getId());
-
- service = context.registerService(Bus.class.getName(), bus, CollectionUtils.toDictionary(props));
- }
- }
-
-}
\ No newline at end of file
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/bus/resource/ResourceManagerImpl.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/bus/resource/ResourceManagerImpl.java
deleted file mode 100644
index 99c6ee9..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/bus/resource/ResourceManagerImpl.java
+++ /dev/null
@@ -1,85 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.cxf.bus.resource;
-
-import java.util.List;
-
-import javax.annotation.Resource;
-
-import org.apache.cxf.Bus;
-import org.apache.cxf.common.injection.NoJSR250Annotations;
-import org.apache.cxf.configuration.ConfiguredBeanLocator;
-import org.apache.cxf.extension.BusExtension;
-import org.apache.cxf.resource.DefaultResourceManager;
-import org.apache.cxf.resource.ObjectTypeResolver;
-import org.apache.cxf.resource.ResourceManager;
-import org.apache.cxf.resource.ResourceResolver;
-
-@NoJSR250Annotations(unlessNull = "bus")
-public class ResourceManagerImpl extends DefaultResourceManager implements BusExtension {
-
- private Bus bus;
-
- public ResourceManagerImpl() {
- }
-
- public ResourceManagerImpl(Bus b) {
- super();
- setBus(b);
- }
-
- @Override
- protected void onFirstResolve() {
- super.onFirstResolve();
- if (bus != null) {
- ConfiguredBeanLocator locator = bus.getExtension(ConfiguredBeanLocator.class);
- if (locator != null) {
- this.addResourceResolvers(locator.getBeansOfType(ResourceResolver.class));
- }
- }
- }
-
- /**
- * Set the list of resolvers for this resource manager.
- * @param resolvers
- */
- public final void setResolvers(List<? extends ResourceResolver> resolvers) {
- registeredResolvers.clear();
- registeredResolvers.addAll(resolvers);
- }
-
- @Resource
- public final void setBus(Bus b) {
- if (bus != b) {
- bus = b;
- firstCalled = false;
- super.addResourceResolver(new ObjectTypeResolver(bus));
- if (null != bus) {
- bus.setExtension(this, ResourceManager.class);
- }
- }
- }
-
- public Class<?> getRegistrationType() {
- return ResourceManager.class;
- }
-
-
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/bus/spring/BusDefinitionParser.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/bus/spring/BusDefinitionParser.java
deleted file mode 100644
index 9d508b6..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/bus/spring/BusDefinitionParser.java
+++ /dev/null
@@ -1,310 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.cxf.bus.spring;
-
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.atomic.AtomicInteger;
-
-import org.w3c.dom.Element;
-
-import org.apache.cxf.Bus;
-import org.apache.cxf.common.injection.NoJSR250Annotations;
-import org.apache.cxf.common.util.StringUtils;
-import org.apache.cxf.configuration.spring.AbstractBeanDefinitionParser;
-import org.apache.cxf.configuration.spring.BusWiringType;
-import org.apache.cxf.feature.Feature;
-import org.apache.cxf.helpers.CastUtils;
-import org.apache.cxf.interceptor.AbstractBasicInterceptorProvider;
-import org.apache.cxf.interceptor.Interceptor;
-import org.apache.cxf.message.Message;
-import org.springframework.beans.PropertyValue;
-import org.springframework.beans.factory.config.BeanDefinition;
-import org.springframework.beans.factory.support.AbstractBeanDefinition;
-import org.springframework.beans.factory.support.BeanDefinitionBuilder;
-import org.springframework.beans.factory.xml.ParserContext;
-import org.springframework.context.ApplicationContext;
-import org.springframework.context.ApplicationContextAware;
-
-public class BusDefinitionParser extends AbstractBeanDefinitionParser {
- private static AtomicInteger counter = new AtomicInteger(0);
-
- public BusDefinitionParser() {
- super();
- setBeanClass(BusConfig.class);
- }
-
- @Override
- protected void doParse(Element element, ParserContext ctx, BeanDefinitionBuilder bean) {
- String bus = element.getAttribute("bus");
- if (StringUtils.isEmpty(bus)) {
- bus = element.getAttribute("name");
- if (StringUtils.isEmpty(bus)) {
- element.setAttribute("bus", bus);
- }
- }
- element.removeAttribute("name");
- if (StringUtils.isEmpty(bus)) {
- bus = "cxf";
- }
- String id = element.getAttribute("id");
- if (!StringUtils.isEmpty(id)) {
- bean.addPropertyValue("id", id);
- }
-
- super.doParse(element, ctx, bean);
-
- if (ctx.getRegistry().containsBeanDefinition(bus)) {
- BeanDefinition def = ctx.getRegistry().getBeanDefinition(bus);
- copyProps(bean, def);
- bean.addConstructorArgValue(bus);
- } else if (!"cxf".equals(bus)) {
- bean.getRawBeanDefinition().setBeanClass(SpringBus.class);
- bean.setDestroyMethodName("shutdown");
- try {
- element.setUserData("ID", bus, null);
- bean.getRawBeanDefinition().getPropertyValues().removePropertyValue("bus");
- } catch (Throwable t) {
- //likely not DOM level 3, ignore
- }
- } else {
- addBusWiringAttribute(bean, BusWiringType.PROPERTY, bus, ctx);
- bean.getRawBeanDefinition().setAttribute(WIRE_BUS_CREATE,
- resolveId(element, null, ctx));
- bean.addConstructorArgValue(bus);
- }
- }
-
- @Override
- protected boolean processBusAttribute(Element element, ParserContext ctx,
- BeanDefinitionBuilder bean,
- String val) {
- return false;
- }
-
- private void copyProps(BeanDefinitionBuilder src, BeanDefinition def) {
- for (PropertyValue v : src.getBeanDefinition().getPropertyValues().getPropertyValues()) {
- if (!"bus".equals(v.getName())) {
- def.getPropertyValues().addPropertyValue(v.getName(), v.getValue());
- }
- src.getBeanDefinition().getPropertyValues().removePropertyValue(v);
- }
-
- }
-
- @Override
- protected void mapElement(ParserContext ctx,
- BeanDefinitionBuilder bean,
- Element e,
- String name) {
- if ("inInterceptors".equals(name) || "inFaultInterceptors".equals(name)
- || "outInterceptors".equals(name) || "outFaultInterceptors".equals(name)
- || "features".equals(name)) {
- List<?> list = ctx.getDelegate().parseListElement(e, bean.getBeanDefinition());
- bean.addPropertyValue(name, list);
- } else if ("properties".equals(name)) {
- Map<?, ?> map = ctx.getDelegate().parseMapElement(e, bean.getBeanDefinition());
- bean.addPropertyValue("properties", map);
- }
- }
- @Override
- protected String resolveId(Element element, AbstractBeanDefinition definition,
- ParserContext ctx) {
- String bus = null;
- try {
- bus = (String)element.getUserData("ID");
- } catch (Throwable t) {
- //ignore
- }
- if (bus == null) {
- bus = element.getAttribute("bus");
- if (StringUtils.isEmpty(bus)) {
- bus = element.getAttribute("name");
- }
- if (StringUtils.isEmpty(bus)) {
- bus = Bus.DEFAULT_BUS_ID + ".config" + counter.getAndIncrement();
- } else {
- bus = bus + ".config";
- }
- try {
- element.setUserData("ID", bus, null);
- } catch (Throwable t) {
- //maybe no DOM level 3, ignore, but, may have issues with the counter
- }
- }
- return bus;
- }
-
- @NoJSR250Annotations
- public static class BusConfig extends AbstractBasicInterceptorProvider
- implements ApplicationContextAware {
-
- Bus bus;
- String busName;
- String id;
- Collection<Feature> features;
- Map<String, Object> properties;
-
- public BusConfig(String busName) {
- this.busName = busName;
- }
-
- public void setBus(Bus bb) {
- if (bus == bb) {
- return;
- }
- if (properties != null) {
- bb.setProperties(properties);
- properties = null;
- }
- if (!getInInterceptors().isEmpty()) {
- bb.getInInterceptors().addAll(getInInterceptors());
- }
- if (!getOutInterceptors().isEmpty()) {
- bb.getOutInterceptors().addAll(getOutInterceptors());
- }
- if (!getInFaultInterceptors().isEmpty()) {
- bb.getInFaultInterceptors().addAll(getInFaultInterceptors());
- }
- if (!getOutFaultInterceptors().isEmpty()) {
- bb.getOutFaultInterceptors().addAll(getOutFaultInterceptors());
- }
- if (!StringUtils.isEmpty(id)) {
- bb.setId(id);
- }
- if (features != null) {
- bb.setFeatures(features);
- features = null;
- }
- bus = bb;
- }
-
- public void setApplicationContext(ApplicationContext applicationContext) {
- if (bus != null) {
- return;
- }
- }
-
- @Override
- public List<Interceptor<? extends Message>> getOutFaultInterceptors() {
- if (bus != null) {
- return bus.getOutFaultInterceptors();
- }
- return super.getOutFaultInterceptors();
- }
-
- @Override
- public List<Interceptor<? extends Message>> getInFaultInterceptors() {
- if (bus != null) {
- return bus.getInFaultInterceptors();
- }
- return super.getInFaultInterceptors();
- }
-
- @Override
- public List<Interceptor<? extends Message>> getInInterceptors() {
- if (bus != null) {
- return bus.getInInterceptors();
- }
- return super.getInInterceptors();
- }
-
- @Override
- public List<Interceptor<? extends Message>> getOutInterceptors() {
- if (bus != null) {
- return bus.getOutInterceptors();
- }
- return super.getOutInterceptors();
- }
-
- @Override
- public void setInInterceptors(List<Interceptor<? extends Message>> interceptors) {
- if (bus != null) {
- bus.getInInterceptors().addAll(interceptors);
- } else {
- super.setInInterceptors(interceptors);
- }
- }
-
- @Override
- public void setInFaultInterceptors(List<Interceptor<? extends Message>> interceptors) {
- if (bus != null) {
- bus.getInFaultInterceptors().addAll(interceptors);
- } else {
- super.setInFaultInterceptors(interceptors);
- }
- }
-
- @Override
- public void setOutInterceptors(List<Interceptor<? extends Message>> interceptors) {
- if (bus != null) {
- bus.getOutInterceptors().addAll(interceptors);
- } else {
- super.setOutInterceptors(interceptors);
- }
- }
-
- @Override
- public void setOutFaultInterceptors(List<Interceptor<? extends Message>> interceptors) {
- if (bus != null) {
- bus.getOutFaultInterceptors().addAll(interceptors);
- } else {
- super.setOutFaultInterceptors(interceptors);
- }
- }
-
- public Collection<Feature> getFeatures() {
- if (bus != null) {
- return bus.getFeatures();
- }
- return features;
- }
-
- public void setFeatures(Collection<? extends Feature> features) {
- if (bus != null) {
- bus.setFeatures(features);
- } else {
- this.features = CastUtils.cast(features);
- }
-
- }
-
- public Map<String, Object> getProperties() {
- if (bus != null) {
- return bus.getProperties();
- }
- return properties;
- }
- public void setProperties(Map<String, Object> s) {
- if (bus != null) {
- bus.setProperties(s);
- } else {
- this.properties = s;
- }
- }
-
- public void setId(String s) {
- id = s;
- }
-
-
- }
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/bus/spring/BusEntityResolver.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/bus/spring/BusEntityResolver.java
deleted file mode 100644
index 1e95e28..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/bus/spring/BusEntityResolver.java
+++ /dev/null
@@ -1,94 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.cxf.bus.spring;
-
-import java.io.IOException;
-import java.util.Map;
-import java.util.Properties;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import org.xml.sax.EntityResolver;
-import org.xml.sax.InputSource;
-import org.xml.sax.SAXException;
-
-import org.apache.cxf.common.logging.LogUtils;
-import org.springframework.beans.factory.xml.DelegatingEntityResolver;
-import org.springframework.core.io.ClassPathResource;
-import org.springframework.core.io.Resource;
-import org.springframework.core.io.support.PropertiesLoaderUtils;
-import org.springframework.util.CollectionUtils;
-
-/**
- *
- */
-public class BusEntityResolver extends DelegatingEntityResolver {
-
- private static final Logger LOG = LogUtils.getL7dLogger(BusEntityResolver.class);
-
- private EntityResolver dtdResolver;
- private EntityResolver schemaResolver;
- private Map<String, String> schemaMappings;
- private ClassLoader classLoader;
-
- public BusEntityResolver(ClassLoader loader, EntityResolver dr, EntityResolver sr) {
- super(dr, sr);
- classLoader = loader;
- dtdResolver = dr;
- schemaResolver = sr;
-
- try {
- Properties mappings = PropertiesLoaderUtils.loadAllProperties("META-INF/spring.schemas",
- classLoader);
- schemaMappings = new ConcurrentHashMap<>(mappings.size());
- CollectionUtils.mergePropertiesIntoMap(mappings, schemaMappings);
- } catch (IOException e) {
- //ignore
- }
- }
-
- @Override
- public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException {
- InputSource source = super.resolveEntity(publicId, systemId);
- if (null == source && null != systemId) {
- // try the schema and dtd resolver in turn, ignoring the suffix in publicId
- LOG.log(Level.FINE, "Attempting to resolve systemId {0}", systemId);
- source = schemaResolver.resolveEntity(publicId, systemId);
- if (null == source) {
- source = dtdResolver.resolveEntity(publicId, systemId);
- }
- }
-
- if (null == source) {
- return null;
- }
-
- String resourceLocation = schemaMappings.get(systemId);
- if (resourceLocation != null && publicId == null) {
- Resource resource = new ClassPathResource(resourceLocation, classLoader);
- if (resource.exists()) {
- source.setPublicId(systemId);
- source.setSystemId(resource.getURL().toString());
- }
- }
- return source;
- }
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/bus/spring/BusExtensionPostProcessor.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/bus/spring/BusExtensionPostProcessor.java
deleted file mode 100644
index 9389be6..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/bus/spring/BusExtensionPostProcessor.java
+++ /dev/null
@@ -1,71 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.cxf.bus.spring;
-
-import org.apache.cxf.Bus;
-import org.apache.cxf.common.injection.NoJSR250Annotations;
-import org.apache.cxf.extension.BusExtension;
-import org.springframework.beans.factory.config.BeanPostProcessor;
-import org.springframework.context.ApplicationContext;
-import org.springframework.context.ApplicationContextAware;
-import org.springframework.core.Ordered;
-
-@NoJSR250Annotations
-public class BusExtensionPostProcessor implements BeanPostProcessor, ApplicationContextAware, Ordered {
-
- private Bus bus;
- private ApplicationContext context;
-
- public void setApplicationContext(ApplicationContext ctx) {
- context = ctx;
- }
-
- public int getOrder() {
- return 1001;
- }
-
-
- @Override
- public Object postProcessAfterInitialization(Object bean, String beanId) {
- return bean;
- }
-
- @Override
- public Object postProcessBeforeInitialization(Object bean, String beanId) {
- if (bean instanceof BusExtension && null != getBus()) {
- Class<? extends Object> cls = ((BusExtension)bean).getRegistrationType();
- registerExt(bean, cls);
- } else if (bean instanceof Bus && Bus.DEFAULT_BUS_ID.equals(beanId)) {
- bus = (Bus)bean;
- }
- return bean;
- }
- private <T> void registerExt(Object bean, Class<T> cls) {
- getBus().setExtension(cls.cast(bean), cls);
- }
-
- private Bus getBus() {
- if (bus == null) {
- bus = (Bus)context.getBean(Bus.DEFAULT_BUS_ID);
- }
- return bus;
- }
-
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/bus/spring/Jsr250BeanPostProcessor.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/bus/spring/Jsr250BeanPostProcessor.java
deleted file mode 100644
index 1fb0746..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/bus/spring/Jsr250BeanPostProcessor.java
+++ /dev/null
@@ -1,164 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.cxf.bus.spring;
-
-
-
-import org.apache.cxf.Bus;
-import org.apache.cxf.common.injection.ResourceInjector;
-import org.apache.cxf.resource.ResourceManager;
-import org.springframework.beans.factory.NoSuchBeanDefinitionException;
-import org.springframework.beans.factory.config.DestructionAwareBeanPostProcessor;
-import org.springframework.context.ApplicationContext;
-import org.springframework.context.ApplicationContextAware;
-import org.springframework.core.Ordered;
-
-public class Jsr250BeanPostProcessor
- implements DestructionAwareBeanPostProcessor, Ordered, ApplicationContextAware {
-
- private ResourceManager resourceManager;
- private ApplicationContext context;
-
- private boolean isProcessing = true;
- //private int count;
- //private int count2;
-
- Jsr250BeanPostProcessor() {
- }
-
- public void setApplicationContext(ApplicationContext applicationContext) {
- context = applicationContext;
- try {
- Class<?> cls = Class
- .forName("org.springframework.context.annotation.CommonAnnotationBeanPostProcessor");
- isProcessing = context.getBeanNamesForType(cls, true, false).length == 0;
- } catch (ClassNotFoundException e) {
- isProcessing = true;
- }
- }
-
- public int getOrder() {
- return 1010;
- }
-
- private boolean injectable(Object bean, String beanId) {
- return !"cxf".equals(beanId) && ResourceInjector.processable(bean.getClass(), bean);
- }
- private ResourceManager getResourceManager(Object bean) {
- if (resourceManager == null) {
- boolean temp = isProcessing;
- isProcessing = false;
- if (bean instanceof ResourceManager) {
- resourceManager = (ResourceManager)bean;
- resourceManager.addResourceResolver(new BusApplicationContextResourceResolver(context));
- } else if (bean instanceof Bus) {
- Bus b = (Bus)bean;
- ResourceManager m = b.getExtension(ResourceManager.class);
- if (m != null) {
- resourceManager = m;
- if (!(b instanceof SpringBus)) {
- resourceManager
- .addResourceResolver(new BusApplicationContextResourceResolver(context));
- }
- }
- } else {
- ResourceManager m = null;
- Bus b = null;
- try {
- m = (ResourceManager)context.getBean(ResourceManager.class.getName());
- } catch (NoSuchBeanDefinitionException t) {
- //ignore - no resource manager
- }
- if (m == null) {
- b = (Bus)context.getBean("cxf");
- m = b.getExtension(ResourceManager.class);
- }
- if (m != null) {
- resourceManager = m;
- if (!(b instanceof SpringBus)) {
- resourceManager
- .addResourceResolver(new BusApplicationContextResourceResolver(context));
- }
- }
- }
- isProcessing = temp;
- }
- return resourceManager;
- }
-
- @Override
- public Object postProcessAfterInitialization(Object bean, String beanId) {
- if (!isProcessing) {
- if (resourceManager == null && bean instanceof ResourceManager) {
- resourceManager = (ResourceManager)bean;
- resourceManager.addResourceResolver(new BusApplicationContextResourceResolver(context));
- }
- return bean;
- }
- if (bean != null
- && injectable(bean, beanId)) {
- new ResourceInjector(getResourceManager(bean)).construct(bean);
- }
- return bean;
- }
-
- @Override
- public Object postProcessBeforeInitialization(Object bean, String beanId) {
- if (!isProcessing) {
- return bean;
- }
- if (bean instanceof Bus) {
- getResourceManager(bean);
- }
- /*
- if (bean.getClass().getName().contains("Corb")) {
- Thread.dumpStack();
- }
- */
-
- if (bean != null
- && injectable(bean, beanId)) {
- new ResourceInjector(getResourceManager(bean)).inject(bean);
- /*
- System.out.println("p :" + (++count) + ": " + bean.getClass().getName() + " " + beanId);
- } else if (bean != null) {
- System.out.println("np: " + (++count2)
- + ": " + bean.getClass().getName() + " " + beanId);
- */
- }
- return bean;
- }
-
- public void postProcessBeforeDestruction(Object bean, String beanId) {
- if (!isProcessing) {
- return;
- }
- if (bean != null
- && injectable(bean, beanId)) {
- new ResourceInjector(getResourceManager(bean)).destroy(bean);
- }
- }
-
- @Override
- public boolean requiresDestruction(Object bean) {
- return isProcessing;
- }
-
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/bus/spring/NamespaceHandler.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/bus/spring/NamespaceHandler.java
deleted file mode 100644
index 9211ea8..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/bus/spring/NamespaceHandler.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.cxf.bus.spring;
-
-import org.w3c.dom.Element;
-
-import org.apache.cxf.configuration.spring.SimpleBeanDefinitionParser;
-import org.apache.cxf.feature.FastInfosetFeature;
-import org.apache.cxf.workqueue.AutomaticWorkQueueImpl;
-import org.springframework.beans.factory.support.BeanDefinitionBuilder;
-import org.springframework.beans.factory.xml.NamespaceHandlerSupport;
-import org.springframework.beans.factory.xml.ParserContext;
-
-public class NamespaceHandler extends NamespaceHandlerSupport {
- @SuppressWarnings("deprecation")
- public void init() {
- registerBeanDefinitionParser("bus",
- new BusDefinitionParser());
- registerBeanDefinitionParser("logging",
- new SimpleBeanDefinitionParser(org.apache.cxf.feature.LoggingFeature.class));
- registerBeanDefinitionParser("fastinfoset",
- new SimpleBeanDefinitionParser(FastInfosetFeature.class));
-
- registerBeanDefinitionParser("workqueue",
- new SimpleBeanDefinitionParser(AutomaticWorkQueueImpl.class) {
-
- @Override
- protected void processNameAttribute(Element element,
- ParserContext ctx,
- BeanDefinitionBuilder bean,
- String val) {
- bean.addPropertyValue("name", val);
- element.removeAttribute("name");
- if (!element.hasAttribute("id")) {
- element.setAttribute("id", "cxf.workqueue." + val);
- }
-
- }
- });
- }
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/bus/spring/SpringBus.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/bus/spring/SpringBus.java
deleted file mode 100644
index 6616c8e..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/bus/spring/SpringBus.java
+++ /dev/null
@@ -1,142 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.cxf.bus.spring;
-
-import org.apache.cxf.bus.extension.ExtensionManagerBus;
-import org.apache.cxf.configuration.ConfiguredBeanLocator;
-import org.apache.cxf.configuration.Configurer;
-import org.apache.cxf.configuration.spring.ConfigurerImpl;
-import org.apache.cxf.resource.ResourceManager;
-import org.springframework.context.ApplicationContext;
-import org.springframework.context.ApplicationContextAware;
-import org.springframework.context.ApplicationEvent;
-import org.springframework.context.ApplicationListener;
-import org.springframework.context.event.ContextClosedEvent;
-import org.springframework.context.event.ContextRefreshedEvent;
-import org.springframework.context.support.AbstractApplicationContext;
-
-/**
- *
- */
-public class SpringBus extends ExtensionManagerBus
- implements ApplicationContextAware {
-
- AbstractApplicationContext ctx;
- boolean closeContext;
-
- public SpringBus() {
- }
-
- public void setBusConfig(BusDefinitionParser.BusConfig bc) {
- bc.setBus(this);
- }
-
- /** {@inheritDoc}*/
- public void setApplicationContext(ApplicationContext applicationContext) {
- ctx = (AbstractApplicationContext)applicationContext;
- @SuppressWarnings("rawtypes")
- ApplicationListener listener = new ApplicationListener() {
- public void onApplicationEvent(ApplicationEvent event) {
- SpringBus.this.onApplicationEvent(event);
- }
- };
- ctx.addApplicationListener(listener);
- ApplicationContext ac = applicationContext.getParent();
- while (ac != null) {
- if (ac instanceof AbstractApplicationContext) {
- ((AbstractApplicationContext)ac).addApplicationListener(listener);
- }
- ac = ac.getParent();
- }
-
- // set the classLoader extension with the application context classLoader
- setExtension(applicationContext.getClassLoader(), ClassLoader.class);
-
- setExtension(new ConfigurerImpl(applicationContext), Configurer.class);
-
- ResourceManager m = getExtension(ResourceManager.class);
- m.addResourceResolver(new BusApplicationContextResourceResolver(applicationContext));
-
- setExtension(applicationContext, ApplicationContext.class);
- ConfiguredBeanLocator loc = getExtension(ConfiguredBeanLocator.class);
- if (!(loc instanceof SpringBeanLocator)) {
- setExtension(new SpringBeanLocator(applicationContext, this), ConfiguredBeanLocator.class);
- }
- if (getState() != BusState.RUNNING) {
- initialize();
- }
- }
-
- public void onApplicationEvent(ApplicationEvent event) {
- if (ctx == null) {
- return;
- }
- boolean doIt = false;
- ApplicationContext ac = ctx;
- while (ac != null) {
- if (event.getSource() == ac) {
- doIt = true;
- break;
- }
- ac = ac.getParent();
- }
- if (doIt) {
- if (event instanceof ContextRefreshedEvent) {
- if (getState() != BusState.RUNNING) {
- initialize();
- }
- } else if (event instanceof ContextClosedEvent && getState() == BusState.RUNNING) {
- // The bus could be create by using SpringBusFactory.createBus("/cxf.xml");
- // Just to make sure the shutdown is called rightly
- shutdown();
- }
- }
- }
-
- @Override
- public void destroyBeans() {
- if (closeContext) {
- ctx.close();
- }
- super.destroyBeans();
- }
-
- @Override
- public String getId() {
- if (id == null) {
- try {
- Class<?> clsbc = Class.forName("org.osgi.framework.BundleContext");
- Class<?> clsb = Class.forName("org.osgi.framework.Bundle");
- Object o = getExtension(clsbc);
- Object o2 = clsbc.getMethod("getBundle").invoke(o);
- String s = (String)clsb.getMethod("getSymbolicName").invoke(o2);
- id = s + '-' + DEFAULT_BUS_ID + Integer.toString(this.hashCode());
- } catch (Throwable t) {
- id = super.getId();
- }
- }
- return id;
- }
-
- public void setCloseContext(boolean b) {
- closeContext = b;
- }
-
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/catalog/CatalogXmlSchemaURIResolver.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/catalog/CatalogXmlSchemaURIResolver.java
deleted file mode 100644
index 15a3ce2..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/catalog/CatalogXmlSchemaURIResolver.java
+++ /dev/null
@@ -1,102 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.cxf.catalog;
-
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.xml.sax.InputSource;
-
-import org.apache.cxf.Bus;
-import org.apache.cxf.helpers.IOUtils;
-import org.apache.cxf.resource.ExtendedURIResolver;
-import org.apache.cxf.transport.TransportURIResolver;
-import org.apache.ws.commons.schema.XmlSchemaException;
-import org.apache.ws.commons.schema.resolver.URIResolver;
-
-/**
- * Resolves URIs using Apache Commons Resolver API.
- */
-public class CatalogXmlSchemaURIResolver implements URIResolver {
-
- private ExtendedURIResolver resolver;
- private Bus bus;
- private Map<String, String> resolved = new HashMap<>();
-
- public CatalogXmlSchemaURIResolver(Bus bus) {
- this.resolver = new TransportURIResolver(bus);
- this.bus = bus;
- }
-
- public Map<String, String> getResolvedMap() {
- return resolved;
- }
-
- public InputSource resolveEntity(String targetNamespace, String schemaLocation, String baseUri) {
- final String resolvedSchemaLocation;
- OASISCatalogManager catalogResolver = OASISCatalogManager.getCatalogManager(bus);
- try {
- resolvedSchemaLocation = new OASISCatalogManagerHelper().resolve(catalogResolver,
- schemaLocation, baseUri);
- } catch (Exception e) {
- throw new RuntimeException("Catalog resolution failed", e);
- }
-
- final InputSource in;
- if (resolvedSchemaLocation == null) {
- in = this.resolver.resolve(schemaLocation, baseUri);
- } else {
- resolved.put(schemaLocation, resolvedSchemaLocation);
- in = this.resolver.resolve(resolvedSchemaLocation, baseUri);
- }
-
- // If we return null, a NPE is raised in SchemaBuilder.
- // If we return new InputSource(), a XmlSchemaException is raised
- // but without any nice error message. So let's just throw a nice error here.
- if (in == null) {
- throw new XmlSchemaException("Unable to locate imported document "
- + "at '" + schemaLocation + "'"
- + (baseUri == null
- ? "."
- : ", relative to '" + baseUri + "'."));
- } else if (in.getByteStream() != null
- && !(in.getByteStream() instanceof ByteArrayInputStream)) {
- //workaround bug in XmlSchema - XmlSchema is not closing the InputStreams
- //that are returned for imports. Thus, with a lot of services starting up
- //or a lot of schemas imported or similar, it's easy to run out of
- //file handles. We'll just load the file into a byte[] and return that.
- try {
- InputStream ins = IOUtils.loadIntoBAIS(in.getByteStream());
- in.setByteStream(ins);
- } catch (IOException e) {
- throw new XmlSchemaException("Unable to load imported document "
- + "at '" + schemaLocation + "'"
- + (baseUri == null
- ? "."
- : ", relative to '" + baseUri + "'."),
- e);
- }
- }
-
- return in;
- }
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/common/i18n/Exception.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/common/i18n/Exception.java
deleted file mode 100644
index fcb38ad..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/common/i18n/Exception.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.cxf.common.i18n;
-
-
-
-public class Exception extends java.lang.Exception {
-
- private static final long serialVersionUID = 1L;
-
- private final Message message;
-
- public Exception(Message msg) {
- message = msg;
- }
-
- public Exception(Message msg, Throwable t) {
- super(t);
- message = msg;
- }
-
- public Exception(Throwable cause) {
- super(cause);
- message = null;
- }
-
- public String getCode() {
- if (null != message) {
- return message.getCode();
- }
- return null;
- }
-
- @Override
- public String getMessage() {
- if (null != message) {
- return message.toString();
- }
- return null;
- }
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/common/i18n/Message.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/common/i18n/Message.java
deleted file mode 100644
index d1a65c8..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/common/i18n/Message.java
+++ /dev/null
@@ -1,91 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.cxf.common.i18n;
-
-import java.io.IOException;
-import java.io.Serializable;
-import java.text.MessageFormat;
-import java.util.MissingResourceException;
-import java.util.ResourceBundle;
-import java.util.logging.Logger;
-
-public class Message implements Serializable {
- private static final long serialVersionUID = 42L;
-
- transient String code;
- transient Object[] parameters;
- transient ResourceBundle bundle;
-
- /**
- * Constructor.
- *
- * @param key the message catalog (resource bundle) key
- * @param logger a logger with an associated resource bundle
- * @param params the message substitution parameters
- */
- public Message(String key, Logger logger, Object...params) {
- this(key, logger.getResourceBundle(), params);
- }
-
- /**
- * Constructor.
- *
- * @param key the message catalog (resource bundle) key
- * @param catalog the resource bundle
- * @param params the message substitution parameters
- */
- public Message(String key, ResourceBundle catalog, Object...params) {
- code = key;
- bundle = catalog;
- parameters = params;
- }
-
- public String toString() {
- final String fmt;
- try {
- if (null == bundle) {
- return code;
- }
- fmt = bundle.getString(code);
- } catch (MissingResourceException ex) {
- return code;
- }
- return MessageFormat.format(fmt, parameters);
- }
-
- public String getCode() {
- return code;
- }
-
- public Object[] getParameters() {
- return parameters;
- }
-
- private void writeObject(java.io.ObjectOutputStream out)
- throws IOException {
- out.writeUTF(toString());
- }
- private void readObject(java.io.ObjectInputStream in)
- throws IOException, ClassNotFoundException {
- code = in.readUTF();
- bundle = null;
- parameters = null;
- }
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/common/i18n/UncheckedException.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/common/i18n/UncheckedException.java
deleted file mode 100644
index ea15fd7..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/common/i18n/UncheckedException.java
+++ /dev/null
@@ -1,84 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.cxf.common.i18n;
-
-import java.util.ResourceBundle;
-import java.util.logging.Logger;
-
-
-
-public class UncheckedException extends java.lang.RuntimeException {
-
- private static final long serialVersionUID = 1L;
-
- protected final Message message;
-
- public UncheckedException(Message msg) {
- message = msg;
- }
-
- public UncheckedException(Message msg, Throwable t) {
- super(t);
- message = msg;
- }
-
- public UncheckedException(Throwable cause) {
- super(cause);
- message = null;
- }
-
- public UncheckedException(Logger log, String msg, Object ... params) {
- message = new org.apache.cxf.common.i18n.Message(msg,
- log,
- params);
- }
- public UncheckedException(ResourceBundle bundle, String msg, Object ... params) {
- message = new org.apache.cxf.common.i18n.Message(msg,
- bundle,
- params);
- }
- public UncheckedException(Logger log, String msg, Throwable t, Object ... params) {
- super(t);
- message = new org.apache.cxf.common.i18n.Message(msg,
- log,
- params);
- }
- public UncheckedException(ResourceBundle bundle, String msg, Throwable t, Object ... params) {
- super(t);
- message = new org.apache.cxf.common.i18n.Message(msg,
- bundle,
- params);
- }
-
- public String getCode() {
- if (null != message) {
- return message.getCode();
- }
- return null;
- }
-
- @Override
- public String getMessage() {
- if (null != message) {
- return message.toString();
- }
- return null;
- }
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/common/injection/ResourceInjector.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/common/injection/ResourceInjector.java
deleted file mode 100644
index 9c420ce7..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/common/injection/ResourceInjector.java
+++ /dev/null
@@ -1,446 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.cxf.common.injection;
-
-
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Field;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import javax.annotation.PostConstruct;
-import javax.annotation.PreDestroy;
-import javax.annotation.Resource;
-import javax.annotation.Resources;
-
-
-import org.apache.cxf.common.annotation.AbstractAnnotationVisitor;
-import org.apache.cxf.common.annotation.AnnotationProcessor;
-import org.apache.cxf.common.logging.LogUtils;
-import org.apache.cxf.common.util.ClassHelper;
-import org.apache.cxf.common.util.ReflectionUtil;
-import org.apache.cxf.common.util.StringUtils;
-import org.apache.cxf.resource.ResourceManager;
-import org.apache.cxf.resource.ResourceResolver;
-
-
-/**
- * injects references specified using @Resource annotation
- *
- */
-public class ResourceInjector extends AbstractAnnotationVisitor {
-
- private static final Logger LOG = LogUtils.getL7dLogger(ResourceInjector.class);
- private static final List<Class<? extends Annotation>> ANNOTATIONS = new ArrayList<>();
-
- static {
- ANNOTATIONS.add(Resource.class);
- ANNOTATIONS.add(Resources.class);
- }
-
-
- private final ResourceManager resourceManager;
- private final List<ResourceResolver> resourceResolvers;
-
- public ResourceInjector(ResourceManager resMgr) {
- this(resMgr, resMgr == null ? null : resMgr.getResourceResolvers());
- }
-
- public ResourceInjector(ResourceManager resMgr, List<ResourceResolver> resolvers) {
- super(ANNOTATIONS);
- resourceManager = resMgr;
- resourceResolvers = resolvers;
- }
-
- private static Field getField(Class<?> cls, String name) {
- if (cls == null) {
- return null;
- }
- try {
- Field f = ReflectionUtil.getDeclaredField(cls, name);
- if (f == null) {
- f = getField(cls.getSuperclass(), name);
- }
- return f;
- } catch (Exception ex) {
- return getField(cls.getSuperclass(), name);
- }
- }
-
- public static boolean processable(Class<?> cls, Object o) {
- if (cls.getName().startsWith("java.")
- || cls.getName().startsWith("javax.")) {
- return false;
- }
- NoJSR250Annotations njsr = cls.getAnnotation(NoJSR250Annotations.class);
- if (njsr != null) {
- for (String s : njsr.unlessNull()) {
- try {
- Field f = getField(cls, s);
- ReflectionUtil.setAccessible(f);
- if (f.get(o) == null) {
- return true;
- }
- } catch (Exception ex) {
- return true;
- }
- }
- return false;
- }
- return true;
- }
-
- public void inject(Object o) {
- inject(o, o.getClass());
- }
-
- public void inject(Object o, Class<?> claz) {
- if (processable(claz, o)) {
- AnnotationProcessor processor = new AnnotationProcessor(o);
- processor.accept(this, claz);
- }
- }
-
- public void construct(Object o) {
- setTarget(o);
- if (processable(targetClass, o)) {
- invokePostConstruct();
- }
- }
- public void construct(Object o, Class<?> cls) {
- setTarget(o, cls);
- if (processable(targetClass, o)) {
- invokePostConstruct();
- }
- }
-
-
- public void destroy(Object o) {
- setTarget(o);
- if (processable(targetClass, o)) {
- invokePreDestroy();
- }
- }
-
-
- // Implementation of org.apache.cxf.common.annotation.AnnotationVisitor
-
- @Override
- public final void visitClass(final Class<?> clz, final Annotation annotation) { //NOPMD
-
- assert annotation instanceof Resource || annotation instanceof Resources : annotation;
-
- if (annotation instanceof Resource) {
- injectResourceClassLevel((Resource)annotation);
- } else if (annotation instanceof Resources) {
- Resources resources = (Resources)annotation;
- for (Resource resource : resources.value()) {
- injectResourceClassLevel(resource);
- }
- }
-
- }
-
- private void injectResourceClassLevel(Resource res) {
- if (res.name() == null || "".equals(res.name())) {
- LOG.log(Level.INFO, "RESOURCE_NAME_NOT_SPECIFIED", target.getClass().getName());
- return;
- }
-
- Object resource;
- // first find a setter that matches this resource
- Method setter = findSetterForResource(res);
- if (setter != null) {
- Class<?> type = getResourceType(res, setter);
- resource = resolveResource(res.name(), type);
- if (resource == null) {
- LOG.log(Level.INFO, "RESOURCE_RESOLVE_FAILED");
- return;
- }
-
- invokeSetter(setter, resource);
- return;
- }
-
- Field field = findFieldForResource(res);
- if (field != null) {
- Class<?> type = getResourceType(res, field);
- resource = resolveResource(res.name(), type);
- if (resource == null) {
- LOG.log(Level.INFO, "RESOURCE_RESOLVE_FAILED");
- return;
- }
- injectField(field, resource);
- return;
- }
- LOG.log(Level.SEVERE, "NO_SETTER_OR_FIELD_FOR_RESOURCE", getTarget().getClass().getName());
- }
-
- public final void visitField(final Field field, final Annotation annotation) {
-
- assert annotation instanceof Resource : annotation;
-
- Resource res = (Resource)annotation;
-
- String name = getFieldNameForResource(res, field);
- Class<?> type = getResourceType(res, field);
-
- Object resource = resolveResource(name, type);
- if (resource == null
- && "".equals(res.name())) {
- resource = resolveResource(null, type);
- }
- if (resource != null) {
- injectField(field, resource);
- } else {
- LOG.log(Level.INFO, "RESOURCE_RESOLVE_FAILED", name);
- }
- }
-
- public final void visitMethod(final Method method, final Annotation annotation) {
-
- assert annotation instanceof Resource : annotation;
-
- Resource res = (Resource)annotation;
-
- String resourceName = getResourceName(res, method);
- Class<?> clz = getResourceType(res, method);
-
- Object resource = resolveResource(resourceName, clz);
- if (resource == null
- && "".equals(res.name())) {
- resource = resolveResource(null, clz);
- }
- if (resource != null) {
- invokeSetter(method, resource);
- } else {
- LOG.log(Level.FINE, "RESOURCE_RESOLVE_FAILED", new Object[] {resourceName, clz});
- }
- }
-
- private Field findFieldForResource(Resource res) {
- assert target != null;
- assert res.name() != null;
-
- for (Field field : target.getClass().getFields()) {
- if (field.getName().equals(res.name())) {
- return field;
- }
- }
-
- for (Field field : target.getClass().getDeclaredFields()) {
- if (field.getName().equals(res.name())) {
- return field;
- }
- }
- return null;
- }
-
-
- private Method findSetterForResource(Resource res) {
- assert target != null;
-
- String setterName = resourceNameToSetter(res.name());
- Method setterMethod = null;
-
- for (Method method : getTarget().getClass().getMethods()) {
- if (setterName.equals(method.getName())) {
- setterMethod = method;
- break;
- }
- }
-
- if (setterMethod != null && setterMethod.getParameterTypes().length != 1) {
- LOG.log(Level.WARNING, "SETTER_INJECTION_WITH_INCORRECT_TYPE", setterMethod);
- }
- return setterMethod;
- }
-
- private static String resourceNameToSetter(String resName) {
- return "set" + StringUtils.capitalize(resName);
- }
-
- private void invokeSetter(Method method, Object resource) {
- try {
- ReflectionUtil.setAccessible(method);
- if (method.getDeclaringClass().isAssignableFrom(getTarget().getClass())) {
- method.invoke(getTarget(), resource);
- } else { // deal with the proxy setter method
- Method targetMethod = getTarget().getClass().getMethod(method.getName(),
- method.getParameterTypes());
- targetMethod.invoke(getTarget(), resource);
- }
- } catch (IllegalAccessException e) {
- LOG.log(Level.SEVERE, "INJECTION_SETTER_NOT_VISIBLE", method);
- } catch (InvocationTargetException | SecurityException e) {
- LogUtils.log(LOG, Level.SEVERE, "INJECTION_SETTER_RAISED_EXCEPTION", e, method);
- } catch (NoSuchMethodException e) {
- LOG.log(Level.SEVERE, "INJECTION_SETTER_METHOD_NOT_FOUND", new Object[] {method.getName()});
- }
- }
-
- private String getResourceName(Resource res, Method method) {
- assert method != null;
- assert res != null;
- assert method.getName().startsWith("set") : method;
-
- if (res.name() == null || res.name().isEmpty()) {
- String name = method.getName().substring(3);
- name = Character.toLowerCase(name.charAt(0)) + name.substring(1);
- return method.getDeclaringClass().getCanonicalName() + '/' + name;
- }
- return res.name();
- }
-
-
-
- private void injectField(Field field, Object resource) {
- assert field != null;
- assert resource != null;
-
- boolean accessible = field.isAccessible();
- try {
- if (field.getType().isAssignableFrom(resource.getClass())) {
- ReflectionUtil.setAccessible(field);
- field.set(ClassHelper.getRealObject(getTarget()), resource);
- }
- } catch (IllegalAccessException e) {
- e.printStackTrace();
- LOG.severe("FAILED_TO_INJECT_FIELD");
- } finally {
- ReflectionUtil.setAccessible(field, accessible);
- }
- }
-
-
- public void invokePostConstruct() {
-
- boolean accessible = false;
- for (Method method : getPostConstructMethods()) {
- PostConstruct pc = method.getAnnotation(PostConstruct.class);
- if (pc != null) {
- try {
- ReflectionUtil.setAccessible(method);
- method.invoke(target);
- } catch (IllegalAccessException e) {
- LOG.log(Level.WARNING, "INJECTION_COMPLETE_NOT_VISIBLE", method);
- } catch (InvocationTargetException e) {
- LOG.log(Level.WARNING, "INJECTION_COMPLETE_THREW_EXCEPTION", e);
- } finally {
- ReflectionUtil.setAccessible(method, accessible);
- }
- }
- }
- }
-
- public void invokePreDestroy() {
-
- boolean accessible = false;
- for (Method method : getPreDestroyMethods()) {
- PreDestroy pd = method.getAnnotation(PreDestroy.class);
- if (pd != null) {
- try {
- ReflectionUtil.setAccessible(method);
- method.invoke(target);
- } catch (IllegalAccessException e) {
- LOG.log(Level.WARNING, "PRE_DESTROY_NOT_VISIBLE", method);
- } catch (InvocationTargetException e) {
- LOG.log(Level.WARNING, "PRE_DESTROY_THREW_EXCEPTION", e);
- } finally {
- ReflectionUtil.setAccessible(method, accessible);
- }
- }
- }
- }
-
-
- private Collection<Method> getPostConstructMethods() {
- return getAnnotatedMethods(PostConstruct.class);
- }
-
- private Collection<Method> getPreDestroyMethods() {
- return getAnnotatedMethods(PreDestroy.class);
- }
-
- private Collection<Method> getAnnotatedMethods(Class<? extends Annotation> acls) {
-
- Collection<Method> methods = new LinkedList<>();
- addAnnotatedMethods(acls, getTarget().getClass().getMethods(), methods);
- addAnnotatedMethods(acls, ReflectionUtil.getDeclaredMethods(getTarget().getClass()), methods);
- if (getTargetClass() != getTarget().getClass()) {
- addAnnotatedMethods(acls, getTargetClass().getMethods(), methods);
- addAnnotatedMethods(acls, ReflectionUtil.getDeclaredMethods(getTargetClass()), methods);
- }
- return methods;
- }
-
- private void addAnnotatedMethods(Class<? extends Annotation> acls, Method[] methods,
- Collection<Method> annotatedMethods) {
- for (Method method : methods) {
- if (method.getAnnotation(acls) != null
- && !annotatedMethods.contains(method)) {
- annotatedMethods.add(method);
- }
- }
- }
-
-
- /**
- * making this protected to keep pmd happy
- */
- protected Class<?> getResourceType(Resource res, Field field) {
- assert res != null;
- Class<?> type = res.type();
- if (res.type() == null || Object.class == res.type()) {
- type = field.getType();
- }
- return type;
- }
-
-
- private Class<?> getResourceType(Resource res, Method method) {
- return res.type() != null && !Object.class.equals(res.type())
- ? res.type()
- : method.getParameterTypes()[0];
- }
-
-
- private String getFieldNameForResource(Resource res, Field field) {
- assert res != null;
- if (res.name() == null || "".equals(res.name())) {
- return field.getDeclaringClass().getCanonicalName() + "/" + field.getName();
- }
- return res.name();
- }
-
- private Object resolveResource(String resourceName, Class<?> type) {
- if (resourceManager == null) {
- return null;
- }
- return resourceManager.resolveResource(resourceName, type, resourceResolvers);
- }
-
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/common/jaxb/JAXBUtils.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/common/jaxb/JAXBUtils.java
deleted file mode 100644
index f018e2a..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/common/jaxb/JAXBUtils.java
+++ /dev/null
@@ -1,1180 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.cxf.common.jaxb;
-
-
-import java.io.BufferedReader;
-import java.io.Closeable;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.lang.annotation.Annotation;
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Target;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.Method;
-import java.lang.reflect.Proxy;
-import java.lang.reflect.Type;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.net.URL;
-import java.net.URLClassLoader;
-import java.nio.charset.StandardCharsets;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Optional;
-import java.util.Set;
-import java.util.StringTokenizer;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import javax.xml.bind.JAXBContext;
-import javax.xml.bind.JAXBElement;
-import javax.xml.bind.JAXBException;
-import javax.xml.bind.Marshaller;
-import javax.xml.bind.PropertyException;
-import javax.xml.bind.SchemaOutputResolver;
-import javax.xml.bind.Unmarshaller;
-import javax.xml.bind.annotation.XmlElement;
-import javax.xml.bind.attachment.AttachmentMarshaller;
-import javax.xml.bind.attachment.AttachmentUnmarshaller;
-import javax.xml.namespace.QName;
-import javax.xml.stream.XMLStreamReader;
-import javax.xml.stream.XMLStreamWriter;
-import javax.xml.transform.Result;
-import javax.xml.transform.Source;
-import javax.xml.transform.dom.DOMResult;
-import javax.xml.transform.stream.StreamResult;
-
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-
-import org.xml.sax.EntityResolver;
-import org.xml.sax.InputSource;
-
-import org.apache.cxf.Bus;
-import org.apache.cxf.common.classloader.ClassLoaderUtils;
-import org.apache.cxf.common.logging.LogUtils;
-import org.apache.cxf.common.spi.ClassLoaderService;
-import org.apache.cxf.common.util.CachedClass;
-import org.apache.cxf.common.util.PackageUtils;
-import org.apache.cxf.common.util.ProxyHelper;
-import org.apache.cxf.common.util.ReflectionInvokationHandler;
-import org.apache.cxf.common.util.ReflectionInvokationHandler.WrapReturn;
-import org.apache.cxf.common.util.ReflectionUtil;
-import org.apache.cxf.common.util.StringUtils;
-import org.apache.cxf.common.util.SystemPropertyAction;
-import org.apache.cxf.common.xmlschema.SchemaCollection;
-import org.apache.cxf.helpers.JavaUtils;
-
-public final class JAXBUtils {
- public static final String JAXB_URI = "http://java.sun.com/xml/ns/jaxb";
-
- private static final Logger LOG = LogUtils.getL7dLogger(JAXBUtils.class);
-
- public enum IdentifierType {
- CLASS,
- INTERFACE,
- GETTER,
- SETTER,
- VARIABLE,
- CONSTANT
- };
-
- private static final char[] XML_NAME_PUNCTUATION_CHARS = new char[] {
- /* hyphen */ '\u002D',
- /* period */ '\u002E',
- /* colon */'\u003A',
- /* dot */ '\u00B7',
- /* greek ano teleia */ '\u0387',
- /* arabic end of ayah */ '\u06DD',
- /* arabic start of rub el hizb */'\u06DE',
- /* underscore */ '\u005F',
- };
-
- private static final String XML_NAME_PUNCTUATION_STRING = new String(XML_NAME_PUNCTUATION_CHARS);
-
- private static final Map<String, String> BUILTIN_DATATYPES_MAP;
- private static final Map<String, Class<?>> HOLDER_TYPES_MAP;
- private static ClassLoader jaxbXjcLoader;
- private static volatile Optional<Object> jaxbMinimumEscapeHandler;
- private static volatile Optional<Object> jaxbNoEscapeHandler;
-
- static {
- BUILTIN_DATATYPES_MAP = new HashMap<>();
- BUILTIN_DATATYPES_MAP.put("string", "java.lang.String");
- BUILTIN_DATATYPES_MAP.put("integer", "java.math.BigInteger");
- BUILTIN_DATATYPES_MAP.put("int", "int");
- BUILTIN_DATATYPES_MAP.put("long", "long");
- BUILTIN_DATATYPES_MAP.put("short", "short");
- BUILTIN_DATATYPES_MAP.put("decimal", "java.math.BigDecimal");
- BUILTIN_DATATYPES_MAP.put("float", "float");
- BUILTIN_DATATYPES_MAP.put("double", "double");
- BUILTIN_DATATYPES_MAP.put("boolean", "boolean");
- BUILTIN_DATATYPES_MAP.put("byte", "byte");
- BUILTIN_DATATYPES_MAP.put("QName", "javax.xml.namespace.QName");
- BUILTIN_DATATYPES_MAP.put("dateTime", "javax.xml.datatype.XMLGregorianCalendar");
- BUILTIN_DATATYPES_MAP.put("base64Binary", "byte[]");
- BUILTIN_DATATYPES_MAP.put("hexBinary", "byte[]");
- BUILTIN_DATATYPES_MAP.put("unsignedInt", "long");
- BUILTIN_DATATYPES_MAP.put("unsignedShort", "short");
- BUILTIN_DATATYPES_MAP.put("unsignedByte", "byte");
- BUILTIN_DATATYPES_MAP.put("time", "javax.xml.datatype.XMLGregorianCalendar");
- BUILTIN_DATATYPES_MAP.put("date", "javax.xml.datatype.XMLGregorianCalendar");
- BUILTIN_DATATYPES_MAP.put("gYear", "javax.xml.datatype.XMLGregorianCalendar");
- BUILTIN_DATATYPES_MAP.put("gYearMonth", "javax.xml.datatype.XMLGregorianCalendar");
- BUILTIN_DATATYPES_MAP.put("gMonth", "javax.xml.datatype.XMLGregorianCalendar");
- BUILTIN_DATATYPES_MAP.put("gMonthDay", "javax.xml.datatype.XMLGregorianCalendar");
- BUILTIN_DATATYPES_MAP.put("gDay", "javax.xml.datatype.XMLGregorianCalendar");
- BUILTIN_DATATYPES_MAP.put("duration", "javax.xml.datatype.Duration");
- BUILTIN_DATATYPES_MAP.put("NOTATION", "javax.xml.namespace.QName");
-
- HOLDER_TYPES_MAP = new HashMap<>();
- HOLDER_TYPES_MAP.put("int", java.lang.Integer.class);
- HOLDER_TYPES_MAP.put("long", java.lang.Long.class);
- HOLDER_TYPES_MAP.put("short", java.lang.Short.class);
- HOLDER_TYPES_MAP.put("float", java.lang.Float.class);
- HOLDER_TYPES_MAP.put("double", java.lang.Double.class);
- HOLDER_TYPES_MAP.put("boolean", java.lang.Boolean.class);
- HOLDER_TYPES_MAP.put("byte", java.lang.Byte.class);
- }
-
-
- /**
- * prevents instantiation
- *
- */
- private JAXBUtils() {
- }
-
- public static void closeUnmarshaller(Unmarshaller u) {
- if (u instanceof Closeable) {
- //need to do this to clear the ThreadLocal cache
- //see https://java.net/jira/browse/JAXB-1000
-
- try {
- ((Closeable)u).close();
- } catch (IOException e) {
- //ignore
- }
- }
- }
- public static Object unmarshall(JAXBContext c, Element e) throws JAXBException {
- Unmarshaller u = c.createUnmarshaller();
- try {
- u.setEventHandler(null);
- return u.unmarshal(e);
- } finally {
- closeUnmarshaller(u);
- }
- }
- public static <T> JAXBElement<T> unmarshall(JAXBContext c, Element e, Class<T> cls) throws JAXBException {
- Unmarshaller u = c.createUnmarshaller();
- try {
- u.setEventHandler(null);
- return u.unmarshal(e, cls);
- } finally {
- closeUnmarshaller(u);
- }
- }
- public static Object unmarshall(JAXBContext c, Source s) throws JAXBException {
- Unmarshaller u = c.createUnmarshaller();
- try {
- u.setEventHandler(null);
- return u.unmarshal(s);
- } finally {
- closeUnmarshaller(u);
- }
- }
- public static <T> JAXBElement<T> unmarshall(JAXBContext c,
- XMLStreamReader reader,
- Class<T> cls) throws JAXBException {
- Unmarshaller u = c.createUnmarshaller();
- try {
- u.setEventHandler(null);
- return u.unmarshal(reader, cls);
- } finally {
- closeUnmarshaller(u);
- }
- }
- public static Object unmarshall(JAXBContext c,
- XMLStreamReader reader) throws JAXBException {
- Unmarshaller u = c.createUnmarshaller();
- try {
- u.setEventHandler(null);
- return u.unmarshal(reader);
- } finally {
- closeUnmarshaller(u);
- }
- }
-
- public static String builtInTypeToJavaType(String type) {
- return BUILTIN_DATATYPES_MAP.get(type);
- }
-
- public static Class<?> holderClass(String type) {
- return HOLDER_TYPES_MAP.get(type);
- }
-
- /**
- * Checks if the specified word is a Java keyword (as defined in JavaUtils).
- *
- * @param word the word to check.
- * @return true if the word is a keyword.
- * @see org.apache.cxf.helpers.JavaUtils
- */
- protected static boolean isJavaKeyword(String word) {
- return JavaUtils.isJavaKeyword(word);
- }
-
- /**
- * Generates a Java package name from a URI according to the
- * algorithm outlined in JAXB 2.0.
- *
- * @param namespaceURI the namespace URI.
- * @return the package name.
- */
- public static String namespaceURIToPackage(String namespaceURI) {
- try {
- return nameSpaceURIToPackage(new URI(namespaceURI));
- } catch (URISyntaxException ex) {
- return null;
- }
- }
-
- /**
- * Generates a Java package name from a URI according to the
- * algorithm outlined in Appendix D of JAXB (2.0+).
- *
- * @param uri the namespace URI.
- * @return the package name.
- */
- public static String nameSpaceURIToPackage(URI uri) {
-
- StringBuilder packageName = new StringBuilder();
- String authority = uri.getAuthority();
- String scheme = uri.getScheme();
- if (authority == null && "urn".equals(scheme)) {
- authority = uri.getSchemeSpecificPart();
- }
-
- if (null != authority && !"".equals(authority)) {
- if ("urn".equals(scheme)) {
- packageName.append(authority);
- /* JAXB 2.2 D.5.1, Rule #5 */
- for (int i = 0; i < packageName.length(); i++) {
- if (packageName.charAt(i) == '-') {
- packageName.setCharAt(i, '.');
- }
- }
- authority = packageName.toString();
- packageName.setLength(0);
-
- StringTokenizer st = new StringTokenizer(authority, ":");
- while (st.hasMoreTokens()) {
- String token = st.nextToken();
- if (packageName.length() > 0) {
- packageName.insert(0, '.');
- packageName.insert(0, normalizePackageNamePart(token));
- } else {
- packageName.insert(0, token);
- }
- }
- authority = packageName.toString();
- packageName.setLength(0);
-
- }
-
- StringTokenizer st = new StringTokenizer(authority, ".");
- if (st.hasMoreTokens()) {
- while (st.hasMoreTokens()) {
- String token = st.nextToken();
- if (packageName.length() == 0) {
- if ("www".equals(token)) {
- continue;
- }
- } else {
- packageName.insert(0, '.');
- }
- packageName.insert(0, normalizePackageNamePart(token));
- }
- }
-
- if (!("http".equalsIgnoreCase(scheme) || "urn".equalsIgnoreCase(scheme))) {
- packageName.insert(0, '.');
- packageName.insert(0, normalizePackageNamePart(scheme));
- }
-
- }
-
- String path = uri.getPath();
- if (path == null) {
- path = "";
- }
- /* JAXB 2.2 D.5.1 Rule 2 - remove trailing .??, .???, or .html only. */
- int index = path.lastIndexOf('.');
- if (index < 0) {
- index = path.length();
- } else {
- String ending = path.substring(index + 1);
- if (ending.length() < 2 || (ending.length() > 3
- && !"html".equalsIgnoreCase(ending))) {
- index = path.length();
- }
- }
- StringTokenizer st = new StringTokenizer(path.substring(0, index), "/");
- while (st.hasMoreTokens()) {
- String token = st.nextToken();
- if (packageName.length() > 0) {
- packageName.append('.');
- }
- packageName.append(normalizePackageNamePart(token));
- }
- return packageName.toString();
- }
-
- private static String normalizePackageNamePart(String name) {
- StringBuilder sname = new StringBuilder(name.toLowerCase());
-
- for (int i = 0; i < sname.length(); i++) {
- sname.setCharAt(i, Character.toLowerCase(sname.charAt(i)));
- }
-
- for (int i = 0; i < sname.length(); i++) {
- if (!Character.isJavaIdentifierPart(sname.charAt(i))) {
- sname.setCharAt(i, '_');
- }
- }
-
- if (isJavaKeyword(sname.toString())) {
- sname.insert(0, '_');
- }
-
- if (!Character.isJavaIdentifierStart(sname.charAt(0))) {
- sname.insert(0, '_');
- }
-
- return sname.toString();
- }
-
-
- /**
- * Converts an XML name to a Java identifier according to the mapping
- * algorithm outlined in the JAXB specification
- *
- * @param name the XML name
- * @return the Java identifier
- */
- public static String nameToIdentifier(String name, IdentifierType type) {
-
- if (null == name || name.length() == 0) {
- return name;
- }
-
- // algorithm will not change an XML name that is already a legal and
- // conventional (!) Java class, method, or constant identifier
-
- StringBuilder buf = new StringBuilder(name);
- boolean hasUnderscore = false;
- boolean legalIdentifier = Character.isJavaIdentifierStart(buf.charAt(0));
-
- for (int i = 1; i < name.length() && legalIdentifier; i++) {
- legalIdentifier &= Character.isJavaIdentifierPart(buf.charAt(i));
- hasUnderscore |= '_' == buf.charAt(i);
- }
-
- boolean conventionalIdentifier = isConventionalIdentifier(buf, type);
- if (legalIdentifier && conventionalIdentifier) {
- if (JAXBUtils.isJavaKeyword(name) && type == IdentifierType.VARIABLE) {
- name = normalizePackageNamePart(name);
- }
- if (!hasUnderscore || IdentifierType.CLASS != type) {
- return name;
- }
- }
-
- // split into words
-
- List<String> words = new ArrayList<>();
-
- StringTokenizer st = new StringTokenizer(name, XML_NAME_PUNCTUATION_STRING);
- while (st.hasMoreTokens()) {
- words.add(st.nextToken());
- }
-
- for (int i = 0; i < words.size(); i++) {
- splitWord(words, i);
- }
-
- return makeConventionalIdentifier(words, type);
- }
-
- private static void splitWord(List<String> words, int listIndex) {
- String word = words.get(listIndex);
- if (word.length() <= 1) {
- return;
- }
- int index = listIndex + 1;
- StringBuilder sword = new StringBuilder(word);
- int first = 0;
- char firstChar = sword.charAt(first);
- if (Character.isLowerCase(firstChar)) {
- sword.setCharAt(first, Character.toUpperCase(firstChar));
- }
- int i = 1;
-
- while (i < sword.length()) {
- if (Character.isDigit(firstChar)) {
- while (i < sword.length() && Character.isDigit(sword.charAt(i))) {
- i++;
- }
- } else if (isCasedLetter(firstChar)) {
- boolean previousIsLower = Character.isLowerCase(firstChar);
- while (i < sword.length() && isCasedLetter(sword.charAt(i))) {
- if (Character.isUpperCase(sword.charAt(i)) && previousIsLower) {
- break;
- }
- previousIsLower = Character.isLowerCase(sword.charAt(i));
- i++;
- }
- } else {
- // first must be a mark or an uncased letter
- while (i < sword.length() && (isMark(sword.charAt(i)) || !isCasedLetter(sword.charAt(i)))) {
- i++;
- }
- }
-
- // characters from first to i are all either
- // * digits
- // * upper or lower case letters, with only the first one an upper
- // * uncased letters or marks
-
-
- String newWord = sword.substring(first, i);
- words.add(index, newWord);
- index++;
- if (i >= sword.length()) {
- break;
- }
- first = i;
- firstChar = sword.charAt(first);
- }
-
- if (index > (listIndex + 1)) {
- words.remove(listIndex);
- }
- }
-
- private static boolean isMark(char c) {
- return Character.isJavaIdentifierPart(c) && !Character.isLetter(c) && !Character.isDigit(c);
- }
-
- private static boolean isCasedLetter(char c) {
- return Character.isUpperCase(c) || Character.isLowerCase(c);
- }
-
- private static boolean isConventionalIdentifier(StringBuilder buf, IdentifierType type) {
- if (null == buf || buf.length() == 0) {
- return false;
- }
- final boolean result;
- if (IdentifierType.CONSTANT == type) {
- for (int i = 0; i < buf.length(); i++) {
- if (Character.isLowerCase(buf.charAt(i))) {
- return false;
- }
- }
- result = true;
- } else if (IdentifierType.VARIABLE == type) {
- result = Character.isLowerCase(buf.charAt(0));
- } else {
- int pos = 3;
- if (IdentifierType.GETTER == type
- && !(buf.length() >= pos
- && "get".equals(buf.subSequence(0, 3)))) {
- return false;
- } else if (IdentifierType.SETTER == type
- && !(buf.length() >= pos && "set".equals(buf.subSequence(0, 3)))) {
- return false;
- } else {
- pos = 0;
- }
- result = Character.isUpperCase(buf.charAt(pos));
- }
- return result;
- }
-
- private static String makeConventionalIdentifier(List<String> words, IdentifierType type) {
- StringBuilder buf = new StringBuilder();
- boolean firstWord = true;
- if (IdentifierType.GETTER == type) {
- buf.append("get");
- } else if (IdentifierType.SETTER == type) {
- buf.append("set");
- }
- for (String w : words) {
- int l = buf.length();
- if (l > 0 && IdentifierType.CONSTANT == type) {
- buf.append('_');
- l++;
- }
- buf.append(w);
- if (IdentifierType.CONSTANT == type) {
- for (int i = l; i < buf.length(); i++) {
- if (Character.isLowerCase(buf.charAt(i))) {
- buf.setCharAt(i, Character.toUpperCase(buf.charAt(i)));
- }
- }
- } else if (IdentifierType.VARIABLE == type) {
- if (firstWord && Character.isUpperCase(buf.charAt(l))) {
- buf.setCharAt(l, Character.toLowerCase(buf.charAt(l)));
- }
- } else {
- if (firstWord && Character.isLowerCase(buf.charAt(l))) {
- buf.setCharAt(l, Character.toUpperCase(buf.charAt(l)));
- }
- }
- firstWord = false;
- }
- return buf.toString();
- }
-
- public static Class<?> getValidClass(Class<?> cls) {
- if (cls.isEnum() || cls.isArray()) {
- return cls;
- }
-
- if (cls == Object.class || cls == String.class || cls.isPrimitive() || cls.isAnnotation()
- || "javax.xml.ws.Holder".equals(cls.getName())) {
- return null;
- } else if (cls.isInterface()
- || "javax.xml.ws.wsaddressing.W3CEndpointReference".equals(cls.getName())) {
- return cls;
- }
-
- Constructor<?> cons = ReflectionUtil.getDeclaredConstructor(cls);
- if (cons == null) {
- cons = ReflectionUtil.getConstructor(cls);
- if (cons == null) {
- return null;
- }
- }
- return cls;
- }
-
- private static synchronized ClassLoader getXJCClassLoader() {
- if (jaxbXjcLoader == null) {
- try {
- Class.forName("com.sun.tools.internal.xjc.api.XJC");
- jaxbXjcLoader = ClassLoader.getSystemClassLoader();
- } catch (Exception t2) {
- //couldn't find either, probably cause tools.jar isn't on
- //the classpath. Let's see if we can find the tools jar
- String s = SystemPropertyAction.getProperty("java.home");
- if (!StringUtils.isEmpty(s)) {
- File home = new File(s);
- File jar = new File(home, "lib/tools.jar");
- if (!jar.exists()) {
- jar = new File(home, "../lib/tools.jar");
- }
- if (jar.exists()) {
- try {
- jaxbXjcLoader = new URLClassLoader(new URL[] {jar.toURI().toURL()});
- Class.forName("com.sun.tools.internal.xjc.api.XJC", false, jaxbXjcLoader);
- } catch (Exception e) {
- jaxbXjcLoader = null;
- }
- }
- }
- }
- }
- return jaxbXjcLoader;
- }
-
- public static Object setNamespaceMapper(Bus bus, final Map<String, String> nspref,
- Marshaller marshaller) throws PropertyException {
- ClassLoaderService classLoaderService = bus.getExtension(ClassLoaderService.class);
- Object mapper = classLoaderService.createNamespaceWrapperInstance(marshaller.getClass(), nspref);
- if (mapper != null) {
- if (marshaller.getClass().getName().contains(".internal.")) {
- marshaller.setProperty("com.sun.xml.internal.bind.namespacePrefixMapper",
- mapper);
- } else if (marshaller.getClass().getName().contains("com.sun")) {
- marshaller.setProperty("com.sun.xml.bind.namespacePrefixMapper",
- mapper);
- } else if (marshaller.getClass().getName().contains("eclipse")) {
- marshaller.setProperty("eclipselink.namespace-prefix-mapper",
- mapper);
- }
- }
- return mapper;
- }
- public static BridgeWrapper createBridge(Set<Class<?>> ctxClasses,
- QName qname,
- Class<?> refcls,
- Annotation[] anns) throws JAXBException {
- try {
- Class<?> cls;
- Class<?> refClass;
- String pkg = "com.sun.xml.bind.";
- try {
- cls = Class.forName("com.sun.xml.bind.api.JAXBRIContext");
- refClass = Class.forName(pkg + "api.TypeReference");
- } catch (ClassNotFoundException e) {
- cls = Class.forName("com.sun.xml.internal.bind.api.JAXBRIContext", true, getXJCClassLoader());
- pkg = "com.sun.xml.internal.bind.";
- refClass = Class.forName(pkg + "api.TypeReference", true, getXJCClassLoader());
- }
- Object ref = refClass.getConstructor(QName.class,
- Type.class,
- anns.getClass()).newInstance(qname, refcls, anns);
- List<Object> typeRefs = new ArrayList<>();
- typeRefs.add(ref);
- List<Class<?>> clses = new ArrayList<>(ctxClasses);
- clses.add(refClass.getField("type").get(ref).getClass());
- if (!refcls.isInterface()) {
- clses.add(refcls);
- }
-
- Object ctx = null;
- for (Method m : cls.getDeclaredMethods()) {
- if ("newInstance".equals(m.getName())
- && m.getParameterTypes().length == 6) {
- ctx = m.invoke(null, clses.toArray(new Class<?>[0]),
- typeRefs, null, null, true, null);
-
- }
- }
-
- if (ctx == null) {
- throw new JAXBException("No ctx found");
- }
-
- Object bridge = ctx.getClass().getMethod("createBridge", refClass).invoke(ctx, ref);
- return ReflectionInvokationHandler.createProxyWrapper(bridge,
- BridgeWrapper.class);
- } catch (Exception ex) {
- throw new JAXBException(ex);
- }
- }
- public interface BridgeWrapper {
-
- Object unmarshal(XMLStreamReader source, AttachmentUnmarshaller am) throws JAXBException;
-
- Object unmarshal(InputStream source) throws JAXBException;
-
- Object unmarshal(Node source, AttachmentUnmarshaller am) throws JAXBException;
-
- void marshal(Object elValue, XMLStreamWriter source, AttachmentMarshaller m) throws JAXBException;
-
- void marshal(Object elValue, StreamResult s1) throws JAXBException;
-
- void marshal(Object elValue, Node source, AttachmentMarshaller am) throws JAXBException;
- }
-
-
- public static SchemaCompiler createSchemaCompiler() throws JAXBException {
- try {
- Class<?> cls;
- Object sc;
- try {
- cls = Class.forName("com.sun.tools.xjc.api.XJC");
- sc = cls.getMethod("createSchemaCompiler").invoke(null);
- } catch (Throwable e) {
- cls = Class.forName("com.sun.tools.internal.xjc.api.XJC", true, getXJCClassLoader());
- sc = cls.getMethod("createSchemaCompiler").invoke(null);
- }
-
- return ReflectionInvokationHandler.createProxyWrapper(sc,
- SchemaCompiler.class);
- } catch (Exception ex) {
- throw new JAXBException(ex);
- }
- }
-
- public static SchemaCompiler createSchemaCompilerWithDefaultAllocator(Set<String> allocatorSet) {
-
- try {
- SchemaCompiler compiler = JAXBUtils.createSchemaCompiler();
- Object allocator = ReflectionInvokationHandler
- .createProxyWrapper(new DefaultClassNameAllocator(allocatorSet),
- JAXBUtils.getParamClass(compiler, "setClassNameAllocator"));
-
- compiler.setClassNameAllocator(allocator);
- return compiler;
- } catch (JAXBException e1) {
- throw new IllegalStateException("Unable to create schema compiler", e1);
- }
-
- }
-
- public static void logGeneratedClassNames(Logger logger, JCodeModel codeModel) {
- if (!logger.isLoggable(Level.FINE)) {
- return;
- }
-
- StringBuilder sb = new StringBuilder();
- boolean first = true;
- for (Iterator<JPackage> itr = codeModel.packages(); itr.hasNext();) {
- JPackage package1 = itr.next();
-
- for (Iterator<JDefinedClass> citr = package1.classes(); citr.hasNext();) {
- if (!first) {
- sb.append(", ");
- } else {
- first = false;
- }
- sb.append(citr.next().fullName());
- }
- }
-
- logger.log(Level.FINE, "Created classes: " + sb.toString());
- }
-
- public static List<String> getGeneratedClassNames(JCodeModel codeModel) {
- List<String> classes = new ArrayList<>();
- for (Iterator<JPackage> itr = codeModel.packages(); itr.hasNext();) {
- JPackage package1 = itr.next();
-
- for (Iterator<JDefinedClass> citr = package1.classes(); citr.hasNext();) {
- classes.add(citr.next().fullName());
- }
- }
- return classes;
- }
- public static Object createFileCodeWriter(File f) throws JAXBException {
- return createFileCodeWriter(f, StandardCharsets.UTF_8.name());
- }
- public static Object createFileCodeWriter(File f, String encoding) throws JAXBException {
- try {
- Class<?> cls;
- try {
- cls = Class.forName("com.sun.codemodel.writer.FileCodeWriter");
- } catch (ClassNotFoundException e) {
- cls = Class.forName("com.sun.codemodel.internal.writer.FileCodeWriter",
- true, getXJCClassLoader());
- }
- if (encoding != null) {
- try {
- return cls.getConstructor(File.class, String.class)
- .newInstance(f, encoding);
- } catch (Exception ex) {
- // try a single argument constructor
- }
- }
- return cls.getConstructor(File.class).newInstance(f);
- } catch (Exception ex) {
- throw new JAXBException(ex);
- }
- }
-
- public static Class<?> getParamClass(SchemaCompiler sc, String method) {
- Object o = ((ReflectionInvokationHandler)Proxy.getInvocationHandler(sc)).getTarget();
- for (Method m : o.getClass().getMethods()) {
- if (m.getName().equals(method) && m.getParameterTypes().length == 1) {
- return m.getParameterTypes()[0];
- }
- }
- return null;
- }
-
-
- public static List<DOMResult> generateJaxbSchemas(
- JAXBContext context, final Map<String, DOMResult> builtIns) throws IOException {
- final List<DOMResult> results = new ArrayList<>();
-
- context.generateSchema(new SchemaOutputResolver() {
- @Override
- public Result createOutput(String ns, String file) throws IOException {
- DOMResult result = new DOMResult();
-
- if (builtIns.containsKey(ns)) {
- DOMResult dr = builtIns.get(ns);
- result.setSystemId(dr.getSystemId());
- results.add(dr);
- return result;
- }
- result.setSystemId(file);
- results.add(result);
- return result;
- }
- });
- return results;
- }
-
- public static String getPackageNamespace(Class<?> cls) {
- Package p = cls.getPackage();
- if (p != null) {
- javax.xml.bind.annotation.XmlSchema schemaAnn =
- p.getAnnotation(javax.xml.bind.annotation.XmlSchema.class);
- if (schemaAnn != null) {
- return schemaAnn.namespace();
- }
- }
- return null;
- }
-
- public static void scanPackages(Set<Class<?>> classes,
- Map<Package, CachedClass> objectFactoryCache) {
- scanPackages(classes, null, objectFactoryCache);
- }
- public static void scanPackages(Set<Class<?>> classes,
- Class<?>[] extraClass,
- Map<Package, CachedClass> objectFactoryCache) {
-
- // add user extra class into jaxb context
- if (extraClass != null && extraClass.length > 0) {
- for (Class<?> clz : extraClass) {
- classes.add(clz);
- }
- }
-
- // try and read any jaxb.index files that are with the other classes.
- // This should
- // allow loading of extra classes (such as subclasses for inheritance
- // reasons)
- // that are in the same package. Also check for ObjectFactory classes
- Map<String, InputStream> packages = new HashMap<>();
- Map<String, ClassLoader> packageLoaders = new HashMap<>();
- Set<Class<?>> objectFactories = new HashSet<>();
- for (Class<?> jcls : classes) {
- String pkgName = PackageUtils.getPackageName(jcls);
- if (!packages.containsKey(pkgName)) {
- Package pkg = jcls.getPackage();
-
- packages.put(pkgName, jcls.getResourceAsStream("jaxb.index"));
- packageLoaders.put(pkgName, getClassLoader(jcls));
- String objectFactoryClassName = pkgName + "." + "ObjectFactory";
- Class<?> ofactory = null;
- CachedClass cachedFactory = null;
- if (pkg != null && objectFactoryCache != null) {
- synchronized (objectFactoryCache) {
- cachedFactory = objectFactoryCache.get(pkg);
- }
- }
- if (cachedFactory != null) {
- ofactory = cachedFactory.getCachedClass();
- }
- if (ofactory == null) {
- try {
- ofactory = Class.forName(objectFactoryClassName, false, getClassLoader(jcls));
- objectFactories.add(ofactory);
- addToObjectFactoryCache(pkg, ofactory, objectFactoryCache);
- } catch (ClassNotFoundException e) {
- addToObjectFactoryCache(pkg, null, objectFactoryCache);
- }
- } else {
- objectFactories.add(ofactory);
- }
- }
- }
- for (Map.Entry<String, InputStream> entry : packages.entrySet()) {
- if (entry.getValue() != null) {
- try (BufferedReader reader = new BufferedReader(
- new InputStreamReader(entry.getValue(), StandardCharsets.UTF_8))) {
- String pkg = entry.getKey();
- ClassLoader loader = packageLoaders.get(pkg);
- if (!StringUtils.isEmpty(pkg)) {
- pkg += ".";
- }
-
- String line = reader.readLine();
- while (line != null) {
- line = line.trim();
- if (line.indexOf('#') != -1) {
- line = line.substring(0, line.indexOf('#'));
- }
- if (!StringUtils.isEmpty(line)) {
- try {
- Class<?> ncls = Class.forName(pkg + line, false, loader);
- classes.add(ncls);
- } catch (Exception e) {
- // ignore
- }
- }
- line = reader.readLine();
- }
- } catch (IOException e) {
- // ignore
- } finally {
- try {
- entry.getValue().close();
- } catch (IOException e) {
- // ignore
- }
- }
- }
- }
- classes.addAll(objectFactories);
- }
-
- private static ClassLoader getClassLoader(final Class<?> clazz) {
- final SecurityManager sm = System.getSecurityManager();
- if (sm != null) {
- return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() {
- @Override
- public ClassLoader run() {
- return clazz.getClassLoader();
- }
- });
- }
- return clazz.getClassLoader();
- }
-
- private static void addToObjectFactoryCache(Package objectFactoryPkg,
- Class<?> ofactory,
- Map<Package, CachedClass> objectFactoryCache) {
- if (objectFactoryPkg == null || objectFactoryCache == null) {
- return;
- }
- synchronized (objectFactoryCache) {
- objectFactoryCache.put(objectFactoryPkg,
- new CachedClass(ofactory));
- }
- }
-
- public static class DefaultClassNameAllocator {
- private final Set<String> typesClassNames;
-
- public DefaultClassNameAllocator() {
- this(new HashSet<>());
- }
-
- public DefaultClassNameAllocator(Set<String> set) {
- typesClassNames = set;
- }
-
- public String assignClassName(String packageName, String className) {
- String fullClassName = className;
- String fullPckClass = packageName + "." + fullClassName;
- int cnt = 0;
- while (typesClassNames.contains(fullPckClass)) {
- cnt++;
- fullClassName = className + cnt;
- fullPckClass = packageName + "." + fullClassName;
- }
- typesClassNames.add(fullPckClass);
- return fullClassName;
- }
-
- }
-
- public interface SchemaCompiler {
- void setEntityResolver(EntityResolver entityResolver);
-
- void setErrorListener(Object elForRun);
-
- void setClassNameAllocator(Object allocator);
-
- @WrapReturn(S2JJAXBModel.class)
- S2JJAXBModel bind();
-
- void parseSchema(InputSource source);
-
- void parseSchema(String key, Element el);
- void parseSchema(String key, XMLStreamReader el);
-
- @WrapReturn(Options.class)
- Options getOptions();
- }
- public interface S2JJAXBModel {
-
- @WrapReturn(JCodeModel.class)
- JCodeModel generateCode(Object object, Object elForRun);
-
- @WrapReturn(Mapping.class)
- Mapping get(QName qn);
-
- @WrapReturn(TypeAndAnnotation.class)
- TypeAndAnnotation getJavaType(QName typeQName);
- }
- public interface Mapping {
- @WrapReturn(TypeAndAnnotation.class)
- TypeAndAnnotation getType();
- }
- public interface TypeAndAnnotation {
- @WrapReturn(JType.class)
- JType getTypeClass();
- }
- public interface JType {
- boolean isArray();
-
- @WrapReturn(JType.class)
- JType elementType();
-
- boolean isPrimitive();
-
- String binaryName();
-
- String fullName();
-
- String name();
-
- @WrapReturn(value = JType.class, iterator = true)
- Iterator<JType> classes();
- }
- public interface Options {
-
- void addGrammar(InputSource is);
-
- void addBindFile(InputSource is);
-
- void parseArguments(String[] args);
-
- String getBuildID();
- }
- public interface JCodeModel {
-
- void build(Object writer) throws IOException;
-
- @WrapReturn(value = JPackage.class, iterator = true)
- Iterator<JPackage> packages();
- }
- public interface JPackage {
-
- String name();
-
- @WrapReturn(value = JDefinedClass.class, iterator = true)
- Iterator<JDefinedClass> classes();
- }
- public interface JDefinedClass {
- String name();
-
- String fullName();
- }
-
- public static boolean isJAXB22() {
- Target t = XmlElement.class.getAnnotation(Target.class);
- //JAXB 2.2 allows XmlElement on params.
- for (ElementType et : t.value()) {
- if (et == ElementType.PARAMETER) {
- return true;
- }
- }
- return false;
- }
-
- public static JAXBContextProxy createJAXBContextProxy(final JAXBContext ctx) {
- return createJAXBContextProxy(ctx, null, null);
- }
- public static JAXBContextProxy createJAXBContextProxy(final JAXBContext ctx,
- final SchemaCollection collection,
- final String defaultNs) {
- if (ctx.getClass().getName().contains("com.sun.")
- || collection == null) {
- return ReflectionInvokationHandler.createProxyWrapper(ctx, JAXBContextProxy.class);
- }
- return new SchemaCollectionContextProxy(ctx, collection, defaultNs);
- }
- public static JAXBBeanInfo getBeanInfo(JAXBContextProxy context, Class<?> cls) {
- Object o = context.getBeanInfo(cls);
- if (o == null) {
- return null;
- }
- if (o instanceof JAXBBeanInfo) {
- return (JAXBBeanInfo)o;
- }
- return ReflectionInvokationHandler.createProxyWrapper(o, JAXBBeanInfo.class);
- }
-
- private static String getPostfix(Class<?> cls) {
- String className = cls.getName();
- if (className.contains("com.sun.xml.internal")
- || className.contains("eclipse")) {
- //eclipse moxy accepts sun package CharacterEscapeHandler
- return ".internal";
- } else if (className.contains("com.sun.xml.bind")
- || className.startsWith("com.ibm.xml")) {
- return "";
- }
- return null;
- }
-
- public static void setMinimumEscapeHandler(Marshaller marshaller) {
- if (jaxbMinimumEscapeHandler == null) {
- jaxbMinimumEscapeHandler = Optional.ofNullable(createMininumEscapeHandler(marshaller.getClass()));
- }
- jaxbMinimumEscapeHandler.ifPresent(p -> setEscapeHandler(marshaller, p));
- }
-
- public static void setNoEscapeHandler(final Marshaller marshaller) {
- if (jaxbNoEscapeHandler == null) {
- jaxbNoEscapeHandler = Optional.ofNullable(createNoEscapeHandler(marshaller.getClass()));
- }
- jaxbNoEscapeHandler.ifPresent(p -> setEscapeHandler(marshaller, p));
- }
-
- public static void setEscapeHandler(Marshaller marshaller, Object escapeHandler) {
- try {
- String postFix = getPostfix(marshaller.getClass());
- if (postFix != null && escapeHandler != null) {
- marshaller.setProperty("com.sun.xml" + postFix + ".bind.characterEscapeHandler", escapeHandler);
- }
- } catch (PropertyException e) {
- LOG.log(Level.INFO, "Failed to set MinumEscapeHandler to jaxb marshaller", e);
- }
- }
-
- public static Object createMininumEscapeHandler(Class<?> cls) {
- return createEscapeHandler(cls, "MinimumEscapeHandler");
- }
-
- public static Object createNoEscapeHandler(Class<?> cls) {
- return createEscapeHandler(cls, "NoEscapeHandler");
- }
-
- private static Object createEscapeHandler(Class<?> cls, String simpleClassName) {
- try {
- String postFix = getPostfix(cls);
- if (postFix == null) {
- LOG.log(Level.WARNING, "Failed to create" + simpleClassName + " for unknown jaxb class:"
- + cls);
- return null;
- }
- Class<?> handlerClass = ClassLoaderUtils.loadClass("com.sun.xml" + postFix
- + ".bind.marshaller." + simpleClassName,
- cls);
- Class<?> handlerInterface = ClassLoaderUtils
- .loadClass("com.sun.xml" + postFix + ".bind.marshaller.CharacterEscapeHandler",
- cls);
- Object targetHandler = ReflectionUtil.getDeclaredField(handlerClass, "theInstance").get(null);
- return ProxyHelper.getProxy(cls.getClassLoader(),
- new Class[] {handlerInterface},
- new EscapeHandlerInvocationHandler(targetHandler));
- } catch (Exception e) {
- if ("NoEscapeHandler".equals(simpleClassName)) {
- //this class doesn't exist in JAXB 2.2 so expected
- LOG.log(Level.FINER, "Failed to create " + simpleClassName);
- } else {
- LOG.log(Level.INFO, "Failed to create " + simpleClassName);
- }
- }
- return null;
- }
-
-
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/common/logging/AbstractDelegatingLogger.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/common/logging/AbstractDelegatingLogger.java
deleted file mode 100644
index dd3cbd5..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/common/logging/AbstractDelegatingLogger.java
+++ /dev/null
@@ -1,457 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.cxf.common.logging;
-
-import java.util.Locale;
-import java.util.MissingResourceException;
-import java.util.ResourceBundle;
-import java.util.logging.Filter;
-import java.util.logging.Handler;
-import java.util.logging.Level;
-import java.util.logging.LogRecord;
-import java.util.logging.Logger;
-
-/**
- * java.util.logging.Logger implementation delegating to another framework.
- * All methods can be used except:
- * setLevel
- * addHandler / getHandlers
- * setParent / getParent
- * setUseParentHandlers / getUseParentHandlers
- */
-public abstract class AbstractDelegatingLogger extends Logger {
-
- protected AbstractDelegatingLogger(String name, String resourceBundleName) {
- super(name, resourceBundleName);
- }
-
- @Override
- public void log(LogRecord record) {
- if (isLoggable(record.getLevel())) {
- doLog(record);
- }
- }
-
- @Override
- public void log(Level level, String msg) {
- if (isLoggable(level)) {
- LogRecord lr = new LogRecord(level, msg);
- doLog(lr);
- }
- }
-
- @Override
- public void log(Level level, String msg, Object param1) {
- if (isLoggable(level)) {
- LogRecord lr = new LogRecord(level, msg);
- Object[] params = {param1 };
- lr.setParameters(params);
- doLog(lr);
- }
- }
-
- @Override
- public void log(Level level, String msg, Object[] params) {
- if (isLoggable(level)) {
- LogRecord lr = new LogRecord(level, msg);
- lr.setParameters(params);
- doLog(lr);
- }
- }
-
- @Override
- public void log(Level level, String msg, Throwable thrown) {
- if (isLoggable(level)) {
- LogRecord lr = new LogRecord(level, msg);
- lr.setThrown(thrown);
- doLog(lr);
- }
- }
-
- @Override
- public void logp(Level level, String sourceClass, String sourceMethod, String msg) {
- if (isLoggable(level)) {
- LogRecord lr = new LogRecord(level, msg);
- lr.setSourceClassName(sourceClass);
- lr.setSourceMethodName(sourceMethod);
- doLog(lr);
- }
- }
-
- @Override
- public void logp(Level level, String sourceClass, String sourceMethod, String msg, Object param1) {
- if (isLoggable(level)) {
- LogRecord lr = new LogRecord(level, msg);
- lr.setSourceClassName(sourceClass);
- lr.setSourceMethodName(sourceMethod);
- Object[] params = {param1 };
- lr.setParameters(params);
- doLog(lr);
- }
- }
-
- @Override
- public void logp(Level level, String sourceClass, String sourceMethod, String msg, Object[] params) {
- if (isLoggable(level)) {
- LogRecord lr = new LogRecord(level, msg);
- lr.setSourceClassName(sourceClass);
- lr.setSourceMethodName(sourceMethod);
- lr.setParameters(params);
- doLog(lr);
- }
- }
-
- @Override
- public void logp(Level level, String sourceClass, String sourceMethod, String msg, Throwable thrown) {
- if (isLoggable(level)) {
- LogRecord lr = new LogRecord(level, msg);
- lr.setSourceClassName(sourceClass);
- lr.setSourceMethodName(sourceMethod);
- lr.setThrown(thrown);
- doLog(lr);
- }
- }
-
-
- @Override
- @Deprecated
- public void logrb(Level level, String sourceClass, String sourceMethod, String bundleName, String msg) {
- if (isLoggable(level)) {
- LogRecord lr = new LogRecord(level, msg);
- lr.setSourceClassName(sourceClass);
- lr.setSourceMethodName(sourceMethod);
- doLog(lr, bundleName);
- }
- }
-
-
- @Override
- @Deprecated
- public void logrb(Level level, String sourceClass, String sourceMethod,
- String bundleName, String msg, Object param1) {
- if (isLoggable(level)) {
- LogRecord lr = new LogRecord(level, msg);
- lr.setSourceClassName(sourceClass);
- lr.setSourceMethodName(sourceMethod);
- Object[] params = {param1 };
- lr.setParameters(params);
- doLog(lr, bundleName);
- }
- }
-
-
- @Override
- @Deprecated
- public void logrb(Level level, String sourceClass, String sourceMethod,
- String bundleName, String msg, Object[] params) {
- if (isLoggable(level)) {
- LogRecord lr = new LogRecord(level, msg);
- lr.setSourceClassName(sourceClass);
- lr.setSourceMethodName(sourceMethod);
- lr.setParameters(params);
- doLog(lr, bundleName);
- }
- }
-
- @Override
- @Deprecated
- public void logrb(Level level, String sourceClass, String sourceMethod,
- String bundleName, String msg, Throwable thrown) {
- if (isLoggable(level)) {
- LogRecord lr = new LogRecord(level, msg);
- lr.setSourceClassName(sourceClass);
- lr.setSourceMethodName(sourceMethod);
- lr.setThrown(thrown);
- doLog(lr, bundleName);
- }
- }
-
- @Override
- public void entering(String sourceClass, String sourceMethod) {
- if (isLoggable(Level.FINER)) {
- logp(Level.FINER, sourceClass, sourceMethod, "ENTRY");
- }
- }
-
- @Override
- public void entering(String sourceClass, String sourceMethod, Object param1) {
- if (isLoggable(Level.FINER)) {
- Object[] params = {param1 };
- logp(Level.FINER, sourceClass, sourceMethod, "ENTRY {0}", params);
- }
- }
-
- @Override
- public void entering(String sourceClass, String sourceMethod, Object[] params) {
- if (isLoggable(Level.FINER)) {
- String msg = "ENTRY";
- if (params == null) {
- logp(Level.FINER, sourceClass, sourceMethod, msg);
- return;
- }
- StringBuilder builder = new StringBuilder(msg);
- for (int i = 0; i < params.length; i++) {
- builder.append(" {");
- builder.append(Integer.toString(i));
- builder.append('}');
- }
- logp(Level.FINER, sourceClass, sourceMethod, builder.toString(), params);
- }
- }
-
- @Override
- public void exiting(String sourceClass, String sourceMethod) {
- if (isLoggable(Level.FINER)) {
- logp(Level.FINER, sourceClass, sourceMethod, "RETURN");
- }
- }
-
- @Override
- public void exiting(String sourceClass, String sourceMethod, Object result) {
- if (isLoggable(Level.FINER)) {
- Object[] params = {result };
- logp(Level.FINER, sourceClass, sourceMethod, "RETURN {0}", params);
- }
- }
-
- @Override
- public void throwing(String sourceClass, String sourceMethod, Throwable thrown) {
- if (isLoggable(Level.FINER)) {
- LogRecord lr = new LogRecord(Level.FINER, "THROW");
- lr.setSourceClassName(sourceClass);
- lr.setSourceMethodName(sourceMethod);
- lr.setThrown(thrown);
- doLog(lr);
- }
- }
-
- @Override
- public void severe(String msg) {
- if (isLoggable(Level.SEVERE)) {
- LogRecord lr = new LogRecord(Level.SEVERE, msg);
- doLog(lr);
- }
- }
-
- @Override
- public void warning(String msg) {
- if (isLoggable(Level.WARNING)) {
- LogRecord lr = new LogRecord(Level.WARNING, msg);
- doLog(lr);
- }
- }
-
- @Override
- public void info(String msg) {
- if (isLoggable(Level.INFO)) {
- LogRecord lr = new LogRecord(Level.INFO, msg);
- doLog(lr);
- }
- }
-
- @Override
- public void config(String msg) {
- if (isLoggable(Level.CONFIG)) {
- LogRecord lr = new LogRecord(Level.CONFIG, msg);
- doLog(lr);
- }
- }
-
- @Override
- public void fine(String msg) {
- if (isLoggable(Level.FINE)) {
- LogRecord lr = new LogRecord(Level.FINE, msg);
- doLog(lr);
- }
- }
-
- @Override
- public void finer(String msg) {
- if (isLoggable(Level.FINER)) {
- LogRecord lr = new LogRecord(Level.FINER, msg);
- doLog(lr);
- }
- }
-
- @Override
- public void finest(String msg) {
- if (isLoggable(Level.FINEST)) {
- LogRecord lr = new LogRecord(Level.FINEST, msg);
- doLog(lr);
- }
- }
-
- @Override
- public void setLevel(Level newLevel) {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public abstract Level getLevel();
-
- @Override
- public boolean isLoggable(Level level) {
- Level l = getLevel();
- return level.intValue() >= l.intValue() && l != Level.OFF;
- }
-
- protected boolean supportsHandlers() {
- return false;
- }
-
- @Override
- public synchronized void addHandler(Handler handler) {
- if (supportsHandlers()) {
- super.addHandler(handler);
- return;
- }
- throw new UnsupportedOperationException();
- }
-
- @Override
- public synchronized void removeHandler(Handler handler) {
- if (supportsHandlers()) {
- super.removeHandler(handler);
- return;
- }
- throw new UnsupportedOperationException();
- }
-
- @Override
- public synchronized Handler[] getHandlers() {
- if (supportsHandlers()) {
- return super.getHandlers();
- }
- throw new UnsupportedOperationException();
- }
-
- @Override
- public synchronized void setUseParentHandlers(boolean useParentHandlers) {
- if (supportsHandlers()) {
- super.setUseParentHandlers(useParentHandlers);
- return;
- }
- throw new UnsupportedOperationException();
- }
-
- @Override
- public synchronized boolean getUseParentHandlers() {
- if (supportsHandlers()) {
- return super.getUseParentHandlers();
- }
- throw new UnsupportedOperationException();
- }
-
- @Override
- public Logger getParent() {
- return null;
- }
-
- @Override
- public void setParent(Logger parent) {
- throw new UnsupportedOperationException();
- }
-
- protected void doLog(LogRecord lr) {
- lr.setLoggerName(getName());
- String rbname = getResourceBundleName();
- if (rbname != null) {
- lr.setResourceBundleName(rbname);
- lr.setResourceBundle(getResourceBundle());
- }
- internalLog(lr);
- }
-
- protected void doLog(LogRecord lr, String rbname) {
- lr.setLoggerName(getName());
- if (rbname != null) {
- lr.setResourceBundleName(rbname);
- lr.setResourceBundle(loadResourceBundle(rbname));
- }
- internalLog(lr);
- }
-
- protected void internalLog(LogRecord record) {
- Filter filter = getFilter();
- if (filter != null && !filter.isLoggable(record)) {
- return;
- }
- String msg = formatMessage(record);
- internalLogFormatted(msg, record);
- }
-
- protected abstract void internalLogFormatted(String msg, LogRecord record);
-
- protected String formatMessage(LogRecord record) {
- String format = record.getMessage();
- ResourceBundle catalog = record.getResourceBundle();
- if (catalog != null) {
- try {
- format = catalog.getString(record.getMessage());
- } catch (MissingResourceException ex) {
- format = record.getMessage();
- }
- }
- try {
- Object[] parameters = record.getParameters();
- if (parameters == null || parameters.length == 0) {
- return format;
- }
- if (format.indexOf("{0") >= 0 || format.indexOf("{1") >= 0
- || format.indexOf("{2") >= 0 || format.indexOf("{3") >= 0) {
- return java.text.MessageFormat.format(format, parameters);
- }
- return format;
- } catch (Exception ex) {
- return format;
- }
- }
-
- /**
- * Load the specified resource bundle
- *
- * @param resourceBundleName
- * the name of the resource bundle to load, cannot be null
- * @return the loaded resource bundle.
- * @throws java.util.MissingResourceException
- * If the specified resource bundle can not be loaded.
- */
- static ResourceBundle loadResourceBundle(String resourceBundleName) {
- // try context class loader to load the resource
- ClassLoader cl = Thread.currentThread().getContextClassLoader();
- if (null != cl) {
- try {
- return ResourceBundle.getBundle(resourceBundleName, Locale.getDefault(), cl);
- } catch (MissingResourceException e) {
- // Failed to load using context classloader, ignore
- }
- }
- // try system class loader to load the resource
- cl = ClassLoader.getSystemClassLoader();
- if (null != cl) {
- try {
- return ResourceBundle.getBundle(resourceBundleName, Locale.getDefault(), cl);
- } catch (MissingResourceException e) {
- // Failed to load using system classloader, ignore
- }
- }
- return null;
- }
-
-}
\ No newline at end of file
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/common/logging/LogUtils.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/common/logging/LogUtils.java
deleted file mode 100644
index 09727e6..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/common/logging/LogUtils.java
+++ /dev/null
@@ -1,485 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.cxf.common.logging;
-
-import java.io.BufferedReader;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.InvocationTargetException;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
-import java.text.MessageFormat;
-import java.util.MissingResourceException;
-import java.util.ResourceBundle;
-import java.util.logging.Level;
-import java.util.logging.LogRecord;
-import java.util.logging.Logger;
-
-import org.apache.cxf.common.i18n.BundleUtils;
-import org.apache.cxf.common.util.StringUtils;
-
-
-/**
- * A container for static utility methods related to logging.
- * By default, CXF logs to java.util.logging. An application can change this. To log to another system, the
- * application must provide an object that extends {@link AbstractDelegatingLogger}, and advertise that class
- * via one of the following mechanisms:
- * <ul>
- * <li>Create a file, in the classpath, named META-INF/cxf/org.apache.cxf.Logger.
- * This file should contain the fully-qualified name
- * of the class, with no comments, on a single line.</li>
- * <li>Call {@link #setLoggerClass(Class)} with a Class<?> reference to the logger class.</li>
- * </ul>
- * CXF provides {@link Slf4jLogger} to use slf4j instead of java.util.logging.
- */
-public final class LogUtils {
- private static final String KEY = "org.apache.cxf.Logger";
-
- private static final Object[] NO_PARAMETERS = new Object[0];
-
-
- private static Class<?> loggerClass;
-
- /**
- * Prevents instantiation.
- */
- private LogUtils() {
- }
-
- static {
- JDKBugHacks.doHacks();
-
- try {
-
- String cname = null;
- try {
- cname = AccessController.doPrivileged(new PrivilegedAction<String>() {
- public String run() {
- return System.getProperty(KEY);
- }
- });
- } catch (Throwable t) {
- //ignore - likely security exception or similar that won't allow
- //access to the system properties. We'll continue with other methods
- }
- if (StringUtils.isEmpty(cname)) {
- InputStream ins = Thread.currentThread().getContextClassLoader()
- .getResourceAsStream("META-INF/cxf/" + KEY);
- if (ins == null) {
- ins = ClassLoader.getSystemResourceAsStream("META-INF/cxf/" + KEY);
- }
- if (ins != null) {
- try (BufferedReader din = new BufferedReader(new InputStreamReader(ins))) {
- cname = din.readLine();
- }
- }
- }
- if (StringUtils.isEmpty(cname)) {
- try {
- // This Class.forName likely will barf in OSGi, but it's OK
- // as we'll just use j.u.l and pax-logging will pick it up fine
- // If we don't call this and there isn't a slf4j impl avail,
- // you get warnings printed to stderr about NOPLoggers and such
- Class.forName("org.slf4j.impl.StaticLoggerBinder");
- Class<?> cls = Class.forName("org.slf4j.LoggerFactory");
- Class<?> fcls = cls.getMethod("getILoggerFactory").invoke(null).getClass();
- String clsName = fcls.getName();
- if (clsName.contains("NOPLogger")) {
- //no real slf4j implementation, use j.u.l
- cname = null;
- } else if (clsName.contains("JDK14")
- || clsName.contains("pax.logging")) {
- //both of these we can use the appropriate j.u.l API's
- //directly and have it work properly
- cname = null;
- } else {
- // Either we cannot really detect where it's logging
- // or we don't want to use a custom logger, so we'll
- // go ahead and use the Slf4jLogger directly
- cname = "org.apache.cxf.common.logging.Slf4jLogger";
- }
- } catch (Throwable t) {
- //ignore - Slf4j not available
- }
- }
- if (!StringUtils.isEmpty(cname)) {
- try {
- loggerClass = Class.forName(cname.trim(), true,
- Thread.currentThread().getContextClassLoader());
- } catch (Throwable ex) {
- loggerClass = Class.forName(cname.trim());
- }
- getLogger(LogUtils.class).fine("Using " + loggerClass.getName() + " for logging.");
- }
- } catch (Throwable ex) {
- //ignore - if we get here, some issue prevented the logger class from being loaded.
- //maybe a ClassNotFound or NoClassDefFound or similar. Just use j.u.l
- loggerClass = null;
- }
- }
-
-
- /**
- * Specify a logger class that inherits from {@link AbstractDelegatingLogger}.
- * Enable users to use their own logger implementation.
- */
- public static void setLoggerClass(Class<? extends AbstractDelegatingLogger> cls) {
- loggerClass = cls;
- }
-
-
- /**
- * Get a Logger with the associated default resource bundle for the class.
- *
- * @param cls the Class to contain the Logger
- * @return an appropriate Logger
- */
- public static Logger getLogger(Class<?> cls) {
- return createLogger(cls, null, cls.getName());
- }
-
- /**
- * Get a Logger with an associated resource bundle.
- *
- * @param cls the Class to contain the Logger
- * @param resourcename the resource name
- * @return an appropriate Logger
- */
- public static Logger getLogger(Class<?> cls, String resourcename) {
- return createLogger(cls, resourcename, cls.getName());
- }
-
- /**
- * Get a Logger with an associated resource bundle.
- *
- * @param cls the Class to contain the Logger (to find resources)
- * @param resourcename the resource name
- * @param loggerName the full name for the logger
- * @return an appropriate Logger
- */
- public static Logger getLogger(Class<?> cls,
- String resourcename,
- String loggerName) {
- return createLogger(cls, resourcename, loggerName);
- }
-
- /**
- * Get a Logger with the associated default resource bundle for the class.
- *
- * @param cls the Class to contain the Logger
- * @return an appropriate Logger
- */
- public static Logger getL7dLogger(Class<?> cls) {
- return createLogger(cls, null, cls.getName());
- }
-
- /**
- * Get a Logger with an associated resource bundle.
- *
- * @param cls the Class to contain the Logger
- * @param resourcename the resource name
- * @return an appropriate Logger
- */
- public static Logger getL7dLogger(Class<?> cls, String resourcename) {
- return createLogger(cls, resourcename, cls.getName());
- }
-
- /**
- * Get a Logger with an associated resource bundle.
- *
- * @param cls the Class to contain the Logger (to find resources)
- * @param resourcename the resource name
- * @param loggerName the full name for the logger
- * @return an appropriate Logger
- */
- public static Logger getL7dLogger(Class<?> cls,
- String resourcename,
- String loggerName) {
- return createLogger(cls, resourcename, loggerName);
- }
-
- /**
- * Create a logger
- */
- protected static Logger createLogger(Class<?> cls,
- String name,
- String loggerName) {
- ClassLoader orig = getContextClassLoader();
- ClassLoader n = getClassLoader(cls);
- if (n != null) {
- setContextClassLoader(n);
- }
- String bundleName = name;
- try {
- ResourceBundle b = null;
- if (bundleName == null) {
- //grab the bundle prior to the call to Logger.getLogger(...) so the
- //ResourceBundle can be loaded outside the big sync block that getLogger really is
- bundleName = BundleUtils.getBundleName(cls);
- try {
- b = BundleUtils.getBundle(cls);
- } catch (MissingResourceException rex) {
- //ignore
- }
- } else {
- bundleName = BundleUtils.getBundleName(cls, bundleName);
- try {
- b = BundleUtils.getBundle(cls, bundleName);
- } catch (MissingResourceException rex) {
- //ignore
- }
- }
- if (b != null) {
- b.getLocale();
- }
-
- if (loggerClass != null) {
- try {
- Constructor<?> cns = loggerClass.getConstructor(String.class, String.class);
- if (name == null) {
- try {
- return (Logger) cns.newInstance(loggerName, bundleName);
- } catch (InvocationTargetException ite) {
- if (ite.getTargetException() instanceof MissingResourceException) {
- return (Logger) cns.newInstance(loggerName, null);
- }
- throw ite;
- }
- }
- try {
- return (Logger) cns.newInstance(loggerName, bundleName);
- } catch (InvocationTargetException ite) {
- if (ite.getTargetException() instanceof MissingResourceException) {
- throw (MissingResourceException)ite.getTargetException();
- }
- throw ite;
- }
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- }
-
- Logger logger;
- try {
- logger = Logger.getLogger(loggerName, bundleName); //NOPMD
- } catch (IllegalArgumentException | MissingResourceException ex) {
- //likely a mismatch on the bundle name, just return the default
- logger = Logger.getLogger(loggerName); //NOPMD
- }
-
- return logger;
- } finally {
- if (n != orig) {
- setContextClassLoader(orig);
- }
- }
- }
-
- private static void setContextClassLoader(final ClassLoader classLoader) {
- final SecurityManager sm = System.getSecurityManager();
- if (sm != null) {
- AccessController.doPrivileged(new PrivilegedAction<Object>() {
- public Object run() {
- Thread.currentThread().setContextClassLoader(classLoader);
- return null;
- }
- });
- } else {
- Thread.currentThread().setContextClassLoader(classLoader);
- }
- }
-
- private static ClassLoader getContextClassLoader() {
- final SecurityManager sm = System.getSecurityManager();
- if (sm != null) {
- return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() {
- public ClassLoader run() {
- return Thread.currentThread().getContextClassLoader();
- }
- });
- }
- return Thread.currentThread().getContextClassLoader();
- }
-
- private static ClassLoader getClassLoader(final Class<?> clazz) {
- final SecurityManager sm = System.getSecurityManager();
- if (sm != null) {
- return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() {
- public ClassLoader run() {
- return clazz.getClassLoader();
- }
- });
- }
- return clazz.getClassLoader();
- }
-
- /**
- * Allows both parameter substitution and a typed Throwable to be logged.
- *
- * @param logger the Logger the log to
- * @param level the severity level
- * @param message the log message
- * @param throwable the Throwable to log
- * @param parameter the parameter to substitute into message
- */
- public static void log(Logger logger,
- Level level,
- String message,
- Throwable throwable,
- Object parameter) {
- if (logger.isLoggable(level)) {
- final String formattedMessage =
- MessageFormat.format(localize(logger, message), parameter);
- doLog(logger, level, formattedMessage, throwable);
- }
- }
-
- /**
- * Allows both parameter substitution and a typed Throwable to be logged.
- *
- * @param logger the Logger the log to
- * @param level the severity level
- * @param message the log message
- * @param throwable the Throwable to log
- * @param parameters the parameters to substitute into message
- */
- public static void log(Logger logger,
- Level level,
- String message,
- Throwable throwable,
- Object... parameters) {
- if (logger.isLoggable(level)) {
- final String formattedMessage =
- MessageFormat.format(localize(logger, message), parameters);
- doLog(logger, level, formattedMessage, throwable);
- }
- }
-
- /**
- * Checks log level and logs
- *
- * @param logger the Logger the log to
- * @param level the severity level
- * @param message the log message
- */
- public static void log(Logger logger,
- Level level,
- String message) {
- log(logger, level, message, NO_PARAMETERS);
- }
-
- /**
- * Checks log level and logs
- *
- * @param logger the Logger the log to
- * @param level the severity level
- * @param message the log message
- * @param throwable the Throwable to log
- */
- public static void log(Logger logger,
- Level level,
- String message,
- Throwable throwable) {
- log(logger, level, message, throwable, NO_PARAMETERS);
- }
-
- /**
- * Checks log level and logs
- *
- * @param logger the Logger the log to
- * @param level the severity level
- * @param message the log message
- * @param parameter the parameter to substitute into message
- */
- public static void log(Logger logger,
- Level level,
- String message,
- Object parameter) {
- log(logger, level, message, new Object[] {parameter});
- }
-
- /**
- * Checks log level and logs
- *
- * @param logger the Logger the log to
- * @param level the severity level
- * @param message the log message
- * @param parameters the parameters to substitute into message
- */
- public static void log(Logger logger,
- Level level,
- String message,
- Object[] parameters) {
- if (logger.isLoggable(level)) {
- String msg = localize(logger, message);
- try {
- msg = MessageFormat.format(msg, parameters);
- } catch (IllegalArgumentException ex) {
- //ignore, log as is
- }
- doLog(logger, level, msg, null);
- }
- }
-
- private static void doLog(Logger log, Level level, String msg, Throwable t) {
- LogRecord record = new LogRecord(level, msg);
-
- record.setLoggerName(log.getName());
- record.setResourceBundleName(log.getResourceBundleName());
- record.setResourceBundle(log.getResourceBundle());
-
- if (t != null) {
- record.setThrown(t);
- }
-
- //try to get the right class name/method name - just trace
- //back the stack till we get out of this class
- StackTraceElement[] stack = (new Throwable()).getStackTrace();
- String cname = LogUtils.class.getName();
- for (int x = 0; x < stack.length; x++) {
- StackTraceElement frame = stack[x];
- if (!frame.getClassName().equals(cname)) {
- record.setSourceClassName(frame.getClassName());
- record.setSourceMethodName(frame.getMethodName());
- break;
- }
- }
- log.log(record);
- }
-
- /**
- * Retrieve localized message retrieved from a logger's resource
- * bundle.
- *
- * @param logger the Logger
- * @param message the message to be localized
- */
- private static String localize(Logger logger, String message) {
- ResourceBundle bundle = logger.getResourceBundle();
- try {
- return bundle != null ? bundle.getString(message) : message;
- } catch (MissingResourceException ex) {
- //string not in the bundle
- return message;
- }
- }
-
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/common/logging/RegexLoggingFilter.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/common/logging/RegexLoggingFilter.java
deleted file mode 100644
index 83178b9..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/common/logging/RegexLoggingFilter.java
+++ /dev/null
@@ -1,117 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.cxf.common.logging;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-public class RegexLoggingFilter {
-
- public static final String DEFAULT_REPLACEMENT = "*****";
-
- private static class ReplaceRegEx {
- private final Pattern pattern;
- private final int group;
- private final String replacement;
-
- ReplaceRegEx(String pattern, int group, String replacement) {
- this.pattern = Pattern.compile(pattern);
- this.group = group;
- this.replacement = replacement;
- }
-
- public CharSequence filter(CharSequence command) {
- Matcher m = pattern.matcher(command);
- int offset = 0;
- while (m.find()) {
- int origLen = command.length();
- command = new StringBuilder(command)
- .replace(m.start(group) + offset, m.end(group) + offset, replacement).toString();
- offset += command.length() - origLen;
- }
- return command;
- }
- }
-
- private String regPattern;
- private int regGroup = 1;
- private String regReplacement = DEFAULT_REPLACEMENT;
-
- private List<ReplaceRegEx> regexs = new ArrayList<>();
-
- public CharSequence filter(CharSequence command) {
- if (regPattern != null) {
- command = new ReplaceRegEx(regPattern, regGroup, regReplacement).filter(command);
- }
- for (ReplaceRegEx regex : regexs) {
- command = regex.filter(command);
- }
- return command;
- }
-
- public void addRegEx(String pattern) {
- addRegEx(pattern, 1);
- }
-
- public void addRegEx(String pattern, int group) {
- addRegEx(pattern, group, DEFAULT_REPLACEMENT);
- }
-
- public void addRegEx(String pattern, int group, String replacement) {
- regexs.add(new ReplaceRegEx(pattern, group, replacement));
- }
-
- public void addCommandOption(String option, String... commands) {
- StringBuilder pattern = new StringBuilder("(");
- for (String command : commands) {
- if (pattern.length() > 1) {
- pattern.append('|');
- }
- pattern.append(Pattern.quote(command));
- }
- pattern.append(") +.*?").append(Pattern.quote(option)).append(" +([^ ]+)");
- regexs.add(new ReplaceRegEx(pattern.toString(), 2, DEFAULT_REPLACEMENT));
- }
-
- public String getPattern() {
- return regPattern;
- }
-
- public void setPattern(String pattern) {
- this.regPattern = pattern;
- }
-
- public String getReplacement() {
- return regReplacement;
- }
-
- public void setReplacement(String replacement) {
- this.regReplacement = replacement;
- }
-
- public int getGroup() {
- return regGroup;
- }
-
- public void setGroup(int group) {
- this.regGroup = group;
- }
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/common/spi/ClassGeneratorClassLoader.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/common/spi/ClassGeneratorClassLoader.java
deleted file mode 100644
index 5906c7a..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/common/spi/ClassGeneratorClassLoader.java
+++ /dev/null
@@ -1,153 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.cxf.common.spi;
-
-import java.lang.ref.WeakReference;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-
-import org.apache.cxf.Bus;
-import org.apache.cxf.BusFactory;
-import org.apache.cxf.common.util.StringUtils;
-import org.apache.cxf.common.util.WeakIdentityHashMap;
-
-/** Class loader used to store and retrieve class generated during runtime to avoid class generation each time.
- * inherited class use asmHelper to generate bytes and use @see #loadClass(String, Class<?>, byte[])
- * or @see #loadClass(String, ClassLoader, byte[]) to store generated class.Class can be generated during buildtime.
- * equivalent class is @see org.apache.cxf.common.spi.GeneratedClassClassLoader
- * @author olivier dufour
- */
-public class ClassGeneratorClassLoader {
- protected static final Map<Class<?>, WeakReference<TypeHelperClassLoader>> CLASS_MAP
- = new WeakIdentityHashMap<>();
- protected static final Map<ClassLoader, WeakReference<TypeHelperClassLoader>> LOADER_MAP
- = new WeakIdentityHashMap<>();
- protected final Bus bus;
-
- public ClassGeneratorClassLoader(final Bus bus) {
- this.bus = bus == null ? BusFactory.getDefaultBus() : bus;
- }
-
- protected Class<?> loadClass(String className, Class<?> cls, byte[] bytes) {
- GeneratedClassClassLoaderCapture capture = bus.getExtension(GeneratedClassClassLoaderCapture.class);
- if (capture != null) {
- capture.capture(className, bytes);
- }
- TypeHelperClassLoader loader = getOrCreateLoader(cls);
- synchronized (loader) {
- Class<?> clz = loader.lookupDefinedClass(className);
- if (clz == null) {
- return loader.defineClass(className, bytes);
- }
- return clz;
- }
- }
- protected Class<?> loadClass(String className, ClassLoader l, byte[] bytes) {
- GeneratedClassClassLoaderCapture capture = bus.getExtension(GeneratedClassClassLoaderCapture.class);
- if (capture != null) {
- capture.capture(className, bytes);
- }
- TypeHelperClassLoader loader = getOrCreateLoader(l);
- synchronized (loader) {
- Class<?> clz = loader.lookupDefinedClass(className);
- if (clz == null) {
- return loader.defineClass(className, bytes);
- }
- return clz;
- }
- }
- protected Class<?> findClass(String className, Class<?> cls) {
- return getOrCreateLoader(cls).lookupDefinedClass(className);
- }
-
- protected Class<?> findClass(String className, ClassLoader classLoader) {
- return getOrCreateLoader(classLoader).lookupDefinedClass(className);
- }
-
- private static synchronized TypeHelperClassLoader getOrCreateLoader(Class<?> cls) {
- WeakReference<TypeHelperClassLoader> ref = CLASS_MAP.get(cls);
- TypeHelperClassLoader ret;
- if (ref == null || ref.get() == null) {
- ret = new TypeHelperClassLoader(cls.getClassLoader());
- CLASS_MAP.put(cls, new WeakReference<>(ret));
- } else {
- ret = ref.get();
- }
- return ret;
- }
-
- private static synchronized TypeHelperClassLoader getOrCreateLoader(ClassLoader l) {
- WeakReference<TypeHelperClassLoader> ref = LOADER_MAP.get(l);
- TypeHelperClassLoader ret;
- if (ref == null || ref.get() == null) {
- ret = new TypeHelperClassLoader(l);
- LOADER_MAP.put(l, new WeakReference<>(ret));
- } else {
- ret = ref.get();
- }
- return ret;
- }
-
- public static class TypeHelperClassLoader extends ClassLoader {
- private final ConcurrentHashMap<String, Class<?>> defined = new ConcurrentHashMap<>();
-
- TypeHelperClassLoader(ClassLoader parent) {
- super(parent);
- }
-
- public Class<?> lookupDefinedClass(String name) {
- return defined.get(StringUtils.slashesToPeriod(name));
- }
-
- @Override
- protected Class<?> findClass(String name) throws ClassNotFoundException {
- if (name.endsWith("package-info")) {
- return getParent().loadClass(name);
- }
- return super.findClass(name);
- }
-
- public Class<?> defineClass(String name, byte[] bytes) {
- Class<?> ret = defined.get(StringUtils.slashesToPeriod(name));
- if (ret != null) {
- return ret;
- }
- if (name.endsWith("package-info")) {
- String s = name.substring(0, name.length() - 13);
- Package p = super.getPackage(s);
- if (p == null) {
- definePackage(StringUtils.slashesToPeriod(s),
- null,
- null,
- null,
- null,
- null,
- null,
- null);
- }
- }
-
- ret = defined.computeIfAbsent(StringUtils.slashesToPeriod(name),
- key -> TypeHelperClassLoader.super.defineClass(key, bytes, 0, bytes.length));
-
- return ret;
- }
- }
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/common/spi/NamespaceClassGenerator.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/common/spi/NamespaceClassGenerator.java
deleted file mode 100644
index 48c755b..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/common/spi/NamespaceClassGenerator.java
+++ /dev/null
@@ -1,450 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.cxf.common.spi;
-
-import java.util.Map;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import org.apache.cxf.Bus;
-import org.apache.cxf.common.classloader.ClassLoaderUtils;
-import org.apache.cxf.common.logging.LogUtils;
-import org.apache.cxf.common.util.ASMHelper;
-import org.apache.cxf.common.util.OpcodesProxy;
-
-public class NamespaceClassGenerator extends ClassGeneratorClassLoader implements NamespaceClassCreator {
-
- private static final Logger LOG = LogUtils.getL7dLogger(ClassGeneratorClassLoader.class);
- private final ASMHelper helper;
-
- public NamespaceClassGenerator(Bus bus) {
- super(bus);
- helper = bus.getExtension(ASMHelper.class);
- }
-
- @Override
- public synchronized Class<?> createNamespaceWrapperClass(Class<?> mcls, Map<String, String> map) {
- String postFix = "";
-
- if (mcls.getName().contains("eclipse")) {
- return createEclipseNamespaceMapper();
- } else if (mcls.getName().contains(".internal")) {
- postFix = "Internal";
- } else if (mcls.getName().contains("com.sun")) {
- postFix = "RI";
- }
-
- String className = "org.apache.cxf.jaxb.NamespaceMapper";
- className += postFix;
- Class<?> cls = findClass(className, NamespaceClassCreator.class);
- Throwable t = null;
- if (cls == null) {
- try {
- byte[] bts = createNamespaceWrapperInternal(postFix);
- className = "org.apache.cxf.jaxb.NamespaceMapper" + postFix;
- return loadClass(className, NamespaceClassCreator.class, bts);
- } catch (RuntimeException ex) {
- // continue
- t = ex;
- }
- }
- if (cls == null
- && (!mcls.getName().contains(".internal.") && mcls.getName().contains("com.sun"))) {
- try {
- cls = ClassLoaderUtils.loadClass("org.apache.cxf.common.jaxb.NamespaceMapper",
- NamespaceClassCreator.class);
- } catch (Throwable ex2) {
- // ignore
- t = ex2;
- }
- }
- LOG.log(Level.INFO, "Could not create a NamespaceMapper compatible with Marshaller class " + mcls.getName(), t);
- return cls;
- }
-
- private Class<?> createEclipseNamespaceMapper() {
- String className = "org.apache.cxf.jaxb.EclipseNamespaceMapper";
- Class<?> cls = findClass(className, NamespaceClassCreator.class);
- if (cls != null) {
- return cls;
- }
- byte[] bts = doCreateEclipseNamespaceMapper();
- //previous code use mcls instead of NamespaceClassGenerator.class
- return loadClass(className, NamespaceClassCreator.class, bts);
- }
-
- /*
- // This is the "prototype" for the ASM generated class below
- public static class MapNamespacePrefixMapper2
- extends org.eclipse.persistence.internal.oxm.record.namespaces.MapNamespacePrefixMapper {
-
- String[] nsctxt;
-
- public MapNamespacePrefixMapper2(Map<String, String> foo) {
- super(foo);
- }
- public String[] getPreDeclaredNamespaceUris() {
- String[] sup = super.getPreDeclaredNamespaceUris();
- if (nsctxt == null) {
- return sup;
- }
- List<String> s = new ArrayList<>(Arrays.asList(sup));
- for (int x = 1; x < nsctxt.length; x = x + 2) {
- s.remove(nsctxt[x]);
- }
- return s.toArray(new String[s.size()]);
- }
- public void setContextualNamespaceDecls(String[] f) {
- nsctxt = f;
- }
- public String[] getContextualNamespaceDecls() {
- return nsctxt;
- }
- }
- */
- //CHECKSTYLE:OFF
- //bunch of really long ASM based methods that cannot be shortened easily
- private byte[] doCreateEclipseNamespaceMapper() {
- OpcodesProxy Opcodes = helper.getOpCodes();
- String slashedName = "org/apache/cxf/jaxb/EclipseNamespaceMapper";
- ASMHelper.ClassWriter cw = helper.createClassWriter();
- if (cw == null) {
- return null;
- }
- String superName = "org/eclipse/persistence/internal/oxm/record/namespaces/MapNamespacePrefixMapper";
- ASMHelper.FieldVisitor fv;
- ASMHelper.MethodVisitor mv;
- cw.visit(Opcodes.V1_6,
- Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL + Opcodes.ACC_SUPER,
- slashedName, null,
- superName, null);
-
- cw.visitSource("EclipseNamespaceMapper.java", null);
-
- fv = cw.visitField(Opcodes.ACC_PRIVATE, "nsctxt", "[Ljava/lang/String;", null, null);
- fv.visitEnd();
-
-
- mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "<init>", "(Ljava/util/Map;)V",
- "(Ljava/util/Map<Ljava/lang/String;Ljava/lang/String;>;)V", null);
- mv.visitCode();
- ASMHelper.Label l0 = helper.createLabel();
- mv.visitLabel(l0);
- mv.visitVarInsn(Opcodes.ALOAD, 0);
- mv.visitVarInsn(Opcodes.ALOAD, 1);
- mv.visitMethodInsn(Opcodes.INVOKESPECIAL,
- superName, "<init>", "(Ljava/util/Map;)V", false);
- ASMHelper.Label l1 = helper.createLabel();
- mv.visitLabel(l1);
- mv.visitInsn(Opcodes.RETURN);
- ASMHelper.Label l2 = helper.createLabel();
- mv.visitLabel(l2);
- mv.visitMaxs(0, 0);
- mv.visitEnd();
-
-
- mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "setContextualNamespaceDecls", "([Ljava/lang/String;)V",
- null, null);
- mv.visitCode();
- l0 = helper.createLabel();
- mv.visitLabel(l0);
- mv.visitLineNumber(47, l0);
- mv.visitVarInsn(Opcodes.ALOAD, 0);
- mv.visitVarInsn(Opcodes.ALOAD, 1);
- mv.visitFieldInsn(Opcodes.PUTFIELD, slashedName, "nsctxt", "[Ljava/lang/String;");
- l1 = helper.createLabel();
- mv.visitLabel(l1);
- mv.visitLineNumber(48, l1);
- mv.visitInsn(Opcodes.RETURN);
- l2 = helper.createLabel();
- mv.visitLabel(l2);
- mv.visitLocalVariable("this", "L" + slashedName + ";", null, l0, l2, 0);
- mv.visitLocalVariable("contextualNamespaceDecls", "[Ljava/lang/String;", null, l0, l2, 1);
- mv.visitMaxs(0, 0);
- mv.visitEnd();
-
- mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "getContextualNamespaceDecls", "()[Ljava/lang/String;", null, null);
- mv.visitCode();
- l0 = helper.createLabel();
- mv.visitLabel(l0);
- mv.visitLineNumber(51, l0);
- mv.visitVarInsn(Opcodes.ALOAD, 0);
- mv.visitFieldInsn(Opcodes.GETFIELD, slashedName, "nsctxt", "[Ljava/lang/String;");
- mv.visitInsn(Opcodes.ARETURN);
- l1 = helper.createLabel();
-
- mv.visitLabel(l1);
- mv.visitLocalVariable("this", "L" + slashedName + ";", null, l0, l1, 0);
-
- mv.visitMaxs(0, 0);
- mv.visitEnd();
-
-
- mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "getPreDeclaredNamespaceUris", "()[Ljava/lang/String;", null, null);
- mv.visitCode();
- l0 = helper.createLabel();
- mv.visitLabel(l0);
- mv.visitLineNumber(1036, l0);
- mv.visitVarInsn(Opcodes.ALOAD, 0);
- mv.visitMethodInsn(Opcodes.INVOKESPECIAL,
- superName,
- "getPreDeclaredNamespaceUris", "()[Ljava/lang/String;", false);
- mv.visitVarInsn(Opcodes.ASTORE, 1);
- l1 = helper.createLabel();
- mv.visitLabel(l1);
- mv.visitLineNumber(1037, l1);
- mv.visitVarInsn(Opcodes.ALOAD, 0);
- mv.visitFieldInsn(Opcodes.GETFIELD, slashedName, "nsctxt", "[Ljava/lang/String;");
- l2 = helper.createLabel();
- mv.visitJumpInsn(Opcodes.IFNONNULL, l2);
- ASMHelper.Label l3 = helper.createLabel();
- mv.visitLabel(l3);
- mv.visitLineNumber(1038, l3);
- mv.visitVarInsn(Opcodes.ALOAD, 1);
- mv.visitInsn(Opcodes.ARETURN);
- mv.visitLabel(l2);
- mv.visitLineNumber(1040, l2);
- mv.visitFrame(Opcodes.F_APPEND, 1, new Object[] {"[Ljava/lang/String;"}, 0, null);
- mv.visitTypeInsn(Opcodes.NEW, "java/util/ArrayList");
- mv.visitInsn(Opcodes.DUP);
- mv.visitVarInsn(Opcodes.ALOAD, 1);
- mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/util/Arrays", "asList",
- "([Ljava/lang/Object;)Ljava/util/List;", false);
- mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/util/ArrayList", "<init>",
- "(Ljava/util/Collection;)V", false);
- mv.visitVarInsn(Opcodes.ASTORE, 2);
- ASMHelper.Label l4 = helper.createLabel();
- mv.visitLabel(l4);
- mv.visitLineNumber(1041, l4);
- mv.visitInsn(Opcodes.ICONST_1);
- mv.visitVarInsn(Opcodes.ISTORE, 3);
- ASMHelper.Label l5 = helper.createLabel();
- mv.visitLabel(l5);
- ASMHelper.Label l6 = helper.createLabel();
- mv.visitJumpInsn(Opcodes.GOTO, l6);
- ASMHelper.Label l7 = helper.createLabel();
- mv.visitLabel(l7);
- mv.visitLineNumber(1042, l7);
- mv.visitFrame(Opcodes.F_APPEND, 2, new Object[] {"java/util/List", Opcodes.INTEGER}, 0, null);
- mv.visitVarInsn(Opcodes.ALOAD, 2);
- mv.visitVarInsn(Opcodes.ALOAD, 0);
- mv.visitFieldInsn(Opcodes.GETFIELD, slashedName, "nsctxt", "[Ljava/lang/String;");
- mv.visitVarInsn(Opcodes.ILOAD, 3);
- mv.visitInsn(Opcodes.AALOAD);
- mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/util/List", "remove", "(Ljava/lang/Object;)Z", true);
- mv.visitInsn(Opcodes.POP);
- ASMHelper.Label l8 = helper.createLabel();
- mv.visitLabel(l8);
- mv.visitLineNumber(1041, l8);
- mv.visitIincInsn(3, 2);
- mv.visitLabel(l6);
- mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
- mv.visitVarInsn(Opcodes.ILOAD, 3);
- mv.visitVarInsn(Opcodes.ALOAD, 0);
- mv.visitFieldInsn(Opcodes.GETFIELD,
- slashedName,
- "nsctxt", "[Ljava/lang/String;");
- mv.visitInsn(Opcodes.ARRAYLENGTH);
- mv.visitJumpInsn(Opcodes.IF_ICMPLT, l7);
- ASMHelper.Label l9 = helper.createLabel();
- mv.visitLabel(l9);
- mv.visitLineNumber(1044, l9);
- mv.visitVarInsn(Opcodes.ALOAD, 2);
- mv.visitVarInsn(Opcodes.ALOAD, 2);
- mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/util/List", "size", "()I", true);
- mv.visitTypeInsn(Opcodes.ANEWARRAY, "java/lang/String");
- mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/util/List",
- "toArray", "([Ljava/lang/Object;)[Ljava/lang/Object;", true);
- mv.visitTypeInsn(Opcodes.CHECKCAST, "[Ljava/lang/String;");
- mv.visitInsn(Opcodes.ARETURN);
- ASMHelper.Label l10 = helper.createLabel();
- mv.visitLabel(l10);
- mv.visitLocalVariable("this", "L" + slashedName + ";",
- null, l0, l10, 0);
- mv.visitLocalVariable("sup", "[Ljava/lang/String;", null, l1, l10, 1);
- mv.visitLocalVariable("s", "Ljava/util/List;", "Ljava/util/List<Ljava/lang/String;>;", l4, l10, 2);
- mv.visitLocalVariable("x", "I", null, l5, l9, 3);
- mv.visitMaxs(0, 0);
- mv.visitEnd();
-
- cw.visitEnd();
-
- return cw.toByteArray();
- }
-
- private byte[] createNamespaceWrapperInternal(String postFix) {
-
- String superName = "com/sun/xml/"
- + ("RI".equals(postFix) ? "" : "internal/")
- + "bind/marshaller/NamespacePrefixMapper";
- String postFixedName = "org/apache/cxf/jaxb/NamespaceMapper" + postFix;
- ASMHelper.ClassWriter cw = helper.createClassWriter();
- if (cw == null) {
- return null;
- }
- ASMHelper.FieldVisitor fv;
- ASMHelper.MethodVisitor mv;
- OpcodesProxy opcodes= helper.getOpCodes();
- cw.visit(opcodes.V1_6,
- opcodes.ACC_PUBLIC + opcodes.ACC_FINAL + opcodes.ACC_SUPER,
- postFixedName, null,
- superName, null);
-
- cw.visitSource("NamespaceMapper.java", null);
-
- fv = cw.visitField(opcodes.ACC_PRIVATE + opcodes.ACC_FINAL,
- "nspref", "Ljava/util/Map;",
- "Ljava/util/Map<Ljava/lang/String;Ljava/lang/String;>;", null);
- fv.visitEnd();
-
- fv = cw.visitField(opcodes.ACC_PRIVATE, "nsctxt", "[Ljava/lang/String;", null, null);
- fv.visitEnd();
-
- fv = cw.visitField(opcodes.ACC_PRIVATE + opcodes.ACC_FINAL + opcodes.ACC_STATIC,
- "EMPTY_STRING", "[Ljava/lang/String;", null, null);
- fv.visitEnd();
-
- mv = cw.visitMethod(opcodes.ACC_STATIC, "<clinit>", "()V", null, null);
- mv.visitCode();
- ASMHelper.Label l0 = helper.createLabel();
- mv.visitLabel(l0);
- mv.visitLineNumber(30, l0);
- mv.visitInsn(opcodes.ICONST_0);
- mv.visitTypeInsn(opcodes.ANEWARRAY, "java/lang/String");
- mv.visitFieldInsn(opcodes.PUTSTATIC, postFixedName, "EMPTY_STRING", "[Ljava/lang/String;");
- mv.visitInsn(opcodes.RETURN);
- mv.visitMaxs(0, 0);
- mv.visitEnd();
-
- mv = cw.visitMethod(opcodes.ACC_PUBLIC, "<init>",
- "(Ljava/util/Map;)V",
- "(Ljava/util/Map<Ljava/lang/String;Ljava/lang/String;>;)V", null);
- mv.visitCode();
- l0 = helper.createLabel();
- mv.visitLabel(l0);
- mv.visitLineNumber(32, l0);
- mv.visitVarInsn(opcodes.ALOAD, 0);
- mv.visitMethodInsn(opcodes.INVOKESPECIAL, superName, "<init>", "()V", false);
- ASMHelper.Label l1 = helper.createLabel();
- mv.visitLabel(l1);
- mv.visitLineNumber(29, l1);
- mv.visitVarInsn(opcodes.ALOAD, 0);
- mv.visitFieldInsn(opcodes.GETSTATIC, postFixedName, "EMPTY_STRING", "[Ljava/lang/String;");
- mv.visitFieldInsn(opcodes.PUTFIELD, postFixedName, "nsctxt", "[Ljava/lang/String;");
- ASMHelper.Label l2 = helper.createLabel();
- mv.visitLabel(l2);
- mv.visitLineNumber(33, l2);
- mv.visitVarInsn(opcodes.ALOAD, 0);
- mv.visitVarInsn(opcodes.ALOAD, 1);
- mv.visitFieldInsn(opcodes.PUTFIELD, postFixedName, "nspref", "Ljava/util/Map;");
- ASMHelper.Label l3 = helper.createLabel();
- mv.visitLabel(l3);
- mv.visitLineNumber(34, l3);
- mv.visitInsn(opcodes.RETURN);
- ASMHelper.Label l4 = helper.createLabel();
- mv.visitLabel(l4);
- mv.visitLocalVariable("this", "L" + postFixedName + ";", null, l0, l4, 0);
- mv.visitLocalVariable("nspref",
- "Ljava/util/Map;", "Ljava/util/Map<Ljava/lang/String;Ljava/lang/String;>;",
- l0, l4, 1);
- mv.visitMaxs(0, 0);
- mv.visitEnd();
-
- mv = cw.visitMethod(opcodes.ACC_PUBLIC, "getPreferredPrefix",
- "(Ljava/lang/String;Ljava/lang/String;Z)Ljava/lang/String;",
- null, null);
- mv.visitCode();
- l0 = helper.createLabel();
- mv.visitLabel(l0);
- mv.visitLineNumber(39, l0);
- mv.visitVarInsn(opcodes.ALOAD, 0);
- mv.visitFieldInsn(opcodes.GETFIELD, postFixedName, "nspref", "Ljava/util/Map;");
- mv.visitVarInsn(opcodes.ALOAD, 1);
- mv.visitMethodInsn(opcodes.INVOKEINTERFACE, "java/util/Map",
- "get", "(Ljava/lang/Object;)Ljava/lang/Object;", true);
- mv.visitTypeInsn(opcodes.CHECKCAST, "java/lang/String");
- mv.visitVarInsn(opcodes.ASTORE, 4);
- l1 = helper.createLabel();
- mv.visitLabel(l1);
- mv.visitLineNumber(40, l1);
- mv.visitVarInsn(opcodes.ALOAD, 4);
- l2 = helper.createLabel();
- mv.visitJumpInsn(opcodes.IFNULL, l2);
- l3 = helper.createLabel();
- mv.visitLabel(l3);
- mv.visitLineNumber(41, l3);
- mv.visitVarInsn(opcodes.ALOAD, 4);
- mv.visitInsn(opcodes.ARETURN);
- mv.visitLabel(l2);
- mv.visitLineNumber(43, l2);
- mv.visitFrame(opcodes.F_APPEND, 1, new Object[] {"java/lang/String"}, 0, null);
- mv.visitVarInsn(opcodes.ALOAD, 2);
- mv.visitInsn(opcodes.ARETURN);
- l4 = helper.createLabel();
- mv.visitLabel(l4);
- mv.visitLocalVariable("this", "L" + postFixedName + ";", null, l0, l4, 0);
- mv.visitLocalVariable("namespaceUri", "Ljava/lang/String;", null, l0, l4, 1);
- mv.visitLocalVariable("suggestion", "Ljava/lang/String;", null, l0, l4, 2);
- mv.visitLocalVariable("requirePrefix", "Z", null, l0, l4, 3);
- mv.visitLocalVariable("prefix", "Ljava/lang/String;", null, l1, l4, 4);
- mv.visitMaxs(0, 0);
- mv.visitEnd();
-
- mv = cw.visitMethod(opcodes.ACC_PUBLIC, "setContextualNamespaceDecls", "([Ljava/lang/String;)V", null, null);
- mv.visitCode();
- l0 = helper.createLabel();
- mv.visitLabel(l0);
- mv.visitLineNumber(47, l0);
- mv.visitVarInsn(opcodes.ALOAD, 0);
- mv.visitVarInsn(opcodes.ALOAD, 1);
- mv.visitFieldInsn(opcodes.PUTFIELD, postFixedName, "nsctxt", "[Ljava/lang/String;");
- l1 = helper.createLabel();
- mv.visitLabel(l1);
- mv.visitLineNumber(48, l1);
- mv.visitInsn(opcodes.RETURN);
- l2 = helper.createLabel();
- mv.visitLabel(l2);
- mv.visitLocalVariable("this", "L" + postFixedName + ";", null, l0, l2, 0);
- mv.visitLocalVariable("contextualNamespaceDecls", "[Ljava/lang/String;", null, l0, l2, 1);
- mv.visitMaxs(0, 0);
- mv.visitEnd();
-
- mv = cw.visitMethod(opcodes.ACC_PUBLIC, "getContextualNamespaceDecls", "()[Ljava/lang/String;", null, null);
- mv.visitCode();
- l0 = helper.createLabel();
- mv.visitLabel(l0);
- mv.visitLineNumber(51, l0);
- mv.visitVarInsn(opcodes.ALOAD, 0);
- mv.visitFieldInsn(opcodes.GETFIELD, postFixedName, "nsctxt", "[Ljava/lang/String;");
- mv.visitInsn(opcodes.ARETURN);
- l1 = helper.createLabel();
-
- mv.visitLabel(l1);
- mv.visitLocalVariable("this", "L" + postFixedName + ";", null, l0, l1, 0);
-
- mv.visitMaxs(0, 0);
- mv.visitEnd();
-
- cw.visitEnd();
-
- return cw.toByteArray();
- }
- //CHECKSTYLE:ON
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/common/util/ASMHelperImpl.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/common/util/ASMHelperImpl.java
deleted file mode 100644
index cc01f14..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/common/util/ASMHelperImpl.java
+++ /dev/null
@@ -1,273 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.cxf.common.util;
-
-import java.lang.reflect.Constructor;
-import java.lang.reflect.GenericArrayType;
-import java.lang.reflect.Method;
-import java.lang.reflect.ParameterizedType;
-import java.lang.reflect.TypeVariable;
-import java.lang.reflect.WildcardType;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.apache.cxf.common.classloader.ClassLoaderUtils;
-
-
-public class ASMHelperImpl implements ASMHelper {
- protected static final Map<Class<?>, String> PRIMITIVE_MAP = new HashMap<>();
- protected static final Map<Class<?>, String> NONPRIMITIVE_MAP = new HashMap<>();
- protected static final Map<Class<?>, Integer> PRIMITIVE_ZERO_MAP = new HashMap<>();
-
- protected boolean badASM;
- private Class<?> cwClass;
-
- public ASMHelperImpl() {
-
- }
-
- static {
- PRIMITIVE_MAP.put(Byte.TYPE, "B");
- PRIMITIVE_MAP.put(Boolean.TYPE, "Z");
- PRIMITIVE_MAP.put(Long.TYPE, "J");
- PRIMITIVE_MAP.put(Integer.TYPE, "I");
- PRIMITIVE_MAP.put(Short.TYPE, "S");
- PRIMITIVE_MAP.put(Character.TYPE, "C");
- PRIMITIVE_MAP.put(Float.TYPE, "F");
- PRIMITIVE_MAP.put(Double.TYPE, "D");
-
- NONPRIMITIVE_MAP.put(Byte.TYPE, Byte.class.getName().replaceAll("\\.", "/"));
- NONPRIMITIVE_MAP.put(Boolean.TYPE, Boolean.class.getName().replaceAll("\\.", "/"));
- NONPRIMITIVE_MAP.put(Long.TYPE, Long.class.getName().replaceAll("\\.", "/"));
- NONPRIMITIVE_MAP.put(Integer.TYPE, Integer.class.getName().replaceAll("\\.", "/"));
- NONPRIMITIVE_MAP.put(Short.TYPE, Short.class.getName().replaceAll("\\.", "/"));
- NONPRIMITIVE_MAP.put(Character.TYPE, Character.class.getName().replaceAll("\\.", "/"));
- NONPRIMITIVE_MAP.put(Float.TYPE, Float.class.getName().replaceAll("\\.", "/"));
- NONPRIMITIVE_MAP.put(Double.TYPE, Double.class.getName().replaceAll("\\.", "/"));
- }
-
- private void tryClass(String s) {
- if (cwClass == null) {
- try {
- Class<?> c2 = ClassLoaderUtils.loadClass(s, ASMHelperImpl.class);
-
- //old versions don't have this, but we need it
- Class<?> cls = ClassLoaderUtils.loadClass(c2.getPackage().getName() + ".MethodVisitor", c2);
- cls.getMethod("visitFrame", Integer.TYPE, Integer.TYPE,
- Object[].class, Integer.TYPE, Object[].class);
- cwClass = c2;
- } catch (Throwable t) {
- //ignore
- }
- }
- }
- private Class<?> getASMClassWriterClass() {
- //force this to make sure the proper OSGi import is generated
- return org.objectweb.asm.ClassWriter.class;
- }
-
- public synchronized Class<?> getASMClass() throws ClassNotFoundException {
- if (cwClass == null) {
- //try the "real" asm first, then the others
- tryClass("org.objectweb.asm.ClassWriter");
- tryClass("org.apache.xbean.asm9.ClassWriter");
- tryClass("org.apache.xbean.asm8.ClassWriter");
- tryClass("org.apache.xbean.asm7.ClassWriter");
- tryClass("org.apache.xbean.asm5.ClassWriter");
- tryClass("org.apache.xbean.asm6.ClassWriter");
- tryClass("org.apache.xbean.asm4.ClassWriter");
- tryClass("org.apache.xbean.asm.ClassWriter");
- tryClass("org.springframework.asm.ClassWriter");
- if (cwClass == null) {
- cwClass = getASMClassWriterClass();
- }
- }
- return cwClass;
- }
- public OpcodesProxy getOpCodes() {
- OpcodesProxy ops = new OpcodesProxy(this);
- PRIMITIVE_ZERO_MAP.put(Byte.TYPE, ops.ICONST_0);
- PRIMITIVE_ZERO_MAP.put(Boolean.TYPE, ops.ICONST_0);
- PRIMITIVE_ZERO_MAP.put(Long.TYPE, ops.LCONST_0);
- PRIMITIVE_ZERO_MAP.put(Integer.TYPE, ops.ICONST_0);
- PRIMITIVE_ZERO_MAP.put(Short.TYPE, ops.ICONST_0);
- PRIMITIVE_ZERO_MAP.put(Character.TYPE, ops.ICONST_0);
- PRIMITIVE_ZERO_MAP.put(Float.TYPE, ops.FCONST_0);
- PRIMITIVE_ZERO_MAP.put(Double.TYPE, ops.DCONST_0);
- return ops;
- }
- public void setBadASM(boolean b) {
- badASM = b;
- }
-
- public String getMethodSignature(Method m) {
- StringBuilder buf = new StringBuilder("(");
- for (Class<?> cl : m.getParameterTypes()) {
- buf.append(getClassCode(cl));
- }
- buf.append(')');
- buf.append(getClassCode(m.getReturnType()));
-
- return buf.toString();
- }
-
- @Override
- public String getNonPrimitive(Class<?> tp) {
- return NONPRIMITIVE_MAP.get(tp);
- }
- @Override
- public String getPrimitive(Class<?> tp) {
- return PRIMITIVE_MAP.get(tp);
- }
-
-
-
-
- public String getClassCode(Class<?> cl) {
- if (cl == Void.TYPE) {
- return "V";
- }
- if (cl.isPrimitive()) {
- return PRIMITIVE_MAP.get(cl);
- }
- if (cl.isArray()) {
- return "[" + getClassCode(cl.getComponentType());
- }
- return "L" + StringUtils.periodToSlashes(cl.getName()) + ";";
- }
- public String getClassCode(java.lang.reflect.Type type) {
- if (type instanceof Class) {
- return getClassCode((Class<?>)type);
- } else if (type instanceof GenericArrayType) {
- GenericArrayType at = (GenericArrayType)type;
- return "[" + getClassCode(at.getGenericComponentType());
- } else if (type instanceof TypeVariable) {
- TypeVariable<?> tv = (TypeVariable<?>)type;
- java.lang.reflect.Type[] bounds = tv.getBounds();
- if (bounds != null && bounds.length == 1) {
- return getClassCode(bounds[0]);
- }
- throw new IllegalArgumentException("Unable to determine type for: " + tv);
- } else if (type instanceof ParameterizedType) {
- ParameterizedType pt = (ParameterizedType)type;
- StringBuilder a = new StringBuilder(getClassCode(pt.getRawType()));
- if (!pt.getRawType().equals(Enum.class)) {
- a.setLength(a.length() - 1);
- a.append('<');
-
- for (java.lang.reflect.Type t : pt.getActualTypeArguments()) {
- a.append(getClassCode(t));
- }
- a.append(">;");
- }
- return a.toString();
- } else if (type instanceof WildcardType) {
- WildcardType wt = (WildcardType)type;
- StringBuilder a = new StringBuilder();
- java.lang.reflect.Type[] lowBounds = wt.getLowerBounds();
- java.lang.reflect.Type[] upBounds = wt.getUpperBounds();
- for (java.lang.reflect.Type t : upBounds) {
- a.append('+');
- a.append(getClassCode(t));
- }
- for (java.lang.reflect.Type t : lowBounds) {
- a.append('-');
- a.append(getClassCode(t));
- }
- return a.toString();
- }
- return null;
- }
-
- public ClassWriter createClassWriter() {
- Object newCw = null;
- if (!badASM) {
- if (cwClass == null) {
- try {
- cwClass = getASMClass();
- } catch (Throwable error) {
- badASM = true;
- throw new RuntimeException("No ASM ClassWriterFound", error);
- }
- }
- // ASM >= 3.x (since cxf is java 8 min we don't care of asm 1/2)
- try {
- Constructor<?> cons = cwClass.getConstructor(Integer.TYPE);
- int i = cwClass.getField("COMPUTE_MAXS").getInt(null);
- i |= cwClass.getField("COMPUTE_FRAMES").getInt(null);
- newCw = cons.newInstance(Integer.valueOf(i));
- } catch (Throwable e1) {
- // ignore
- }
- }
- if (newCw != null) {
- return ReflectionInvokationHandler.createProxyWrapper(newCw, ClassWriter.class);
- }
- return null;
- }
-
-
- public ASMType getType(final String type) {
- try {
- final Class<?> cls = ClassLoaderUtils.loadClass(cwClass.getPackage().getName() + ".Type", cwClass);
- final Method m = cls.getMethod("getType", String.class);
- final Method m2 = cls.getMethod("getOpcode", Integer.TYPE);
- @SuppressWarnings("unused")
- ASMType t = new ASMType() {
- Object tp = ReflectionUtil.setAccessible(m).invoke(null, type);
- public Object getValue() {
- return tp;
- }
- public Class<?> realType() {
- return cls;
- }
- public int getOpcode(int ireturn) {
- try {
- return (Integer)ReflectionUtil.setAccessible(m2).invoke(tp, ireturn);
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- }
- };
- return t;
- } catch (Exception ex) {
- throw new RuntimeException(ex);
- }
- }
- public Label createLabel() {
- try {
- final Class<?> cls = ClassLoaderUtils.loadClass(cwClass.getPackage().getName() + ".Label",
- cwClass);
- @SuppressWarnings("unused")
- Label l = new Label() {
- Object l = cls.newInstance();
- public Object getValue() {
- return l;
- }
- public Class<?> realType() {
- return cls;
- }
- };
- return l;
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- }
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/common/util/Base64Utility.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/common/util/Base64Utility.java
deleted file mode 100644
index 043eba7..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/common/util/Base64Utility.java
+++ /dev/null
@@ -1,474 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.cxf.common.util;
-
-/**
- * Base64Utility - this static class provides useful base64
- * encoding utilities.
- */
-
-// Java imports
-import java.io.IOException;
-import java.io.OutputStream;
-import java.io.Writer;
-import java.nio.CharBuffer;
-import java.nio.charset.StandardCharsets;
-import java.util.Arrays;
-import java.util.logging.Logger;
-
-import org.apache.cxf.common.i18n.Message;
-import org.apache.cxf.common.logging.LogUtils;
-
-
-/**
- * This class converts to/from base64. The alternative conversions include:
- *
- * encode:
- * byte[] into String
- * byte[] into char[]
- * byte[] into OutStream
- * byte[] into Writer
- * decode:
- * char[] into byte[]
- * String into byte[]
- * char[] into OutStream
- * String into OutStream
- *
- */
-public final class Base64Utility {
-
- private static final Logger LOG = LogUtils.getL7dLogger(Base64Utility.class);
-
-
- // base 64 character set
- //
- private static final char[] BCS = {
- 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
- 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T',
- 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd',
- 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
- 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x',
- 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7',
- '8', '9', '+', '/'
- };
-
- private static final char[] BCS_URL_SAFE = Arrays.copyOf(BCS, BCS.length);
-
- // base 64 padding
- private static final char PAD = '=';
-
- // size of base 64 decode table
- private static final int BDTSIZE = 128;
-
- // base 64 decode table
- private static final byte[] BDT = new byte[128];
-
-
- private static final int PAD_SIZE0 = 1;
- private static final int PAD_SIZE4 = 2;
- private static final int PAD_SIZE8 = 3;
-
- // class static initializer for building decode table
- static {
- for (int i = 0; i < BDTSIZE; i++) {
- BDT[i] = Byte.MAX_VALUE;
- }
-
- for (int i = 0; i < BCS.length; i++) {
- BDT[BCS[i]] = (byte)i;
- }
-
- BCS_URL_SAFE[62] = '-';
- BCS_URL_SAFE[63] = '_';
- }
-
-
- private Base64Utility() {
- //utility class, never constructed
- }
-
-
-
- /**
- * The <code>decode_chunk</code> routine decodes a chunk of data
- * into its native encoding.
- *
- * base64 encodes each 3 octets of data into 4 characters from a
- * limited 64 character set. The 3 octets are joined to form
- * 24 bits which are then split into 4 x 6bit values. Each 6 bit
- * value is then used as an index into the 64 character table of
- * base64 chars. If the total data length is not a 3 octet multiple
- * the '=' char is used as padding for the final 4 char group,
- * either 1 octet + '==' or 2 octets + '='.
- *
- * @param id The input data to be processed
- * @param o The offset from which to begin processing
- * @param l The length (bound) at which processing is to end
- * @return The decoded data
- * @exception Base64Exception Thrown is processing fails due to
- * formatting exceptions in the encoded data
- */
- public static byte[] decodeChunk(char[] id,
- int o,
- int l)
- throws Base64Exception {
-
- if (id != null && id.length == 0 && l == 0) {
- return new byte[0];
- }
-
- // Keep it simple - must be >= 4. Unpadded
- // base64 data contain < 3 octets is invalid.
- //
- if ((l - o) < 4) {
- return null;
- }
-
- char[] ib = new char[4];
- int ibcount = 0;
-
- // cryan. Calc the num of octets. Each 4 chars of base64 chars
- // (representing 24 bits) encodes 3 octets.
- //
- int octetCount = 3 * (l / 4);
-
- // Final 4 chars may contain 3 octets or padded to contain
- // 1 or 2 octets.
- //
- if (id[l - 1] == PAD) {
- // TT== means last 4 chars encode 8 bits (ie subtract 2)
- // TTT= means last 4 chars encode 16 bits (ie subtract 1)
- octetCount -= (id[l - 2] == PAD) ? 2 : 1;
- }
-
- byte[] ob = new byte[octetCount];
- int obcount = 0;
-
- for (int i = o; i < o + l && i < id.length; i++) {
- if (id[i] == PAD
- || id[i] < BDT.length
- && BDT[id[i]] != Byte.MAX_VALUE) {
-
- ib[ibcount++] = id[i];
-
- // Decode each 4 char sequence.
- //
- if (ibcount == ib.length) {
- ibcount = 0;
- obcount += processEncodeme(ib, ob, obcount);
- }
- }
- }
-
- if (obcount != ob.length) {
- byte []tmp = new byte[obcount];
- System.arraycopy(ob, 0, tmp, 0, obcount);
- ob = tmp;
- }
-
- return ob;
- }
-
- public static byte[] decode(String id) throws Base64Exception {
- return decode(id, false);
- }
-
- public static byte[] decode(String id, boolean urlSafe) throws Base64Exception {
- if (urlSafe) {
- id = id.replace('-', '+').replace('_', '/');
- switch (id.length() % 4) {
- case 0:
- break;
- case 2:
- id += "==";
- break;
- case 3:
- id += "=";
- break;
- default:
- throw new Base64Exception(new Message("BASE64_RUNTIME_EXCEPTION", LOG));
- }
- }
- try {
- char[] cd = id.toCharArray();
- return decodeChunk(cd, 0, cd.length);
- } catch (Exception e) {
- LOG.warning("Invalid base64 encoded string : " + id);
- throw new Base64Exception(new Message("BASE64_RUNTIME_EXCEPTION", LOG), e);
- }
- }
-
- public static void decode(char[] id,
- int o,
- int l,
- OutputStream ostream)
- throws Base64Exception {
-
- try {
- ostream.write(decodeChunk(id, o, l));
- } catch (Exception e) {
- LOG.warning("Invalid base64 encoded string : " + new String(id));
- throw new Base64Exception(new Message("BASE64_RUNTIME_EXCEPTION", LOG), e);
- }
- }
-
- public static void decode(String id,
- OutputStream ostream)
- throws Base64Exception {
-
- try {
- char[] cd = id.toCharArray();
- ostream.write(decodeChunk(cd, 0, cd.length));
- } catch (IOException ioe) {
- throw new Base64Exception(new Message("BASE64_DECODE_IOEXCEPTION", LOG), ioe);
- } catch (Exception e) {
- LOG.warning("Invalid base64 encoded string : " + id);
- throw new Base64Exception(new Message("BASE64_RUNTIME_EXCEPTION", LOG), e);
- }
- }
-
- // Returns base64 representation of specified byte array.
- //
- public static String encode(byte[] id) {
- return encode(id, false);
- }
-
- public static String encode(byte[] id, boolean urlSafe) {
- char[] cd = encodeChunk(id, 0, id.length);
- return new String(cd, 0, cd.length);
- }
-
- // Returns base64 representation of specified byte array.
- //
- public static char[] encodeChunk(byte[] id,
- int o,
- int l) {
- return encodeChunk(id, o, l, false);
- }
-
- public static char[] encodeChunk(byte[] id,
- int o,
- int l,
- boolean urlSafe) {
- if (id != null && id.length == 0 && l == 0) {
- return new char[0];
- } else if (l <= 0) {
- return null;
- }
-
- char[] out;
-
- // If not a multiple of 3 octets then a final padded 4 char
- // slot is needed.
- //
- if (l % 3 == 0) {
- out = new char[l / 3 * 4];
- } else {
- int finalLen = !urlSafe ? 4 : l % 3 == 1 ? 2 : 3;
- out = new char[l / 3 * 4 + finalLen];
- }
-
- int rindex = o;
- int windex = 0;
- int rest = l;
-
- final char[] base64Table = urlSafe ? BCS_URL_SAFE : BCS;
- while (rest >= 3) {
- int i = ((id[rindex] & 0xff) << 16)
- + ((id[rindex + 1] & 0xff) << 8)
- + (id[rindex + 2] & 0xff);
-
- out[windex++] = base64Table[i >> 18];
- out[windex++] = base64Table[(i >> 12) & 0x3f];
- out[windex++] = base64Table[(i >> 6) & 0x3f];
- out[windex++] = base64Table[i & 0x3f];
- rindex += 3;
- rest -= 3;
- }
-
- if (rest == 1) {
- int i = id[rindex] & 0xff;
- out[windex++] = base64Table[i >> 2];
- out[windex++] = base64Table[(i << 4) & 0x3f];
- if (!urlSafe) {
- out[windex++] = PAD;
- out[windex] = PAD;
- }
- } else if (rest == 2) {
- int i = ((id[rindex] & 0xff) << 8) + (id[rindex + 1] & 0xff);
- out[windex++] = base64Table[i >> 10];
- out[windex++] = base64Table[(i >> 4) & 0x3f];
- out[windex++] = base64Table[(i << 2) & 0x3f];
- if (!urlSafe) {
- out[windex] = PAD;
- }
- }
- return out;
- }
-
- public static void encodeAndStream(byte[] id,
- int o,
- int l,
- OutputStream os) throws IOException {
- encodeAndStream(id, o, l, false, os);
- }
-
- public static void encodeAndStream(byte[] id,
- int o,
- int l,
- boolean urlSafe,
- OutputStream os) throws IOException {
- if (l <= 0) {
- return;
- }
-
- int rindex = o;
- int rest = l;
- final char[] base64Table = urlSafe ? BCS_URL_SAFE : BCS;
-
- char[] chunk = new char[4];
- while (rest >= 3) {
- int i = ((id[rindex] & 0xff) << 16)
- + ((id[rindex + 1] & 0xff) << 8)
- + (id[rindex + 2] & 0xff);
- chunk[0] = base64Table[i >> 18];
- chunk[1] = base64Table[(i >> 12) & 0x3f];
- chunk[2] = base64Table[(i >> 6) & 0x3f];
- chunk[3] = base64Table[i & 0x3f];
- writeCharArrayToStream(chunk, 4, os);
- rindex += 3;
- rest -= 3;
- }
- if (rest == 0) {
- return;
- }
- if (rest == 1) {
- int i = id[rindex] & 0xff;
- chunk[0] = base64Table[i >> 2];
- chunk[1] = base64Table[(i << 4) & 0x3f];
- if (!urlSafe) {
- chunk[2] = PAD;
- chunk[3] = PAD;
- }
- } else if (rest == 2) {
- int i = ((id[rindex] & 0xff) << 8) + (id[rindex + 1] & 0xff);
- chunk[0] = base64Table[i >> 10];
- chunk[1] = base64Table[(i >> 4) & 0x3f];
- chunk[2] = base64Table[(i << 2) & 0x3f];
- if (!urlSafe) {
- chunk[3] = PAD;
- }
- }
- int finalLenToWrite = !urlSafe ? 4 : rest == 1 ? 2 : 3;
- writeCharArrayToStream(chunk, finalLenToWrite, os);
- }
-
- private static void writeCharArrayToStream(char[] chunk, int len, OutputStream os) throws IOException {
- // may be we can just cast to byte when creating chunk[] earlier on
- byte[] bytes = StandardCharsets.UTF_8.encode(CharBuffer.wrap(chunk, 0, len)).array();
- os.write(bytes);
- }
-
- //
- // Outputs base64 representation of the specified byte array
- // to a byte stream.
- //
- public static void encodeChunk(byte[] id,
- int o,
- int l,
- OutputStream ostream) throws Base64Exception {
- try {
- ostream.write(new String(encodeChunk(id, o, l)).getBytes());
- } catch (IOException e) {
- throw new Base64Exception(new Message("BASE64_ENCODE_IOEXCEPTION", LOG), e);
- }
- }
-
- // Outputs base64 representation of the specified byte
- // array to a character stream.
- //
- public static void encode(byte[] id,
- int o,
- int l,
- Writer writer) throws Base64Exception {
- try {
- writer.write(encodeChunk(id, o, l));
- } catch (IOException e) {
- throw new Base64Exception(new Message("BASE64_ENCODE_WRITER_IOEXCEPTION", LOG), e);
- }
- }
- //---- Private static methods --------------------------------------
-
- /**
- * The <code>process</code> routine processes an atomic base64
- * unit of encoding (encodeme) into its native encoding. This class is
- * used by decode routines to do the grunt work of decoding
- * base64 encoded information
- *
- * @param ib Input character buffer of encoded bytes
- * @param ob Output byte buffer of decoded bytes
- * @param p Pointer to the encodeme of interest
- * @return The decoded encodeme
- * @exception Base64Exception Thrown is processing fails due to
- * formatting exceptions in the encoded data
- */
- private static int processEncodeme(char[] ib,
- byte[] ob,
- int p)
- throws Base64Exception {
-
-
- int spad = PAD_SIZE8;
- if (ib[3] == PAD) {
- spad = PAD_SIZE4;
- }
- if (ib[2] == PAD) {
- spad = PAD_SIZE0;
- }
-
- int b0 = BDT[ib[0]];
- int b1 = BDT[ib[1]];
- int b2 = BDT[ib[2]];
- int b3 = BDT[ib[3]];
-
- switch (spad) {
- case PAD_SIZE0:
- ob[p] = (byte)(b0 << 2 & 0xfc | b1 >> 4 & 0x3);
- return PAD_SIZE0;
- case PAD_SIZE4:
- ob[p++] = (byte)(b0 << 2 & 0xfc | b1 >> 4 & 0x3);
- ob[p] = (byte)(b1 << 4 & 0xf0 | b2 >> 2 & 0xf);
- return PAD_SIZE4;
- case PAD_SIZE8:
- ob[p++] = (byte)(b0 << 2 & 0xfc | b1 >> 4 & 0x3);
- ob[p++] = (byte)(b1 << 4 & 0xf0 | b2 >> 2 & 0xf);
- ob[p] = (byte)(b2 << 6 & 0xc0 | b3 & 0x3f);
- return PAD_SIZE8;
- default:
- // We should never get here
- throw new IllegalStateException();
- }
- }
-
- public static boolean isValidBase64(int ch) {
- return ch == PAD || BDT[ch] != Byte.MAX_VALUE;
- }
-
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/common/util/CachedClass.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/common/util/CachedClass.java
deleted file mode 100644
index fe2df06..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/common/util/CachedClass.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.cxf.common.util;
-
-import java.lang.ref.WeakReference;
-
-public class CachedClass {
- private WeakReference<Class<?>> cachedClazz;
-
- public CachedClass(Class<?> cachedClass) {
- this.cachedClazz = new WeakReference<>(cachedClass);
- }
-
- public Class<?> getCachedClass() {
- return cachedClazz == null ? null : cachedClazz.get();
- }
-
- public void setCachedClass(Class<?> cachedClass) {
- this.cachedClazz = new WeakReference<>(cachedClass);
- }
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/common/util/ClassHelper.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/common/util/ClassHelper.java
deleted file mode 100644
index adec469..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/common/util/ClassHelper.java
+++ /dev/null
@@ -1,140 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.cxf.common.util;
-
-
-import java.lang.reflect.Proxy;
-
-import org.apache.cxf.Bus;
-import org.apache.cxf.BusFactory;
-
-/**
- *
- */
-public class ClassHelper {
-
- public static final String USE_DEFAULT_CLASS_HELPER = "org.apache.cxf.useDefaultClassHelpers";
-
- static final ClassHelper HELPER;
- static final ClassUnwrapper DEFAULT_UNWRAPPER;
- static final ClassUnwrapper UNWRAPPER;
-
- /**
- * Default class unwrapper implementation which delegates to the ClassHelper
- * internal methods.
- *
- */
- private static class DefaultClassUnwrapper implements ClassUnwrapper {
- private final ClassHelper helper;
-
- DefaultClassUnwrapper(ClassHelper helper) {
- this.helper = helper;
- }
-
- @Override
- public Class<?> getRealClassFromClass(Class<?> clazz) {
- return helper.getRealClassFromClassInternal(clazz);
- }
-
- @Override
- public Class<?> getRealClass(Object o) {
- return helper.getRealClassInternal(o);
- }
-
- @Override
- public Object getRealObject(Object o) {
- return helper.getRealObjectInternal(o);
- }
- }
-
- static {
- HELPER = new ClassHelper();
- DEFAULT_UNWRAPPER = new DefaultClassUnwrapper(HELPER);
- UNWRAPPER = getClassUnwrapper(DEFAULT_UNWRAPPER);
- }
-
- protected ClassHelper() {
- }
-
- private static ClassUnwrapper getClassUnwrapper(ClassUnwrapper defaultHelper) {
- boolean useSpring = true;
- String s = SystemPropertyAction.getPropertyOrNull("org.apache.cxf.useSpringClassHelpers");
- if (!StringUtils.isEmpty(s)) {
- useSpring = "1".equals(s) || Boolean.parseBoolean(s);
- }
- if (useSpring) {
- try {
- return new SpringClassUnwrapper();
- } catch (Throwable ex) {
- // ignore
- }
- }
- return defaultHelper;
- }
-
- private Class<?> getRealClassInternal(Object o) {
- return getRealObjectInternal(o).getClass();
- }
-
- private Class<?> getRealClassFromClassInternal(Class<?> cls) {
- return cls;
- }
-
- private Object getRealObjectInternal(Object o) {
- return o instanceof Proxy ? Proxy.getInvocationHandler(o) : o;
- }
-
- public static Class<?> getRealClass(Object o) {
- return getRealClass(null, o);
- }
-
- public static Class<?> getRealClassFromClass(Class<?> cls) {
- return getRealClassFromClass(null, cls);
- }
-
- public static Class<?> getRealClassFromClass(Bus bus, Class<?> cls) {
- return getContextClassUnwrapper(getBus(bus)).getRealClassFromClass(cls);
- }
-
- public static Object getRealObject(Object o) {
- return getContextClassUnwrapper(getBus(null)).getRealObject(o);
- }
-
- public static Class<?> getRealClass(Bus bus, Object o) {
- return getContextClassUnwrapper(getBus(bus)).getRealClass(o);
- }
-
- private static ClassUnwrapper getContextClassUnwrapper(Bus bus) {
- if (bus != null && bus.getProperty(ClassUnwrapper.class.getName()) != null) {
- return (ClassUnwrapper) bus.getProperty(ClassUnwrapper.class.getName());
- }
-
- return (DEFAULT_UNWRAPPER == UNWRAPPER || checkUseDefaultClassHelper(bus)) ? DEFAULT_UNWRAPPER : UNWRAPPER;
- }
-
- private static Bus getBus(Bus bus) {
- return bus == null ? BusFactory.getThreadDefaultBus() : bus;
- }
-
- private static boolean checkUseDefaultClassHelper(Bus bus) {
- return bus != null && Boolean.TRUE.equals(bus.getProperty(USE_DEFAULT_CLASS_HELPER));
- }
-
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/common/util/CollectionUtils.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/common/util/CollectionUtils.java
deleted file mode 100644
index 4e888c3..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/common/util/CollectionUtils.java
+++ /dev/null
@@ -1,126 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.cxf.common.util;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Dictionary;
-import java.util.Enumeration;
-import java.util.Iterator;
-import java.util.Map;
-
-public final class CollectionUtils {
- private CollectionUtils() {
-
- }
-
- public static <T> Collection<T> diff(Collection<T> c1, Collection<T> c2) {
- if (c1 == null || c1.isEmpty() || c2 == null || c2.isEmpty()) {
- return c1;
- }
- Collection<T> difference = new ArrayList<>();
- for (T item : c1) {
- if (!c2.contains(item)) {
- difference.add(item);
- }
- }
- return difference;
- }
-
- public static <T> boolean isEmpty(Collection<T> c) {
- if (c != null && !c.isEmpty()) {
- for (T item : c) {
- if (item != null) {
- return false;
- }
- }
- }
- return true;
- }
-
- public static <K, V> boolean isEmpty(Map<K, V> m) {
- return m == null || m.isEmpty();
- }
-
- public static <S, T> Dictionary<S, T> singletonDictionary(S s, T t) {
- return toDictionary(Collections.singletonMap(s, t));
- }
-
- public static <S, T> Dictionary<S, T> toDictionary(Map<S, T> map) {
- return new MapToDictionary<>(map);
- }
-
- static class MapToDictionary<S, T> extends Dictionary<S, T> {
- /**
- * Map source.
- **/
- private final Map<S, T> map;
-
- MapToDictionary(Map<S, T> map) {
- this.map = map;
- }
-
-
- public Enumeration<T> elements() {
- return map != null ? new IteratorToEnumeration<>(map.values().iterator()) : null;
- }
-
- public T get(Object key) {
- return map != null ? map.get(key) : null;
- }
-
- public boolean isEmpty() {
- return map == null || map.isEmpty();
- }
-
- public Enumeration<S> keys() {
- return map != null ? new IteratorToEnumeration<>(map.keySet().iterator()) : null;
- }
-
- public T put(S key, T value) {
- throw new UnsupportedOperationException();
- }
-
- public T remove(Object key) {
- throw new UnsupportedOperationException();
- }
-
- public int size() {
- return map != null ? map.size() : 0;
- }
-
- static class IteratorToEnumeration<X> implements Enumeration<X> {
- private final Iterator<X> iter;
-
- IteratorToEnumeration(Iterator<X> iter) {
- this.iter = iter;
- }
-
- public boolean hasMoreElements() {
- return iter != null && iter.hasNext();
- }
-
- public X nextElement() {
- return iter != null ? iter.next() : null;
- }
- }
- }
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/common/util/Compiler.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/common/util/Compiler.java
deleted file mode 100644
index 9d0c819..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/common/util/Compiler.java
+++ /dev/null
@@ -1,382 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.cxf.common.util;
-
-import java.io.File;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.LinkedList;
-import java.util.List;
-
-import javax.tools.Diagnostic;
-import javax.tools.DiagnosticListener;
-import javax.tools.JavaCompiler;
-import javax.tools.JavaCompiler.CompilationTask;
-import javax.tools.JavaFileManager;
-import javax.tools.JavaFileObject;
-import javax.tools.StandardJavaFileManager;
-import javax.tools.ToolProvider;
-
-import org.apache.cxf.helpers.FileUtils;
-
-public class Compiler {
- private long maxMemory = Runtime.getRuntime().maxMemory();
- private boolean verbose;
- private String target;
- private String outputDir;
- private String classPath;
- private String encoding;
- private boolean forceFork = Boolean.getBoolean(Compiler.class.getName() + "-fork");
- private File classpathTmpFile;
- private List<String> errors = new LinkedList<>();
- private List<String> warnings = new LinkedList<>();
-
- public Compiler() {
- }
-
- public List<String> getErrors() {
- return errors;
- }
- public List<String> getWarnings() {
- return warnings;
- }
-
- public void setMaxMemory(long l) {
- maxMemory = l;
- }
- public void setVerbose(boolean b) {
- verbose = b;
- }
- public void setTarget(String s) {
- target = s;
- }
- public void setOutputDir(File s) {
- if (s != null) {
- outputDir = s.getAbsolutePath().replace(File.pathSeparatorChar, '/');
- } else {
- outputDir = null;
- }
- }
- public void setOutputDir(String s) {
- outputDir = s.replace(File.pathSeparatorChar, '/');
- }
- public void setClassPath(String s) {
- classPath = StringUtils.isEmpty(s) ? null : s;
- }
-
- // https://issues.apache.org/jira/browse/CXF-8049
- private String getSystemClassPath() {
- String javaClasspath = SystemPropertyAction.getProperty("java.class.path");
-
- if (!StringUtils.isEmpty(javaClasspath)) {
- List<String> correctedEntries = new ArrayList<>();
-
- String[] toks = javaClasspath.split(File.pathSeparator);
-
- for (String tok: toks) {
- // if any classpath entry contains a whitespace char,
- // enclose the entry in double quotes
- if (tok.matches(".*\\s+.*")) {
- correctedEntries.add("\"" + tok + "\"");
- } else {
- correctedEntries.add(tok);
- }
- }
-
- return String.join(File.pathSeparator, correctedEntries);
- }
-
- return javaClasspath;
- }
-
- protected void addArgs(List<String> list) {
- if (!StringUtils.isEmpty(encoding)) {
- list.add("-encoding");
- list.add(encoding);
- }
- if (!StringUtils.isEmpty(target)) {
- list.add("-target");
- list.add(target);
- list.add("-source");
- list.add(target);
- }
-
- if (!StringUtils.isEmpty(outputDir)) {
- list.add("-d");
- list.add(outputDir);
- }
-
- if (StringUtils.isEmpty(classPath)) {
- String javaClasspath = getSystemClassPath();
- boolean classpathSetted = !StringUtils.isEmpty(javaClasspath);
- if (!classpathSetted) {
- File f = new File(getClass().getClassLoader().getResource(".").getFile());
- f = new File(f, "../lib");
- if (f.exists() && f.isDirectory()) {
- list.add("-extdirs");
- list.add(f.toString());
- }
- } else {
- list.add("-classpath");
- list.add(javaClasspath);
- }
- } else {
- list.add("-classpath");
- list.add(classPath);
- }
-
- }
- public boolean compileFiles(File[] files) {
- List<String> f = new ArrayList<>(files.length);
- for (File file : files) {
- f.add(file.getAbsolutePath());
- }
- return compileFiles(f.toArray(new String[0]));
- }
- public boolean compileFiles(List<File> files) {
- List<String> f = new ArrayList<>(files.size());
- for (File file : files) {
- f.add(file.getAbsolutePath());
- }
- return compileFiles(f.toArray(new String[0]));
- }
- public boolean compileFiles(String[] files) {
- String endorsed = SystemPropertyAction.getProperty("java.endorsed.dirs");
- if (!forceFork) {
- return useJava6Compiler(files);
- }
-
- List<String> list = new ArrayList<>();
-
- // Start of honoring java.home for used javac
- String fsep = File.separator;
- String javacstr = "javac";
- String platformjavacname = "javac";
-
- if (SystemPropertyAction.getProperty("os.name").toLowerCase().indexOf("windows") > -1) {
- platformjavacname = "javac.exe";
- }
-
- if (new File(SystemPropertyAction.getProperty("java.home") + fsep + platformjavacname).exists()) {
- // check if java.home is jdk home
- javacstr = SystemPropertyAction.getProperty("java.home") + fsep + platformjavacname;
- } else if (new File(SystemPropertyAction.getProperty("java.home") + fsep + ".." + fsep + "bin" + fsep
- + platformjavacname).exists()) {
- // check if java.home is jre home
- javacstr = SystemPropertyAction.getProperty("java.home") + fsep + ".." + fsep + "bin" + fsep
- + platformjavacname;
- } else if (new File(SystemPropertyAction.getProperty("java.home") + fsep + "bin" + fsep
- + platformjavacname).exists()) {
- //java9
- javacstr = SystemPropertyAction.getProperty("java.home") + fsep + "bin" + fsep
- + platformjavacname;
- }
- list.add(javacstr);
- // End of honoring java.home for used javac
-
- if (!StringUtils.isEmpty(endorsed)) {
- list.add("-endorseddirs");
- list.add(endorsed);
- }
-
- //fix for CXF-2081, set maximum heap of this VM to javac.
- list.add("-J-Xmx" + maxMemory);
-
- addArgs(list);
- int classpathIdx = list.indexOf("-classpath");
- String classpath = list.get(classpathIdx + 1);
- checkLongClasspath(classpath, list, classpathIdx);
- int idx = list.size();
- Collections.addAll(list, files);
-
- return internalCompile(list.toArray(new String[0]), idx);
- }
-
- protected boolean useJava6Compiler(String[] files) {
- JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
- if (compiler == null) {
- throw new IllegalStateException(
- "No compiler detected, make sure you are running on top of a JDK instead of a JRE.");
- }
- StandardJavaFileManager fileManager = compiler.getStandardFileManager(null, null, null);
- Iterable<? extends JavaFileObject> fileList = fileManager.getJavaFileObjectsFromStrings(Arrays
- .asList(files));
-
- return internalJava6Compile(compiler, wrapJavaFileManager(fileManager), setupDiagnosticListener(),
- fileList);
- }
-
- protected JavaFileManager wrapJavaFileManager(StandardJavaFileManager standardJavaFileManger) {
- return standardJavaFileManger;
- }
-
- protected DiagnosticListener<JavaFileObject> setupDiagnosticListener() {
- return new DiagnosticListener<JavaFileObject>() {
- public void report(Diagnostic<? extends JavaFileObject> diagnostic) {
- switch (diagnostic.getKind()) {
- case ERROR:
- errors.add(diagnostic.toString());
- if (verbose) {
- System.err.println(diagnostic.toString());
- }
- break;
- case WARNING:
- case MANDATORY_WARNING:
- warnings.add(diagnostic.toString());
- if (verbose) {
- System.err.println(diagnostic.toString());
- }
- break;
- default:
- break;
- }
- }
- };
- }
-
- protected boolean internalJava6Compile(JavaCompiler compiler, JavaFileManager fileManager,
- DiagnosticListener<JavaFileObject> listener,
- Iterable<? extends JavaFileObject> fileList) {
- List<String> args = new ArrayList<>();
- addArgs(args);
- CompilationTask task = compiler.getTask(null, fileManager, listener, args, null, fileList);
- Boolean ret = task.call();
- try {
- fileManager.close();
- } catch (IOException e) {
- System.err.print("[ERROR] IOException during compiling.");
- e.printStackTrace();
- }
- return ret;
- }
-
- public boolean internalCompile(String[] args, int sourceFileIndex) {
- File tmpFile = null;
- try {
- final String[] cmdArray;
- if (isLongCommandLines(args) && sourceFileIndex >= 0) {
- tmpFile = FileUtils.createTempFile("cxf-compiler", null);
- try (PrintWriter out = new PrintWriter(new FileWriter(tmpFile))) {
- for (int i = sourceFileIndex; i < args.length; i++) {
- if (args[i].indexOf(' ') > -1) {
- args[i] = args[i].replace(File.separatorChar, '/');
- //
- // javac gives an error if you use forward slashes
- // with package-info.java. Refer to:
- // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6198196
- //
- if (args[i].indexOf("package-info.java") > -1
- && SystemPropertyAction.getProperty("os.name")
- .toLowerCase().indexOf("windows") > -1) {
- out.println('"' + args[i].replaceAll("/", "\\\\\\\\") + '"');
- } else {
- out.println('"' + args[i] + '"');
- }
- } else {
- out.println(args[i]);
- }
- }
- out.flush();
- }
- cmdArray = new String[sourceFileIndex + 1];
- System.arraycopy(args, 0, cmdArray, 0, sourceFileIndex);
- cmdArray[sourceFileIndex] = "@" + tmpFile;
- } else {
- cmdArray = new String[args.length];
- System.arraycopy(args, 0, cmdArray, 0, args.length);
- }
-
- if (SystemPropertyAction.getProperty("os.name").toLowerCase().indexOf("windows") > -1) {
- for (int i = 0; i < cmdArray.length; i++) {
- if (cmdArray[i].indexOf("package-info") == -1) {
- cmdArray[i] = cmdArray[i].replace('\\', '/');
- }
- }
- }
-
- final Process p = Runtime.getRuntime().exec(cmdArray);
-
- if (p.getErrorStream() != null) {
- StreamPrinter errorStreamPrinter = new StreamPrinter(p.getErrorStream(), "", System.out);
- errorStreamPrinter.start();
- }
-
- if (p.getInputStream() != null) {
- StreamPrinter infoStreamPrinter = new StreamPrinter(p.getInputStream(), "[INFO]", System.out);
- infoStreamPrinter.start();
- }
-
- return p.waitFor() == 0 ? true : false;
- } catch (SecurityException e) {
- System.err.println("[ERROR] SecurityException during exec() of compiler \"" + args[0] + "\".");
- } catch (InterruptedException e) {
- // ignore
-
- } catch (IOException e) {
- System.err.print("[ERROR] IOException during exec() of compiler \"" + args[0] + "\"");
- System.err.println(". Check your path environment variable.");
- } finally {
- if (tmpFile != null && tmpFile.exists()) {
- FileUtils.delete(tmpFile);
- }
- if (classpathTmpFile != null && classpathTmpFile.exists()) {
- FileUtils.delete(classpathTmpFile);
- }
- }
-
- return false;
- }
-
- private boolean isLongCommandLines(String[] args) {
- StringBuilder strBuffer = new StringBuilder();
- for (int i = 0; i < args.length; i++) {
- strBuffer.append(args[i]);
- }
- return strBuffer.length() > 4096;
- }
-
- private boolean isLongClasspath(String classpath) {
- return classpath.length() > 2048;
- }
-
- private void checkLongClasspath(String classpath, List<String> list, int classpathIdx) {
- if (isLongClasspath(classpath)) {
- try {
- classpathTmpFile = FileUtils.createTempFile("cxf-compiler-classpath", null);
- try (PrintWriter out = new PrintWriter(new FileWriter(classpathTmpFile))) {
- out.println(classpath);
- out.flush();
- }
- list.set(classpathIdx + 1, "@" + classpathTmpFile);
- } catch (IOException e) {
- System.err.print("[ERROR] can't write long classpath to @argfile");
- }
- }
- }
-
- public void setEncoding(String string) {
- encoding = string;
- }
-
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/common/util/ModCountCopyOnWriteArrayList.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/common/util/ModCountCopyOnWriteArrayList.java
deleted file mode 100644
index daa6407..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/common/util/ModCountCopyOnWriteArrayList.java
+++ /dev/null
@@ -1,156 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.cxf.common.util;
-
-import java.util.Collection;
-import java.util.concurrent.CopyOnWriteArrayList;
-import java.util.concurrent.atomic.AtomicInteger;
-
-public final class ModCountCopyOnWriteArrayList<T> extends CopyOnWriteArrayList<T> {
- private static final long serialVersionUID = 1783937035760941219L;
- private AtomicInteger modCount = new AtomicInteger();
-
- public ModCountCopyOnWriteArrayList() {
- super();
- }
- public ModCountCopyOnWriteArrayList(Collection<? extends T> c) {
- super(c);
- if (c instanceof ModCountCopyOnWriteArrayList) {
- modCount.set(((ModCountCopyOnWriteArrayList<?>)c).getModCount());
- }
- }
-
- public int getModCount() {
- return modCount.get();
- }
-
- public void setModCount(int i) {
- modCount.set(i);
- }
-
- @Override
- public void add(int index, T element) {
- super.add(index, element);
- modCount.incrementAndGet();
- }
-
- @Override
- public boolean add(T element) {
- if (super.add(element)) {
- modCount.incrementAndGet();
- return true;
- }
- return false;
- }
-
- @Override
- public boolean addAll(Collection<? extends T> c) {
- if (super.addAll(c)) {
- modCount.incrementAndGet();
- return true;
- }
- return false;
- }
-
- @Override
- public boolean addAll(int index, Collection<? extends T> c) {
- if (super.addAll(index, c)) {
- modCount.incrementAndGet();
- return true;
- }
- return false;
- }
-
- @Override
- public int addAllAbsent(Collection<? extends T> c) {
- int i = super.addAllAbsent(c);
- if (i > 0) {
- modCount.incrementAndGet();
- }
- return i;
- }
-
- @Override
- public boolean addIfAbsent(T element) {
- if (super.addIfAbsent(element)) {
- modCount.incrementAndGet();
- return true;
- }
- return false;
- }
-
- @Override
- public void clear() {
- super.clear();
- modCount.incrementAndGet();
- }
-
- @Override
- public T remove(int index) {
- T t = super.remove(index);
- if (t != null) {
- modCount.incrementAndGet();
- }
- return t;
- }
-
- @Override
- public boolean remove(Object o) {
- if (super.remove(o)) {
- modCount.incrementAndGet();
- return true;
- }
- return false;
- }
-
- @Override
- public boolean removeAll(Collection<?> c) {
- if (super.removeAll(c)) {
- modCount.incrementAndGet();
- return true;
- }
- return false;
- }
-
- @Override
- public boolean retainAll(Collection<?> c) {
- if (super.retainAll(c)) {
- modCount.incrementAndGet();
- return true;
- }
- return false;
- }
-
- @Override
- public int hashCode() {
- return super.hashCode() + modCount.get();
- }
-
- @Override
- public boolean equals(Object o) {
- if (o instanceof ModCountCopyOnWriteArrayList) {
- return super.equals(o) && modCount.get()
- == ((ModCountCopyOnWriteArrayList<?>)o).getModCount();
- }
- return false;
- }
-
-}
-
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/common/util/PackageUtils.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/common/util/PackageUtils.java
deleted file mode 100644
index 9d014c8..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/common/util/PackageUtils.java
+++ /dev/null
@@ -1,181 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.cxf.common.util;
-
-import java.lang.reflect.Proxy;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
-import java.util.StringTokenizer;
-
-import org.apache.cxf.helpers.JavaUtils;
-
-
-public final class PackageUtils {
-
- private PackageUtils() {
-
- }
-
- static String getPackageName(String className) {
- int pos = className.lastIndexOf('.');
- if (pos != -1) {
- return className.substring(0, pos);
- }
- return "";
- }
-
- public static String getPackageName(Class<?> clazz) {
- String className = clazz.getName();
- if (className.startsWith("[L")) {
- className = className.substring(2);
- }
- return getPackageName(className);
- }
-
- public static String getSharedPackageName(List<Class<?>> classes) {
- if (classes.isEmpty()) {
- return "";
- }
- List<List<String>> lParts = new ArrayList<>(classes.size());
- List<String> currentParts = new ArrayList<>();
- for (Class<?> cls : classes) {
- if (!Proxy.isProxyClass(cls)) {
- lParts.add(Arrays.asList(getPackageName(cls).split("\\.")));
- }
- }
- for (int i = 0; i < lParts.get(0).size(); i++) {
- int j = 1;
- for (; j < lParts.size(); j++) {
- if (i > (lParts.get(j).size() - 1) || !lParts.get(j).get(i).equals(lParts.get(0).get(i))) {
- break;
- }
- }
- if (j == lParts.size()) {
- currentParts.add(lParts.get(j - 1).get(i));
- } else {
- break;
- }
- }
- return String.join(".", currentParts);
- }
-
- public static String parsePackageName(String namespace, String defaultPackageName) {
- return (defaultPackageName != null && !defaultPackageName.trim().isEmpty())
- ? defaultPackageName : getPackageNameByNameSpaceURI(namespace.trim());
- }
-
- public static String getPackageNameByNameSpaceURI(String nameSpaceURI) {
- int idx = nameSpaceURI.indexOf(':');
- boolean urnScheme = false;
- if (idx >= 0) {
- final String scheme = nameSpaceURI.substring(0, idx);
- urnScheme = "urn".equalsIgnoreCase(scheme);
- if ("http".equalsIgnoreCase(scheme) || urnScheme) {
- nameSpaceURI = nameSpaceURI.substring(idx + (urnScheme ? 1 : 3)); //
- }
- }
-
- List<String> tokens = tokenize(nameSpaceURI, "/:");
- if (tokens.isEmpty()) {
- return null;
- }
-
- if (tokens.size() > 1) {
- String lastToken = tokens.get(tokens.size() - 1);
- idx = lastToken.lastIndexOf('.');
- if (idx > 0) {
- lastToken = lastToken.replace('.', '_');
- tokens.set(tokens.size() - 1, lastToken);
- }
- }
-
- String domain = tokens.remove(0);
- List<String> r = tokenize(domain, urnScheme ? ".-" : ".");
- Collections.reverse(r);
- if ("www".equalsIgnoreCase(r.get(r.size() - 1))) {
- // remove leading www
- r.remove(r.size() - 1);
- }
-
- // replace the domain name with tokenized items
- tokens.addAll(0, r);
-
- // iterate through the tokens and apply xml->java name algorithm
- for (int i = 0; i < tokens.size(); i++) {
-
- // get the token and remove illegal chars
- String token = tokens.get(i);
- token = removeIllegalIdentifierChars(token);
-
- token = token.toLowerCase();
-
- // this will check for reserved keywords
- if (JavaUtils.isJavaKeyword(token)) {
- token = '_' + token;
- }
-
- tokens.set(i, token);
- }
-
- // concat all the pieces and return it
- return String.join(".", tokens);
- }
-
- private static List<String> tokenize(String str, String sep) {
- StringTokenizer tokens = new StringTokenizer(str, sep);
- List<String> r = new ArrayList<>();
-
- while (tokens.hasMoreTokens()) {
- r.add(tokens.nextToken());
- }
- return r;
- }
-
- private static String removeIllegalIdentifierChars(String token) {
- StringBuilder newToken = new StringBuilder();
- for (int i = 0; i < token.length(); i++) {
- char c = token.charAt(i);
-
- if (i == 0 && !Character.isJavaIdentifierStart(c)) {
- // prefix an '_' if the first char is illegal
- newToken.append('_').append(c);
- } else if (!Character.isJavaIdentifierPart(c)) {
- // replace the char with an '_' if it is illegal
- newToken.append('_');
- } else {
- // add the legal char
- newToken.append(c);
- }
- }
- return newToken.toString();
- }
-
- public static String getNamespace(String packageName) {
- if (packageName == null || packageName.isEmpty()) {
- return null;
- }
- final List<String> parts = Arrays.asList(packageName.split("\\."));
- Collections.reverse(parts);
- return "http://" + String.join(".", parts) + '/';
- }
-
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/common/util/ProxyClassLoader.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/common/util/ProxyClassLoader.java
deleted file mode 100644
index 073ca46..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/common/util/ProxyClassLoader.java
+++ /dev/null
@@ -1,89 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.cxf.common.util;
-
-import java.net.URL;
-import java.util.HashSet;
-import java.util.Set;
-
-/**
- * Utility class loader that can be used to create proxies in cases where
- * the the client classes are not visible to the loader of the
- * service class.
- */
-public class ProxyClassLoader extends ClassLoader {
- private final Class<?>[] classes;
- private final Set<ClassLoader> loaders = new HashSet<>();
- private boolean checkSystem;
-
- public ProxyClassLoader(ClassLoader parent) {
- super(parent);
- classes = null;
- }
-
- public ProxyClassLoader(ClassLoader parent, Class<?>[] cls) {
- super(parent);
- classes = cls;
- }
-
- public void addLoader(ClassLoader loader) {
- if (loader == null) {
- checkSystem = true;
- } else {
- loaders.add(loader);
- }
- }
-
- @Override
- public Class<?> findClass(String name) throws ClassNotFoundException {
- if (classes != null) {
- for (Class<?> c : classes) {
- if (name.equals(c.getName())) {
- return c;
- }
- }
- }
- for (ClassLoader loader : loaders) {
- try {
- return loader.loadClass(name);
- } catch (ClassNotFoundException | NoClassDefFoundError cnfe) {
- // Try next
- }
- }
- if (checkSystem) {
- try {
- return getSystemClassLoader().loadClass(name);
- } catch (ClassNotFoundException | NoClassDefFoundError cnfe) {
- // Try next
- }
- }
- throw new ClassNotFoundException(name);
- }
-
- @Override
- public URL findResource(String name) {
- for (ClassLoader loader : loaders) {
- URL url = loader.getResource(name);
- if (url != null) {
- return url;
- }
- }
- return null;
- }
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/common/util/ProxyHelper.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/common/util/ProxyHelper.java
deleted file mode 100644
index 380e2bb..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/common/util/ProxyHelper.java
+++ /dev/null
@@ -1,140 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.cxf.common.util;
-
-import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.Method;
-import java.lang.reflect.Proxy;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import org.apache.cxf.common.classloader.ClassLoaderUtils;
-import org.apache.cxf.common.logging.LogUtils;
-
-/**
- *
- */
-public class ProxyHelper {
- static final ProxyHelper HELPER;
- static {
- ProxyHelper theHelper;
- try {
- theHelper = new CglibProxyHelper();
- } catch (Throwable ex) {
- theHelper = new ProxyHelper();
- }
- HELPER = theHelper;
- }
-
- private static final Logger LOG = LogUtils.getL7dLogger(ProxyHelper.class);
-
- protected ProxyClassLoaderCache proxyClassLoaderCache =
- new ProxyClassLoaderCache();
-
-
- protected ProxyHelper() {
- }
-
- protected Object getProxyInternal(ClassLoader loader, Class<?>[] interfaces, InvocationHandler handler) {
- ClassLoader combinedLoader = getClassLoaderForInterfaces(loader, interfaces);
- return Proxy.newProxyInstance(combinedLoader, interfaces, handler);
- }
-
- /**
- * Return a classloader that can see all the given interfaces If the given loader can see all interfaces
- * then it is used. If not then a combined classloader of all interface classloaders is returned.
- *
- * @param loader use supplied class loader
- * @param interfaces
- * @return classloader that sees all interfaces
- */
- private ClassLoader getClassLoaderForInterfaces(final ClassLoader loader, final Class<?>[] interfaces) {
- if (canSeeAllInterfaces(loader, interfaces)) {
- LOG.log(Level.FINE, "current classloader " + loader + " can see all interface");
- return loader;
- }
- String sortedNameFromInterfaceArray = getSortedNameFromInterfaceArray(interfaces);
- ClassLoader cachedLoader = proxyClassLoaderCache.getProxyClassLoader(loader, interfaces);
- if (canSeeAllInterfaces(cachedLoader, interfaces)) {
- LOG.log(Level.FINE, "find required loader from ProxyClassLoader cache with key"
- + sortedNameFromInterfaceArray);
- return cachedLoader;
- } else {
- LOG.log(Level.FINE, "find a loader from ProxyClassLoader cache with interfaces "
- + sortedNameFromInterfaceArray
- + " but can't see all interfaces");
- for (Class<?> currentInterface : interfaces) {
- String ifName = currentInterface.getName();
-
- if (!ifName.startsWith("org.apache.cxf") && !ifName.startsWith("java")) {
- // remove the stale ProxyClassLoader and recreate one
- proxyClassLoaderCache.removeStaleProxyClassLoader(currentInterface);
- cachedLoader = proxyClassLoaderCache.getProxyClassLoader(loader, interfaces);
-
- }
- }
- }
-
- return cachedLoader;
- }
-
- private String getSortedNameFromInterfaceArray(Class<?>[] interfaces) {
- SortedArraySet<String> arraySet = new SortedArraySet<>();
- for (Class<?> currentInterface : interfaces) {
- arraySet.add(currentInterface.getName() + ClassLoaderUtils.getClassLoaderName(currentInterface));
- }
- return arraySet.toString();
- }
-
-
- private boolean canSeeAllInterfaces(ClassLoader loader, Class<?>[] interfaces) {
- for (Class<?> currentInterface : interfaces) {
- String ifName = currentInterface.getName();
- try {
- Class<?> ifClass = Class.forName(ifName, true, loader);
- if (ifClass != currentInterface) {
- return false;
- }
- //we need to check all the params/returns as well as the Proxy creation
- //will try to create methods for all of this even if they aren't used
- //by the client and not available in the clients classloader
- for (Method m : ifClass.getMethods()) {
- Class<?> returnType = m.getReturnType();
- if (!returnType.isPrimitive()) {
- Class.forName(returnType.getName(), true, loader);
- }
- for (Class<?> p : m.getParameterTypes()) {
- if (!p.isPrimitive()) {
- Class.forName(p.getName(), true, loader);
- }
- }
- }
- } catch (NoClassDefFoundError | ClassNotFoundException e) {
- return false;
- }
- }
- return true;
- }
-
- public static Object getProxy(ClassLoader loader, Class<?>[] interfaces, InvocationHandler handler) {
- return HELPER.getProxyInternal(loader, interfaces, handler);
- }
-
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/common/util/ReflectionInvokationHandler.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/common/util/ReflectionInvokationHandler.java
deleted file mode 100644
index 1b4d904..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/common/util/ReflectionInvokationHandler.java
+++ /dev/null
@@ -1,199 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.cxf.common.util;
-
-import java.lang.annotation.Annotation;
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.lang.reflect.Proxy;
-import java.util.Iterator;
-
-/**
- *
- */
-public class ReflectionInvokationHandler implements InvocationHandler {
- private Object target;
-
- public ReflectionInvokationHandler(Object obj) {
- target = obj;
- }
-
- public Object getTarget() {
- return target;
- }
-
- /** {@inheritDoc}*/
- public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
- WrapReturn wr = method.getAnnotation(WrapReturn.class);
- final Class<?> targetClass = target.getClass();
- final Class<?>[] parameterTypes = getParameterTypes(method, args);
- try {
- Method m;
- try {
- m = targetClass.getMethod(method.getName(), parameterTypes);
- } catch (NoSuchMethodException nsme) {
-
- boolean[] optionals = new boolean[method.getParameterTypes().length];
- int i = 0;
- int optionalNumber = 0;
- for (final Annotation[] a : method.getParameterAnnotations()) {
- optionals[i] = false;
- for (final Annotation potential : a) {
- if (Optional.class.equals(potential.annotationType())) {
- optionals[i] = true;
- optionalNumber++;
- break;
- }
- }
- i++;
- }
-
- Class<?>[] newParams = new Class<?>[args.length - optionalNumber];
- Object[] newArgs = new Object[args.length - optionalNumber];
- int argI = 0;
- for (int j = 0; j < parameterTypes.length; j++) {
- if (optionals[j]) {
- continue;
- }
- newArgs[argI] = args[j];
- newParams[argI] = parameterTypes[j];
- argI++;
- }
- m = targetClass.getMethod(method.getName(), newParams);
- args = newArgs;
- }
- ReflectionUtil.setAccessible(m);
- return wrapReturn(wr, m.invoke(target, args));
- } catch (InvocationTargetException e) {
- throw e.getCause();
- } catch (NoSuchMethodException e) {
- for (Method m2 : targetClass.getMethods()) {
- if (m2.getName().equals(method.getName())
- && m2.getParameterTypes().length == method.getParameterTypes().length) {
- boolean found = true;
- for (int x = 0; x < m2.getParameterTypes().length; x++) {
- if (args[x] != null
- && !m2.getParameterTypes()[x].isInstance(args[x])) {
- found = false;
- }
- }
- if (found) {
- ReflectionUtil.setAccessible(m2);
- return wrapReturn(wr, m2.invoke(target, args));
- }
- }
- }
- throw e;
- }
- }
- private Class<?>[] getParameterTypes(Method method, Object[] args) {
- Class<?>[] types = method.getParameterTypes();
- final Annotation[][] parAnnotations = method.getParameterAnnotations();
- for (int x = 0; x < types.length; x++) {
- UnwrapParam p = getUnwrapParam(parAnnotations[x]);
- if (p != null) {
- String s = p.methodName();
- String tn = p.typeMethodName();
- try {
- Method m = args[x].getClass().getMethod(s);
- if ("#default".equals(tn)) {
- types[x] = m.getReturnType();
- } else {
- Method m2 = args[x].getClass().getMethod(tn);
- types[x] = (Class<?>)ReflectionUtil.setAccessible(m2).invoke(args[x]);
- }
- args[x] = ReflectionUtil.setAccessible(m).invoke(args[x]);
- } catch (Exception ex) {
- throw new RuntimeException(ex);
- }
- }
- }
- return types;
- }
-
- private UnwrapParam getUnwrapParam(Annotation[] annotations) {
- for (Annotation a : annotations) {
- if (a instanceof UnwrapParam) {
- return (UnwrapParam)a;
- }
- }
- return null;
- }
-
- private static Object wrapReturn(WrapReturn wr, Object t) {
- if (wr == null || t == null) {
- return t;
- }
- if (wr.iterator()) {
- return new WrapperIterator(wr.value(), (Iterator<?>)t);
- }
- return createProxyWrapper(t, wr.value());
- }
-
- public static <T> T createProxyWrapper(Object target, Class<T> inf) {
- InvocationHandler h = new ReflectionInvokationHandler(target);
- return inf.cast(Proxy.newProxyInstance(inf.getClassLoader(), new Class<?>[] {inf}, h));
- }
-
- @Target(ElementType.PARAMETER)
- @Retention(RetentionPolicy.RUNTIME)
- public @interface Optional {
- }
-
- @Target(ElementType.METHOD)
- @Retention(RetentionPolicy.RUNTIME)
- public @interface WrapReturn {
- Class<?> value();
- boolean iterator() default false;
- }
-
- @Target(ElementType.PARAMETER)
- @Retention(RetentionPolicy.RUNTIME)
- public @interface UnwrapParam {
- String methodName() default "getValue";
- String typeMethodName() default "#default";
- }
-
- private static class WrapperIterator implements Iterator<Object> {
- Class<?> cls;
- Iterator<?> internal;
- WrapperIterator(Class<?> c, Iterator<?> it) {
- internal = it;
- cls = c;
- }
- public boolean hasNext() {
- return internal.hasNext();
- }
- public Object next() {
- Object obj = internal.next();
- return createProxyWrapper(obj, cls);
- }
-
- @Override
- public void remove() {
- internal.remove();
- }
- }
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/common/util/SortedArraySet.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/common/util/SortedArraySet.java
deleted file mode 100644
index 9c2b139..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/common/util/SortedArraySet.java
+++ /dev/null
@@ -1,266 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.cxf.common.util;
-
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Comparator;
-import java.util.Iterator;
-import java.util.NoSuchElementException;
-import java.util.SortedSet;
-import java.util.concurrent.atomic.AtomicReference;
-
-
-/**
- * This class implements most of the <tt>Set</tt> interface, backed by a
- * sorted Array. This makes iterators very fast, lookups are log(n), but
- * adds are fairly expensive.
- *
- * This class is also threadsafe, but without synchronizations. Lookups
- * and iterators will iterate over the state of the Set when the iterator
- * was created.
- *
- * If no data is stored in the Set, it uses very little memory. The backing
- * array is created on demand.
- *
- * This class is primarly useful for stuff that will be setup at startup, but
- * then iterated over MANY times during runtime.
- *
- * @param <T>
- */
-public final class SortedArraySet<T> implements SortedSet<T> {
- final AtomicReference<T[]> data = new AtomicReference<>();
-
- public void clear() {
- data.set(null);
- }
-
- public boolean isEmpty() {
- T[] tmp = data.get();
- return tmp == null || tmp.length == 0;
- }
-
- public Iterator<T> iterator() {
- return new SASIterator<>(data.get());
- }
-
- public int size() {
- T[] tmp = data.get();
- return tmp == null ? 0 : tmp.length;
- }
-
- @SuppressWarnings("unchecked")
- private T[] newArray(int size) {
- return (T[])new Object[size];
- }
-
- public boolean add(T o) {
- if (!contains(o)) {
- T[] tmp = data.get();
- T[] tmp2;
- if (tmp == null) {
- tmp2 = newArray(1);
- tmp2[0] = o;
- } else {
- tmp2 = newArray(tmp.length + 1);
- System.arraycopy(tmp, 0, tmp2, 0, tmp.length);
- tmp2[tmp2.length - 1] = o;
- Arrays.sort(tmp2);
- }
-
- if (!data.compareAndSet(tmp, tmp2)) {
- return add(o);
- }
- return true;
- }
- return false;
- }
- public boolean addAll(Collection<? extends T> c) {
- boolean val = false;
- for (T t : c) {
- val |= add(t);
- }
- return val;
- }
- public boolean containsAll(Collection<?> c) {
- boolean val = false;
- for (Object t : c) {
- val |= contains(t);
- }
- return val;
- }
-
- public boolean contains(Object o) {
- T[] tmp = data.get();
- if (tmp == null) {
- return false;
- }
- return Arrays.binarySearch(tmp, o) >= 0;
- }
-
- public boolean removeAll(Collection<?> c) {
- boolean val = false;
- for (Object t : c) {
- val |= remove(t);
- }
- return val;
- }
- public boolean retainAll(Collection<?> c) {
- boolean val = false;
- for (T t : this) {
- if (!c.contains(t)) {
- val |= remove(t);
- }
- }
- return val;
- }
-
- public boolean remove(Object o) {
- T[] tmp = data.get();
-
- if (tmp == null) {
- return false;
- }
- int idx = Arrays.binarySearch(tmp, o);
- if (idx != -1) {
- if (tmp.length == 1
- && !data.compareAndSet(tmp, null)) {
- return remove(o);
- }
- T[] tmp2 = newArray(tmp.length - 1);
- System.arraycopy(tmp, 0, tmp2, 0, idx);
- System.arraycopy(tmp, idx + 1, tmp2, idx, tmp.length - 1 - idx);
- if (!data.compareAndSet(tmp, tmp2)) {
- return remove(o);
- }
- return true;
- }
- return false;
- }
-
-
- public Object[] toArray() {
- T[] tmp = data.get();
- if (tmp == null) {
- return new Object[0];
- }
- T[] tmp2 = newArray(tmp.length);
- System.arraycopy(tmp, 0, tmp2, 0, tmp.length);
- return tmp2;
- }
-
- @SuppressWarnings("unchecked")
- public <X> X[] toArray(X[] a) {
- T[] tmp = data.get();
- if (tmp == null) {
- if (a.length != 0) {
- return (X[])java.lang.reflect.Array.
- newInstance(a.getClass().getComponentType(), 0);
- }
- return a;
- }
-
- if (a.length < tmp.length) {
- a = (X[])java.lang.reflect.Array.
- newInstance(a.getClass().getComponentType(), tmp.length);
- }
- System.arraycopy(tmp, 0, a, 0, tmp.length);
- if (a.length > tmp.length) {
- a[tmp.length] = null;
- }
- return a;
- }
-
- @SuppressWarnings("unchecked")
- public boolean equals(Object o) {
- if (!(o instanceof SortedArraySet)) {
- return false;
- }
- SortedArraySet<T> as = (SortedArraySet<T>)o;
- return Arrays.equals(data.get(), as.data.get());
- }
- public String toString() {
- return Arrays.toString(data.get());
- }
- public int hashCode() {
- return Arrays.hashCode(data.get());
- }
-
-
- private class SASIterator<X> implements Iterator<X> {
- final X[] data;
- int idx;
-
- SASIterator(X[] d) {
- data = d;
- }
-
- public boolean hasNext() {
- return data != null && idx != data.length;
- }
-
- public X next() {
- if (data == null || idx == data.length) {
- throw new NoSuchElementException();
- }
- return data[idx++];
- }
-
- @Override
- public void remove() {
- if (idx > 0) {
- SortedArraySet.this.remove((Object)data[idx - 1]);
- }
- }
- }
-
-
- public Comparator<? super T> comparator() {
- return null;
- }
-
- public T first() {
- T[] tmp = data.get();
- if (tmp == null || tmp.length == 0) {
- return null;
- }
- return tmp[0];
- }
-
- public T last() {
- T[] tmp = data.get();
- if (tmp == null || tmp.length == 0) {
- return null;
- }
- return tmp[tmp.length - 1];
- }
-
- public SortedSet<T> headSet(T toElement) {
- throw new UnsupportedOperationException();
- }
-
- public SortedSet<T> subSet(T fromElement, T toElement) {
- throw new UnsupportedOperationException();
- }
-
- public SortedSet<T> tailSet(T fromElement) {
- throw new UnsupportedOperationException();
- }
-
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/common/util/SpringClassUnwrapper.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/common/util/SpringClassUnwrapper.java
deleted file mode 100644
index a196eb0..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/common/util/SpringClassUnwrapper.java
+++ /dev/null
@@ -1,111 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.cxf.common.util;
-
-import org.springframework.aop.TargetSource;
-import org.springframework.aop.framework.Advised;
-import org.springframework.aop.support.AopUtils;
-import org.springframework.beans.factory.BeanCreationException;
-import org.springframework.util.ClassUtils;
-
-/**
- *
- */
-class SpringClassUnwrapper implements ClassUnwrapper {
- SpringClassUnwrapper() throws ClassNotFoundException {
- Class.forName("org.springframework.aop.support.AopUtils");
- Class.forName("org.springframework.aop.framework.Advised");
- }
-
- @Override
- public Class<?> getRealClassFromClass(Class<?> cls) {
- if (ClassUtils.isCglibProxyClass(cls)) {
- final Class<?> superclass = cls.getSuperclass();
- // Lambda's generated class names also contain $$ which makes them trigger CGLIB
- // proxy path. Adding more checks to handle this particular case.
- if (superclass != null && (superclass != Object.class || wasCglibEnhanced(cls))) {
- return getRealClassFromClass(superclass);
- }
- }
- return cls;
- }
-
- @Override
- public Object getRealObject(Object o) {
- if (o instanceof Advised) {
- try {
-
- Advised advised = (Advised)o;
- Object target = advised.getTargetSource().getTarget();
- //could be a proxy of a proxy.....
- return getRealObject(target);
- } catch (Exception ex) {
- // ignore
- }
- }
- return o;
- }
-
- @Override
- public Class<?> getRealClass(Object o) {
- if (AopUtils.isAopProxy(o) && (o instanceof Advised)) {
- Advised advised = (Advised)o;
- try {
- TargetSource targetSource = advised.getTargetSource();
-
- final Object target;
- try {
- target = targetSource.getTarget();
- } catch (BeanCreationException ex) {
- // some scopes such as 'request' may not
- // be active on the current thread yet
- return getRealClassFromClass(targetSource.getTargetClass());
- }
-
- if (target == null) {
- Class<?> targetClass = AopUtils.getTargetClass(o);
- if (targetClass != null) {
- return getRealClassFromClass(targetClass);
- }
- } else {
- return getRealClass(target);
- }
- } catch (Exception ex) {
- // ignore
- }
-
- } else if (ClassUtils.isCglibProxyClass(o.getClass())) {
- return getRealClassFromClass(AopUtils.getTargetClass(o));
- }
-
- return o.getClass();
- }
-
- /**
- * This additional check is not very reliable since CGLIB allows to
- * supply own NamingPolicy implementations. However, it works with native
- * CGLIB proxies ("byCGLIB$$") as well as Spring CGLIB proxies (by "BySpringCGLIB$$").
- * More expensive approach is to use reflection and inspect the class declared methods,
- * looking for CGLIB-specific ones like CGLIB$BIND_CALLBACKS.
- */
- private static boolean wasCglibEnhanced(Class<?> cls) {
- return cls.getName().contains("CGLIB");
- }
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/common/util/SpringClasspathScanner.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/common/util/SpringClasspathScanner.java
deleted file mode 100644
index 9113d77..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/common/util/SpringClasspathScanner.java
+++ /dev/null
@@ -1,202 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.cxf.common.util;
-
-import java.io.IOException;
-import java.lang.annotation.Annotation;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.cxf.common.classloader.ClassLoaderUtils;
-import org.springframework.core.io.Resource;
-import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
-import org.springframework.core.io.support.ResourcePatternResolver;
-import org.springframework.core.type.AnnotationMetadata;
-import org.springframework.core.type.classreading.CachingMetadataReaderFactory;
-import org.springframework.core.type.classreading.MetadataReader;
-import org.springframework.core.type.classreading.MetadataReaderFactory;
-import org.springframework.util.ClassUtils;
-
-class SpringClasspathScanner extends ClasspathScanner {
-
- private static final boolean IN_OSGI = isSpringInOsgi();
-
-
- SpringClasspathScanner() throws Exception {
- Class.forName("org.springframework.core.io.support.PathMatchingResourcePatternResolver");
- Class.forName("org.springframework.core.type.classreading.CachingMetadataReaderFactory");
- }
- private static boolean isSpringInOsgi() {
- try {
- Class.forName("org.springframework.osgi.io.OsgiBundleResourcePatternResolver");
- Class.forName("org.springframework.osgi.util.BundleDelegatingClassLoader");
- return true;
- } catch (Throwable ex) {
- return false;
- }
- }
-
- @Override
- protected Map< Class< ? extends Annotation >, Collection< Class< ? > > > findClassesInternal(
- Collection< String > basePackages,
- List<Class< ? extends Annotation > > annotations,
- ClassLoader loader)
- throws IOException, ClassNotFoundException {
-
- ResourcePatternResolver resolver = getResolver(loader);
- MetadataReaderFactory factory = new CachingMetadataReaderFactory(resolver);
-
- final Map< Class< ? extends Annotation >, Collection< Class< ? > > > classes =
- new HashMap<>();
- final Map< Class< ? extends Annotation >, Collection< String > > matchingInterfaces =
- new HashMap<>();
- final Map<String, String[]> nonMatchingClasses = new HashMap<>();
-
- for (Class< ? extends Annotation > annotation: annotations) {
- classes.put(annotation, new HashSet<>());
- matchingInterfaces.put(annotation, new HashSet<>());
- }
-
- if (basePackages == null || basePackages.isEmpty()) {
- return classes;
- }
-
- for (final String basePackage: basePackages) {
- final boolean scanAllPackages = basePackage.equals(WILDCARD);
- final String packageSearchPath = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX
- + (scanAllPackages ? "" : ClassUtils.convertClassNameToResourcePath(basePackage))
- + ALL_CLASS_FILES;
-
- final Resource[] resources = resolver.getResources(packageSearchPath);
-
-
- for (final Resource resource: resources) {
- final MetadataReader reader = factory.getMetadataReader(resource);
- final AnnotationMetadata metadata = reader.getAnnotationMetadata();
-
- if (scanAllPackages && shouldSkip(metadata.getClassName())) {
- continue;
- }
-
- for (Class< ? extends Annotation > annotation: annotations) {
- boolean concreteClass = !metadata.isInterface() && !metadata.isAbstract();
- if (metadata.isAnnotated(annotation.getName())) {
- if (concreteClass) {
- classes.get(annotation).add(loadClass(metadata.getClassName(), loader));
- } else {
- matchingInterfaces.get(annotation).add(metadata.getClassName());
- }
- } else if (concreteClass && metadata.getInterfaceNames().length > 0) {
- nonMatchingClasses.put(metadata.getClassName(), metadata.getInterfaceNames());
- }
- }
- }
- }
- if (!nonMatchingClasses.isEmpty()) {
- for (Map.Entry<Class<? extends Annotation>, Collection<String>> e1 : matchingInterfaces.entrySet()) {
- for (Map.Entry<String, String[]> e2 : nonMatchingClasses.entrySet()) {
- for (String intName : e2.getValue()) {
- if (e1.getValue().contains(intName)) {
- classes.get(e1.getKey()).add(loadClass(e2.getKey(), loader));
- break;
- }
- }
- }
- }
- }
-
- for (Map.Entry<Class<? extends Annotation>, Collection<String>> e : matchingInterfaces.entrySet()) {
- if (classes.get(e.getKey()).isEmpty()) {
- for (String intName : e.getValue()) {
- classes.get(e.getKey()).add(loadClass(intName, loader));
- }
- }
- }
-
- return classes;
- }
-
- @Override
- protected List<URL> findResourcesInternal(Collection<String> basePackages,
- String extension,
- ClassLoader loader)
- throws IOException {
- final List<URL> resourceURLs = new ArrayList<>();
- if (basePackages == null || basePackages.isEmpty()) {
- return resourceURLs;
- }
- ResourcePatternResolver resolver = getResolver(loader);
-
- for (final String basePackage: basePackages) {
- final boolean scanAllPackages = basePackage.equals(WILDCARD);
-
- String theBasePackage = basePackage;
- if (theBasePackage.startsWith(CLASSPATH_URL_SCHEME)) {
- theBasePackage = theBasePackage.substring(CLASSPATH_URL_SCHEME.length());
- }
-
- final String packageSearchPath = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX
- + (scanAllPackages ? "" : basePackage.contains(WILDCARD) ? basePackage
- : ClassUtils.convertClassNameToResourcePath(theBasePackage)) + ALL_FILES + "." + extension;
-
- final Resource[] resources = resolver.getResources(packageSearchPath);
- for (final Resource resource: resources) {
- resourceURLs.add(resource.getURL());
- }
- }
-
- return resourceURLs;
- }
-
- private ResourcePatternResolver getResolver(ClassLoader loader) {
- ResourcePatternResolver resolver = null;
-
- if (IN_OSGI) {
- resolver = SpringOsgiUtil.getResolver(loader);
- }
- if (resolver == null) {
- resolver = loader != null
- ? new PathMatchingResourcePatternResolver(loader) : new PathMatchingResourcePatternResolver();
- }
- return resolver;
- }
-
- private boolean shouldSkip(final String classname) {
- for (String packageToSkip: PACKAGES_TO_SKIP) {
- if (classname.startsWith(packageToSkip)) {
- return true;
- }
- }
-
- return false;
- }
-
- private Class<?> loadClass(String className, ClassLoader loader)
- throws ClassNotFoundException {
- if (loader == null) {
- return ClassLoaderUtils.loadClass(className, getClass());
- }
- return loader.loadClass(className);
- }
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/common/util/StreamPrinter.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/common/util/StreamPrinter.java
deleted file mode 100644
index fa88287..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/common/util/StreamPrinter.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.cxf.common.util;
-
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.OutputStream;
-import java.io.PrintWriter;
-
-class StreamPrinter extends Thread {
- private InputStream is;
- private String msg;
- private OutputStream os;
-
- StreamPrinter(InputStream stream, String type, OutputStream redirect) {
- is = stream;
- msg = type;
- os = redirect;
- }
-
- @Override
- public void run() {
- try {
- PrintWriter pw = null;
- if (os != null) {
- pw = new PrintWriter(os);
- }
- InputStreamReader isr = new InputStreamReader(is);
- BufferedReader br = new BufferedReader(isr);
- String line = br.readLine();
- while (line != null) {
- if (pw != null) {
- pw.println(msg + " " + line);
- }
- line = br.readLine();
- }
- if (pw != null) {
- pw.flush();
- }
- } catch (IOException ioe) {
- throw new RuntimeException(ioe);
- }
- }
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/common/util/URIParserUtil.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/common/util/URIParserUtil.java
deleted file mode 100644
index 462896f..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/common/util/URIParserUtil.java
+++ /dev/null
@@ -1,209 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.cxf.common.util;
-
-import java.io.File;
-import java.net.MalformedURLException;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.net.URL;
-import java.nio.charset.StandardCharsets;
-import java.util.StringTokenizer;
-
-import org.apache.cxf.common.classloader.ClassLoaderUtils;
-
-public final class URIParserUtil {
- private static final String EXCLUDED_CHARS = "<>\"{}|\\^`";
-
- private URIParserUtil() {
- // complete
- }
-
- private static boolean isExcluded(char ch) {
- return ch <= 0x20 || ch >= 0x7F || EXCLUDED_CHARS.indexOf(ch) != -1;
- }
-
- public static URL[] pathToURLs(String path) {
- StringTokenizer st = new StringTokenizer(path, File.pathSeparator);
- URL[] urls = new URL[st.countTokens()];
- int count = 0;
- while (st.hasMoreTokens()) {
- File file = new File(st.nextToken());
- URL url = null;
- try {
- url = file.toURI().toURL();
- } catch (MalformedURLException e) {
- e.printStackTrace();
- }
- if (url != null) {
- urls[count++] = url;
- }
- }
- if (urls.length != count) {
- URL[] tmp = new URL[count];
- System.arraycopy(urls, 0, tmp, 0, count);
- urls = tmp;
- }
- return urls;
- }
-
- public static String escapeChars(String s) {
- StringBuilder sb = new StringBuilder(s.length());
-
- for (int x = 0; x < s.length(); x++) {
- char ch = s.charAt(x);
- if (isExcluded(ch)) {
- byte[] bytes = Character.toString(ch).getBytes(StandardCharsets.UTF_8);
- for (byte b : bytes) {
- sb.append('%');
- StringUtils.byteToHex(b, sb);
- }
- } else {
- sb.append(ch);
- }
- }
- return sb.toString();
- }
- public static String normalize(final String uri) {
- URL url = null;
- String result;
- try {
- url = new URL(uri);
- result = escapeChars(url.toURI().normalize().toString().replace('\\', '/'));
- } catch (MalformedURLException e1) {
- try {
- if (uri.startsWith("classpath:")) {
- url = ClassLoaderUtils.getResource(uri.substring(10), URIParserUtil.class);
- return url != null ? url.toExternalForm() : uri;
- }
- File file = new File(uri);
- if (file.exists()) {
- return file.toURI().normalize().toString();
- }
- final String f;
- if (uri.indexOf(':') != -1 && !uri.startsWith("/")) {
- f = "file:/" + uri;
- } else {
- f = "file:" + uri;
- }
- url = new URL(f);
- return escapeChars(url.toString().replace("\\", "/"));
- } catch (Exception e2) {
- return escapeChars(uri.replace("\\", "/"));
- }
- } catch (URISyntaxException e) {
- result = escapeChars(url.toString().replace("\\", "/"));
- }
- return result;
- }
-
- public static String getAbsoluteURI(final String arg) {
- if (arg == null) {
- return null;
- }
-
- try {
- URI uri = new URI(arg);
- if ("file".equalsIgnoreCase(uri.getScheme())) {
- if (!uri.isOpaque()) {
- return uri.normalize().toString();
- }
- return new File("").toURI().resolve(uri.getPath()).toString();
- }
- return normalize(arg);
- } catch (Exception e2) {
- return normalize(arg);
- }
- }
-
- public static String relativize(String base, String toBeRelativized) throws URISyntaxException {
- if (base == null || toBeRelativized == null) {
- return null;
- }
- return relativize(new URI(base), new URI(toBeRelativized));
- }
-
- /**
- * This is a custom implementation for doing what URI.relativize(URI uri) should be
- * doing but is not actually doing when URI roots do not fully match.
- * See http://bugs.java.com/bugdatabase/view_bug.do?bug_id=6226081
- *
- * @param baseURI The base URI
- * @param toBeRelativizedURI The URI to be relativized
- * @return The string value of the URI you'd expect to get as result
- * of calling baseURI.relativize(toBeRelativizedURI).
- * null is returned if the parameters are null or are not
- * both absolute or not absolute.
- * @throws URISyntaxException
- */
- public static String relativize(URI baseURI, URI toBeRelativizedURI) throws URISyntaxException {
- if (baseURI == null || toBeRelativizedURI == null) {
- return null;
- }
- if (baseURI.isAbsolute() ^ toBeRelativizedURI.isAbsolute()) {
- return null;
- }
- final String base = baseURI.getSchemeSpecificPart();
- final String toBeRelativized = toBeRelativizedURI.getSchemeSpecificPart();
- final int l1 = base.length();
- final int l2 = toBeRelativized.length();
- if (l1 == 0) {
- return toBeRelativized;
- }
- int slashes = 0;
- StringBuilder sb = new StringBuilder();
- boolean differenceFound = false;
- for (int i = 0; i < l1; i++) {
- char c = base.charAt(i);
- if (i < l2) {
- if (!differenceFound && c == toBeRelativized.charAt(i)) {
- sb.append(c);
- } else {
- differenceFound = true;
- if (c == '/') {
- slashes++;
- }
- }
- } else {
- if (c == '/') {
- slashes++;
- }
- }
- }
- String rResolved = new URI(getRoot(sb.toString())).relativize(new URI(toBeRelativized)).toString();
- StringBuilder relativizedPath = new StringBuilder();
- for (int i = 0; i < slashes; i++) {
- relativizedPath.append("../");
- }
- relativizedPath.append(rResolved);
- return relativizedPath.toString();
- }
-
- private static String getRoot(String uri) {
- int idx = uri.lastIndexOf('/');
- if (idx == uri.length() - 1) {
- return uri;
- } else if (idx == -1) {
- return "";
- } else {
- return uri.substring(0, idx + 1);
- }
- }
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/common/xmlschema/SchemaCollection.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/common/xmlschema/SchemaCollection.java
deleted file mode 100644
index 0f3a579..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/common/xmlschema/SchemaCollection.java
+++ /dev/null
@@ -1,389 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.cxf.common.xmlschema;
-
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import javax.xml.namespace.QName;
-
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-
-import org.apache.ws.commons.schema.XmlSchema;
-import org.apache.ws.commons.schema.XmlSchemaAll;
-import org.apache.ws.commons.schema.XmlSchemaAttribute;
-import org.apache.ws.commons.schema.XmlSchemaAttributeGroupRef;
-import org.apache.ws.commons.schema.XmlSchemaAttributeOrGroupRef;
-import org.apache.ws.commons.schema.XmlSchemaChoice;
-import org.apache.ws.commons.schema.XmlSchemaCollection;
-import org.apache.ws.commons.schema.XmlSchemaComplexContentExtension;
-import org.apache.ws.commons.schema.XmlSchemaComplexContentRestriction;
-import org.apache.ws.commons.schema.XmlSchemaComplexType;
-import org.apache.ws.commons.schema.XmlSchemaContent;
-import org.apache.ws.commons.schema.XmlSchemaContentModel;
-import org.apache.ws.commons.schema.XmlSchemaElement;
-import org.apache.ws.commons.schema.XmlSchemaParticle;
-import org.apache.ws.commons.schema.XmlSchemaSequence;
-import org.apache.ws.commons.schema.XmlSchemaSequenceMember;
-import org.apache.ws.commons.schema.XmlSchemaSimpleContentExtension;
-import org.apache.ws.commons.schema.XmlSchemaSimpleContentRestriction;
-import org.apache.ws.commons.schema.XmlSchemaType;
-import org.apache.ws.commons.schema.extensions.ExtensionRegistry;
-import org.apache.ws.commons.schema.resolver.URIResolver;
-import org.apache.ws.commons.schema.utils.NamespaceMap;
-import org.apache.ws.commons.schema.utils.NamespacePrefixList;
-import org.apache.ws.commons.schema.utils.XmlSchemaObjectBase;
-
-/**
- * Wrapper class for XmlSchemaCollection that deals with various quirks and bugs.
- */
-public class SchemaCollection {
-
- private final XmlSchemaCollection xmlSchemaCollection;
- private final Map<XmlSchema, Set<XmlSchemaType>> xmlTypesCheckedForCrossImportsPerSchema
- = new HashMap<>();
-
- public SchemaCollection() {
- this(new XmlSchemaCollection());
- }
-
- public SchemaCollection(XmlSchemaCollection col) {
- xmlSchemaCollection = col;
- if (xmlSchemaCollection.getNamespaceContext() == null) {
- // an empty prefix map avoids extra checks for null.
- xmlSchemaCollection.setNamespaceContext(new NamespaceMap());
- }
- }
-
- public XmlSchemaCollection getXmlSchemaCollection() {
- return xmlSchemaCollection;
- }
-
- public boolean equals(Object obj) {
- if (obj instanceof SchemaCollection) {
- return xmlSchemaCollection.equals(((SchemaCollection)obj).xmlSchemaCollection);
- } else if (obj instanceof XmlSchemaCollection) {
- return xmlSchemaCollection.equals(obj);
- }
- return false;
- }
-
- public XmlSchemaElement getElementByQName(QName qname) {
- return xmlSchemaCollection.getElementByQName(qname);
- }
-
- public XmlSchemaAttribute getAttributeByQName(QName qname) {
- return xmlSchemaCollection.getAttributeByQName(qname);
- }
-
- public ExtensionRegistry getExtReg() {
- return xmlSchemaCollection.getExtReg();
- }
-
- public NamespacePrefixList getNamespaceContext() {
- return xmlSchemaCollection.getNamespaceContext();
- }
-
- public XmlSchemaType getTypeByQName(QName schemaTypeName) {
- return xmlSchemaCollection.getTypeByQName(schemaTypeName);
- }
-
- public XmlSchema[] getXmlSchema(String systemId) {
- return xmlSchemaCollection.getXmlSchema(systemId);
- }
-
- public XmlSchema[] getXmlSchemas() {
- return xmlSchemaCollection.getXmlSchemas();
- }
-
- public int hashCode() {
- return xmlSchemaCollection.hashCode();
- }
-
- public void init() {
- xmlSchemaCollection.init();
- }
-
- public XmlSchema read(Element elem, String uri) {
- return xmlSchemaCollection.read(elem, uri);
- }
-
- public XmlSchema read(Document d, String uri) {
- return xmlSchemaCollection.read(d, uri);
- }
-
- public XmlSchema read(Element elem) {
- return xmlSchemaCollection.read(elem);
- }
-
- public void setBaseUri(String baseUri) {
- xmlSchemaCollection.setBaseUri(baseUri);
- }
-
- public void setExtReg(ExtensionRegistry extReg) {
- xmlSchemaCollection.setExtReg(extReg);
- }
-
- public void setNamespaceContext(NamespacePrefixList namespaceContext) {
- xmlSchemaCollection.setNamespaceContext(namespaceContext);
- }
-
- public void setSchemaResolver(URIResolver schemaResolver) {
- xmlSchemaCollection.setSchemaResolver(schemaResolver);
- }
-
- /**
- * This function is not part of the XmlSchema API. Who knows why?
- *
- * @param namespaceURI targetNamespace
- * @return schema, or null.
- */
- public XmlSchema getSchemaByTargetNamespace(String namespaceURI) {
- for (XmlSchema schema : xmlSchemaCollection.getXmlSchemas()) {
- if (namespaceURI != null && namespaceURI.equals(schema.getTargetNamespace())
- || namespaceURI == null && schema.getTargetNamespace() == null) {
- return schema;
- }
- }
- return null;
- }
-
- public XmlSchema getSchemaForElement(QName name) {
- for (XmlSchema schema : xmlSchemaCollection.getXmlSchemas()) {
- if (name.getNamespaceURI().equals(schema.getTargetNamespace())) {
-
- if (schema.getElementByName(name.getLocalPart()) != null) {
- return schema;
- } else if (schema.getElementByName(name) != null) {
- return schema;
- }
- }
- }
- return null;
- }
-
- /**
- * Once upon a time, XmlSchema had a bug in the constructor used in this function. So this wrapper was
- * created to hold a workaround.
- *
- * @param namespaceURI TNS for new schema.
- * @return new schema
- */
-
- public XmlSchema newXmlSchemaInCollection(String namespaceURI) {
- return new XmlSchema(namespaceURI, xmlSchemaCollection);
- }
-
- /**
- * Validate that a qualified name points to some namespace in the schema.
- *
- * @param qname
- */
- public void validateQNameNamespace(QName qname) {
- // astonishingly, xmlSchemaCollection has no accessor by target URL.
- if ("".equals(qname.getNamespaceURI())) {
- return; // references to the 'unqualified' namespace are OK even if there is no schema for it.
- }
- for (XmlSchema schema : xmlSchemaCollection.getXmlSchemas()) {
- if (schema.getTargetNamespace().equals(qname.getNamespaceURI())) {
- return;
- }
- }
- throw new InvalidXmlSchemaReferenceException(qname + " refers to unknown namespace.");
- }
-
- public void validateElementName(QName referrer, QName elementQName) {
- XmlSchemaElement element = xmlSchemaCollection.getElementByQName(elementQName);
- if (element == null) {
- throw new InvalidXmlSchemaReferenceException(referrer + " references non-existent element "
- + elementQName);
- }
- }
-
- public void validateTypeName(QName referrer, QName typeQName) {
- XmlSchemaType type = xmlSchemaCollection.getTypeByQName(typeQName);
- if (type == null) {
- throw new InvalidXmlSchemaReferenceException(referrer + " references non-existent type "
- + typeQName);
- }
- }
-
- public void addCrossImports() {
- /*
- * We need to inventory all the cross-imports to see if any are missing.
- */
- for (XmlSchema schema : xmlSchemaCollection.getXmlSchemas()) {
- addOneSchemaCrossImports(schema);
- }
- }
-
- private void addOneSchemaCrossImports(XmlSchema schema) {
- /*
- * We need to visit all the top-level items.
- */
- for (XmlSchemaElement element : schema.getElements().values()) {
- addElementCrossImportsElement(schema, element);
- }
- for (XmlSchemaAttribute attribute : schema.getAttributes().values()) {
- XmlSchemaUtils.addImportIfNeeded(schema, attribute.getRef().getTargetQName());
- XmlSchemaUtils.addImportIfNeeded(schema, attribute.getSchemaTypeName());
- }
- for (XmlSchemaType type : schema.getSchemaTypes().values()) {
- addCrossImportsType(schema, type);
- }
- }
-
- private void addElementCrossImportsElement(XmlSchema schema, XmlSchemaElement item) {
- XmlSchemaElement element = item;
- XmlSchemaUtils.addImportIfNeeded(schema, element.getRef().getTargetQName());
- XmlSchemaUtils.addImportIfNeeded(schema, element.getSchemaTypeName());
- // if there's an anonymous type, it might have element refs in it.
- XmlSchemaType schemaType = element.getSchemaType();
- if (!crossImportsAdded(schema, schemaType)) {
- addCrossImportsType(schema, schemaType);
- }
- }
-
- /**
- * Determines whether the schema has already received (cross) imports for the schemaType
- *
- * @param schema
- * @param schemaType
- * @return false if cross imports for schemaType must still be added to schema
- */
- private boolean crossImportsAdded(XmlSchema schema, XmlSchemaType schemaType) {
- boolean result = true;
- if (schemaType != null) {
- Set<XmlSchemaType> xmlTypesCheckedForCrossImports;
- if (!xmlTypesCheckedForCrossImportsPerSchema.containsKey(schema)) {
- xmlTypesCheckedForCrossImports = new HashSet<>();
- xmlTypesCheckedForCrossImportsPerSchema.put(schema, xmlTypesCheckedForCrossImports);
- } else {
- xmlTypesCheckedForCrossImports = xmlTypesCheckedForCrossImportsPerSchema.get(schema);
- }
- if (!xmlTypesCheckedForCrossImports.contains(schemaType)) {
- // cross imports for this schemaType have not yet been added
- xmlTypesCheckedForCrossImports.add(schemaType);
- result = false;
- }
- }
- return result;
- }
-
- private void addCrossImportsType(XmlSchema schema, XmlSchemaType schemaType) {
- // the base type might cross schemas.
- if (schemaType instanceof XmlSchemaComplexType) {
- XmlSchemaComplexType complexType = (XmlSchemaComplexType)schemaType;
- XmlSchemaUtils.addImportIfNeeded(schema, complexType.getBaseSchemaTypeName());
- addCrossImports(schema, complexType.getContentModel());
- addCrossImportsAttributeList(schema, complexType.getAttributes());
- // could it be a choice or something else?
-
- if (complexType.getParticle() instanceof XmlSchemaChoice) {
- XmlSchemaChoice choice = (XmlSchemaChoice)complexType.getParticle();
- addCrossImports(schema, choice);
- } else if (complexType.getParticle() instanceof XmlSchemaAll) {
- XmlSchemaAll all = (XmlSchemaAll)complexType.getParticle();
- addCrossImports(schema, all);
- } else if (complexType.getParticle() instanceof XmlSchemaSequence) {
- XmlSchemaSequence sequence = (XmlSchemaSequence)complexType.getParticle();
- addCrossImports(schema, sequence);
- }
- }
- }
- private void addCrossImports(XmlSchema schema, XmlSchemaAll all) {
- for (XmlSchemaObjectBase seqMember : all.getItems()) {
- if (seqMember instanceof XmlSchemaElement) {
- addElementCrossImportsElement(schema, (XmlSchemaElement)seqMember);
- }
- }
- }
-
- private void addCrossImports(XmlSchema schema, XmlSchemaChoice choice) {
- for (XmlSchemaObjectBase seqMember : choice.getItems()) {
- if (seqMember instanceof XmlSchemaElement) {
- addElementCrossImportsElement(schema, (XmlSchemaElement)seqMember);
- }
- }
- }
- private void addCrossImports(XmlSchema schema, XmlSchemaSequence sequence) {
- for (XmlSchemaSequenceMember seqMember : sequence.getItems()) {
- if (seqMember instanceof XmlSchemaElement) {
- addElementCrossImportsElement(schema, (XmlSchemaElement)seqMember);
- }
- }
- }
-
- private void addCrossImportsAttributeList(XmlSchema schema, List<XmlSchemaAttributeOrGroupRef> list) {
- for (XmlSchemaAttributeOrGroupRef attr : list) {
- final QName ref;
- if (attr instanceof XmlSchemaAttribute) {
- ref = ((XmlSchemaAttribute)attr).getRef().getTargetQName();
- } else {
- XmlSchemaAttributeGroupRef groupRef = (XmlSchemaAttributeGroupRef)attr;
- ref = groupRef.getRef().getTargetQName();
- }
-
- if (ref != null) {
- XmlSchemaUtils.addImportIfNeeded(schema, ref);
- }
- }
- }
-
- private void addCrossImports(XmlSchema schema, XmlSchemaContentModel contentModel) {
- if (contentModel == null) {
- return;
- }
- XmlSchemaContent content = contentModel.getContent();
- if (content == null) {
- return;
- }
- if (content instanceof XmlSchemaComplexContentExtension) {
- XmlSchemaComplexContentExtension extension = (XmlSchemaComplexContentExtension)content;
- XmlSchemaUtils.addImportIfNeeded(schema, extension.getBaseTypeName());
- addCrossImportsAttributeList(schema, extension.getAttributes());
- XmlSchemaParticle particle = extension.getParticle();
- if (particle instanceof XmlSchemaSequence) {
- addCrossImports(schema, (XmlSchemaSequence)particle);
- } else if (particle instanceof XmlSchemaChoice) {
- addCrossImports(schema, (XmlSchemaChoice)particle);
- } else if (particle instanceof XmlSchemaAll) {
- addCrossImports(schema, (XmlSchemaAll)particle);
- }
- } else if (content instanceof XmlSchemaComplexContentRestriction) {
- XmlSchemaComplexContentRestriction restriction = (XmlSchemaComplexContentRestriction)content;
- XmlSchemaUtils.addImportIfNeeded(schema, restriction.getBaseTypeName());
- addCrossImportsAttributeList(schema, restriction.getAttributes());
- } else if (content instanceof XmlSchemaSimpleContentExtension) {
- XmlSchemaSimpleContentExtension extension = (XmlSchemaSimpleContentExtension)content;
- XmlSchemaUtils.addImportIfNeeded(schema, extension.getBaseTypeName());
- addCrossImportsAttributeList(schema, extension.getAttributes());
- } else if (content instanceof XmlSchemaSimpleContentRestriction) {
- XmlSchemaSimpleContentRestriction restriction = (XmlSchemaSimpleContentRestriction)content;
- XmlSchemaUtils.addImportIfNeeded(schema, restriction.getBaseTypeName());
- addCrossImportsAttributeList(schema, restriction.getAttributes());
- }
- }
-
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/configuration/jsse/MultiKeyPasswordKeyManager.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/configuration/jsse/MultiKeyPasswordKeyManager.java
deleted file mode 100644
index 6a1aee5..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/configuration/jsse/MultiKeyPasswordKeyManager.java
+++ /dev/null
@@ -1,84 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.cxf.configuration.jsse;
-
-import java.net.Socket;
-import java.security.GeneralSecurityException;
-import java.security.KeyStore;
-import java.security.KeyStoreException;
-import java.security.Principal;
-import java.security.PrivateKey;
-import java.security.cert.Certificate;
-import java.security.cert.X509Certificate;
-
-import javax.net.ssl.X509KeyManager;
-
-public class MultiKeyPasswordKeyManager implements X509KeyManager {
- private final KeyStore mKeyStore;
- private final String mKeyAlias;
- private final String mKeyPassword;
-
- public MultiKeyPasswordKeyManager(KeyStore keystore, String keyAlias, String keyPassword) {
- mKeyStore = keystore;
- mKeyAlias = keyAlias;
- mKeyPassword = keyPassword;
- }
-
- public String[] getClientAliases(String keyType, Principal[] issuers) {
- return new String[] {
- mKeyAlias
- };
- }
-
- public String[] getServerAliases(String keyType, Principal[] issuers) {
- return new String[] {
- mKeyAlias
- };
- }
- public X509Certificate[] getCertificateChain(String alias) {
- final Certificate[] chain;
- try {
- chain = mKeyStore.getCertificateChain(alias);
- } catch (KeyStoreException kse) {
- throw new RuntimeException(kse);
- }
- final X509Certificate[] certChain = new X509Certificate[chain.length];
- for (int i = 0; i < chain.length; i++) {
- certChain[i] = (X509Certificate)chain[i];
- }
- return certChain;
- }
-
- public PrivateKey getPrivateKey(String alias) {
- try {
- return (PrivateKey)mKeyStore.getKey(alias, mKeyPassword.toCharArray());
- } catch (GeneralSecurityException gse) {
- throw new RuntimeException(gse);
- }
- }
-
- public String chooseClientAlias(String[] keyType, Principal[] issuers, Socket socket) {
- return mKeyAlias;
- }
-
- public String chooseServerAlias(String keyType, Principal[] issuers, Socket socket) {
- return mKeyAlias;
- }
-
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/configuration/jsse/TLSClientParameters.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/configuration/jsse/TLSClientParameters.java
deleted file mode 100644
index 3e0099a..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/configuration/jsse/TLSClientParameters.java
+++ /dev/null
@@ -1,258 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.cxf.configuration.jsse;
-
-import java.util.List;
-import java.util.Objects;
-
-import javax.net.ssl.HostnameVerifier;
-import javax.net.ssl.SSLContext;
-import javax.net.ssl.SSLSocketFactory;
-
-/**
- * This class extends {@link TLSParameterBase} with client-specific
- * SSL/TLS parameters.
- *
- */
-public class TLSClientParameters extends TLSParameterBase {
- private boolean disableCNCheck;
- private SSLSocketFactory sslSocketFactory;
- private int sslCacheTimeout = 86400;
- private boolean useHttpsURLConnectionDefaultSslSocketFactory;
- private boolean useHttpsURLConnectionDefaultHostnameVerifier;
- private HostnameVerifier hostnameVerifier;
- private SSLContext sslContext;
-
- /**
- * Set custom HostnameVerifier
- * @param verifier hostname verifier
- */
- public void setHostnameVerifier(HostnameVerifier verifier) {
- hostnameVerifier = verifier;
- }
-
- /**
- * Get custom HostnameVerifier
- * @return hostname verifier
- */
- public HostnameVerifier getHostnameVerifier() {
- return hostnameVerifier;
- }
- /**
- * Set whether or not JSEE should omit checking if the host name
- * specified in the URL matches that of the Common Name
- * (CN) on the server's certificate. Default is false;
- * this attribute should not be set to true during production use.
- */
- public void setDisableCNCheck(boolean disableCNCheck) {
- this.disableCNCheck = disableCNCheck;
- }
-
- /**
- * Returns whether or not JSSE omits checking if the
- * host name specified in the URL matches that of the Common Name
- * (CN) on the server's certificate.
- */
- public boolean isDisableCNCheck() {
- return disableCNCheck;
- }
-
- /**
- * This sets the SSLSocketFactory to use, causing all other properties of
- * this bean (and its superclass) to get ignored (this takes precendence).
- */
- public final void setSSLSocketFactory(SSLSocketFactory factory) {
- sslSocketFactory = factory;
- }
-
-
- /**
- * Returns the SSLSocketFactory to be used, or null if none has been set.
- */
- public final SSLSocketFactory getSSLSocketFactory() {
- return sslSocketFactory;
- }
-
- /**
- * Returns the SSL cache timeout in seconds if it has been configured or the default value
- */
- public int getSslCacheTimeout() {
- return sslCacheTimeout;
- }
-
- /**
- * This sets the SSL Session Cache timeout value in seconds for client sessions handled by CXF
- */
- public void setSslCacheTimeout(int sslCacheTimeout) {
- this.sslCacheTimeout = sslCacheTimeout;
- }
-
-
- /**
- * Returns whether or not {@link javax.net.ssl.HttpsURLConnection#getDefaultSSLSocketFactory()} should be
- * used to create https connections. If <code>true</code> , {@link #getJsseProvider()} ,
- * {@link #getSecureSocketProtocol()}, {@link #getTrustManagers()}, {@link #getKeyManagers()},
- * {@link #getSecureRandom()}, {@link #getCipherSuites()} and {@link #getCipherSuitesFilter()} are
- * ignored.
- */
- public boolean isUseHttpsURLConnectionDefaultSslSocketFactory() {
- return useHttpsURLConnectionDefaultSslSocketFactory;
- }
-
- /**
- * Sets whether or not {@link javax.net.ssl.HttpsURLConnection#getDefaultSSLSocketFactory()} should be
- * used to create https connections.
- *
- * @see #isUseHttpsURLConnectionDefaultSslSocketFactory()
- */
- public void setUseHttpsURLConnectionDefaultSslSocketFactory(
- boolean useHttpsURLConnectionDefaultSslSocketFactory) {
- this.useHttpsURLConnectionDefaultSslSocketFactory = useHttpsURLConnectionDefaultSslSocketFactory;
- }
-
- /**
- * Returns whether or not {@link javax.net.ssl.HttpsURLConnection#getDefaultHostnameVerifier()} should be
- * used to create https connections. If <code>true</code>, {@link #isDisableCNCheck()} is ignored.
- */
- public boolean isUseHttpsURLConnectionDefaultHostnameVerifier() {
- return useHttpsURLConnectionDefaultHostnameVerifier;
- }
-
- /**
- * Sets whether or not {@link javax.net.ssl.HttpsURLConnection#getDefaultHostnameVerifier()} should be
- * used to create https connections.
- *
- * @see #isUseHttpsURLConnectionDefaultHostnameVerifier()
- */
- public void setUseHttpsURLConnectionDefaultHostnameVerifier(
- boolean useHttpsURLConnectionDefaultHostnameVerifier) {
- this.useHttpsURLConnectionDefaultHostnameVerifier = useHttpsURLConnectionDefaultHostnameVerifier;
- }
-
- public int hashCode() {
- int hash = disableCNCheck ? 37 : 17;
- if (sslSocketFactory != null) {
- hash = hash * 41 + System.identityHashCode(sslSocketFactory);
- }
- if (sslContext != null) {
- hash = hash * 41 + System.identityHashCode(sslContext);
- }
- hash = hash(hash, useHttpsURLConnectionDefaultSslSocketFactory);
- hash = hash(hash, useHttpsURLConnectionDefaultHostnameVerifier);
- hash = hash(hash, sslCacheTimeout);
- hash = hash(hash, secureRandom);
- hash = hash(hash, protocol);
- hash = hash(hash, certAlias);
- hash = hash(hash, provider);
- for (String cs : ciphersuites) {
- hash = hash(hash, cs);
- }
- hash = hash(hash, keyManagers);
- hash = hash(hash, trustManagers);
- if (cipherSuiteFilters != null) {
- hash = hash(hash, cipherSuiteFilters.getInclude());
- hash = hash(hash, cipherSuiteFilters.getExclude());
- }
- if (certConstraints != null) {
- hash = hash(hash, certConstraints.getIssuerDNConstraints());
- hash = hash(hash, certConstraints.getSubjectDNConstraints());
- }
- return hash;
- }
- private int hash(int i, Object o) {
- if (o != null) {
- return i * 37 + o.hashCode();
- }
- return i;
- }
- private int hash(int i, Object[] os) {
- if (os == null) {
- return i;
- }
- for (Object o : os) {
- i = hash(i, o);
- }
- return i;
- }
-
- @Override
- public boolean equals(Object o) {
- if (o == this) {
- return true;
- }
- if (o instanceof TLSClientParameters) {
- TLSClientParameters that = (TLSClientParameters)o;
- boolean eq = disableCNCheck == that.disableCNCheck;
- eq &= sslSocketFactory == that.sslSocketFactory;
- eq &= sslContext == that.sslContext;
- eq &= useHttpsURLConnectionDefaultSslSocketFactory == that.useHttpsURLConnectionDefaultSslSocketFactory;
- eq &= useHttpsURLConnectionDefaultHostnameVerifier == that.useHttpsURLConnectionDefaultHostnameVerifier;
- eq &= sslCacheTimeout == that.sslCacheTimeout;
- eq &= secureRandom == that.secureRandom;
- eq &= Objects.equals(certAlias, that.certAlias);
- eq &= Objects.equals(protocol, that.protocol);
- eq &= Objects.equals(provider, that.provider);
- eq &= equals(ciphersuites, that.ciphersuites);
- eq &= Objects.deepEquals(keyManagers, that.keyManagers);
- eq &= Objects.deepEquals(trustManagers, that.trustManagers);
- if (cipherSuiteFilters != null) {
- if (that.cipherSuiteFilters != null) {
- eq &= equals(cipherSuiteFilters.getExclude(), that.cipherSuiteFilters.getExclude());
- eq &= equals(cipherSuiteFilters.getInclude(), that.cipherSuiteFilters.getInclude());
- } else {
- eq = false;
- }
- } else {
- eq &= that.cipherSuiteFilters == null;
- }
- if (certConstraints != null) {
- if (that.certConstraints != null) {
- eq &= Objects.equals(certConstraints.getIssuerDNConstraints(),
- that.certConstraints.getIssuerDNConstraints());
- eq &= Objects.equals(certConstraints.getSubjectDNConstraints(),
- that.certConstraints.getSubjectDNConstraints());
- } else {
- eq = false;
- }
- } else {
- eq &= that.certConstraints == null;
- }
- return eq;
- }
- return false;
- }
-
- private static boolean equals(final List<?> obj1, final List<?> obj2) {
- return obj1.equals(obj2);
- }
-
- /**
- * Get the SSLContext parameter to use (if it has been set)
- */
- public SSLContext getSslContext() {
- return sslContext;
- }
-
- /**
- * Set an SSLContext parameter to use to create https connections
- */
- public void setSslContext(SSLContext sslContext) {
- this.sslContext = sslContext;
- }
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/configuration/jsse/TLSParameterJaxBUtils.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/configuration/jsse/TLSParameterJaxBUtils.java
deleted file mode 100644
index bd16aa4..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/configuration/jsse/TLSParameterJaxBUtils.java
+++ /dev/null
@@ -1,420 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.cxf.configuration.jsse;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URL;
-import java.nio.file.Files;
-import java.nio.file.NoSuchFileException;
-import java.nio.file.Paths;
-import java.security.GeneralSecurityException;
-import java.security.KeyStore;
-import java.security.KeyStoreException;
-import java.security.NoSuchAlgorithmException;
-import java.security.SecureRandom;
-import java.security.cert.Certificate;
-import java.security.cert.CertificateException;
-import java.security.cert.CertificateFactory;
-import java.security.cert.PKIXBuilderParameters;
-import java.security.cert.X509CertSelector;
-import java.security.cert.X509Certificate;
-import java.util.Collection;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import javax.net.ssl.CertPathTrustManagerParameters;
-import javax.net.ssl.KeyManager;
-import javax.net.ssl.KeyManagerFactory;
-import javax.net.ssl.TrustManager;
-import javax.net.ssl.TrustManagerFactory;
-import javax.security.auth.callback.CallbackHandler;
-import javax.security.auth.callback.PasswordCallback;
-
-import org.apache.cxf.Bus;
-import org.apache.cxf.BusFactory;
-import org.apache.cxf.common.classloader.ClassLoaderUtils;
-import org.apache.cxf.common.logging.LogUtils;
-import org.apache.cxf.configuration.security.CertStoreType;
-import org.apache.cxf.configuration.security.KeyManagersType;
-import org.apache.cxf.configuration.security.KeyStoreType;
-import org.apache.cxf.configuration.security.SecureRandomParameters;
-import org.apache.cxf.configuration.security.TrustManagersType;
-import org.apache.cxf.resource.ResourceManager;
-
-/**
- * This class provides some functionality to convert the JAXB
- * generated types in the security.xsd to the items needed
- * to programatically configure the HTTPConduit and HTTPDestination
- * with TLSClientParameters and TLSServerParameters respectively.
- */
-public final class TLSParameterJaxBUtils {
-
- private static final Logger LOG =
- LogUtils.getL7dLogger(TLSParameterJaxBUtils.class);
-
- private TLSParameterJaxBUtils() {
- // empty
- }
- /**
- * This method converts the JAXB generated type into a SecureRandom.
- */
- public static SecureRandom getSecureRandom(
- SecureRandomParameters secureRandomParams
- ) throws GeneralSecurityException {
-
- SecureRandom secureRandom = null;
- if (secureRandomParams != null) {
- String secureRandomAlg =
- secureRandomParams.getAlgorithm();
- String randomProvider =
- secureRandomParams.getProvider();
- if (randomProvider != null) {
- secureRandom = secureRandomAlg != null
- ? SecureRandom.getInstance(
- secureRandomAlg,
- randomProvider)
- : null;
- } else {
- secureRandom = secureRandomAlg != null
- ? SecureRandom.getInstance(
- secureRandomAlg)
- : null;
- }
- }
- return secureRandom;
- }
-
- public static KeyStore getKeyStore(KeyStoreType kst) throws GeneralSecurityException, IOException {
- return getKeyStore(kst, false);
- }
-
- /**
- * This method converts a JAXB generated KeyStoreType into a KeyStore.
- */
- public static KeyStore getKeyStore(KeyStoreType kst, boolean trustStore)
- throws GeneralSecurityException,
- IOException {
-
- if (kst == null) {
- return null;
- }
- final String type;
- if (trustStore) {
- type = SSLUtils.getTrustStoreType(kst.isSetType()
- ? kst.getType() : null, LOG, KeyStore.getDefaultType());
- } else {
- type = SSLUtils.getKeystoreType(kst.isSetType()
- ? kst.getType() : null, LOG, KeyStore.getDefaultType());
- }
-
- char[] password = kst.isSetPassword()
- ? deobfuscate(kst.getPassword())
- : null;
- if (password == null) {
- final String tmp;
- if (trustStore) {
- tmp = SSLUtils.getTruststorePassword(null, LOG);
- } else {
- tmp = SSLUtils.getKeystorePassword(null, LOG);
- }
- if (tmp != null) {
- password = tmp.toCharArray();
- }
- }
- final String provider;
- if (trustStore) {
- provider = SSLUtils.getTruststoreProvider(kst.isSetProvider() ? kst.getProvider() : null, LOG);
- } else {
- provider = SSLUtils.getKeystoreProvider(kst.isSetProvider() ? kst.getProvider() : null, LOG);
- }
- KeyStore keyStore = provider == null
- ? KeyStore.getInstance(type)
- : KeyStore.getInstance(type, provider);
-
- if (kst.isSetFile()) {
- try (InputStream kstInputStream = Files.newInputStream(Paths.get(kst.getFile()))) {
- keyStore.load(kstInputStream, password);
- }
- } else if (kst.isSetResource()) {
- final InputStream is = getResourceAsStream(kst.getResource());
- if (is == null) {
- final String msg =
- "Could not load keystore resource " + kst.getResource();
- LOG.severe(msg);
- throw new IOException(msg);
- }
- keyStore.load(is, password);
- } else if (kst.isSetUrl()) {
- keyStore.load(new URL(kst.getUrl()).openStream(), password);
- } else {
- final String loc;
- if (trustStore) {
- loc = SSLUtils.getTruststore(null, LOG);
- } else {
- loc = SSLUtils.getKeystore(null, LOG);
- }
- if (loc != null) {
- try (InputStream ins = Files.newInputStream(Paths.get(loc))) {
- keyStore.load(ins, password);
- } catch (NoSuchFileException ex) {
- // Fall back to load the location as a stream
- try (InputStream ins = getResourceAsStream(loc)) {
- keyStore.load(ins, password);
- }
- }
- }
- }
- return keyStore;
- }
-
- /**
- * This method converts a JAXB generated CertStoreType into a KeyStore.
- */
- public static KeyStore getKeyStore(final CertStoreType pst)
- throws IOException, CertificateException, KeyStoreException, NoSuchAlgorithmException {
-
- if (pst == null) {
- return null;
- }
- String type;
- if (pst.isSetType()) {
- type = pst.getType();
- } else {
- type = KeyStore.getDefaultType();
- }
- if (pst.isSetFile()) {
- InputStream is = Files.newInputStream(Paths.get(pst.getFile()));
- return createTrustStore(is, type);
- }
- if (pst.isSetResource()) {
- final InputStream is = getResourceAsStream(pst.getResource());
- if (is == null) {
- final String msg =
- "Could not load truststore resource " + pst.getResource();
- LOG.severe(msg);
- throw new IOException(msg);
- }
- return createTrustStore(is, type);
- }
- if (pst.isSetUrl()) {
- return createTrustStore(new URL(pst.getUrl()).openStream(), type);
- }
- throw new IllegalArgumentException("Could not create KeyStore based on information in CertStoreType");
- }
-
- private static InputStream getResourceAsStream(String resource) {
- InputStream is = ClassLoaderUtils.getResourceAsStream(resource, TLSParameterJaxBUtils.class);
- if (is == null) {
- Bus bus = BusFactory.getThreadDefaultBus(true);
- ResourceManager rm = bus.getExtension(ResourceManager.class);
- if (rm != null) {
- is = rm.getResourceAsStream(resource);
- }
- }
- return is;
- }
-
- /**
- * Create a KeyStore containing the trusted CA certificates contained
- * in the supplied input stream.
- */
- private static KeyStore createTrustStore(final InputStream is, String type)
- throws IOException, CertificateException, KeyStoreException, NoSuchAlgorithmException {
-
- final Collection<? extends Certificate> certs = loadCertificates(is);
- final KeyStore keyStore =
- KeyStore.getInstance(type);
- keyStore.load(null, null);
- for (Certificate cert : certs) {
- final X509Certificate xcert = (X509Certificate) cert;
- keyStore.setCertificateEntry(
- xcert.getSubjectX500Principal().getName(),
- cert
- );
- }
- return keyStore;
- }
-
- /**
- * load the certificates as X.509 certificates
- */
- private static Collection<? extends Certificate> loadCertificates(final InputStream is)
- throws IOException, CertificateException {
-
- final CertificateFactory factory = CertificateFactory.getInstance("X.509");
- return factory.generateCertificates(is);
- }
-
- private static char[] deobfuscate(String s) {
- // From the Jetty org.eclipse.jetty.http.security.Password class
- if (!s.startsWith("OBF:")) {
- return s.toCharArray();
- }
- s = s.substring(4);
-
- char[] b = new char[s.length() / 2];
- int l = 0;
- for (int i = 0; i < s.length(); i += 4) {
- String x = s.substring(i, i + 4);
- int i0 = Integer.parseInt(x, 36);
- int i1 = i0 / 256;
- int i2 = i0 % 256;
- b[l++] = (char) ((i1 + i2 - 254) / 2);
- }
-
- return new String(b, 0, l).toCharArray();
- }
-
- /**
- * This method converts the JAXB KeyManagersType into a list of
- * JSSE KeyManagers.
- */
- public static KeyManager[] getKeyManagers(KeyManagersType kmc)
- throws GeneralSecurityException,
- IOException {
-
- KeyStore keyStore = getKeyStore(kmc.getKeyStore(), false);
-
- String alg = kmc.isSetFactoryAlgorithm()
- ? kmc.getFactoryAlgorithm()
- : KeyManagerFactory.getDefaultAlgorithm();
-
- char[] keyPass = getKeyPassword(kmc);
-
- KeyManagerFactory fac =
- kmc.isSetProvider()
- ? KeyManagerFactory.getInstance(alg, kmc.getProvider())
- : KeyManagerFactory.getInstance(alg);
-
- fac.init(keyStore, keyPass);
-
- return fac.getKeyManagers();
- }
-
- /**
- * This method converts the JAXB KeyManagersType into a list of
- * JSSE KeyManagers.
- */
- public static KeyManager[] getKeyManagers(KeyManagersType kmc, String alias)
- throws GeneralSecurityException,
- IOException {
-
- KeyStore keyStore = getKeyStore(kmc.getKeyStore(), false);
-
- String alg = kmc.isSetFactoryAlgorithm()
- ? kmc.getFactoryAlgorithm()
- : KeyManagerFactory.getDefaultAlgorithm();
-
- char[] keyPass = getKeyPassword(kmc);
-
- KeyManagerFactory fac =
- kmc.isSetProvider()
- ? KeyManagerFactory.getInstance(alg, kmc.getProvider())
- : KeyManagerFactory.getInstance(alg);
-
- try {
- fac.init(keyStore, keyPass);
-
- return fac.getKeyManagers();
- } catch (java.security.UnrecoverableKeyException uke) {
- //jsse has the restriction that different key in keystore
- //cannot has different password, use MultiKeyPasswordKeyManager
- //as fallback when this happen
- MultiKeyPasswordKeyManager manager
- = new MultiKeyPasswordKeyManager(keyStore, alias,
- new String(keyPass));
- return new KeyManager[]{manager};
- }
- }
-
- private static char[] getKeyPassword(KeyManagersType kmc) {
- char[] keyPass = kmc.isSetKeyPassword()
- ? deobfuscate(kmc.getKeyPassword())
- : null;
-
- if (keyPass != null) {
- return keyPass;
- }
-
- String callbackHandlerClass = kmc.getKeyPasswordCallbackHandler();
- if (callbackHandlerClass == null) {
- return null;
- }
- try {
- final CallbackHandler ch = (CallbackHandler) ClassLoaderUtils
- .loadClass(callbackHandlerClass, TLSParameterJaxBUtils.class).newInstance();
- String prompt = kmc.getKeyStore().getFile();
- if (prompt == null) {
- prompt = kmc.getKeyStore().getResource();
- }
- PasswordCallback pwCb = new PasswordCallback(prompt, false);
- PasswordCallback[] callbacks = new PasswordCallback[] {pwCb};
- ch.handle(callbacks);
- keyPass = callbacks[0].getPassword();
- } catch (Exception e) {
- LOG.log(Level.WARNING,
- "Cannot load key password from callback handler: " + e.getMessage(), e);
- }
- return keyPass;
- }
-
- /**
- * This method converts the JAXB TrustManagersType into a list of
- * JSSE TrustManagers.
- */
- @Deprecated
- public static TrustManager[] getTrustManagers(TrustManagersType tmc)
- throws GeneralSecurityException,
- IOException {
- return getTrustManagers(tmc, false);
- }
-
- public static TrustManager[] getTrustManagers(TrustManagersType tmc, boolean enableRevocation)
- throws GeneralSecurityException,
- IOException {
-
- final KeyStore keyStore =
- tmc.isSetKeyStore()
- ? getKeyStore(tmc.getKeyStore(), true)
- : (tmc.isSetCertStore()
- ? getKeyStore(tmc.getCertStore())
- : null);
-
- String alg = tmc.isSetFactoryAlgorithm()
- ? tmc.getFactoryAlgorithm()
- : TrustManagerFactory.getDefaultAlgorithm();
-
- TrustManagerFactory fac =
- tmc.isSetProvider()
- ? TrustManagerFactory.getInstance(alg, tmc.getProvider())
- : TrustManagerFactory.getInstance(alg);
-
- if (enableRevocation) {
- PKIXBuilderParameters param = new PKIXBuilderParameters(keyStore, new X509CertSelector());
- param.setRevocationEnabled(true);
-
- fac.init(new CertPathTrustManagerParameters(param));
- } else {
- fac.init(keyStore);
- }
-
- return fac.getTrustManagers();
- }
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/configuration/spring/ConfigurerImpl.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/configuration/spring/ConfigurerImpl.java
deleted file mode 100644
index d920936..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/configuration/spring/ConfigurerImpl.java
+++ /dev/null
@@ -1,288 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.cxf.configuration.spring;
-
-import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.TreeMap;
-import java.util.concurrent.CopyOnWriteArraySet;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-import java.util.regex.PatternSyntaxException;
-
-import org.apache.cxf.common.injection.NoJSR250Annotations;
-import org.apache.cxf.common.logging.LogUtils;
-import org.apache.cxf.configuration.Configurable;
-import org.apache.cxf.configuration.Configurer;
-import org.apache.cxf.extension.BusExtension;
-import org.springframework.beans.factory.BeanFactory;
-import org.springframework.beans.factory.NoSuchBeanDefinitionException;
-import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
-import org.springframework.beans.factory.config.BeanDefinition;
-import org.springframework.beans.factory.support.AbstractBeanFactory;
-import org.springframework.beans.factory.support.BeanDefinitionRegistry;
-import org.springframework.beans.factory.wiring.BeanConfigurerSupport;
-import org.springframework.beans.factory.wiring.BeanWiringInfo;
-import org.springframework.beans.factory.wiring.BeanWiringInfoResolver;
-import org.springframework.context.ApplicationContext;
-import org.springframework.context.ApplicationContextAware;
-import org.springframework.context.ConfigurableApplicationContext;
-
-@NoJSR250Annotations
-public class ConfigurerImpl extends BeanConfigurerSupport
- implements Configurer, ApplicationContextAware, BusExtension {
-
- private static final Logger LOG = LogUtils.getL7dLogger(ConfigurerImpl.class);
-
- private Set<ApplicationContext> appContexts;
- private final Map<String, List<MatcherHolder>> wildCardBeanDefinitions = new TreeMap<>();
- private BeanFactory beanFactory;
-
- static class MatcherHolder implements Comparable<MatcherHolder> {
- Matcher matcher;
- String wildCardId;
- MatcherHolder(String orig, Matcher matcher) {
- wildCardId = orig;
- this.matcher = matcher;
- }
-
- @Override
- public int compareTo(MatcherHolder mh) {
- int literalCharsLen1 = this.wildCardId.replace("*", "").length();
- int literalCharsLen2 = mh.wildCardId.replace("*", "").length();
- // The expression with more literal characters should end up on the top of the list
- return Integer.compare(literalCharsLen1, literalCharsLen2) * -1;
- }
- }
-
- public ConfigurerImpl() {
- // complete
- }
-
- public ConfigurerImpl(ApplicationContext ac) {
- setApplicationContext(ac);
- }
-
- @Override
- public void setBeanFactory(BeanFactory beanFactory) {
- this.beanFactory = beanFactory;
- super.setBeanFactory(beanFactory);
- }
-
- private void initWildcardDefinitionMap() {
- if (null != appContexts) {
- for (ApplicationContext appContext : appContexts) {
- for (String n : appContext.getBeanDefinitionNames()) {
- if (isWildcardBeanName(n)) {
- AutowireCapableBeanFactory bf = appContext.getAutowireCapableBeanFactory();
- BeanDefinitionRegistry bdr = (BeanDefinitionRegistry) bf;
- BeanDefinition bd = bdr.getBeanDefinition(n);
- String className = bd.getBeanClassName();
- if (null != className) {
- final String name = n.charAt(0) != '*' ? n
- : "." + n.replaceAll("\\.", "\\."); //old wildcard
- try {
- Matcher matcher = Pattern.compile(name).matcher("");
- List<MatcherHolder> m = wildCardBeanDefinitions.get(className);
- if (m == null) {
- m = new ArrayList<>();
- wildCardBeanDefinitions.put(className, m);
- }
- MatcherHolder holder = new MatcherHolder(n, matcher);
- m.add(holder);
- } catch (PatternSyntaxException npe) {
- //not a valid patter, we'll ignore
- }
- } else {
- LogUtils.log(LOG, Level.WARNING, "WILDCARD_BEAN_ID_WITH_NO_CLASS_MSG", n);
- }
- }
- }
- }
- }
- }
-
- public void configureBean(Object beanInstance) {
- configureBean(null, beanInstance, true);
- }
-
- public void configureBean(String bn, Object beanInstance) {
- configureBean(bn, beanInstance, true);
- }
- public synchronized void configureBean(String bn, Object beanInstance, boolean checkWildcards) {
-
- if (null == appContexts) {
- return;
- }
-
- if (null == bn) {
- bn = getBeanName(beanInstance);
- if (null == bn) {
- return;
- }
- }
-
- if (checkWildcards) {
- configureWithWildCard(bn, beanInstance);
- }
-
- final String beanName = bn;
- setBeanWiringInfoResolver(new BeanWiringInfoResolver() {
- public BeanWiringInfo resolveWiringInfo(Object instance) {
- if (!beanName.isEmpty()) {
- return new BeanWiringInfo(beanName);
- }
- return null;
- }
- });
-
- for (ApplicationContext appContext : appContexts) {
- if (appContext.containsBean(bn)) {
- this.setBeanFactory(appContext.getAutowireCapableBeanFactory());
- }
- }
-
- try {
- //this will prevent a call into the AbstractBeanFactory.markBeanAsCreated(...)
- //which saves ALL the names into a HashSet. For URL based configuration,
- //this can leak memory
- if (beanFactory instanceof AbstractBeanFactory) {
- ((AbstractBeanFactory)beanFactory).getMergedBeanDefinition(bn);
- }
- super.configureBean(beanInstance);
- if (LOG.isLoggable(Level.FINE)) {
- LOG.fine("Successfully performed injection.");
- }
- } catch (NoSuchBeanDefinitionException ex) {
- // users often wonder why the settings in their configuration files seem
- // to have no effect - the most common cause is that they have been using
- // incorrect bean ids
- if (LOG.isLoggable(Level.FINE)) {
- LOG.log(Level.FINE, "NO_MATCHING_BEAN_MSG", beanName);
- }
- }
- }
-
- private void configureWithWildCard(String bn, Object beanInstance) {
- if (!wildCardBeanDefinitions.isEmpty()) {
- Class<?> clazz = beanInstance.getClass();
- while (!Object.class.equals(clazz)) {
- String className = clazz.getName();
- List<MatcherHolder> matchers = wildCardBeanDefinitions.get(className);
- if (matchers != null) {
- for (MatcherHolder m : matchers) {
- synchronized (m.matcher) {
- m.matcher.reset(bn);
- if (m.matcher.matches()) {
- configureBean(m.wildCardId, beanInstance, false);
- return;
- }
- }
- }
- }
- clazz = clazz.getSuperclass();
- }
- }
- }
-
- private boolean isWildcardBeanName(String bn) {
- return bn.indexOf('*') != -1 || bn.indexOf('?') != -1
- || (bn.indexOf('(') != -1 && bn.indexOf(')') != -1);
- }
-
- protected String getBeanName(Object beanInstance) {
- if (beanInstance instanceof Configurable) {
- return ((Configurable)beanInstance).getBeanName();
- }
- String beanName = null;
- Method m = null;
- try {
- m = beanInstance.getClass().getDeclaredMethod("getBeanName", (Class[])null);
- } catch (NoSuchMethodException ex) {
- try {
- m = beanInstance.getClass().getMethod("getBeanName", (Class[])null);
- } catch (NoSuchMethodException e) {
- //ignore
- }
- }
- if (m != null) {
- try {
- beanName = (String)(m.invoke(beanInstance));
- } catch (Exception ex) {
- LogUtils.log(LOG, Level.WARNING, "ERROR_DETERMINING_BEAN_NAME_EXC", ex);
- }
- }
-
- if (null == beanName) {
- LogUtils.log(LOG, Level.FINE, "COULD_NOT_DETERMINE_BEAN_NAME_MSG",
- beanInstance.getClass().getName());
- }
-
- return beanName;
- }
-
- public final void setApplicationContext(ApplicationContext ac) {
- appContexts = new CopyOnWriteArraySet<>();
- addApplicationContext(ac);
- this.beanFactory = ac.getAutowireCapableBeanFactory();
- super.setBeanFactory(this.beanFactory);
- }
-
- public final void addApplicationContext(ApplicationContext ac) {
- if (!appContexts.contains(ac)) {
- appContexts.add(ac);
- List<ApplicationContext> inactiveApplicationContexts = new ArrayList<>();
- Iterator<ApplicationContext> it = appContexts.iterator();
- while (it.hasNext()) {
- ApplicationContext c = it.next();
- if (c instanceof ConfigurableApplicationContext
- && !((ConfigurableApplicationContext)c).isActive()) {
- inactiveApplicationContexts.add(c);
- }
- }
- // Remove the inactive application context here can avoid the UnsupportedOperationException
- for (ApplicationContext context : inactiveApplicationContexts) {
- appContexts.remove(context);
- }
- initWildcardDefinitionMap();
- }
- }
-
- @Override
- public void destroy() {
- super.destroy();
- appContexts.clear();
- }
-
- public Class<?> getRegistrationType() {
- return Configurer.class;
- }
-
- protected Set<ApplicationContext> getAppContexts() {
- return appContexts;
- }
-
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/databinding/source/SourceDataBinding.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/databinding/source/SourceDataBinding.java
deleted file mode 100644
index 5321779..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/databinding/source/SourceDataBinding.java
+++ /dev/null
@@ -1,104 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.cxf.databinding.source;
-
-
-import javax.xml.stream.XMLStreamReader;
-import javax.xml.stream.XMLStreamWriter;
-
-import org.w3c.dom.Node;
-
-import org.apache.cxf.common.xmlschema.SchemaCollection;
-import org.apache.cxf.databinding.DataReader;
-import org.apache.cxf.databinding.DataWriter;
-import org.apache.cxf.service.Service;
-import org.apache.cxf.service.ServiceModelVisitor;
-import org.apache.cxf.service.model.MessagePartInfo;
-import org.apache.cxf.service.model.ServiceInfo;
-import org.apache.ws.commons.schema.constants.Constants;
-
-/**
- * A simple databinding implementation which reads and writes Source objects.
- */
-public class SourceDataBinding extends org.apache.cxf.databinding.AbstractDataBinding {
-
- public static final String PREFERRED_FORMAT = "source-preferred-format";
-
- final Class<?> preferred;
-
- public SourceDataBinding() {
- super();
- preferred = null;
- }
- public SourceDataBinding(Class<?> pref) {
- super();
- preferred = pref;
- }
-
- public void initialize(Service service) {
- for (ServiceInfo serviceInfo : service.getServiceInfos()) {
- SchemaCollection schemaCollection = serviceInfo.getXmlSchemaCollection();
- if (schemaCollection.getXmlSchemas().length > 1) {
- // Schemas are already populated.
- continue;
- }
- new ServiceModelVisitor(serviceInfo) {
- @Override
- public void begin(MessagePartInfo part) {
- if (part.getTypeQName() != null || part.getElementQName() != null) {
- return;
- }
- part.setTypeQName(Constants.XSD_ANYTYPE);
- }
- } .walk();
- }
- }
-
-
- @SuppressWarnings("unchecked")
- public <T> DataReader<T> createReader(Class<T> cls) {
- if (cls == XMLStreamReader.class) {
- return (DataReader<T>) new XMLStreamDataReader(preferred);
- } else if (cls == Node.class) {
- return (DataReader<T>) new NodeDataReader();
- } else {
- throw new UnsupportedOperationException("The type " + cls.getName() + " is not supported.");
- }
- }
-
- public Class<?>[] getSupportedReaderFormats() {
- return new Class<?>[] {XMLStreamReader.class, Node.class};
- }
-
- @SuppressWarnings("unchecked")
- public <T> DataWriter<T> createWriter(Class<T> cls) {
- if (cls == XMLStreamWriter.class) {
- return (DataWriter<T>) new XMLStreamDataWriter();
- } else if (cls == Node.class) {
- return (DataWriter<T>) new NodeDataWriter();
- }
- throw new UnsupportedOperationException("The type " + cls.getName() + " is not supported.");
- }
-
- public Class<?>[] getSupportedWriterFormats() {
- return new Class<?>[] {XMLStreamWriter.class, Node.class};
- }
-
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/databinding/stax/StaxDataBinding.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/databinding/stax/StaxDataBinding.java
deleted file mode 100644
index 3cb836b..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/databinding/stax/StaxDataBinding.java
+++ /dev/null
@@ -1,187 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.cxf.databinding.stax;
-
-import java.util.Collection;
-import java.util.logging.Logger;
-
-import javax.xml.namespace.QName;
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamReader;
-import javax.xml.stream.XMLStreamWriter;
-import javax.xml.validation.Schema;
-
-import org.w3c.dom.Node;
-
-import org.apache.cxf.common.logging.LogUtils;
-import org.apache.cxf.common.xmlschema.SchemaCollection;
-import org.apache.cxf.databinding.AbstractInterceptorProvidingDataBinding;
-import org.apache.cxf.databinding.DataReader;
-import org.apache.cxf.databinding.DataWriter;
-import org.apache.cxf.interceptor.Fault;
-import org.apache.cxf.interceptor.StaxInEndingInterceptor;
-import org.apache.cxf.message.Attachment;
-import org.apache.cxf.message.Message;
-import org.apache.cxf.phase.AbstractPhaseInterceptor;
-import org.apache.cxf.phase.Phase;
-import org.apache.cxf.service.Service;
-import org.apache.cxf.service.ServiceModelVisitor;
-import org.apache.cxf.service.model.MessagePartInfo;
-import org.apache.cxf.service.model.ServiceInfo;
-import org.apache.cxf.staxutils.StaxUtils;
-import org.apache.ws.commons.schema.constants.Constants;
-
-/**
- * A simple databinding implementation which reads and writes Source objects.
- * This will not work with the standard databinding interceptors.
- */
-public class StaxDataBinding extends AbstractInterceptorProvidingDataBinding {
-
- private XMLStreamDataReader xsrReader;
- private XMLStreamDataWriter xswWriter;
-
- public StaxDataBinding() {
- super();
- this.xsrReader = new XMLStreamDataReader();
- this.xswWriter = new XMLStreamDataWriter();
- inInterceptors.add(new StaxInEndingInterceptor(Phase.POST_INVOKE));
- inFaultInterceptors.add(new StaxInEndingInterceptor(Phase.POST_INVOKE));
-
- inInterceptors.add(RemoveStaxInEndingInterceptor.INSTANCE);
- inFaultInterceptors.add(RemoveStaxInEndingInterceptor.INSTANCE);
- }
-
- static class RemoveStaxInEndingInterceptor extends AbstractPhaseInterceptor<Message> {
- static final RemoveStaxInEndingInterceptor INSTANCE = new RemoveStaxInEndingInterceptor();
-
- RemoveStaxInEndingInterceptor() {
- super(Phase.PRE_INVOKE);
- addBefore(StaxInEndingInterceptor.class.getName());
- }
-
- public void handleMessage(Message message) {
- message.getInterceptorChain().remove(StaxInEndingInterceptor.INSTANCE);
- }
- }
-
-
- public void initialize(Service service) {
- for (ServiceInfo serviceInfo : service.getServiceInfos()) {
- SchemaCollection schemaCollection = serviceInfo.getXmlSchemaCollection();
- if (schemaCollection.getXmlSchemas().length > 1) {
- // Schemas are already populated.
- continue;
- }
- new ServiceModelVisitor(serviceInfo) {
-
- @Override
- public void begin(MessagePartInfo part) {
- if (part.getTypeQName() != null || part.getElementQName() != null) {
- return;
- }
- part.setTypeQName(Constants.XSD_ANYTYPE);
- }
- } .walk();
- }
- }
-
- @SuppressWarnings("unchecked")
- public <T> DataReader<T> createReader(Class<T> cls) {
- if (cls == XMLStreamReader.class) {
- return (DataReader<T>) xsrReader;
- }
- throw new UnsupportedOperationException("The type " + cls.getName() + " is not supported.");
- }
-
- public Class<?>[] getSupportedReaderFormats() {
- return new Class<?>[] {XMLStreamReader.class};
- }
-
- @SuppressWarnings("unchecked")
- public <T> DataWriter<T> createWriter(Class<T> cls) {
- if (cls == XMLStreamWriter.class) {
- return (DataWriter<T>) xswWriter;
- }
- throw new UnsupportedOperationException("The type " + cls.getName() + " is not supported.");
- }
-
- public Class<?>[] getSupportedWriterFormats() {
- return new Class<?>[] {XMLStreamWriter.class, Node.class};
- }
-
- public static class XMLStreamDataReader implements DataReader<XMLStreamReader> {
-
- public Object read(MessagePartInfo part, XMLStreamReader input) {
- return read(null, input, part.getTypeClass());
- }
-
- public Object read(QName name, XMLStreamReader input, Class<?> type) {
- return input;
- }
-
- public Object read(XMLStreamReader reader) {
- return reader;
- }
-
- public void setSchema(Schema s) {
- }
-
- public void setAttachments(Collection<Attachment> attachments) {
- }
-
- public void setProperty(String prop, Object value) {
- }
- }
-
- public static class XMLStreamDataWriter implements DataWriter<XMLStreamWriter> {
- private static final Logger LOG = LogUtils.getL7dLogger(XMLStreamDataWriter.class);
-
- public void write(Object obj, MessagePartInfo part, XMLStreamWriter output) {
- write(obj, output);
- }
-
- public void write(Object obj, XMLStreamWriter writer) {
- try {
- if (obj instanceof XMLStreamReader) {
- XMLStreamReader xmlStreamReader = (XMLStreamReader) obj;
- StaxUtils.copy(xmlStreamReader, writer);
- xmlStreamReader.close();
- } else if (obj instanceof XMLStreamWriterCallback) {
- ((XMLStreamWriterCallback) obj).write(writer);
- } else {
- throw new UnsupportedOperationException("Data types of "
- + obj.getClass() + " are not supported.");
- }
- } catch (XMLStreamException e) {
- throw new Fault("COULD_NOT_READ_XML_STREAM", LOG, e);
- }
- }
-
- public void setSchema(Schema s) {
- }
-
- public void setAttachments(Collection<Attachment> attachments) {
- }
-
- public void setProperty(String key, Object value) {
- }
-
- }
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/endpoint/AbstractConduitSelector.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/endpoint/AbstractConduitSelector.java
deleted file mode 100644
index 250e523..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/endpoint/AbstractConduitSelector.java
+++ /dev/null
@@ -1,308 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.cxf.endpoint;
-
-import java.io.Closeable;
-import java.io.IOException;
-import java.util.List;
-import java.util.concurrent.CopyOnWriteArrayList;
-import java.util.logging.Logger;
-
-import org.apache.cxf.BusException;
-import org.apache.cxf.common.util.PropertyUtils;
-import org.apache.cxf.common.util.StringUtils;
-import org.apache.cxf.interceptor.Fault;
-import org.apache.cxf.message.Exchange;
-import org.apache.cxf.message.Message;
-import org.apache.cxf.message.MessageUtils;
-import org.apache.cxf.service.model.EndpointInfo;
-import org.apache.cxf.transport.Conduit;
-import org.apache.cxf.transport.ConduitInitiator;
-import org.apache.cxf.transport.ConduitInitiatorManager;
-import org.apache.cxf.transport.MessageObserver;
-import org.apache.cxf.ws.addressing.AttributedURIType;
-import org.apache.cxf.ws.addressing.EndpointReferenceType;
-
-
-/**
- * Abstract base class holding logic common to any ConduitSelector
- * that retrieves a Conduit from the ConduitInitiator.
- */
-public abstract class AbstractConduitSelector implements ConduitSelector, Closeable {
- public static final String CONDUIT_COMPARE_FULL_URL
- = "org.apache.cxf.ConduitSelector.compareFullUrl";
- protected static final String KEEP_CONDUIT_ALIVE = "KeepConduitAlive";
-
-
- //collection of conduits that were created so we can close them all at the end
- protected List<Conduit> conduits = new CopyOnWriteArrayList<>();
-
-
- protected Endpoint endpoint;
-
-
- public AbstractConduitSelector() {
- }
-
- /**
- * Constructor, allowing a specific conduit to override normal selection.
- *
- * @param c specific conduit
- */
- public AbstractConduitSelector(Conduit c) {
- if (c != null) {
- conduits.add(c);
- }
- }
-
- public void close() {
- for (Conduit c : conduits) {
- c.close();
- }
- conduits.clear();
- }
-
- protected void removeConduit(Conduit conduit) {
- if (conduit != null) {
- conduit.close();
- conduits.remove(conduit);
- }
- }
-
- /**
- * Mechanics to actually get the Conduit from the ConduitInitiator
- * if necessary.
- *
- * @param message the current Message
- */
- protected Conduit getSelectedConduit(Message message) {
- Conduit c = findCompatibleConduit(message);
- if (c == null) {
- Exchange exchange = message.getExchange();
- EndpointInfo ei = endpoint.getEndpointInfo();
- String transportID = ei.getTransportId();
- try {
- ConduitInitiatorManager conduitInitiatorMgr = exchange.getBus()
- .getExtension(ConduitInitiatorManager.class);
- if (conduitInitiatorMgr != null) {
- ConduitInitiator conduitInitiator =
- conduitInitiatorMgr.getConduitInitiator(transportID);
- if (conduitInitiator != null) {
- c = createConduit(message, exchange, conduitInitiator);
- } else {
- getLogger().warning("ConduitInitiator not found: "
- + ei.getAddress());
- }
- } else {
- getLogger().warning("ConduitInitiatorManager not found");
- }
- } catch (BusException | IOException ex) {
- throw new Fault(ex);
- }
- }
- if (c != null && c.getTarget() != null && c.getTarget().getAddress() != null) {
- replaceEndpointAddressPropertyIfNeeded(message, c.getTarget().getAddress().getValue(), c);
- }
- //the search for the conduit could cause extra properties to be reset/loaded.
- message.resetContextCache();
- message.put(Conduit.class, c);
- return c;
- }
-
- protected Conduit createConduit(Message message, Exchange exchange, ConduitInitiator conduitInitiator)
- throws IOException {
- Conduit c;
- synchronized (endpoint) {
- if (!conduits.isEmpty()) {
- c = findCompatibleConduit(message);
- if (c != null) {
- return c;
- }
- }
- EndpointInfo ei = endpoint.getEndpointInfo();
- String add = (String)message.get(Message.ENDPOINT_ADDRESS);
- String basePath = (String)message.get(Message.BASE_PATH);
- if (StringUtils.isEmpty(add)
- || add.equals(ei.getAddress())) {
- c = conduitInitiator.getConduit(ei, exchange.getBus());
- replaceEndpointAddressPropertyIfNeeded(message, add, c);
- } else {
- EndpointReferenceType epr = new EndpointReferenceType();
- AttributedURIType ad = new AttributedURIType();
- ad.setValue(StringUtils.isEmpty(basePath) ? add : basePath);
- epr.setAddress(ad);
- c = conduitInitiator.getConduit(ei, epr, exchange.getBus());
- }
- MessageObserver observer =
- exchange.get(MessageObserver.class);
- if (observer != null) {
- c.setMessageObserver(observer);
- } else {
- getLogger().warning("MessageObserver not found");
- }
- conduits.add(c);
- }
- return c;
- }
-
- // Some conduits may replace the endpoint address after it has already been prepared
- // but before the invocation has been done (ex, org.apache.cxf.clustering.LoadDistributorTargetSelector)
- // which may affect JAX-RS clients where actual endpoint address property may include additional path
- // segments.
- protected boolean replaceEndpointAddressPropertyIfNeeded(Message message,
- String endpointAddress,
- Conduit cond) {
- return false;
- }
-
- /**
- * @return the encapsulated Endpoint
- */
- public Endpoint getEndpoint() {
- return endpoint;
- }
-
- /**
- * @param ep the endpoint to encapsulate
- */
- public void setEndpoint(Endpoint ep) {
- endpoint = ep;
- }
-
- /**
- * Called on completion of the MEP for which the Conduit was required.
- *
- * @param exchange represents the completed MEP
- */
- public void complete(Exchange exchange) {
- // Clients expecting explicit InputStream responses
- // will need to keep low level conduits operating on InputStreams open
- // and will be responsible for closing the streams
-
- if (PropertyUtils.isTrue(exchange.get(KEEP_CONDUIT_ALIVE))) {
- return;
- }
- try {
- if (exchange.getInMessage() != null) {
- Conduit c = exchange.getOutMessage().get(Conduit.class);
- if (c == null) {
- getSelectedConduit(exchange.getInMessage()).close(exchange.getInMessage());
- } else {
- c.close(exchange.getInMessage());
- }
- }
- } catch (IOException e) {
- //IGNORE
- }
- }
- /**
- * @return the logger to use
- */
- protected abstract Logger getLogger();
-
- /**
- * If address protocol was changed, conduit should be re-initialised
- *
- * @param message the current Message
- */
- protected Conduit findCompatibleConduit(Message message) {
- Conduit c = message.get(Conduit.class);
- if (c == null
- && message.getExchange() != null
- && message.getExchange().getOutMessage() != null
- && message.getExchange().getOutMessage() != message) {
- c = message.getExchange().getOutMessage().get(Conduit.class);
- }
- if (c != null) {
- return c;
- }
- ContextualBooleanGetter cbg = new ContextualBooleanGetter(message);
- for (Conduit c2 : conduits) {
- if (c2.getTarget() == null
- || c2.getTarget().getAddress() == null
- || c2.getTarget().getAddress().getValue() == null) {
- continue;
- }
- String conduitAddress = c2.getTarget().getAddress().getValue();
-
- EndpointInfo ei = endpoint.getEndpointInfo();
- String actualAddress = ei.getAddress();
-
- String messageAddress = (String)message.get(Message.ENDPOINT_ADDRESS);
- if (messageAddress != null) {
- actualAddress = messageAddress;
- }
-
- if (matchAddresses(conduitAddress, actualAddress, cbg)) {
- return c2;
- }
- }
- for (Conduit c2 : conduits) {
- if (c2.getTarget() == null
- || c2.getTarget().getAddress() == null
- || c2.getTarget().getAddress().getValue() == null) {
- return c2;
- }
- }
- return null;
- }
-
- private boolean matchAddresses(String conduitAddress, String actualAddress, ContextualBooleanGetter cbg) {
- if (conduitAddress.length() == actualAddress.length()) {
- //let's be optimistic and try full comparison first, regardless of CONDUIT_COMPARE_FULL_URL value,
- //which can be expensive to fetch; as a matter of fact, anyway, if the addresses fully match,
- //their hosts also match
- if (conduitAddress.equalsIgnoreCase(actualAddress)) {
- return true;
- }
- return !cbg.isFullComparison() && matchAddressSubstrings(conduitAddress, actualAddress);
- }
- return !cbg.isFullComparison() && matchAddressSubstrings(conduitAddress, actualAddress);
- }
-
- //smart address substring comparison that tries to avoid building and comparing substrings unless strictly required
- private boolean matchAddressSubstrings(String conduitAddress, String actualAddress) {
- int idx = conduitAddress.indexOf(':');
- if (idx == actualAddress.indexOf(':')) {
- if (idx <= 0) {
- return true;
- }
- return conduitAddress.substring(0, idx).equalsIgnoreCase(actualAddress.substring(0, idx));
- }
- //no possible match as for sure the substrings before idx will be different
- return false;
- }
-
- private static final class ContextualBooleanGetter {
- private Boolean value;
- private final Message message;
-
- ContextualBooleanGetter(Message message) {
- this.message = message;
- }
-
- public boolean isFullComparison() {
- if (value == null) {
- value = MessageUtils.getContextualBoolean(message, CONDUIT_COMPARE_FULL_URL, false);
- }
- return value;
- }
- }
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/endpoint/ClientCallback.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/endpoint/ClientCallback.java
deleted file mode 100644
index 467b5a8..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/endpoint/ClientCallback.java
+++ /dev/null
@@ -1,166 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.cxf.endpoint;
-
-import java.util.Map;
-import java.util.concurrent.CancellationException;
-import java.util.concurrent.CompletableFuture;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.Future;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.TimeoutException;
-
-import org.apache.cxf.message.Message;
-
-/**
- * Asynchronous callback object for calls to {@link Client#invoke(ClientCallback, String, Object...)}
- * and related functions.
- *
- * The default behavior of this expects the following pattern:
- * <ol>
- * <li>ClientCallback cb = new ClientCallback();<>
- * <li>client.invoke(cb, "someMethod", ....);</li>
- * <li>cb.wait();</li>
- * <li>// CXF calls notify on the callback object when the operation is complete.</li>
- * </ol>
- */
-public class ClientCallback implements Future<Object[]> {
- protected final CompletableFuture<Object[]> delegate = new CompletableFuture<>();
- protected Map<String, Object> context;
- protected boolean started;
-
- public ClientCallback() {
- }
-
- /**
- * Called when a message is first received prior to any actions
- * being applied to the message. The InterceptorChain is setup so
- * modifications to that can be done.
- */
- public void start(Message msg) {
- started = true;
- }
-
- /**
- * If the processing of the incoming message proceeds normally, this
- * method is called with the response context values and the resulting objects.
- *
- * The default behavior just stores the objects and calls notifyAll to wake
- * up threads waiting for the response.
- *
- * @param ctx
- * @param res
- */
- public void handleResponse(Map<String, Object> ctx, Object[] res) {
- context = ctx;
- delegate.complete(res);
-
- synchronized (this) {
- notifyAll();
- }
- }
-
- /**
- * If processing of the incoming message results in an exception, this
- * method is called with the resulting exception.
- *
- * The default behavior just stores the objects and calls notifyAll to wake
- * up threads waiting for the response.
- *
- * @param ctx
- * @param ex
- */
- public void handleException(Map<String, Object> ctx, Throwable ex) {
- context = ctx;
- delegate.completeExceptionally(ex);
-
- synchronized (this) {
- notifyAll();
- }
- }
-
-
- public boolean cancel(boolean mayInterruptIfRunning) {
- if (!started) {
- delegate.cancel(mayInterruptIfRunning);
-
- synchronized (this) {
- notifyAll();
- }
-
- return true;
- }
- return false;
- }
-
- /**
- * return the map of items returned from an operation.
- * @return the response context
- * @throws InterruptedException if the operation was cancelled.
- * @throws ExecutionException if the operation resulted in a fault.
- */
- public Map<String, Object> getResponseContext() throws InterruptedException, ExecutionException {
- synchronized (this) {
- if (!delegate.isDone()) {
- wait();
- }
- }
- if (delegate.isCancelled()) {
- throw new InterruptedException("Operation Cancelled");
- }
- if (delegate.isCompletedExceptionally()) {
- delegate.get();
- }
- return context;
- }
-
- /**
- * {@inheritDoc}
- */
- public Object[] get() throws InterruptedException, ExecutionException {
- try {
- return delegate.get();
- } catch (final CancellationException ex) {
- // Preserving the exception raised by former implementation
- throw new InterruptedException("Operation has been cancelled");
- }
- }
-
- /**
- * {@inheritDoc}
- */
- public Object[] get(long timeout, TimeUnit unit) throws InterruptedException,
- ExecutionException, TimeoutException {
- try {
- return delegate.get(timeout, unit);
- } catch (final CancellationException ex) {
- // Preserving the exception raised by former implementation
- throw new InterruptedException("Operation has been cancelled");
- }
- }
-
- public boolean isCancelled() {
- return delegate.isCancelled();
- }
-
- public boolean isDone() {
- return delegate.isDone();
- }
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/endpoint/ClientImpl.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/endpoint/ClientImpl.java
deleted file mode 100644
index 53d3a43..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/endpoint/ClientImpl.java
+++ /dev/null
@@ -1,1192 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.cxf.endpoint;
-
-import java.io.Closeable;
-import java.io.IOException;
-import java.io.Serializable;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.WeakHashMap;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.Executor;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import javax.xml.namespace.QName;
-import javax.xml.ws.handler.MessageContext;
-
-import org.apache.cxf.Bus;
-import org.apache.cxf.BusFactory;
-import org.apache.cxf.binding.Binding;
-import org.apache.cxf.common.classloader.ClassLoaderUtils;
-import org.apache.cxf.common.classloader.ClassLoaderUtils.ClassLoaderHolder;
-import org.apache.cxf.common.i18n.UncheckedException;
-import org.apache.cxf.common.logging.LogUtils;
-import org.apache.cxf.common.util.PropertyUtils;
-import org.apache.cxf.helpers.CastUtils;
-import org.apache.cxf.interceptor.AbstractBasicInterceptorProvider;
-import org.apache.cxf.interceptor.ClientOutFaultObserver;
-import org.apache.cxf.interceptor.Fault;
-import org.apache.cxf.interceptor.Interceptor;
-import org.apache.cxf.interceptor.InterceptorChain;
-import org.apache.cxf.interceptor.InterceptorProvider;
-import org.apache.cxf.message.Exchange;
-import org.apache.cxf.message.ExchangeImpl;
-import org.apache.cxf.message.Message;
-import org.apache.cxf.message.MessageContentsList;
-import org.apache.cxf.message.MessageImpl;
-import org.apache.cxf.phase.PhaseChainCache;
-import org.apache.cxf.phase.PhaseInterceptorChain;
-import org.apache.cxf.phase.PhaseManager;
-import org.apache.cxf.service.Service;
-import org.apache.cxf.service.model.BindingInfo;
-import org.apache.cxf.service.model.BindingMessageInfo;
-import org.apache.cxf.service.model.BindingOperationInfo;
-import org.apache.cxf.service.model.EndpointInfo;
-import org.apache.cxf.service.model.MessageInfo;
-import org.apache.cxf.service.model.ServiceInfo;
-import org.apache.cxf.transport.Conduit;
-import org.apache.cxf.transport.MessageObserver;
-import org.apache.cxf.workqueue.SynchronousExecutor;
-
-public class ClientImpl
- extends AbstractBasicInterceptorProvider
- implements Client, Retryable, MessageObserver {
-
- public static final String THREAD_LOCAL_REQUEST_CONTEXT = "thread.local.request.context";
- /**
- * When a synchronous request/response invoke is done using an asynchronous transport mechanism,
- * this is the timeout used for waiting for the response. Default is 60 seconds.
- */
- public static final String SYNC_TIMEOUT = "cxf.synchronous.timeout";
-
- public static final String FINISHED = "exchange.finished";
-
- private static final Logger LOG = LogUtils.getL7dLogger(ClientImpl.class);
-
- protected Bus bus;
- protected ConduitSelector conduitSelector;
- protected ClientOutFaultObserver outFaultObserver;
- protected int synchronousTimeout = 60000; // default 60 second timeout
-
- protected PhaseChainCache outboundChainCache = new PhaseChainCache();
- protected PhaseChainCache inboundChainCache = new PhaseChainCache();
-
- protected Map<String, Object> currentRequestContext = new ConcurrentHashMap<>(8, 0.75f, 4);
- protected Thread latestContextThread;
- protected Map<Thread, EchoContext> requestContext
- = Collections.synchronizedMap(new WeakHashMap<Thread, EchoContext>());
-
- protected Map<Thread, ResponseContext> responseContext
- = Collections.synchronizedMap(new WeakHashMap<Thread, ResponseContext>());
-
- protected Executor executor;
-
- public ClientImpl(Bus b, Endpoint e) {
- this(b, e, (ConduitSelector)null);
- }
-
- public ClientImpl(Bus b, Endpoint e, Conduit c) {
- this(b, e, new PreexistingConduitSelector(c));
- }
-
- public ClientImpl(Bus b, Endpoint e, ConduitSelector sc) {
- bus = b;
- outFaultObserver = new ClientOutFaultObserver(bus);
- getConduitSelector(sc).setEndpoint(e);
- notifyLifecycleManager();
- }
-
- /**
- * Create a Client that uses a specific EndpointImpl.
- * @param bus
- * @param svc
- * @param port
- * @param endpointImplFactory
- */
- public ClientImpl(Bus bus, Service svc, QName port,
- EndpointImplFactory endpointImplFactory) {
- this.bus = bus;
- outFaultObserver = new ClientOutFaultObserver(bus);
- EndpointInfo epfo = findEndpoint(svc, port);
-
- try {
- if (endpointImplFactory != null) {
- getConduitSelector().setEndpoint(endpointImplFactory.newEndpointImpl(bus, svc, epfo));
- } else {
- getConduitSelector().setEndpoint(new EndpointImpl(bus, svc, epfo));
- }
- } catch (EndpointException epex) {
- throw new IllegalStateException("Unable to create endpoint: " + epex.getMessage(), epex);
- }
- notifyLifecycleManager();
- }
-
- public Bus getBus() {
- return bus;
- }
-
- public void destroy() {
- if (bus == null) {
- return;
- }
- if (getEndpoint() != null) {
- for (Closeable c : getEndpoint().getCleanupHooks()) {
- try {
- c.close();
- } catch (IOException e) {
- //ignore
- }
- }
- }
- ClientLifeCycleManager mgr = bus.getExtension(ClientLifeCycleManager.class);
- if (null != mgr) {
- mgr.clientDestroyed(this);
- }
-
- if (conduitSelector != null) {
- if (conduitSelector instanceof Closeable) {
- try {
- ((Closeable)conduitSelector).close();
- } catch (IOException e) {
- //ignore, we're destroying anyway
- }
- } else {
- getConduit().close();
- }
- }
-
- bus = null;
- conduitSelector = null;
- outFaultObserver = null;
- outboundChainCache = null;
- inboundChainCache = null;
-
- currentRequestContext = null;
- requestContext.clear();
- requestContext = null;
- responseContext.clear();
- responseContext = null;
- executor = null;
- }
-
- private void notifyLifecycleManager() {
- ClientLifeCycleManager mgr = bus.getExtension(ClientLifeCycleManager.class);
- if (null != mgr) {
- mgr.clientCreated(this);
- }
- }
-
- private EndpointInfo findEndpoint(Service svc, QName port) {
- if (port != null) {
- EndpointInfo epfo = svc.getEndpointInfo(port);
- if (epfo == null) {
- throw new IllegalArgumentException("The service " + svc.getName()
- + " does not have an endpoint " + port + ".");
- }
- return epfo;
- }
-
- for (ServiceInfo svcfo : svc.getServiceInfos()) {
- for (EndpointInfo e : svcfo.getEndpoints()) {
- BindingInfo bfo = e.getBinding();
- String bid = bfo.getBindingId();
- if ("http://schemas.xmlsoap.org/wsdl/soap/".equals(bid)
- || "http://schemas.xmlsoap.org/wsdl/soap12/".equals(bid)) {
- for (Object o : bfo.getExtensors().get()) {
- try {
- String s = (String)o.getClass().getMethod("getTransportURI").invoke(o);
- if (s != null && s.endsWith("http")) {
- return e;
- }
- } catch (Throwable t) {
- //ignore
- }
- }
- }
- }
- }
- throw new UnsupportedOperationException(
- "Only document-style SOAP 1.1 and 1.2 http are supported "
- + "for auto-selection of endpoint; none were found.");
- }
-
- public Endpoint getEndpoint() {
- return getConduitSelector().getEndpoint();
- }
-
- public void releaseThreadContexts() {
- final Thread t = Thread.currentThread();
- requestContext.remove(t);
- responseContext.remove(t);
- }
-
- @Override
- public Contexts getContexts() {
- return new Contexts() {
- @Override
- public void close() throws Exception {
- releaseThreadContexts();
- }
- @Override
- public Map<String, Object> getRequestContext() {
- return ClientImpl.this.getRequestContext();
- }
- @Override
- public Map<String, Object> getResponseContext() {
- return ClientImpl.this.getResponseContext();
- }
- };
- }
-
- public Map<String, Object> getRequestContext() {
- if (isThreadLocalRequestContext()) {
- final Thread t = Thread.currentThread();
- requestContext.computeIfAbsent(t, k -> new EchoContext(currentRequestContext));
- latestContextThread = t;
- return requestContext.get(t);
- }
- return currentRequestContext;
- }
- public Map<String, Object> getResponseContext() {
- if (!responseContext.containsKey(Thread.currentThread())) {
- final Thread t = Thread.currentThread();
- responseContext.put(t, new ResponseContext(responseContext));
- }
- return responseContext.get(Thread.currentThread());
- }
- protected Map<String, Object> setResponseContext(Map<String, Object> ctx) {
- if (ctx instanceof ResponseContext) {
- ResponseContext c = (ResponseContext)ctx;
- responseContext.put(Thread.currentThread(), c);
- return c;
- }
- ResponseContext c = new ResponseContext(ctx, responseContext);
- responseContext.put(Thread.currentThread(), c);
- return c;
- }
- public boolean isThreadLocalRequestContext() {
- Object o = currentRequestContext.get(THREAD_LOCAL_REQUEST_CONTEXT);
- if (o != null) {
- final boolean local;
- if (o instanceof Boolean) {
- local = ((Boolean)o).booleanValue();
- } else {
- local = Boolean.parseBoolean(o.toString());
- }
- return local;
- }
- return false;
- }
- public void setThreadLocalRequestContext(boolean b) {
- currentRequestContext.put(THREAD_LOCAL_REQUEST_CONTEXT, b);
- }
-
-
- public Object[] invoke(BindingOperationInfo oi, Object... params) throws Exception {
- return invoke(oi, params, null);
- }
-
- public Object[] invoke(String operationName, Object... params) throws Exception {
- QName q = new QName(getEndpoint().getService().getName().getNamespaceURI(), operationName);
-
- return invoke(q, params);
- }
-
- public Object[] invoke(QName operationName, Object... params) throws Exception {
- BindingOperationInfo op = getEndpoint().getEndpointInfo().getBinding().getOperation(operationName);
- if (op == null) {
- throw new UncheckedException(
- new org.apache.cxf.common.i18n.Message("NO_OPERATION", LOG, operationName));
- }
-
- if (op.isUnwrappedCapable()) {
- op = op.getUnwrappedOperation();
- }
-
- return invoke(op, params);
- }
-
- public Object[] invokeWrapped(String operationName, Object... params) throws Exception {
- QName q = new QName(getEndpoint().getService().getName().getNamespaceURI(), operationName);
-
- return invokeWrapped(q, params);
- }
-
- public Object[] invokeWrapped(QName operationName, Object... params) throws Exception {
- BindingOperationInfo op = getEndpoint().getEndpointInfo().getBinding().getOperation(operationName);
- if (op == null) {
- throw new UncheckedException(
- new org.apache.cxf.common.i18n.Message("NO_OPERATION", LOG, operationName));
- }
- return invoke(op, params);
- }
-
- public Object[] invoke(BindingOperationInfo oi,
- Object[] params,
- Exchange exchange) throws Exception {
- Map<String, Object> context = new HashMap<>();
- return invoke(oi, params, context, exchange);
- }
- public Object[] invoke(BindingOperationInfo oi,
- Object[] params,
- Map<String, Object> context) throws Exception {
- return invoke(oi, params, context, (Exchange)null);
- }
-
- public void invoke(ClientCallback callback,
- String operationName,
- Object... params) throws Exception {
- QName q = new QName(getEndpoint().getService().getName().getNamespaceURI(), operationName);
- invoke(callback, q, params);
- }
-
- public void invoke(ClientCallback callback,
- QName operationName,
- Object... params) throws Exception {
- BindingOperationInfo op = getEndpoint().getEndpointInfo().getBinding().getOperation(operationName);
- if (op == null) {
- throw new UncheckedException(
- new org.apache.cxf.common.i18n.Message("NO_OPERATION", LOG, operationName));
- }
-
- if (op.isUnwrappedCapable()) {
- op = op.getUnwrappedOperation();
- }
-
- invoke(callback, op, params);
- }
-
-
- public void invokeWrapped(ClientCallback callback,
- String operationName,
- Object... params)
- throws Exception {
- QName q = new QName(getEndpoint().getService().getName().getNamespaceURI(), operationName);
- invokeWrapped(callback, q, params);
- }
-
- public void invokeWrapped(ClientCallback callback,
- QName operationName,
- Object... params)
- throws Exception {
- BindingOperationInfo op = getEndpoint().getEndpointInfo().getBinding().getOperation(operationName);
- if (op == null) {
- throw new UncheckedException(
- new org.apache.cxf.common.i18n.Message("NO_OPERATION", LOG, operationName));
- }
- invoke(callback, op, params);
- }
-
-
- public void invoke(ClientCallback callback,
- BindingOperationInfo oi,
- Object... params) throws Exception {
- invoke(callback, oi, params, null, null);
- }
-
- public void invoke(ClientCallback callback,
- BindingOperationInfo oi,
- Object[] params,
- Map<String, Object> context) throws Exception {
- invoke(callback, oi, params, context, null);
- }
-
- public void invoke(ClientCallback callback,
- BindingOperationInfo oi,
- Object[] params,
- Exchange exchange) throws Exception {
- invoke(callback, oi, params, null, exchange);
- }
-
- public void invoke(ClientCallback callback,
- BindingOperationInfo oi,
- Object[] params,
- Map<String, Object> context,
- Exchange exchange) throws Exception {
- doInvoke(callback, oi, params, context, exchange);
- }
-
- public Object[] invoke(BindingOperationInfo oi,
- Object[] params,
- Map<String, Object> context,
- Exchange exchange) throws Exception {
- return doInvoke(null, oi, params, context, exchange);
- }
-
- private Object[] doInvoke(final ClientCallback callback,
- BindingOperationInfo oi,
- Object[] params,
- Map<String, Object> context,
- Exchange exchange) throws Exception {
- Bus origBus = BusFactory.getAndSetThreadDefaultBus(bus);
- ClassLoaderHolder origLoader = null;
- Map<String, Object> resContext = null;
- try {
- ClassLoader loader = bus.getExtension(ClassLoader.class);
- if (loader != null) {
- origLoader = ClassLoaderUtils.setThreadContextClassloader(loader);
- }
- if (exchange == null) {
- exchange = new ExchangeImpl();
- }
- exchange.setSynchronous(callback == null);
- Endpoint endpoint = getEndpoint();
- if (LOG.isLoggable(Level.FINE)) {
- LOG.fine("Invoke, operation info: " + oi + ", params: " + Arrays.toString(params));
- }
- Message message = endpoint.getBinding().createMessage();
-
- // Make sure INVOCATION CONTEXT, REQUEST_CONTEXT and RESPONSE_CONTEXT are present
- // on message
- if (context == null) {
- context = new HashMap<>();
- }
- Map<String, Object> reqContext = CastUtils.cast((Map<?, ?>)context.get(REQUEST_CONTEXT));
- resContext = CastUtils.cast((Map<?, ?>)context.get(RESPONSE_CONTEXT));
- if (reqContext == null) {
- reqContext = new HashMap<>(getRequestContext());
- context.put(REQUEST_CONTEXT, reqContext);
- }
- if (resContext == null) {
- resContext = new ResponseContext(responseContext);
- context.put(RESPONSE_CONTEXT, resContext);
- }
-
- message.put(Message.INVOCATION_CONTEXT, context);
- setContext(reqContext, message);
- exchange.putAll(reqContext);
-
- setParameters(params, message);
-
- if (null != oi) {
- exchange.setOneWay(oi.getOutput() == null);
- }
-
- exchange.setOutMessage(message);
- exchange.put(ClientCallback.class, callback);
-
- setOutMessageProperties(message, oi);
- setExchangeProperties(exchange, endpoint, oi);
-
- PhaseInterceptorChain chain = setupInterceptorChain(endpoint);
- message.setInterceptorChain(chain);
- if (callback == null) {
- chain.setFaultObserver(outFaultObserver);
- } else {
- // We need to wrap the outFaultObserver if the callback is not null
- // calling the conduitSelector.complete to make sure the fail over feature works
- chain.setFaultObserver(new MessageObserver() {
- public void onMessage(Message message) {
- Exception ex = message.getContent(Exception.class);
- if (ex != null) {
- completeExchange(message.getExchange());
- if (message.getContent(Exception.class) == null) {
- // handle the right response
- Message inMsg = message.getExchange().getInMessage();
- Map<String, Object> ctx = responseContext.get(Thread.currentThread());
- List<Object> resList = CastUtils.cast(inMsg.getContent(List.class));
- Object[] result = resList == null ? null : resList.toArray();
- callback.handleResponse(ctx, result);
- return;
- }
- }
- outFaultObserver.onMessage(message);
- }
- });
- }
- prepareConduitSelector(message);
-
- // add additional interceptors and such
- modifyChain(chain, message, false);
- try {
- chain.doIntercept(message);
- } catch (Fault fault) {
- enrichFault(fault);
- throw fault;
- }
-
- if (callback != null) {
- return null;
- }
- return processResult(message, exchange, oi, resContext);
- } finally {
- //ensure ResponseContext has HTTP RESPONSE CODE
- if (null != exchange) {
- Integer responseCode = (Integer)exchange.get(Message.RESPONSE_CODE);
- resContext.put(MessageContext.HTTP_RESPONSE_CODE, responseCode);
- resContext.put(org.apache.cxf.message.Message.RESPONSE_CODE, responseCode);
- setResponseContext(resContext);
- }
- if (origLoader != null) {
- origLoader.reset();
- }
- if (origBus != bus) {
- BusFactory.setThreadDefaultBus(origBus);
- }
- }
- }
-
- private void completeExchange(Exchange exchange) {
- getConduitSelector().complete(exchange);
- }
-
- /**
- * TODO This is SOAP specific code and should not be in cxf core
- * @param fault
- */
- private void enrichFault(Fault fault) {
- if (fault.getCause().getCause() instanceof IOException
- || fault.getCause() instanceof IOException) {
- String soap11NS = "http://schemas.xmlsoap.org/soap/envelope/";
- String soap12NS = "http://www.w3.org/2003/05/soap-envelope";
- QName faultCode = fault.getFaultCode();
- //for SoapFault, if it's underlying cause is IOException,
- //it means something like server is down or can't create
- //connection, according to soap spec we should set fault as
- //Server Fault
- if (faultCode.getNamespaceURI().equals(
- soap11NS)
- && "Client".equals(faultCode.getLocalPart())) {
- faultCode = new QName(soap11NS, "Server");
- fault.setFaultCode(faultCode);
- }
- if (faultCode.getNamespaceURI().equals(
- soap12NS)
- && "Sender".equals(faultCode.getLocalPart())) {
- faultCode = new QName(soap12NS, "Receiver");
- fault.setFaultCode(faultCode);
- }
- }
- }
-
- protected Object[] processResult(Message message,
- Exchange exchange,
- BindingOperationInfo oi,
- Map<String, Object> resContext) throws Exception {
- Exception ex = null;
- // Check to see if there is a Fault from the outgoing chain if it's an out Message
- if (!message.get(Message.INBOUND_MESSAGE).equals(Boolean.TRUE)) {
- ex = message.getContent(Exception.class);
- }
- boolean mepCompleteCalled = false;
- if (ex != null) {
- completeExchange(exchange);
- mepCompleteCalled = true;
- if (message.getContent(Exception.class) != null) {
- throw ex;
- }
- }
- ex = message.getExchange().get(Exception.class);
- if (ex != null) {
- if (!mepCompleteCalled) {
- completeExchange(exchange);
- }
- throw ex;
- }
-
- //REVISIT
- // - use a protocol neutral no-content marker instead of 202?
- // - move the decoupled destination property name into api
- Integer responseCode = (Integer)exchange.get(Message.RESPONSE_CODE);
- if (null != responseCode && 202 == responseCode) {
- Endpoint ep = exchange.getEndpoint();
- if (null != ep && null != ep.getEndpointInfo() && null == ep.getEndpointInfo().
- getProperty("org.apache.cxf.ws.addressing.MAPAggregator.decoupledDestination")) {
- return null;
- }
- }
-
- // Wait for a response if we need to
- if (oi != null && !oi.getOperationInfo().isOneWay()) {
- waitResponse(exchange);
- }
-
- // leave the input stream open for the caller
- Boolean keepConduitAlive = (Boolean)exchange.get(Client.KEEP_CONDUIT_ALIVE);
- if (keepConduitAlive == null || !keepConduitAlive) {
- completeExchange(exchange);
- }
-
- // Grab the response objects if there are any
- List<Object> resList = null;
- Message inMsg = exchange.getInMessage();
- if (inMsg != null) {
- if (null != resContext) {
- resContext.putAll(inMsg);
- // remove the recursive reference if present
- resContext.remove(Message.INVOCATION_CONTEXT);
- setResponseContext(resContext);
- }
- resList = CastUtils.cast(inMsg.getContent(List.class));
- }
-
- // check for an incoming fault
- ex = getException(exchange);
-
- if (ex != null) {
- throw ex;
- }
-
- if (resList == null
- && oi != null && !oi.getOperationInfo().isOneWay()) {
-
- BindingOperationInfo boi = oi;
- if (boi.isUnwrapped()) {
- boi = boi.getWrappedOperation();
- }
- if (!boi.getOutput().getMessageParts().isEmpty()) {
- //we were supposed to get some output, but didn't.
- throw new IllegalEmptyResponseException("Response message did not contain proper response data."
- + " Expected: " + boi.getOutput().getMessageParts().get(0).getConcreteName());
- }
- }
- if (resList != null) {
- return resList.toArray();
- }
-
- return null;
- }
- protected Exception getException(Exchange exchange) {
- if (exchange.getInFaultMessage() != null) {
- return exchange.getInFaultMessage().getContent(Exception.class);
- } else if (exchange.getOutFaultMessage() != null) {
- return exchange.getOutFaultMessage().getContent(Exception.class);
- } else if (exchange.getInMessage() != null) {
- return exchange.getInMessage().getContent(Exception.class);
- }
- return null;
- }
-
- protected void setContext(Map<String, Object> ctx, Message message) {
- if (ctx != null) {
- message.putAll(ctx);
- if (LOG.isLoggable(Level.FINE)) {
- LOG.fine("set requestContext to message be" + ctx);
- }
- }
- }
-
- protected void waitResponse(Exchange exchange) throws IOException {
- synchronized (exchange) {
- long remaining = synchronousTimeout;
- Long o = PropertyUtils.getLong(exchange.getOutMessage(), SYNC_TIMEOUT);
- if (o != null) {
- remaining = o;
- }
- while (!Boolean.TRUE.equals(exchange.get(FINISHED)) && remaining > 0) {
- long start = System.currentTimeMillis();
- try {
- exchange.wait(remaining);
- } catch (InterruptedException ex) {
- // ignore
- }
- long end = System.currentTimeMillis();
- remaining -= (int)(end - start);
- }
- if (!Boolean.TRUE.equals(exchange.get(FINISHED))) {
- LogUtils.log(LOG, Level.WARNING, "RESPONSE_TIMEOUT",
- exchange.getBindingOperationInfo().getOperationInfo().getName().toString());
- String msg = new org.apache.cxf.common.i18n.Message("RESPONSE_TIMEOUT", LOG, exchange
- .getBindingOperationInfo().getOperationInfo().getName().toString()).toString();
- throw new IOException(msg);
- }
- }
- }
-
- protected void setParameters(Object[] params, Message message) {
- MessageContentsList contents = new MessageContentsList(params);
- message.setContent(List.class, contents);
- }
-
- public void onMessage(Message message) {
- if (bus == null) {
- throw new IllegalStateException("Message received on a Client that has been closed or destroyed.");
- }
- Endpoint endpoint = message.getExchange().getEndpoint();
- if (endpoint == null) {
- // in this case correlation will occur outside the transport,
- // however there's a possibility that the endpoint may have been
- // rebased in the meantime, so that the response will be mediated
- // via a set of in interceptors provided by a *different* endpoint
- //
- endpoint = getConduitSelector().getEndpoint();
- message.getExchange().put(Endpoint.class, endpoint);
- }
- message = endpoint.getBinding().createMessage(message);
- message.getExchange().setInMessage(message);
- message.put(Message.REQUESTOR_ROLE, Boolean.TRUE);
- message.put(Message.INBOUND_MESSAGE, Boolean.TRUE);
- PhaseManager pm = bus.getExtension(PhaseManager.class);
-
- List<Interceptor<? extends Message>> i1 = bus.getInInterceptors();
- if (LOG.isLoggable(Level.FINE)) {
- LOG.fine("Interceptors contributed by bus: " + i1);
- }
- List<Interceptor<? extends Message>> i2 = getInInterceptors();
- if (LOG.isLoggable(Level.FINE)) {
- LOG.fine("Interceptors contributed by client: " + i2);
- }
- List<Interceptor<? extends Message>> i3 = endpoint.getInInterceptors();
- if (LOG.isLoggable(Level.FINE)) {
- LOG.fine("Interceptors contributed by endpoint: " + i3);
- }
- List<Interceptor<? extends Message>> i4 = endpoint.getBinding().getInInterceptors();
- if (LOG.isLoggable(Level.FINE)) {
- LOG.fine("Interceptors contributed by binding: " + i4);
- }
-
- PhaseInterceptorChain chain;
- if (endpoint.getService().getDataBinding() instanceof InterceptorProvider) {
- InterceptorProvider p = (InterceptorProvider)endpoint.getService().getDataBinding();
- if (LOG.isLoggable(Level.FINE)) {
- LOG.fine("Interceptors contributed by databinding: " + p.getInInterceptors());
- }
- chain = inboundChainCache.get(pm.getInPhases(), i1, i2, i3, i4,
- p.getInInterceptors());
- } else {
- chain = inboundChainCache.get(pm.getInPhases(), i1, i2, i3, i4);
- }
- message.setInterceptorChain(chain);
-
- chain.setFaultObserver(outFaultObserver);
- modifyChain(chain, message, true);
- modifyChain(chain, message.getExchange().getOutMessage(), true);
-
- Bus origBus = BusFactory.getAndSetThreadDefaultBus(bus);
- // execute chain
- ClientCallback callback = message.getExchange().get(ClientCallback.class);
- try {
- if (callback != null) {
- if (callback.isCancelled()) {
- completeExchange(message.getExchange());
- return;
- }
- callback.start(message);
- }
-
- String startingAfterInterceptorID = (String) message.get(
- InterceptorChain.STARTING_AFTER_INTERCEPTOR_ID);
- String startingInterceptorID = (String) message.get(
- InterceptorChain.STARTING_AT_INTERCEPTOR_ID);
- if (startingAfterInterceptorID != null) {
- chain.doInterceptStartingAfter(message, startingAfterInterceptorID);
- } else if (startingInterceptorID != null) {
- chain.doInterceptStartingAt(message, startingInterceptorID);
- } else if (message.getContent(Exception.class) != null) {
- outFaultObserver.onMessage(message);
- } else {
- callback = message.getExchange().get(ClientCallback.class);
-
- if (callback != null && !isPartialResponse(message)) {
- try {
- chain.doIntercept(message);
- } catch (Throwable error) {
- //so that asyn callback handler get chance to
- //handle non-runtime exceptions
- message.getExchange().setInMessage(message);
- Map<String, Object> resCtx = CastUtils
- .cast((Map<?, ?>) message.getExchange()
- .getOutMessage().get(
- Message.INVOCATION_CONTEXT));
- resCtx = CastUtils.cast((Map<?, ?>) resCtx
- .get(RESPONSE_CONTEXT));
- if (resCtx != null) {
- setResponseContext(resCtx);
- }
- // remove callback so that it won't be invoked twice
- callback = message.getExchange().remove(ClientCallback.class);
- if (callback != null) {
- callback.handleException(resCtx, error);
- }
- }
- } else {
- chain.doIntercept(message);
- }
-
- }
-
- callback = message.getExchange().get(ClientCallback.class);
- if (callback == null || isPartialResponse(message)) {
- return;
- }
-
- // remove callback so that it won't be invoked twice
- callback = message.getExchange().remove(ClientCallback.class);
- if (callback != null) {
- message.getExchange().setInMessage(message);
- Map<String, Object> resCtx = CastUtils.cast((Map<?, ?>)message
- .getExchange()
- .getOutMessage()
- .get(Message.INVOCATION_CONTEXT));
- resCtx = CastUtils.cast((Map<?, ?>)resCtx.get(RESPONSE_CONTEXT));
- if (resCtx != null && responseContext != null) {
- setResponseContext(resCtx);
- }
- try {
- Object[] obj = processResult(message, message.getExchange(),
- null, resCtx);
-
- callback.handleResponse(resCtx, obj);
- } catch (Throwable ex) {
- callback.handleException(resCtx, ex);
- }
- }
- } finally {
- if (origBus != bus) {
- BusFactory.setThreadDefaultBus(origBus);
- }
- synchronized (message.getExchange()) {
- if (!isPartialResponse(message)
- || message.getContent(Exception.class) != null) {
- message.getExchange().put(FINISHED, Boolean.TRUE);
- message.getExchange().setInMessage(message);
- message.getExchange().notifyAll();
- }
- }
- }
- }
-
- public Conduit getConduit() {
- Message message = new MessageImpl();
- Exchange exchange = new ExchangeImpl();
- message.setExchange(exchange);
- message.putAll(getRequestContext());
- setExchangeProperties(exchange, getEndpoint(), null);
- return getConduitSelector().selectConduit(message);
- }
-
- protected void prepareConduitSelector(Message message) {
- getConduitSelector().prepare(message);
- message.getExchange().put(ConduitSelector.class, getConduitSelector());
- }
-
- protected void setOutMessageProperties(Message message, BindingOperationInfo boi) {
- message.put(Message.REQUESTOR_ROLE, Boolean.TRUE);
- message.put(Message.INBOUND_MESSAGE, Boolean.FALSE);
- if (null != boi) {
- message.put(BindingMessageInfo.class, boi.getInput());
- message.put(MessageInfo.class, boi.getOperationInfo().getInput());
- }
- }
-
- protected void setExchangeProperties(Exchange exchange,
- Endpoint endpoint,
- BindingOperationInfo boi) {
- if (endpoint != null) {
- exchange.put(Endpoint.class, endpoint);
- exchange.put(Service.class, endpoint.getService());
- exchange.put(Binding.class, endpoint.getBinding());
- }
- if (boi != null) {
- exchange.put(BindingOperationInfo.class, boi);
- }
-
- if (exchange.isSynchronous() || executor == null) {
- exchange.put(MessageObserver.class, this);
- } else {
- exchange.put(Executor.class, executor);
- exchange.put(MessageObserver.class, new MessageObserver() {
- public void onMessage(final Message message) {
- if (!message.getExchange()
- .containsKey(Executor.class.getName() + ".USING_SPECIFIED")) {
-
- executor.execute(new Runnable() {
- public void run() {
- ClientImpl.this.onMessage(message);
- }
- });
- } else {
- ClientImpl.this.onMessage(message);
- }
- }
- });
- }
- exchange.put(Retryable.class, this);
- exchange.put(Client.class, this);
- exchange.put(Bus.class, bus);
-
- if (endpoint != null) {
- EndpointInfo endpointInfo = endpoint.getEndpointInfo();
- if (boi != null) {
- exchange.put(Message.WSDL_OPERATION, boi.getName());
- }
-
- QName serviceQName = endpointInfo.getService().getName();
- exchange.put(Message.WSDL_SERVICE, serviceQName);
-
- QName interfaceQName = endpointInfo.getService().getInterface().getName();
- exchange.put(Message.WSDL_INTERFACE, interfaceQName);
-
- QName portQName = endpointInfo.getName();
- exchange.put(Message.WSDL_PORT, portQName);
- URI wsdlDescription = endpointInfo.getProperty("URI", URI.class);
- if (wsdlDescription == null) {
- String address = endpointInfo.getAddress();
- try {
- wsdlDescription = new URI(address + "?wsdl");
- } catch (URISyntaxException e) {
- // do nothing
- }
- endpointInfo.setProperty("URI", wsdlDescription);
- }
- exchange.put(Message.WSDL_DESCRIPTION, wsdlDescription);
- }
- }
-
- protected PhaseInterceptorChain setupInterceptorChain(Endpoint endpoint) {
-
- PhaseManager pm = bus.getExtension(PhaseManager.class);
-
- List<Interceptor<? extends Message>> i1 = bus.getOutInterceptors();
- if (LOG.isLoggable(Level.FINE)) {
- LOG.fine("Interceptors contributed by bus: " + i1);
- }
- List<Interceptor<? extends Message>> i2 = getOutInterceptors();
- if (LOG.isLoggable(Level.FINE)) {
- LOG.fine("Interceptors contributed by client: " + i2);
- }
- List<Interceptor<? extends Message>> i3 = endpoint.getOutInterceptors();
- if (LOG.isLoggable(Level.FINE)) {
- LOG.fine("Interceptors contributed by endpoint: " + i3);
- }
- List<Interceptor<? extends Message>> i4 = endpoint.getBinding().getOutInterceptors();
- if (LOG.isLoggable(Level.FINE)) {
- LOG.fine("Interceptors contributed by binding: " + i4);
- }
- List<Interceptor<? extends Message>> i5 = null;
- if (endpoint.getService().getDataBinding() instanceof InterceptorProvider) {
- i5 = ((InterceptorProvider)endpoint.getService().getDataBinding()).getOutInterceptors();
- if (LOG.isLoggable(Level.FINE)) {
- LOG.fine("Interceptors contributed by databinding: " + i5);
- }
- }
- if (i5 != null) {
- return outboundChainCache.get(pm.getOutPhases(), i1, i2, i3, i4, i5);
- }
- return outboundChainCache.get(pm.getOutPhases(), i1, i2, i3, i4);
- }
-
- protected void modifyChain(InterceptorChain chain, Message ctx, boolean in) {
- if (ctx == null) {
- return;
- }
- Collection<InterceptorProvider> providers
- = CastUtils.cast((Collection<?>)ctx.get(Message.INTERCEPTOR_PROVIDERS));
- if (providers != null) {
- for (InterceptorProvider p : providers) {
- if (in) {
- chain.add(p.getInInterceptors());
- } else {
- chain.add(p.getOutInterceptors());
- }
- }
- }
- String key = in ? Message.IN_INTERCEPTORS : Message.OUT_INTERCEPTORS;
- Collection<Interceptor<? extends Message>> is
- = CastUtils.cast((Collection<?>)ctx.get(key));
- if (is != null) {
- chain.add(is);
- }
- }
-
- protected void setEndpoint(Endpoint e) {
- getConduitSelector().setEndpoint(e);
- }
-
- public int getSynchronousTimeout() {
- return synchronousTimeout;
- }
-
- public void setSynchronousTimeout(int synchronousTimeout) {
- this.synchronousTimeout = synchronousTimeout;
- }
-
- public final ConduitSelector getConduitSelector() {
- return getConduitSelector(null);
- }
-
- protected final ConduitSelector getConduitSelector(
- ConduitSelector override
- ) {
- if (null == conduitSelector) {
- setConduitSelector(override);
- }
- return conduitSelector;
- }
-
- public final synchronized void setConduitSelector(ConduitSelector selector) {
- conduitSelector = selector == null ? new UpfrontConduitSelector() : selector;
- }
-
- private boolean isPartialResponse(Message in) {
- return Boolean.TRUE.equals(in.get(Message.PARTIAL_RESPONSE_MESSAGE));
- }
-
- @Override
- public void close() throws Exception {
- destroy();
- }
-
-
- public class EchoContext extends ConcurrentHashMap<String, Object> {
- private static final long serialVersionUID = 1L;
- public EchoContext(Map<String, Object> sharedMap) {
- super(8, 0.75f, 4);
- putAll(sharedMap);
- }
-
- public void reload() {
- super.clear();
- super.putAll(requestContext.get(latestContextThread));
- }
-
- @Override
- public void clear() {
- super.clear();
- try {
- for (Map.Entry<Thread, EchoContext> ent : requestContext.entrySet()) {
- if (ent.getValue() == this) {
- requestContext.remove(ent.getKey());
- return;
- }
- }
- } catch (Throwable t) {
- //ignore
- }
- }
- }
-
- /**
- * Class to handle the response contexts. The clear is overloaded to remove
- * this context from the threadLocal caches in the ClientImpl
- */
- static class ResponseContext implements Map<String, Object>, Serializable {
- private static final long serialVersionUID = 2L;
- final Map<String, Object> wrapped;
- final Map<Thread, ResponseContext> responseContext;
-
- ResponseContext(Map<String, Object> origMap, Map<Thread, ResponseContext> rc) {
- wrapped = origMap;
- responseContext = rc;
- }
-
- ResponseContext(Map<Thread, ResponseContext> rc) {
- wrapped = new HashMap<>();
- responseContext = rc;
- }
-
- @Override
- public void clear() {
- wrapped.clear();
- try {
- for (Map.Entry<Thread, ResponseContext> ent : responseContext.entrySet()) {
- if (ent.getValue() == this) {
- responseContext.remove(ent.getKey());
- return;
- }
- }
- } catch (Throwable t) {
- //ignore
- }
- }
-
- @Override
- public int size() {
- return wrapped.size();
- }
- @Override
- public boolean isEmpty() {
- return wrapped.isEmpty();
- }
- @Override
- public boolean containsKey(Object key) {
- return wrapped.containsKey(key);
- }
- @Override
- public boolean containsValue(Object value) {
- return wrapped.containsKey(value);
- }
- @Override
- public Object get(Object key) {
- return wrapped.get(key);
- }
- @Override
- public Object put(String key, Object value) {
- return wrapped.put(key, value);
- }
- @Override
- public Object remove(Object key) {
- return wrapped.remove(key);
- }
- @Override
- public void putAll(Map<? extends String, ? extends Object> m) {
- wrapped.putAll(m);
- }
- @Override
- public Set<String> keySet() {
- return wrapped.keySet();
- }
- @Override
- public Collection<Object> values() {
- return wrapped.values();
- }
- @Override
- public Set<Entry<String, Object>> entrySet() {
- return wrapped.entrySet();
- }
- }
-
- public void setExecutor(Executor executor) {
- if (!SynchronousExecutor.isA(executor)) {
- this.executor = executor;
- }
- }
-
-
- public class IllegalEmptyResponseException extends IllegalStateException {
- private static final long serialVersionUID = 1L;
-
- public IllegalEmptyResponseException() {
- super();
- }
-
- public IllegalEmptyResponseException(String message) {
- super(message);
- }
-
- public IllegalEmptyResponseException(String message, Throwable cause) {
- super(message, cause);
- }
-
- public IllegalEmptyResponseException(Throwable cause) {
- super(cause);
- }
- }
-
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/endpoint/EndpointImpl.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/endpoint/EndpointImpl.java
deleted file mode 100644
index 340211b..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/endpoint/EndpointImpl.java
+++ /dev/null
@@ -1,220 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.cxf.endpoint;
-
-import java.io.Closeable;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-import java.util.ResourceBundle;
-import java.util.concurrent.CopyOnWriteArrayList;
-import java.util.concurrent.Executor;
-import java.util.logging.Logger;
-
-import javax.xml.namespace.QName;
-
-import org.apache.cxf.Bus;
-import org.apache.cxf.BusException;
-import org.apache.cxf.BusFactory;
-import org.apache.cxf.binding.Binding;
-import org.apache.cxf.binding.BindingFactory;
-import org.apache.cxf.binding.BindingFactoryManager;
-import org.apache.cxf.common.i18n.Message;
-import org.apache.cxf.common.logging.LogUtils;
-import org.apache.cxf.configuration.Configurable;
-import org.apache.cxf.feature.Feature;
-import org.apache.cxf.helpers.CastUtils;
-import org.apache.cxf.interceptor.AbstractAttributedInterceptorProvider;
-import org.apache.cxf.interceptor.ClientFaultConverter;
-import org.apache.cxf.interceptor.InFaultChainInitiatorObserver;
-import org.apache.cxf.interceptor.MessageSenderInterceptor;
-import org.apache.cxf.interceptor.OutFaultChainInitiatorObserver;
-import org.apache.cxf.service.Service;
-import org.apache.cxf.service.model.BindingInfo;
-import org.apache.cxf.service.model.EndpointInfo;
-import org.apache.cxf.transport.MessageObserver;
-
-public class EndpointImpl extends AbstractAttributedInterceptorProvider implements Endpoint, Configurable {
-
- private static final long serialVersionUID = -7660560719050162091L;
- private static final Logger LOG = LogUtils.getL7dLogger(EndpointImpl.class);
- private static final ResourceBundle BUNDLE = LOG.getResourceBundle();
-
- private Service service;
- private Binding binding;
- private EndpointInfo endpointInfo;
- private Executor executor;
- private Bus bus;
- private MessageObserver inFaultObserver;
- private MessageObserver outFaultObserver;
- private List<Feature> activeFeatures;
- private List<Closeable> cleanupHooks;
-
- public EndpointImpl(Bus bus, Service s, QName endpointName) throws EndpointException {
- this(bus, s, s.getEndpointInfo(endpointName));
- }
-
- public EndpointImpl(Bus bus, Service s, EndpointInfo ei) throws EndpointException {
- if (ei == null) {
- throw new NullPointerException("EndpointInfo can not be null!");
- }
-
- if (bus == null) {
- this.bus = BusFactory.getThreadDefaultBus();
- } else {
- this.bus = bus;
- }
- service = s;
- endpointInfo = ei;
-
- createBinding(endpointInfo.getBinding());
-
- inFaultObserver = new InFaultChainInitiatorObserver(bus);
- outFaultObserver = new OutFaultChainInitiatorObserver(bus);
-
- getInFaultInterceptors().add(new ClientFaultConverter());
- getOutInterceptors().add(new MessageSenderInterceptor());
- getOutFaultInterceptors().add(new MessageSenderInterceptor());
- }
-
- public String getBeanName() {
- return endpointInfo.getName().toString() + ".endpoint";
- }
-
-
- public EndpointInfo getEndpointInfo() {
- return endpointInfo;
- }
-
- public Service getService() {
- return service;
- }
-
- public Binding getBinding() {
- return binding;
- }
-
- public Executor getExecutor() {
- return executor == null ? service.getExecutor() : executor;
- }
-
- public void setExecutor(Executor e) {
- executor = e;
- }
-
- public Bus getBus() {
- return bus;
- }
-
- public void setBus(Bus bus) {
- this.bus = bus;
- }
-
- final void createBinding(BindingInfo bi) throws EndpointException {
- if (null != bi) {
- String namespace = bi.getBindingId();
- try {
- final BindingFactory bf = bus.getExtension(BindingFactoryManager.class).getBindingFactory(namespace);
- if (null == bf) {
- Message msg = new Message("NO_BINDING_FACTORY", BUNDLE, namespace);
- throw new EndpointException(msg);
- }
- binding = bf.createBinding(bi);
- } catch (BusException ex) {
- throw new EndpointException(ex);
- }
- }
- }
-
-
- public MessageObserver getInFaultObserver() {
- return inFaultObserver;
- }
-
- public MessageObserver getOutFaultObserver() {
- return outFaultObserver;
- }
-
- public void setInFaultObserver(MessageObserver observer) {
- inFaultObserver = observer;
- }
-
- public void setOutFaultObserver(MessageObserver observer) {
- outFaultObserver = observer;
-
- }
-
- /**
- * Utility method to make it easy to set properties from Spring.
- *
- * @param properties
- */
- public void setProperties(Map<String, Object> properties) {
- this.putAll(properties);
- }
-
- /**
- * @return the list of features <b>already</b> activated for this endpoint.
- */
- public List<Feature> getActiveFeatures() {
- return activeFeatures;
- }
-
- /**
- * @param features the list of features <b>already</b> activated for this endpoint.
- */
- public void initializeActiveFeatures(List<? extends Feature> features) {
- activeFeatures = CastUtils.cast(features);
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (!(obj instanceof EndpointImpl)) {
- return false;
- }
-
- return super.equals(obj);
- }
-
- /**
- * Returns the hashCode based on the EndpointInfo so that this object
- * can be used as a map key.
- */
- @Override
- public int hashCode() {
- return endpointInfo.hashCode();
- }
-
- public synchronized void addCleanupHook(Closeable c) {
- if (cleanupHooks == null) {
- cleanupHooks = new CopyOnWriteArrayList<>();
- }
- cleanupHooks.add(c);
- }
- public List<Closeable> getCleanupHooks() {
- if (cleanupHooks == null) {
- return Collections.emptyList();
- }
- return cleanupHooks;
- }
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/endpoint/ServerImpl.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/endpoint/ServerImpl.java
deleted file mode 100644
index c417cb6..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/endpoint/ServerImpl.java
+++ /dev/null
@@ -1,221 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.cxf.endpoint;
-
-import java.io.Closeable;
-import java.io.IOException;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import javax.management.JMException;
-
-import org.apache.cxf.Bus;
-import org.apache.cxf.BusException;
-import org.apache.cxf.binding.BindingFactory;
-import org.apache.cxf.common.logging.LogUtils;
-import org.apache.cxf.common.logging.RegexLoggingFilter;
-import org.apache.cxf.management.InstrumentationManager;
-import org.apache.cxf.service.model.EndpointInfo;
-import org.apache.cxf.transport.Destination;
-import org.apache.cxf.transport.DestinationFactory;
-import org.apache.cxf.transport.DestinationFactoryManager;
-import org.apache.cxf.transport.MessageObserver;
-import org.apache.cxf.transport.MultipleEndpointObserver;
-
-public class ServerImpl implements Server {
- private static final Logger LOG = LogUtils.getL7dLogger(ServerImpl.class);
-
- protected final Endpoint endpoint;
- protected final Bus bus;
- protected final BindingFactory bindingFactory;
-
- private Destination destination;
- private ServerRegistry serverRegistry;
- private ServerLifeCycleManager slcMgr;
- private InstrumentationManager iMgr;
- private ManagedEndpoint mep;
- private boolean stopped = true;
- private boolean destroyDest = true;
-
- public ServerImpl(Bus bus,
- Endpoint endpoint,
- DestinationFactory destinationFactory,
- BindingFactory bindingFactory) throws BusException, IOException {
- this.endpoint = endpoint;
- this.bus = bus;
- this.bindingFactory = bindingFactory;
-
- initDestination(destinationFactory);
- }
-
- private void initDestination(DestinationFactory destinationFactory) throws BusException, IOException {
- EndpointInfo ei = endpoint.getEndpointInfo();
-
- //Treat local transport as a special case, transports loaded by transportId can be replaced
- //by local transport when the publishing address is a local transport protocol.
- //Of course its not an ideal situation here to use a hard-coded prefix. To be refactored.
- if (destinationFactory == null) {
- if (ei.getAddress() != null && ei.getAddress().indexOf("local://") != -1) {
- destinationFactory = bus.getExtension(DestinationFactoryManager.class)
- .getDestinationFactoryForUri(ei.getAddress());
- }
-
- if (destinationFactory == null) {
- destinationFactory = bus.getExtension(DestinationFactoryManager.class)
- .getDestinationFactory(ei.getTransportId());
- }
- }
-
- destination = destinationFactory.getDestination(ei, bus);
- String wantFilter = ei.getAddress();
-
- if (wantFilter != null && wantFilter.startsWith("jms")) {
- RegexLoggingFilter filter = new RegexLoggingFilter();
- filter.setPattern("jms(.*?)password=+([^ ]+)");
- filter.setGroup(2);
- wantFilter = filter.filter(wantFilter).toString();
- }
- LOG.info("Setting the server's publish address to be " + wantFilter);
- serverRegistry = bus.getExtension(ServerRegistry.class);
-
- mep = new ManagedEndpoint(bus, endpoint, this);
-
- slcMgr = bus.getExtension(ServerLifeCycleManager.class);
- if (slcMgr != null) {
- slcMgr.registerListener(mep);
- }
-
- iMgr = bus.getExtension(InstrumentationManager.class);
- if (iMgr != null) {
- try {
- iMgr.register(mep);
- } catch (JMException jmex) {
- LOG.log(Level.WARNING, "Registering ManagedEndpoint failed.", jmex);
- }
- }
- }
-
- public Destination getDestination() {
- return destination;
- }
-
- public void setDestination(Destination destination) {
- this.destination = destination;
- }
-
- public void start() {
- if (!stopped) {
- return;
- }
- LOG.fine("Server is starting.");
-
- try {
- bindingFactory.addListener(destination, endpoint);
- } catch (RuntimeException e) {
- if (e.getMessage().contains("endpoint already registered on address")) {
- //this destination is used by another endpoint with same endpoint address
- //so shouldn't be destroyed by this server
- this.destroyDest = false;
- }
- throw e;
- }
-
- // register the active server to run
- if (null != serverRegistry) {
- LOG.fine("register the server to serverRegistry ");
- serverRegistry.register(this);
- }
- if (slcMgr == null) {
- slcMgr = bus.getExtension(ServerLifeCycleManager.class);
- if (slcMgr != null && mep != null) {
- slcMgr.registerListener(mep);
- }
- }
- if (slcMgr != null) {
- slcMgr.startServer(this);
- }
- stopped = false;
- }
-
- public boolean isStopped() {
- return stopped;
- }
- public boolean isStarted() {
- return !stopped;
- }
-
- public void stop() {
- if (stopped) {
- return;
- }
-
- LOG.fine("Server is stopping.");
-
- for (Closeable c : endpoint.getCleanupHooks()) {
- try {
- c.close();
- } catch (IOException e) {
- //ignore
- }
- }
- if (slcMgr != null) {
- slcMgr.stopServer(this);
- }
-
- MessageObserver mo = getDestination().getMessageObserver();
- if (mo instanceof MultipleEndpointObserver) {
- ((MultipleEndpointObserver)mo).getEndpoints().remove(endpoint);
- if (((MultipleEndpointObserver)mo).getEndpoints().isEmpty()) {
- getDestination().setMessageObserver(null);
- }
- } else {
- getDestination().setMessageObserver(null);
- }
- stopped = true;
- }
-
- public void destroy() {
- stop();
- if (this.destroyDest) {
- //we should shutdown the destination here
- getDestination().shutdown();
- }
-
- if (null != serverRegistry) {
- LOG.fine("unregister the server to serverRegistry ");
- serverRegistry.unregister(this);
- }
-
- if (iMgr != null) {
- try {
- iMgr.unregister(mep);
- } catch (JMException jmex) {
- LOG.log(Level.WARNING, "Unregistering ManagedEndpoint failed.", jmex);
- }
- iMgr = null;
- }
-
- }
-
- public Endpoint getEndpoint() {
- return endpoint;
- }
-
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/feature/FastInfosetFeature.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/feature/FastInfosetFeature.java
deleted file mode 100644
index daa4bd3..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/feature/FastInfosetFeature.java
+++ /dev/null
@@ -1,110 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.cxf.feature;
-
-import org.apache.cxf.Bus;
-import org.apache.cxf.common.injection.NoJSR250Annotations;
-import org.apache.cxf.interceptor.FIStaxInInterceptor;
-import org.apache.cxf.interceptor.FIStaxOutInterceptor;
-import org.apache.cxf.interceptor.InterceptorProvider;
-
-
-/**
- * <pre>
- * <![CDATA[
- <jaxws:endpoint ...>
- <jaxws:features>
- <bean class="org.apache.cxf.feature.FastInfosetFeature"/>
- </jaxws:features>
- </jaxws:endpoint>
- ]]>
- </pre>
- */
-@NoJSR250Annotations
-public class FastInfosetFeature extends DelegatingFeature<FastInfosetFeature.Portable> {
- public FastInfosetFeature() {
- super(new Portable());
- }
-
- public void setForce(boolean b) {
- delegate.setForce(b);
- }
-
- public boolean getForce() {
- return delegate.getForce();
- }
-
- public static class Portable implements AbstractPortableFeature {
- boolean force;
- private Integer serializerAttributeValueMapMemoryLimit;
- private Integer serializerMinAttributeValueSize;
- private Integer serializerMaxAttributeValueSize;
- private Integer serializerCharacterContentChunkMapMemoryLimit;
- private Integer serializerMinCharacterContentChunkSize;
- private Integer serializerMaxCharacterContentChunkSize;
-
- @Override
- public void doInitializeProvider(InterceptorProvider provider, Bus bus) {
-
- FIStaxInInterceptor in = new FIStaxInInterceptor();
-
- FIStaxOutInterceptor out = new FIStaxOutInterceptor(force);
- if (serializerAttributeValueMapMemoryLimit != null && serializerAttributeValueMapMemoryLimit > 0) {
- out.setSerializerAttributeValueMapMemoryLimit(serializerAttributeValueMapMemoryLimit);
- }
- if (serializerMinAttributeValueSize != null && serializerMinAttributeValueSize > 0) {
- out.setSerializerMinAttributeValueSize(serializerMinAttributeValueSize);
- }
- if (serializerMaxAttributeValueSize != null && serializerMaxAttributeValueSize > 0) {
- out.setSerializerMaxAttributeValueSize(serializerMaxAttributeValueSize);
- }
- if (serializerCharacterContentChunkMapMemoryLimit != null
- && serializerCharacterContentChunkMapMemoryLimit > 0) {
- out.setSerializerCharacterContentChunkMapMemoryLimit(
- serializerCharacterContentChunkMapMemoryLimit);
- }
- if (serializerMinCharacterContentChunkSize != null && serializerMinCharacterContentChunkSize > 0) {
- out.setSerializerMinCharacterContentChunkSize(serializerMinCharacterContentChunkSize);
- }
- if (serializerMaxCharacterContentChunkSize != null && serializerMaxCharacterContentChunkSize > 0) {
- out.setSerializerMaxCharacterContentChunkSize(serializerMaxCharacterContentChunkSize);
- }
-
- provider.getInInterceptors().add(in);
- provider.getInFaultInterceptors().add(in);
- provider.getOutInterceptors().add(out);
- provider.getOutFaultInterceptors().add(out);
- }
-
- /**
- * Set if FastInfoset is always used without negotiation
- * @param b
- */
- public void setForce(boolean b) {
- force = b;
- }
-
- /**
- * Retrieve the value set with {@link #setForce(boolean)}.
- */
- public boolean getForce() {
- return force;
- }
- }
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/feature/WrappedFeature.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/feature/WrappedFeature.java
deleted file mode 100644
index 2236a38..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/feature/WrappedFeature.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.cxf.feature;
-
-import org.apache.cxf.Bus;
-import org.apache.cxf.endpoint.Client;
-import org.apache.cxf.endpoint.Server;
-import org.apache.cxf.interceptor.InterceptorProvider;
-
-/**
- * A Feature is something that is able to customize a Server, Client, or Bus, typically
- * adding capabilities. For instance, there may be a LoggingFeature which configures
- * one of the above to log each of their messages.
- * <p>
- * By default the initialize methods all delegate to initializeProvider(InterceptorProvider).
- * If you're simply adding interceptors to a Server, Client, or Bus, this allows you to add
- * them easily.
- */
-public class WrappedFeature extends AbstractFeature {
- final Feature wrapped;
- public WrappedFeature(Feature f) {
- wrapped = f;
- }
-
- @Override
- public void initialize(Server server, Bus bus) {
- wrapped.initialize(server, bus);
- }
-
- @Override
- public void initialize(Client client, Bus bus) {
- wrapped.initialize(client, bus);
- }
-
- @Override
- public void initialize(InterceptorProvider interceptorProvider, Bus bus) {
- wrapped.initialize(interceptorProvider, bus);
- }
-
- @Override
- public void initialize(Bus bus) {
- wrapped.initialize(bus);
- }
-
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/feature/transform/XSLTOutInterceptor.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/feature/transform/XSLTOutInterceptor.java
deleted file mode 100644
index 53605cc..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/feature/transform/XSLTOutInterceptor.java
+++ /dev/null
@@ -1,210 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.cxf.feature.transform;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.io.Reader;
-import java.io.Writer;
-import java.util.logging.Logger;
-
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamWriter;
-import javax.xml.transform.Templates;
-import javax.xml.transform.stream.StreamSource;
-
-import org.apache.cxf.common.logging.LogUtils;
-import org.apache.cxf.helpers.IOUtils;
-import org.apache.cxf.interceptor.AbstractOutDatabindingInterceptor;
-import org.apache.cxf.interceptor.Fault;
-import org.apache.cxf.interceptor.StaxOutInterceptor;
-import org.apache.cxf.io.CachedOutputStream;
-import org.apache.cxf.io.CachedOutputStreamCallback;
-import org.apache.cxf.io.CachedWriter;
-import org.apache.cxf.message.Message;
-import org.apache.cxf.phase.Phase;
-import org.apache.cxf.staxutils.DelegatingXMLStreamWriter;
-import org.apache.cxf.staxutils.StaxUtils;
-
-/** Class provides XSLT transformation of outgoing message.
- * Actually it breaks streaming (can be fixed in further versions when XSLT engine supports XML stream)
- */
-public class XSLTOutInterceptor extends AbstractXSLTInterceptor {
- private static final Logger LOG = LogUtils.getL7dLogger(XSLTOutInterceptor.class);
-
- public XSLTOutInterceptor(String xsltPath) {
- super(Phase.PRE_STREAM, StaxOutInterceptor.class, null, xsltPath);
- }
-
- public XSLTOutInterceptor(String phase, Class<?> before, Class<?> after, String xsltPath) {
- super(phase, before, after, xsltPath);
- }
-
- @Override
- public void handleMessage(Message message) {
- if (checkContextProperty(message)) {
- return;
- }
-
- // 1. Try to get and transform XMLStreamWriter message content
- XMLStreamWriter xWriter = message.getContent(XMLStreamWriter.class);
- if (xWriter != null) {
- transformXWriter(message, xWriter);
- } else {
- // 2. Try to get and transform OutputStream message content
- OutputStream out = message.getContent(OutputStream.class);
- if (out != null) {
- transformOS(message, out);
- } else {
- // 3. Try to get and transform Writer message content (actually used for JMS TextMessage)
- Writer writer = message.getContent(Writer.class);
- if (writer != null) {
- transformWriter(message, writer);
- }
- }
- }
- }
-
- protected void transformXWriter(Message message, XMLStreamWriter xWriter) {
- CachedWriter writer = new CachedWriter();
- XMLStreamWriter delegate = StaxUtils.createXMLStreamWriter(writer);
- XSLTStreamWriter wrapper = new XSLTStreamWriter(getXSLTTemplate(), writer, delegate, xWriter);
- message.setContent(XMLStreamWriter.class, wrapper);
- message.put(AbstractOutDatabindingInterceptor.DISABLE_OUTPUTSTREAM_OPTIMIZATION,
- Boolean.TRUE);
- }
-
- protected void transformOS(Message message, OutputStream out) {
- CachedOutputStream wrapper = new CachedOutputStream();
- CachedOutputStreamCallback callback = new XSLTCachedOutputStreamCallback(getXSLTTemplate(), out);
- wrapper.registerCallback(callback);
- message.setContent(OutputStream.class, wrapper);
- }
-
- protected void transformWriter(Message message, Writer writer) {
- XSLTCachedWriter wrapper = new XSLTCachedWriter(getXSLTTemplate(), writer);
- message.setContent(Writer.class, wrapper);
- }
-
-
- public static class XSLTStreamWriter extends DelegatingXMLStreamWriter {
- private final Templates xsltTemplate;
- private final CachedWriter cachedWriter;
- private final XMLStreamWriter origXWriter;
-
- public XSLTStreamWriter(Templates xsltTemplate, CachedWriter cachedWriter,
- XMLStreamWriter delegateXWriter, XMLStreamWriter origXWriter) {
- super(delegateXWriter);
- this.xsltTemplate = xsltTemplate;
- this.cachedWriter = cachedWriter;
- this.origXWriter = origXWriter;
- }
-
- @Override
- public void close() {
- Reader transformedReader = null;
- try {
- super.flush();
- transformedReader = XSLTUtils.transform(xsltTemplate, cachedWriter.getReader());
- StaxUtils.copy(new StreamSource(transformedReader), origXWriter);
- } catch (XMLStreamException e) {
- throw new Fault("STAX_COPY", LOG, e, e.getMessage());
- } catch (IOException e) {
- throw new Fault("GET_CACHED_INPUT_STREAM", LOG, e, e.getMessage());
- } finally {
- try {
- if (transformedReader != null) {
- transformedReader.close();
- }
- cachedWriter.close();
- StaxUtils.close(origXWriter);
- super.close();
- } catch (Exception e) {
- LOG.warning("Cannot close stream after transformation: " + e.getMessage());
- }
- }
- }
- }
-
- public static class XSLTCachedOutputStreamCallback implements CachedOutputStreamCallback {
- private final Templates xsltTemplate;
- private final OutputStream origStream;
-
- public XSLTCachedOutputStreamCallback(Templates xsltTemplate, OutputStream origStream) {
- this.xsltTemplate = xsltTemplate;
- this.origStream = origStream;
- }
-
- @Override
- public void onFlush(CachedOutputStream wrapper) {
- }
-
- @Override
- public void onClose(CachedOutputStream wrapper) {
- InputStream transformedStream;
- Exception exceptionOnClose = null;
- try {
- transformedStream = XSLTUtils.transform(xsltTemplate, wrapper.getInputStream());
- IOUtils.copyAndCloseInput(transformedStream, origStream);
- } catch (IOException e) {
- throw new Fault("STREAM_COPY", LOG, e, e.getMessage());
- } finally {
- try {
- origStream.close();
- } catch (Exception e) {
- exceptionOnClose = e;
- }
- }
-
- if (exceptionOnClose == null) {
- return;
- }
- throw new Fault(exceptionOnClose);
- }
- }
-
- public static class XSLTCachedWriter extends CachedWriter {
- private final Templates xsltTemplate;
- private final Writer origWriter;
-
- public XSLTCachedWriter(Templates xsltTemplate, Writer origWriter) {
- this.xsltTemplate = xsltTemplate;
- this.origWriter = origWriter;
- }
-
- @Override
- protected void doClose() {
- try {
- final Reader transformedReader = XSLTUtils.transform(xsltTemplate, getReader());
- IOUtils.copyAndCloseInput(transformedReader, origWriter, IOUtils.DEFAULT_BUFFER_SIZE);
- } catch (IOException e) {
- throw new Fault("READER_COPY", LOG, e, e.getMessage());
- } finally {
- try {
- origWriter.close();
- } catch (IOException e) {
- LOG.warning("Cannot close stream after transformation: " + e.getMessage());
- }
- }
- }
- }
-
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/headers/Header.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/headers/Header.java
deleted file mode 100644
index f933c14..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/headers/Header.java
+++ /dev/null
@@ -1,78 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.cxf.headers;
-
-import javax.xml.namespace.QName;
-
-import org.apache.cxf.databinding.DataBinding;
-
-public class Header {
- public enum Direction {
- DIRECTION_IN,
- DIRECTION_OUT,
- DIRECTION_INOUT
- }
-
- public static final String HEADER_LIST = Header.class.getName() + ".list";
-
-
- private DataBinding dataBinding;
- private QName name;
- private Object object;
-
- private Direction direction = Header.Direction.DIRECTION_OUT;
-
- public Header(QName q, Object o) {
- this(q, o, null);
- }
-
- public Header(QName q, Object o, DataBinding b) {
- object = o;
- name = q;
- dataBinding = b;
- }
-
- public DataBinding getDataBinding() {
- return dataBinding;
- }
- public void setDataBinding(DataBinding dataBinding) {
- this.dataBinding = dataBinding;
- }
- public QName getName() {
- return name;
- }
- public void setName(QName name) {
- this.name = name;
- }
- public Object getObject() {
- return object;
- }
- public void setObject(Object object) {
- this.object = object;
- }
-
- public void setDirection(Direction hdrDirection) {
- this.direction = hdrDirection;
- }
-
- public Direction getDirection() {
- return direction;
- }
-
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/helpers/DOMUtils.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/helpers/DOMUtils.java
deleted file mode 100644
index 37bde67..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/helpers/DOMUtils.java
+++ /dev/null
@@ -1,895 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.cxf.helpers;
-
-import java.io.IOException;
-import java.io.StringReader;
-import java.lang.reflect.Field;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.LinkedHashSet;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.WeakHashMap;
-
-import javax.xml.XMLConstants;
-import javax.xml.namespace.QName;
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-
-import org.w3c.dom.Attr;
-import org.w3c.dom.Comment;
-import org.w3c.dom.Document;
-import org.w3c.dom.DocumentFragment;
-import org.w3c.dom.Element;
-import org.w3c.dom.NamedNodeMap;
-import org.w3c.dom.Node;
-import org.w3c.dom.Text;
-
-import org.xml.sax.EntityResolver;
-import org.xml.sax.InputSource;
-import org.xml.sax.SAXException;
-
-import org.apache.cxf.common.logging.LogUtils;
-import org.apache.cxf.common.util.ReflectionUtil;
-import org.apache.cxf.common.util.StringUtils;
-
-/**
- * Few simple utils to read DOM. This is originally from the Jakarta Commons Modeler.
- */
-public final class DOMUtils {
- private static boolean isJre9SAAJ;
- private static final Map<ClassLoader, DocumentBuilder> DOCUMENT_BUILDERS
- = Collections.synchronizedMap(new WeakHashMap<ClassLoader, DocumentBuilder>());
- private static final String XMLNAMESPACE = "xmlns";
- private static volatile Document emptyDocument;
-
- private static final ClassValue<Method> GET_DOM_ELEMENTS_METHODS = new ClassValue<Method>() {
- @Override
- protected Method computeValue(Class<?> type) {
- try {
- return ReflectionUtil.getMethod(type, "getDomElement");
- } catch (NoSuchMethodException e) {
- //best effort to try, do nothing if NoSuchMethodException
- return null;
- }
- }
- };
- private static final ClassValue<Field> GET_DOCUMENT_FRAGMENT_FIELDS = new ClassValue<Field>() {
- @Override
- protected Field computeValue(Class<?> type) {
- return ReflectionUtil.getDeclaredField(type, "documentFragment");
- }
-
- };
-
- static {
- try {
- Method[] methods = DOMUtils.class.getClassLoader().
- loadClass("com.sun.xml.messaging.saaj.soap.SOAPDocumentImpl").getMethods();
- for (Method method : methods) {
- if ("register".equals(method.getName())) {
- //this is the 1.4+ SAAJ impl
- setJava9SAAJ(true);
- break;
- }
- }
- } catch (ClassNotFoundException cnfe) {
- LogUtils.getL7dLogger(DOMUtils.class).finest(
- "can't load class com.sun.xml.messaging.saaj.soap.SOAPDocumentImpl");
-
- try {
- Method[] methods = DOMUtils.class.getClassLoader().
- loadClass("com.sun.xml.internal.messaging.saaj.soap.SOAPDocumentImpl").getMethods();
- for (Method method : methods) {
- if ("register".equals(method.getName())) {
- //this is the SAAJ impl in JDK9
- setJava9SAAJ(true);
- break;
- }
- }
- } catch (ClassNotFoundException cnfe1) {
- LogUtils.getL7dLogger(DOMUtils.class).finest(
- "can't load class com.sun.xml.internal.messaging.saaj.soap.SOAPDocumentImpl");
- }
- } catch (Throwable throwable) {
- LogUtils.getL7dLogger(DOMUtils.class).finest(
- "Other JDK vendor");
- }
- }
-
- private DOMUtils() {
- }
-
- private static DocumentBuilder getDocumentBuilder() throws ParserConfigurationException {
- ClassLoader loader = getContextClassLoader();
- if (loader == null) {
- loader = getClassLoader(DOMUtils.class);
- }
- if (loader == null) {
- return createDocumentBuilder();
- }
- DocumentBuilder factory = DOCUMENT_BUILDERS.get(loader);
- if (factory == null) {
- factory = createDocumentBuilder();
- DOCUMENT_BUILDERS.put(loader, factory);
- }
- return factory;
- }
-
- private static DocumentBuilder createDocumentBuilder() throws ParserConfigurationException {
- DocumentBuilderFactory f = DocumentBuilderFactory.newInstance();
- f.setNamespaceAware(true);
- f.setFeature(javax.xml.XMLConstants.FEATURE_SECURE_PROCESSING, true);
- f.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
- return f.newDocumentBuilder();
- }
-
- private static ClassLoader getContextClassLoader() {
- final SecurityManager sm = System.getSecurityManager();
- if (sm != null) {
- return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() {
- public ClassLoader run() {
- return Thread.currentThread().getContextClassLoader();
- }
- });
- }
- return Thread.currentThread().getContextClassLoader();
- }
-
- private static ClassLoader getClassLoader(final Class<?> clazz) {
- final SecurityManager sm = System.getSecurityManager();
- if (sm != null) {
- return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() {
- public ClassLoader run() {
- return clazz.getClassLoader();
- }
- });
- }
- return clazz.getClassLoader();
- }
-
- /**
- * Creates a new Document object
- * @throws ParserConfigurationException
- */
- public static Document newDocument() {
- return createDocument();
- }
- public static Document createDocument() {
- try {
- return getDocumentBuilder().newDocument();
- } catch (ParserConfigurationException e) {
- throw new RuntimeException(e);
- }
- }
-
- private static synchronized Document createEmptyDocument() {
- if (emptyDocument == null) {
- emptyDocument = createDocument();
-
- // uncomment this to see if anything is actually setting anything into the empty doc
- /*
- final Document doc = createDocument();
- emptyDocument = (Document)org.apache.cxf.common.util.ProxyHelper.getProxy(
- DOMUtils.class.getClassLoader(),
- new Class<?>[] {Document.class},
- new java.lang.reflect.InvocationHandler() {
- @Override
- public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
- if (method.getName().contains("create")) {
- return method.invoke(doc, args);
- }
- throw new IllegalStateException("Cannot modify factory document");
- }
- });
- */
- }
- return emptyDocument;
- }
- /**
- * Returns a static Document that should always be "empty". It's useful as a factory for
- * for creating Elements and other nodes that will be traversed later and don't need to
- * be attached into a document
- * @return an empty document
- */
- public static Document getEmptyDocument() {
- Document doc = emptyDocument;
- if (doc == null) {
- doc = createEmptyDocument();
- }
- return doc;
- }
-
-
- /**
- * This function is much like getAttribute, but returns null, not "", for a nonexistent attribute.
- *
- * @param e
- * @param attributeName
- */
- public static String getAttributeValueEmptyNull(Element e, String attributeName) {
- Attr node = e.getAttributeNode(attributeName);
- if (node == null) {
- return null;
- }
- return node.getValue();
- }
-
- /**
- * Get the text content of a node and all it's children or null if there is no text
- */
- public static String getAllContent(Node n) {
- StringBuilder b = new StringBuilder();
- getAllContent(n, b);
- return b.toString();
- }
- private static void getAllContent(Node n, StringBuilder b) {
- Node nd = n.getFirstChild();
- while (nd != null) {
- if (nd instanceof Text && !(nd instanceof Comment)) {
- b.append(((Text)nd).getData());
- } else {
- getAllContent(nd, b);
- }
- nd = nd.getNextSibling();
- }
- }
- /**
- * Get the trimmed text content of a node or null if there is no text
- */
- public static String getContent(Node n) {
- String s = getRawContent(n);
- if (s != null) {
- s = s.trim();
- }
- return s;
- }
-
- /**
- * Get the raw text content of a node or null if there is no text
- */
- public static String getRawContent(Node n) {
- if (n == null) {
- return null;
- }
- StringBuilder b = null;
- String s = null;
- Node n1 = n.getFirstChild();
- while (n1 != null) {
- if (n1.getNodeType() == Node.TEXT_NODE || n1.getNodeType() == Node.CDATA_SECTION_NODE) {
- if (b != null) {
- b.append(((Text)n1).getNodeValue());
- } else if (s == null) {
- s = ((Text)n1).getNodeValue();
- } else {
- b = new StringBuilder(s).append(((Text)n1).getNodeValue());
- s = null;
- }
- }
- n1 = n1.getNextSibling();
- }
- if (b != null) {
- return b.toString();
- }
- return s;
- }
-
- /**
- * Get the first element child.
- *
- * @param parent lookup direct childs
- * @param name name of the element. If null return the first element.
- */
- public static Node getChild(Node parent, String name) {
- if (parent == null) {
- return null;
- }
-
- Node first = parent.getFirstChild();
- if (first == null) {
- return null;
- }
-
- for (Node node = first; node != null; node = node.getNextSibling()) {
-
- if (node.getNodeType() != Node.ELEMENT_NODE) {
- continue;
- }
- if (name != null && name.equals(node.getNodeName())) {
- return node;
- }
- if (name == null) {
- return node;
- }
- }
- return null;
- }
-
-
- public static boolean hasAttribute(Element element, String value) {
- NamedNodeMap attributes = element.getAttributes();
- for (int i = 0; i < attributes.getLength(); i++) {
- Node node = attributes.item(i);
- if (value.equals(node.getNodeValue())) {
- return true;
- }
- }
- return false;
- }
- public static String getAttribute(Node element, String attName) {
- NamedNodeMap attrs = element.getAttributes();
- if (attrs == null) {
- return null;
- }
- Node attN = attrs.getNamedItem(attName);
- if (attN == null) {
- return null;
- }
- return attN.getNodeValue();
- }
-
- public static String getAttribute(Element element, QName attName) {
- Attr attr;
- if (StringUtils.isEmpty(attName.getNamespaceURI())) {
- attr = element.getAttributeNode(attName.getLocalPart());
- } else {
- attr = element.getAttributeNodeNS(attName.getNamespaceURI(), attName.getLocalPart());
- }
- return attr == null ? null : attr.getValue();
- }
-
- public static void setAttribute(Node node, String attName, String val) {
- NamedNodeMap attributes = node.getAttributes();
- Node attNode = node.getOwnerDocument().createAttributeNS(null, attName);
- attNode.setNodeValue(val);
- attributes.setNamedItem(attNode);
- }
-
- public static void removeAttribute(Node node, String attName) {
- NamedNodeMap attributes = node.getAttributes();
- attributes.removeNamedItem(attName);
- }
-
- /**
- * Set or replace the text value
- */
- public static void setText(Node node, String val) {
- Node chld = DOMUtils.getChild(node, Node.TEXT_NODE);
- if (chld == null) {
- Node textN = node.getOwnerDocument().createTextNode(val);
- node.appendChild(textN);
- return;
- }
- // change the value
- chld.setNodeValue(val);
- }
-
- /**
- * Find the first direct child with a given attribute.
- *
- * @param parent
- * @param elemName name of the element, or null for any
- * @param attName attribute we're looking for
- * @param attVal attribute value or null if we just want any
- */
- public static Element findChildWithAtt(Node parent, String elemName, String attName, String attVal) {
-
- Element child = (Element)getChild(parent, Node.ELEMENT_NODE);
- if (attVal == null) {
- while (child != null && (elemName == null || elemName.equals(child.getNodeName()))
- && DOMUtils.getAttribute(child, attName) != null) {
- child = (Element)getNext(child, elemName, Node.ELEMENT_NODE);
- }
- } else {
- while (child != null && (elemName == null || elemName.equals(child.getNodeName()))
- && !attVal.equals(DOMUtils.getAttribute(child, attName))) {
- child = (Element)getNext(child, elemName, Node.ELEMENT_NODE);
- }
- }
- return child;
- }
-
- /**
- * Get the first child's content ( ie it's included TEXT node ).
- */
- public static String getChildContent(Node parent, String name) {
- Node first = parent.getFirstChild();
- if (first == null) {
- return null;
- }
- for (Node node = first; node != null; node = node.getNextSibling()) {
-
- if (name.equals(node.getNodeName())) {
- return getRawContent(node);
- }
- }
- return null;
- }
-
- public static QName getElementQName(Element el) {
- return new QName(el.getNamespaceURI(), el.getLocalName());
- }
-
- /**
- * Creates a QName object based on the qualified name
- * and using the Node as a base to lookup the namespace
- * for the prefix
- * @param qualifiedName
- * @param node
- */
- public static QName createQName(String qualifiedName, Node node) {
- if (qualifiedName == null) {
- return null;
- }
-
- int index = qualifiedName.indexOf(':');
-
- if (index == -1) {
- return new QName(qualifiedName);
- }
-
- String prefix = qualifiedName.substring(0, index);
- String localName = qualifiedName.substring(index + 1);
- String ns = node.lookupNamespaceURI(prefix);
-
- if (ns == null) {
- throw new RuntimeException("Invalid QName in mapping: " + qualifiedName);
- }
-
- return new QName(ns, localName, prefix);
- }
-
- public static QName convertStringToQName(String expandedQName) {
- return convertStringToQName(expandedQName, "");
- }
-
- public static QName convertStringToQName(String expandedQName, String prefix) {
- int ind1 = expandedQName.indexOf('{');
- if (ind1 != 0) {
- return new QName(expandedQName);
- }
-
- int ind2 = expandedQName.indexOf('}');
- if (ind2 <= ind1 + 1 || ind2 >= expandedQName.length() - 1) {
- return null;
- }
- String ns = expandedQName.substring(ind1 + 1, ind2);
- String localName = expandedQName.substring(ind2 + 1);
- return new QName(ns, localName, prefix);
- }
- public static Set<QName> convertStringsToQNames(List<String> expandedQNames) {
- Set<QName> dropElements = Collections.emptySet();
- if (expandedQNames != null) {
- dropElements = new LinkedHashSet<>(expandedQNames.size());
- for (String val : expandedQNames) {
- dropElements.add(convertStringToQName(val));
- }
- }
- return dropElements;
- }
-
-
- /**
- * Get the first direct child with a given type
- */
- public static Element getFirstElement(Node parent) {
- Node n = parent.getFirstChild();
- while (n != null && Node.ELEMENT_NODE != n.getNodeType()) {
- n = n.getNextSibling();
- }
- if (n == null) {
- return null;
- }
- return (Element)n;
- }
-
- public static Element getNextElement(Element el) {
- Node nd = el.getNextSibling();
- while (nd != null) {
- if (nd.getNodeType() == Node.ELEMENT_NODE) {
- return (Element)nd;
- }
- nd = nd.getNextSibling();
- }
- return null;
- }
-
- /**
- * Return the first element child with the specified qualified name.
- *
- * @param parent
- * @param q
- */
- public static Element getFirstChildWithName(Element parent, QName q) {
- String ns = q.getNamespaceURI();
- String lp = q.getLocalPart();
- return getFirstChildWithName(parent, ns, lp);
- }
-
- /**
- * Return the first element child with the specified qualified name.
- *
- * @param parent
- * @param ns
- * @param lp
- */
- public static Element getFirstChildWithName(Element parent, String ns, String lp) {
- for (Node n = parent.getFirstChild(); n != null; n = n.getNextSibling()) {
- if (n instanceof Element) {
- Element e = (Element)n;
- String ens = (e.getNamespaceURI() == null) ? "" : e.getNamespaceURI();
- if (ns.equals(ens) && lp.equals(e.getLocalName())) {
- return e;
- }
- }
- }
- return null;
- }
-
- /**
- * Return child elements with specified name.
- *
- * @param parent
- * @param ns
- * @param localName
- */
- public static List<Element> getChildrenWithName(Element parent, String ns, String localName) {
- List<Element> r = new ArrayList<>();
- for (Node n = parent.getFirstChild(); n != null; n = n.getNextSibling()) {
- if (n instanceof Element) {
- Element e = (Element)n;
- String eNs = (e.getNamespaceURI() == null) ? "" : e.getNamespaceURI();
- if (ns.equals(eNs) && localName.equals(e.getLocalName())) {
- r.add(e);
- }
- }
- }
- return r;
- }
-
- /**
- * Returns all child elements with specified namespace.
- *
- * @param parent the element to search under
- * @param ns the namespace to find elements in
- * @return all child elements with specified namespace
- */
- public static List<Element> getChildrenWithNamespace(Element parent, String ns) {
- List<Element> r = new ArrayList<>();
- for (Node n = parent.getFirstChild(); n != null; n = n.getNextSibling()) {
- if (n instanceof Element) {
- Element e = (Element)n;
- String eNs = (e.getNamespaceURI() == null) ? "" : e.getNamespaceURI();
- if (ns.equals(eNs)) {
- r.add(e);
- }
- }
- }
- return r;
- }
-
- /**
- * Get the first child of the specified type.
- *
- * @param parent
- * @param type
- */
- public static Node getChild(Node parent, int type) {
- Node n = parent.getFirstChild();
- while (n != null && type != n.getNodeType()) {
- n = n.getNextSibling();
- }
- if (n == null) {
- return null;
- }
- return n;
- }
-
- /**
- * Get the next sibling with the same name and type
- */
- public static Node getNext(Node current) {
- String name = current.getNodeName();
- int type = current.getNodeType();
- return getNext(current, name, type);
- }
-
- /**
- * Return the next sibling with a given name and type
- */
- public static Node getNext(Node current, String name, int type) {
- Node first = current.getNextSibling();
- if (first == null) {
- return null;
- }
-
- for (Node node = first; node != null; node = node.getNextSibling()) {
-
- if (type >= 0 && node.getNodeType() != type) {
- continue;
- }
-
- if (name == null) {
- return node;
- }
- if (name.equals(node.getNodeName())) {
- return node;
- }
- }
- return null;
- }
-
- public static class NullResolver implements EntityResolver {
- public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException {
- return new InputSource(new StringReader(""));
- }
- }
-
- public static String getPrefixRecursive(Element el, String ns) {
- String prefix = getPrefix(el, ns);
- if (prefix == null && el.getParentNode() instanceof Element) {
- prefix = getPrefixRecursive((Element)el.getParentNode(), ns);
- }
- return prefix;
- }
-
- public static String getPrefix(Element el, String ns) {
- NamedNodeMap atts = el.getAttributes();
- for (int i = 0; i < atts.getLength(); i++) {
- Node node = atts.item(i);
- String name = node.getNodeName();
- if (ns.equals(node.getNodeValue())
- && (name != null && (XMLNAMESPACE.equals(name) || name.startsWith(XMLNAMESPACE + ":")))) {
- return node.getLocalName();
- }
- }
- return null;
- }
-
- /**
- * Get all prefixes defined, up to the root, for a namespace URI.
- *
- * @param element
- * @param namespaceUri
- * @param prefixes
- */
- public static void getPrefixesRecursive(Element element, String namespaceUri, List<String> prefixes) {
- getPrefixes(element, namespaceUri, prefixes);
- Node parent = element.getParentNode();
- if (parent instanceof Element) {
- getPrefixesRecursive((Element)parent, namespaceUri, prefixes);
- }
- }
-
- /**
- * Get all prefixes defined on this element for the specified namespace.
- *
- * @param element
- * @param namespaceUri
- * @param prefixes
- */
- public static void getPrefixes(Element element, String namespaceUri, List<String> prefixes) {
- NamedNodeMap atts = element.getAttributes();
- for (int i = 0; i < atts.getLength(); i++) {
- Node node = atts.item(i);
- String name = node.getNodeName();
- if (namespaceUri.equals(node.getNodeValue())
- && (name != null && (XMLNAMESPACE.equals(name) || name.startsWith(XMLNAMESPACE + ":")))) {
- prefixes.add(node.getPrefix());
- }
- }
- }
-
- public static String createNamespace(Element el, String ns) {
- String p = "ns1";
- int i = 1;
- while (getPrefix(el, ns) != null) {
- p = "ns" + i;
- i++;
- }
- addNamespacePrefix(el, ns, p);
- return p;
- }
-
- /**
- * Starting from a node, find the namespace declaration for a prefix. for a matching namespace
- * declaration.
- *
- * @param node search up from here to search for namespace definitions
- * @param searchPrefix the prefix we are searching for
- * @return the namespace if found.
- */
- public static String getNamespace(Node node, String searchPrefix) {
-
- Element el;
- while (!(node instanceof Element)) {
- node = node.getParentNode();
- }
- el = (Element)node;
-
- NamedNodeMap atts = el.getAttributes();
- for (int i = 0; i < atts.getLength(); i++) {
- Node currentAttribute = atts.item(i);
- String currentLocalName = currentAttribute.getLocalName();
- String currentPrefix = currentAttribute.getPrefix();
- if (searchPrefix.equals(currentLocalName) && XMLNAMESPACE.equals(currentPrefix)) {
- return currentAttribute.getNodeValue();
- } else if (StringUtils.isEmpty(searchPrefix) && XMLNAMESPACE.equals(currentLocalName)
- && StringUtils.isEmpty(currentPrefix)) {
- return currentAttribute.getNodeValue();
- }
- }
-
- Node parent = el.getParentNode();
- if (parent instanceof Element) {
- return getNamespace(parent, searchPrefix);
- }
-
- return null;
- }
-
- public static List<Element> findAllElementsByTagNameNS(Element elem, String nameSpaceURI,
- String localName) {
- List<Element> ret = new LinkedList<>();
- findAllElementsByTagNameNS(elem, nameSpaceURI, localName, ret);
- return ret;
- }
-
- /**
- * Try to get the DOM Node from the SAAJ Node with JAVA9 afterwards
- * @param node The original node we need check
- * @return The DOM node
- */
- public static Node getDomElement(Node node) {
- if (node != null && isJava9SAAJ()) {
- //java9plus hack
- Method method = GET_DOM_ELEMENTS_METHODS.get(node.getClass());
- if (method != null) {
- try {
- return (Node)ReflectionUtil.setAccessible(method).invoke(node);
- } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
- throw new RuntimeException(e);
- }
- }
- }
- return node;
- }
-
- /**
- * Try to get the DOM DocumentFragment from the SAAJ DocumentFragment with JAVA9 afterwards
- * @param fragment The original documentFragment we need to check
- * @return The DOM DocumentFragment
- */
- public static DocumentFragment getDomDocumentFragment(DocumentFragment fragment) {
- if (fragment != null && isJava9SAAJ()) {
- //java9 plus hack
- Field f = GET_DOCUMENT_FRAGMENT_FIELDS.get(fragment.getClass());
- if (f != null) {
- return ReflectionUtil.accessDeclaredField(f, fragment, DocumentFragment.class);
- }
- }
- return fragment;
- }
-
- private static void findAllElementsByTagNameNS(Element el, String nameSpaceURI, String localName,
- List<Element> elementList) {
-
- if (el.getNamespaceURI() != null && localName.equals(el.getLocalName())
- && nameSpaceURI.contains(el.getNamespaceURI())) {
- elementList.add(el);
- }
- Element elem = getFirstElement(el);
- while (elem != null) {
- findAllElementsByTagNameNS(elem, nameSpaceURI, localName, elementList);
- elem = getNextElement(elem);
- }
- }
-
- public static List<Element> findAllElementsByTagName(Element elem, String tagName) {
- List<Element> ret = new LinkedList<>();
- findAllElementsByTagName(elem, tagName, ret);
- return ret;
- }
-
- private static void findAllElementsByTagName(Element el, String tagName, List<Element> elementList) {
-
- if (tagName.equals(el.getTagName())) {
- elementList.add(el);
- }
- Element elem = getFirstElement(el);
- while (elem != null) {
- findAllElementsByTagName(elem, tagName, elementList);
- elem = getNextElement(elem);
- }
- }
- public static boolean hasElementWithName(Element el, String nameSpaceURI, String localName) {
- if (el.getNamespaceURI() != null && localName.equals(el.getLocalName())
- && nameSpaceURI.contains(el.getNamespaceURI())) {
- return true;
- }
- Element elem = getFirstElement(el);
- while (elem != null) {
- if (hasElementWithName(elem, nameSpaceURI, localName)) {
- return true;
- }
- elem = getNextElement(elem);
- }
- return false;
- }
- public static boolean hasElementInNS(Element el, String namespace) {
-
- if (namespace.equals(el.getNamespaceURI())) {
- return true;
- }
- Element elem = getFirstElement(el);
- while (elem != null) {
- if (hasElementInNS(elem, namespace)) {
- return true;
- }
- elem = getNextElement(elem);
- }
- return false;
- }
- /**
- * Set a namespace/prefix on an element if it is not set already. First off, it searches for the element
- * for the prefix associated with the specified namespace. If the prefix isn't null, then this is
- * returned. Otherwise, it creates a new attribute using the namespace/prefix passed as parameters.
- *
- * @param element
- * @param namespace
- * @param prefix
- * @return the prefix associated with the set namespace
- */
- public static String setNamespace(Element element, String namespace, String prefix) {
- String pre = getPrefixRecursive(element, namespace);
- if (pre != null) {
- return pre;
- }
- element.setAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, "xmlns:" + prefix, namespace);
- return prefix;
- }
-
- /**
- * Add a namespace prefix definition to an element.
- *
- * @param element
- * @param namespaceUri
- * @param prefix
- */
- public static void addNamespacePrefix(Element element, String namespaceUri, String prefix) {
- element.setAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, "xmlns:" + prefix, namespaceUri);
- }
-
- public static boolean isJava9SAAJ() {
- return isJre9SAAJ;
- }
-
- private static void setJava9SAAJ(boolean isJava9SAAJ) {
- DOMUtils.isJre9SAAJ = isJava9SAAJ;
- }
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/helpers/IOUtils.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/helpers/IOUtils.java
deleted file mode 100644
index 74af28d..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/helpers/IOUtils.java
+++ /dev/null
@@ -1,428 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.cxf.helpers;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.OutputStream;
-import java.io.PushbackInputStream;
-import java.io.Reader;
-import java.io.UnsupportedEncodingException;
-import java.io.Writer;
-import java.nio.charset.Charset;
-import java.nio.file.Files;
-
-import org.apache.cxf.io.CopyingOutputStream;
-import org.apache.cxf.io.Transferable;
-
-public final class IOUtils {
- public static final Charset UTF8_CHARSET = java.nio.charset.StandardCharsets.UTF_8;
- public static final int DEFAULT_BUFFER_SIZE = 1024 * 4;
-
- private IOUtils() {
-
- }
-
- /**
- * Checks if input stream is empty. If the standard InputStream means do not provide
- * such details, the stream might be wrapped into PushbackInputStream and is going
- * to be returned instead of original one.
- * @param is input stream to check
- * @return "null" if original input stream is empty, otherwise original stream or
- * original stream wrapped into PushbackInputStream.
- * @throws IOException
- */
- public static InputStream nullOrNotEmptyStream(InputStream is) throws IOException {
- if (isEmpty(is)) {
- return null;
- } else if (!(is instanceof PushbackInputStream)) {
- final byte[] bytes = new byte[1];
-
- final PushbackInputStream pbStream = new PushbackInputStream(is);
- boolean isEmpty = isEof(pbStream.read(bytes));
-
- if (!isEmpty) {
- pbStream.unread(bytes);
- return pbStream;
- }
-
- return null;
- }
-
- return is;
- }
-
- public static boolean isEmpty(InputStream is) throws IOException {
- if (is == null) {
- return true;
- }
- try {
- // if available is 0 it does not mean it is empty
- if (is.available() > 0) {
- return false;
- }
- } catch (IOException ioe) {
- //Do nothing
- }
- final byte[] bytes = new byte[1];
- if (is.markSupported()) {
- is.mark(1);
- try {
- return isEof(is.read(bytes));
- } finally {
- is.reset();
- }
- }
-
- if (!(is instanceof PushbackInputStream)) {
- return false;
- }
-
- // it may be an attachment stream
- PushbackInputStream pbStream = (PushbackInputStream)is;
- boolean isEmpty = isEof(pbStream.read(bytes));
- if (!isEmpty) {
- pbStream.unread(bytes);
- }
-
- return isEmpty;
- }
- private static boolean isEof(int result) {
- return result == -1;
- }
- /**
- * Use this function instead of new String(byte[], String) to avoid surprises from
- * non-standard default encodings.
- * @param bytes
- * @param charsetName
- */
- public static String newStringFromBytes(byte[] bytes, String charsetName) {
- try {
- return new String(bytes, charsetName);
- } catch (UnsupportedEncodingException e) {
- throw
- new RuntimeException("Impossible failure: Charset.forName(\""
- + charsetName + "\") returns invalid name.");
-
- }
- }
-
-
- /**
- * Use this function instead of new String(byte[]) to avoid surprises from non-standard default encodings.
- * @param bytes
- */
- public static String newStringFromBytes(byte[] bytes) {
- return newStringFromBytes(bytes, UTF8_CHARSET.name());
- }
-
- /**
- * Use this function instead of new String(byte[], int, int, String)
- * to avoid surprises from non-standard default encodings.
- * @param bytes
- * @param charsetName
- * @param start
- * @param length
- */
- public static String newStringFromBytes(byte[] bytes, String charsetName, int start, int length) {
- try {
- return new String(bytes, start, length, charsetName);
- } catch (UnsupportedEncodingException e) {
- throw
- new RuntimeException("Impossible failure: Charset.forName(\""
- + charsetName + "\") returns invalid name.");
-
- }
- }
-
- /**
- * Use this function instead of new String(byte[], int, int)
- * to avoid surprises from non-standard default encodings.
- * @param bytes
- * @param start
- * @param length
- */
- public static String newStringFromBytes(byte[] bytes, int start, int length) {
- return newStringFromBytes(bytes, UTF8_CHARSET.name(), start, length);
- }
-
- public static int copy(final InputStream input, final OutputStream output)
- throws IOException {
- if (input == null) {
- return 0;
- }
- if (output instanceof CopyingOutputStream) {
- return ((CopyingOutputStream)output).copyFrom(input);
- }
- return copy(input, output, DEFAULT_BUFFER_SIZE);
- }
-
- public static int copyAndCloseInput(final InputStream input,
- final OutputStream output) throws IOException {
- try (InputStream in = input) {
- return copy(in, output);
- }
- }
-
- public static int copyAndCloseInput(final InputStream input,
- final OutputStream output, int bufferSize) throws IOException {
- try (InputStream in = input) {
- return copy(in, output, bufferSize);
- }
- }
-
- public static void copyAndCloseInput(final Reader input,
- final Writer output) throws IOException {
- try (Reader r = input) {
- copy(r, output, DEFAULT_BUFFER_SIZE);
- }
- }
-
- public static void copyAndCloseInput(final Reader input,
- final Writer output, int bufferSize) throws IOException {
- try (Reader r = input) {
- copy(r, output, bufferSize);
- }
- }
-
- public static int copy(final InputStream input, final OutputStream output,
- int bufferSize) throws IOException {
- int avail = input.available();
- if (avail > 262144) {
- avail = 262144;
- }
- if (avail > bufferSize) {
- bufferSize = avail;
- }
- final byte[] buffer = new byte[bufferSize];
- int n = input.read(buffer);
- int total = 0;
- while (-1 != n) {
- if (n == 0) {
- throw new IOException("0 bytes read in violation of InputStream.read(byte[])");
- }
- output.write(buffer, 0, n);
- total += n;
- n = input.read(buffer);
- }
- return total;
- }
-
- /**
- * Copy at least the specified number of bytes from the input to the output
- * or until the inputstream is finished.
- * @param input
- * @param output
- * @param atLeast
- * @throws IOException
- */
- public static void copyAtLeast(final InputStream input,
- final OutputStream output,
- int atLeast) throws IOException {
- final byte[] buffer = new byte[4096];
- int n = atLeast > buffer.length ? buffer.length : atLeast;
- n = input.read(buffer, 0, n);
- while (-1 != n) {
- if (n == 0) {
- throw new IOException("0 bytes read in violation of InputStream.read(byte[])");
- }
- output.write(buffer, 0, n);
- atLeast -= n;
- if (atLeast <= 0) {
- return;
- }
- n = atLeast > buffer.length ? buffer.length : atLeast;
- n = input.read(buffer, 0, n);
- }
- }
-
- public static void copyAtLeast(final Reader input,
- final Writer output,
- int atLeast) throws IOException {
- final char[] buffer = new char[4096];
- int n = atLeast > buffer.length ? buffer.length : atLeast;
- n = input.read(buffer, 0, n);
- while (-1 != n) {
- if (n == 0) {
- throw new IOException("0 bytes read in violation of Reader.read(char[])");
- }
- output.write(buffer, 0, n);
- atLeast -= n;
- if (atLeast <= 0) {
- return;
- }
- n = atLeast > buffer.length ? buffer.length : atLeast;
- n = input.read(buffer, 0, n);
- }
- }
-
-
- public static void copy(final Reader input, final Writer output,
- final int bufferSize) throws IOException {
- final char[] buffer = new char[bufferSize];
- int n = input.read(buffer);
- while (-1 != n) {
- output.write(buffer, 0, n);
- n = input.read(buffer);
- }
- }
-
- public static void transferTo(InputStream inputStream, File destinationFile) throws IOException {
- if (Transferable.class.isAssignableFrom(inputStream.getClass())) {
- ((Transferable)inputStream).transferTo(destinationFile);
- } else {
- try (OutputStream out = Files.newOutputStream(destinationFile.toPath())) {
- copyAndCloseInput(inputStream, out);
- }
- }
- }
-
-
- public static String toString(final InputStream input) throws IOException {
- return toString(input, DEFAULT_BUFFER_SIZE);
- }
- public static String toString(final InputStream input, String charset) throws IOException {
- return toString(input, DEFAULT_BUFFER_SIZE, charset);
- }
- public static String toString(final InputStream input, int bufferSize)
- throws IOException {
- return toString(input, bufferSize, null);
- }
- public static String toString(final InputStream input, int bufferSize, String charset)
- throws IOException {
-
-
- int avail = input.available();
- if (avail > bufferSize) {
- bufferSize = avail;
- }
- Reader reader = charset == null ? new InputStreamReader(input, UTF8_CHARSET)
- : new InputStreamReader(input, charset);
- return toString(reader, bufferSize);
- }
-
- public static String toString(final Reader input) throws IOException {
- return toString(input, DEFAULT_BUFFER_SIZE);
- }
- public static String toString(final Reader input, int bufSize) throws IOException {
-
- StringBuilder buf = new StringBuilder();
- final char[] buffer = new char[bufSize];
- try (Reader r = input) {
- int n = r.read(buffer);
- while (-1 != n) {
- if (n == 0) {
- throw new IOException("0 bytes read in violation of InputStream.read(byte[])");
- }
- buf.append(buffer, 0, n);
- n = r.read(buffer);
- }
- return buf.toString();
- }
- }
-
- public static String readStringFromStream(InputStream in)
- throws IOException {
- return toString(in);
- }
-
- /**
- * Load the InputStream into memory and return a ByteArrayInputStream that
- * represents it. Closes the in stream.
- *
- * @param in
- * @throws IOException
- */
- public static ByteArrayInputStream loadIntoBAIS(InputStream in)
- throws IOException {
- int i = in.available();
- if (i < DEFAULT_BUFFER_SIZE) {
- i = DEFAULT_BUFFER_SIZE;
- }
- LoadingByteArrayOutputStream bout = new LoadingByteArrayOutputStream(i);
- copy(in, bout);
- in.close();
- return bout.createInputStream();
- }
-
- public static void consume(InputStream in) throws IOException {
- int i = in.available();
- if (i == 0) {
- //if i is 0, then we MAY have already hit the end of the stream
- //so try a read and return rather than allocate a buffer and such
- int i2 = in.read();
- if (i2 == -1) {
- return;
- }
- //reading the byte may have caused a buffer to fill
- i = in.available();
- }
- if (i < DEFAULT_BUFFER_SIZE) {
- i = DEFAULT_BUFFER_SIZE;
- }
- if (i > 65536) {
- i = 65536;
- }
- byte[] bytes = new byte[i];
- while (in.read(bytes) != -1) {
- //nothing - just discarding
- }
- }
-
- /**
- * Consumes at least the given number of bytes from the input stream
- * @param input
- * @param atLeast
- * @throws IOException
- */
- public static void consume(final InputStream input,
- int atLeast) throws IOException {
- final byte[] buffer = new byte[4096];
- int n = atLeast > buffer.length ? buffer.length : atLeast;
- n = input.read(buffer, 0, n);
- while (-1 != n) {
- if (n == 0) {
- throw new IOException("0 bytes read in violation of InputStream.read(byte[])");
- }
- atLeast -= n;
- if (atLeast <= 0) {
- return;
- }
- n = atLeast > buffer.length ? buffer.length : atLeast;
- n = input.read(buffer, 0, n);
- }
- }
-
- public static byte[] readBytesFromStream(InputStream in) throws IOException {
- int i = in.available();
- if (i < DEFAULT_BUFFER_SIZE) {
- i = DEFAULT_BUFFER_SIZE;
- }
- try (InputStream input = in; ByteArrayOutputStream bos = new ByteArrayOutputStream(i)) {
- copy(input, bos);
- return bos.toByteArray();
- }
- }
-
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/helpers/ServiceUtils.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/helpers/ServiceUtils.java
deleted file mode 100644
index a39ee94..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/helpers/ServiceUtils.java
+++ /dev/null
@@ -1,214 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.cxf.helpers;
-
-import java.util.StringTokenizer;
-
-import org.apache.cxf.annotations.SchemaValidation.SchemaValidationType;
-import org.apache.cxf.endpoint.Endpoint;
-import org.apache.cxf.message.Exchange;
-import org.apache.cxf.message.Message;
-import org.apache.cxf.message.MessageUtils;
-import org.apache.cxf.service.model.AbstractPropertiesHolder;
-import org.apache.cxf.service.model.BindingOperationInfo;
-import org.apache.cxf.service.model.EndpointInfo;
-import org.apache.cxf.service.model.OperationInfo;
-
-public final class ServiceUtils {
-
- private ServiceUtils() {
- }
-
- /**
- * A short cut method to be able to test for if Schema Validation should be enabled
- * for IN or OUT without having to check BOTH and IN or OUT.
- *
- * @param message
- * @param type
- */
- public static boolean isSchemaValidationEnabled(SchemaValidationType type, Message message) {
- SchemaValidationType validationType = getSchemaValidationType(message);
-
- boolean isRequestor = MessageUtils.isRequestor(message);
- if (SchemaValidationType.REQUEST.equals(validationType)) {
- if (isRequestor) {
- validationType = SchemaValidationType.OUT;
- } else {
- validationType = SchemaValidationType.IN;
- }
- } else if (SchemaValidationType.RESPONSE.equals(validationType)) {
- if (isRequestor) {
- validationType = SchemaValidationType.IN;
- } else {
- validationType = SchemaValidationType.OUT;
- }
- }
-
- return validationType.equals(type)
- || ((SchemaValidationType.IN.equals(type) || SchemaValidationType.OUT.equals(type))
- && SchemaValidationType.BOTH.equals(validationType));
- }
- /**
- * A convenience method to check for schema validation config in the message context, and then in the service model.
- * Does not modify the Message context (other than what is done in the getContextualProperty itself)
- *
- * @param message
- */
- public static SchemaValidationType getSchemaValidationType(Message message) {
- SchemaValidationType validationType = getOverrideSchemaValidationType(message);
- if (validationType == null) {
- validationType = getSchemaValidationTypeFromModel(message);
- }
- if (validationType == null) {
- Object obj = message.getContextualProperty(Message.SCHEMA_VALIDATION_ENABLED);
- if (obj != null) {
- validationType = getSchemaValidationType(obj);
- }
- }
- if (validationType == null) {
- validationType = SchemaValidationType.NONE;
- }
-
- return validationType;
- }
-
- private static SchemaValidationType getOverrideSchemaValidationType(Message message) {
- Object obj = message.get(Message.SCHEMA_VALIDATION_ENABLED);
- if (obj == null && message.getExchange() != null) {
- obj = message.getExchange().get(Message.SCHEMA_VALIDATION_ENABLED);
- }
- if (obj != null) {
- // this method will transform the legacy enabled as well
- return getSchemaValidationType(obj);
- }
- return null;
- }
-
- private static SchemaValidationType getSchemaValidationTypeFromModel(Message message) {
- Exchange exchange = message.getExchange();
- SchemaValidationType validationType = null;
-
- if (exchange != null) {
-
- BindingOperationInfo boi = exchange.getBindingOperationInfo();
- if (boi != null) {
- OperationInfo opInfo = boi.getOperationInfo();
- if (opInfo != null) {
- validationType = getSchemaValidationTypeFromModel(opInfo);
- }
- }
-
- if (validationType == null) {
- Endpoint endpoint = exchange.getEndpoint();
- if (endpoint != null) {
- EndpointInfo ep = endpoint.getEndpointInfo();
- if (ep != null) {
- validationType = getSchemaValidationTypeFromModel(ep);
- }
- }
- }
- }
-
- return validationType;
- }
-
- private static SchemaValidationType getSchemaValidationTypeFromModel(
- AbstractPropertiesHolder properties) {
- Object obj = properties.getProperty(Message.SCHEMA_VALIDATION_TYPE);
- if (obj != null) {
- return getSchemaValidationType(obj);
- }
- return null;
- }
-
- public static SchemaValidationType getSchemaValidationType(Object obj) {
- if (obj instanceof SchemaValidationType) {
- return (SchemaValidationType)obj;
- } else if (obj != null) {
- String value = obj.toString().toUpperCase(); // handle boolean values as well
- if ("TRUE".equals(value)) {
- return SchemaValidationType.BOTH;
- } else if ("FALSE".equals(value)) {
- return SchemaValidationType.NONE;
- } else if (value.length() > 0) {
- return SchemaValidationType.valueOf(value);
- }
- }
-
- // fall through default value
- return SchemaValidationType.NONE;
- }
-
- /**
- * Generates a suitable service name from a given class. The returned name
- * is the simple name of the class, i.e. without the package name.
- *
- * @param clazz the class.
- * @return the name.
- */
- public static String makeServiceNameFromClassName(Class<?> clazz) {
- String name = clazz.getName();
- int last = name.lastIndexOf('.');
- if (last != -1) {
- name = name.substring(last + 1);
- }
-
- int inner = name.lastIndexOf('$');
- if (inner != -1) {
- name = name.substring(inner + 1);
- }
-
- return name;
- }
-
- /**
- * Generates the name of a XML namespace from a given class name and
- * protocol. The returned namespace will take the form
- * <code>protocol://domain</code>, where <code>protocol</code> is the
- * given protocol, and <code>domain</code> the inversed package name of
- * the given class name. <p/> For instance, if the given class name is
- * <code>org.codehaus.xfire.services.Echo</code>, and the protocol is
- * <code>http</code>, the resulting namespace would be
- * <code>http://services.xfire.codehaus.org</code>.
- *
- * @param className the class name
- * @param protocol the protocol (eg. <code>http</code>)
- * @return the namespace
- */
- public static String makeNamespaceFromClassName(String className, String protocol) {
- int index = className.lastIndexOf('.');
-
- if (index == -1) {
- return protocol + "://" + "DefaultNamespace";
- }
-
- String packageName = className.substring(0, index);
-
- StringTokenizer st = new StringTokenizer(packageName, ".");
- String[] words = new String[st.countTokens()];
-
- for (int i = words.length - 1; i >= 0; --i) {
- words[i] = st.nextToken();
- }
-
- return protocol + "://" + String.join(".", words) + "/";
- }
-
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/interceptor/AbstractFaultChainInitiatorObserver.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/interceptor/AbstractFaultChainInitiatorObserver.java
deleted file mode 100644
index 70d5ae0..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/interceptor/AbstractFaultChainInitiatorObserver.java
+++ /dev/null
@@ -1,142 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.cxf.interceptor;
-
-import java.util.SortedSet;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import org.apache.cxf.Bus;
-import org.apache.cxf.BusFactory;
-import org.apache.cxf.common.classloader.ClassLoaderUtils;
-import org.apache.cxf.common.classloader.ClassLoaderUtils.ClassLoaderHolder;
-import org.apache.cxf.common.logging.LogUtils;
-import org.apache.cxf.message.Exchange;
-import org.apache.cxf.message.FaultMode;
-import org.apache.cxf.message.Message;
-import org.apache.cxf.message.MessageImpl;
-import org.apache.cxf.phase.Phase;
-import org.apache.cxf.phase.PhaseInterceptorChain;
-import org.apache.cxf.service.model.BindingFaultInfo;
-import org.apache.cxf.transport.MessageObserver;
-
-public abstract class AbstractFaultChainInitiatorObserver implements MessageObserver {
-
- private static final Logger LOG = LogUtils.getL7dLogger(AbstractFaultChainInitiatorObserver.class);
-
- private Bus bus;
- private ClassLoader loader;
-
- public AbstractFaultChainInitiatorObserver(Bus bus) {
- this.bus = bus;
- if (bus != null) {
- loader = bus.getExtension(ClassLoader.class);
- }
- }
-
- public void onMessage(Message message) {
-
- assert null != message;
-
- Bus origBus = BusFactory.getAndSetThreadDefaultBus(bus);
- ClassLoaderHolder origLoader = null;
- try {
- if (loader != null) {
- origLoader = ClassLoaderUtils.setThreadContextClassloader(loader);
- }
-
- Exchange exchange = message.getExchange();
-
- Message faultMessage;
-
- // now that we have switched over to the fault chain,
- // prevent any further operations on the in/out message
-
- if (isOutboundObserver()) {
- Exception ex = message.getContent(Exception.class);
- if (!(ex instanceof Fault)) {
- ex = new Fault(ex);
- }
- FaultMode mode = message.get(FaultMode.class);
-
- faultMessage = exchange.getOutMessage();
- if (null == faultMessage) {
- faultMessage = new MessageImpl();
- faultMessage.setExchange(exchange);
- faultMessage = exchange.getEndpoint().getBinding().createMessage(faultMessage);
- }
- faultMessage.setContent(Exception.class, ex);
- if (null != mode) {
- faultMessage.put(FaultMode.class, mode);
- }
- //CXF-3981
- if (message.get("javax.xml.ws.addressing.context.inbound") != null) {
- faultMessage.put("javax.xml.ws.addressing.context.inbound",
- message.get("javax.xml.ws.addressing.context.inbound"));
- }
- exchange.setOutMessage(null);
- exchange.setOutFaultMessage(faultMessage);
- if (message.get(BindingFaultInfo.class) != null) {
- faultMessage.put(BindingFaultInfo.class, message.get(BindingFaultInfo.class));
- }
- } else {
- faultMessage = message;
- exchange.setInMessage(null);
- exchange.setInFaultMessage(faultMessage);
- }
-
-
- // setup chain
- PhaseInterceptorChain chain = new PhaseInterceptorChain(getPhases());
- initializeInterceptors(faultMessage.getExchange(), chain);
-
- faultMessage.setInterceptorChain(chain);
- try {
- chain.doIntercept(faultMessage);
- } catch (RuntimeException exc) {
- LOG.log(Level.SEVERE, "ERROR_DURING_ERROR_PROCESSING", exc);
- throw exc;
- } catch (Exception exc) {
- LOG.log(Level.SEVERE, "ERROR_DURING_ERROR_PROCESSING", exc);
- throw new RuntimeException(exc);
- }
- } finally {
- if (origBus != bus) {
- BusFactory.setThreadDefaultBus(origBus);
- }
- if (origLoader != null) {
- origLoader.reset();
- }
- }
- }
-
- protected abstract boolean isOutboundObserver();
-
- protected abstract SortedSet<Phase> getPhases();
-
- protected void initializeInterceptors(Exchange ex, PhaseInterceptorChain chain) {
-
- }
-
- public Bus getBus() {
- return bus;
- }
-
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/interceptor/AbstractLoggingInterceptor.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/interceptor/AbstractLoggingInterceptor.java
deleted file mode 100644
index 5178453..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/interceptor/AbstractLoggingInterceptor.java
+++ /dev/null
@@ -1,298 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.cxf.interceptor;
-
-import java.io.File;
-import java.io.FileWriter;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.PrintWriter;
-import java.io.StringReader;
-import java.io.StringWriter;
-import java.net.URI;
-import java.util.Arrays;
-import java.util.List;
-import java.util.logging.Level;
-import java.util.logging.LogRecord;
-import java.util.logging.Logger;
-
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamWriter;
-import javax.xml.transform.stream.StreamSource;
-
-import org.apache.cxf.common.logging.LogUtils;
-import org.apache.cxf.common.util.PropertyUtils;
-import org.apache.cxf.common.util.StringUtils;
-import org.apache.cxf.endpoint.Endpoint;
-import org.apache.cxf.io.CachedOutputStream;
-import org.apache.cxf.message.Message;
-import org.apache.cxf.phase.AbstractPhaseInterceptor;
-import org.apache.cxf.service.model.EndpointInfo;
-import org.apache.cxf.service.model.InterfaceInfo;
-import org.apache.cxf.staxutils.PrettyPrintXMLStreamWriter;
-import org.apache.cxf.staxutils.StaxUtils;
-
-/**
- * A simple logging handler which outputs the bytes of the message to the
- * Logger.
- * @deprecated
- */
-@Deprecated
-public abstract class AbstractLoggingInterceptor extends AbstractPhaseInterceptor<Message> {
- public static final int DEFAULT_LIMIT = 48 * 1024;
- protected static final String BINARY_CONTENT_MESSAGE = "--- Binary Content ---";
- protected static final String MULTIPART_CONTENT_MESSAGE = "--- Multipart Content ---";
- private static final String MULTIPART_CONTENT_MEDIA_TYPE = "multipart";
- private static final String LIVE_LOGGING_PROP = "org.apache.cxf.logging.enable";
- private static final List<String> BINARY_CONTENT_MEDIA_TYPES = Arrays.asList(
- "application/octet-stream", "application/pdf", "image/png", "image/jpeg", "image/gif");
-
- protected int limit = DEFAULT_LIMIT;
- protected long threshold = -1;
- protected PrintWriter writer;
- protected boolean prettyLogging;
- private boolean showBinaryContent;
- private boolean showMultipartContent = true;
- private List<String> binaryContentMediaTypes = BINARY_CONTENT_MEDIA_TYPES;
-
- public AbstractLoggingInterceptor(String phase) {
- super(phase);
- }
- public AbstractLoggingInterceptor(String id, String phase) {
- super(id, phase);
- }
-
- protected static boolean isLoggingDisabledNow(Message message) {
- Object liveLoggingProp = message.getContextualProperty(LIVE_LOGGING_PROP);
- return liveLoggingProp != null && PropertyUtils.isFalse(liveLoggingProp);
- }
-
- protected abstract Logger getLogger();
-
- Logger getMessageLogger(Message message) {
- if (isLoggingDisabledNow(message)) {
- return null;
- }
- Endpoint ep = message.getExchange().getEndpoint();
- if (ep == null || ep.getEndpointInfo() == null) {
- return getLogger();
- }
- EndpointInfo endpoint = ep.getEndpointInfo();
- if (endpoint.getService() == null) {
- return getLogger();
- }
- Logger logger = endpoint.getProperty("MessageLogger", Logger.class);
- if (logger == null) {
- String serviceName = endpoint.getService().getName().getLocalPart();
- InterfaceInfo iface = endpoint.getService().getInterface();
- String portName = endpoint.getName().getLocalPart();
- String portTypeName = iface.getName().getLocalPart();
- String logName = "org.apache.cxf.services." + serviceName + "."
- + portName + "." + portTypeName;
- logger = LogUtils.getL7dLogger(this.getClass(), null, logName);
- endpoint.setProperty("MessageLogger", logger);
- }
- return logger;
- }
-
- public void setOutputLocation(String s) {
- if (s == null || "<logger>".equals(s)) {
- writer = null;
- } else if ("<stdout>".equals(s)) {
- writer = new PrintWriter(System.out, true);
- } else if ("<stderr>".equals(s)) {
- writer = new PrintWriter(System.err, true);
- } else {
- try {
- URI uri = new URI(s);
- File file = new File(uri);
- writer = new PrintWriter(new FileWriter(file, true), true);
- } catch (Exception ex) {
- getLogger().log(Level.WARNING, "Error configuring log location " + s, ex);
- }
- }
- }
-
- public void setPrintWriter(PrintWriter w) {
- writer = w;
- }
-
- public PrintWriter getPrintWriter() {
- return writer;
- }
-
- public void setLimit(int lim) {
- limit = lim;
- }
-
- public int getLimit() {
- return limit;
- }
-
- public void setPrettyLogging(boolean flag) {
- prettyLogging = flag;
- }
-
- public boolean isPrettyLogging() {
- return prettyLogging;
- }
-
- public void setInMemThreshold(long t) {
- threshold = t;
- }
-
- public long getInMemThreshold() {
- return threshold;
- }
-
- protected void writePayload(StringBuilder builder, CachedOutputStream cos,
- String encoding, String contentType, boolean truncated)
- throws Exception {
- // Just transform the XML message when the cos has content
- if (!truncated && isPrettyLogging() && contentType != null && contentType.contains("xml")
- && !contentType.toLowerCase().contains("multipart/related") && cos.size() > 0) {
-
- StringWriter swriter = new StringWriter();
- XMLStreamWriter xwriter = StaxUtils.createXMLStreamWriter(swriter);
- xwriter = new PrettyPrintXMLStreamWriter(xwriter, 2);
- try (InputStream in = cos.getInputStream()) {
- InputStreamReader inputStreamReader = StringUtils.isEmpty(encoding)
- ? new InputStreamReader(in) : new InputStreamReader(in, encoding);
- StaxUtils.copy(new StreamSource(inputStreamReader), xwriter);
- } catch (XMLStreamException xse) {
- //ignore
- } finally {
- try {
- xwriter.flush();
- xwriter.close();
- } catch (XMLStreamException xse2) {
- //ignore
- }
- }
-
- String result = swriter.toString();
- if (result.length() < limit || limit == -1) {
- builder.append(result);
- } else {
- builder.append(result.substring(0, limit));
- }
-
- } else {
- if (StringUtils.isEmpty(encoding)) {
- cos.writeCacheTo(builder, limit);
- } else {
- cos.writeCacheTo(builder, encoding, limit);
- }
- }
- }
- protected void writePayload(StringBuilder builder,
- StringWriter stringWriter,
- String contentType)
- throws Exception {
- if (isPrettyLogging()
- && contentType != null
- && contentType.contains("xml")
- && stringWriter.getBuffer().length() > 0) {
- try {
- writePrettyPayload(builder, stringWriter, contentType);
- return;
- } catch (Exception ex) {
- // log it as is
- }
- }
- StringBuffer buffer = stringWriter.getBuffer();
- if (buffer.length() > limit) {
- builder.append(buffer.subSequence(0, limit));
- } else {
- builder.append(buffer);
- }
- }
- protected void writePrettyPayload(StringBuilder builder,
- StringWriter stringWriter,
- String contentType)
- throws Exception {
- // Just transform the XML message when the cos has content
-
- StringWriter swriter = new StringWriter();
- XMLStreamWriter xwriter = StaxUtils.createXMLStreamWriter(swriter);
- xwriter = new PrettyPrintXMLStreamWriter(xwriter, 2);
- StaxUtils.copy(new StreamSource(new StringReader(stringWriter.getBuffer().toString())), xwriter);
- xwriter.close();
-
- String result = swriter.toString();
- if (result.length() < limit || limit == -1) {
- builder.append(swriter.toString());
- } else {
- builder.append(swriter.toString().substring(0, limit));
- }
- }
-
-
- /**
- * Transform the string before display. The implementation in this class
- * does nothing. Override this method if you wish to change the contents of the
- * logged message before it is delivered to the output.
- * For example, you can use this to mask out sensitive information.
- * @param originalLogString the raw log message.
- * @return transformed data
- */
- protected String transform(String originalLogString) {
- return originalLogString;
- }
-
- protected void log(Logger logger, String message) {
- message = transform(message);
- if (writer != null) {
- writer.println(message);
- // Flushing the writer to make sure the message is written
- writer.flush();
- } else if (logger.isLoggable(Level.INFO)) {
- LogRecord lr = new LogRecord(Level.INFO, message);
- lr.setSourceClassName(logger.getName());
- lr.setSourceMethodName(null);
- lr.setLoggerName(logger.getName());
- logger.log(lr);
- }
- }
- public void setShowBinaryContent(boolean showBinaryContent) {
- this.showBinaryContent = showBinaryContent;
- }
- public boolean isShowBinaryContent() {
- return showBinaryContent;
- }
- protected boolean isBinaryContent(String contentType) {
- return contentType != null && binaryContentMediaTypes.contains(contentType);
- }
- public boolean isShowMultipartContent() {
- return showMultipartContent;
- }
- public void setShowMultipartContent(boolean showMultipartContent) {
- this.showMultipartContent = showMultipartContent;
- }
- protected boolean isMultipartContent(String contentType) {
- return contentType != null && contentType.startsWith(MULTIPART_CONTENT_MEDIA_TYPE);
- }
- public List<String> getBinaryContentMediaTypes() {
- return binaryContentMediaTypes;
- }
- public void setBinaryContentMediaTypes(List<String> binaryContentMediaTypes) {
- this.binaryContentMediaTypes = binaryContentMediaTypes;
- }
-
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/interceptor/AnnotationInterceptors.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/interceptor/AnnotationInterceptors.java
deleted file mode 100644
index 8cc757e..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/interceptor/AnnotationInterceptors.java
+++ /dev/null
@@ -1,151 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.cxf.interceptor;
-
-import java.lang.annotation.Annotation;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.ResourceBundle;
-
-import org.apache.cxf.common.classloader.ClassLoaderUtils;
-import org.apache.cxf.common.i18n.BundleUtils;
-import org.apache.cxf.feature.Feature;
-import org.apache.cxf.feature.Features;
-import org.apache.cxf.message.Message;
-
-public class AnnotationInterceptors {
-
- private static final ResourceBundle BUNDLE = BundleUtils.getBundle(AnnotationInterceptors.class);
-
- private Class<?>[] clazzes;
-
- public AnnotationInterceptors(Class<?> ... clz) {
- clazzes = clz;
- }
-
- private <T> List<T> getAnnotationObject(Class<? extends Annotation> annotationClazz, Class<T> type) {
-
- for (Class<?> cls : clazzes) {
- Annotation annotation = cls.getAnnotation(annotationClazz);
- if (annotation != null) {
- return initializeAnnotationObjects(annotation, type);
- }
- }
- return null;
- }
-
- private <T> List<T> initializeAnnotationObjects(Annotation annotation,
- Class<T> type) {
- List<T> list = new ArrayList<>();
- for (String cn : getAnnotationObjectNames(annotation)) {
- list.add(initializeAnnotationObject(cn, type));
- }
- for (Class<? extends T> cn : getAnnotationObjectClasses(annotation, type)) {
- list.add(initializeAnnotationObject(cn));
- }
- return list;
- }
-
- @SuppressWarnings("unchecked")
- private <T> Class<? extends T>[] getAnnotationObjectClasses(Annotation ann, Class<T> type) { //NOPMD
- if (ann instanceof InFaultInterceptors) {
- return (Class<? extends T>[])((InFaultInterceptors)ann).classes();
- } else if (ann instanceof InInterceptors) {
- return (Class<? extends T>[])((InInterceptors)ann).classes();
- } else if (ann instanceof OutFaultInterceptors) {
- return (Class<? extends T>[])((OutFaultInterceptors)ann).classes();
- } else if (ann instanceof OutInterceptors) {
- return (Class<? extends T>[])((OutInterceptors)ann).classes();
- } else if (ann instanceof Features) {
- return (Class<? extends T>[])((Features)ann).classes();
- }
- throw new UnsupportedOperationException("Doesn't support the annotation: " + ann);
- }
-
- private String[] getAnnotationObjectNames(Annotation ann) {
- if (ann instanceof InFaultInterceptors) {
- return ((InFaultInterceptors)ann).interceptors();
- } else if (ann instanceof InInterceptors) {
- return ((InInterceptors)ann).interceptors();
- } else if (ann instanceof OutFaultInterceptors) {
- return ((OutFaultInterceptors)ann).interceptors();
- } else if (ann instanceof OutInterceptors) {
- return ((OutInterceptors)ann).interceptors();
- } else if (ann instanceof Features) {
- return ((Features)ann).features();
- }
-
- throw new UnsupportedOperationException("Doesn't support the annotation: " + ann);
- }
-
- private <T> T initializeAnnotationObject(String annObjectName, Class<T> type) {
- try {
- final Object object = ClassLoaderUtils.loadClass(annObjectName, this.getClass()).newInstance();
- return type.cast(object);
- } catch (Throwable e) {
- throw new Fault(new org.apache.cxf.common.i18n.Message(
- "COULD_NOT_CREATE_ANNOTATION_OBJECT",
- BUNDLE, annObjectName), e);
- }
- }
- private <T> T initializeAnnotationObject(Class<T> type) {
- try {
- return type.cast(type.newInstance());
- } catch (Throwable e) {
- throw new Fault(new org.apache.cxf.common.i18n.Message(
- "COULD_NOT_CREATE_ANNOTATION_OBJECT",
- BUNDLE, type.getName()), e);
- }
- }
-
- private List<Interceptor<? extends Message>> getAnnotationInterceptorList(Class<? extends Annotation> t) {
- @SuppressWarnings("rawtypes")
- List<Interceptor> i = getAnnotationObject(t, Interceptor.class);
- if (i == null) {
- return null;
- }
- List<Interceptor<? extends Message>> m = new ArrayList<>();
- for (Interceptor<?> i2 : i) {
- m.add(i2);
- }
- return m;
- }
-
- public List<Interceptor<? extends Message>> getInFaultInterceptors() {
- return getAnnotationInterceptorList(InFaultInterceptors.class);
- }
-
- public List<Interceptor<? extends Message>> getInInterceptors() {
- return getAnnotationInterceptorList(InInterceptors.class);
- }
-
- public List<Interceptor<? extends Message>> getOutFaultInterceptors() {
- return getAnnotationInterceptorList(OutFaultInterceptors.class);
- }
-
- public List<Interceptor<? extends Message>> getOutInterceptors() {
- return getAnnotationInterceptorList(OutInterceptors.class);
- }
-
- public List<Feature> getFeatures() {
- return getAnnotationObject(Features.class, Feature.class);
- }
-
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/interceptor/AttachmentInInterceptor.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/interceptor/AttachmentInInterceptor.java
deleted file mode 100644
index 0a56be1..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/interceptor/AttachmentInInterceptor.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.cxf.interceptor;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Collections;
-import java.util.List;
-import java.util.logging.Logger;
-
-import org.apache.cxf.attachment.AttachmentDeserializer;
-import org.apache.cxf.attachment.AttachmentUtil;
-import org.apache.cxf.common.logging.LogUtils;
-import org.apache.cxf.message.Message;
-import org.apache.cxf.phase.AbstractPhaseInterceptor;
-import org.apache.cxf.phase.Phase;
-
-public class AttachmentInInterceptor extends AbstractPhaseInterceptor<Message> {
-
- private static final Logger LOG = LogUtils.getL7dLogger(AttachmentInInterceptor.class);
-
- private static final List<String> TYPES = Collections.singletonList("multipart/related");
-
- public AttachmentInInterceptor() {
- super(Phase.RECEIVE);
- }
-
- public void handleMessage(Message message) {
- if (isGET(message)) {
- LOG.fine("AttachmentInInterceptor skipped in HTTP GET method");
- return;
- }
- if (message.getContent(InputStream.class) == null) {
- return;
- }
-
- String contentType = (String) message.get(Message.CONTENT_TYPE);
- if (AttachmentUtil.isTypeSupported(contentType, getSupportedTypes())) {
- AttachmentDeserializer ad = new AttachmentDeserializer(message, getSupportedTypes());
- try {
- ad.initializeAttachments();
- } catch (IOException e) {
- throw new Fault(e);
- }
- }
- }
-
- @Override
- public void handleFault(Message messageParam) {
- }
-
- protected List<String> getSupportedTypes() {
- return TYPES;
- }
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/interceptor/ClientOutFaultObserver.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/interceptor/ClientOutFaultObserver.java
deleted file mode 100644
index 341b3b0..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/interceptor/ClientOutFaultObserver.java
+++ /dev/null
@@ -1,68 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.cxf.interceptor;
-
-import java.util.Map;
-import java.util.SortedSet;
-
-import org.apache.cxf.Bus;
-import org.apache.cxf.endpoint.Client;
-import org.apache.cxf.endpoint.ClientCallback;
-import org.apache.cxf.helpers.CastUtils;
-import org.apache.cxf.message.Message;
-import org.apache.cxf.phase.Phase;
-import org.apache.cxf.phase.PhaseManager;
-
-public class ClientOutFaultObserver extends AbstractFaultChainInitiatorObserver {
-
- public ClientOutFaultObserver(Bus bus) {
- super(bus);
- }
-
- @Override
- protected SortedSet<Phase> getPhases() {
- return getBus().getExtension(PhaseManager.class).getOutPhases();
- }
-
- /**
- * override the super class method
- */
- @Override
- public void onMessage(Message m) {
- if (m.get(Message.INBOUND_MESSAGE).equals(Boolean.TRUE)) {
- //it's outbound fault observer so only take care of outbound fault
- return;
- }
- Exception ex = m.getContent(Exception.class);
- // remove callback so that it won't be invoked twice
- ClientCallback callback = m.getExchange().remove(ClientCallback.class);
-
- if (callback != null) {
- Map<String, Object> resCtx = CastUtils.cast((Map<?, ?>) m.getExchange().getOutMessage().get(
- Message.INVOCATION_CONTEXT));
- resCtx = CastUtils.cast((Map<?, ?>) resCtx.get(Client.RESPONSE_CONTEXT));
- callback.handleException(resCtx, ex);
- }
- }
-
- protected boolean isOutboundObserver() {
- return true;
- }
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/interceptor/InFaultChainInitiatorObserver.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/interceptor/InFaultChainInitiatorObserver.java
deleted file mode 100644
index fd35182..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/interceptor/InFaultChainInitiatorObserver.java
+++ /dev/null
@@ -1,84 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.cxf.interceptor;
-
-import java.util.Collection;
-import java.util.SortedSet;
-
-import org.apache.cxf.Bus;
-import org.apache.cxf.endpoint.Client;
-import org.apache.cxf.endpoint.Endpoint;
-import org.apache.cxf.helpers.CastUtils;
-import org.apache.cxf.message.Exchange;
-import org.apache.cxf.message.Message;
-import org.apache.cxf.phase.Phase;
-import org.apache.cxf.phase.PhaseInterceptorChain;
-import org.apache.cxf.phase.PhaseManager;
-
-public class InFaultChainInitiatorObserver extends AbstractFaultChainInitiatorObserver {
-
- public InFaultChainInitiatorObserver(Bus bus) {
- super(bus);
- }
-
- @Override
- protected void initializeInterceptors(Exchange ex, PhaseInterceptorChain chain) {
- Endpoint e = ex.getEndpoint();
- Client c = ex.get(Client.class);
- InterceptorProvider ip = ex.get(InterceptorProvider.class);
-
- chain.add(getBus().getInFaultInterceptors());
- if (c != null) {
- chain.add(c.getInFaultInterceptors());
- } else if (ip != null) {
- chain.add(ip.getInFaultInterceptors());
- }
- chain.add(e.getService().getInFaultInterceptors());
- chain.add(e.getInFaultInterceptors());
- chain.add(e.getBinding().getInFaultInterceptors());
- if (e.getService().getDataBinding() instanceof InterceptorProvider) {
- chain.add(((InterceptorProvider)e.getService().getDataBinding()).getInFaultInterceptors());
- }
-
- addToChain(chain, ex.getInFaultMessage());
- addToChain(chain, ex.getOutMessage());
- }
- private void addToChain(PhaseInterceptorChain chain, Message m) {
- Collection<InterceptorProvider> providers
- = CastUtils.cast((Collection<?>)m.get(Message.INTERCEPTOR_PROVIDERS));
- if (providers != null) {
- for (InterceptorProvider p : providers) {
- chain.add(p.getInFaultInterceptors());
- }
- }
- Collection<Interceptor<? extends Message>> is
- = CastUtils.cast((Collection<?>)m.get(Message.FAULT_IN_INTERCEPTORS));
- if (is != null) {
- chain.add(is);
- }
- }
-
- protected SortedSet<Phase> getPhases() {
- return getBus().getExtension(PhaseManager.class).getInPhases();
- }
-
- protected boolean isOutboundObserver() {
- return false;
- }
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/interceptor/InterceptorChain.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/interceptor/InterceptorChain.java
deleted file mode 100644
index da5deba..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/interceptor/InterceptorChain.java
+++ /dev/null
@@ -1,109 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.cxf.interceptor;
-
-import java.util.Collection;
-import java.util.ListIterator;
-
-import org.apache.cxf.message.Message;
-import org.apache.cxf.transport.MessageObserver;
-
-/**
- * Base interface for all interceptor chains. An interceptor chain is an
- * ordered list of interceptors associated with one portion of the message
- * processing pipeline. Interceptor chains are defined for a client's request
- * processing, response processing, and incoming SOAP fault processing. Interceptor
- * chains are defined for a service's request processing, response processing, and
- * outgoing SOAP fault processing.
- */
-public interface InterceptorChain extends Iterable<Interceptor<? extends Message>> {
-
- enum State {
- PAUSED,
- SUSPENDED,
- EXECUTING,
- COMPLETE,
- ABORTED,
- }
-
- String STARTING_AFTER_INTERCEPTOR_ID = "starting_after_interceptor_id";
- String STARTING_AT_INTERCEPTOR_ID = "starting_at_interceptor_id";
-
- /**
- * Adds a single interceptor to the interceptor chain.
- *
- * @param i the interceptor to add
- */
- void add(Interceptor<? extends Message> i);
-
- /**
- * Adds multiple interceptors to the interceptor chain.
- * @param i the interceptors to add to the chain
- */
- void add(Collection<Interceptor<? extends Message>> i);
-
- void remove(Interceptor<? extends Message> i);
-
- boolean doIntercept(Message message);
-
- boolean doInterceptStartingAfter(Message message, String startingAfterInterceptorID);
-
- boolean doInterceptStartingAt(Message message, String startingAtInterceptorID);
-
- /**
- * Pauses the current chain. When the stack unwinds, the chain will just
- * return from the doIntercept method normally.
- */
- void pause();
-
- /**
- * Suspends the current chain. When the stack unwinds, the chain back up
- * the iterator by one (so on resume, the interceptor that called pause will
- * be re-entered) and then throw a SuspendedInvocationException to the caller
- */
- void suspend();
-
- /**
- * Resumes the chain. The chain will use the current thread to continue processing
- * the last message that was passed into doIntercept
- */
- void resume();
-
- /**
- * If the chain is marked as paused, this will JUST mark the chain as
- * in the EXECUTING phase. This is useful if an interceptor pauses the chain,
- * but then immediately decides it should not have done that. It can unpause
- * the chain and return normally and the normal processing will continue.
- */
- void unpause();
-
-
- void reset();
-
- State getState();
-
- ListIterator<Interceptor<? extends Message>> getIterator();
-
- MessageObserver getFaultObserver();
-
- void setFaultObserver(MessageObserver i);
-
- void abort();
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/interceptor/LoggingMessage.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/interceptor/LoggingMessage.java
deleted file mode 100644
index 661e3db..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/interceptor/LoggingMessage.java
+++ /dev/null
@@ -1,133 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.cxf.interceptor;
-
-import java.util.concurrent.atomic.AtomicInteger;
-
-/**
- * @deprecated use the logging module rt/features/logging instead
- */
-@Deprecated
-public final class LoggingMessage {
- public static final String ID_KEY = LoggingMessage.class.getName() + ".ID";
- private static final AtomicInteger ID = new AtomicInteger();
-
- private final String heading;
- private final StringBuilder address;
- private final StringBuilder contentType;
- private final StringBuilder encoding;
- private final StringBuilder httpMethod;
- private final StringBuilder header;
- private final StringBuilder message;
- private final StringBuilder payload;
- private final StringBuilder responseCode;
- private final String id;
-
-
- public LoggingMessage(String h, String i) {
- heading = h;
- id = i;
-
- contentType = new StringBuilder();
- address = new StringBuilder();
- encoding = new StringBuilder();
- httpMethod = new StringBuilder();
- header = new StringBuilder();
- message = new StringBuilder();
- payload = new StringBuilder();
- responseCode = new StringBuilder();
- }
-
- public String getId() {
- return id;
- }
-
- public static String nextId() {
- return Integer.toString(ID.incrementAndGet());
- }
-
-
- public StringBuilder getAddress() {
- return address;
- }
-
- public StringBuilder getEncoding() {
- return encoding;
- }
-
- public StringBuilder getHeader() {
- return header;
- }
-
- public StringBuilder getHttpMethod() {
- return httpMethod;
- }
-
- public StringBuilder getContentType() {
- return contentType;
- }
-
- public StringBuilder getMessage() {
- return message;
- }
-
- public StringBuilder getPayload() {
- return payload;
- }
-
- public StringBuilder getResponseCode() {
- return responseCode;
- }
-
- public String toString() {
- StringBuilder buffer = new StringBuilder(128);
- buffer.append(heading);
- buffer.append("\nID: ").append(id);
- if (address.length() > 0) {
- buffer.append("\nAddress: ");
- buffer.append(address);
- }
- if (responseCode.length() > 0) {
- buffer.append("\nResponse-Code: ");
- buffer.append(responseCode);
- }
- if (encoding.length() > 0) {
- buffer.append("\nEncoding: ");
- buffer.append(encoding);
- }
- if (httpMethod.length() > 0) {
- buffer.append("\nHttp-Method: ");
- buffer.append(httpMethod);
- }
- buffer.append("\nContent-Type: ");
- buffer.append(contentType);
- buffer.append("\nHeaders: ");
- buffer.append(header);
- if (message.length() > 0) {
- buffer.append("\nMessages: ");
- buffer.append(message);
- }
- if (payload.length() > 0) {
- buffer.append("\nPayload: ");
- buffer.append(payload);
- }
- buffer.append("\n--------------------------------------");
- return buffer.toString();
- }
-}
\ No newline at end of file
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/interceptor/OneWayProcessorInterceptor.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/interceptor/OneWayProcessorInterceptor.java
deleted file mode 100644
index b140601..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/interceptor/OneWayProcessorInterceptor.java
+++ /dev/null
@@ -1,177 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.cxf.interceptor;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.concurrent.Executor;
-import java.util.concurrent.RejectedExecutionException;
-import java.util.logging.Logger;
-
-import org.apache.cxf.common.logging.LogUtils;
-import org.apache.cxf.endpoint.Endpoint;
-import org.apache.cxf.io.DelegatingInputStream;
-import org.apache.cxf.message.Exchange;
-import org.apache.cxf.message.Message;
-import org.apache.cxf.message.MessageImpl;
-import org.apache.cxf.message.MessageUtils;
-import org.apache.cxf.phase.AbstractPhaseInterceptor;
-import org.apache.cxf.phase.Phase;
-import org.apache.cxf.transport.Conduit;
-import org.apache.cxf.workqueue.WorkQueueManager;
-
-
-/**
- *
- */
-public class OneWayProcessorInterceptor extends AbstractPhaseInterceptor<Message> {
- public static final String USE_ORIGINAL_THREAD
- = OneWayProcessorInterceptor.class.getName() + ".USE_ORIGINAL_THREAD";
- private static final Logger LOG = LogUtils.getL7dLogger(OneWayProcessorInterceptor.class);
-
- public OneWayProcessorInterceptor() {
- super(Phase.PRE_LOGICAL);
- }
- public OneWayProcessorInterceptor(String phase) {
- super(phase);
- }
-
- @Override
- public void handleFault(Message message) {
- if (message.getExchange().isOneWay()
- && !isRequestor(message)) {
- //in a one way, if an exception is thrown, the stream needs to be closed
- InputStream in = message.getContent(InputStream.class);
- if (in != null) {
- try {
- in.close();
- } catch (IOException e) {
- //ignore
- }
- }
-
- }
- }
- public void handleMessage(Message message) {
-
- if (message.getExchange().isOneWay()
- && !isRequestor(message)
- && message.get(OneWayProcessorInterceptor.class) == null
- && message.getExchange().get(Executor.class) == null) {
- //one way on server side, fork the rest of this chain onto the
- //workqueue, call the Outgoing chain directly.
-
- message.put(OneWayProcessorInterceptor.class, this);
- final InterceptorChain chain = message.getInterceptorChain();
-
- boolean robust =
- MessageUtils.getContextualBoolean(message, Message.ROBUST_ONEWAY, false);
-
- boolean useOriginalThread =
- MessageUtils.getContextualBoolean(message, USE_ORIGINAL_THREAD, false);
-
- if (!useOriginalThread && !robust) {
- //need to suck in all the data from the input stream as
- //the transport might discard any data on the stream when this
- //thread unwinds or when the empty response is sent back
- DelegatingInputStream in = message.getContent(DelegatingInputStream.class);
- if (in != null) {
- in.cacheInput();
- }
- }
-
- if (robust) {
- // continue to invoke the chain
- chain.pause();
- chain.resume();
- if (message.getContent(Exception.class) != null) {
- // CXF-5629 fault has been delivered alread in resume()
- return;
- }
- }
-
- try {
- Message partial = createMessage(message.getExchange());
- partial.remove(Message.CONTENT_TYPE);
- partial.setExchange(message.getExchange());
- Conduit conduit = message.getExchange().getDestination()
- .getBackChannel(message);
- if (conduit != null) {
- message.getExchange().setInMessage(null);
- //for a one-way, the back channel could be
- //null if it knows it cannot send anything.
- conduit.prepare(partial);
- conduit.close(partial);
- message.getExchange().setInMessage(message);
- }
- } catch (IOException e) {
- //IGNORE
- }
-
- if (!useOriginalThread && !robust) {
- chain.pause();
- try {
- final Object lock = new Object();
- synchronized (lock) {
- message.getExchange().getBus().getExtension(WorkQueueManager.class)
- .getAutomaticWorkQueue().execute(new Runnable() {
- public void run() {
- synchronized (lock) {
- lock.notifyAll();
- }
- chain.resume();
- }
- });
- //wait a few milliseconds for the background thread to start processing
- //Mostly just to make an attempt at keeping the ordering of the
- //messages coming in from a client. Not guaranteed though.
- lock.wait(20L);
- }
- } catch (RejectedExecutionException e) {
- LOG.warning(
- "Executor queue is full, run the oneway invocation task in caller thread."
- + " Users can specify a larger executor queue to avoid this.");
- // only block the thread if the prop is unset or set to false, otherwise let it go
- if (!MessageUtils.getContextualBoolean(message,
- "org.apache.cxf.oneway.rejected_execution_exception", false)) {
- //the executor queue is full, so run the task in the caller thread
- chain.unpause();
- }
-
- } catch (InterruptedException e) {
- //ignore - likely a busy work queue so we'll just let the one-way go
- }
- }
- }
- }
-
- private static Message createMessage(Exchange exchange) {
- Endpoint ep = exchange.getEndpoint();
- Message msg = null;
- if (ep != null) {
- msg = new MessageImpl();
- msg.setExchange(exchange);
- msg = ep.getBinding().createMessage(msg);
- }
- return msg;
- }
-
-
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/interceptor/OutFaultChainInitiatorObserver.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/interceptor/OutFaultChainInitiatorObserver.java
deleted file mode 100644
index a00e403..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/interceptor/OutFaultChainInitiatorObserver.java
+++ /dev/null
@@ -1,84 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.cxf.interceptor;
-
-import java.util.Collection;
-import java.util.SortedSet;
-
-import org.apache.cxf.Bus;
-import org.apache.cxf.endpoint.Client;
-import org.apache.cxf.endpoint.Endpoint;
-import org.apache.cxf.helpers.CastUtils;
-import org.apache.cxf.message.Exchange;
-import org.apache.cxf.message.Message;
-import org.apache.cxf.phase.Phase;
-import org.apache.cxf.phase.PhaseInterceptorChain;
-import org.apache.cxf.phase.PhaseManager;
-
-public class OutFaultChainInitiatorObserver extends AbstractFaultChainInitiatorObserver {
-
- public OutFaultChainInitiatorObserver(Bus bus) {
- super(bus);
- }
-
- @Override
- protected void initializeInterceptors(Exchange ex, PhaseInterceptorChain chain) {
- Endpoint e = ex.getEndpoint();
- Client c = ex.get(Client.class);
-
- chain.add(getBus().getOutFaultInterceptors());
- if (c != null) {
- chain.add(c.getOutFaultInterceptors());
- }
- chain.add(e.getService().getOutFaultInterceptors());
- chain.add(e.getOutFaultInterceptors());
- chain.add(e.getBinding().getOutFaultInterceptors());
- if (e.getService().getDataBinding() instanceof InterceptorProvider) {
- chain.add(((InterceptorProvider)e.getService().getDataBinding()).getOutFaultInterceptors());
- }
-
- addToChain(chain, ex.getInMessage());
- addToChain(chain, ex.getOutFaultMessage());
- }
- private void addToChain(PhaseInterceptorChain chain, Message m) {
- Collection<InterceptorProvider> providers
- = CastUtils.cast((Collection<?>)m.get(Message.INTERCEPTOR_PROVIDERS));
- if (providers != null) {
- for (InterceptorProvider p : providers) {
- chain.add(p.getOutFaultInterceptors());
- }
- }
- Collection<Interceptor<? extends Message>> is
- = CastUtils.cast((Collection<?>)m.get(Message.FAULT_OUT_INTERCEPTORS));
- if (is != null) {
- chain.add(is);
- }
- if (m.getDestination() instanceof InterceptorProvider) {
- chain.add(((InterceptorProvider)m.getDestination()).getOutFaultInterceptors());
- }
- }
-
- protected SortedSet<Phase> getPhases() {
- return getBus().getExtension(PhaseManager.class).getOutPhases();
- }
-
- protected boolean isOutboundObserver() {
- return true;
- }
-}
\ No newline at end of file
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/interceptor/security/DefaultSecurityContext.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/interceptor/security/DefaultSecurityContext.java
deleted file mode 100644
index 9b712f3..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/interceptor/security/DefaultSecurityContext.java
+++ /dev/null
@@ -1,188 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.cxf.interceptor.security;
-
-
-import java.lang.reflect.Method;
-import java.security.Principal;
-import java.util.Enumeration;
-import java.util.HashSet;
-import java.util.Set;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import javax.security.auth.Subject;
-
-import org.apache.cxf.common.logging.LogUtils;
-import org.apache.cxf.common.security.GroupPrincipal;
-import org.apache.cxf.common.util.ReflectionUtil;
-import org.apache.cxf.security.LoginSecurityContext;
-
-/**
- * SecurityContext which implements isUserInRole using the
- * following approach : skip the first Subject principal, and then checks
- * Groups the principal is a member of
- */
-public class DefaultSecurityContext implements LoginSecurityContext {
- private static final Logger LOG = LogUtils.getL7dLogger(DefaultSecurityContext.class);
- private static Class<?> javaGroup;
- private static Class<?> karafGroup;
-
- private Principal p;
- private Subject subject;
-
- static {
- try {
- javaGroup = Class.forName("java.security.acl.Group");
- } catch (Exception e) {
- javaGroup = null;
- }
- try {
- karafGroup = Class.forName("org.apache.karaf.jaas.boot.principal.Group");
- } catch (Exception e) {
- karafGroup = null;
- }
- }
-
- public DefaultSecurityContext(Subject subject) {
- this.p = findPrincipal(null, subject);
- this.subject = subject;
- }
-
- public DefaultSecurityContext(String principalName, Subject subject) {
- this.p = findPrincipal(principalName, subject);
- this.subject = subject;
- }
-
- public DefaultSecurityContext(Principal p, Subject subject) {
- this.p = p;
- this.subject = subject;
- if (p == null) {
- this.p = findPrincipal(null, subject);
- }
- }
-
- private static Principal findPrincipal(String principalName, Subject subject) {
- if (subject == null) {
- return null;
- }
-
- for (Principal principal : subject.getPrincipals()) {
- if (!isGroupPrincipal(principal)
- && (principalName == null || principal.getName().equals(principalName))) {
- return principal;
- }
- }
-
- // No match for the principalName. Just return first non-Group Principal
- if (principalName != null) {
- for (Principal principal : subject.getPrincipals()) {
- if (!isGroupPrincipal(principal)) {
- return principal;
- }
- }
- }
-
- return null;
- }
-
- public Principal getUserPrincipal() {
- return p;
- }
-
- public boolean isUserInRole(String role) {
- if (subject != null) {
- for (Principal principal : subject.getPrincipals()) {
- if (isGroupPrincipal(principal)
- && checkGroup(principal, role)) {
- return true;
- } else if (p != principal
- && role.equals(principal.getName())) {
- return true;
- }
- }
- }
- return false;
- }
-
-
- protected boolean checkGroup(Principal principal, String role) {
- if (principal.getName().equals(role)) {
- return true;
- }
-
- Enumeration<? extends Principal> members;
- try {
- Method m = ReflectionUtil.getMethod(principal.getClass(), "members");
- m.setAccessible(true);
- @SuppressWarnings("unchecked")
- Enumeration<? extends Principal> ms = (Enumeration<? extends Principal>)m.invoke(principal);
- members = ms;
- } catch (Exception e) {
- if (LOG.isLoggable(Level.FINE)) {
- LOG.fine("Unable to invoke memebers in " + principal.getName() + ":" + e.getMessage());
- }
- return false;
- }
-
- while (members.hasMoreElements()) {
- // this might be a plain role but could represent a group consisting of other groups/roles
- Principal member = members.nextElement();
- if (member.getName().equals(role)
- || isGroupPrincipal(member)
- && checkGroup((GroupPrincipal)member, role)) {
- return true;
- }
- }
- return false;
- }
-
-
- public Subject getSubject() {
- return subject;
- }
-
- public Set<Principal> getUserRoles() {
- Set<Principal> roles = new HashSet<>();
- if (subject != null) {
- for (Principal principal : subject.getPrincipals()) {
- if (principal != p) {
- roles.add(principal);
- }
- }
- }
- return roles;
- }
-
-
- private static boolean instanceOfGroup(Object obj) {
- try {
- return (javaGroup != null && javaGroup.isInstance(obj))
- || (karafGroup != null && karafGroup.isInstance(obj));
- } catch (Exception ex) {
- return false;
- }
- }
-
- public static boolean isGroupPrincipal(Principal principal) {
- return principal instanceof GroupPrincipal
- || instanceOfGroup(principal);
- }
-
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/interceptor/security/JAASLoginInterceptor.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/interceptor/security/JAASLoginInterceptor.java
deleted file mode 100644
index 3363c20..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/interceptor/security/JAASLoginInterceptor.java
+++ /dev/null
@@ -1,233 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.cxf.interceptor.security;
-
-import java.security.PrivilegedAction;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import javax.security.auth.Subject;
-import javax.security.auth.callback.Callback;
-import javax.security.auth.callback.CallbackHandler;
-import javax.security.auth.callback.NameCallback;
-import javax.security.auth.login.Configuration;
-import javax.security.auth.login.LoginContext;
-import javax.security.auth.login.LoginException;
-
-import org.apache.cxf.common.logging.LogUtils;
-import org.apache.cxf.interceptor.InterceptorChain;
-import org.apache.cxf.interceptor.security.callback.CallbackHandlerProvider;
-import org.apache.cxf.interceptor.security.callback.CallbackHandlerProviderAuthPol;
-import org.apache.cxf.interceptor.security.callback.CallbackHandlerProviderUsernameToken;
-import org.apache.cxf.message.Message;
-import org.apache.cxf.phase.AbstractPhaseInterceptor;
-import org.apache.cxf.phase.Phase;
-import org.apache.cxf.security.SecurityContext;
-
-public class JAASLoginInterceptor extends AbstractPhaseInterceptor<Message> {
- public static final String ROLE_CLASSIFIER_PREFIX = "prefix";
- public static final String ROLE_CLASSIFIER_CLASS_NAME = "classname";
-
- private static final Logger LOG = LogUtils.getL7dLogger(JAASLoginInterceptor.class);
-
- private String contextName = "";
- private Configuration loginConfig;
- private String roleClassifier;
- private String roleClassifierType = ROLE_CLASSIFIER_PREFIX;
- private boolean reportFault;
- private boolean useDoAs = true;
- private List<CallbackHandlerProvider> callbackHandlerProviders;
- private boolean allowAnonymous = true;
- private boolean allowNamedPrincipals;
-
- public JAASLoginInterceptor() {
- this(Phase.UNMARSHAL);
- }
-
- public JAASLoginInterceptor(String phase) {
- super(phase);
- this.callbackHandlerProviders = new ArrayList<>();
- this.callbackHandlerProviders.add(new CallbackHandlerProviderAuthPol());
- this.callbackHandlerProviders.add(new CallbackHandlerProviderUsernameToken());
- }
-
- public void setContextName(String name) {
- contextName = name;
- }
-
- public String getContextName() {
- return contextName;
- }
-
- /**
- * @deprecated replaced by {@link #setRoleClassifier(String)}
- * @param name
- */
- @Deprecated
- public void setRolePrefix(String name) {
- setRoleClassifier(name);
- }
-
- public void setRoleClassifier(String value) {
- roleClassifier = value;
- }
-
- public String getRoleClassifier() {
- return roleClassifier;
- }
-
- public void setRoleClassifierType(String value) {
- if (!ROLE_CLASSIFIER_PREFIX.equals(value)
- && !ROLE_CLASSIFIER_CLASS_NAME.equals(value)) {
- throw new IllegalArgumentException("Unsupported role classifier");
- }
- roleClassifierType = value;
- }
-
- public String getRoleClassifierType() {
- return roleClassifierType;
- }
-
- public void setReportFault(boolean reportFault) {
- this.reportFault = reportFault;
- }
-
- public void setUseDoAs(boolean useDoAs) {
- this.useDoAs = useDoAs;
- }
-
- private CallbackHandler getFirstCallbackHandler(Message message) {
- for (CallbackHandlerProvider cbp : callbackHandlerProviders) {
- CallbackHandler cbh = cbp.create(message);
- if (cbh != null) {
- return cbh;
- }
- }
- return null;
- }
-
- public void handleMessage(final Message message) {
- if (allowNamedPrincipals) {
- SecurityContext sc = message.get(SecurityContext.class);
- if (sc != null && sc.getUserPrincipal() != null
- && sc.getUserPrincipal().getName() != null) {
- return;
- }
- }
-
- CallbackHandler handler = getFirstCallbackHandler(message);
-
- if (handler == null && !allowAnonymous) {
- throw new AuthenticationException("Authentication required but no authentication information was supplied");
- }
-
- try {
- LoginContext ctx = new LoginContext(getContextName(), null, handler, loginConfig);
- ctx.login();
- Subject subject = ctx.getSubject();
- String name = getUsername(handler);
- message.put(SecurityContext.class, createSecurityContext(name, subject));
-
- // Run the further chain in the context of this subject.
- // This allows other code to retrieve the subject using pure JAAS
- if (useDoAs) {
- Subject.doAs(subject, new PrivilegedAction<Void>() {
-
- @Override
- public Void run() {
- InterceptorChain chain = message.getInterceptorChain();
- if (chain != null) {
- message.put("suspend.chain.on.current.interceptor", Boolean.TRUE);
- chain.doIntercept(message);
- }
- return null;
- }
- });
- }
-
- } catch (LoginException ex) {
- String errorMessage = "Authentication failed: " + ex.getMessage();
- LOG.log(Level.FINE, errorMessage, ex);
- if (reportFault) {
- AuthenticationException aex = new AuthenticationException(errorMessage);
- aex.initCause(ex);
- throw aex;
-
- }
- throw new AuthenticationException("Authentication failed (details can be found in server log)");
- }
- }
-
- private String getUsername(CallbackHandler handler) {
- if (handler == null) {
- return null;
- }
- try {
- NameCallback usernameCallBack = new NameCallback("user");
- handler.handle(new Callback[]{usernameCallBack });
- return usernameCallBack.getName();
- } catch (Exception e) {
- return null;
- }
- }
-
- protected CallbackHandler getCallbackHandler(String name, String password) {
- return new NamePasswordCallbackHandler(name, password);
- }
-
- protected SecurityContext createSecurityContext(String name, Subject subject) {
- if (getRoleClassifier() != null) {
- return new RolePrefixSecurityContextImpl(subject, getRoleClassifier(),
- getRoleClassifierType());
- }
- return new DefaultSecurityContext(name, subject);
- }
-
- public Configuration getLoginConfig() {
- return loginConfig;
- }
-
- public void setLoginConfig(Configuration loginConfig) {
- this.loginConfig = loginConfig;
- }
-
- public List<CallbackHandlerProvider> getCallbackHandlerProviders() {
- return callbackHandlerProviders;
- }
-
- public void setCallbackHandlerProviders(List<CallbackHandlerProvider> callbackHandlerProviders) {
- this.callbackHandlerProviders.clear();
- this.callbackHandlerProviders.addAll(callbackHandlerProviders);
- }
-
- public void addCallbackHandlerProviders(List<CallbackHandlerProvider> callbackHandlerProviders2) {
- this.callbackHandlerProviders.addAll(callbackHandlerProviders2);
- }
-
- public void setAllowAnonymous(boolean allowAnonymous) {
- this.allowAnonymous = allowAnonymous;
- }
-
- public void setAllowNamedPrincipals(boolean allowNamedPrincipals) {
- this.allowNamedPrincipals = allowNamedPrincipals;
- }
-
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/internal/CXFAPINamespaceHandler.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/internal/CXFAPINamespaceHandler.java
deleted file mode 100644
index e3d432d..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/internal/CXFAPINamespaceHandler.java
+++ /dev/null
@@ -1,127 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.cxf.internal;
-
-import java.net.URL;
-import java.util.Set;
-
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-
-import org.apache.aries.blueprint.NamespaceHandler;
-import org.apache.aries.blueprint.Namespaces;
-import org.apache.aries.blueprint.ParserContext;
-import org.apache.aries.blueprint.mutable.MutableBeanMetadata;
-import org.apache.cxf.bus.blueprint.BusDefinitionParser;
-import org.apache.cxf.configuration.blueprint.SimpleBPBeanDefinitionParser;
-import org.apache.cxf.feature.FastInfosetFeature;
-import org.apache.cxf.workqueue.AutomaticWorkQueueImpl;
-import org.osgi.service.blueprint.reflect.ComponentMetadata;
-import org.osgi.service.blueprint.reflect.Metadata;
-
-@Namespaces({"http://cxf.apache.org/blueprint/core",
- "http://cxf.apache.org/configuration/beans",
- "http://cxf.apache.org/configuration/parameterized-types",
- "http://cxf.apache.org/configuration/security",
- "http://schemas.xmlsoap.org/wsdl/",
- "http://www.w3.org/2005/08/addressing",
- "http://schemas.xmlsoap.org/ws/2004/08/addressing"})
-public class CXFAPINamespaceHandler implements NamespaceHandler {
-
- public URL getSchemaLocation(String namespace) {
- String location = null;
-
- // when schema is being resolved for custom namespace elements, "namespace" is real namespace
- // (from xmlns:prefix="<namespace>"
- // but when namespace is <xsd:import>ed, aries/xerces uses systemID (schemaLocation)
-
- if ("http://cxf.apache.org/configuration/beans".equals(namespace)
- || "http://cxf.apache.org/schemas/configuration/cxf-beans.xsd".equals(namespace)) {
- location = "schemas/configuration/cxf-beans.xsd";
- } else if ("http://cxf.apache.org/configuration/parameterized-types".equals(namespace)
- || "http://cxf.apache.org/schemas/configuration/parameterized-types.xsd".equals(namespace)) {
- location = "schemas/configuration/parameterized-types.xsd";
- } else if ("http://cxf.apache.org/configuration/security".equals(namespace)
- || "http://cxf.apache.org/schemas/configuration/security.xsd".equals(namespace)) {
- location = "schemas/configuration/security.xsd";
- } else if ("http://schemas.xmlsoap.org/wsdl/".equals(namespace)
- || "http://schemas.xmlsoap.org/wsdl/2003-02-11.xsd".equals(namespace)) {
- location = "schemas/wsdl/wsdl.xsd";
- } else if ("http://www.w3.org/2005/08/addressing".equals(namespace)
- || "http://www.w3.org/2006/03/addressing/ws-addr.xsd".equals(namespace)) {
- location = "schemas/wsdl/ws-addr.xsd";
- } else if ("http://schemas.xmlsoap.org/ws/2004/08/addressing".equals(namespace)) {
- location = "schemas/wsdl/addressing.xsd";
- } else if ("http://cxf.apache.org/blueprint/core".equals(namespace)) {
- location = "schemas/blueprint/core.xsd";
- }
- if (location != null) {
- return getClass().getClassLoader().getResource(location);
- }
- return null;
- }
-
-
- @SuppressWarnings("deprecation")
- public Metadata parse(Element element, ParserContext context) {
- String s = element.getLocalName();
- if ("bus".equals(s)) {
- //parse bus
- return new BusDefinitionParser().parse(element, context);
- } else if ("logging".equals(s)) {
- //logging feature
- return new SimpleBPBeanDefinitionParser(org.apache.cxf.feature.LoggingFeature.class)
- .parse(element, context);
- } else if ("fastinfoset".equals(s)) {
- //fastinfosetfeature
- return new SimpleBPBeanDefinitionParser(FastInfosetFeature.class).parse(element, context);
- } else if ("workqueue".equals(s)) {
- return new SimpleBPBeanDefinitionParser(AutomaticWorkQueueImpl.class) {
-
- @Override
- public String getId(Element element, ParserContext context) {
- String id = element.hasAttribute("id") ? element.getAttribute("id") : null;
- if (id == null) {
- id = "cxf.workqueue.";
- id += element.hasAttribute("name") ? element.getAttribute("name") : "def";
- }
- return id;
- }
-
- @Override
- protected void processNameAttribute(Element element, ParserContext ctx,
- MutableBeanMetadata bean, String val) {
- bean.addProperty("name", createValue(ctx, val));
- }
- } .parse(element, context);
- }
- return null;
- }
-
- @SuppressWarnings("rawtypes")
- public Set<Class> getManagedClasses() {
- //probably should have the various stuff in cxf-api in here?
- return null;
- }
- public ComponentMetadata decorate(Node node, ComponentMetadata component, ParserContext context) {
- return null;
- }
-
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/io/CacheAndWriteOutputStream.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/io/CacheAndWriteOutputStream.java
deleted file mode 100644
index d89edb9..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/io/CacheAndWriteOutputStream.java
+++ /dev/null
@@ -1,96 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.cxf.io;
-
-import java.io.IOException;
-import java.io.OutputStream;
-
-/**
- * This outputstream implementation will both write to the outputstream
- * that is specified and cache the data at the same time. This allows us
- * to go back and retransmit the data at a later time if necessary.
- *
- */
-public class CacheAndWriteOutputStream extends CachedOutputStream {
- OutputStream flowThroughStream;
- long count;
- long limit = Long.MAX_VALUE;
- private boolean isClosed;
-
- public CacheAndWriteOutputStream(OutputStream stream) {
- super();
- if (stream == null) {
- throw new IllegalArgumentException("Stream may not be null");
- }
- flowThroughStream = stream;
- }
-
- public void setCacheLimit(long l) {
- limit = l;
- }
-
- public void closeFlowthroughStream() throws IOException {
- postClose();
- }
-
- protected void postClose() throws IOException {
- if (!isClosed) {
- flowThroughStream.flush();
- flowThroughStream.close();
- isClosed = true;
- }
- }
-
- public OutputStream getFlowThroughStream() {
- return flowThroughStream;
- }
-
- @Override
- protected void onWrite() throws IOException {
- // does nothing
- }
-
- @Override
- public void write(int b) throws IOException {
- flowThroughStream.write(b);
- if (count <= limit) {
- super.write(b);
- }
- count++;
- }
-
- @Override
- public void write(byte[] b, int off, int len) throws IOException {
- flowThroughStream.write(b, off, len);
- if (count <= limit) {
- super.write(b, off, len);
- }
- count += len;
- }
-
- @Override
- public void write(byte[] b) throws IOException {
- flowThroughStream.write(b);
- if (count <= limit) {
- super.write(b);
- }
- count += b.length;
- }
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/io/CachedWriter.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/io/CachedWriter.java
deleted file mode 100644
index 0178563..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/io/CachedWriter.java
+++ /dev/null
@@ -1,665 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.cxf.io;
-
-import java.io.BufferedOutputStream;
-import java.io.CharArrayReader;
-import java.io.CharArrayWriter;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.OutputStream;
-import java.io.OutputStreamWriter;
-import java.io.Reader;
-import java.io.Writer;
-import java.nio.charset.StandardCharsets;
-import java.nio.file.Files;
-import java.security.GeneralSecurityException;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-
-import javax.crypto.CipherInputStream;
-import javax.crypto.CipherOutputStream;
-
-import org.apache.cxf.Bus;
-import org.apache.cxf.BusFactory;
-import org.apache.cxf.common.util.SystemPropertyAction;
-import org.apache.cxf.helpers.FileUtils;
-import org.apache.cxf.helpers.IOUtils;
-
-import static java.nio.charset.StandardCharsets.UTF_8;
-
-public class CachedWriter extends Writer {
- private static final File DEFAULT_TEMP_DIR;
- private static int defaultThreshold;
- private static long defaultMaxSize;
- private static String defaultCipherTransformation;
-
- static {
-
- String s = SystemPropertyAction.getPropertyOrNull(CachedConstants.OUTPUT_DIRECTORY_SYS_PROP);
- if (s == null) {
- // lookup the deprecated property
- s = SystemPropertyAction.getPropertyOrNull("org.apache.cxf.io.CachedWriter.OutputDirectory");
- }
- if (s != null) {
- File f = new File(s);
- if (f.exists() && f.isDirectory()) {
- DEFAULT_TEMP_DIR = f;
- } else {
- DEFAULT_TEMP_DIR = null;
- }
- } else {
- DEFAULT_TEMP_DIR = null;
- }
-
- setDefaultThreshold(-1);
- setDefaultMaxSize(-1);
- setDefaultCipherTransformation(null);
- }
-
- protected boolean outputLocked;
- protected Writer currentStream;
-
- private boolean cosClosed;
- private long threshold = defaultThreshold;
- private long maxSize = defaultMaxSize;
- private File outputDir = DEFAULT_TEMP_DIR;
- private String cipherTransformation = defaultCipherTransformation;
-
- private long totalLength;
-
- private boolean inmem;
-
- private boolean tempFileFailed;
- private File tempFile;
- private boolean allowDeleteOfFile = true;
- private CipherPair ciphers;
-
- private List<CachedWriterCallback> callbacks;
-
- private List<Object> streamList = new ArrayList<>();
-
-
- static class LoadingCharArrayWriter extends CharArrayWriter {
- LoadingCharArrayWriter() {
- super(1024);
- }
- public char[] rawCharArray() {
- return super.buf;
- }
- }
-
-
- public CachedWriter() {
- this(defaultThreshold);
-
- inmem = true;
- }
-
- public CachedWriter(long threshold) {
- this.threshold = threshold;
- currentStream = new LoadingCharArrayWriter();
- inmem = true;
- readBusProperties();
- }
-
- private void readBusProperties() {
- Bus b = BusFactory.getThreadDefaultBus(false);
- if (b != null) {
- String v = getBusProperty(b, CachedConstants.THRESHOLD_BUS_PROP, null);
- if (v != null && threshold == defaultThreshold) {
- threshold = Integer.parseInt(v);
- }
- v = getBusProperty(b, CachedConstants.MAX_SIZE_BUS_PROP, null);
- if (v != null) {
- maxSize = Integer.parseInt(v);
- }
- v = getBusProperty(b, CachedConstants.CIPHER_TRANSFORMATION_BUS_PROP, null);
- if (v != null) {
- cipherTransformation = v;
- }
- v = getBusProperty(b, CachedConstants.OUTPUT_DIRECTORY_BUS_PROP, null);
- if (v != null) {
- File f = new File(v);
- if (f.exists() && f.isDirectory()) {
- outputDir = f;
- }
- }
- }
- }
-
- private static String getBusProperty(Bus b, String key, String dflt) {
- String v = (String)b.getProperty(key);
- return v != null ? v : dflt;
- }
-
- public void holdTempFile() {
- allowDeleteOfFile = false;
- }
- public void releaseTempFileHold() {
- allowDeleteOfFile = true;
- }
-
- public void registerCallback(CachedWriterCallback cb) {
- if (null == callbacks) {
- callbacks = new ArrayList<>();
- }
- callbacks.add(cb);
- }
-
- public void deregisterCallback(CachedWriterCallback cb) {
- if (null != callbacks) {
- callbacks.remove(cb);
- }
- }
-
- public List<CachedWriterCallback> getCallbacks() {
- return callbacks == null ? null : Collections.unmodifiableList(callbacks);
- }
-
- /**
- * Perform any actions required on stream flush (freeze headers, reset
- * output stream ... etc.)
- */
- protected void doFlush() throws IOException {
-
- }
-
- public void flush() throws IOException {
- if (!cosClosed) {
- currentStream.flush();
- }
-
- if (null != callbacks) {
- for (CachedWriterCallback cb : callbacks) {
- cb.onFlush(this);
- }
- }
- doFlush();
- }
-
- /**
- * Perform any actions required on stream closure (handle response etc.)
- */
- protected void doClose() throws IOException {
-
- }
-
- /**
- * Perform any actions required after stream closure (close the other related stream etc.)
- */
- protected void postClose() throws IOException {
-
- }
-
- /**
- * Locks the output stream to prevent additional writes, but maintains
- * a pointer to it so an InputStream can be obtained
- * @throws IOException
- */
- public void lockOutputStream() throws IOException {
- if (outputLocked) {
- return;
- }
- currentStream.flush();
- outputLocked = true;
- if (null != callbacks) {
- for (CachedWriterCallback cb : callbacks) {
- cb.onClose(this);
- }
- }
- doClose();
- streamList.remove(currentStream);
- }
-
- public void close() throws IOException {
- if (!cosClosed) {
- currentStream.flush();
- }
- outputLocked = true;
- if (null != callbacks) {
- for (CachedWriterCallback cb : callbacks) {
- cb.onClose(this);
- }
- }
- doClose();
- currentStream.close();
- maybeDeleteTempFile(currentStream);
- if (ciphers != null) {
- ciphers.clean();
- }
- postClose();
- }
-
- public boolean equals(Object obj) {
- if (obj == this) {
- return true;
- }
- if (obj instanceof CachedWriter) {
- return currentStream.equals(((CachedWriter)obj).currentStream);
- }
- return currentStream.equals(obj);
- }
-
- /**
- * Replace the original stream with the new one, optionally copying the content of the old one
- * into the new one.
- * When with Attachment, needs to replace the xml writer stream with the stream used by
- * AttachmentSerializer or copy the cached output stream to the "real"
- * output stream, i.e. onto the wire.
- *
- * @param out the new output stream
- * @param copyOldContent flag indicating if the old content should be copied
- * @throws IOException
- */
- public void resetOut(Writer out, boolean copyOldContent) throws IOException {
- if (out == null) {
- out = new LoadingCharArrayWriter();
- }
-
- if (currentStream instanceof CachedWriter) {
- CachedWriter ac = (CachedWriter) currentStream;
- Reader in = ac.getReader();
- IOUtils.copyAndCloseInput(in, out);
- } else {
- if (inmem) {
- if (currentStream instanceof LoadingCharArrayWriter) {
- LoadingCharArrayWriter byteOut = (LoadingCharArrayWriter) currentStream;
- if (copyOldContent && byteOut.size() > 0) {
- byteOut.writeTo(out);
- }
- } else {
- throw new IOException("Unknown format of currentStream");
- }
- } else {
- // read the file
- currentStream.close();
- if (copyOldContent) {
- InputStreamReader fin = createInputStreamReader(tempFile);
- IOUtils.copyAndCloseInput(fin, out);
- }
- streamList.remove(currentStream);
- deleteTempFile();
- inmem = true;
- }
- }
- currentStream = out;
- outputLocked = false;
- }
-
-
- public long size() {
- return totalLength;
- }
-
- public char[] getChars() throws IOException {
- flush();
- if (inmem) {
- if (currentStream instanceof LoadingCharArrayWriter) {
- return ((LoadingCharArrayWriter)currentStream).toCharArray();
- }
- throw new IOException("Unknown format of currentStream");
- }
- // read the file
- try (Reader fin = createInputStreamReader(tempFile)) {
- CharArrayWriter out = new CharArrayWriter((int)tempFile.length());
- char[] bytes = new char[1024];
- int x = fin.read(bytes);
- while (x != -1) {
- out.write(bytes, 0, x);
- x = fin.read(bytes);
- }
- return out.toCharArray();
- }
- }
-
- public void writeCacheTo(Writer out) throws IOException {
- flush();
- if (inmem) {
- if (currentStream instanceof LoadingCharArrayWriter) {
- ((LoadingCharArrayWriter)currentStream).writeTo(out);
- } else {
- throw new IOException("Unknown format of currentStream");
- }
- } else {
- // read the file
- try (Reader fin = createInputStreamReader(tempFile)) {
- char[] bytes = new char[1024];
- int x = fin.read(bytes);
- while (x != -1) {
- out.write(bytes, 0, x);
- x = fin.read(bytes);
- }
- }
- }
- }
-
- public void writeCacheTo(StringBuilder out, long limit) throws IOException {
- flush();
- if (totalLength < limit
- || limit == -1) {
- writeCacheTo(out);
- return;
- }
-
- long count = 0;
- if (inmem) {
- if (currentStream instanceof LoadingCharArrayWriter) {
- LoadingCharArrayWriter s = (LoadingCharArrayWriter)currentStream;
- out.append(s.rawCharArray(), 0, (int)limit);
- } else {
- throw new IOException("Unknown format of currentStream");
- }
- } else {
- // read the file
- try (Reader fin = createInputStreamReader(tempFile)) {
- char[] bytes = new char[1024];
- long x = fin.read(bytes);
- while (x != -1) {
- if ((count + x) > limit) {
- x = limit - count;
- }
- out.append(bytes, 0, (int)x);
- count += x;
-
- if (count >= limit) {
- x = -1;
- } else {
- x = fin.read(bytes);
- }
- }
- }
- }
- }
-
- public void writeCacheTo(StringBuilder out) throws IOException {
- flush();
- if (inmem) {
- if (currentStream instanceof LoadingCharArrayWriter) {
- LoadingCharArrayWriter lcaw = (LoadingCharArrayWriter)currentStream;
- out.append(lcaw.rawCharArray(), 0, lcaw.size());
- } else {
- throw new IOException("Unknown format of currentStream");
- }
- } else {
- // read the file
- try (Reader r = createInputStreamReader(tempFile)) {
- char[] chars = new char[1024];
- int x = r.read(chars);
- while (x != -1) {
- out.append(chars, 0, x);
- x = r.read(chars);
- }
- }
- }
- }
-
-
- /**
- * @return the underlying output stream
- */
- public Writer getOut() {
- return currentStream;
- }
-
- public int hashCode() {
- return currentStream.hashCode();
- }
-
- public String toString() {
- StringBuilder builder = new StringBuilder().append('[')
- .append(CachedWriter.class.getName())
- .append(" Content: ");
- try {
- writeCacheTo(builder);
- } catch (IOException e) {
- //ignore
- }
- return builder.append(']').toString();
- }
-
- protected void onWrite() throws IOException {
-
- }
-
- private void enforceLimits() throws IOException {
- if (maxSize > 0 && totalLength > maxSize) {
- throw new CacheSizeExceededException();
- }
- if (inmem && totalLength > threshold && currentStream instanceof LoadingCharArrayWriter) {
- createFileOutputStream();
- }
- }
-
-
- public void write(char[] cbuf, int off, int len) throws IOException {
- if (!outputLocked) {
- onWrite();
- this.totalLength += len;
- enforceLimits();
- currentStream.write(cbuf, off, len);
- }
- }
-
- private void createFileOutputStream() throws IOException {
- if (tempFileFailed) {
- return;
- }
- LoadingCharArrayWriter bout = (LoadingCharArrayWriter)currentStream;
- try {
- if (outputDir == null) {
- tempFile = FileUtils.createTempFile("cos", "tmp");
- } else {
- tempFile = FileUtils.createTempFile("cos", "tmp", outputDir, false);
- }
- currentStream = createOutputStreamWriter(tempFile);
- bout.writeTo(currentStream);
- inmem = false;
- streamList.add(currentStream);
- } catch (Exception ex) {
- //Could be IOException or SecurityException or other issues.
- //Don't care what, just keep it in memory.
- tempFileFailed = true;
- if (currentStream != bout) {
- currentStream.close();
- }
- deleteTempFile();
- inmem = true;
- currentStream = bout;
- }
- }
-
- public File getTempFile() {
- return tempFile != null && tempFile.exists() ? tempFile : null;
- }
-
- public Reader getReader() throws IOException {
- flush();
- if (inmem) {
- if (currentStream instanceof LoadingCharArrayWriter) {
- LoadingCharArrayWriter lcaw = (LoadingCharArrayWriter)currentStream;
- return new CharArrayReader(lcaw.rawCharArray(), 0, lcaw.size());
- }
- return null;
- }
- try {
- InputStream fileInputStream = new FileInputStream(tempFile) {
- boolean closed;
-
- @Override
- public void close() throws IOException {
- if (!closed) {
- super.close();
- maybeDeleteTempFile(this);
- }
- closed = true;
- }
- };
- streamList.add(fileInputStream);
- if (cipherTransformation != null) {
- fileInputStream = new CipherInputStream(fileInputStream, ciphers.getDecryptor()) {
- boolean closed;
-
- @Override
- public void close() throws IOException {
- if (!closed) {
- super.close();
- closed = true;
- }
- }
- };
- }
- return new InputStreamReader(fileInputStream, StandardCharsets.UTF_8);
- } catch (FileNotFoundException e) {
- throw new IOException("Cached file was deleted, " + e.toString());
- }
- }
-
- private synchronized void deleteTempFile() {
- if (tempFile != null) {
- File file = tempFile;
- tempFile = null;
- FileUtils.delete(file);
- }
- }
- private void maybeDeleteTempFile(Object stream) {
- streamList.remove(stream);
- if (!inmem && tempFile != null && streamList.isEmpty() && allowDeleteOfFile) {
- if (currentStream != null) {
- try {
- currentStream.close();
- postClose();
- } catch (Exception e) {
- //ignore
- }
- }
- deleteTempFile();
- currentStream = new LoadingCharArrayWriter();
- inmem = true;
- }
- }
-
- public void setOutputDir(File outputDir) throws IOException {
- this.outputDir = outputDir;
- }
- public void setThreshold(long threshold) {
- this.threshold = threshold;
- }
-
- public void setMaxSize(long maxSize) {
- this.maxSize = maxSize;
- }
-
- public void setCipherTransformation(String cipherTransformation) {
- this.cipherTransformation = cipherTransformation;
- }
-
- public static void setDefaultMaxSize(long l) {
- if (l == -1) {
- String s = System.getProperty(CachedConstants.MAX_SIZE_SYS_PROP);
- if (s == null) {
- // lookup the deprecated property
- s = System.getProperty("org.apache.cxf.io.CachedWriter.MaxSize", "-1");
- }
- l = Long.parseLong(s);
- }
- defaultMaxSize = l;
- }
-
- public static void setDefaultThreshold(int i) {
- if (i == -1) {
- i = SystemPropertyAction.getInteger(CachedConstants.THRESHOLD_SYS_PROP, -1);
- if (i == -1) {
- // lookup the deprecated property
- i = SystemPropertyAction.getInteger("org.apache.cxf.io.CachedWriter.Threshold", -1);
- }
- if (i <= 0) {
- i = 64 * 1024;
- }
- }
- defaultThreshold = i;
-
- }
-
- public static void setDefaultCipherTransformation(String n) {
- if (n == null) {
- n = SystemPropertyAction.getPropertyOrNull(CachedConstants.CIPHER_TRANSFORMATION_SYS_PROP);
- }
- defaultCipherTransformation = n;
- }
-
- private OutputStreamWriter createOutputStreamWriter(File file) throws IOException {
- OutputStream out = new BufferedOutputStream(Files.newOutputStream(file.toPath()));
- if (cipherTransformation != null) {
- try {
- if (ciphers == null) {
- ciphers = new CipherPair(cipherTransformation);
- }
- } catch (GeneralSecurityException e) {
- out.close();
- throw new IOException(e.getMessage(), e);
- }
- out = new CipherOutputStream(out, ciphers.getEncryptor()) {
-
- @Override
- public void close() throws IOException {
- if (!cosClosed) {
- super.close();
- cosClosed = true;
- }
- }
- };
- }
- return new OutputStreamWriter(out, UTF_8) {
-
- @Override
- public void close() throws IOException {
- if (!cosClosed) {
- super.close();
- cosClosed = true;
- }
- }
- };
- }
-
- private InputStreamReader createInputStreamReader(File file) throws IOException {
- InputStream in = Files.newInputStream(file.toPath());
- if (cipherTransformation != null) {
- in = new CipherInputStream(in, ciphers.getDecryptor()) {
- boolean closed;
-
- @Override
- public void close() throws IOException {
- if (!closed) {
- super.close();
- closed = true;
- }
- }
- };
- }
- return new InputStreamReader(in, UTF_8);
- }
-
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/io/ReaderInputStream.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/io/ReaderInputStream.java
deleted file mode 100644
index e95ed88..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/io/ReaderInputStream.java
+++ /dev/null
@@ -1,294 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.cxf.io;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.Reader;
-import java.nio.ByteBuffer;
-import java.nio.CharBuffer;
-import java.nio.charset.Charset;
-import java.nio.charset.CharsetEncoder;
-import java.nio.charset.CoderResult;
-import java.nio.charset.CodingErrorAction;
-
-/**
- * {@link InputStream} implementation that reads a character stream from a {@link Reader}
- * and transforms it to a byte stream using a specified charset encoding. The stream
- * is transformed using a {@link CharsetEncoder} object, guaranteeing that all charset
- * encodings supported by the JRE are handled correctly. In particular for charsets such as
- * UTF-16, the implementation ensures that one and only one byte order marker
- * is produced.
- * <p>
- * Since in general it is not possible to predict the number of characters to be read from the
- * {@link Reader} to satisfy a read request on the {@link ReaderInputStream}, all reads from
- * the {@link Reader} are buffered. There is therefore no well defined correlation
- * between the current position of the {@link Reader} and that of the {@link ReaderInputStream}.
- * This also implies that in general there is no need to wrap the underlying {@link Reader}
- * in a {@link java.io.BufferedReader}.
- * <p>
- * {@link ReaderInputStream} implements the inverse transformation of {@link java.io.InputStreamReader};
- * in the following example, reading from <tt>in2</tt> would return the same byte
- * sequence as reading from <tt>in</tt> (provided that the initial byte sequence is legal
- * with respect to the charset encoding):
- * <pre>
- * InputStream in = ...
- * Charset cs = ...
- * InputStreamReader reader = new InputStreamReader(in, cs);
- * ReaderInputStream in2 = new ReaderInputStream(reader, cs);</pre>
- * {@link ReaderInputStream} implements the same transformation as {@link java.io.OutputStreamWriter},
- * except that the control flow is reversed: both classes transform a character stream
- * into a byte stream, but {@link java.io.OutputStreamWriter} pushes data to the underlying stream,
- * while {@link ReaderInputStream} pulls it from the underlying stream.
- * <p>
- * Note that while there are use cases where there is no alternative to using
- * this class, very often the need to use this class is an indication of a flaw
- * in the design of the code. This class is typically used in situations where an existing
- * API only accepts an {@link InputStream}, but where the most natural way to produce the data
- * is as a character stream, i.e. by providing a {@link Reader} instance. An example of a situation
- * where this problem may appear is when implementing the {@link javax.activation.DataSource}
- * interface from the Java Activation Framework.
- * <p>
- * Given the fact that the {@link Reader} class doesn't provide any way to predict whether the next
- * read operation will block or not, it is not possible to provide a meaningful
- * implementation of the {@link InputStream#available()} method. A call to this method
- * will always return 0. Also, this class doesn't support {@link InputStream#mark(int)}.
- * <p>
- * Instances of {@link ReaderInputStream} are not thread safe.
- *
- * @since 2.0
- */
-public class ReaderInputStream extends InputStream {
- private static final int DEFAULT_BUFFER_SIZE = 1024;
-
- private final Reader reader;
- private final CharsetEncoder encoder;
-
- /**
- * CharBuffer used as input for the decoder. It should be reasonably
- * large as we read data from the underlying Reader into this buffer.
- */
- private final CharBuffer encoderIn;
-
- /**
- * ByteBuffer used as output for the decoder. This buffer can be small
- * as it is only used to transfer data from the decoder to the
- * buffer provided by the caller.
- */
- private final ByteBuffer encoderOut;
-
- private CoderResult lastCoderResult;
- private boolean endOfInput;
-
- /**
- * Construct a new {@link ReaderInputStream}.
- *
- * @param reader the target {@link Reader}
- * @param encoder the charset encoder
- * @since 2.1
- */
- public ReaderInputStream(Reader reader, CharsetEncoder encoder) {
- this(reader, encoder, DEFAULT_BUFFER_SIZE);
- }
-
- /**
- * Construct a new {@link ReaderInputStream}.
- *
- * @param reader the target {@link Reader}
- * @param encoder the charset encoder
- * @param bufferSize the size of the input buffer in number of characters
- * @since 2.1
- */
- public ReaderInputStream(Reader reader, CharsetEncoder encoder, int bufferSize) {
- this.reader = reader;
- this.encoder = encoder;
- this.encoderIn = CharBuffer.allocate(bufferSize);
- encoderIn.flip();
- this.encoderOut = ByteBuffer.allocate(128);
- encoderOut.flip();
- }
-
- /**
- * Construct a new {@link ReaderInputStream}.
- *
- * @param reader the target {@link Reader}
- * @param charset the charset encoding
- * @param bufferSize the size of the input buffer in number of characters
- */
- public ReaderInputStream(Reader reader, Charset charset, int bufferSize) {
- this(reader,
- charset.newEncoder()
- .onMalformedInput(CodingErrorAction.REPLACE)
- .onUnmappableCharacter(CodingErrorAction.REPLACE),
- bufferSize);
- }
-
- /**
- * Construct a new {@link ReaderInputStream} with a default input buffer size of
- * 1024 characters.
- *
- * @param reader the target {@link Reader}
- * @param charset the charset encoding
- */
- public ReaderInputStream(Reader reader, Charset charset) {
- this(reader, charset, DEFAULT_BUFFER_SIZE);
- }
-
- /**
- * Construct a new {@link ReaderInputStream}.
- *
- * @param reader the target {@link Reader}
- * @param charsetName the name of the charset encoding
- * @param bufferSize the size of the input buffer in number of characters
- */
- public ReaderInputStream(Reader reader, String charsetName, int bufferSize) {
- this(reader, Charset.forName(charsetName), bufferSize);
- }
-
- /**
- * Construct a new {@link ReaderInputStream} with a default input buffer size of
- * 1024 characters.
- *
- * @param reader the target {@link Reader}
- * @param charsetName the name of the charset encoding
- */
- public ReaderInputStream(Reader reader, String charsetName) {
- this(reader, charsetName, DEFAULT_BUFFER_SIZE);
- }
-
- /**
- * Construct a new {@link ReaderInputStream} that uses the default character encoding
- * with a default input buffer size of 1024 characters.
- *
- * @param reader the target {@link Reader}
- */
- public ReaderInputStream(Reader reader) {
- this(reader, Charset.defaultCharset());
- }
-
- /**
- * Fills the internal char buffer from the reader.
- *
- * @throws IOException
- * If an I/O error occurs
- */
- private void fillBuffer() throws IOException {
- if (!endOfInput && (lastCoderResult == null || lastCoderResult.isUnderflow())) {
- encoderIn.compact();
- int position = encoderIn.position();
- // We don't use Reader#read(CharBuffer) here because it is more efficient
- // to write directly to the underlying char array (the default implementation
- // copies data to a temporary char array).
- int c = reader.read(encoderIn.array(), position, encoderIn.remaining());
- if (c == -1) {
- endOfInput = true;
- } else {
- encoderIn.position(position + c);
- }
- encoderIn.flip();
- }
- encoderOut.compact();
- lastCoderResult = encoder.encode(encoderIn, encoderOut, endOfInput);
- encoderOut.flip();
- }
-
- /**
- * Read the specified number of bytes into an array.
- *
- * @param b the byte array to read into
- * @param off the offset to start reading bytes into
- * @param len the number of bytes to read
- * @return the number of bytes read or <code>-1</code>
- * if the end of the stream has been reached
- * @throws IOException if an I/O error occurs
- */
- @Override
- public int read(byte[] b, int off, int len) throws IOException {
- if (b == null) {
- throw new NullPointerException("Byte array must not be null");
- }
- if (len < 0 || off < 0 || (off + len) > b.length) {
- throw new IndexOutOfBoundsException("Array Size=" + b.length
- + ", offset=" + off + ", length=" + len);
- }
- int read = 0;
- if (len == 0) {
- return 0; // Always return 0 if len == 0
- }
- while (len > 0) {
- if (encoderOut.hasRemaining()) {
- int c = Math.min(encoderOut.remaining(), len);
- encoderOut.get(b, off, c);
- off += c;
- len -= c;
- read += c;
- } else {
- fillBuffer();
- if (endOfInput && !encoderOut.hasRemaining()) {
- break;
- }
- }
- }
- return read == 0 && endOfInput ? -1 : read;
- }
-
- /**
- * Read the specified number of bytes into an array.
- *
- * @param b the byte array to read into
- * @return the number of bytes read or <code>-1</code>
- * if the end of the stream has been reached
- * @throws IOException if an I/O error occurs
- */
- @Override
- public int read(byte[] b) throws IOException {
- return read(b, 0, b.length);
- }
-
- /**
- * Read a single byte.
- *
- * @return either the byte read or <code>-1</code> if the end of the stream
- * has been reached
- * @throws IOException if an I/O error occurs
- */
- @Override
- public int read() throws IOException {
- for (;;) {
- if (encoderOut.hasRemaining()) {
- return encoderOut.get() & 0xFF;
- } else {
- fillBuffer();
- if (endOfInput && !encoderOut.hasRemaining()) {
- return -1;
- }
- }
- }
- }
-
- /**
- * Close the stream. This method will cause the underlying {@link Reader}
- * to be closed.
- * @throws IOException if an I/O error occurs
- */
- @Override
- public void close() throws IOException {
- reader.close();
- }
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/io/WriteOnCloseOutputStream.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/io/WriteOnCloseOutputStream.java
deleted file mode 100644
index 17f4579..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/io/WriteOnCloseOutputStream.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.cxf.io;
-
-import java.io.IOException;
-import java.io.OutputStream;
-
-/**
- * This outputstream implementation will cache the message until close()
- * is called, at which point it will write the message to the OutputStream
- * supplied via the constructor.
- */
-public class WriteOnCloseOutputStream extends CachedOutputStream {
-
- OutputStream flowThroughStream;
-
- public WriteOnCloseOutputStream(OutputStream stream) {
- super();
- flowThroughStream = stream;
- }
-
-
- @Override
- protected void doClose() throws IOException {
- resetOut(flowThroughStream, true);
- flowThroughStream.flush();
- }
-
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxb/FactoryClassGenerator.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxb/FactoryClassGenerator.java
deleted file mode 100644
index fe4c08b..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxb/FactoryClassGenerator.java
+++ /dev/null
@@ -1,86 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.cxf.jaxb;
-
-import java.lang.reflect.Constructor;
-
-import org.apache.cxf.Bus;
-import org.apache.cxf.common.spi.ClassGeneratorClassLoader;
-import org.apache.cxf.common.util.ASMHelper;
-import org.apache.cxf.common.util.OpcodesProxy;
-import org.apache.cxf.common.util.ReflectionUtil;
-import org.apache.cxf.common.util.StringUtils;
-
-
-public class FactoryClassGenerator extends ClassGeneratorClassLoader implements FactoryClassCreator {
- private final ASMHelper helper;
- FactoryClassGenerator(Bus bus) {
- super(bus);
- helper = bus.getExtension(ASMHelper.class);
- }
- @SuppressWarnings("unused")
- public Class<?> createFactory(Class<?> cls) {
- String newClassName = cls.getName() + "Factory";
- Class<?> factoryClass = findClass(newClassName, cls);
- if (factoryClass != null) {
- return factoryClass;
- }
- Constructor<?> contructor = ReflectionUtil.getDeclaredConstructors(cls)[0];
- OpcodesProxy opcodes = helper.getOpCodes();
- ASMHelper.ClassWriter cw = helper.createClassWriter();
- ASMHelper.MethodVisitor mv;
-
- cw.visit(opcodes.V1_6, opcodes.ACC_PUBLIC + opcodes.ACC_SUPER,
- StringUtils.periodToSlashes(newClassName), null, "java/lang/Object", null);
-
- cw.visitSource(cls.getSimpleName() + "Factory" + ".java", null);
-
- mv = cw.visitMethod(opcodes.ACC_PUBLIC, "<init>", "()V", null, null);
- mv.visitCode();
- mv.visitVarInsn(opcodes.ALOAD, 0);
- mv.visitMethodInsn(opcodes.INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false);
- mv.visitInsn(opcodes.RETURN);
- mv.visitMaxs(0, 0);
- mv.visitEnd();
-
- mv = cw.visitMethod(opcodes.ACC_PUBLIC, "create" + cls.getSimpleName(),
- "()L" + StringUtils.periodToSlashes(cls.getName()) + ";", null, null);
- mv.visitCode();
- String name = cls.getName().replace('.', '/');
- mv.visitTypeInsn(opcodes.NEW, name);
- mv.visitInsn(opcodes.DUP);
- StringBuilder paraString = new StringBuilder(32).append('(');
-
- for (Class<?> paraClass : contructor.getParameterTypes()) {
- mv.visitInsn(opcodes.ACONST_NULL);
- paraString.append("Ljava/lang/Object;");
- }
- paraString.append(")V");
-
- mv.visitMethodInsn(opcodes.INVOKESPECIAL, name, "<init>", paraString.toString(), false);
-
- mv.visitInsn(opcodes.ARETURN);
- mv.visitMaxs(0, 0);
- mv.visitEnd();
-
- cw.visitEnd();
- return loadClass(newClassName, cls, cw.toByteArray());
- }
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxb/JAXBDataBase.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxb/JAXBDataBase.java
deleted file mode 100644
index 55ac0cf..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxb/JAXBDataBase.java
+++ /dev/null
@@ -1,192 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.cxf.jaxb;
-
-import java.lang.annotation.Annotation;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import javax.xml.bind.JAXBContext;
-import javax.xml.bind.ValidationEventHandler;
-import javax.xml.bind.annotation.XmlAttachmentRef;
-import javax.xml.bind.annotation.XmlList;
-import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
-import javax.xml.bind.attachment.AttachmentMarshaller;
-import javax.xml.bind.attachment.AttachmentUnmarshaller;
-import javax.xml.validation.Schema;
-
-import org.apache.cxf.common.classloader.ClassLoaderUtils;
-import org.apache.cxf.common.logging.LogUtils;
-import org.apache.cxf.jaxb.attachment.JAXBAttachmentMarshaller;
-import org.apache.cxf.jaxb.attachment.JAXBAttachmentUnmarshaller;
-import org.apache.cxf.message.Attachment;
-import org.apache.cxf.message.Message;
-import org.apache.cxf.service.model.AbstractMessageContainer;
-import org.apache.cxf.service.model.MessageInfo;
-import org.apache.cxf.service.model.MessagePartInfo;
-import org.apache.cxf.service.model.OperationInfo;
-
-/**
- *
- */
-public abstract class JAXBDataBase {
- static final Logger LOG = LogUtils.getL7dLogger(JAXBDataBase.class);
-
- protected JAXBContext context;
- protected Schema schema;
- protected Collection<Attachment> attachments;
- protected Integer mtomThreshold; // null if we should default.
-
- protected JAXBDataBase(JAXBContext ctx) {
- context = ctx;
- }
-
- public void setSchema(Schema s) {
- this.schema = s;
- }
-
- public void setJAXBContext(JAXBContext jc) {
- this.context = jc;
- }
-
- public Schema getSchema() {
- return schema;
- }
- public JAXBContext getJAXBContext() {
- return context;
- }
-
- public Collection<Attachment> getAttachments() {
- return attachments;
- }
-
- public void setAttachments(Collection<Attachment> attachments) {
- this.attachments = attachments;
- }
-
- protected AttachmentUnmarshaller getAttachmentUnmarshaller() {
- return new JAXBAttachmentUnmarshaller(attachments);
- }
-
- protected AttachmentMarshaller getAttachmentMarshaller() {
- return new JAXBAttachmentMarshaller(attachments, mtomThreshold);
- }
-
- public void setProperty(String prop, Object value) {
- }
-
- protected Annotation[] getJAXBAnnotation(MessagePartInfo mpi) {
- List<Annotation> annoList = null;
- if (mpi != null) {
- annoList = extractJAXBAnnotations((Annotation[])mpi.getProperty("parameter.annotations"));
- if (annoList == null) {
- annoList = extractJAXBAnnotations(getReturnMethodAnnotations(mpi));
- }
- }
- return annoList == null ? new Annotation[0] : annoList.toArray(new Annotation[0]);
- }
-
- private List<Annotation> extractJAXBAnnotations(Annotation[] anns) {
- List<Annotation> annoList = null;
- if (anns != null) {
- for (Annotation ann : anns) {
- if (ann instanceof XmlList || ann instanceof XmlAttachmentRef
- || ann instanceof XmlJavaTypeAdapter) {
- if (annoList == null) {
- annoList = new ArrayList<>();
- }
- annoList.add(ann);
- }
- }
- }
- return annoList;
- }
-
- private Annotation[] getReturnMethodAnnotations(MessagePartInfo mpi) {
- AbstractMessageContainer mi = mpi.getMessageInfo();
- if (mi == null || !isOutputMessage(mi)) {
- return null;
- }
- OperationInfo oi = mi.getOperation();
- return oi != null ? (Annotation[])oi.getProperty("method.return.annotations") : null;
- }
-
- protected boolean isOutputMessage(AbstractMessageContainer messageContainer) {
- if (messageContainer instanceof MessageInfo) {
- return MessageInfo.Type.OUTPUT.equals(((MessageInfo)messageContainer).getType());
- }
- return false;
- }
-
- public Integer getMtomThreshold() {
- return mtomThreshold;
- }
-
- public void setMtomThreshold(Integer threshold) {
- this.mtomThreshold = threshold;
- }
-
- protected final boolean honorJAXBAnnotations(MessagePartInfo part) {
- if (part == null) {
- return false;
- }
- if (!part.isElement()) {
- //RPC-Lit always needs to look for these
- return true;
- }
- //certain cases that use XmlJavaTypeAdapters will require this and the
- //JAXBSchemaInitializer will set this.
- Boolean b = (Boolean)part.getProperty("honor.jaxb.annotations");
- return b != null && b;
- }
-
- protected ValidationEventHandler getValidationEventHandler(String cn) {
- try {
- return (ValidationEventHandler)ClassLoaderUtils.loadClass(cn, getClass()).newInstance();
- } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {
- LOG.log(Level.INFO, "Could not create validation event handler", e);
- }
- return null;
- }
-
- protected ValidationEventHandler getValidationEventHandler(Message m, String property) {
- Object value = m.getContextualProperty(property);
- ValidationEventHandler veventHandler;
- if (value instanceof String) {
- veventHandler = getValidationEventHandler((String)value);
- } else {
- veventHandler = (ValidationEventHandler)value;
- }
- if (veventHandler == null) {
- value = m.getContextualProperty(JAXBDataBinding.VALIDATION_EVENT_HANDLER);
- if (value instanceof String) {
- veventHandler = getValidationEventHandler((String)value);
- } else {
- veventHandler = (ValidationEventHandler)value;
- }
- }
- return veventHandler;
- }
-
-
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxb/JAXBDataBinding.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxb/JAXBDataBinding.java
deleted file mode 100644
index a66e9bf..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxb/JAXBDataBinding.java
+++ /dev/null
@@ -1,873 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.cxf.jaxb;
-
-import java.io.IOException;
-import java.io.OutputStream;
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-import java.lang.reflect.ParameterizedType;
-import java.lang.reflect.Type;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.LinkedHashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.function.Consumer;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import javax.xml.bind.JAXBContext;
-import javax.xml.bind.JAXBElement;
-import javax.xml.bind.JAXBException;
-import javax.xml.bind.Marshaller;
-import javax.xml.bind.Unmarshaller;
-import javax.xml.bind.ValidationEventHandler;
-import javax.xml.bind.annotation.XmlElement;
-import javax.xml.bind.annotation.XmlElementRef;
-import javax.xml.bind.annotation.adapters.XmlAdapter;
-import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
-import javax.xml.namespace.QName;
-import javax.xml.stream.XMLEventReader;
-import javax.xml.stream.XMLEventWriter;
-import javax.xml.stream.XMLStreamReader;
-import javax.xml.stream.XMLStreamWriter;
-import javax.xml.transform.dom.DOMResult;
-import javax.xml.transform.dom.DOMSource;
-
-import org.w3c.dom.Document;
-import org.w3c.dom.Node;
-
-import org.xml.sax.InputSource;
-
-import org.apache.cxf.Bus;
-import org.apache.cxf.common.injection.NoJSR250Annotations;
-import org.apache.cxf.common.jaxb.JAXBBeanInfo;
-import org.apache.cxf.common.jaxb.JAXBContextCache;
-import org.apache.cxf.common.jaxb.JAXBContextCache.CachedContextAndSchemas;
-import org.apache.cxf.common.jaxb.JAXBContextProxy;
-import org.apache.cxf.common.jaxb.JAXBUtils;
-import org.apache.cxf.common.logging.LogUtils;
-import org.apache.cxf.common.util.PackageUtils;
-import org.apache.cxf.common.util.PropertyUtils;
-import org.apache.cxf.common.util.ReflectionUtil;
-import org.apache.cxf.common.xmlschema.SchemaCollection;
-import org.apache.cxf.databinding.AbstractInterceptorProvidingDataBinding;
-import org.apache.cxf.databinding.AbstractWrapperHelper;
-import org.apache.cxf.databinding.DataReader;
-import org.apache.cxf.databinding.DataWriter;
-import org.apache.cxf.databinding.WrapperCapableDatabinding;
-import org.apache.cxf.databinding.WrapperHelper;
-import org.apache.cxf.interceptor.InterceptorProvider;
-import org.apache.cxf.jaxb.attachment.JAXBAttachmentSchemaValidationHack;
-import org.apache.cxf.jaxb.io.DataReaderImpl;
-import org.apache.cxf.jaxb.io.DataWriterImpl;
-import org.apache.cxf.resource.URIResolver;
-import org.apache.cxf.service.Service;
-import org.apache.cxf.service.factory.ServiceConstructionException;
-import org.apache.cxf.service.model.MessageInfo;
-import org.apache.cxf.service.model.MessagePartInfo;
-import org.apache.cxf.service.model.ServiceInfo;
-import org.apache.cxf.staxutils.StaxUtils;
-import org.apache.cxf.ws.addressing.ObjectFactory;
-
-@NoJSR250Annotations
-public class JAXBDataBinding extends AbstractInterceptorProvidingDataBinding
- implements WrapperCapableDatabinding, InterceptorProvider {
-
- public static final String READER_VALIDATION_EVENT_HANDLER = "jaxb-reader-validation-event-handler";
- public static final String VALIDATION_EVENT_HANDLER = "jaxb-validation-event-handler";
- public static final String SET_VALIDATION_EVENT_HANDLER = "set-jaxb-validation-event-handler";
- public static final String WRITER_VALIDATION_EVENT_HANDLER = "jaxb-writer-validation-event-handler";
-
- public static final String SCHEMA_RESOURCE = "SCHEMRESOURCE";
- public static final String MTOM_THRESHOLD = "org.apache.cxf.jaxb.mtomThreshold";
-
- public static final String UNWRAP_JAXB_ELEMENT = "unwrap.jaxb.element";
-
- public static final String USE_JAXB_BRIDGE = "use.jaxb.bridge";
-
- public static final String JAXB_SCAN_PACKAGES = "jaxb.scanPackages";
-
- private static final Logger LOG = LogUtils.getLogger(JAXBDataBinding.class);
-
- private static final Class<?>[] SUPPORTED_READER_FORMATS = new Class<?>[] {Node.class,
- XMLEventReader.class,
- XMLStreamReader.class};
- private static final Class<?>[] SUPPORTED_WRITER_FORMATS = new Class<?>[] {OutputStream.class,
- Node.class,
- XMLEventWriter.class,
- XMLStreamWriter.class};
-
- private static class DelayedDOMResult extends DOMResult {
- private final URL resource;
- private final String publicId;
- DelayedDOMResult(URL url, String sysId, String pId) {
- super(null, sysId);
- resource = url;
- publicId = pId;
- }
- public synchronized Node getNode() {
- Node nd = super.getNode();
- if (nd == null) {
- try {
- InputSource src = new InputSource(resource.openStream());
- src.setSystemId(this.getSystemId());
- src.setPublicId(publicId);
- Document doc = StaxUtils.read(src);
- setNode(doc);
- nd = super.getNode();
- } catch (Exception ex) {
- throw new RuntimeException(ex);
- }
- }
- return nd;
- }
- }
- private static final Map<String, DOMResult> BUILT_IN_SCHEMAS = new HashMap<>();
- static {
- try (URIResolver resolver = new URIResolver()) {
- try {
- resolver.resolve("", "classpath:/schemas/wsdl/ws-addr-wsdl.xsd", JAXBDataBinding.class);
- if (resolver.isResolved()) {
- resolver.getInputStream().close();
- DOMResult dr = new DelayedDOMResult(resolver.getURL(),
- "classpath:/schemas/wsdl/ws-addr-wsdl.xsd",
- "http://www.w3.org/2005/02/addressing/wsdl");
- BUILT_IN_SCHEMAS.put("http://www.w3.org/2005/02/addressing/wsdl", dr);
- resolver.unresolve();
- }
- } catch (Exception e) {
- //IGNORE
- }
- try {
- resolver.resolve("", "classpath:/schemas/wsdl/ws-addr.xsd", JAXBDataBinding.class);
- if (resolver.isResolved()) {
- resolver.getInputStream().close();
- DOMResult dr = new DelayedDOMResult(resolver.getURL(),
- "classpath:/schemas/wsdl/ws-addr.xsd",
- "http://www.w3.org/2005/08/addressing");
- BUILT_IN_SCHEMAS.put("http://www.w3.org/2005/08/addressing", dr);
- resolver.unresolve();
- }
- } catch (Exception e) {
- //IGNORE
- }
- try {
- resolver.resolve("", "classpath:/schemas/wsdl/wsrm.xsd", JAXBDataBinding.class);
- if (resolver.isResolved()) {
- resolver.getInputStream().close();
- DOMResult dr = new DelayedDOMResult(resolver.getURL(),
- "classpath:/schemas/wsdl/wsrm.xsd",
- "http://schemas.xmlsoap.org/ws/2005/02/rm");
- BUILT_IN_SCHEMAS.put("http://schemas.xmlsoap.org/ws/2005/02/rm", dr);
- resolver.unresolve();
- }
- } catch (Exception e) {
- //IGNORE
- }
- } catch (Exception e) {
- //IGNORE
- }
- }
-
- Class<?>[] extraClass;
-
- JAXBContext context;
- Set<Class<?>> contextClasses;
- Collection<Object> typeRefs = new ArrayList<>();
-
- Class<?> cls;
-
- private Map<String, Object> contextProperties = new HashMap<>();
- private List<XmlAdapter<?, ?>> adapters = new ArrayList<>();
- private Map<String, Object> marshallerProperties = new HashMap<>();
- private Map<String, Object> unmarshallerProperties = new HashMap<>();
- private Unmarshaller.Listener unmarshallerListener;
- private Marshaller.Listener marshallerListener;
- private ValidationEventHandler validationEventHandler;
- private Object escapeHandler;
- private Object noEscapeHandler;
-
- private boolean unwrapJAXBElement = true;
- private boolean scanPackages = true;
- private boolean qualifiedSchemas;
-
- public JAXBDataBinding() {
- }
-
- public JAXBDataBinding(boolean q) {
- this.qualifiedSchemas = q;
- }
-
- public JAXBDataBinding(Class<?>... classes) throws JAXBException {
- contextClasses = new LinkedHashSet<>(Arrays.asList(classes));
- setContext(createJAXBContext(contextClasses)); //NOPMD - specifically allow this
- }
- public JAXBDataBinding(boolean qualified, Map<String, Object> props) throws JAXBException {
- this(qualified);
- if (props != null && props.get("jaxb.additionalContextClasses") != null) {
- Object o = props.get("jaxb.additionalContextClasses");
- if (o instanceof Class) {
- o = new Class[] {(Class<?>)o};
- }
- extraClass = (Class[])o;
- }
-
- // the default for scan packages is true, so the jaxb scan packages
- // property must be explicitly set to false to disable it
- if (PropertyUtils.isFalse(props, JAXB_SCAN_PACKAGES)) {
- scanPackages = false;
- }
- }
-
- public JAXBDataBinding(JAXBContext context) {
- this();
- setContext(context);
- }
-
- protected boolean getQualifiedSchemas() {
- return qualifiedSchemas;
- }
-
- public JAXBContext getContext() {
- return context;
- }
-
- public final void setContext(JAXBContext ctx) {
- context = ctx;
- //create default MininumEscapeHandler
- escapeHandler = JAXBUtils.createMininumEscapeHandler(ctx.getClass());
- noEscapeHandler = JAXBUtils.createNoEscapeHandler(ctx.getClass());
- }
-
- public Object getEscapeHandler() {
- return escapeHandler;
- }
-
- public void setEscapeHandler(Object handler) {
- escapeHandler = handler;
- }
-
- public void applyEscapeHandler(boolean escape, Consumer<Object> consumer) {
- if (escape) {
- consumer.accept(escapeHandler);
- } else if (noEscapeHandler != null) {
- consumer.accept(noEscapeHandler);
- }
- }
-
-
- @SuppressWarnings("unchecked")
- public <T> DataWriter<T> createWriter(Class<T> c) {
-
- Integer mtomThresholdInt = Integer.valueOf(getMtomThreshold());
- if (c == XMLStreamWriter.class) {
- DataWriterImpl<XMLStreamWriter> r
- = new DataWriterImpl<>(getBus(), this, true);
- r.setMtomThreshold(mtomThresholdInt);
- return (DataWriter<T>)r;
- } else if (c == OutputStream.class) {
- DataWriterImpl<OutputStream> r = new DataWriterImpl<>(getBus(), this, false);
- r.setMtomThreshold(mtomThresholdInt);
- return (DataWriter<T>)r;
- } else if (c == XMLEventWriter.class) {
- DataWriterImpl<XMLEventWriter> r = new DataWriterImpl<>(getBus(), this, true);
- r.setMtomThreshold(mtomThresholdInt);
- return (DataWriter<T>)r;
- } else if (c == Node.class) {
- DataWriterImpl<Node> r = new DataWriterImpl<>(getBus(), this, false);
- r.setMtomThreshold(mtomThresholdInt);
- return (DataWriter<T>)r;
- }
- return null;
- }
-
- public Class<?>[] getSupportedWriterFormats() {
- return SUPPORTED_WRITER_FORMATS;
- }
-
- @SuppressWarnings("unchecked")
- public <T> DataReader<T> createReader(Class<T> c) {
- DataReader<T> dr = null;
- if (c == XMLStreamReader.class) {
- dr = (DataReader<T>)new DataReaderImpl<XMLStreamReader>(this, unwrapJAXBElement);
- } else if (c == XMLEventReader.class) {
- dr = (DataReader<T>)new DataReaderImpl<XMLEventReader>(this, unwrapJAXBElement);
- } else if (c == Node.class) {
- dr = (DataReader<T>)new DataReaderImpl<Node>(this, unwrapJAXBElement);
- }
-
- return dr;
- }
-
- public Class<?>[] getSupportedReaderFormats() {
- return SUPPORTED_READER_FORMATS;
- }
-
- @SuppressWarnings("unchecked")
- public synchronized void initialize(Service service) {
-
- inInterceptors.addIfAbsent(JAXBAttachmentSchemaValidationHack.INSTANCE);
- inFaultInterceptors.addIfAbsent(JAXBAttachmentSchemaValidationHack.INSTANCE);
-
- // context is already set, don't redo it
- if (context != null) {
- return;
- }
-
- contextClasses = new LinkedHashSet<>();
-
- for (ServiceInfo serviceInfo : service.getServiceInfos()) {
- JAXBContextInitializer initializer = new JAXBContextInitializer(getBus(), serviceInfo, contextClasses,
- typeRefs, this.getUnmarshallerProperties());
- initializer.walk();
- if (serviceInfo.getProperty("extra.class") != null) {
- Set<Class<?>> exClasses = serviceInfo.getProperty("extra.class", Set.class);
- contextClasses.addAll(exClasses);
- }
-
- }
-
- String tns = getNamespaceToUse(service);
- final CachedContextAndSchemas cachedContextAndSchemas;
- try {
- cachedContextAndSchemas = createJAXBContextAndSchemas(contextClasses, tns);
- } catch (JAXBException e1) {
- throw new ServiceConstructionException(e1);
- }
- final JAXBContext ctx = cachedContextAndSchemas.getContext();
- if (LOG.isLoggable(Level.FINE)) {
- LOG.log(Level.FINE, "CREATED_JAXB_CONTEXT", new Object[] {ctx, contextClasses});
- }
- setContext(ctx);
-
- for (ServiceInfo serviceInfo : service.getServiceInfos()) {
- SchemaCollection col = serviceInfo.getXmlSchemaCollection();
-
- if (col.getXmlSchemas().length > 1) {
- // someone has already filled in the types
- justCheckForJAXBAnnotations(serviceInfo);
- continue;
- }
-
- boolean schemasFromCache = false;
- Collection<DOMSource> schemas = getSchemas();
- if (schemas == null || schemas.isEmpty()) {
- schemas = cachedContextAndSchemas.getSchemas();
- if (schemas != null) {
- schemasFromCache = true;
- }
- } else {
- schemasFromCache = true;
- }
- Set<DOMSource> bi = new LinkedHashSet<>();
- if (schemas == null) {
- schemas = new LinkedHashSet<>();
- try {
- for (DOMResult r : generateJaxbSchemas()) {
- DOMSource src = new DOMSource(r.getNode(), r.getSystemId());
- if (isInBuiltInSchemas(r)) {
- bi.add(src);
- } else {
- schemas.add(src);
- }
- }
- //put any builtins at the end. Anything that DOES import them
- //will cause it to load automatically and we'll skip them later
- schemas.addAll(bi);
- } catch (IOException e) {
- throw new ServiceConstructionException("SCHEMA_GEN_EXC", LOG, e);
- }
- }
- for (DOMSource r : schemas) {
- if (bi.contains(r)) {
- String ns = ((Document)r.getNode()).getDocumentElement().getAttribute("targetNamespace");
- if (serviceInfo.getSchema(ns) != null) {
- continue;
- }
- }
- //StaxUtils.print(r.getNode());
- //System.out.println();
- addSchemaDocument(serviceInfo,
- col,
- (Document)r.getNode(),
- r.getSystemId());
- }
-
- JAXBSchemaInitializer schemaInit = new JAXBSchemaInitializer(serviceInfo, col, context,
- this.qualifiedSchemas, tns);
- schemaInit.walk();
- if (cachedContextAndSchemas != null && !schemasFromCache) {
- cachedContextAndSchemas.setSchemas(schemas);
- }
- }
- }
-
- protected void justCheckForJAXBAnnotations(ServiceInfo serviceInfo) {
- for (MessageInfo mi: serviceInfo.getMessages().values()) {
- for (MessagePartInfo mpi : mi.getMessageParts()) {
- checkForJAXBAnnotations(mpi, serviceInfo.getXmlSchemaCollection(), serviceInfo.getTargetNamespace());
- }
- }
- }
- private void checkForJAXBAnnotations(MessagePartInfo mpi, SchemaCollection schemaCollection, String ns) {
- Annotation[] anns = (Annotation[])mpi.getProperty("parameter.annotations");
- JAXBContextProxy ctx = JAXBUtils.createJAXBContextProxy(context, schemaCollection, ns);
- XmlJavaTypeAdapter jta = JAXBSchemaInitializer.findFromTypeAdapter(ctx, mpi.getTypeClass(), anns);
- if (jta != null) {
- JAXBBeanInfo jtaBeanInfo = JAXBSchemaInitializer.findFromTypeAdapter(ctx, jta.value());
- JAXBBeanInfo beanInfo = JAXBSchemaInitializer.getBeanInfo(ctx, mpi.getTypeClass());
- if (jtaBeanInfo != beanInfo) {
- mpi.setProperty("parameter.annotations", anns);
- mpi.setProperty("honor.jaxb.annotations", Boolean.TRUE);
- }
- }
- }
-
- protected String getNamespaceToUse(Service service) {
- if ("true".equals(service.get("org.apache.cxf.databinding.namespace"))) {
- return null;
- }
- final String tns;
- if (!service.getServiceInfos().isEmpty()) {
- tns = service.getServiceInfos().get(0).getInterface().getName().getNamespaceURI();
- } else {
- tns = service.getName().getNamespaceURI();
- }
- return tns;
- }
-
- public void setExtraClass(Class<?>[] userExtraClass) {
- extraClass = userExtraClass;
- }
-
- public Class<?>[] getExtraClass() {
- return extraClass;
- }
-
- // default access for tests.
- List<DOMResult> generateJaxbSchemas() throws IOException {
- return JAXBUtils.generateJaxbSchemas(context, BUILT_IN_SCHEMAS);
- }
-
- public JAXBContext createJAXBContext(Set<Class<?>> classes) throws JAXBException {
- return createJAXBContext(classes, null);
- }
-
- public JAXBContext createJAXBContext(Set<Class<?>> classes, String defaultNs) throws JAXBException {
- return createJAXBContextAndSchemas(classes, defaultNs).getContext();
- }
-
- public CachedContextAndSchemas createJAXBContextAndSchemas(Set<Class<?>> classes,
- String defaultNs)
- throws JAXBException {
- //add user extra class into jaxb context
- if (extraClass != null && extraClass.length > 0) {
- for (Class<?> clz : extraClass) {
- classes.add(clz);
- }
- }
- if (scanPackages) {
- JAXBContextCache.scanPackages(classes);
- }
- addWsAddressingTypes(classes);
-
- return JAXBContextCache.getCachedContextAndSchemas(classes, defaultNs,
- contextProperties,
- typeRefs, true);
- }
-
-
- private void addWsAddressingTypes(Set<Class<?>> classes) {
- if (classes.contains(ObjectFactory.class)) {
- // ws-addressing is used, lets add the specific types
- try {
- classes.add(Class.forName("org.apache.cxf.ws.addressing.wsdl.ObjectFactory"));
- classes.add(Class.forName("org.apache.cxf.ws.addressing.wsdl.AttributedQNameType"));
- classes.add(Class.forName("org.apache.cxf.ws.addressing.wsdl.ServiceNameType"));
- } catch (ClassNotFoundException unused) {
- // REVISIT - ignorable if WS-ADDRESSING not available?
- // maybe add a way to allow interceptors to add stuff to the
- // context?
- }
- }
- }
-
- public Set<Class<?>> getContextClasses() {
- return Collections.unmodifiableSet(this.contextClasses);
- }
-
- /**
- * Return a map of properties. These properties are passed to
- * JAXBContext.newInstance when this object creates a context.
- *
- * @return the map of JAXB context properties.
- */
- public Map<String, Object> getContextProperties() {
- return contextProperties;
- }
-
- /**
- * Set a map of JAXB context properties. These properties are passed to
- * JAXBContext.newInstance when this object creates a context. Note that if
- * you create a JAXB context elsewhere, you will not respect these
- * properties unless you handle it manually.
- *
- * @param contextProperties map of properties.
- */
- public void setContextProperties(Map<String, Object> contextProperties) {
- this.contextProperties = contextProperties;
- }
-
- public List<XmlAdapter<?, ?>> getConfiguredXmlAdapters() {
- return adapters;
- }
-
- public void setConfiguredXmlAdapters(List<XmlAdapter<?, ?>> adpters) {
- this.adapters = adpters;
- }
-
- /**
- * Return a map of properties. These properties are set into the JAXB
- * Marshaller (via Marshaller.setProperty(...) when the marshaller is
- * created.
- *
- * @return the map of JAXB marshaller properties.
- */
- public Map<String, Object> getMarshallerProperties() {
- return marshallerProperties;
- }
-
- /**
- * Set a map of JAXB marshaller properties. These properties are set into
- * the JAXB Marshaller (via Marshaller.setProperty(...) when the marshaller
- * is created.
- *
- * @param marshallerProperties map of properties.
- */
- public void setMarshallerProperties(Map<String, Object> marshallerProperties) {
- this.marshallerProperties = marshallerProperties;
- }
-
-
- /**
- * Return a map of properties. These properties are set into the JAXB
- * Unmarshaller (via Unmarshaller.setProperty(...) when the unmarshaller is
- * created.
- *
- * @return the map of JAXB unmarshaller properties.
- */
- public Map<String, Object> getUnmarshallerProperties() {
- return unmarshallerProperties;
- }
-
- /**
- * Set a map of JAXB unmarshaller properties. These properties are set into
- * the JAXB Unmarshaller (via Unmarshaller.setProperty(...) when the unmarshaller
- * is created.
- *
- * @param unmarshallerProperties map of properties.
- */
- public void setUnmarshallerProperties(Map<String, Object> unmarshallerProperties) {
- this.unmarshallerProperties = unmarshallerProperties;
- }
-
- /**
- * Returns the Unmarshaller.Listener that will be registered on the Unmarshallers
- * @return
- */
- public Unmarshaller.Listener getUnmarshallerListener() {
- return unmarshallerListener;
- }
-
- /**
- * Sets the Unmarshaller.Listener that will be registered on the Unmarshallers
- * @param unmarshallerListener
- */
- public void setUnmarshallerListener(Unmarshaller.Listener unmarshallerListener) {
- this.unmarshallerListener = unmarshallerListener;
- }
- /**
- * Returns the Marshaller.Listener that will be registered on the Marshallers
- * @return
- */
- public Marshaller.Listener getMarshallerListener() {
- return marshallerListener;
- }
-
- /**
- * Sets the Marshaller.Listener that will be registered on the Marshallers
- * @param marshallerListener
- */
- public void setMarshallerListener(Marshaller.Listener marshallerListener) {
- this.marshallerListener = marshallerListener;
- }
-
-
- public ValidationEventHandler getValidationEventHandler() {
- return validationEventHandler;
- }
-
- public void setValidationEventHandler(ValidationEventHandler validationEventHandler) {
- this.validationEventHandler = validationEventHandler;
- }
-
-
- public boolean isUnwrapJAXBElement() {
- return unwrapJAXBElement;
- }
-
- public void setUnwrapJAXBElement(boolean unwrapJAXBElement) {
- this.unwrapJAXBElement = unwrapJAXBElement;
- }
-
- public WrapperHelper createWrapperHelper(Class<?> wrapperType, QName wrapperName, List<String> partNames,
- List<String> elTypeNames, List<Class<?>> partClasses) {
- List<Method> getMethods = new ArrayList<>(partNames.size());
- List<Method> setMethods = new ArrayList<>(partNames.size());
- List<Method> jaxbMethods = new ArrayList<>(partNames.size());
- List<Field> fields = new ArrayList<>(partNames.size());
-
- Method[] allMethods = wrapperType.getMethods();
- String packageName = PackageUtils.getPackageName(wrapperType);
-
- //if wrappertype class is generated by ASM, getPackage() always return null
- if (wrapperType.getPackage() != null) {
- packageName = wrapperType.getPackage().getName();
- }
-
- String objectFactoryClassName = packageName + ".ObjectFactory";
-
- Object objectFactory = null;
- try {
- objectFactory = wrapperType.getClassLoader().loadClass(objectFactoryClassName).newInstance();
- } catch (Exception e) {
- //ignore, probably won't need it
- }
- Method[] allOFMethods;
- if (objectFactory != null) {
- allOFMethods = objectFactory.getClass().getMethods();
- } else {
- allOFMethods = new Method[0];
- }
-
- for (int x = 0; x < partNames.size(); x++) {
- String partName = partNames.get(x);
- if (partName == null) {
- getMethods.add(null);
- setMethods.add(null);
- fields.add(null);
- jaxbMethods.add(null);
- continue;
- }
-
- String elementType = elTypeNames.get(x);
-
- String getAccessor = JAXBUtils.nameToIdentifier(partName, JAXBUtils.IdentifierType.GETTER);
- String setAccessor = JAXBUtils.nameToIdentifier(partName, JAXBUtils.IdentifierType.SETTER);
- Method getMethod = null;
- Method setMethod = null;
- Class<?> valueClass = wrapperType;
-
- try {
- getMethod = valueClass.getMethod(getAccessor, AbstractWrapperHelper.NO_CLASSES);
- } catch (NoSuchMethodException ex) {
- //ignore for now
- }
-
- Field elField = getElField(partName, valueClass);
- if (getMethod == null
- && elementType != null
- && "boolean".equalsIgnoreCase(elementType)
- && (elField == null
- || (!Collection.class.isAssignableFrom(elField.getType())
- && !elField.getType().isArray()))) {
-
- try {
- String newAcc = getAccessor.replaceFirst("get", "is");
- getMethod = wrapperType.getMethod(newAcc, AbstractWrapperHelper.NO_CLASSES);
- } catch (NoSuchMethodException ex) {
- //ignore for now
- }
- }
- if (getMethod == null
- && "return".equals(partName)) {
- //RI generated code uses this
- try {
- getMethod = valueClass.getMethod("get_return", AbstractWrapperHelper.NO_CLASSES);
- } catch (NoSuchMethodException ex) {
- try {
- getMethod = valueClass.getMethod("is_return",
- new Class[0]);
- } catch (NoSuchMethodException ex2) {
- //ignore for now
- }
- }
- }
- if (getMethod == null && elField != null) {
- getAccessor = JAXBUtils.nameToIdentifier(elField.getName(), JAXBUtils.IdentifierType.GETTER);
- setAccessor = JAXBUtils.nameToIdentifier(elField.getName(), JAXBUtils.IdentifierType.SETTER);
- try {
- getMethod = valueClass.getMethod(getAccessor, AbstractWrapperHelper.NO_CLASSES);
- } catch (NoSuchMethodException ex) {
- //ignore for now
- }
- }
- String setAccessor2 = setAccessor;
- if ("return".equals(partName)) {
- //some versions of jaxb map "return" to "set_return" instead of "setReturn"
- setAccessor2 = "set_return";
- }
-
- for (Method method : allMethods) {
- if (method.getParameterTypes() != null && method.getParameterTypes().length == 1
- && (setAccessor.equals(method.getName())
- || setAccessor2.equals(method.getName()))) {
- setMethod = method;
- break;
- }
- }
-
- getMethods.add(getMethod);
- setMethods.add(setMethod);
- if (setMethod != null
- && JAXBElement.class.isAssignableFrom(setMethod.getParameterTypes()[0])) {
-
- Type t = setMethod.getGenericParameterTypes()[0];
- Class<?> pcls = null;
- if (t instanceof ParameterizedType) {
- t = ((ParameterizedType)t).getActualTypeArguments()[0];
- }
- if (t instanceof Class) {
- pcls = (Class<?>)t;
- }
-
- String methodName = "create" + wrapperType.getSimpleName()
- + setMethod.getName().substring(3);
-
- for (Method m : allOFMethods) {
- if (m.getName().equals(methodName)
- && m.getParameterTypes().length == 1
- && (pcls == null
- || pcls.equals(m.getParameterTypes()[0]))) {
- jaxbMethods.add(m);
- }
- }
- } else {
- jaxbMethods.add(null);
- }
-
- if (elField != null) {
- // JAXB Type get XmlElement Annotation
- XmlElement el = elField.getAnnotation(XmlElement.class);
- if (el != null
- && (partName.equals(el.name())
- || "##default".equals(el.name()))) {
- ReflectionUtil.setAccessible(elField);
- fields.add(elField);
- } else {
- if (getMethod == null && setMethod == null) {
- if (el != null) {
- LOG.warning("Could not create accessor for property " + partName
- + " of type " + wrapperType.getName() + " as the @XmlElement "
- + "defines the name as " + el.name());
- } else {
- LOG.warning("Could not create accessor for property " + partName
- + " of type " + wrapperType.getName());
- }
- }
- fields.add(null);
- }
- } else {
- fields.add(null);
- }
-
- }
-
- return createWrapperHelper(getBus(), wrapperType,
- setMethods.toArray(new Method[0]),
- getMethods.toArray(new Method[0]),
- jaxbMethods.toArray(new Method[0]),
- fields.toArray(new Field[0]),
- objectFactory);
- }
-
- public static boolean isInBuiltInSchemas(DOMResult schema) {
- return BUILT_IN_SCHEMAS.containsValue(schema);
- }
-
- private static Field getElField(String partName, final Class<?> wrapperType) {
- String fieldName = JAXBUtils.nameToIdentifier(partName, JAXBUtils.IdentifierType.VARIABLE);
- Field[] fields = ReflectionUtil.getDeclaredFields(wrapperType);
- for (Field field : fields) {
- XmlElement el = field.getAnnotation(XmlElement.class);
- if (el != null
- && partName.equals(el.name())) {
- return field;
- }
-
- XmlElementRef xmlElementRefAnnotation = field.getAnnotation(XmlElementRef.class);
- if (xmlElementRefAnnotation != null && partName.equals(xmlElementRefAnnotation.name())) {
- return field;
- }
-
- if (field.getName().equals(fieldName)) {
- return field;
- }
- }
- return null;
- }
-
-
- private static WrapperHelper createWrapperHelper(Bus bus, Class<?> wrapperType, Method[] setMethods,
- Method[] getMethods, Method[] jaxbMethods,
- Field[] fields, Object objectFactory) {
-
- WrapperHelper wh = compileWrapperHelper(bus, wrapperType, setMethods, getMethods, jaxbMethods, fields,
- objectFactory);
-
- if (wh == null) {
- wh = new JAXBWrapperHelper(wrapperType, setMethods, getMethods, jaxbMethods, fields,
- objectFactory);
- }
- return wh;
- }
-
- private static WrapperHelper compileWrapperHelper(Bus bus, Class<?> wrapperType, Method[] setMethods,
- Method[] getMethods, Method[] jaxbMethods,
- Field[] fields, Object objectFactory) {
- try {
- WrapperHelperCreator creator = bus.getExtension(WrapperHelperCreator.class);
- return creator.compile(wrapperType, setMethods, getMethods,
- jaxbMethods, fields, objectFactory);
- } catch (Throwable t) {
- // Some error - probably a bad version of ASM or similar
- return null;
- }
- }
-
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxb/JAXBEncoderDecoder.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxb/JAXBEncoderDecoder.java
deleted file mode 100644
index 4d177e9..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxb/JAXBEncoderDecoder.java
+++ /dev/null
@@ -1,1119 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.cxf.jaxb;
-
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Array;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.Field;
-import java.lang.reflect.GenericArrayType;
-import java.lang.reflect.Member;
-import java.lang.reflect.Method;
-import java.lang.reflect.Modifier;
-import java.lang.reflect.ParameterizedType;
-import java.lang.reflect.Type;
-import java.security.AccessController;
-import java.security.PrivilegedActionException;
-import java.security.PrivilegedExceptionAction;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Calendar;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.Enumeration;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.TreeMap;
-import java.util.logging.Logger;
-
-import javax.xml.bind.JAXBElement;
-import javax.xml.bind.JAXBException;
-import javax.xml.bind.Marshaller;
-import javax.xml.bind.Unmarshaller;
-import javax.xml.bind.annotation.XmlAccessOrder;
-import javax.xml.bind.annotation.XmlAccessType;
-import javax.xml.bind.annotation.XmlAccessorOrder;
-import javax.xml.bind.annotation.XmlAttribute;
-import javax.xml.bind.annotation.XmlType;
-import javax.xml.bind.annotation.adapters.HexBinaryAdapter;
-import javax.xml.bind.attachment.AttachmentMarshaller;
-import javax.xml.bind.attachment.AttachmentUnmarshaller;
-import javax.xml.namespace.NamespaceContext;
-import javax.xml.namespace.QName;
-import javax.xml.stream.Location;
-import javax.xml.stream.XMLEventReader;
-import javax.xml.stream.XMLEventWriter;
-import javax.xml.stream.XMLStreamConstants;
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamReader;
-import javax.xml.stream.XMLStreamWriter;
-import javax.xml.stream.util.StreamReaderDelegate;
-import javax.xml.transform.stream.StreamResult;
-
-import org.w3c.dom.Attr;
-import org.w3c.dom.DocumentFragment;
-import org.w3c.dom.Element;
-import org.w3c.dom.NamedNodeMap;
-import org.w3c.dom.Node;
-
-import org.apache.cxf.common.i18n.Message;
-import org.apache.cxf.common.jaxb.JAXBUtils;
-import org.apache.cxf.common.logging.LogUtils;
-import org.apache.cxf.common.util.ReflectionUtil;
-import org.apache.cxf.common.util.StringUtils;
-import org.apache.cxf.helpers.CastUtils;
-import org.apache.cxf.helpers.DOMUtils;
-import org.apache.cxf.interceptor.Fault;
-import org.apache.cxf.service.model.MessagePartInfo;
-import org.apache.cxf.service.model.SchemaInfo;
-import org.apache.cxf.staxutils.DepthXMLStreamReader;
-import org.apache.cxf.staxutils.StaxUtils;
-import org.apache.cxf.staxutils.W3CDOMStreamWriter;
-import org.apache.cxf.staxutils.W3CNamespaceContext;
-import org.apache.ws.commons.schema.XmlSchemaElement;
-import org.apache.ws.commons.schema.XmlSchemaSimpleType;
-import org.apache.ws.commons.schema.XmlSchemaSimpleTypeList;
-import org.apache.ws.commons.schema.constants.Constants;
-
-/**
- * Utility functions for JAXB.
- */
-public final class JAXBEncoderDecoder {
- private static final class AddXSITypeStreamReader extends StreamReaderDelegate {
- private boolean first = true;
- private int offset = 1;
- private final QName typeQName;
-
- private AddXSITypeStreamReader(XMLStreamReader reader, QName typeQName) {
- super(reader);
- this.typeQName = typeQName;
- }
-
- public int getAttributeCount() {
- return super.getAttributeCount() + offset;
- }
-
- public String getAttributeLocalName(int index) {
- if (first && index == 0) {
- return "type";
- }
- return super.getAttributeLocalName(index - offset);
- }
-
- public QName getAttributeName(int index) {
- if (first && index == 0) {
- return new QName(Constants.URI_2001_SCHEMA_XSI, "type");
- }
- return super.getAttributeName(index - offset);
- }
-
- public String getAttributeNamespace(int index) {
- if (first && index == 0) {
- return Constants.URI_2001_SCHEMA_XSI;
- }
- return super.getAttributeNamespace(index - offset);
- }
-
- public String getAttributePrefix(int index) {
- if (first && index == 0) {
- return "xsi";
- }
- return super.getAttributePrefix(index - offset);
- }
-
- public String getAttributeType(int index) {
- if (first && index == 0) {
- return "#TEXT";
- }
- return super.getAttributeType(index - offset);
- }
-
- public String getAttributeValue(int index) {
- if (first && index == 0) {
- String pfx = this.getNamespaceContext().getPrefix(typeQName.getNamespaceURI());
- if (StringUtils.isEmpty(pfx)) {
- return typeQName.getLocalPart();
- }
- return pfx + ":" + typeQName.getLocalPart();
- }
- return super.getAttributeValue(index - offset);
- }
-
- public int next() throws XMLStreamException {
- first = false;
- offset = 0;
- return super.next();
- }
-
- public String getAttributeValue(String namespaceUri,
- String localName) {
- if (first
- && Constants.URI_2001_SCHEMA_XSI.equals(namespaceUri)
- && "type".equals(localName)) {
- String pfx = this.getNamespaceContext().getPrefix(typeQName.getNamespaceURI());
- if (StringUtils.isEmpty(pfx)) {
- return typeQName.getLocalPart();
- }
- return pfx + ":" + typeQName.getLocalPart();
- }
- return super.getAttributeValue(namespaceUri, localName);
- }
- }
-
- private static final Logger LOG = LogUtils.getLogger(JAXBEncoderDecoder.class);
-
- private JAXBEncoderDecoder() {
- }
-
- public static void marshall(Marshaller marshaller,
- Object elValue,
- MessagePartInfo part,
- Object source) {
- try {
- // The Marshaller.JAXB_FRAGMENT will tell the Marshaller not to
- // generate the xml declaration.
- marshaller.setProperty(Marshaller.JAXB_FRAGMENT, true);
- marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, false);
- } catch (javax.xml.bind.PropertyException e) {
- // intentionally empty.
- }
-
- Class<?> cls = null;
- if (part != null) {
- cls = part.getTypeClass();
- }
-
- if (cls == null) {
- cls = null != elValue ? elValue.getClass() : null;
- }
-
- if (cls != null && cls.isArray() && elValue instanceof Collection) {
- Collection<?> col = (Collection<?>)elValue;
- elValue = col.toArray((Object[])Array.newInstance(cls.getComponentType(), col.size()));
- }
-
- try {
- Object mObj = elValue;
- QName elName = null;
- if (part != null) {
- elName = part.getConcreteName();
- }
-
- if (null != elName) {
-
- if (part != null && part.getXmlSchema() instanceof XmlSchemaElement) {
-
- XmlSchemaElement el = (XmlSchemaElement)part.getXmlSchema();
-
- if (mObj.getClass().isArray()
- && el.getSchemaType() instanceof XmlSchemaSimpleType
- && ((XmlSchemaSimpleType)el.getSchemaType()).
- getContent() instanceof XmlSchemaSimpleTypeList) {
- mObj = Arrays.asList((Object[])mObj);
- writeObject(marshaller, source, newJAXBElement(elName, cls, mObj));
- } else if (part.getMessageInfo().getOperation().isUnwrapped()
- && (mObj.getClass().isArray() || mObj instanceof List)
- && el.getMaxOccurs() != 1) {
- writeArrayObject(marshaller,
- source,
- elName,
- mObj);
- } else {
- writeObject(marshaller, source, newJAXBElement(elName, cls, mObj));
- }
- } else if (byte[].class == cls && part.getTypeQName() != null
- && "hexBinary".equals(part.getTypeQName().getLocalPart())) {
- mObj = new HexBinaryAdapter().marshal((byte[])mObj);
- writeObject(marshaller, source, newJAXBElement(elName, String.class, mObj));
- } else if (mObj instanceof JAXBElement) {
- writeObject(marshaller, source, mObj);
- } else if (marshaller.getSchema() != null) {
- //force xsi:type so types can be validated instead of trying to
- //use the RPC/lit element names that aren't in the schema
- writeObject(marshaller, source, newJAXBElement(elName, Object.class, mObj));
- } else {
- writeObject(marshaller, source, newJAXBElement(elName, cls, mObj));
- }
- } else {
- writeObject(marshaller, source, mObj);
- }
- } catch (Fault ex) {
- throw ex;
- } catch (javax.xml.bind.MarshalException ex) {
- Message faultMessage = new Message("MARSHAL_ERROR", LOG, ex.getLinkedException()
- .getMessage());
- throw new Fault(faultMessage, ex);
- } catch (Exception ex) {
- throw new Fault(new Message("MARSHAL_ERROR", LOG, ex.getMessage()), ex);
- }
- }
- @SuppressWarnings({ "unchecked", "rawtypes" })
- private static JAXBElement<?> newJAXBElement(QName elName, Class<?> cls, Object mObj) {
- if (mObj instanceof JAXBElement) {
- return (JAXBElement)mObj;
- }
- if (cls == null && mObj != null) {
- cls = mObj.getClass();
- }
- return new JAXBElement(elName, cls, mObj);
- }
-
- //TODO: cache the JAXBRIContext
- public static void marshalWithBridge(QName qname,
- Class<?> cls,
- Annotation[] anns,
- Set<Class<?>> ctxClasses,
- Object elValue,
- Object source, AttachmentMarshaller am) {
- try {
- JAXBUtils.BridgeWrapper bridge = JAXBUtils.createBridge(ctxClasses, qname, cls, anns);
-
- if (source instanceof XMLStreamWriter) {
- bridge.marshal(elValue, (XMLStreamWriter)source, am);
- } else if (source instanceof OutputStream) {
- //the namespace is missing when marshal the xsd:QName type
- //to the OutputStream directly
- java.io.StringWriter sw = new java.io.StringWriter();
- StreamResult s1 = new StreamResult(sw);
- bridge.marshal(elValue, s1);
- ((OutputStream)source).write(sw.toString().getBytes());
- } else if (source instanceof Node) {
- bridge.marshal(elValue, (Node)source, am);
- } else {
- throw new Fault(new Message("UNKNOWN_SOURCE", LOG, source.getClass().getName()));
- }
- } catch (javax.xml.bind.MarshalException ex) {
- Message faultMessage = new Message("MARSHAL_ERROR", LOG, ex.getLinkedException()
- .getMessage());
- throw new Fault(faultMessage, ex);
- } catch (Exception ex) {
- throw new Fault(new Message("MARSHAL_ERROR", LOG, ex.getMessage()), ex);
- }
-
- }
-
-// TODO: cache the JAXBRIContext
- public static Object unmarshalWithBridge(QName qname,
- Class<?> cls,
- Annotation[] anns,
- Set<Class<?>> ctxClasses,
- Object source,
- AttachmentUnmarshaller am) {
-
- try {
- JAXBUtils.BridgeWrapper bridge = JAXBUtils.createBridge(ctxClasses, qname, cls, anns);
-
- if (source instanceof XMLStreamReader) {
- //DOMUtils.writeXml(StaxUtils.read((XMLStreamReader)source), System.out);
- return bridge.unmarshal((XMLStreamReader)source, am);
- } else if (source instanceof InputStream) {
- return bridge.unmarshal((InputStream)source);
- } else if (source instanceof Node) {
- return bridge.unmarshal((Node)source, am);
- } else {
- throw new Fault(new Message("UNKNOWN_SOURCE", LOG, source.getClass().getName()));
- }
- } catch (javax.xml.bind.MarshalException ex) {
- Message faultMessage = new Message("MARSHAL_ERROR", LOG, ex.getLinkedException()
- .getMessage());
- throw new Fault(faultMessage, ex);
- } catch (Exception ex) {
- throw new Fault(new Message("MARSHAL_ERROR", LOG, ex.getMessage()), ex);
- }
-
- }
-
- public static void marshallException(Marshaller marshaller, Exception elValue,
- MessagePartInfo part, Object source) {
- XMLStreamWriter writer = getStreamWriter(source);
- QName qn = part.getElementQName();
- try {
- writer.writeStartElement("ns1", qn.getLocalPart(), qn.getNamespaceURI());
- Class<?> cls = part.getTypeClass();
- XmlAccessType accessType = Utils.getXmlAccessType(cls);
- String namespace = part.getElementQName().getNamespaceURI();
- String attNs = namespace;
-
- SchemaInfo sch = part.getMessageInfo().getOperation().getInterface()
- .getService().getSchema(namespace);
- if (sch == null) {
- LOG.warning("Schema associated with " + namespace + " is null");
- namespace = null;
- attNs = null;
- } else {
- if (!sch.isElementFormQualified()) {
- namespace = null;
- }
- if (!sch.isAttributeFormQualified()) {
- attNs = null;
- }
- }
- List<Member> combinedMembers = new ArrayList<>();
-
- for (Field f : Utils.getFields(cls, accessType)) {
- XmlAttribute at = f.getAnnotation(XmlAttribute.class);
- if (at == null) {
- combinedMembers.add(f);
- } else {
- QName fname = new QName(attNs, StringUtils.isEmpty(at.name()) ? f.getName() : at.name());
- ReflectionUtil.setAccessible(f);
- Object o = Utils.getFieldValue(f, elValue);
- DocumentFragment frag = DOMUtils.getEmptyDocument().createDocumentFragment();
- writeObject(marshaller, frag, newJAXBElement(fname, String.class, o));
-
- if (attNs != null) {
- writer.writeAttribute(attNs, fname.getLocalPart(),
- DOMUtils.getAllContent(frag));
- } else {
- writer.writeAttribute(fname.getLocalPart(), DOMUtils.getAllContent(frag));
- }
- }
- }
- for (Method m : Utils.getGetters(cls, accessType)) {
- if (!m.isAnnotationPresent(XmlAttribute.class)) {
- combinedMembers.add(m);
- } else {
- int idx = m.getName().startsWith("get") ? 3 : 2;
- String name = m.getName().substring(idx);
- name = Character.toLowerCase(name.charAt(0)) + name.substring(1);
- XmlAttribute at = m.getAnnotation(XmlAttribute.class);
- QName mname = new QName(namespace, StringUtils.isEmpty(at.name()) ? name : at.name());
- DocumentFragment frag = DOMUtils.getEmptyDocument().createDocumentFragment();
- Object o = Utils.getMethodValue(m, elValue);
- writeObject(marshaller, frag, newJAXBElement(mname, String.class, o));
- if (attNs != null) {
- writer.writeAttribute(attNs, mname.getLocalPart(),
- DOMUtils.getAllContent(frag));
- } else {
- writer.writeAttribute(mname.getLocalPart(), DOMUtils.getAllContent(frag));
- }
- }
- }
-
- XmlAccessorOrder xmlAccessorOrder = cls.getAnnotation(XmlAccessorOrder.class);
- if (xmlAccessorOrder != null && xmlAccessorOrder.value().equals(XmlAccessOrder.ALPHABETICAL)) {
- Collections.sort(combinedMembers, new Comparator<Member>() {
- public int compare(Member m1, Member m2) {
- return m1.getName().compareTo(m2.getName());
- }
- });
- }
- XmlType xmlType = cls.getAnnotation(XmlType.class);
- if (xmlType != null && xmlType.propOrder().length > 1 && !xmlType.propOrder()[0].isEmpty()) {
- final List<String> orderList = Arrays.asList(xmlType.propOrder());
- Collections.sort(combinedMembers, new Comparator<Member>() {
- public int compare(Member m1, Member m2) {
- String m1Name = getName(m1);
- String m2Name = getName(m2);
- int m1Index = orderList.indexOf(m1Name);
- int m2Index = orderList.indexOf(m2Name);
- if (m1Index != -1 && m2Index != -1) {
- return m1Index - m2Index;
- }
- if (m1Index == -1 && m2Index != -1) {
- return 1;
- }
- if (m1Index != -1 && m2Index == -1) {
- return -1;
- }
- return 0;
- }
- });
- }
- for (Member member : combinedMembers) {
- if (member instanceof Field) {
- Field f = (Field)member;
- QName fname = new QName(namespace, f.getName());
- ReflectionUtil.setAccessible(f);
- if (JAXBSchemaInitializer.isArray(f.getGenericType())) {
- writeArrayObject(marshaller, writer, fname, f.get(elValue));
- } else {
- Object o = Utils.getFieldValue(f, elValue);
- writeObject(marshaller, writer, newJAXBElement(fname, String.class, o));
- }
- } else { // it's a Method
- Method m = (Method)member;
- int idx = m.getName().startsWith("get") ? 3 : 2;
- String name = m.getName().substring(idx);
- name = Character.toLowerCase(name.charAt(0)) + name.substring(1);
- QName mname = new QName(namespace, name);
- if (JAXBSchemaInitializer.isArray(m.getGenericReturnType())) {
- writeArrayObject(marshaller, writer, mname, m.invoke(elValue));
- } else {
- Object o = Utils.getMethodValue(m, elValue);
- writeObject(marshaller, writer, newJAXBElement(mname, String.class, o));
- }
- }
- }
-
- writer.writeEndElement();
- writer.flush();
- } catch (Exception e) {
- throw new Fault(new Message("MARSHAL_ERROR", LOG, e.getMessage()), e);
- } finally {
- StaxUtils.close(writer);
- }
- }
-
- private static String getName(Member m1) {
- final String m1Name;
- if (m1 instanceof Field) {
- m1Name = ((Field)m1).getName();
- } else {
- int idx = m1.getName().startsWith("get") ? 3 : 2;
- String name = m1.getName().substring(idx);
- m1Name = Character.toLowerCase(name.charAt(0)) + name.substring(1);
- }
- return m1Name;
- }
- private static void writeArrayObject(Marshaller marshaller,
- Object source,
- QName mname,
- Object mObj) throws Fault, JAXBException {
- // Have to handle this ourselves.... which really
- // sucks.... but what can we do?
- if (mObj == null) {
- return;
- }
- Object objArray;
- final Class<?> cls;
- if (mObj instanceof List) {
- List<?> l = (List<?>)mObj;
- objArray = l.toArray();
- cls = null;
- } else {
- objArray = mObj;
- cls = objArray.getClass().getComponentType();
- }
- int len = Array.getLength(objArray);
- for (int x = 0; x < len; x++) {
- Object o = Array.get(objArray, x);
- writeObject(marshaller, source,
- newJAXBElement(mname, cls == null ? o.getClass() : cls, o));
- }
- }
-
- public static Exception unmarshallException(Unmarshaller u,
- Object source,
- MessagePartInfo part) {
- XMLStreamReader reader;
- if (source instanceof XMLStreamReader) {
- reader = (XMLStreamReader)source;
- } else if (source instanceof Element) {
- reader = StaxUtils.createXMLStreamReader((Element)source);
- try {
- // advance into the node
- reader.nextTag();
- } catch (XMLStreamException e) {
- // ignore
- }
- } else {
- throw new Fault(new Message("UNKNOWN_SOURCE", LOG, source.getClass().getName()));
- }
- try {
- QName qn = part.getElementQName();
- if (!qn.equals(reader.getName())) {
- throw new Fault(new Message("ELEMENT_NAME_MISMATCH", LOG, qn, reader.getName()));
- }
-
- Class<?> cls = part.getTypeClass();
- Object obj;
- try {
- Constructor<?> cons = cls.getConstructor();
- obj = cons.newInstance();
- } catch (NoSuchMethodException nse) {
- Constructor<?> cons = cls.getConstructor(new Class[] {String.class});
- obj = cons.newInstance(new Object[1]);
- }
-
- XmlAccessType accessType = Utils.getXmlAccessType(cls);
- reader.nextTag();
- while (reader.getEventType() == XMLStreamConstants.START_ELEMENT) {
- QName q = reader.getName();
- String fieldName = q.getLocalPart();
- Field f = Utils.getField(cls, accessType, fieldName);
- if (f != null) {
- Type type = f.getGenericType();
- ReflectionUtil.setAccessible(f);
- if (JAXBSchemaInitializer.isArray(type)) {
- Class<?> compType = JAXBSchemaInitializer.getArrayComponentType(type);
- List<Object> ret = unmarshallArray(u, reader, q, compType, createList(type));
- Object o = ret;
- if (!isList(type)) {
- if (compType.isPrimitive()) {
- o = java.lang.reflect.Array.newInstance(compType, ret.size());
- for (int x = 0; x < ret.size(); x++) {
- Array.set(o, x, ret.get(x));
- }
- } else {
- o = ret.toArray((Object[]) Array.newInstance(compType, ret.size()));
- }
- }
-
- f.set(obj, o);
- } else {
- Object o = getElementValue(u.unmarshal(reader, Utils.getFieldType(f)));
- Utils.setFieldValue(f, obj, o);
- }
- } else {
- String s = StringUtils.capitalize(q.getLocalPart());
- Method m = Utils.getMethod(cls, accessType, "get" + s);
- if (m == null) {
- m = Utils.getMethod(cls, accessType, "is" + s);
- }
- Type type = m.getGenericReturnType();
- Object o;
- if (JAXBSchemaInitializer.isArray(type)) {
- Class<?> compType = JAXBSchemaInitializer
- .getArrayComponentType(type);
- List<Object> ret = unmarshallArray(u, reader,
- q,
- compType,
- createList(type));
- o = ret;
- if (!isList(type)) {
- if (compType.isPrimitive()) {
- o = java.lang.reflect.Array.newInstance(compType, ret.size());
- for (int x = 0; x < ret.size(); x++) {
- Array.set(o, x, ret.get(x));
- }
- } else {
- o = ret.toArray((Object[])Array.newInstance(compType, ret.size()));
- }
- }
- } else {
- o = getElementValue(u.unmarshal(reader, Utils.getMethodReturnType(m)));
- }
- Method m2 = Utils.getMethod(cls, accessType, "set" + s, m.getReturnType());
- if (m2 != null) {
- if (JAXBSchemaInitializer.isArray(type)) {
- m2.invoke(obj, o);
- } else {
- Utils.setMethodValue(m, m2, obj, o);
- }
- } else {
- Field fn = ReflectionUtil.getDeclaredField(cls, q.getLocalPart());
- if (fn != null) {
- ReflectionUtil.setAccessible(fn);
- fn.set(obj, o);
- }
- }
- }
- if (reader.getEventType() == XMLStreamConstants.END_ELEMENT && q.equals(reader.getName())) {
- reader.next();
- }
- }
- return (Exception)obj;
- } catch (Exception e) {
- throw new Fault(new Message("MARSHAL_ERROR", LOG, e.getMessage()), e);
- }
- }
-
- private static void writeObject(Marshaller u, Object source, Object mObj) throws Fault, JAXBException {
- if (source instanceof XMLStreamWriter) {
- // allows the XML Stream Writer to adjust it's behaviour based on the state of the unmarshaller
- if (source instanceof MarshallerAwareXMLWriter) {
- ((MarshallerAwareXMLWriter) source).setMarshaller(u);
- }
- u.marshal(mObj, (XMLStreamWriter)source);
- } else if (source instanceof OutputStream) {
- u.marshal(mObj, (OutputStream)source);
- } else if (source instanceof Node) {
- u.marshal(mObj, (Node)source);
- } else if (source instanceof XMLEventWriter) {
- // allows the XML Event Writer to adjust it's behaviour based on the state of the unmarshaller
- if (source instanceof MarshallerAwareXMLWriter) {
- ((MarshallerAwareXMLWriter) source).setMarshaller(u);
- }
-
- u.marshal(mObj, (XMLEventWriter)source);
- } else {
- throw new Fault(new Message("UNKNOWN_SOURCE", LOG, source.getClass().getName()));
- }
- }
-
- private static XMLStreamWriter getStreamWriter(Object source) throws Fault {
- if (source instanceof XMLStreamWriter) {
- return (XMLStreamWriter)source;
- } else if (source instanceof OutputStream) {
- return StaxUtils.createXMLStreamWriter((OutputStream)source);
- } else if (source instanceof Node) {
- return new W3CDOMStreamWriter((Element)source);
- }
- throw new Fault(new Message("UNKNOWN_SOURCE", LOG, source.getClass().getName()));
- }
-
-
- public static void marshallNullElement(Marshaller marshaller,
- Object source,
- MessagePartInfo part) {
- Class<?> clazz = part != null ? part.getTypeClass() : null;
- try {
- writeObject(marshaller, source, newJAXBElement(part.getElementQName(), clazz, null));
- } catch (JAXBException e) {
- throw new Fault(new Message("MARSHAL_ERROR", LOG, e.getMessage()), e);
- }
- }
-
-
- public static Object unmarshall(Unmarshaller u,
- Object source,
- MessagePartInfo part,
- boolean unwrap) {
- Class<?> clazz = part != null ? part.getTypeClass() : null;
- if (clazz != null && Exception.class.isAssignableFrom(clazz)
- && Boolean.TRUE.equals(part.getProperty(JAXBDataBinding.class.getName() + ".CUSTOM_EXCEPTION"))) {
- return unmarshallException(u, source, part);
- }
-
- QName elName = part != null ? part.getConcreteName() : null;
- if (clazz != null && clazz.isArray()
- && part.getXmlSchema() instanceof XmlSchemaElement) {
- XmlSchemaElement el = (XmlSchemaElement)part.getXmlSchema();
-
- if (el.getSchemaType() instanceof XmlSchemaSimpleType
- && ((XmlSchemaSimpleType)el.getSchemaType()).getContent()
- instanceof XmlSchemaSimpleTypeList) {
-
- Object obj = unmarshall(u, source, elName, null, unwrap);
- if (clazz.isArray() && obj instanceof List) {
- return ((List<?>)obj).toArray((Object[])Array.newInstance(clazz.getComponentType(),
- ((List<?>)obj).size()));
- }
-
- return obj;
- } else if (part.getMessageInfo().getOperation().isUnwrapped() && el.getMaxOccurs() != 1) {
- // must read ourselves....
- List<Object> ret = unmarshallArray(u, source, elName, clazz.getComponentType(),
- createList(part));
- Object o = ret;
- if (!isList(part)) {
- if (isSet(part)) {
- o = createSet(part, ret);
- } else if (clazz.getComponentType().isPrimitive()) {
- o = java.lang.reflect.Array.newInstance(clazz.getComponentType(), ret.size());
- for (int x = 0; x < ret.size(); x++) {
- Array.set(o, x, ret.get(x));
- }
- } else {
- o = ret.toArray((Object[])Array.newInstance(clazz.getComponentType(), ret.size()));
- }
- }
- return o;
- }
- } else if (byte[].class == clazz && part.getTypeQName() != null
- && "hexBinary".equals(part.getTypeQName().getLocalPart())) {
-
- String obj = (String)unmarshall(u, source, elName, String.class, unwrap);
- return new HexBinaryAdapter().unmarshal(obj);
- } else if (part != null && u.getSchema() != null
- && !(part.getXmlSchema() instanceof XmlSchemaElement)) {
- //Validating RPC/Lit, make sure we don't try a root element name thing
- source = updateSourceWithXSIType(source, part.getTypeQName());
- }
-
- Object o = unmarshall(u, source, elName, clazz, unwrap);
- if (o != null && o.getClass().isArray() && isList(part)) {
- List<Object> ret = createList(part);
- Collections.addAll(ret, (Object[])o);
- o = ret;
- }
- return o;
- }
-
- private static Object updateSourceWithXSIType(Object source, final QName typeQName) {
- if (source instanceof XMLStreamReader
- && typeQName != null) {
- XMLStreamReader reader = (XMLStreamReader)source;
- String type = reader.getAttributeValue(Constants.URI_2001_SCHEMA_XSI, "type");
- if (StringUtils.isEmpty(type)) {
- source = new AddXSITypeStreamReader(reader, typeQName);
- }
- }
- return source;
- }
-
- private static Object createSet(MessagePartInfo part, List<Object> ret) {
- Type genericType = (Type)part.getProperty("generic.type");
- Class<?> tp2 = (Class<?>)((ParameterizedType)genericType).getRawType();
- if (tp2.isInterface()) {
- return new HashSet<>(ret);
- }
- Collection<Object> c;
- try {
- c = CastUtils.cast((Collection<?>)tp2.newInstance());
- } catch (Exception e) {
- c = new HashSet<>();
- }
-
- c.addAll(ret);
- return c;
- }
-
- private static boolean isSet(MessagePartInfo part) {
- if (part.getTypeClass().isArray() && !part.getTypeClass().getComponentType().isPrimitive()) {
- // && Collection.class.isAssignableFrom(part.getTypeClass())) {
- // it's List Para
- //
- Type genericType = (Type)part.getProperty("generic.type");
-
- if (genericType instanceof ParameterizedType) {
- Type tp2 = ((ParameterizedType)genericType).getRawType();
- if (tp2 instanceof Class) {
- return Set.class.isAssignableFrom((Class<?>)tp2);
- }
- }
- }
- return false;
- }
-
- private static List<Object> createList(MessagePartInfo part) {
- Type genericType = (Type)part.getProperty("generic.type");
- return createList(genericType);
- }
- private static List<Object> createList(Type genericType) {
- if (genericType instanceof ParameterizedType) {
- Type tp2 = ((ParameterizedType)genericType).getRawType();
- if (tp2 instanceof Class) {
- Class<?> cls = (Class<?>)tp2;
- if (!cls.isInterface() && List.class.isAssignableFrom(cls)) {
- try {
- return CastUtils.cast((List<?>)cls.newInstance());
- } catch (Exception e) {
- // ignore, just return an ArrayList
- }
- }
- }
- }
- return new ArrayList<>();
- }
-
- private static boolean isList(Type cls) {
- return cls instanceof ParameterizedType;
- }
- private static boolean isList(MessagePartInfo part) {
- if (part.getTypeClass().isArray() && !part.getTypeClass().getComponentType().isPrimitive()) {
- // && Collection.class.isAssignableFrom(part.getTypeClass())) {
- // it's List Para
- //
- Type genericType = (Type)part.getProperty("generic.type");
-
- if (genericType instanceof ParameterizedType) {
- Type tp2 = ((ParameterizedType)genericType).getRawType();
- if (tp2 instanceof Class) {
- return List.class.isAssignableFrom((Class<?>)tp2);
- }
- }
- }
- return false;
- }
-
- private static Object doUnmarshal(final Unmarshaller u,
- final Object source,
- final QName elName,
- final Class<?> clazz,
- final boolean unwrap) throws Exception {
-
- final Object obj;
- boolean unmarshalWithClass = true;
-
- if (clazz == null
- || (!clazz.isPrimitive()
- && !clazz.isArray()
- && !clazz.isEnum()
- && !clazz.equals(Calendar.class)
- && (Modifier.isAbstract(clazz.getModifiers())
- || Modifier.isInterface(clazz.getModifiers())))) {
- unmarshalWithClass = false;
- }
-
- if (clazz != null
- && ("javax.xml.datatype.XMLGregorianCalendar".equals(clazz.getName())
- || "javax.xml.datatype.Duration".equals(clazz.getName()))) {
- // special treat two jaxb defined built-in abstract types
- unmarshalWithClass = true;
- }
- if (source instanceof Node) {
- obj = unmarshalWithClass ? u.unmarshal((Node)source, clazz)
- : u.unmarshal((Node)source);
- } else if (source instanceof DepthXMLStreamReader) {
- // JAXB optimizes a ton of stuff depending on the StreamReader impl. Thus,
- // we REALLY want to pass the original reader in. This is OK with JAXB
- // as it doesn't read beyond the end so the DepthXMLStreamReader state
- // would be OK when it returns. The main winner is FastInfoset where parsing
- // a testcase I have goes from about 300/sec to well over 1000.
-
- DepthXMLStreamReader dr = (DepthXMLStreamReader)source;
- XMLStreamReader reader = dr.getReader();
-
- // allows the XML Stream Reader to adjust it's behaviour based on the state of the unmarshaller
- if (reader instanceof UnmarshallerAwareXMLReader) {
- ((UnmarshallerAwareXMLReader) reader).setUnmarshaller(u);
- }
-
- if (u.getSchema() != null) {
- //validating, but we may need more namespaces
- reader = findExtraNamespaces(reader);
- }
- obj = unmarshalWithClass ? u.unmarshal(reader, clazz) : u
- .unmarshal(dr.getReader());
- } else if (source instanceof XMLStreamReader) {
- XMLStreamReader reader = (XMLStreamReader)source;
-
- // allows the XML Stream Reader to adjust it's behaviour based on the state of the unmarshaller
- if (reader instanceof UnmarshallerAwareXMLReader) {
- ((UnmarshallerAwareXMLReader) reader).setUnmarshaller(u);
- }
-
- if (u.getSchema() != null) {
- //validating, but we may need more namespaces
- reader = findExtraNamespaces(reader);
- }
- obj = unmarshalWithClass ? u.unmarshal(reader, clazz) : u
- .unmarshal(reader);
- } else if (source instanceof XMLEventReader) {
- // allows the XML Event Reader to adjust it's behaviour based on the state of the unmarshaller
- if (source instanceof UnmarshallerAwareXMLReader) {
- ((UnmarshallerAwareXMLReader) source).setUnmarshaller(u);
- }
-
- obj = unmarshalWithClass ? u.unmarshal((XMLEventReader)source, clazz) : u
- .unmarshal((XMLEventReader)source);
- } else if (source == null) {
- throw new Fault(new Message("UNKNOWN_SOURCE", LOG, "null"));
- } else {
- throw new Fault(new Message("UNKNOWN_SOURCE", LOG, source.getClass().getName()));
- }
- return unwrap ? getElementValue(obj) : obj;
- }
- public static Object unmarshall(final Unmarshaller u,
- final Object source,
- final QName elName,
- final Class<?> clazz,
- final boolean unwrap) {
- try {
- return AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() {
- public Object run() throws Exception {
- return doUnmarshal(u, source, elName, clazz, unwrap);
- }
- });
- } catch (PrivilegedActionException e) {
- Exception ex = e.getException();
- if (ex instanceof Fault) {
- throw (Fault)ex;
- }
- if (ex instanceof javax.xml.bind.UnmarshalException) {
- javax.xml.bind.UnmarshalException unmarshalEx = (javax.xml.bind.UnmarshalException)ex;
- if (unmarshalEx.getLinkedException() != null) {
- throw new Fault(new Message("UNMARSHAL_ERROR", LOG,
- unmarshalEx.getLinkedException().getMessage()), ex);
- }
- throw new Fault(new Message("UNMARSHAL_ERROR", LOG,
- unmarshalEx.getMessage()), ex);
- }
- throw new Fault(new Message("UNMARSHAL_ERROR", LOG, ex.getMessage()), ex);
- }
- }
-
- private static XMLStreamReader findExtraNamespaces(XMLStreamReader source) {
- //due to a deficiency in the Stax API, there isn't a way to get all
- //the namespace prefixes that are "valid" at this point. Thus, JAXB
- //cannot set all the prefixes into the validator (which also doesn't allow
- //setting a NSContext, just allows declaring of prefixes) so resolving
- //prefixes and such will fail if they were declared on any of the parent
- //elements.
- //
- //We'll use some reflection to grab the known namespaces from woodstox
- //or the xerces parser and fake extra namespace decls on the root elements.
- //slight performance penalty, but there already is a penalty if you are validating
- //anyway.
-
- NamespaceContext c = source.getNamespaceContext();
- final Map<String, String> nsMap = new TreeMap<>();
- try {
- if (c instanceof W3CNamespaceContext) {
- Element element = ((W3CNamespaceContext)c).getElement();
- while (element != null) {
- NamedNodeMap namedNodeMap = element.getAttributes();
- for (int i = 0; i < namedNodeMap.getLength(); i++) {
- Attr attr = (Attr)namedNodeMap.item(i);
- if (attr.getPrefix() != null && "xmlns".equals(attr.getPrefix())) {
- nsMap.put(attr.getLocalName(), attr.getValue());
- }
- }
- element = (Element)element.getParentNode();
- }
- } else {
- try {
- //Woodstox version
- c = (NamespaceContext)c.getClass().getMethod("createNonTransientNsContext",
- Location.class)
- .invoke(c, new Object[1]);
- } catch (Throwable t) {
- //ignore
- }
- Field f = ReflectionUtil.getDeclaredField(c.getClass(), "mNamespaces");
- ReflectionUtil.setAccessible(f);
- String[] ns = (String[])f.get(c);
- for (int x = 0; x < ns.length; x += 2) {
- if (ns[x] == null) {
- nsMap.put("", ns[x + 1]);
- } else {
- nsMap.put(ns[x], ns[x + 1]);
- }
- }
- }
- } catch (Throwable t) {
- //internal JDK/xerces version
- try {
- Field f = ReflectionUtil.getDeclaredField(c.getClass(), "fNamespaceContext");
- ReflectionUtil.setAccessible(f);
- Object c2 = f.get(c);
- Enumeration<?> enm = (Enumeration<?>)c2.getClass().getMethod("getAllPrefixes").invoke(c2);
- while (enm.hasMoreElements()) {
- String s = (String)enm.nextElement();
- if (s == null) {
- nsMap.put("", c.getNamespaceURI(null));
- } else {
- nsMap.put(s, c.getNamespaceURI(s));
- }
- }
- } catch (Throwable t2) {
- //ignore
- }
- }
- if (!nsMap.isEmpty()) {
- for (int x = 0; x < source.getNamespaceCount(); x++) {
- String pfx = source.getNamespacePrefix(x);
- if (pfx == null) {
- nsMap.remove("");
- } else {
- nsMap.remove(pfx);
- }
- }
- if (!nsMap.isEmpty()) {
- @SuppressWarnings("unchecked")
- final Map.Entry<String, String>[] namespaces
- = nsMap.entrySet().toArray(new Map.Entry[nsMap.size()]);
- //OK. we have extra namespaces. We'll need to wrapper the reader
- //with a new one that will fake extra namespace events
- source = new DepthXMLStreamReader(source) {
- public int getNamespaceCount() {
- if (getDepth() == 0 && isStartElement()) {
- return super.getNamespaceCount() + nsMap.size();
- }
- return super.getNamespaceCount();
- }
-
- public String getNamespacePrefix(int arg0) {
- if (getDepth() == 0 && isStartElement()) {
- int i = super.getNamespaceCount();
- if (arg0 >= i) {
- arg0 -= i;
- return namespaces[arg0].getKey();
- }
- }
- return super.getNamespacePrefix(arg0);
- }
-
- public String getNamespaceURI(int arg0) {
- if (getDepth() == 0 && isStartElement()) {
- int i = super.getNamespaceCount();
- if (arg0 >= i) {
- arg0 -= i;
- return namespaces[arg0].getValue();
- }
- }
- return super.getNamespaceURI(arg0);
- }
-
- };
- }
- }
-
- return source;
- }
-
- public static Object getElementValue(Object obj) {
- if (null == obj) {
- return null;
- }
-
- if (obj instanceof JAXBElement) {
- return ((JAXBElement<?>)obj).getValue();
- }
- return obj;
- }
-
- public static Class<?> getClassFromType(Type t) {
- if (t instanceof Class) {
- return (Class<?>)t;
- } else if (t instanceof GenericArrayType) {
- GenericArrayType g = (GenericArrayType)t;
- return Array.newInstance(getClassFromType(g.getGenericComponentType()), 0).getClass();
- } else if (t instanceof ParameterizedType) {
- ParameterizedType p = (ParameterizedType)t;
- return getClassFromType(p.getRawType());
- }
- // TypeVariable and WildCardType are not handled as it is unlikely such
- // Types will
- // JAXB Code Generated.
- assert false;
- throw new IllegalArgumentException("Cannot get Class object from unknown Type");
- }
-
- public static List<Object> unmarshallArray(Unmarshaller u, Object source,
- QName elName, Class<?> clazz,
- List<Object> ret) {
- try {
- XMLStreamReader reader;
- if (source instanceof XMLStreamReader) {
- reader = (XMLStreamReader)source;
- } else if (source instanceof Element) {
- reader = StaxUtils.createXMLStreamReader((Element)source);
- } else {
- throw new Fault(new Message("UNKNOWN_SOURCE", LOG, source.getClass().getName()));
- }
- while (reader.getName().equals(elName)) {
- JAXBElement<?> type = u.unmarshal(reader, clazz);
- if (type != null) {
- ret.add(type.getValue());
- }
- while (reader.getEventType() != XMLStreamConstants.START_ELEMENT
- && reader.getEventType() != XMLStreamConstants.END_ELEMENT) {
- reader.nextTag();
- }
- }
- return ret;
- } catch (Fault ex) {
- throw ex;
- } catch (javax.xml.bind.MarshalException ex) {
- throw new Fault(new Message("UNMARSHAL_ERROR", LOG, ex.getLinkedException()
- .getMessage()), ex);
- } catch (Exception ex) {
- throw new Fault(new Message("UNMARSHAL_ERROR", LOG, ex.getMessage()), ex);
- }
- }
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxb/JAXBSchemaInitializer.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxb/JAXBSchemaInitializer.java
deleted file mode 100644
index dde712f..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxb/JAXBSchemaInitializer.java
+++ /dev/null
@@ -1,823 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.cxf.jaxb;
-
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Array;
-import java.lang.reflect.Field;
-import java.lang.reflect.GenericArrayType;
-import java.lang.reflect.Method;
-import java.lang.reflect.ParameterizedType;
-import java.lang.reflect.Type;
-import java.lang.reflect.TypeVariable;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.Iterator;
-import java.util.List;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import javax.xml.bind.JAXBContext;
-import javax.xml.bind.annotation.XmlAccessOrder;
-import javax.xml.bind.annotation.XmlAccessType;
-import javax.xml.bind.annotation.XmlAccessorOrder;
-import javax.xml.bind.annotation.XmlElement;
-import javax.xml.bind.annotation.XmlList;
-import javax.xml.bind.annotation.XmlTransient;
-import javax.xml.bind.annotation.XmlType;
-import javax.xml.bind.annotation.adapters.XmlAdapter;
-import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
-import javax.xml.namespace.QName;
-
-import org.apache.cxf.common.i18n.Message;
-import org.apache.cxf.common.jaxb.JAXBBeanInfo;
-import org.apache.cxf.common.jaxb.JAXBContextProxy;
-import org.apache.cxf.common.jaxb.JAXBUtils;
-import org.apache.cxf.common.logging.LogUtils;
-import org.apache.cxf.common.util.StringUtils;
-import org.apache.cxf.common.xmlschema.SchemaCollection;
-import org.apache.cxf.interceptor.Fault;
-import org.apache.cxf.service.ServiceModelVisitor;
-import org.apache.cxf.service.model.FaultInfo;
-import org.apache.cxf.service.model.MessagePartInfo;
-import org.apache.cxf.service.model.SchemaInfo;
-import org.apache.cxf.service.model.ServiceInfo;
-import org.apache.cxf.wsdl.WSDLConstants;
-import org.apache.ws.commons.schema.XmlSchema;
-import org.apache.ws.commons.schema.XmlSchemaComplexType;
-import org.apache.ws.commons.schema.XmlSchemaElement;
-import org.apache.ws.commons.schema.XmlSchemaForm;
-import org.apache.ws.commons.schema.XmlSchemaSequence;
-import org.apache.ws.commons.schema.XmlSchemaSequenceMember;
-import org.apache.ws.commons.schema.XmlSchemaSimpleType;
-import org.apache.ws.commons.schema.XmlSchemaSimpleTypeList;
-import org.apache.ws.commons.schema.XmlSchemaType;
-import org.apache.ws.commons.schema.utils.NamespaceMap;
-
-/**
- * Walks the service model and sets up the element/type names.
- */
-class JAXBSchemaInitializer extends ServiceModelVisitor {
- private static final Logger LOG = LogUtils.getLogger(JAXBSchemaInitializer.class);
-
- private SchemaCollection schemas;
- private JAXBContextProxy context;
- private final boolean qualifiedSchemas;
-
- JAXBSchemaInitializer(ServiceInfo serviceInfo,
- SchemaCollection col,
- JAXBContext context,
- boolean q,
- String defaultNs) {
- super(serviceInfo);
- schemas = col;
- this.context = JAXBUtils.createJAXBContextProxy(context, serviceInfo.getXmlSchemaCollection(), defaultNs);
- this.qualifiedSchemas = q;
- }
-
- static Class<?> getArrayComponentType(Type cls) {
- if (cls instanceof Class) {
- if (((Class<?>)cls).isArray()) {
- return ((Class<?>)cls).getComponentType();
- }
- return (Class<?>)cls;
- } else if (cls instanceof ParameterizedType) {
- for (Type t2 : ((ParameterizedType)cls).getActualTypeArguments()) {
- return getArrayComponentType(t2);
- }
- } else if (cls instanceof GenericArrayType) {
- GenericArrayType gt = (GenericArrayType)cls;
- Class<?> ct = (Class<?>) gt.getGenericComponentType();
- return Array.newInstance(ct, 0).getClass();
- }
- return null;
- }
-
- public JAXBBeanInfo getBeanInfo(Type cls) {
- if (cls instanceof Class) {
- if (((Class<?>)cls).isArray()) {
- return getBeanInfo(((Class<?>)cls).getComponentType());
- }
- return getBeanInfo((Class<?>)cls);
- } else if (cls instanceof ParameterizedType) {
- for (Type t2 : ((ParameterizedType)cls).getActualTypeArguments()) {
- return getBeanInfo(t2);
- }
- } else if (cls instanceof GenericArrayType) {
- GenericArrayType gt = (GenericArrayType)cls;
- Class<?> ct = (Class<?>) gt.getGenericComponentType();
- ct = Array.newInstance(ct, 0).getClass();
-
- return getBeanInfo(ct);
- }
-
- return null;
- }
-
- public JAXBBeanInfo getBeanInfo(Class<?> cls) {
- return getBeanInfo(context, cls);
- }
-
- public static JAXBBeanInfo getBeanInfo(JAXBContextProxy context, Class<?> cls) {
- return JAXBUtils.getBeanInfo(context, cls);
- }
-
- @Override
- public void begin(MessagePartInfo part) {
- // Check to see if the WSDL information has been filled in for us.
- if (part.getTypeQName() != null || part.getElementQName() != null) {
- checkForExistence(part);
- return;
- }
-
- Class<?> clazz = part.getTypeClass();
- if (clazz == null) {
- return;
- }
-
- boolean isFromWrapper = part.getMessageInfo().getOperation().isUnwrapped();
- boolean isList = false;
- if (clazz.isArray()) {
- if (isFromWrapper && !Byte.TYPE.equals(clazz.getComponentType())) {
- clazz = clazz.getComponentType();
- } else if (!isFromWrapper) {
- Annotation[] anns = (Annotation[])part.getProperty("parameter.annotations");
- for (Annotation a : anns) {
- if (a instanceof XmlList) {
- part.setProperty("honor.jaxb.annotations", Boolean.TRUE);
- clazz = clazz.getComponentType();
- isList = true;
- }
- }
- }
- }
-
- Annotation[] anns = (Annotation[])part.getProperty("parameter.annotations");
- XmlJavaTypeAdapter jta = findFromTypeAdapter(context, clazz, anns);
- JAXBBeanInfo jtaBeanInfo = null;
- if (jta != null) {
- jtaBeanInfo = findFromTypeAdapter(context, jta.value());
- }
- JAXBBeanInfo beanInfo = getBeanInfo(clazz);
- if (jtaBeanInfo != beanInfo && jta != null) {
- beanInfo = jtaBeanInfo;
- if (anns == null) {
- anns = new Annotation[] {jta};
- } else {
- boolean found = false;
- for (Annotation t : anns) {
- if (t == jta) {
- found = true;
- }
- }
- if (!found) {
- Annotation[] tmp = new Annotation[anns.length + 1];
- System.arraycopy(anns, 0, tmp, 0, anns.length);
- tmp[anns.length] = jta;
- anns = tmp;
- }
- }
- part.setProperty("parameter.annotations", anns);
- part.setProperty("honor.jaxb.annotations", Boolean.TRUE);
- }
- if (beanInfo == null) {
- if (Exception.class.isAssignableFrom(clazz)) {
- QName name = (QName)part.getMessageInfo().getProperty("elementName");
- part.setElementQName(name);
- buildExceptionType(part, clazz);
- }
- return;
- }
- boolean isElement = beanInfo.isElement()
- && !Boolean.TRUE.equals(part.getMessageInfo().getOperation()
- .getProperty("operation.force.types"));
- boolean hasType = !beanInfo.getTypeNames().isEmpty();
- if (isElement && isFromWrapper && hasType) {
- //if there is both a Global element and a global type, AND we are in a wrapper,
- //make sure we use the type instead of a ref to the element to
- //match the rules for wrapped/unwrapped
- isElement = false;
- }
-
- part.setElement(isElement);
-
- if (isElement) {
- QName name = new QName(beanInfo.getElementNamespaceURI(null),
- beanInfo.getElementLocalName(null));
- XmlSchemaElement el = schemas.getElementByQName(name);
- if (el != null && el.getRef().getTarget() != null) {
- part.setTypeQName(el.getRef().getTargetQName());
- } else {
- part.setElementQName(name);
- }
- part.setXmlSchema(el);
- } else {
- QName typeName = getTypeName(beanInfo);
- if (typeName != null) {
- XmlSchemaType type = schemas.getTypeByQName(typeName);
- if (isList && type instanceof XmlSchemaSimpleType) {
- XmlSchemaSimpleType simpleType = new XmlSchemaSimpleType(type.getParent(), false);
- XmlSchemaSimpleTypeList list = new XmlSchemaSimpleTypeList();
- XmlSchemaSimpleType stype = (XmlSchemaSimpleType)type;
- list.setItemTypeName(stype.getQName());
- simpleType.setContent(list);
- part.setXmlSchema(simpleType);
- if (part.getConcreteName() == null) {
- part.setConcreteName(new QName(null, part.getName().getLocalPart()));
- }
- } else {
- part.setTypeQName(typeName);
- part.setXmlSchema(type);
- }
- }
- }
- }
-
- static XmlJavaTypeAdapter findFromTypeAdapter(JAXBContextProxy context, Class<?> clazz, Annotation[] anns) {
- if (anns != null) {
- for (Annotation a : anns) {
- if (XmlJavaTypeAdapter.class.isAssignableFrom(a.annotationType())) {
- JAXBBeanInfo ret = findFromTypeAdapter(context, ((XmlJavaTypeAdapter)a).value());
- if (ret != null) {
- return (XmlJavaTypeAdapter)a;
- }
- }
- }
- }
- if (clazz != null) {
- XmlJavaTypeAdapter xjta = clazz.getAnnotation(XmlJavaTypeAdapter.class);
- if (xjta != null) {
- JAXBBeanInfo ret = findFromTypeAdapter(context, xjta.value());
- if (ret != null) {
- return xjta;
- }
- }
- }
- return null;
- }
-
- static JAXBBeanInfo findFromTypeAdapter(JAXBContextProxy context,
- @SuppressWarnings("rawtypes")
- Class<? extends XmlAdapter> aclass) {
- Class<?> c2 = aclass;
- Type sp = c2.getGenericSuperclass();
- while (!XmlAdapter.class.equals(c2) && c2 != null) {
- sp = c2.getGenericSuperclass();
- c2 = c2.getSuperclass();
- }
- if (sp instanceof ParameterizedType) {
- Type tp = ((ParameterizedType)sp).getActualTypeArguments()[0];
- if (tp instanceof Class) {
- return getBeanInfo(context, (Class<?>)tp);
- }
- }
- return null;
- }
-
- private QName getTypeName(JAXBBeanInfo beanInfo) {
- Iterator<QName> itr = beanInfo.getTypeNames().iterator();
- if (!itr.hasNext()) {
- return null;
- }
-
- return itr.next();
- }
- public void checkForExistence(MessagePartInfo part) {
- QName qn = part.getElementQName();
- if (qn != null) {
- XmlSchemaElement el = schemas.getElementByQName(qn);
- if (el == null) {
- Class<?> clazz = part.getTypeClass();
- if (clazz == null) {
- return;
- }
-
- boolean isFromWrapper = part.getMessageInfo().getOperation().isUnwrapped();
- if (isFromWrapper && clazz.isArray() && !Byte.TYPE.equals(clazz.getComponentType())) {
- clazz = clazz.getComponentType();
- }
- JAXBBeanInfo beanInfo = getBeanInfo(clazz);
- if (beanInfo == null) {
- if (Exception.class.isAssignableFrom(clazz)) {
- QName name = (QName)part.getMessageInfo().getProperty("elementName");
- part.setElementQName(name);
- buildExceptionType(part, clazz);
- }
- return;
- }
-
- QName typeName = getTypeName(beanInfo);
-
- createBridgeXsElement(part, qn, typeName);
- } else if (part.getXmlSchema() == null) {
- part.setXmlSchema(el);
- }
- }
- }
-
- private void createBridgeXsElement(MessagePartInfo part, QName qn, QName typeName) {
- SchemaInfo schemaInfo = serviceInfo.getSchema(qn.getNamespaceURI());
- if (schemaInfo != null) {
- XmlSchemaElement el = schemaInfo.getElementByQName(qn);
- if (el == null) {
- createXsElement(schemaInfo.getSchema(), part, typeName, schemaInfo);
-
- } else if (!typeName.equals(el.getSchemaTypeName())) {
- throw new Fault(new Message("CANNOT_CREATE_ELEMENT", LOG,
- qn, typeName, el.getSchemaTypeName()));
- }
- return;
- }
-
- XmlSchema schema = schemas.newXmlSchemaInCollection(qn.getNamespaceURI());
- if (qualifiedSchemas) {
- schema.setElementFormDefault(XmlSchemaForm.QUALIFIED);
- }
- schemaInfo = new SchemaInfo(qn.getNamespaceURI(), qualifiedSchemas, false);
- schemaInfo.setSchema(schema);
-
- createXsElement(schema, part, typeName, schemaInfo);
-
- NamespaceMap nsMap = new NamespaceMap();
- nsMap.add(WSDLConstants.CONVENTIONAL_TNS_PREFIX, schema.getTargetNamespace());
- nsMap.add(WSDLConstants.NP_SCHEMA_XSD, WSDLConstants.NS_SCHEMA_XSD);
- schema.setNamespaceContext(nsMap);
-
- serviceInfo.addSchema(schemaInfo);
- }
-
- private XmlSchemaElement createXsElement(XmlSchema schema,
- MessagePartInfo part,
- QName typeName, SchemaInfo schemaInfo) {
- XmlSchemaElement el = new XmlSchemaElement(schema, true);
- el.setName(part.getElementQName().getLocalPart());
- el.setNillable(true);
- el.setSchemaTypeName(typeName);
- part.setXmlSchema(el);
- schemaInfo.setElement(null);
- return el;
- }
-
- public void end(FaultInfo fault) {
- MessagePartInfo part = fault.getFirstMessagePart();
- Class<?> cls = part.getTypeClass();
- Class<?> cl2 = (Class<?>)fault.getProperty(Class.class.getName());
- if (cls != cl2) {
- QName name = (QName)fault.getProperty("elementName");
- part.setElementQName(name);
- JAXBBeanInfo beanInfo = getBeanInfo(cls);
- if (beanInfo == null) {
- throw new Fault(new Message("NO_BEAN_INFO", LOG, cls.getName()));
- }
- SchemaInfo schemaInfo = serviceInfo.getSchema(part.getElementQName().getNamespaceURI());
- if (schemaInfo != null
- && !isExistSchemaElement(schemaInfo.getSchema(), part.getElementQName())) {
-
- XmlSchemaElement el = new XmlSchemaElement(schemaInfo.getSchema(), true);
- el.setName(part.getElementQName().getLocalPart());
- el.setNillable(true);
-
- schemaInfo.setElement(null);
-
- Iterator<QName> itr = beanInfo.getTypeNames().iterator();
- if (!itr.hasNext()) {
- return;
- }
- QName typeName = itr.next();
- el.setSchemaTypeName(typeName);
- }
- } else if (part.getXmlSchema() == null) {
- try {
- cls.getConstructor(new Class[] {String.class});
- } catch (Exception e) {
- try {
- cls.getConstructor(new Class[0]);
- } catch (Exception e2) {
- //no String or default constructor, we cannot use it
- return;
- }
- }
-
- //not mappable in JAXBContext directly, we'll have to do it manually :-(
- SchemaInfo schemaInfo = serviceInfo.getSchema(part.getElementQName().getNamespaceURI());
- if (schemaInfo == null
- || isExistSchemaElement(schemaInfo.getSchema(), part.getElementQName())) {
- return;
- }
-
- XmlSchemaElement el = new XmlSchemaElement(schemaInfo.getSchema(), true);
- el.setName(part.getElementQName().getLocalPart());
-
- schemaInfo.setElement(null);
-
- part.setXmlSchema(el);
-
- XmlSchemaComplexType ct = new XmlSchemaComplexType(schemaInfo.getSchema(), false);
- el.setSchemaType(ct);
- XmlSchemaSequence seq = new XmlSchemaSequence();
- ct.setParticle(seq);
-
- Method[] methods = cls.getMethods();
- for (Method m : methods) {
- if (m.getName().startsWith("get")
- || m.getName().startsWith("is")) {
- int beginIdx = m.getName().startsWith("get") ? 3 : 2;
- try {
- m.getDeclaringClass().getMethod("set" + m.getName().substring(beginIdx),
- m.getReturnType());
-
- JAXBBeanInfo beanInfo = getBeanInfo(m.getReturnType());
- if (beanInfo != null) {
- el = new XmlSchemaElement(schemaInfo.getSchema(), false);
- el.setName(m.getName().substring(beginIdx));
- Iterator<QName> itr = beanInfo.getTypeNames().iterator();
- if (!itr.hasNext()) {
- return;
- }
- QName typeName = itr.next();
- el.setSchemaTypeName(typeName);
- }
-
- seq.getItems().add(el);
- } catch (Exception e) {
- //not mappable
- }
- }
- }
- }
- }
-
-
- private void buildExceptionType(MessagePartInfo part, Class<?> cls) {
- SchemaInfo schemaInfo = null;
- for (SchemaInfo s : serviceInfo.getSchemas()) {
- if (s.getNamespaceURI().equals(part.getElementQName().getNamespaceURI())) {
- schemaInfo = s;
- break;
- }
- }
- XmlAccessorOrder xmlAccessorOrder = cls.getAnnotation(XmlAccessorOrder.class);
- XmlType xmlTypeAnno = cls.getAnnotation(XmlType.class);
- String[] propertyOrder = null;
- boolean respectXmlTypeNS = false;
- XmlSchema faultBeanSchema = null;
- if (xmlTypeAnno != null && !StringUtils.isEmpty(xmlTypeAnno.namespace())
- && !xmlTypeAnno.namespace().equals(part.getElementQName().getNamespaceURI())) {
- respectXmlTypeNS = true;
- NamespaceMap nsMap = new NamespaceMap();
- nsMap.add(WSDLConstants.CONVENTIONAL_TNS_PREFIX, xmlTypeAnno.namespace());
- nsMap.add(WSDLConstants.NP_SCHEMA_XSD, WSDLConstants.NS_SCHEMA_XSD);
-
- SchemaInfo faultBeanSchemaInfo = createSchemaIfNeeded(xmlTypeAnno.namespace(), nsMap);
- faultBeanSchema = faultBeanSchemaInfo.getSchema();
- }
-
- if (xmlTypeAnno != null && xmlTypeAnno.propOrder().length > 0) {
- propertyOrder = xmlTypeAnno.propOrder();
- //TODO: handle @XmlAccessOrder
- }
-
- if (schemaInfo == null) {
- NamespaceMap nsMap = new NamespaceMap();
- nsMap.add(WSDLConstants.CONVENTIONAL_TNS_PREFIX, part.getElementQName().getNamespaceURI());
- nsMap.add(WSDLConstants.NP_SCHEMA_XSD, WSDLConstants.NS_SCHEMA_XSD);
- schemaInfo = createSchemaIfNeeded(part.getElementQName().getNamespaceURI(), nsMap);
-
- }
- XmlSchema schema = schemaInfo.getSchema();
-
-
- // Before updating everything, make sure we haven't added this
- // type yet. Multiple methods that throw the same exception
- // types will cause duplicates.
- String faultTypeName = xmlTypeAnno != null && !StringUtils.isEmpty(xmlTypeAnno.name())
- ? xmlTypeAnno.name() : part.getElementQName().getLocalPart();
- XmlSchemaType existingType = schema.getTypeByName(faultTypeName);
- if (existingType != null) {
- return;
- }
-
- XmlSchemaElement el = new XmlSchemaElement(schema, true);
- el.setName(part.getElementQName().getLocalPart());
- part.setXmlSchema(el);
- schemaInfo.setElement(null);
-
- if (respectXmlTypeNS) {
- schema = faultBeanSchema; //create complexType in the new created schema for xmlType
- }
-
- XmlSchemaComplexType ct = new XmlSchemaComplexType(schema, true);
- ct.setName(faultTypeName);
-
- el.setSchemaTypeName(ct.getQName());
-
- XmlSchemaSequence seq = new XmlSchemaSequence();
- ct.setParticle(seq);
- String namespace = part.getElementQName().getNamespaceURI();
- XmlAccessType accessType = Utils.getXmlAccessType(cls);
-//
- for (Field f : Utils.getFields(cls, accessType)) {
- //map field
- Type type = Utils.getFieldType(f);
- //we want to return the right type for collections so if we get null
- //from the return type we check if it's ParameterizedType and get the
- //generic return type.
- if ((type == null) && (f.getGenericType() instanceof ParameterizedType)) {
- type = f.getGenericType();
- }
- if (generateGenericType(type)) {
- buildGenericElements(schema, seq, f);
- } else {
- JAXBBeanInfo beanInfo = getBeanInfo(type);
- if (beanInfo != null) {
- XmlElement xmlElementAnno = f.getAnnotation(XmlElement.class);
- addElement(schema, seq, beanInfo, new QName(namespace, f.getName()), isArray(type), xmlElementAnno);
- }
- }
- }
- for (Method m : Utils.getGetters(cls, accessType)) {
- //map method
- Type type = Utils.getMethodReturnType(m);
- // we want to return the right type for collections so if we get null
- // from the return type we check if it's ParameterizedType and get the
- // generic return type.
- if ((type == null) && (m.getGenericReturnType() instanceof ParameterizedType)) {
- type = m.getGenericReturnType();
- }
-
- if (generateGenericType(type)) {
- buildGenericElements(schema, seq, m, type);
- } else {
- JAXBBeanInfo beanInfo = getBeanInfo(type);
- if (beanInfo != null) {
- int idx = m.getName().startsWith("get") ? 3 : 2;
- String name = m.getName().substring(idx);
- name = Character.toLowerCase(name.charAt(0)) + name.substring(1);
- XmlElement xmlElementAnno = m.getAnnotation(XmlElement.class);
- addElement(schema, seq, beanInfo, new QName(namespace, name), isArray(type), xmlElementAnno);
- }
- }
- }
- // Create element in xsd:sequence for Exception.class
- if (Exception.class.isAssignableFrom(cls)) {
- addExceptionMessage(cls, schema, seq);
- }
-
- if (propertyOrder != null) {
- if (propertyOrder.length == seq.getItems().size()) {
- sortItems(seq, propertyOrder);
- } else if (propertyOrder.length > 1
- || (propertyOrder.length == 1 && !propertyOrder[0].isEmpty())) {
- LOG.log(Level.WARNING, "propOrder in @XmlType doesn't define all schema elements :"
- + Arrays.toString(propertyOrder));
- }
- }
-
- if (xmlAccessorOrder != null && xmlAccessorOrder.value().equals(XmlAccessOrder.ALPHABETICAL)
- && propertyOrder == null) {
- sort(seq);
- }
-
- schemas.addCrossImports();
- part.setProperty(JAXBDataBinding.class.getName() + ".CUSTOM_EXCEPTION", Boolean.TRUE);
- }
- private void addExceptionMessage(Class<?> cls, XmlSchema schema, XmlSchemaSequence seq) {
- try {
- //a subclass could mark the message method as transient
- Method m = cls.getMethod("getMessage");
- if (!m.isAnnotationPresent(XmlTransient.class)
- && m.getDeclaringClass().equals(Throwable.class)) {
- JAXBBeanInfo beanInfo = getBeanInfo(java.lang.String.class);
- XmlSchemaElement exEle = new XmlSchemaElement(schema, false);
- exEle.setName("message");
- exEle.setSchemaTypeName(getTypeName(beanInfo));
- exEle.setMinOccurs(0);
- seq.getItems().add(exEle);
- }
- } catch (Exception e) {
- //ignore, just won't have the message element
- }
- }
-
- private boolean generateGenericType(Type type) {
- if (type instanceof ParameterizedType) {
- ParameterizedType paramType = (ParameterizedType)type;
- if (paramType.getActualTypeArguments().length > 1) {
- return true;
-
- }
- }
- return false;
- }
-
- private void buildGenericElements(XmlSchema schema, XmlSchemaSequence seq, Field f) {
- XmlSchemaComplexType generics = new XmlSchemaComplexType(schema, true);
- Type type = f.getGenericType();
- String rawType = ((ParameterizedType)type).getRawType().toString();
- String typeName = StringUtils.uncapitalize(rawType.substring(rawType.lastIndexOf('.') + 1));
- generics.setName(typeName);
-
- Class<?> genericsClass = f.getType();
- buildGenericSeq(schema, generics, genericsClass);
-
- String name = Character.toLowerCase(f.getName().charAt(0)) + f.getName().substring(1);
- XmlSchemaElement newel = new XmlSchemaElement(schema, false);
- newel.setName(name);
- newel.setSchemaTypeName(generics.getQName());
- newel.setMinOccurs(0);
- if (!seq.getItems().contains(newel)) {
- seq.getItems().add(newel);
- }
- }
-
- private void buildGenericElements(XmlSchema schema, XmlSchemaSequence seq, Method m, Type type) {
- String rawType = ((ParameterizedType)type).getRawType().toString();
- String typeName = StringUtils.uncapitalize(rawType.substring(rawType.lastIndexOf('.') + 1));
-
- XmlSchemaComplexType generics = (XmlSchemaComplexType)schema.getTypeByName(typeName);
- if (generics == null) {
- generics = new XmlSchemaComplexType(schema, true);
- generics.setName(typeName);
- }
-
- Class<?> genericsClass = m.getReturnType();
- buildGenericSeq(schema, generics, genericsClass);
-
- int idx = m.getName().startsWith("get") ? 3 : 2;
- String name = m.getName().substring(idx);
- name = Character.toLowerCase(name.charAt(0)) + name.substring(1);
- XmlSchemaElement newel = new XmlSchemaElement(schema, false);
- newel.setName(name);
- newel.setSchemaTypeName(generics.getQName());
- newel.setMinOccurs(0);
- if (!seq.getItems().contains(newel)) {
- seq.getItems().add(newel);
- }
- }
-
- private void buildGenericSeq(XmlSchema schema, XmlSchemaComplexType generics, Class<?> genericsClass) {
- XmlSchemaSequence genericsSeq = new XmlSchemaSequence();
- generics.setParticle(genericsSeq);
- XmlAccessType accessType = Utils.getXmlAccessType(genericsClass);
-
- for (Field f : Utils.getFields(genericsClass, accessType)) {
- if (f.getGenericType() instanceof TypeVariable) {
- String genericName = Character.toLowerCase(f.getName().charAt(0)) + f.getName().substring(1);
- XmlSchemaElement genericEle = new XmlSchemaElement(schema, false);
- genericEle.setName(genericName);
- genericEle.setMinOccurs(0);
- JAXBBeanInfo anyBean = getBeanInfo(context, f.getType());
- Iterator<QName> itr = anyBean.getTypeNames().iterator();
- if (!itr.hasNext()) {
- return;
- }
- QName typeName = itr.next();
- genericEle.setSchemaTypeName(typeName);
- genericsSeq.getItems().add(genericEle);
- }
- }
-
- for (Method genericMethod : Utils.getGetters(genericsClass, accessType)) {
- if (genericMethod.getGenericReturnType() instanceof TypeVariable) {
- int idx = genericMethod.getName().startsWith("get") ? 3 : 2;
- String genericName = genericMethod.getName().substring(idx);
- genericName = Character.toLowerCase(genericName.charAt(0)) + genericName.substring(1);
- XmlSchemaElement genericEle = new XmlSchemaElement(schema, false);
- genericEle.setName(genericName);
- genericEle.setMinOccurs(0);
- JAXBBeanInfo anyBean = getBeanInfo(context, genericMethod.getReturnType());
- Iterator<QName> itr = anyBean.getTypeNames().iterator();
- if (!itr.hasNext()) {
- return;
- }
- QName typeName = itr.next();
- genericEle.setSchemaTypeName(typeName);
- genericsSeq.getItems().add(genericEle);
- }
-
- }
- }
-
-
- static boolean isArray(Type cls) {
- if (cls instanceof Class) {
- return ((Class<?>)cls).isArray();
- } else if (cls instanceof ParameterizedType) {
- ParameterizedType pt = (ParameterizedType)cls;
- return pt.getActualTypeArguments().length == 1
- && pt.getRawType() instanceof Class
- && Collection.class.isAssignableFrom((Class<?>)pt.getRawType());
- } else if (cls instanceof GenericArrayType) {
- return true;
- }
- return false;
- }
-
- protected void addElement(XmlSchema schema,
- XmlSchemaSequence seq, JAXBBeanInfo beanInfo,
- QName name, boolean isArray, XmlElement xmlElementAnno) {
- XmlSchemaElement el = new XmlSchemaElement(schema, false);
- if (isArray) {
- el.setMinOccurs(0);
- el.setMaxOccurs(Long.MAX_VALUE);
- } else {
- if (xmlElementAnno == null) {
- el.setMinOccurs(0);
- el.setNillable(false);
- } else {
- el.setNillable(xmlElementAnno.nillable());
- int minOccurs = xmlElementAnno.required() ? 1 : 0;
- el.setMinOccurs(minOccurs);
- }
- }
-
- if (beanInfo.isElement()) {
- QName ename = new QName(beanInfo.getElementNamespaceURI(null),
- beanInfo.getElementLocalName(null));
- XmlSchemaElement el2 = schemas.getElementByQName(ename);
- el.setNillable(false);
- el.getRef().setTargetQName(el2.getQName());
- } else {
- if (xmlElementAnno != null && !StringUtils.isEmpty(xmlElementAnno.name())) {
- el.setName(xmlElementAnno.name());
- } else {
- el.setName(name.getLocalPart());
- }
- Iterator<QName> itr = beanInfo.getTypeNames().iterator();
- if (!itr.hasNext()) {
- return;
- }
- QName typeName = itr.next();
- el.setSchemaTypeName(typeName);
- }
-
- seq.getItems().add(el);
- }
-
- private SchemaInfo createSchemaIfNeeded(String namespace, NamespaceMap nsMap) {
- SchemaInfo schemaInfo = serviceInfo.getSchema(namespace);
- if (schemaInfo == null) {
- XmlSchema xmlSchema = schemas.newXmlSchemaInCollection(namespace);
-
- if (qualifiedSchemas) {
- xmlSchema.setElementFormDefault(XmlSchemaForm.QUALIFIED);
- }
-
- xmlSchema.setNamespaceContext(nsMap);
-
- schemaInfo = new SchemaInfo(namespace);
- schemaInfo.setSchema(xmlSchema);
- serviceInfo.addSchema(schemaInfo);
- }
- return schemaInfo;
- }
-
- private boolean isExistSchemaElement(XmlSchema schema, QName qn) {
- return schema.getElementByName(qn) != null;
- }
-
- private void sortItems(final XmlSchemaSequence seq, final String[] propertyOrder) {
- final List<String> propList = Arrays.asList(propertyOrder);
- Collections.sort(seq.getItems(), new Comparator<XmlSchemaSequenceMember>() {
- public int compare(XmlSchemaSequenceMember o1, XmlSchemaSequenceMember o2) {
- XmlSchemaElement element1 = (XmlSchemaElement)o1;
- XmlSchemaElement element2 = (XmlSchemaElement)o2;
- int index1 = propList.indexOf(element1.getName());
- int index2 = propList.indexOf(element2.getName());
- return index1 - index2;
- }
-
- });
- }
- //sort to Alphabetical order
- private void sort(final XmlSchemaSequence seq) {
- Collections.sort(seq.getItems(), new Comparator<XmlSchemaSequenceMember>() {
- public int compare(XmlSchemaSequenceMember o1, XmlSchemaSequenceMember o2) {
- XmlSchemaElement element1 = (XmlSchemaElement)o1;
- XmlSchemaElement element2 = (XmlSchemaElement)o2;
- return element1.getName().compareTo(element2.getName());
- }
-
- });
- }
-
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxb/io/DataReaderImpl.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxb/io/DataReaderImpl.java
deleted file mode 100644
index ef8a15b..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxb/io/DataReaderImpl.java
+++ /dev/null
@@ -1,207 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.cxf.jaxb.io;
-
-import java.lang.annotation.Annotation;
-import java.util.Map;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import javax.xml.bind.JAXBException;
-import javax.xml.bind.PropertyException;
-import javax.xml.bind.UnmarshalException;
-import javax.xml.bind.Unmarshaller;
-import javax.xml.bind.ValidationEvent;
-import javax.xml.bind.ValidationEventHandler;
-import javax.xml.bind.annotation.adapters.XmlAdapter;
-import javax.xml.namespace.QName;
-
-import org.apache.cxf.common.i18n.Message;
-import org.apache.cxf.common.jaxb.JAXBUtils;
-import org.apache.cxf.common.logging.LogUtils;
-import org.apache.cxf.databinding.DataReader;
-import org.apache.cxf.interceptor.Fault;
-import org.apache.cxf.jaxb.JAXBDataBase;
-import org.apache.cxf.jaxb.JAXBDataBinding;
-import org.apache.cxf.jaxb.JAXBEncoderDecoder;
-import org.apache.cxf.jaxb.UnmarshallerEventHandler;
-import org.apache.cxf.message.MessageUtils;
-import org.apache.cxf.service.model.MessagePartInfo;
-
-public class DataReaderImpl<T> extends JAXBDataBase implements DataReader<T> {
- private static final Logger LOG = LogUtils.getLogger(JAXBDataBinding.class);
- JAXBDataBinding databinding;
- boolean unwrapJAXBElement;
- ValidationEventHandler veventHandler;
- boolean setEventHandler = true;
-
- public DataReaderImpl(JAXBDataBinding binding, boolean unwrap) {
- super(binding.getContext());
- unwrapJAXBElement = unwrap;
- databinding = binding;
- }
-
- public Object read(T input) {
- return read(null, input);
- }
-
- private static class WSUIDValidationHandler implements ValidationEventHandler {
- ValidationEventHandler origHandler;
- WSUIDValidationHandler(ValidationEventHandler o) {
- origHandler = o;
- }
-
- public boolean handleEvent(ValidationEvent event) {
- // if the original handler has already handled the event, no need for us
- // to do anything, otherwise if not yet handled, then do this 'hack'
- if (origHandler != null && origHandler.handleEvent(event)) {
- return true;
- }
- // hack for CXF-3453
- String msg = event.getMessage();
- return msg != null
- && msg.contains(":Id")
- && (msg.startsWith("cvc-type.3.1.1")
- || msg.startsWith("cvc-type.3.2.2")
- || msg.startsWith("cvc-complex-type.3.1.1")
- || msg.startsWith("cvc-complex-type.3.2.2"));
- }
- }
-
- public void setProperty(String prop, Object value) {
- if (prop.equals(JAXBDataBinding.UNWRAP_JAXB_ELEMENT)) {
- unwrapJAXBElement = Boolean.TRUE.equals(value);
- } else if (prop.equals(org.apache.cxf.message.Message.class.getName())) {
- org.apache.cxf.message.Message m = (org.apache.cxf.message.Message)value;
- veventHandler = getValidationEventHandler(m, JAXBDataBinding.READER_VALIDATION_EVENT_HANDLER);
- if (veventHandler == null) {
- veventHandler = databinding.getValidationEventHandler();
- }
- setEventHandler = MessageUtils.getContextualBoolean(m,
- JAXBDataBinding.SET_VALIDATION_EVENT_HANDLER, true);
-
- Object unwrapProperty = m.get(JAXBDataBinding.UNWRAP_JAXB_ELEMENT);
- if (unwrapProperty == null) {
- unwrapProperty = m.getExchange().get(JAXBDataBinding.UNWRAP_JAXB_ELEMENT);
- }
- if (unwrapProperty != null) {
- unwrapJAXBElement = Boolean.TRUE.equals(unwrapProperty);
- }
- }
- }
-
- private Unmarshaller createUnmarshaller() {
- try {
- Unmarshaller um = context.createUnmarshaller();
- if (databinding.getUnmarshallerListener() != null) {
- um.setListener(databinding.getUnmarshallerListener());
- }
- if (setEventHandler) {
- um.setEventHandler(new WSUIDValidationHandler(veventHandler));
- }
- if (databinding.getUnmarshallerProperties() != null) {
- for (Map.Entry<String, Object> propEntry
- : databinding.getUnmarshallerProperties().entrySet()) {
- try {
- um.setProperty(propEntry.getKey(), propEntry.getValue());
- } catch (PropertyException pe) {
- LOG.log(Level.INFO, "PropertyException setting Marshaller properties", pe);
- }
- }
- }
- um.setSchema(schema);
- um.setAttachmentUnmarshaller(getAttachmentUnmarshaller());
- for (XmlAdapter<?, ?> adapter : databinding.getConfiguredXmlAdapters()) {
- um.setAdapter(adapter);
- }
- return um;
- } catch (javax.xml.bind.UnmarshalException ex) {
- throw new Fault(new Message("UNMARSHAL_ERROR", LOG, ex.getLinkedException()
- .getMessage()), ex);
- } catch (JAXBException ex) {
- throw new Fault(new Message("UNMARSHAL_ERROR", LOG, ex.getMessage()), ex);
- }
- }
-
- public Object read(MessagePartInfo part, T reader) {
- boolean honorJaxbAnnotation = honorJAXBAnnotations(part);
- if (honorJaxbAnnotation) {
- Annotation[] anns = getJAXBAnnotation(part);
- if (anns.length > 0) {
- // RpcLit will use the JAXB Bridge to unmarshall part message when it is
- // annotated with @XmlList,@XmlAttachmentRef,@XmlJavaTypeAdapter
- // TODO:Cache the JAXBRIContext
- QName qname = new QName(null, part.getConcreteName().getLocalPart());
-
- Object obj = JAXBEncoderDecoder.unmarshalWithBridge(qname,
- part.getTypeClass(),
- anns,
- databinding.getContextClasses(),
- reader,
- getAttachmentUnmarshaller());
-
- onCompleteUnmarshalling();
-
- return obj;
- }
- }
-
- Unmarshaller um = createUnmarshaller();
- try {
- Object obj = JAXBEncoderDecoder.unmarshall(um, reader, part,
- unwrapJAXBElement);
- onCompleteUnmarshalling();
-
- return obj;
- } finally {
- JAXBUtils.closeUnmarshaller(um);
- }
- }
-
- public Object read(QName name, T input, Class<?> type) {
- Unmarshaller um = createUnmarshaller();
-
- try {
- Object obj = JAXBEncoderDecoder.unmarshall(um, input,
- name, type,
- unwrapJAXBElement);
- onCompleteUnmarshalling();
-
- return obj;
- } finally {
- JAXBUtils.closeUnmarshaller(um);
- }
-
- }
-
- private void onCompleteUnmarshalling() {
- if (setEventHandler && veventHandler instanceof UnmarshallerEventHandler) {
- try {
- ((UnmarshallerEventHandler) veventHandler).onUnmarshalComplete();
- } catch (UnmarshalException e) {
- if (e.getLinkedException() != null) {
- throw new Fault(new Message("UNMARSHAL_ERROR", LOG,
- e.getLinkedException().getMessage()), e);
- }
- throw new Fault(new Message("UNMARSHAL_ERROR", LOG, e.getMessage()), e);
- }
- }
- }
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxrs/JAXRSInvoker.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxrs/JAXRSInvoker.java
deleted file mode 100644
index 163ff78..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxrs/JAXRSInvoker.java
+++ /dev/null
@@ -1,460 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.cxf.jaxrs;
-
-
-import java.io.IOException;
-import java.lang.reflect.Method;
-import java.lang.reflect.Proxy;
-import java.util.Collections;
-import java.util.List;
-import java.util.ResourceBundle;
-import java.util.concurrent.CancellationException;
-import java.util.concurrent.CompletionException;
-import java.util.concurrent.CompletionStage;
-import java.util.logging.Logger;
-
-import javax.ws.rs.WebApplicationException;
-import javax.ws.rs.container.AsyncResponse;
-import javax.ws.rs.container.ResourceContext;
-import javax.ws.rs.core.Application;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.MultivaluedMap;
-import javax.ws.rs.core.Response;
-
-import org.apache.cxf.common.classloader.ClassLoaderUtils;
-import org.apache.cxf.common.classloader.ClassLoaderUtils.ClassLoaderHolder;
-import org.apache.cxf.common.i18n.BundleUtils;
-import org.apache.cxf.common.logging.LogUtils;
-import org.apache.cxf.common.util.ClassHelper;
-import org.apache.cxf.helpers.CastUtils;
-import org.apache.cxf.interceptor.Fault;
-import org.apache.cxf.interceptor.InterceptorChain.State;
-import org.apache.cxf.jaxrs.impl.AsyncResponseImpl;
-import org.apache.cxf.jaxrs.impl.MetadataMap;
-import org.apache.cxf.jaxrs.impl.ResourceContextImpl;
-import org.apache.cxf.jaxrs.lifecycle.ResourceProvider;
-import org.apache.cxf.jaxrs.model.ClassResourceInfo;
-import org.apache.cxf.jaxrs.model.OperationResourceInfo;
-import org.apache.cxf.jaxrs.model.ProviderInfo;
-import org.apache.cxf.jaxrs.model.URITemplate;
-import org.apache.cxf.jaxrs.provider.ServerProviderFactory;
-import org.apache.cxf.jaxrs.utils.ExceptionUtils;
-import org.apache.cxf.jaxrs.utils.InjectionUtils;
-import org.apache.cxf.jaxrs.utils.JAXRSUtils;
-import org.apache.cxf.message.Exchange;
-import org.apache.cxf.message.Message;
-import org.apache.cxf.message.MessageContentsList;
-import org.apache.cxf.service.invoker.AbstractInvoker;
-
-public class JAXRSInvoker extends AbstractInvoker {
- private static final Logger LOG = LogUtils.getL7dLogger(JAXRSInvoker.class);
- private static final ResourceBundle BUNDLE = BundleUtils.getBundle(JAXRSInvoker.class);
- private static final String SERVICE_LOADER_AS_CONTEXT = "org.apache.cxf.serviceloader-context";
- private static final String SERVICE_OBJECT_SCOPE = "org.apache.cxf.service.scope";
- private static final String REQUEST_SCOPE = "request";
- private static final String LAST_SERVICE_OBJECT = "org.apache.cxf.service.object.last";
- private static final String PROXY_INVOCATION_ERROR_FRAGMENT
- = "object is not an instance of declaring class";
-
- public JAXRSInvoker() {
- }
-
- public Object invoke(Exchange exchange, Object request) {
- MessageContentsList responseList = checkExchangeForResponse(exchange);
- if (responseList != null) {
- return responseList;
- }
- AsyncResponse asyncResp = exchange.get(AsyncResponse.class);
- if (asyncResp != null) {
- AsyncResponseImpl asyncImpl = (AsyncResponseImpl)asyncResp;
- asyncImpl.prepareContinuation();
- try {
- asyncImpl.handleTimeout();
- return handleAsyncResponse(exchange, asyncImpl);
- } catch (Throwable t) {
- return handleAsyncFault(exchange, asyncImpl, t);
- }
- }
-
- ResourceProvider provider = getResourceProvider(exchange);
- Object rootInstance = null;
- Message inMessage = exchange.getInMessage();
- try {
- rootInstance = getServiceObject(exchange);
- Object serviceObject = getActualServiceObject(exchange, rootInstance);
-
- return invoke(exchange, request, serviceObject);
- } catch (WebApplicationException ex) {
- responseList = checkExchangeForResponse(exchange);
- if (responseList != null) {
- return responseList;
- }
- return handleFault(ex, inMessage);
- } finally {
- boolean suspended = isSuspended(exchange);
- if (suspended || exchange.isOneWay() || inMessage.get(Message.THREAD_CONTEXT_SWITCHED) != null) {
- ServerProviderFactory.clearThreadLocalProxies(inMessage);
- }
- if (suspended || isServiceObjectRequestScope(inMessage)) {
- persistRoots(exchange, rootInstance, provider);
- } else {
- provider.releaseInstance(inMessage, rootInstance);
- }
- }
- }
-
- private boolean isSuspended(Exchange exchange) {
- return exchange.getInMessage().getInterceptorChain().getState() == State.SUSPENDED;
- }
-
- private Object handleAsyncResponse(Exchange exchange, AsyncResponseImpl ar) {
- Object asyncObj = ar.getResponseObject();
- if (asyncObj instanceof Throwable) {
- final Throwable throwable = (Throwable)asyncObj;
- Throwable cause = throwable;
-
- if (throwable instanceof CompletionException) {
- cause = throwable.getCause();
- }
-
- return handleAsyncFault(exchange, ar, (cause != null) ? cause : throwable);
- }
- setResponseContentTypeIfNeeded(exchange.getInMessage(), asyncObj);
- return new MessageContentsList(asyncObj);
- }
-
- private Object handleAsyncFault(Exchange exchange, AsyncResponseImpl ar, Throwable t) {
- try {
- return handleFault(new Fault(t), exchange.getInMessage(), null, null);
- } catch (Fault ex) {
- ar.setUnmappedThrowable(ex.getCause() == null ? ex : ex.getCause());
- if (isSuspended(exchange)) {
- ar.reset();
- exchange.getInMessage().getInterceptorChain().unpause();
- }
- return new MessageContentsList(Response.serverError().build());
- }
- }
-
- private void persistRoots(Exchange exchange, Object rootInstance, Object provider) {
- exchange.put(JAXRSUtils.ROOT_INSTANCE, rootInstance);
- exchange.put(JAXRSUtils.ROOT_PROVIDER, provider);
- }
-
- @SuppressWarnings("unchecked")
- public Object invoke(Exchange exchange, Object request, Object resourceObject) {
-
- final OperationResourceInfo ori = exchange.get(OperationResourceInfo.class);
- final ClassResourceInfo cri = ori.getClassResourceInfo();
- final Message inMessage = exchange.getInMessage();
- final ServerProviderFactory providerFactory = ServerProviderFactory.getInstance(inMessage);
- cri.injectContexts(resourceObject, ori, inMessage);
-
- if (cri.isRoot()) {
- ProviderInfo<Application> appProvider = providerFactory.getApplicationProvider();
- if (appProvider != null) {
- InjectionUtils.injectContexts(appProvider.getProvider(),
- appProvider,
- inMessage);
- }
- }
-
-
- Method methodToInvoke = getMethodToInvoke(cri, ori, resourceObject);
-
- List<Object> params = null;
- if (request instanceof List) {
- params = CastUtils.cast((List<?>)request);
- } else if (request != null) {
- params = new MessageContentsList(request);
- }
-
- Object result = null;
- ClassLoaderHolder contextLoader = null;
- AsyncResponseImpl asyncResponse = null;
- try {
- if (setServiceLoaderAsContextLoader(inMessage)) {
- contextLoader = ClassLoaderUtils
- .setThreadContextClassloader(resourceObject.getClass().getClassLoader());
- }
- if (!ori.isSubResourceLocator()) {
- asyncResponse = (AsyncResponseImpl)inMessage.get(AsyncResponse.class);
- }
- result = invoke(exchange, resourceObject, methodToInvoke, params);
- if (asyncResponse == null && !ori.isSubResourceLocator()) {
- asyncResponse = checkFutureResponse(inMessage, checkResultObject(result));
- }
- if (asyncResponse != null) {
- if (!asyncResponse.suspendContinuationIfNeeded()) {
- result = handleAsyncResponse(exchange, asyncResponse);
- } else {
- providerFactory.clearThreadLocalProxies();
- }
- }
- } catch (Fault ex) {
- Object faultResponse;
- if (asyncResponse != null) {
- faultResponse = handleAsyncFault(exchange, asyncResponse,
- ex.getCause() == null ? ex : ex.getCause());
- } else {
- faultResponse = handleFault(ex, inMessage, cri, methodToInvoke);
- }
- return faultResponse;
- } finally {
- exchange.put(LAST_SERVICE_OBJECT, resourceObject);
- if (contextLoader != null) {
- contextLoader.reset();
- }
- }
- ClassResourceInfo subCri = null;
- if (ori.isSubResourceLocator()) {
- try {
- MultivaluedMap<String, String> values = getTemplateValues(inMessage);
- String subResourcePath = values.getFirst(URITemplate.FINAL_MATCH_GROUP);
- String httpMethod = (String)inMessage.get(Message.HTTP_REQUEST_METHOD);
- String contentType = (String)inMessage.get(Message.CONTENT_TYPE);
- if (contentType == null) {
- contentType = "*/*";
- }
- List<MediaType> acceptContentType =
- (List<MediaType>)exchange.get(Message.ACCEPT_CONTENT_TYPE);
-
- result = checkSubResultObject(result, subResourcePath);
-
- final Class<?> subResponseType;
- if (result.getClass() == Class.class) {
- ResourceContext rc = new ResourceContextImpl(inMessage, ori);
- result = rc.getResource((Class<?>)result);
- subResponseType = InjectionUtils.getActualType(methodToInvoke.getGenericReturnType());
- } else {
- subResponseType = methodToInvoke.getReturnType();
- }
-
- subCri = cri.getSubResource(subResponseType,
- ClassHelper.getRealClass(exchange.getBus(), result), result);
- if (subCri == null) {
- org.apache.cxf.common.i18n.Message errorM =
- new org.apache.cxf.common.i18n.Message("NO_SUBRESOURCE_FOUND",
- BUNDLE,
- subResourcePath);
- LOG.severe(errorM.toString());
- throw ExceptionUtils.toNotFoundException(null, null);
- }
-
- OperationResourceInfo subOri = JAXRSUtils.findTargetMethod(
- Collections.singletonMap(subCri, values),
- inMessage,
- httpMethod,
- values,
- contentType,
- acceptContentType);
- exchange.put(OperationResourceInfo.class, subOri);
- inMessage.put(URITemplate.TEMPLATE_PARAMETERS, values);
- inMessage.put(URITemplate.URI_TEMPLATE, JAXRSUtils.getUriTemplate(inMessage, subCri, ori, subOri));
-
- if (!subOri.isSubResourceLocator()
- && JAXRSUtils.runContainerRequestFilters(providerFactory,
- inMessage,
- false,
- subOri.getNameBindings())) {
- return new MessageContentsList(exchange.get(Response.class));
- }
-
- // work out request parameters for the sub-resource class. Here we
- // presume InputStream has not been consumed yet by the root resource class.
- List<Object> newParams = JAXRSUtils.processParameters(subOri, values, inMessage);
- inMessage.setContent(List.class, newParams);
-
- return this.invoke(exchange, newParams, result);
- } catch (IOException ex) {
- Response resp = JAXRSUtils.convertFaultToResponse(ex, inMessage);
- if (resp == null) {
- resp = JAXRSUtils.convertFaultToResponse(ex, inMessage);
- }
- return new MessageContentsList(resp);
- } catch (WebApplicationException ex) {
- Response excResponse;
- if (JAXRSUtils.noResourceMethodForOptions(ex.getResponse(),
- (String)inMessage.get(Message.HTTP_REQUEST_METHOD))) {
- excResponse = JAXRSUtils.createResponse(Collections.singletonList(subCri),
- null, null, 200, true);
- } else {
- excResponse = JAXRSUtils.convertFaultToResponse(ex, inMessage);
- }
- return new MessageContentsList(excResponse);
- }
- }
- setResponseContentTypeIfNeeded(inMessage, result);
- return result;
- }
-
- protected AsyncResponseImpl checkFutureResponse(Message inMessage, Object result) {
- if (result instanceof CompletionStage) {
- final CompletionStage<?> stage = (CompletionStage<?>)result;
- final AsyncResponseImpl asyncResponse = new AsyncResponseImpl(inMessage);
- stage.whenComplete((v, t) -> {
- if (t instanceof CancellationException) {
- asyncResponse.cancel();
- } else {
- asyncResponse.resume(v != null ? v : t);
- }
- });
- return asyncResponse;
- }
- return null;
- }
-
- protected Method getMethodToInvoke(ClassResourceInfo cri, OperationResourceInfo ori, Object resourceObject) {
- Method resourceMethod = cri.getMethodDispatcher().getMethod(ori);
-
- Method methodToInvoke;
- if (Proxy.class.isInstance(resourceObject)) {
- methodToInvoke = cri.getMethodDispatcher().getProxyMethod(resourceMethod);
- if (methodToInvoke == null) {
- methodToInvoke = InjectionUtils.checkProxy(resourceMethod, resourceObject);
- cri.getMethodDispatcher().addProxyMethod(resourceMethod, methodToInvoke);
- }
- } else {
- methodToInvoke = resourceMethod;
- }
- return methodToInvoke;
- }
-
- private MessageContentsList checkExchangeForResponse(Exchange exchange) {
- Response r = exchange.get(Response.class);
- if (r != null) {
- JAXRSUtils.setMessageContentType(exchange.getInMessage(), r);
- return new MessageContentsList(r);
- }
- return null;
- }
-
- private void setResponseContentTypeIfNeeded(Message inMessage, Object response) {
- if (response instanceof Response) {
- JAXRSUtils.setMessageContentType(inMessage, (Response)response);
- }
- }
- private Object handleFault(Throwable ex, Message inMessage) {
- return handleFault(new Fault(ex), inMessage, null, null);
- }
- private Object handleFault(Fault ex, Message inMessage,
- ClassResourceInfo cri, Method methodToInvoke) {
- String errorMessage = ex.getMessage();
- if (errorMessage != null && cri != null
- && errorMessage.contains(PROXY_INVOCATION_ERROR_FRAGMENT)) {
- org.apache.cxf.common.i18n.Message errorM =
- new org.apache.cxf.common.i18n.Message("PROXY_INVOCATION_FAILURE",
- BUNDLE,
- methodToInvoke,
- cri.getServiceClass().getName());
- LOG.severe(errorM.toString());
- }
- Response excResponse =
- JAXRSUtils.convertFaultToResponse(ex.getCause() == null ? ex : ex.getCause(), inMessage);
- if (excResponse == null) {
- inMessage.getExchange().put(Message.PROPOGATE_EXCEPTION,
- ExceptionUtils.propogateException(inMessage));
- throw ex;
- }
- return new MessageContentsList(excResponse);
- }
-
- @SuppressWarnings("unchecked")
- protected MultivaluedMap<String, String> getTemplateValues(Message msg) {
- MultivaluedMap<String, String> values = new MetadataMap<>();
- MultivaluedMap<String, String> oldValues =
- (MultivaluedMap<String, String>)msg.get(URITemplate.TEMPLATE_PARAMETERS);
- if (oldValues != null) {
- values.putAll(oldValues);
- }
- return values;
- }
-
- private boolean setServiceLoaderAsContextLoader(Message inMessage) {
- Object en = inMessage.getContextualProperty(SERVICE_LOADER_AS_CONTEXT);
- return Boolean.TRUE.equals(en) || "true".equals(en);
- }
-
- private boolean isServiceObjectRequestScope(Message inMessage) {
- Object scope = inMessage.getContextualProperty(SERVICE_OBJECT_SCOPE);
- return REQUEST_SCOPE.equals(scope);
- }
-
- private ResourceProvider getResourceProvider(Exchange exchange) {
- Object provider = exchange.remove(JAXRSUtils.ROOT_PROVIDER);
- if (provider == null) {
- OperationResourceInfo ori = exchange.get(OperationResourceInfo.class);
- ClassResourceInfo cri = ori.getClassResourceInfo();
- return cri.getResourceProvider();
- }
- return (ResourceProvider)provider;
- }
-
- public Object getServiceObject(Exchange exchange) {
-
- Object root = exchange.remove(JAXRSUtils.ROOT_INSTANCE);
- if (root != null) {
- return root;
- }
-
- OperationResourceInfo ori = exchange.get(OperationResourceInfo.class);
- ClassResourceInfo cri = ori.getClassResourceInfo();
-
- return cri.getResourceProvider().getInstance(exchange.getInMessage());
- }
-
- protected Object getActualServiceObject(Exchange exchange, Object rootInstance) {
-
- Object last = exchange.get(LAST_SERVICE_OBJECT);
- return last != null ? last : rootInstance;
- }
-
-
-
- private static Object checkResultObject(Object result) {
-
- if (result != null) {
- if (result instanceof MessageContentsList) {
- result = ((MessageContentsList)result).get(0);
- } else if (result instanceof List) {
- result = ((List<?>)result).get(0);
- } else if (result.getClass().isArray()) {
- result = ((Object[])result)[0];
- }
- }
- return result;
- }
- private static Object checkSubResultObject(Object result, String subResourcePath) {
- result = checkResultObject(result);
- if (result == null) {
- org.apache.cxf.common.i18n.Message errorM =
- new org.apache.cxf.common.i18n.Message("NULL_SUBRESOURCE",
- BUNDLE,
- subResourcePath);
- LOG.info(errorM.toString());
- throw ExceptionUtils.toNotFoundException(null, null);
- }
-
- return result;
- }
-
-
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxrs/JAXRSServerFactoryBean.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxrs/JAXRSServerFactoryBean.java
deleted file mode 100644
index 7871226..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxrs/JAXRSServerFactoryBean.java
+++ /dev/null
@@ -1,467 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.cxf.jaxrs;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.LinkedHashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import javax.ws.rs.core.Application;
-
-import org.apache.cxf.Bus;
-import org.apache.cxf.common.classloader.ClassLoaderUtils;
-import org.apache.cxf.common.classloader.ClassLoaderUtils.ClassLoaderHolder;
-import org.apache.cxf.endpoint.Endpoint;
-import org.apache.cxf.endpoint.Server;
-import org.apache.cxf.endpoint.ServerImpl;
-import org.apache.cxf.feature.Feature;
-import org.apache.cxf.helpers.CastUtils;
-import org.apache.cxf.jaxrs.ext.ResourceComparator;
-import org.apache.cxf.jaxrs.impl.RequestPreprocessor;
-import org.apache.cxf.jaxrs.lifecycle.PerRequestResourceProvider;
-import org.apache.cxf.jaxrs.lifecycle.ResourceProvider;
-import org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider;
-import org.apache.cxf.jaxrs.model.ApplicationInfo;
-import org.apache.cxf.jaxrs.model.ClassResourceInfo;
-import org.apache.cxf.jaxrs.provider.ServerProviderFactory;
-import org.apache.cxf.jaxrs.utils.AnnotationUtils;
-import org.apache.cxf.jaxrs.utils.InjectionUtils;
-import org.apache.cxf.jaxrs.utils.JAXRSUtils;
-import org.apache.cxf.service.factory.FactoryBeanListener;
-import org.apache.cxf.service.factory.ServiceConstructionException;
-import org.apache.cxf.service.invoker.Invoker;
-
-
-/**
- * Bean to help easily create Server endpoints for JAX-RS. Example:
- * <pre>
- * JAXRSServerFactoryBean sf = JAXRSServerFactoryBean();
- * sf.setResourceClasses(Book.class);
- * sf.setBindingId(JAXRSBindingFactory.JAXRS_BINDING_ID);
- * sf.setAddress("http://localhost:9080/");
- * Server myServer = sf.create();
- * </pre>
- * This will start a server for you and register it with the ServerManager. Note
- * you should explicitly close the {@link org.apache.cxf.endpoint.Server} created
- * when finished with it:
- * <pre>
- * myServer.close();
- * myServer.destroy(); // closes first if close() not previously called
- * </pre>
- */
-public class JAXRSServerFactoryBean extends AbstractJAXRSFactoryBean {
-
- protected Map<Class<?>, ResourceProvider> resourceProviders = new HashMap<>();
-
- private Server server;
- private boolean start = true;
- private Map<Object, Object> languageMappings;
- private Map<Object, Object> extensionMappings;
- private ResourceComparator rc;
- private ApplicationInfo appProvider;
- private String documentLocation;
-
- public JAXRSServerFactoryBean() {
- this(new JAXRSServiceFactoryBean());
- }
-
- public JAXRSServerFactoryBean(JAXRSServiceFactoryBean sf) {
- super(sf);
- }
-
- /**
- * Saves the reference to the JAX-RS {@link Application}
- * @param app
- */
- public void setApplication(Application app) {
- setApplicationInfo(new ApplicationInfo(app, getBus()));
- }
-
- public void setApplicationInfo(ApplicationInfo provider) {
- appProvider = provider;
- Set<String> appNameBindings = AnnotationUtils.getNameBindings(bus, provider.getProvider().getClass());
- for (ClassResourceInfo cri : getServiceFactory().getClassResourceInfo()) {
- Set<String> clsNameBindings = new LinkedHashSet<>(appNameBindings);
- clsNameBindings.addAll(AnnotationUtils.getNameBindings(bus, cri.getServiceClass()));
- cri.setNameBindings(clsNameBindings);
- }
- }
-
- /**
- * Resource comparator which may be used to customize the way
- * a root resource or resource method is selected
- * @param rcomp comparator
- */
- public void setResourceComparator(ResourceComparator rcomp) {
- rc = rcomp;
- }
-
- /**
- * By default the subresources are resolved dynamically, mainly due to
- * the JAX-RS specification allowing Objects being returned from the subresource
- * locators. Setting this property to true enables the runtime to do the
- * early resolution.
- *
- * @param enableStatic enabling the static resolution if set to true
- */
- public void setStaticSubresourceResolution(boolean enableStatic) {
- serviceFactory.setEnableStaticResolution(enableStatic);
- }
-
-
- /**
- * Creates the JAX-RS Server instance
- * @return the server
- */
- public void init() {
- if (server == null) {
- create();
- }
- }
-
- /**
- * Creates the JAX-RS Server instance
- * @return the server
- */
- public Server create() {
- ClassLoaderHolder origLoader = null;
- try {
- Bus bus = getBus();
- ClassLoader loader = bus.getExtension(ClassLoader.class);
- if (loader != null) {
- origLoader = ClassLoaderUtils.setThreadContextClassloader(loader);
- }
- serviceFactory.setBus(bus);
- checkResources(true);
- if (serviceFactory.getService() == null) {
- serviceFactory.create();
- }
-
- Endpoint ep = createEndpoint();
-
- getServiceFactory().sendEvent(FactoryBeanListener.Event.PRE_SERVER_CREATE,
- server);
-
- server = new ServerImpl(getBus(),
- ep,
- getDestinationFactory(),
- getBindingFactory());
-
- Invoker invoker = serviceFactory.getInvoker();
- if (invoker == null) {
- ep.getService().setInvoker(createInvoker());
- } else {
- ep.getService().setInvoker(invoker);
- }
-
- ServerProviderFactory factory = setupFactory(ep);
-
- ep.put(Application.class.getName(), appProvider);
- factory.setRequestPreprocessor(
- new RequestPreprocessor(languageMappings, extensionMappings));
- ep.put(Bus.class.getName(), getBus());
- if (documentLocation != null) {
- ep.put(JAXRSUtils.DOC_LOCATION, documentLocation);
- }
- if (rc != null) {
- ep.put("org.apache.cxf.jaxrs.comparator", rc);
- }
- checkPrivateEndpoint(ep);
-
- applyBusFeatures(getBus());
- applyFeatures();
-
- updateClassResourceProviders(ep);
- injectContexts(factory, (ApplicationInfo)ep.get(Application.class.getName()));
- factory.applyDynamicFeatures(getServiceFactory().getClassResourceInfo());
-
-
- getServiceFactory().sendEvent(FactoryBeanListener.Event.SERVER_CREATED,
- server,
- null,
- null);
-
-
- if (start) {
- try {
- server.start();
- } catch (RuntimeException re) {
- if (!(re instanceof ServiceConstructionException
- && re.getMessage().startsWith("There is an endpoint already running on"))) {
- //avoid destroying another server on the same endpoint url
- server.destroy(); // prevent resource leak if server really started by itself
-
- }
- throw re;
- }
- }
- } catch (Exception e) {
- throw new ServiceConstructionException(e);
- } finally {
- if (origLoader != null) {
- origLoader.reset();
- }
- }
-
- return server;
- }
-
- public Server getServer() {
- return server;
- }
-
- protected ServerProviderFactory setupFactory(Endpoint ep) {
- ServerProviderFactory factory = ServerProviderFactory.createInstance(getBus());
- setBeanInfo(factory);
- factory.setApplicationProvider(appProvider);
- super.setupFactory(factory, ep);
- return factory;
- }
-
- protected void setBeanInfo(ServerProviderFactory factory) {
- List<ClassResourceInfo> cris = serviceFactory.getClassResourceInfo();
- for (ClassResourceInfo cri : cris) {
- cri.initBeanParamInfo(factory);
- }
-
- }
-
- protected void applyBusFeatures(final Bus bus) {
- if (bus.getFeatures() != null) {
- for (Feature feature : bus.getFeatures()) {
- feature.initialize(server, bus);
- }
- }
- }
-
- protected void applyFeatures() {
- if (getFeatures() != null) {
- for (Feature feature : getFeatures()) {
- feature.initialize(server, getBus());
- }
- }
- }
-
- protected Invoker createInvoker() {
- return serviceFactory.createInvoker();
- }
-
- /**
- * Sets the language mappings,
- * example, 'en' is the key and 'en-gb' is the value.
- *
- * @param lMaps the language mappings
- */
- public void setLanguageMappings(Map<Object, Object> lMaps) {
- languageMappings = lMaps;
- }
-
- /**
- * Sets the extension mappings,
- * example, 'xml' is the key and 'text/xml' is the value.
- *
- * @param extMaps the extension mappings
- */
- public void setExtensionMappings(Map<Object, Object> extMaps) {
- extensionMappings = extMaps;
- }
-
- public List<Class<?>> getResourceClasses() {
- return serviceFactory.getResourceClasses();
- }
-
- /**
- * This method is used primarily by Spring handler processing
- * the jaxrs:server/@serviceClass attribute. It delegates to
- * setResourceClasses method accepting the array of Class parameters.
- * @param clazz the service/resource class
- */
- public void setServiceClass(Class<?> clazz) {
- serviceFactory.setResourceClasses(clazz);
- }
-
- /**
- * Sets one or more root resource classes
- * @param classes the list of resource classes
- */
- public void setResourceClasses(List<Class<?>> classes) {
- serviceFactory.setResourceClasses(classes);
- }
-
- /**
- * Sets one or more root resource classes
- * @param classes the array of resource classes
- */
- public void setResourceClasses(Class<?>... classes) {
- serviceFactory.setResourceClasses(classes);
- }
-
- /**
- * Sets the resource beans. If this is set then the JAX-RS runtime
- * will not be responsible for the life-cycle of resource classes.
- *
- * @param beans the array of resource instances
- */
- public void setServiceBeanObjects(Object... beans) {
- setServiceBeans(Arrays.asList(beans));
- }
-
- /**
- * Sets the single resource bean. If this is set then the JAX-RS runtime
- * will not be responsible for the life-cycle of resource classes.
- * Please avoid setting the resource class of this bean explicitly,
- * the runtime will determine it itself.
- *
- * @param bean resource instance
- */
- public void setServiceBean(Object bean) {
- setServiceBeans(Arrays.asList(bean));
- }
-
- /**
- * Sets the resource beans. If this is set then the JAX-RS runtime
- * will not be responsible for the life-cycle of resource classes.
- *
- * @param beans the list of resource instances
- */
- public void setServiceBeans(List<Object> beans) {
- List<Object> newBeans = new ArrayList<>();
- addToBeans(newBeans, beans);
- serviceFactory.setResourceClassesFromBeans(newBeans);
- }
-
- /**
- * Sets the provider managing the life-cycle of the given resource class
- * <pre>
- * Example:
- * setResourceProvider(BookStoreInterface.class, new SingletonResourceProvider(new BookStore()));
- * </pre>
- * @param c resource class
- * @param rp resource provider
- */
- public void setResourceProvider(Class<?> c, ResourceProvider rp) {
- resourceProviders.put(c, rp);
- }
-
- /**
- * Sets the provider managing the life-cycle of the resource class
- * <pre>
- * Example:
- * setResourceProvider(new SingletonResourceProvider(new BookStore()));
- * </pre>
- * @param rp resource provider
- */
- public void setResourceProvider(ResourceProvider rp) {
- setResourceProviders(CastUtils.cast(Collections.singletonList(rp), ResourceProvider.class));
- }
-
- /**
- * Sets the list of providers managing the life-cycle of the resource classes
- *
- * @param rps resource providers
- */
- public void setResourceProviders(List<ResourceProvider> rps) {
- for (ResourceProvider rp : rps) {
- Class<?> c = rp.getResourceClass();
- setServiceClass(c);
- resourceProviders.put(c, rp);
- }
- }
-
- /**
- * Sets the custom Invoker which can be used to customize the way
- * the default JAX-RS invoker calls on the service bean
- * @param invoker
- */
- public void setInvoker(Invoker invoker) {
- serviceFactory.setInvoker(invoker);
- }
-
- /**
- * Determines whether Services are automatically started during the create() call. Default is true.
- * If false will need to call start() method on Server to activate it.
- * @param start Whether (true) or not (false) to start the Server during Server creation.
- */
- public void setStart(boolean start) {
- this.start = start;
- }
-
- protected void injectContexts(ServerProviderFactory factory, ApplicationInfo fallback) {
- // Sometimes the application provider (ApplicationInfo) is injected through
- // the endpoint, not JAXRSServerFactoryBean (like for example OpenApiFeature
- // or Swagger2Feature do). As such, without consulting the endpoint, the injection
- // may not work properly.
- final ApplicationInfo appInfoProvider = (appProvider == null) ? fallback : appProvider;
- final Application application = appInfoProvider == null ? null : appInfoProvider.getProvider();
-
- for (ClassResourceInfo cri : serviceFactory.getClassResourceInfo()) {
- if (cri.isSingleton()) {
- InjectionUtils.injectContextProxiesAndApplication(cri,
- cri.getResourceProvider().getInstance(null),
- application,
- factory);
- }
- }
- if (application != null) {
- InjectionUtils.injectContextProxiesAndApplication(appInfoProvider,
- application, null, null);
- }
- }
-
- protected void updateClassResourceProviders(Endpoint ep) {
- for (ClassResourceInfo cri : serviceFactory.getClassResourceInfo()) {
- if (cri.getResourceProvider() == null) {
- ResourceProvider rp = resourceProviders.get(cri.getResourceClass());
- if (rp != null) {
- cri.setResourceProvider(rp);
- } else {
- setDefaultResourceProvider(cri);
- }
- }
- if (cri.getResourceProvider() instanceof SingletonResourceProvider) {
- ((SingletonResourceProvider)cri.getResourceProvider()).init(ep);
- }
- }
- }
-
- protected void setDefaultResourceProvider(ClassResourceInfo cri) {
- cri.setResourceProvider(new PerRequestResourceProvider(cri.getResourceClass()));
- }
-
- /**
- * Set the reference to the document (WADL, etc) describing the endpoint
- * @param docLocation document location
- */
- public void setDocLocation(String docLocation) {
- this.documentLocation = docLocation;
- }
-
- /**
- * Get the reference to the document (WADL, etc) describing the endpoint
- * @return document location
- */
- public String getDocLocation() {
- return documentLocation;
- }
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
deleted file mode 100644
index 8937909..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
+++ /dev/null
@@ -1,1149 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.cxf.jaxrs.client;
-
-import java.io.Closeable;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.lang.annotation.Annotation;
-import java.lang.invoke.MethodHandle;
-import java.lang.invoke.MethodHandles;
-import java.lang.reflect.Field;
-import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.Method;
-import java.lang.reflect.Modifier;
-import java.lang.reflect.Type;
-import java.net.URI;
-import java.security.AccessController;
-import java.security.PrivilegedActionException;
-import java.security.PrivilegedExceptionAction;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.ResourceBundle;
-import java.util.function.Predicate;
-import java.util.logging.Logger;
-import java.util.stream.Collectors;
-
-import javax.ws.rs.BeanParam;
-import javax.ws.rs.CookieParam;
-import javax.ws.rs.FormParam;
-import javax.ws.rs.HeaderParam;
-import javax.ws.rs.MatrixParam;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.ProcessingException;
-import javax.ws.rs.QueryParam;
-import javax.ws.rs.WebApplicationException;
-import javax.ws.rs.client.InvocationCallback;
-import javax.ws.rs.container.AsyncResponse;
-import javax.ws.rs.core.HttpHeaders;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.MultivaluedMap;
-import javax.ws.rs.core.Response;
-import javax.ws.rs.core.UriBuilder;
-
-import org.apache.cxf.Bus;
-import org.apache.cxf.BusFactory;
-import org.apache.cxf.common.classloader.ClassLoaderUtils;
-import org.apache.cxf.common.classloader.ClassLoaderUtils.ClassLoaderHolder;
-import org.apache.cxf.common.i18n.BundleUtils;
-import org.apache.cxf.common.logging.LogUtils;
-import org.apache.cxf.common.util.PrimitiveUtils;
-import org.apache.cxf.common.util.PropertyUtils;
-import org.apache.cxf.common.util.ReflectionUtil;
-import org.apache.cxf.common.util.StringUtils;
-import org.apache.cxf.endpoint.Endpoint;
-import org.apache.cxf.helpers.CastUtils;
-import org.apache.cxf.interceptor.Fault;
-import org.apache.cxf.interceptor.InterceptorProvider;
-import org.apache.cxf.jaxrs.ext.multipart.Attachment;
-import org.apache.cxf.jaxrs.ext.multipart.Multipart;
-import org.apache.cxf.jaxrs.impl.MetadataMap;
-import org.apache.cxf.jaxrs.impl.ResponseImpl;
-import org.apache.cxf.jaxrs.model.ClassResourceInfo;
-import org.apache.cxf.jaxrs.model.OperationResourceInfo;
-import org.apache.cxf.jaxrs.model.Parameter;
-import org.apache.cxf.jaxrs.model.ParameterType;
-import org.apache.cxf.jaxrs.utils.AnnotationUtils;
-import org.apache.cxf.jaxrs.utils.FormUtils;
-import org.apache.cxf.jaxrs.utils.InjectionUtils;
-import org.apache.cxf.jaxrs.utils.JAXRSUtils;
-import org.apache.cxf.message.Exchange;
-import org.apache.cxf.message.Message;
-
-/**
- * Proxy-based client implementation
- *
- */
-public class ClientProxyImpl extends AbstractClient implements
- InvocationHandlerAware, InvocationHandler, Closeable {
-
- protected static final Logger LOG = LogUtils.getL7dLogger(ClientProxyImpl.class);
- protected static final ResourceBundle BUNDLE = BundleUtils.getBundle(ClientProxyImpl.class);
- protected static final String SLASH = "/";
- protected static final String BUFFER_PROXY_RESPONSE = "buffer.proxy.response";
- protected static final String PROXY_METHOD_PARAM_BODY_INDEX = "proxy.method.parameter.body.index";
-
- protected ClassResourceInfo cri;
- protected ClassLoader proxyLoader;
- protected boolean inheritHeaders;
- protected boolean isRoot;
- protected Map<String, Object> valuesMap = Collections.emptyMap();
- protected BodyWriter bodyWriter = new BodyWriter();
- protected Client proxy;
- public ClientProxyImpl(URI baseURI,
- ClassLoader loader,
- ClassResourceInfo cri,
- boolean isRoot,
- boolean inheritHeaders,
- Object... varValues) {
- this(baseURI, loader, cri, isRoot, inheritHeaders, Collections.emptyMap(), varValues);
- }
-
- public ClientProxyImpl(URI baseURI,
- ClassLoader loader,
- ClassResourceInfo cri,
- boolean isRoot,
- boolean inheritHeaders,
- Map<String, Object> properties,
- Object... varValues) {
- this(new LocalClientState(baseURI, properties), loader, cri, isRoot, inheritHeaders, varValues);
- }
-
- public ClientProxyImpl(ClientState initialState,
- ClassLoader loader,
- ClassResourceInfo cri,
- boolean isRoot,
- boolean inheritHeaders,
- Object... varValues) {
- super(initialState);
- this.proxyLoader = loader;
- this.cri = cri;
- this.isRoot = isRoot;
- this.inheritHeaders = inheritHeaders;
- initValuesMap(varValues);
- cfg.getInInterceptors().add(new ClientAsyncResponseInterceptor());
- }
-
- void setProxyClient(Client client) {
- this.proxy = client;
- }
-
- private void initValuesMap(Object... varValues) {
- if (isRoot) {
- List<String> vars = cri.getURITemplate().getVariables();
- valuesMap = new LinkedHashMap<>();
- for (int i = 0; i < vars.size(); i++) {
- if (varValues.length > 0) {
- if (i < varValues.length) {
- valuesMap.put(vars.get(i), varValues[i]);
- } else {
- org.apache.cxf.common.i18n.Message msg = new org.apache.cxf.common.i18n.Message(
- "ROOT_VARS_MISMATCH", BUNDLE, vars.size(), varValues.length);
- LOG.info(msg.toString());
- break;
- }
- } else {
- valuesMap.put(vars.get(i), "");
- }
- }
- }
- }
-
- private static class WrappedException extends Exception {
- private static final long serialVersionUID = 1183890106889852917L;
-
- final Throwable wrapped;
- WrappedException(Throwable wrapped) {
- this.wrapped = wrapped;
- }
- Throwable getWrapped() {
- return wrapped;
- }
- }
-
- private static Object invokeDefaultMethod(Class<?> declaringClass, Object o, Method m, Object[] params)
- throws Throwable {
-
- try {
- return AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() {
- @Override
- public Object run() throws Exception {
- try {
- final MethodHandles.Lookup lookup = MethodHandles
- .publicLookup()
- .in(declaringClass);
- // force private access so unreflectSpecial can invoke the interface's default method
- Field f;
- try {
- f = MethodHandles.Lookup.class.getDeclaredField("allowedModes");
- } catch (NoSuchFieldException nsfe) {
- // IBM and OpenJ9 JDKs use a different field name
- f = MethodHandles.Lookup.class.getDeclaredField("accessMode");
- m.setAccessible(true);
- }
- final int modifiers = f.getModifiers();
- if (Modifier.isFinal(modifiers)) {
- final Field modifiersField = Field.class.getDeclaredField("modifiers");
- modifiersField.setAccessible(true);
- modifiersField.setInt(f, modifiers & ~Modifier.FINAL);
- f.setAccessible(true);
- f.set(lookup, MethodHandles.Lookup.PRIVATE);
- }
- MethodHandle mh = lookup.unreflectSpecial(m, declaringClass).bindTo(o);
- return params != null && params.length > 0 ? mh.invokeWithArguments(params) : mh.invoke();
- } catch (Throwable t) {
- try { // try using built-in JDK 9+ API for invoking default method
- return invokeDefaultMethodUsingPrivateLookup(declaringClass, o, m, params);
- } catch (final NoSuchMethodException ex) {
- throw new WrappedException(t);
- }
- }
- }
- });
- } catch (PrivilegedActionException pae) {
- Throwable wrapped = pae.getCause();
- if (wrapped instanceof WrappedException) {
- throw ((WrappedException)wrapped).getWrapped();
- }
- throw wrapped;
- }
- }
-
- /**
- * For JDK 9+, we could use MethodHandles.privateLookupIn, which is not
- * available in JDK 8.
- */
- private static Object invokeDefaultMethodUsingPrivateLookup(Class<?> declaringClass, Object o, Method m,
- Object[] params) throws WrappedException, NoSuchMethodException {
- try {
- final Method privateLookup = MethodHandles
- .class
- .getDeclaredMethod("privateLookupIn", Class.class, MethodHandles.Lookup.class);
-
- return ((MethodHandles.Lookup)privateLookup
- .invoke(null, declaringClass, MethodHandles.lookup()))
- .unreflectSpecial(m, declaringClass)
- .bindTo(o)
- .invokeWithArguments(params);
- } catch (NoSuchMethodException t) {
- throw t;
- } catch (Throwable t) {
- throw new WrappedException(t);
- }
- }
-
- /**
- * Updates the current state if Client method is invoked, otherwise
- * does the remote invocation or returns a new proxy if subresource
- * method is invoked. Can throw an expected exception if ResponseExceptionMapper
- * is registered
- */
- @Override
- public Object invoke(Object o, Method m, Object[] params) throws Throwable {
- checkClosed();
- Class<?> declaringClass = m.getDeclaringClass();
- if (Client.class == declaringClass || InvocationHandlerAware.class == declaringClass
- || Object.class == declaringClass || Closeable.class == declaringClass
- || AutoCloseable.class == declaringClass) {
- return m.invoke(this, params);
- }
- resetResponse();
- OperationResourceInfo ori = cri.getMethodDispatcher().getOperationResourceInfo(m);
- if (ori == null) {
- if (m.isDefault()) {
- return invokeDefaultMethod(declaringClass, o, m, params);
- }
- reportInvalidResourceMethod(m, "INVALID_RESOURCE_METHOD");
- }
-
- MultivaluedMap<ParameterType, Parameter> types = getParametersInfo(m, params, ori);
- List<Parameter> beanParamsList = getParameters(types, ParameterType.BEAN);
-
- int bodyIndex = getBodyIndex(types, ori);
-
- List<Object> pathParams = getPathParamValues(m, params, types, beanParamsList, ori, bodyIndex);
-
- UriBuilder builder = getCurrentBuilder().clone();
- if (isRoot) {
- addNonEmptyPath(builder, ori.getClassResourceInfo().getURITemplate().getValue());
- }
- addNonEmptyPath(builder, ori.getURITemplate().getValue());
-
- handleMatrixes(m, params, types, beanParamsList, builder);
- handleQueries(m, params, types, beanParamsList, builder);
-
- URI uri = builder.buildFromEncoded(pathParams.toArray()).normalize();
-
- MultivaluedMap<String, String> headers = getHeaders();
- MultivaluedMap<String, String> paramHeaders = new MetadataMap<>();
- handleHeaders(m, params, paramHeaders, beanParamsList, types);
- handleCookies(m, params, paramHeaders, beanParamsList, types);
-
- if (ori.isSubResourceLocator()) {
- ClassResourceInfo subCri = cri.getSubResource(m.getReturnType(), m.getReturnType());
- if (subCri == null) {
- reportInvalidResourceMethod(m, "INVALID_SUBRESOURCE");
- }
-
- MultivaluedMap<String, String> subHeaders = paramHeaders;
- if (inheritHeaders) {
- subHeaders.putAll(headers);
- }
-
- ClientState newState = getState().newState(uri, subHeaders,
- getTemplateParametersMap(ori.getURITemplate(), pathParams));
- ClientProxyImpl proxyImpl =
- new ClientProxyImpl(newState, proxyLoader, subCri, false, inheritHeaders);
- proxyImpl.setConfiguration(getConfiguration());
- return JAXRSClientFactory.createProxy(m.getReturnType(), proxyLoader, proxyImpl);
- }
- headers.putAll(paramHeaders);
-
- getState().setTemplates(getTemplateParametersMap(ori.getURITemplate(), pathParams));
-
- Object body = null;
- if (bodyIndex != -1) {
- body = params[bodyIndex];
- if (body == null) {
- bodyIndex = -1;
- }
- } else if (types.containsKey(ParameterType.FORM)) {
- body = handleForm(m, params, types, beanParamsList);
- } else if (types.containsKey(ParameterType.REQUEST_BODY)) {
- body = handleMultipart(types, ori, params);
- } else if (hasFormParams(params, beanParamsList)) {
- body = handleForm(m, params, types, beanParamsList);
- }
-
- setRequestHeaders(headers, ori, types.containsKey(ParameterType.FORM),
- body == null ? null : body.getClass(), m.getReturnType());
-
- try {
- return doChainedInvocation(uri, headers, ori, params, body, bodyIndex, null, null);
- } finally {
- resetResponseStateImmediatelyIfNeeded();
- }
-
- }
-
- protected void addNonEmptyPath(UriBuilder builder, String pathValue) {
- if (!SLASH.equals(pathValue)) {
- builder.path(pathValue);
- }
- }
-
- protected MultivaluedMap<ParameterType, Parameter> getParametersInfo(Method m,
- Object[] params, OperationResourceInfo ori) {
- MultivaluedMap<ParameterType, Parameter> map = new MetadataMap<>();
-
- List<Parameter> parameters = ori.getParameters();
- if (parameters.isEmpty()) {
- return map;
- }
- int requestBodyParam = 0;
- int multipartParam = 0;
- for (Parameter p : parameters) {
- if (isIgnorableParameter(m, p)) {
- continue;
- }
- if (p.getType() == ParameterType.REQUEST_BODY) {
- requestBodyParam++;
- if (getMultipart(ori, p.getIndex()) != null) {
- multipartParam++;
- }
- }
- map.add(p.getType(), p);
- }
-
- if (map.containsKey(ParameterType.REQUEST_BODY)) {
- if (requestBodyParam > 1 && requestBodyParam != multipartParam) {
- reportInvalidResourceMethod(ori.getMethodToInvoke(), "SINGLE_BODY_ONLY");
- }
- if (map.containsKey(ParameterType.FORM)) {
- reportInvalidResourceMethod(ori.getMethodToInvoke(), "ONLY_FORM_ALLOWED");
- }
- }
- return map;
- }
-
- protected boolean isIgnorableParameter(Method m, Parameter p) {
- if (p.getType() == ParameterType.CONTEXT) {
- return true;
- }
- return p.getType() == ParameterType.REQUEST_BODY
- && m.getParameterTypes()[p.getIndex()] == AsyncResponse.class;
- }
-
- protected static int getBodyIndex(MultivaluedMap<ParameterType, Parameter> map,
- OperationResourceInfo ori) {
- List<Parameter> list = map.get(ParameterType.REQUEST_BODY);
- int index = list == null || list.size() > 1 ? -1 : list.get(0).getIndex();
- if (ori.isSubResourceLocator() && index != -1) {
- reportInvalidResourceMethod(ori.getMethodToInvoke(), "NO_BODY_IN_SUBRESOURCE");
- }
- return index;
- }
-
- protected void checkResponse(Method m, Response r, Message inMessage) throws Throwable {
- Throwable t = null;
- int status = r.getStatus();
-
- if (status >= 300) {
- Class<?>[] exTypes = m.getExceptionTypes();
- if (exTypes.length == 0) {
- exTypes = new Class<?>[]{WebApplicationException.class};
- }
- for (Class<?> exType : exTypes) {
- ResponseExceptionMapper<?> mapper = findExceptionMapper(inMessage, exType);
- if (mapper != null) {
- t = mapper.fromResponse(r);
- if (t != null) {
- throw t;
- }
- }
- }
-
- if ((t == null) && (m.getReturnType() == Response.class) && (m.getExceptionTypes().length == 0)) {
- return;
- }
-
- t = convertToWebApplicationException(r);
-
- if (inMessage.getExchange().get(Message.RESPONSE_CODE) == null) {
- throw t;
- }
-
- Endpoint ep = inMessage.getExchange().getEndpoint();
- inMessage.getExchange().put(InterceptorProvider.class, getConfiguration());
- inMessage.setContent(Exception.class, new Fault(t));
- inMessage.getInterceptorChain().abort();
- if (ep.getInFaultObserver() != null) {
- ep.getInFaultObserver().onMessage(inMessage);
- }
-
- throw t;
-
- }
- }
-
- protected static ResponseExceptionMapper<?> findExceptionMapper(Message message, Class<?> exType) {
- ClientProviderFactory pf = ClientProviderFactory.getInstance(message);
- return pf.createResponseExceptionMapper(message, exType);
- }
-
- protected MultivaluedMap<String, String> setRequestHeaders(MultivaluedMap<String, String> headers,
- OperationResourceInfo ori,
- boolean formParams,
- Class<?> bodyClass,
- Class<?> responseClass) {
- if (headers.getFirst(HttpHeaders.CONTENT_TYPE) == null) {
- if (formParams || bodyClass != null && MultivaluedMap.class.isAssignableFrom(bodyClass)) {
- headers.putSingle(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED);
- } else {
- String ctType = null;
- List<MediaType> consumeTypes = ori.getConsumeTypes();
- if (!consumeTypes.isEmpty() && !consumeTypes.get(0).equals(MediaType.WILDCARD_TYPE)) {
- ctType = JAXRSUtils.mediaTypeToString(ori.getConsumeTypes().get(0));
- }
- if (ctType != null) {
- headers.putSingle(HttpHeaders.CONTENT_TYPE, ctType);
- }
- }
- }
-
- List<MediaType> accepts = getAccept(headers);
- if (accepts == null) {
- if (responseClass == Void.class || responseClass == Void.TYPE) {
- accepts = Collections.singletonList(MediaType.WILDCARD_TYPE);
- } else {
- List<MediaType> produceTypes = ori.getProduceTypes();
- boolean produceWildcard = produceTypes.isEmpty()
- || produceTypes.get(0).equals(MediaType.WILDCARD_TYPE);
- if (produceWildcard) {
- accepts = InjectionUtils.isPrimitive(responseClass)
- ? Collections.singletonList(MediaType.TEXT_PLAIN_TYPE)
- : Collections.singletonList(MediaType.APPLICATION_XML_TYPE);
- } else {
- accepts = produceTypes;
- }
- }
-
- for (MediaType mt : accepts) {
- headers.add(HttpHeaders.ACCEPT, JAXRSUtils.mediaTypeToString(mt));
- }
- }
-
- return headers;
- }
-
- protected List<MediaType> getAccept(MultivaluedMap<String, String> allHeaders) {
- List<String> headers = allHeaders.get(HttpHeaders.ACCEPT);
- if (headers == null || headers.isEmpty()) {
- return null;
- }
- return headers.stream().
- flatMap(header -> JAXRSUtils.parseMediaTypes(header).stream()).collect(Collectors.toList());
- }
-
- protected List<Object> getPathParamValues(Method m,
- Object[] params,
- MultivaluedMap<ParameterType, Parameter> map,
- List<Parameter> beanParams,
- OperationResourceInfo ori,
- int bodyIndex) {
- List<Object> list = new ArrayList<>();
-
- List<String> methodVars = ori.getURITemplate().getVariables();
- List<Parameter> paramsList = getParameters(map, ParameterType.PATH);
- Map<String, BeanPair> beanParamValues = new HashMap<>(beanParams.size());
- beanParams.forEach(p -> {
- beanParamValues.putAll(getValuesFromBeanParam(params[p.getIndex()], PathParam.class));
- });
- if (!beanParamValues.isEmpty() && !methodVars.containsAll(beanParamValues.keySet())) {
- List<String> classVars = ori.getClassResourceInfo().getURITemplate().getVariables();
- classVars.forEach(classVar -> {
- BeanPair pair = beanParamValues.get(classVar);
- if (pair != null) {
- Object paramValue = convertParamValue(pair.getValue(), pair.getAnns());
- if (isRoot) {
- valuesMap.put(classVar, paramValue);
- } else {
- list.add(paramValue);
- }
- }
- });
- }
- if (isRoot) {
- list.addAll(valuesMap.values());
- }
-
-
- Map<String, Parameter> paramsMap = new LinkedHashMap<>();
- paramsList.forEach(p -> {
- if (p.getName().isEmpty()) {
- MultivaluedMap<String, Object> values = InjectionUtils.extractValuesFromBean(params[p.getIndex()], "");
- methodVars.forEach(var -> {
- list.addAll(values.get(var));
- });
- } else {
- paramsMap.put(p.getName(), p);
- }
- });
-
- Object requestBody = bodyIndex == -1 ? null : params[bodyIndex];
- methodVars.forEach(varName -> {
- Parameter p = paramsMap.remove(varName);
- if (p != null) {
- list.add(convertParamValue(params[p.getIndex()],
- m.getParameterTypes()[p.getIndex()],
- getParamAnnotations(m, p)));
- } else if (beanParamValues.containsKey(varName)) {
- BeanPair pair = beanParamValues.get(varName);
- list.add(convertParamValue(pair.getValue(), pair.getAnns()));
- } else if (requestBody != null) {
- try {
- Method getter = requestBody.getClass().
- getMethod("get" + StringUtils.capitalize(varName), new Class<?>[]{});
- list.add(getter.invoke(requestBody, new Object[]{}));
- } catch (Exception ex) {
- // continue
- }
- }
- });
-
- for (Parameter p : paramsMap.values()) {
- if (valuesMap.containsKey(p.getName())) {
- int index = 0;
- for (Iterator<String> it = valuesMap.keySet().iterator(); it.hasNext(); index++) {
- if (it.next().equals(p.getName()) && index < list.size()) {
- list.set(index, convertParamValue(params[p.getIndex()], null));
- break;
- }
- }
- }
- }
-
-
- return list;
- }
-
- protected static Annotation[] getParamAnnotations(Method m, Parameter p) {
- return m.getParameterAnnotations()[p.getIndex()];
- }
-
- protected static List<Parameter> getParameters(MultivaluedMap<ParameterType, Parameter> map,
- ParameterType key) {
- return map.get(key) == null ? Collections.emptyList() : map.get(key);
- }
-
- protected void handleQueries(Method m,
- Object[] params,
- MultivaluedMap<ParameterType, Parameter> map,
- List<Parameter> beanParams,
- UriBuilder ub) {
- List<Parameter> qs = getParameters(map, ParameterType.QUERY);
- qs.stream().
- filter(p -> params[p.getIndex()] != null).
- forEachOrdered(p -> {
- addMatrixQueryParamsToBuilder(ub, p.getName(), ParameterType.QUERY,
- getParamAnnotations(m, p), params[p.getIndex()]);
- });
- beanParams.stream().
- map(p -> getValuesFromBeanParam(params[p.getIndex()], QueryParam.class)).
- forEachOrdered(values -> {
- values.forEach((key, value) -> {
- if (value != null) {
- addMatrixQueryParamsToBuilder(ub, key, ParameterType.QUERY,
- value.getAnns(), value.getValue());
- }
- });
- });
- }
-
- protected Map<String, BeanPair> getValuesFromBeanParam(Object bean, Class<? extends Annotation> annClass) {
- Map<String, BeanPair> values = new HashMap<>();
- getValuesFromBeanParam(bean, annClass, values);
- return values;
- }
-
- protected Map<String, BeanPair> getValuesFromBeanParam(Object bean,
- Class<? extends Annotation> annClass,
- Map<String, BeanPair> values) {
- boolean completeFieldIntrospectionNeeded = false;
- for (Method m : bean.getClass().getMethods()) {
- if (m.getName().startsWith("set")) {
- try {
- String propertyName = m.getName().substring(3);
- Annotation methodAnnotation = m.getAnnotation(annClass);
- boolean beanParam = m.getAnnotation(BeanParam.class) != null;
- if (methodAnnotation != null || beanParam) {
- Method getter = bean.getClass().getMethod("get" + propertyName, new Class<?>[]{});
- Object value = getter.invoke(bean, new Object[]{});
- if (value != null) {
- if (methodAnnotation != null) {
- String annotationValue = AnnotationUtils.getAnnotationValue(methodAnnotation);
- values.put(annotationValue, new BeanPair(value, m.getParameterAnnotations()[0]));
- } else {
- getValuesFromBeanParam(value, annClass, values);
- }
- }
- } else {
- String fieldName = StringUtils.uncapitalize(propertyName);
- Field f = InjectionUtils.getDeclaredField(bean.getClass(), fieldName);
- if (f == null) {
- completeFieldIntrospectionNeeded = true;
- continue;
- }
- boolean jaxrsParamAnnAvailable = getValuesFromBeanParamField(bean, f, annClass, values);
- if (!jaxrsParamAnnAvailable && f.getAnnotation(BeanParam.class) != null) {
- Object value = ReflectionUtil.accessDeclaredField(f, bean, Object.class);
- if (value != null) {
- getValuesFromBeanParam(value, annClass, values);
- }
- }
- }
- } catch (Throwable t) {
- // ignore
- }
- }
- if (completeFieldIntrospectionNeeded) {
- for (Field f : bean.getClass().getDeclaredFields()) {
- boolean jaxrsParamAnnAvailable = getValuesFromBeanParamField(bean, f, annClass, values);
- if (!jaxrsParamAnnAvailable && f.getAnnotation(BeanParam.class) != null) {
- Object value = ReflectionUtil.accessDeclaredField(f, bean, Object.class);
- if (value != null) {
- getValuesFromBeanParam(value, annClass, values);
- }
- }
- }
- }
- }
- return values;
- }
-
- protected boolean getValuesFromBeanParamField(Object bean,
- Field f,
- Class<? extends Annotation> annClass,
- Map<String, BeanPair> values) {
- boolean jaxrsParamAnnAvailable = false;
- Annotation fieldAnnotation = f.getAnnotation(annClass);
- if (fieldAnnotation != null) {
- jaxrsParamAnnAvailable = true;
- Object value = ReflectionUtil.accessDeclaredField(f, bean, Object.class);
- if (value != null) {
- String annotationValue = AnnotationUtils.getAnnotationValue(fieldAnnotation);
- values.put(annotationValue, new BeanPair(value, f.getAnnotations()));
- }
- }
- return jaxrsParamAnnAvailable;
- }
-
- protected void handleMatrixes(Method m,
- Object[] params,
- MultivaluedMap<ParameterType, Parameter> map,
- List<Parameter> beanParams,
- UriBuilder ub) {
- List<Parameter> mx = getParameters(map, ParameterType.MATRIX);
- mx.stream().
- filter(p -> params[p.getIndex()] != null).
- forEachOrdered(p -> {
- addMatrixQueryParamsToBuilder(ub, p.getName(), ParameterType.MATRIX,
- getParamAnnotations(m, p), params[p.getIndex()]);
- });
- beanParams.stream().
- map(p -> getValuesFromBeanParam(params[p.getIndex()], MatrixParam.class)).
- forEachOrdered(values -> {
- values.forEach((key, value) -> {
- if (value != null) {
- addMatrixQueryParamsToBuilder(ub, key, ParameterType.MATRIX,
- value.getAnns(), value.getValue());
- }
- });
- });
- }
-
- protected MultivaluedMap<String, String> handleForm(Method m,
- Object[] params,
- MultivaluedMap<ParameterType, Parameter> map,
- List<Parameter> beanParams) {
-
- MultivaluedMap<String, String> form = new MetadataMap<>();
-
- List<Parameter> fm = getParameters(map, ParameterType.FORM);
- fm.forEach(p -> {
- addFormValue(form, p.getName(), params[p.getIndex()], getParamAnnotations(m, p));
- });
- beanParams.stream().
- map(p -> getValuesFromBeanParam(params[p.getIndex()], FormParam.class)).
- forEachOrdered(values -> {
- values.forEach((key, value) -> {
- addFormValue(form, key, value.getValue(), value.getAnns());
- });
- });
-
- return form;
- }
-
- protected void addFormValue(MultivaluedMap<String, String> form, String name, Object pValue, Annotation[] anns) {
- if (pValue != null) {
- if (InjectionUtils.isSupportedCollectionOrArray(pValue.getClass())) {
- Collection<?> c = pValue.getClass().isArray()
- ? Arrays.asList((Object[]) pValue) : (Collection<?>) pValue;
- for (Iterator<?> it = c.iterator(); it.hasNext();) {
- FormUtils.addPropertyToForm(form, name, convertParamValue(it.next(), anns));
- }
- } else {
- FormUtils.addPropertyToForm(form, name, name.isEmpty()
- ? pValue : convertParamValue(pValue, anns));
- }
-
- }
-
- }
-
- protected List<Attachment> handleMultipart(MultivaluedMap<ParameterType, Parameter> map,
- OperationResourceInfo ori,
- Object[] params) {
- List<Parameter> fm = getParameters(map, ParameterType.REQUEST_BODY);
- List<Attachment> atts = new ArrayList<>(fm.size());
- fm.forEach(p -> {
- Multipart part = getMultipart(ori, p.getIndex());
- if (part != null) {
- Object partObject = params[p.getIndex()];
- if (partObject != null) {
- atts.add(new Attachment(part.value(), part.type(), partObject));
- }
- }
- });
- return atts;
- }
-
- protected void handleHeaders(Method m,
- Object[] params,
- MultivaluedMap<String, String> headers,
- List<Parameter> beanParams,
- MultivaluedMap<ParameterType, Parameter> map) {
- List<Parameter> hs = getParameters(map, ParameterType.HEADER);
- hs.stream().
- filter(p -> params[p.getIndex()] != null).
- forEachOrdered(p -> {
- headers.add(p.getName(), convertParamValue(params[p.getIndex()], getParamAnnotations(m, p)));
- });
- beanParams.stream().
- map(p -> getValuesFromBeanParam(params[p.getIndex()], HeaderParam.class)).
- forEachOrdered(values -> {
- values.forEach((key, value) -> {
- if (value != null) {
- headers.add(key, convertParamValue(value.getValue(), value.getAnns()));
- }
- });
- });
- }
-
- protected static Multipart getMultipart(OperationResourceInfo ori, int index) {
- Method aMethod = ori.getAnnotatedMethod();
- return aMethod != null ? AnnotationUtils.getAnnotation(
- aMethod.getParameterAnnotations()[index], Multipart.class) : null;
- }
-
- protected void handleCookies(Method m,
- Object[] params,
- MultivaluedMap<String, String> headers,
- List<Parameter> beanParams,
- MultivaluedMap<ParameterType, Parameter> map) {
- List<Parameter> cs = getParameters(map, ParameterType.COOKIE);
- cs.stream().
- filter(p -> params[p.getIndex()] != null).
- forEachOrdered(p -> {
- headers.add(HttpHeaders.COOKIE,
- p.getName() + '='
- + convertParamValue(params[p.getIndex()].toString(), getParamAnnotations(m, p)));
- });
- beanParams.stream().
- map(p -> getValuesFromBeanParam(params[p.getIndex()], CookieParam.class)).
- forEachOrdered(values -> {
- values.forEach((key, value) -> {
- if (value != null) {
- headers.add(HttpHeaders.COOKIE,
- key + "=" + convertParamValue(value.getValue(), value.getAnns()));
- }
- });
- });
- }
-
- protected Message createMessage(Object body,
- OperationResourceInfo ori,
- MultivaluedMap<String, String> headers,
- URI currentURI,
- Exchange exchange,
- Map<String, Object> invocationContext,
- boolean isProxy) {
- return createMessage(body, ori.getHttpMethod(), headers, currentURI,
- exchange, invocationContext, isProxy);
- }
-
- //CHECKSTYLE:OFF
- protected Object doChainedInvocation(URI uri,
- MultivaluedMap<String, String> headers,
- OperationResourceInfo ori,
- Object[] methodParams,
- Object body,
- int bodyIndex,
- Exchange exchange,
- Map<String, Object> invocationContext) throws Throwable {
- //CHECKSTYLE:ON
- Bus configuredBus = getConfiguration().getBus();
- Bus origBus = BusFactory.getAndSetThreadDefaultBus(configuredBus);
- ClassLoaderHolder origLoader = null;
- try {
- ClassLoader loader = configuredBus.getExtension(ClassLoader.class);
- if (loader != null) {
- origLoader = ClassLoaderUtils.setThreadContextClassloader(loader);
- }
- Message outMessage = createMessage(body, ori, headers, uri, exchange, invocationContext, true);
- if (bodyIndex != -1) {
- outMessage.put(Type.class, ori.getMethodToInvoke().getGenericParameterTypes()[bodyIndex]);
- }
- outMessage.getExchange().setOneWay(ori.isOneway());
- setSupportOnewayResponseProperty(outMessage);
- outMessage.setContent(OperationResourceInfo.class, ori);
- setPlainOperationNameProperty(outMessage, ori.getMethodToInvoke().getName());
- outMessage.getExchange().put(Method.class, ori.getMethodToInvoke());
-
- outMessage.put(Annotation.class.getName(),
- getMethodAnnotations(ori.getAnnotatedMethod(), bodyIndex));
-
- outMessage.getExchange().put(Message.SERVICE_OBJECT, proxy);
- if (methodParams != null) {
- outMessage.put(List.class, Arrays.asList(methodParams));
- }
- if (body != null) {
- outMessage.put(PROXY_METHOD_PARAM_BODY_INDEX, bodyIndex);
- }
- outMessage.getInterceptorChain().add(bodyWriter);
-
- Map<String, Object> reqContext = getRequestContext(outMessage);
- reqContext.put(OperationResourceInfo.class.getName(), ori);
- reqContext.put(PROXY_METHOD_PARAM_BODY_INDEX, bodyIndex);
-
- // execute chain
- InvocationCallback<Object> asyncCallback = checkAsyncCallback(ori, reqContext, outMessage);
- if (asyncCallback != null) {
- return doInvokeAsync(ori, outMessage, asyncCallback);
- }
- doRunInterceptorChain(outMessage);
-
- Object[] results = preProcessResult(outMessage);
- if (results != null && results.length == 1) {
- return results[0];
- }
-
- try {
- return handleResponse(outMessage, ori.getClassResourceInfo().getServiceClass());
- } finally {
- completeExchange(outMessage.getExchange(), true);
- }
-
- } finally {
- if (origLoader != null) {
- origLoader.reset();
- }
- if (origBus != configuredBus) {
- BusFactory.setThreadDefaultBus(origBus);
- }
- }
-
- }
-
- protected InvocationCallback<Object> checkAsyncCallback(OperationResourceInfo ori,
- Map<String, Object> reqContext,
- Message outMessage) {
- Object callbackProp = reqContext.get(InvocationCallback.class.getName());
- if (callbackProp != null) {
- if (callbackProp instanceof Collection) {
- @SuppressWarnings("unchecked")
- Collection<InvocationCallback<Object>> callbacks = (Collection<InvocationCallback<Object>>)callbackProp;
- for (InvocationCallback<Object> callback : callbacks) {
- if (doCheckAsyncCallback(ori, callback) != null) {
- return callback;
- }
- }
- } else {
- @SuppressWarnings("unchecked")
- InvocationCallback<Object> callback = (InvocationCallback<Object>)callbackProp;
- return doCheckAsyncCallback(ori, callback);
- }
- }
- return null;
- }
-
- protected InvocationCallback<Object> doCheckAsyncCallback(OperationResourceInfo ori,
- InvocationCallback<Object> callback) {
- Type callbackOutType = getCallbackType(callback);
- Class<?> callbackRespClass = getCallbackClass(callbackOutType);
-
- Class<?> methodReturnType = ori.getMethodToInvoke().getReturnType();
- if (Object.class == callbackRespClass
- || callbackRespClass.isAssignableFrom(methodReturnType)
- || PrimitiveUtils.canPrimitiveTypeBeAutoboxed(methodReturnType, callbackRespClass)) {
- return callback;
- }
- return null;
- }
-
- protected Object doInvokeAsync(OperationResourceInfo ori,
- Message outMessage,
- InvocationCallback<Object> asyncCallback) {
- outMessage.getExchange().setSynchronous(false);
- setAsyncMessageObserverIfNeeded(outMessage.getExchange());
- JaxrsClientCallback<?> cb = newJaxrsClientCallback(asyncCallback, outMessage,
- ori.getMethodToInvoke().getReturnType(), ori.getMethodToInvoke().getGenericReturnType());
- outMessage.getExchange().put(JaxrsClientCallback.class, cb);
- doRunInterceptorChain(outMessage);
-
- return null;
- }
-
- protected JaxrsClientCallback<?> newJaxrsClientCallback(InvocationCallback<Object> asyncCallback,
- Message outMessage,
- Class<?> responseClass,
- Type outGenericType) {
- return new JaxrsClientCallback<>(asyncCallback, responseClass, outGenericType);
- }
-
- @Override
- protected Object retryInvoke(URI newRequestURI,
- MultivaluedMap<String, String> headers,
- Object body,
- Exchange exchange,
- Map<String, Object> invContext) throws Throwable {
-
- Map<String, Object> reqContext = CastUtils.cast((Map<?, ?>)invContext.get(REQUEST_CONTEXT));
- int bodyIndex = body != null ? (Integer)reqContext.get(PROXY_METHOD_PARAM_BODY_INDEX) : -1;
- OperationResourceInfo ori =
- (OperationResourceInfo)reqContext.get(OperationResourceInfo.class.getName());
- return doChainedInvocation(newRequestURI, headers, ori, null,
- body, bodyIndex, exchange, invContext);
- }
-
- protected Object handleResponse(Message outMessage, Class<?> serviceCls)
- throws Throwable {
- try {
- Response r = setResponseBuilder(outMessage, outMessage.getExchange()).build();
- ((ResponseImpl)r).setOutMessage(outMessage);
- getState().setResponse(r);
-
- Method method = outMessage.getExchange().get(Method.class);
- checkResponse(method, r, outMessage);
- if (method.getReturnType() == Void.class || method.getReturnType() == Void.TYPE) {
- return null;
- }
- if (method.getReturnType() == Response.class
- && (r.getEntity() == null || InputStream.class.isAssignableFrom(r.getEntity().getClass())
- && ((InputStream)r.getEntity()).available() == 0)) {
- return r;
- }
- if (PropertyUtils.isTrue(super.getConfiguration().getResponseContext().get(BUFFER_PROXY_RESPONSE))) {
- r.bufferEntity();
- }
-
- Class<?> returnType = getReturnType(method, outMessage);
- Type genericType = getGenericReturnType(serviceCls, method, returnType);
-
- returnType = InjectionUtils.updateParamClassToTypeIfNeeded(returnType, genericType);
- return readBody(r,
- outMessage,
- returnType,
- genericType,
- method.getDeclaredAnnotations());
- } finally {
- ClientProviderFactory.getInstance(outMessage).clearThreadLocalProxies();
- }
- }
-
- protected Type getGenericReturnType(Class<?> serviceCls, Method method, Class<?> returnType) {
- return InjectionUtils.processGenericTypeIfNeeded(serviceCls, returnType, method.getGenericReturnType());
- }
-
- protected Class<?> getReturnType(Method method, Message outMessage) {
- return method.getReturnType();
- }
-
- public Object getInvocationHandler() {
- return this;
- }
-
- protected static void reportInvalidResourceMethod(Method m, String name) {
- org.apache.cxf.common.i18n.Message errorMsg =
- new org.apache.cxf.common.i18n.Message(name,
- BUNDLE,
- m.getDeclaringClass().getName(),
- m.getName());
- LOG.severe(errorMsg.toString());
- throw new ProcessingException(errorMsg.toString());
- }
-
- protected static Annotation[] getMethodAnnotations(Method aMethod, int bodyIndex) {
- return aMethod == null || bodyIndex == -1 ? new Annotation[0]
- : aMethod.getParameterAnnotations()[bodyIndex];
- }
-
- /**
- * Checks if @BeanParam object has at least one @FormParam declaration.
- * @param params parameter values
- * @param beanParams bean parameters
- * @return "true" @BeanParam object has at least one @FormParam, "false" otherwise
- */
- private boolean hasFormParams(Object[] params, List<Parameter> beanParams) {
- return beanParams
- .stream()
- .map(p -> getValuesFromBeanParam(params[p.getIndex()], FormParam.class))
- .anyMatch(((Predicate<Map<String, BeanPair>>) Map::isEmpty).negate());
- }
-
- protected class BodyWriter extends AbstractBodyWriter {
-
- @Override
- protected void doWriteBody(Message outMessage,
- Object body,
- Type bodyType,
- Annotation[] customAnns,
- OutputStream os) throws Fault {
-
-
- OperationResourceInfo ori = outMessage.getContent(OperationResourceInfo.class);
- if (ori == null) {
- return;
- }
-
- Method method = ori.getMethodToInvoke();
- int bodyIndex = (Integer)outMessage.get(PROXY_METHOD_PARAM_BODY_INDEX);
-
- Annotation[] anns = customAnns != null ? customAnns
- : getMethodAnnotations(ori.getAnnotatedMethod(), bodyIndex);
- try {
- Class<?>[] parameterTypes = method.getParameterTypes();
- if (bodyIndex >= 0 && bodyIndex < parameterTypes.length) {
- Class<?> paramClass = parameterTypes[bodyIndex];
- Class<?> bodyClass =
- paramClass.isAssignableFrom(body.getClass()) ? paramClass : body.getClass();
- Type genericType = bodyType;
- if (genericType == null) {
- Type[] genericParameterTypes = method.getGenericParameterTypes();
- if (bodyIndex < genericParameterTypes.length) {
- genericType = genericParameterTypes[bodyIndex];
- }
- }
- genericType = InjectionUtils.processGenericTypeIfNeeded(
- ori.getClassResourceInfo().getServiceClass(), bodyClass, genericType);
- bodyClass = InjectionUtils.updateParamClassToTypeIfNeeded(bodyClass, genericType);
- writeBody(body, outMessage, bodyClass, genericType, anns, os);
- } else {
- Type paramType = body.getClass();
- if (bodyType != null) {
- paramType = bodyType;
- }
- writeBody(body, outMessage, body.getClass(), paramType,
- anns, os);
- }
- } catch (Exception ex) {
- throw new Fault(ex);
- }
-
- }
-
- }
-
- protected static class BeanPair {
- protected Object value;
- protected Annotation[] anns;
- BeanPair(Object value, Annotation[] anns) {
- this.value = value;
- this.anns = anns;
- }
- public Object getValue() {
- return value;
- }
- public Annotation[] getAnns() {
- return anns;
- }
- }
- class ClientAsyncResponseInterceptor extends AbstractClientAsyncResponseInterceptor {
- @Override
- protected void doHandleAsyncResponse(Message message, Response r, JaxrsClientCallback<?> cb) {
- try {
- Object entity = handleResponse(message.getExchange().getOutMessage(),
- cb.getResponseClass());
- cb.handleResponse(message, new Object[] {entity});
- } catch (Throwable t) {
- cb.handleException(message, t);
- } finally {
- completeExchange(message.getExchange(), false);
- closeAsyncResponseIfPossible(r, message, cb);
- }
- }
- }
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxrs/client/JAXRSClientFactory.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxrs/client/JAXRSClientFactory.java
deleted file mode 100644
index 1e487ab..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxrs/client/JAXRSClientFactory.java
+++ /dev/null
@@ -1,414 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.cxf.jaxrs.client;
-
-import java.lang.reflect.InvocationHandler;
-import java.net.URI;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-
-import javax.ws.rs.core.MultivaluedMap;
-
-import org.apache.cxf.common.util.ProxyHelper;
-import org.apache.cxf.feature.Feature;
-import org.apache.cxf.jaxrs.model.UserResource;
-
-/**
- * Factory for creating proxy clients.
- *
- */
-public final class JAXRSClientFactory {
-
- private JAXRSClientFactory() {
-
- }
-
- /**
- * Creates a proxy
- * @param baseAddress baseAddress
- * @param cls resource class, if not interface then a CGLIB proxy will be created
- * @return typed proxy
- */
- public static <T> T create(String baseAddress, Class<T> cls) {
- return create(URI.create(baseAddress), cls);
- }
-
- /**
- * Creates a proxy using a custom class loader
- * @param baseAddress baseAddress
- * @param loader class loader
- * @param cls resource class, if not interface then a CGLIB proxy will be created
- * @return typed proxy
- */
- public static <T> T create(String baseAddress, Class<T> cls, ClassLoader loader) {
- JAXRSClientFactoryBean bean = getBean(baseAddress, cls, null);
- bean.setClassLoader(loader);
- return bean.create(cls);
- }
-
- /**
- * Creates a proxy
- * @param baseURI baseURI
- * @param cls resource class, if not interface then a CGLIB proxy will be created
- * @return typed proxy
- */
- public static <T> T create(URI baseURI, Class<T> cls) {
- return create(baseURI, cls, false);
- }
-
- /**
- * Creates a proxy
- * @param baseURI baseURI
- * @param cls resource class, if not interface then a CGLIB proxy will be created
- * @param inheritHeaders if true then existing proxy headers will be inherited by
- * subresource proxies if any
- * @return typed proxy
- */
- public static <T> T create(URI baseURI, Class<T> cls, boolean inheritHeaders) {
- JAXRSClientFactoryBean bean = getBean(baseURI.toString(), cls, null);
- bean.setInheritHeaders(inheritHeaders);
- return bean.create(cls);
- }
-
- /**
- * Creates a proxy
- * @param baseAddress baseAddres
- * @param cls resource class, if not interface then a CGLIB proxy will be created
- * @param properties additional properties
- * @return typed proxy
- */
- public static <T> T create(String baseAddress, Class<T> cls, Map<String, Object> properties) {
- JAXRSClientFactoryBean bean = getBean(baseAddress, cls, null);
- bean.setProperties(properties);
- return bean.create(cls);
- }
-
- /**
- * Creates a proxy
- * @param baseAddress baseAddress
- * @param cls resource class, if not interface then a CGLIB proxy will be created
- * @param configLocation classpath location of the configuration resource
- * @return typed proxy
- */
- public static <T> T create(String baseAddress, Class<T> cls, String configLocation) {
- JAXRSClientFactoryBean bean = getBean(baseAddress, cls, configLocation);
- return bean.create(cls);
- }
-
- /**
- * Creates a proxy
- * @param baseAddress baseAddress
- * @param cls resource class, if not interface then a CGLIB proxy will be created
- * This class is expected to have a root JAXRS Path annotation containing
- * template variables, for ex, "/path/{id1}/{id2}"
- * @param configLocation classpath location of the configuration resource
- * @param varValues values to replace root Path template variables
- * @return typed proxy
- */
- public static <T> T create(String baseAddress, Class<T> cls, String configLocation,
- Object... varValues) {
- JAXRSClientFactoryBean bean = getBean(baseAddress, cls, configLocation);
- return bean.create(cls, varValues);
- }
-
-
- /**
- * Creates a proxy
- * @param baseAddress baseAddress
- * @param cls proxy class, if not interface then a CGLIB proxy will be created
- * @param providers list of providers
- * @return typed proxy
- */
- public static <T> T create(String baseAddress, Class<T> cls, List<?> providers) {
- return create(baseAddress, cls, providers, null);
- }
-
- /**
- * Creates a thread safe proxy
- * @param baseAddress baseAddress
- * @param cls proxy class, if not interface then a CGLIB proxy will be created
- * @param providers list of providers
- * @param threadSafe if true then a thread-safe proxy will be created
- * @return typed proxy
- */
- public static <T> T create(String baseAddress, Class<T> cls, List<?> providers, boolean threadSafe) {
- return create(baseAddress, cls, providers, Collections.emptyMap(), threadSafe);
- }
- /**
- * Creates a thread safe proxy
- * @param baseAddress baseAddress
- * @param cls proxy class, if not interface then a CGLIB proxy will be created
- * @param providers list of providers
- * @param threadSafe if true then a thread-safe proxy will be created
- * @param properties additional properties
- * @return typed proxy
- */
- public static <T> T create(String baseAddress, Class<T> cls, List<?> providers,
- Map<String, Object> properties, boolean threadSafe) {
- JAXRSClientFactoryBean bean = getBean(baseAddress, cls, null);
- bean.setProviders(providers);
- bean.setProperties(properties);
- if (threadSafe) {
- bean.setInitialState(new ThreadLocalClientState(baseAddress, properties));
- }
- return bean.create(cls);
- }
-
- /**
- * Creates a thread safe proxy and allows to specify time to keep state.
- * @param baseAddress baseAddress
- * @param cls proxy class, if not interface then a CGLIB proxy will be created
- * @param providers list of providers
- * @param timeToKeepState how long to keep this state
- * @return typed proxy
- */
- public static <T> T create(String baseAddress, Class<T> cls, List<?> providers, long timeToKeepState) {
- JAXRSClientFactoryBean bean = getBean(baseAddress, cls, null);
- bean.setProviders(providers);
- bean.setInitialState(new ThreadLocalClientState(baseAddress, timeToKeepState));
- return bean.create(cls);
- }
-
- /**
- * Creates a proxy
- * @param baseAddress baseAddress
- * @param cls proxy class, if not interface then a CGLIB proxy will be created
- * @param providers list of providers
- * @param configLocation classpath location of the configuration resource
- * @return typed proxy
- */
- public static <T> T create(String baseAddress, Class<T> cls, List<?> providers, String configLocation) {
- JAXRSClientFactoryBean bean = getBean(baseAddress, cls, configLocation);
- bean.setProviders(providers);
- return bean.create(cls);
- }
-
- /**
- * Creates a proxy
- * @param baseAddress baseAddress
- * @param cls proxy class, if not interface then a CGLIB proxy will be created
- * @param providers list of providers
- * @param features the features which will be applied to the client
- * @param configLocation classpath location of the configuration resource
- * @return typed proxy
- */
- public static <T> T create(String baseAddress, Class<T> cls, List<?> providers,
- List<Feature> features,
- String configLocation) {
- JAXRSClientFactoryBean bean = getBean(baseAddress, cls, configLocation);
- bean.setProviders(providers);
- bean.setFeatures(features);
- return bean.create(cls);
- }
-
- /**
- * Creates a proxy which will do basic authentication
- * @param baseAddress baseAddress
- * @param cls proxy class, if not interface then a CGLIB proxy will be created
- * @param username username
- * @param password password
- * @param configLocation classpath location of the configuration resource
- * @return typed proxy
- */
- public static <T> T create(String baseAddress, Class<T> cls, String username,
- String password, String configLocation) {
- JAXRSClientFactoryBean bean = getBean(baseAddress, cls, configLocation);
- bean.setUsername(username);
- bean.setPassword(password);
- return bean.create(cls);
- }
-
- /**
- * Creates a proxy which will do basic authentication
- * @param baseAddress baseAddress
- * @param cls proxy class, if not interface then a CGLIB proxy will be created
- * @param providers list of providers
- * @param username username
- * @param password password
- * @param configLocation classpath location of the configuration resource
- * @return typed proxy
- */
- public static <T> T create(String baseAddress, Class<T> cls, List<?> providers,
- String username, String password, String configLocation) {
- JAXRSClientFactoryBean bean = getBean(baseAddress, cls, configLocation);
- bean.setUsername(username);
- bean.setPassword(password);
- bean.setProviders(providers);
- return bean.create(cls);
- }
-
- /**
- * Creates a proxy using user resource model
- * @param baseAddress baseAddress
- * @param cls proxy class, if not interface then a CGLIB proxy will be created
- * @param modelRef model location
- * @return typed proxy
- */
- public static <T> T createFromModel(String baseAddress, Class<T> cls, String modelRef,
- String configLocation) {
- return createFromModel(baseAddress, cls, modelRef, Collections.emptyList(), configLocation);
- }
-
- /**
- * Creates a proxy using user resource model
- * @param baseAddress baseAddress
- * @param cls proxy class, if not interface then a CGLIB proxy will be created
- * @param modelRef model location
- * @param providers list of providers
- * @param configLocation classpath location of the configuration resource
- * @return typed proxy
- */
- public static <T> T createFromModel(String baseAddress, Class<T> cls, String modelRef,
- List<?> providers, String configLocation) {
- JAXRSClientFactoryBean bean = WebClient.getBean(baseAddress, configLocation);
- bean.setProviders(providers);
- bean.setModelRef(modelRef);
- bean.setServiceClass(cls);
- return bean.create(cls);
- }
-
- /**
- * Creates a thread safe proxy using user resource model
- * @param baseAddress baseAddress
- * @param cls proxy class, if not interface then a CGLIB proxy will be created
- * @param modelRef model location
- * @param providers list of providers
- * @param threadSafe if true then thread-safe proxy will be created
- * @return typed proxy
- */
- public static <T> T createFromModel(String baseAddress, Class<T> cls, String modelRef,
- List<?> providers, boolean threadSafe) {
- JAXRSClientFactoryBean bean = WebClient.getBean(baseAddress, null);
- bean.setProviders(providers);
- bean.setModelRef(modelRef);
- bean.setServiceClass(cls);
- if (threadSafe) {
- bean.setInitialState(new ThreadLocalClientState(baseAddress));
- }
- return bean.create(cls);
- }
-
- /**
- * Creates a thread safe proxy using user resource model and allows to
- * specify time to keep state.
- * @param baseAddress baseAddress
- * @param cls proxy class, if not interface then a CGLIB proxy will be created
- * @param modelRef model location
- * @param providers list of providers
- * @param timeToKeepState how long to keep this state
- * @return typed proxy
- */
- public static <T> T createFromModel(String baseAddress, Class<T> cls, String modelRef,
- List<?> providers, long timeToKeepState) {
- JAXRSClientFactoryBean bean = WebClient.getBean(baseAddress, null);
- bean.setProviders(providers);
- bean.setModelRef(modelRef);
- bean.setServiceClass(cls);
- bean.setInitialState(new ThreadLocalClientState(baseAddress, timeToKeepState));
- return bean.create(cls);
- }
-
- /**
- * Creates a proxy using user resource model
- * @param baseAddress baseAddress
- * @param cls proxy class, if not interface then a CGLIB proxy will be created
- * @param modelBeans model beans
- * @param configLocation classpath location of the configuration resource
- * @return typed proxy
- */
- public static <T> T createFromModel(String baseAddress, Class<T> cls, List<UserResource> modelBeans,
- String configLocation) {
- return createFromModel(baseAddress, cls, modelBeans, Collections.emptyList(), configLocation);
- }
-
- /**
- * Creates a proxy using user resource model
- * @param baseAddress baseAddress
- * @param cls proxy class, if not interface then a CGLIB proxy will be created
- * @param modelBeans model beans
- * @param providers list of providers
- * @param configLocation classpath location of the configuration resource
- * @return typed proxy
- */
- public static <T> T createFromModel(String baseAddress, Class<T> cls, List<UserResource> modelBeans,
- List<?> providers, String configLocation) {
- JAXRSClientFactoryBean bean = WebClient.getBean(baseAddress, configLocation);
-
- bean.setProviders(providers);
- bean.setModelBeans(modelBeans);
- bean.setServiceClass(cls);
- return bean.create(cls);
- }
-
- /**
- * Creates a proxy, baseURI will be set to Client currentURI
- *
- * @param client Client instance
- * @param cls proxy class, if not interface then a CGLIB proxy will be created
- * @return typed proxy
- */
- public static <T> T fromClient(Client client, Class<T> cls) {
- return fromClient(client, cls, false);
- }
-
- /**
- * Creates a proxy, baseURI will be set to Client currentURI
- * @param client Client instance
- * @param cls proxy class, if not interface then a CGLIB proxy will be created
- * @param inheritHeaders if true then existing Client headers will be inherited by new proxy
- * and subresource proxies if any
- * @return typed proxy
- */
- public static <T> T fromClient(Client client, Class<T> cls, boolean inheritHeaders) {
- JAXRSClientFactoryBean bean = getBean(client.getCurrentURI().toString(), cls, null);
- bean.setInheritHeaders(inheritHeaders);
-
- ClientState clientState = WebClient.getClientState(client);
-
- final T proxy;
- if (clientState == null) {
- proxy = bean.create(cls);
- if (inheritHeaders) {
- WebClient.client(proxy).headers(client.getHeaders());
- }
- } else {
- MultivaluedMap<String, String> headers = inheritHeaders ? client.getHeaders() : null;
- bean.setInitialState(clientState.newState(client.getCurrentURI(), headers, null, bean.getProperties()));
- proxy = bean.create(cls);
- }
- WebClient.copyProperties(WebClient.client(proxy), client);
- return proxy;
- }
-
- static <T> T createProxy(Class<T> cls, ClassLoader loader, InvocationHandler handler) {
-
- return cls.cast(ProxyHelper.getProxy(loader == null ? cls.getClassLoader() : loader,
- new Class[]{Client.class, InvocationHandlerAware.class, cls},
- handler));
- }
-
- private static JAXRSClientFactoryBean getBean(String baseAddress, Class<?> cls, String configLocation) {
- JAXRSClientFactoryBean bean = WebClient.getBean(baseAddress, configLocation);
- bean.setServiceClass(cls);
- return bean;
- }
-
-
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxrs/client/LocalClientState.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxrs/client/LocalClientState.java
deleted file mode 100644
index 477e5d3..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxrs/client/LocalClientState.java
+++ /dev/null
@@ -1,185 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.cxf.jaxrs.client;
-
-import java.net.URI;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-
-import javax.ws.rs.core.MultivaluedMap;
-import javax.ws.rs.core.Response;
-import javax.ws.rs.core.UriBuilder;
-
-import org.apache.cxf.common.util.StringUtils;
-import org.apache.cxf.jaxrs.impl.MetadataMap;
-import org.apache.cxf.jaxrs.impl.UriBuilderImpl;
-
-/**
- * Keeps the client state such as the baseURI, currentURI, requestHeaders, current response
- *
- */
-public class LocalClientState implements ClientState {
- private static final String HTTP_SCHEME = "http";
- private static final String WS_SCHEME = "ws";
-
- private MultivaluedMap<String, String> requestHeaders = new MetadataMap<>(false, true);
- private MultivaluedMap<String, String> templates;
- private Response response;
- private URI baseURI;
- private UriBuilder currentBuilder;
- private Map<String, Object> properties;
-
- public LocalClientState() {
-
- }
-
- public LocalClientState(URI baseURI) {
- this(baseURI, Collections.emptyMap());
- }
-
- public LocalClientState(URI baseURI, Map<String, Object> properties) {
- this.baseURI = baseURI;
-
- if (properties != null) {
- this.properties = new HashMap<>(properties);
- }
-
- resetCurrentUri(properties);
- }
-
- public LocalClientState(URI baseURI, URI currentURI) {
- this(baseURI, currentURI, Collections.emptyMap());
- }
-
- public LocalClientState(URI baseURI, URI currentURI, Map<String, Object> properties) {
- this.baseURI = baseURI;
-
- if (properties != null) {
- this.properties = new HashMap<>(properties);
- }
-
- this.currentBuilder = new UriBuilderImpl(properties).uri(currentURI);
- }
-
- public LocalClientState(LocalClientState cs) {
- this.requestHeaders = new MetadataMap<>(cs.requestHeaders);
- this.templates = cs.templates == null ? null : new MetadataMap<String, String>(cs.templates);
- this.response = cs.response;
-
- this.baseURI = cs.baseURI;
- this.currentBuilder = cs.currentBuilder != null ? cs.currentBuilder.clone() : null;
- this.properties = cs.properties;
- }
-
- private void resetCurrentUri(Map<String, Object> props) {
- if (isSupportedScheme(baseURI)) {
- this.currentBuilder = new UriBuilderImpl(props).uri(baseURI);
- } else {
- this.currentBuilder = new UriBuilderImpl(props).uri("/");
- }
- }
-
- public void setCurrentBuilder(UriBuilder currentBuilder) {
- this.currentBuilder = currentBuilder;
- }
-
- public UriBuilder getCurrentBuilder() {
- return currentBuilder;
- }
-
- public void setBaseURI(URI baseURI) {
- this.baseURI = baseURI;
- resetCurrentUri(Collections.emptyMap());
- }
-
- public URI getBaseURI() {
- return baseURI;
- }
-
- public void setResponse(Response r) {
- this.response = r;
- }
-
- public Response getResponse() {
- return response;
- }
-
- public void setRequestHeaders(MultivaluedMap<String, String> requestHeaders) {
- this.requestHeaders = requestHeaders;
- }
-
- public MultivaluedMap<String, String> getRequestHeaders() {
- return requestHeaders;
- }
-
- public MultivaluedMap<String, String> getTemplates() {
- return templates;
- }
-
- public void setTemplates(MultivaluedMap<String, String> map) {
- if (templates == null) {
- this.templates = map;
- } else if (map != null) {
- templates.putAll(map);
- } else {
- templates = null;
- }
- }
-
- public void reset() {
- requestHeaders.clear();
- response = null;
- currentBuilder = new UriBuilderImpl(properties).uri(baseURI);
- templates = null;
- }
-
- public ClientState newState(URI currentURI, MultivaluedMap<String, String> headers,
- MultivaluedMap<String, String> templatesMap, Map<String, Object> props) {
- final ClientState state;
- if (isSupportedScheme(currentURI)) {
- state = new LocalClientState(currentURI, props);
- } else {
- state = new LocalClientState(baseURI, currentURI, props);
- }
- if (headers != null) {
- state.setRequestHeaders(headers);
- }
- // we need to carry the template parameters forward
- MultivaluedMap<String, String> newTemplateParams = templates;
- if (newTemplateParams != null && templatesMap != null) {
- newTemplateParams.putAll(templatesMap);
- } else {
- newTemplateParams = templatesMap;
- }
- state.setTemplates(newTemplateParams);
- return state;
- }
-
- public ClientState newState(URI currentURI,
- MultivaluedMap<String, String> headers,
- MultivaluedMap<String, String> templatesMap) {
- return newState(currentURI, headers, templatesMap, properties);
- }
-
- private static boolean isSupportedScheme(URI uri) {
- return !StringUtils.isEmpty(uri.getScheme())
- && (uri.getScheme().startsWith(HTTP_SCHEME) || uri.getScheme().startsWith(WS_SCHEME));
- }
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxrs/client/WebClient.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxrs/client/WebClient.java
deleted file mode 100644
index eaedd4b..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxrs/client/WebClient.java
+++ /dev/null
@@ -1,1349 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.cxf.jaxrs.client;
-
-import java.io.OutputStream;
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Type;
-import java.net.URI;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Future;
-
-import javax.ws.rs.HttpMethod;
-import javax.ws.rs.ProcessingException;
-import javax.ws.rs.WebApplicationException;
-import javax.ws.rs.client.AsyncInvoker;
-import javax.ws.rs.client.CompletionStageRxInvoker;
-import javax.ws.rs.client.Entity;
-import javax.ws.rs.client.InvocationCallback;
-import javax.ws.rs.client.RxInvoker;
-import javax.ws.rs.client.RxInvokerProvider;
-import javax.ws.rs.client.SyncInvoker;
-import javax.ws.rs.core.Cookie;
-import javax.ws.rs.core.EntityTag;
-import javax.ws.rs.core.Form;
-import javax.ws.rs.core.GenericEntity;
-import javax.ws.rs.core.GenericType;
-import javax.ws.rs.core.HttpHeaders;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.MultivaluedMap;
-import javax.ws.rs.core.PathSegment;
-import javax.ws.rs.core.Response;
-import javax.ws.rs.core.Response.ResponseBuilder;
-import javax.ws.rs.core.UriBuilder;
-
-import org.apache.cxf.Bus;
-import org.apache.cxf.BusFactory;
-import org.apache.cxf.bus.spring.SpringBusFactory;
-import org.apache.cxf.common.classloader.ClassLoaderUtils;
-import org.apache.cxf.common.classloader.ClassLoaderUtils.ClassLoaderHolder;
-import org.apache.cxf.common.util.ClassHelper;
-import org.apache.cxf.common.util.PropertyUtils;
-import org.apache.cxf.feature.Feature;
-import org.apache.cxf.helpers.CastUtils;
-import org.apache.cxf.interceptor.Fault;
-import org.apache.cxf.jaxrs.client.spec.ClientImpl.WebTargetImpl;
-import org.apache.cxf.jaxrs.client.spec.InvocationBuilderImpl;
-import org.apache.cxf.jaxrs.impl.ResponseImpl;
-import org.apache.cxf.jaxrs.impl.UriBuilderImpl;
-import org.apache.cxf.jaxrs.model.ParameterType;
-import org.apache.cxf.jaxrs.model.URITemplate;
-import org.apache.cxf.jaxrs.utils.HttpUtils;
-import org.apache.cxf.jaxrs.utils.JAXRSUtils;
-import org.apache.cxf.jaxrs.utils.ParameterizedCollectionType;
-import org.apache.cxf.message.Exchange;
-import org.apache.cxf.message.Message;
-
-
-/**
- * Http-centric web client
- *
- */
-public class WebClient extends AbstractClient {
- private static final String REQUEST_CLASS = "request.class";
- private static final String REQUEST_TYPE = "request.type";
- private static final String REQUEST_ANNS = "request.annotations";
- private static final String RESPONSE_CLASS = "response.class";
- private static final String RESPONSE_TYPE = "response.type";
- private static final String WEB_CLIENT_OPERATION_REPORTING = "enable.webclient.operation.reporting";
- private BodyWriter bodyWriter = new BodyWriter();
- protected WebClient(String baseAddress) {
- this(convertStringToURI(baseAddress), Collections.emptyMap());
- }
-
- protected WebClient(String baseAddress, Map<String, Object> properties) {
- this(convertStringToURI(baseAddress), properties);
- }
-
- protected WebClient(URI baseURI) {
- this(baseURI, Collections.emptyMap());
- }
-
- protected WebClient(URI baseURI, Map<String, Object> properties) {
- this(new LocalClientState(baseURI, properties));
- }
-
- protected WebClient(ClientState state) {
- super(state);
- cfg.getInInterceptors().add(new ClientAsyncResponseInterceptor());
- }
-
-
-
-
- /**
- * Creates WebClient
- * @param baseAddress baseAddress
- */
- public static WebClient create(String baseAddress) {
- return create(baseAddress, Collections.emptyMap());
- }
-
- /**
- * Creates WebClient
- * @param baseAddress baseAddress
- */
- public static WebClient create(String baseAddress, Map<String, Object> properties) {
- JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean();
- bean.setAddress(baseAddress);
- bean.setProperties(properties);
- return bean.createWebClient();
- }
-
- /**
- * Creates WebClient
- * @param baseURI baseURI
- */
- public static WebClient create(URI baseURI) {
- return create(baseURI.toString());
- }
-
- /**
- * Creates WebClient
- * @param baseURI baseURI
- */
- public static WebClient create(String baseURI, boolean threadSafe) {
- return create(baseURI, Collections.emptyList(), threadSafe);
- }
-
- /**
- * Creates WebClient
- * @param baseAddress baseURI
- * @param providers list of providers
- */
- public static WebClient create(String baseAddress, List<?> providers) {
- return create(baseAddress, providers, null);
- }
-
- /**
- * Creates WebClient
- * @param baseAddress baseURI
- * @param providers list of providers
- * @param threadSafe if true ThreadLocalClientState is used
- */
- public static WebClient create(String baseAddress, List<?> providers, boolean threadSafe) {
- return create(baseAddress, providers, Collections.emptyMap(), threadSafe);
- }
-
- /**
- * Creates WebClient
- * @param baseAddress baseURI
- * @param providers list of providers
- * @param threadSafe if true ThreadLocalClientState is used
- * @param properties additional properties
- */
- public static WebClient create(String baseAddress, List<?> providers,
- Map<String, Object> properties, boolean threadSafe) {
- JAXRSClientFactoryBean bean = getBean(baseAddress, null);
- bean.setProviders(providers);
- bean.setProperties(properties);
- if (threadSafe) {
- bean.setInitialState(new ThreadLocalClientState(baseAddress, properties));
- }
- return bean.createWebClient();
- }
-
- /**
- * Creates a thread safe WebClient
- * @param baseAddress baseURI
- * @param providers list of providers
- * @param timeToKeepState time to keep this thread safe state.
- */
- public static WebClient create(String baseAddress, List<?> providers, long timeToKeepState) {
- JAXRSClientFactoryBean bean = getBean(baseAddress, null);
- bean.setProviders(providers);
- bean.setInitialState(new ThreadLocalClientState(baseAddress, timeToKeepState));
- return bean.createWebClient();
- }
-
- /**
- * Creates WebClient
- * @param baseAddress baseAddress
- * @param providers list of providers
- * @param configLocation classpath location of the configuration resource, can be null
- * @return WebClient instance
- */
- public static WebClient create(String baseAddress, List<?> providers, String configLocation) {
- JAXRSClientFactoryBean bean = getBean(baseAddress, configLocation);
- bean.setProviders(providers);
- return bean.createWebClient();
- }
-
- /**
- * Creates WebClient with a list of custom features
- * @param baseAddress baseAddress
- * @param providers list of providers
- * @param features the features which will be applied to the client
- * @param configLocation classpath location of the configuration resource, can be null
- * @return WebClient instance
- */
- public static WebClient create(String baseAddress,
- List<?> providers,
- List<? extends Feature> features,
- String configLocation) {
- JAXRSClientFactoryBean bean = getBean(baseAddress, configLocation);
- bean.setProviders(providers);
- bean.setFeatures(features);
- return bean.createWebClient();
- }
-
- /**
- * Creates WebClient
- * @param baseAddress baseAddress
- * @param configLocation classpath location of the configuration resource, can be null
- * @return WebClient instance
- */
- public static WebClient create(String baseAddress, String configLocation) {
- JAXRSClientFactoryBean bean = getBean(baseAddress, configLocation);
-
- return bean.createWebClient();
- }
-
- /**
- * Creates WebClient which will do basic authentication
- * @param baseAddress baseAddress
- * @param username username
- * @param password password
- * @param configLocation classpath location of the configuration resource, can be null
- * @return WebClient instance
- */
- public static WebClient create(String baseAddress, String username, String password,
- String configLocation) {
- JAXRSClientFactoryBean bean = getBean(baseAddress, configLocation);
-
- bean.setUsername(username);
- bean.setPassword(password);
-
- return bean.createWebClient();
- }
-
- /**
- * Creates WebClient which will do basic authentication
- * @param baseAddress baseAddress
- * @param providers list of providers
- * @param username username
- * @param password password
- * @param configLocation classpath location of the configuration resource, can be null
- * @return WebClient instance
- */
- public static WebClient create(String baseAddress, List<?> providers,
- String username, String password, String configLocation) {
- JAXRSClientFactoryBean bean = getBean(baseAddress, configLocation);
-
- bean.setUsername(username);
- bean.setPassword(password);
- bean.setProviders(providers);
- return bean.createWebClient();
- }
-
- /**
- * Creates WebClient, baseURI will be set to Client currentURI
- * @param object existing client object
- */
- public static WebClient fromClientObject(Object object) {
- Client client = client(object);
- return client == null ? null : fromClient(client, false);
- }
-
- /**
- * Creates WebClient, baseURI will be set to Client currentURI
- * @param client existing client
- */
- public static WebClient fromClient(Client client) {
- return fromClient(client, false);
- }
-
- /**
- * Creates WebClient, baseURI will be set to Client currentURI
- * @param client existing client
- * @param inheritHeaders if existing Client headers can be inherited by new client
- */
- public static WebClient fromClient(Client client, boolean inheritHeaders) {
-
- final WebClient webClient;
-
- ClientState clientState = getClientState(client);
- if (clientState == null) {
- webClient = create(client.getCurrentURI());
- if (inheritHeaders) {
- webClient.headers(client.getHeaders());
- }
- } else {
- MultivaluedMap<String, String> headers = inheritHeaders ? client.getHeaders() : null;
- webClient = new WebClient(clientState.newState(client.getCurrentURI(), headers, null));
- }
- copyProperties(webClient, client);
- return webClient;
- }
-
- /**
- * Converts object to Client
- * @param object the object
- * @return Client object converted to Client
- */
- public static Client client(Object object) {
- if (object instanceof Client) {
- return (Client)object;
- }
- return null;
- }
-
- /**
- * Retrieves ClientConfiguration
- * @param client proxy or http-centric Client
- * @return underlying ClientConfiguration instance
- */
- public static ClientConfiguration getConfig(Object client) {
- if (client instanceof WebTargetImpl) {
- client = ((WebTargetImpl)client).getWebClient();
- } else if (client instanceof InvocationBuilderImpl) {
- client = ((InvocationBuilderImpl)client).getWebClient();
- }
-
- if (client instanceof Client) {
- if (client instanceof WebClient) {
- return ((AbstractClient)client).getConfiguration();
- } else if (client instanceof InvocationHandlerAware) {
- Object handler = ((InvocationHandlerAware)client).getInvocationHandler();
- return ((AbstractClient)handler).getConfiguration();
- }
- }
- throw new IllegalArgumentException("Not a valid Client");
- }
-
- /**
- * Does HTTP invocation
- * @param httpMethod HTTP method
- * @param body request body, can be null
- * @return JAXRS Response, entity may hold a string representaion of
- * error message if client or server error occured
- */
- public Response invoke(String httpMethod, Object body) {
- return doInvoke(httpMethod, body, null, Response.class, Response.class);
- }
-
- /**
- * Does HTTP POST invocation
- * @param body request body, can be null
- * @return JAXRS Response
- */
- public Response post(Object body) {
- return invoke(HttpMethod.POST, body);
- }
-
- /**
- * Does HTTP PUT invocation
- * @param body request body, can be null
- * @return JAXRS Response
- */
- public Response put(Object body) {
- return invoke(HttpMethod.PUT, body);
- }
-
- /**
- * Does HTTP GET invocation
- * @return JAXRS Response
- */
- public Response get() {
- return invoke(HttpMethod.GET, null);
- }
-
- /**
- * Does HTTP HEAD invocation
- * @return JAXRS Response
- */
- public Response head() {
- return invoke(HttpMethod.HEAD, null);
- }
-
- /**
- * Does HTTP OPTIONS invocation
- * @return JAXRS Response
- */
- public Response options() {
- return invoke(HttpMethod.OPTIONS, null);
- }
-
- /**
- * Does HTTP DELETE invocation
- * @return JAXRS Response
- */
- public Response delete() {
- return invoke(HttpMethod.DELETE, null);
- }
-
- /**
- * Posts form data
- * @param values form values
- * @return JAXRS Response
- */
- public Response form(Map<String, List<Object>> values) {
- type(MediaType.APPLICATION_FORM_URLENCODED);
- return doInvoke(HttpMethod.POST, values, null, Response.class, Response.class);
- }
-
- /**
- * Posts form data
- * @param form form values
- * @return JAXRS Response
- */
- public Response form(Form form) {
- type(MediaType.APPLICATION_FORM_URLENCODED);
- return doInvoke(HttpMethod.POST, form.asMap(), null, Response.class, Response.class);
- }
-
- /**
- * Does HTTP invocation and returns types response object
- * @param httpMethod HTTP method
- * @param body request body, can be null
- * @param responseType generic response type
- * @return typed object, can be null. Response status code and headers
- * can be obtained too, see Client.getResponse()
- */
- public <T> T invoke(String httpMethod, Object body, GenericType<T> responseType) {
- @SuppressWarnings("unchecked")
- Class<T> responseClass = (Class<T>)responseType.getRawType();
- Response r = doInvoke(httpMethod, body, null, responseClass, responseType.getType());
- return castResponse(r, responseClass);
- }
-
- /**
- * Does HTTP invocation and returns types response object
- * @param httpMethod HTTP method
- * @param body request body, can be null
- * @param responseClass expected type of response object
- * @return typed object, can be null. Response status code and headers
- * can be obtained too, see Client.getResponse()
- */
- public <T> T invoke(String httpMethod, Object body, Class<T> responseClass) {
- Response r = doInvoke(httpMethod, body, null, responseClass, responseClass);
- return castResponse(r, responseClass);
- }
-
- /**
- * Does HTTP invocation and returns types response object
- * @param httpMethod HTTP method
- * @param body request body, can be null
- * @param requestClass request body class
- * @param responseClass expected type of response object
- * @return typed object, can be null. Response status code and headers
- * can be obtained too, see Client.getResponse()
- */
- public <T> T invoke(String httpMethod, Object body, Class<?> requestClass, Class<T> responseClass) {
- Response r = doInvoke(httpMethod, body, requestClass, null, responseClass, responseClass);
- return castResponse(r, responseClass);
- }
-
- @SuppressWarnings("unchecked")
- private <T> T castResponse(Response r, Class<T> responseClass) {
- return (T)(responseClass == Response.class ? r : r.getEntity());
- }
- /**
- * Does HTTP POST invocation and returns typed response object
- * @param body request body, can be null
- * @param responseClass expected type of response object
- * @return typed object, can be null. Response status code and headers
- * can be obtained too, see Client.getResponse()
- */
- public <T> T post(Object body, Class<T> responseClass) {
- return invoke(HttpMethod.POST, body, responseClass);
- }
-
- /**
- * Does HTTP POST invocation and returns typed response object
- * @param body request body, can be null
- * @param responseType generic response type
- * @return typed object, can be null. Response status code and headers
- * can be obtained too, see Client.getResponse()
- */
- public <T> T post(Object body, GenericType<T> responseType) {
- return invoke(HttpMethod.POST, body, responseType);
- }
-
- /**
- * Does HTTP Async POST invocation and returns Future.
- * Shortcut for async().post(Entity, InvocationCallback)
- * @param callback invocation callback
- * @return the future
- */
- public <T> Future<T> post(Object body, InvocationCallback<T> callback) {
- return doInvokeAsyncCallback(HttpMethod.POST, body, body.getClass(), null, callback);
- }
-
- /**
- * Does HTTP PUT invocation and returns typed response object
- * @param body request body, can be null
- * @param responseClass expected type of response object
- * @return typed object, can be null. Response status code and headers
- * can be obtained too, see Client.getResponse()
- */
- public <T> T put(Object body, Class<T> responseClass) {
- return invoke(HttpMethod.PUT, body, responseClass);
- }
-
-
- /**
- * Does HTTP PUT invocation and returns typed response object
- * @param body request body, can be null
- * @param responseType generic response type
- * @return typed object, can be null. Response status code and headers
- * can be obtained too, see Client.getResponse()
- */
- public <T> T put(Object body, GenericType<T> responseType) {
- return invoke(HttpMethod.PUT, body, responseType);
- }
-
- /**
- * Does HTTP Async PUT invocation and returns Future.
- * Shortcut for async().put(Entity, InvocationCallback)
- * @param callback invocation callback
- * @return the future
- */
- public <T> Future<T> put(Object body, InvocationCallback<T> callback) {
- return doInvokeAsyncCallback(HttpMethod.PUT, body, body.getClass(), null, callback);
- }
-
- /**
- * Does HTTP invocation and returns a collection of typed objects
- * @param httpMethod HTTP method
- * @param body request body, can be null
- * @param memberClass expected type of collection member class
- * @return typed collection
- */
- public <T> Collection<? extends T> invokeAndGetCollection(String httpMethod, Object body,
- Class<T> memberClass) {
- Response r = doInvoke(httpMethod, body, null,
- Collection.class, new ParameterizedCollectionType(memberClass));
- return CastUtils.cast((Collection<?>)r.getEntity(), memberClass);
- }
-
- /**
- * Posts a collection of typed objects
- * @param collection request body
- * @param memberClass type of collection member class
- * @return JAX-RS Response
- */
- public <T> Response postCollection(Object collection, Class<T> memberClass) {
- return doInvoke(HttpMethod.POST, collection, new ParameterizedCollectionType(memberClass),
- Response.class, Response.class);
- }
-
- /**
- * Posts a collection of typed objects
- * @param collection request body
- * @param memberClass type of collection member class
- * @param responseClass expected type of response object
- * @return JAX-RS Response
- */
- public <T1, T2> T2 postCollection(Object collection, Class<T1> memberClass,
- Class<T2> responseClass) {
- Response r = doInvoke(HttpMethod.POST, collection, new ParameterizedCollectionType(memberClass),
- responseClass, responseClass);
- return responseClass.cast(responseClass == Response.class ? r : r.getEntity());
- }
-
- /**
- * Posts collection of typed objects and returns a collection of typed objects
- * @param collection request body
- * @param memberClass type of collection member class
- * @param responseClass expected type of response object
- * @return JAX-RS Response
- */
- public <T1, T2> Collection<? extends T2> postAndGetCollection(Object collection,
- Class<T1> memberClass,
- Class<T2> responseClass) {
- Response r = doInvoke(HttpMethod.POST, collection, new ParameterizedCollectionType(memberClass),
- Collection.class, new ParameterizedCollectionType(responseClass));
- return CastUtils.cast((Collection<?>)r.getEntity(), responseClass);
- }
-
- /**
- * Posts the object and returns a collection of typed objects
- * @param body request body
- * @param responseClass expected type of response object
- * @return JAX-RS Response
- */
- public <T> Collection<? extends T> postObjectGetCollection(Object body,
- Class<T> responseClass) {
- Response r = doInvoke(HttpMethod.POST, body, null, Collection.class,
- new ParameterizedCollectionType(responseClass));
- return CastUtils.cast((Collection<?>)r.getEntity(), responseClass);
- }
-
- /**
- * Posts request body and returns a collection of typed objects
- * @param body request body, can be null
- * @param memberClass expected type of collection member class
- * @return typed collection
- */
- public <T> Collection<? extends T> postAndGetCollection(Object body, Class<T> memberClass) {
- return invokeAndGetCollection(HttpMethod.POST, body, memberClass);
- }
-
- /**
- * Does HTTP GET invocation and returns a collection of typed objects
- * @param memberClass expected type of collection member class
- * @return typed collection
- */
- public <T> Collection<? extends T> getCollection(Class<T> memberClass) {
- return invokeAndGetCollection(HttpMethod.GET, null, memberClass);
- }
-
- /**
- * Does HTTP GET invocation and returns typed response object
- * @param responseClass expected type of response object
- * @return typed object, can be null. Response status code and headers
- * can be obtained too, see Client.getResponse()
- */
- public <T> T get(Class<T> responseClass) {
- return invoke(HttpMethod.GET, null, responseClass);
- }
-
-
- /**
- * Does HTTP GET invocation and returns typed response object
- * @param responseType generic response type
- * @return typed object, can be null. Response status code and headers
- * can be obtained too, see Client.getResponse()
- */
- public <T> T get(GenericType<T> responseType) {
- return invoke(HttpMethod.GET, null, responseType);
- }
-
- /**
- * Does HTTP Async GET invocation and returns Future.
- * Shortcut for async().get(InvocationCallback)
- * @param callback invocation callback
- * @return the future
- */
- public <T> Future<T> get(InvocationCallback<T> callback) {
- return doInvokeAsyncCallback(HttpMethod.GET, null, null, null, callback);
- }
-
- /**
- * Updates the current URI path
- * @param path new relative path segment
- * @return updated WebClient
- */
- public WebClient path(Object path) {
- getCurrentBuilder().path(convertParamValue(path, null));
-
- return this;
- }
-
- /**
- * Updates the current URI path with path segment which may contain template variables
- * @param path new relative path segment
- * @param values template variable values
- * @return updated WebClient
- */
- public WebClient path(String path, Object... values) {
- URI u = new UriBuilderImpl().uri(URI.create("http://tempuri")).path(path).buildFromEncoded(values);
- getState().setTemplates(getTemplateParametersMap(new URITemplate(path), Arrays.asList(values)));
- return path(u.getRawPath());
- }
-
- @Override
- public WebClient query(String name, Object ...values) {
- return (WebClient)super.query(name, values);
- }
-
- /**
- * Updates the current URI matrix parameters
- * @param name matrix name
- * @param values matrix values
- * @return updated WebClient
- */
- public WebClient matrix(String name, Object ...values) {
- addMatrixQueryParamsToBuilder(getCurrentBuilder(), name, ParameterType.MATRIX, null, values);
- return this;
- }
-
- /**
- * Updates the current URI fragment
- * @param name fragment name
- * @return updated WebClient
- */
- public WebClient fragment(String name) {
- getCurrentBuilder().fragment(name);
- return this;
- }
-
- /**
- * Moves WebClient to a new baseURI or forwards to new currentURI
- * @param newAddress new URI
- * @param forward if true then currentURI will be based on baseURI
- * @return updated WebClient
- */
- public WebClient to(String newAddress, boolean forward) {
- getState().setTemplates(null);
- if (forward) {
- if (!newAddress.startsWith("/")
- && !newAddress.startsWith(getBaseURI().toString())) {
- throw new IllegalArgumentException("Base address can not be preserved");
- }
- resetCurrentBuilder(URI.create(newAddress));
- } else {
- resetBaseAddress(URI.create(newAddress));
- }
- return this;
- }
-
- /**
- * Goes back
- * @param fast if true then goes back to baseURI otherwise to a previous path segment
- * @return updated WebClient
- */
- public WebClient back(boolean fast) {
- getState().setTemplates(null);
- if (fast) {
- getCurrentBuilder().replacePath(getBaseURI().getPath());
- } else {
- URI uri = getCurrentURI();
- if (uri == getBaseURI()) {
- return this;
- }
- List<PathSegment> segments = JAXRSUtils.getPathSegments(uri.getPath(), false);
- getCurrentBuilder().replacePath(null);
- for (int i = 0; i < segments.size() - 1; i++) {
- getCurrentBuilder().path(HttpUtils.fromPathSegment(segments.get(i)));
- }
-
- }
- return this;
- }
-
- /**
- * Replaces the current path with the new value.
- * @param path new path value. If it starts from "/" then all the current
- * path starting from the base URI will be replaced, otherwise only the
- * last path segment will be replaced. Providing a null value is equivalent
- * to calling back(true)
- * @return updated WebClient
- */
- public WebClient replacePath(String path) {
- if (path == null) {
- return back(true);
- }
- back(path.startsWith("/") ? true : false);
- return path(path);
- }
-
- /**
- * Resets the current query
- * @return updated WebClient
- */
- public WebClient resetQuery() {
- return replaceQuery(null);
- }
-
- /**
- * Replaces the current query with the new value.
- * @param queryString the new value, providing a null is
- * equivalent to calling resetQuery().
- * @return updated WebClient
- */
- public WebClient replaceQuery(String queryString) {
- getCurrentBuilder().replaceQuery(queryString);
- return this;
- }
-
- /**
- * Replaces the header value with the new values.
- * @param headerName headerValues
- * @param value new values, null is equivalent to removing the header
- * @return updated WebClient
- */
- public WebClient replaceHeader(String headerName, Object value) {
- MultivaluedMap<String, String> headers = getState().getRequestHeaders();
- headers.remove(headerName);
- if (value != null) {
- super.header(headerName, value);
- }
- return this;
- }
-
- /**
- * Replaces the current query with the new value.
- * @param queryParam query param name
- * @param value the new value, providing a null is
- * equivalent to calling resetQuery().
- * @return updated WebClient
- */
- public WebClient replaceQueryParam(String queryParam, Object... value) {
- getCurrentBuilder().replaceQueryParam(queryParam, value);
- return this;
- }
-
- @Override
- public WebClient type(MediaType ct) {
- return (WebClient)super.type(ct);
- }
-
- @Override
- public WebClient type(String type) {
- return (WebClient)super.type(type);
- }
-
- @Override
- public WebClient accept(MediaType... types) {
- return (WebClient)super.accept(types);
- }
-
- @Override
- public WebClient accept(String... types) {
- return (WebClient)super.accept(types);
- }
-
- @Override
- public WebClient language(String language) {
- return (WebClient)super.language(language);
- }
-
- @Override
- public WebClient acceptLanguage(String ...languages) {
- return (WebClient)super.acceptLanguage(languages);
- }
-
- @Override
- public WebClient encoding(String encoding) {
- return (WebClient)super.encoding(encoding);
- }
-
- @Override
- public WebClient acceptEncoding(String ...encodings) {
- return (WebClient)super.acceptEncoding(encodings);
- }
-
- @Override
- public WebClient match(EntityTag tag, boolean ifNot) {
- return (WebClient)super.match(tag, ifNot);
- }
-
- @Override
- public WebClient modified(Date date, boolean ifNot) {
- return (WebClient)super.modified(date, ifNot);
- }
-
- @Override
- public WebClient cookie(Cookie cookie) {
- return (WebClient)super.cookie(cookie);
- }
-
- @Override
- public WebClient authorization(Object auth) {
- return (WebClient)super.authorization(auth);
- }
-
- @Override
- public WebClient header(String name, Object... values) {
- return (WebClient)super.header(name, values);
- }
-
- @Override
- public WebClient headers(MultivaluedMap<String, String> map) {
- return (WebClient)super.headers(map);
- }
-
- @Override
- public WebClient reset() {
- //clearTemplates();
- return (WebClient)super.reset();
- }
-
- protected Response doInvoke(String httpMethod,
- Object body,
- Type inGenericType,
- Class<?> responseClass,
- Type outGenericType) {
- return doInvoke(httpMethod, body, body == null ? null : body.getClass(), inGenericType,
- responseClass, outGenericType);
- }
-
-
-
- protected Response doInvoke(String httpMethod,
- Object body,
- Class<?> requestClass,
- Type inGenericType,
- Class<?> responseClass,
- Type outGenericType) {
- Annotation[] inAnns = null;
- if (body instanceof Entity) {
- Entity<?> entity = (Entity<?>)body;
- setEntityHeaders(entity);
- body = entity.getEntity();
- requestClass = body.getClass();
- inGenericType = body.getClass();
- inAnns = entity.getAnnotations();
- }
- if (body instanceof GenericEntity) {
- GenericEntity<?> genericEntity = (GenericEntity<?>)body;
- body = genericEntity.getEntity();
- requestClass = genericEntity.getRawType();
- inGenericType = genericEntity.getType();
- }
- MultivaluedMap<String, String> headers = prepareHeaders(responseClass, body);
- resetResponse();
- final Response r;
- try {
- r = doChainedInvocation(httpMethod, headers, body, requestClass, inGenericType,
- inAnns, responseClass, outGenericType, null, null);
- } finally {
- resetResponseStateImmediatelyIfNeeded();
- }
-
- int status = r.getStatus();
- if (status != 304 && status >= 300 && responseClass != Response.class) {
- throw convertToWebApplicationException(r);
- }
- return r;
- }
-
- protected <T> Future<T> doInvokeAsyncCallback(String httpMethod,
- Object body,
- Class<?> requestClass,
- Type inType,
- InvocationCallback<T> callback) {
-
- Type outType = getCallbackType(callback);
- Class<?> respClass = getCallbackClass(outType);
- return doInvokeAsync(httpMethod, body, requestClass, inType, respClass, outType, callback);
- }
-
- protected <T> Future<T> doInvokeAsync(String httpMethod,
- Object body,
- Class<?> requestClass,
- Type inType,
- Class<?> respClass,
- Type outType,
- InvocationCallback<T> callback) {
- JaxrsClientCallback<T> cb = new JaxrsClientCallback<>(callback, respClass, outType);
- prepareAsyncClient(httpMethod, body, requestClass, inType, respClass, outType, cb);
- return cb.createFuture();
- }
-
- protected void prepareAsyncClient(String httpMethod,
- Object body,
- Class<?> requestClass,
- Type inType,
- Class<?> respClass,
- Type outType,
- JaxrsClientCallback<?> cb) {
- Annotation[] inAnns = null;
- if (body instanceof Entity) {
- Entity<?> entity = (Entity<?>)body;
- setEntityHeaders(entity);
- body = entity.getEntity();
- requestClass = body.getClass();
- inType = body.getClass();
- inAnns = entity.getAnnotations();
- }
- if (body instanceof GenericEntity) {
- GenericEntity<?> genericEntity = (GenericEntity<?>)body;
- body = genericEntity.getEntity();
- requestClass = genericEntity.getRawType();
- inType = genericEntity.getType();
- }
-
- MultivaluedMap<String, String> headers = prepareHeaders(respClass, body);
- resetResponse();
-
- Message m = finalizeMessage(httpMethod, headers, body, requestClass, inType,
- inAnns, respClass, outType, null, null);
-
- m.getExchange().setSynchronous(false);
- setAsyncMessageObserverIfNeeded(m.getExchange());
- m.getExchange().put(JaxrsClientCallback.class, cb);
-
- doRunInterceptorChain(m);
- }
-
-
- private MultivaluedMap<String, String> prepareHeaders(Class<?> responseClass, Object body) {
- MultivaluedMap<String, String> headers = getHeaders();
- if (headers.getFirst(HttpHeaders.CONTENT_TYPE) == null && body instanceof Form) {
- headers.putSingle(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED);
- }
-
- if (responseClass != null && responseClass != Response.class
- && headers.getFirst(HttpHeaders.ACCEPT) == null) {
- headers.putSingle(HttpHeaders.ACCEPT, MediaType.WILDCARD);
- }
- return headers;
- }
-
- class ClientAsyncResponseInterceptor extends AbstractClientAsyncResponseInterceptor {
- @Override
- protected void doHandleAsyncResponse(Message message, Response r, JaxrsClientCallback<?> cb) {
- if (r == null) {
- try {
- r = handleResponse(message.getExchange().getOutMessage(),
- cb.getResponseClass(),
- cb.getOutGenericType());
- } catch (Throwable t) {
- cb.handleException(message, t);
- return;
- } finally {
- completeExchange(message.getExchange(), false);
- }
- }
- if (cb.getResponseClass() == null || Response.class.equals(cb.getResponseClass())) {
- cb.handleResponse(message, new Object[] {r});
- } else if (r.getStatus() >= 300) {
- cb.handleException(message, convertToWebApplicationException(r));
- } else {
- cb.handleResponse(message, new Object[] {r.getEntity()});
- closeAsyncResponseIfPossible(r, message, cb);
- }
- }
- }
-
-
-
- //TODO: retry invocation will not work in case of async request failures for the moment
- @Override
- protected Object retryInvoke(URI newRequestURI,
- MultivaluedMap<String, String> headers,
- Object body,
- Exchange exchange,
- Map<String, Object> invContext) throws Throwable {
-
- Map<String, Object> reqContext = CastUtils.cast((Map<?, ?>)invContext.get(REQUEST_CONTEXT));
- String httpMethod = (String)reqContext.get(Message.HTTP_REQUEST_METHOD);
- Class<?> requestClass = (Class<?>)reqContext.get(REQUEST_CLASS);
- Type inType = (Type)reqContext.get(REQUEST_TYPE);
- Annotation[] inAnns = (Annotation[])reqContext.get(REQUEST_ANNS);
- Class<?> respClass = (Class<?>)reqContext.get(RESPONSE_CLASS);
- Type outType = (Type)reqContext.get(RESPONSE_TYPE);
- return doChainedInvocation(httpMethod, headers, body, requestClass, inType,
- inAnns, respClass, outType, exchange, invContext);
- }
- //CHECKSTYLE:OFF
- protected Response doChainedInvocation(String httpMethod, //NOPMD
- MultivaluedMap<String, String> headers,
- Object body,
- Class<?> requestClass,
- Type inType,
- Annotation[] inAnns,
- Class<?> respClass,
- Type outType,
- Exchange exchange,
- Map<String, Object> invContext) {
- //CHECKSTYLE:ON
- Bus configuredBus = getConfiguration().getBus();
- Bus origBus = BusFactory.getAndSetThreadDefaultBus(configuredBus);
- ClassLoaderHolder origLoader = null;
- try {
- ClassLoader loader = configuredBus.getExtension(ClassLoader.class);
- if (loader != null) {
- origLoader = ClassLoaderUtils.setThreadContextClassloader(loader);
- }
- Message m = finalizeMessage(httpMethod, headers, body, requestClass, inType,
- inAnns, respClass, outType, exchange, invContext);
- doRunInterceptorChain(m);
- return doResponse(m, respClass, outType);
- } finally {
- if (origLoader != null) {
- origLoader.reset();
- }
- if (origBus != configuredBus) {
- BusFactory.setThreadDefaultBus(origBus);
- }
- }
- }
-
- //CHECKSTYLE:OFF
- private Message finalizeMessage(String httpMethod, //NOPMD
- MultivaluedMap<String, String> headers,
- Object body,
- Class<?> requestClass,
- Type inGenericType,
- Annotation[] inAnns,
- Class<?> responseClass,
- Type outGenericType,
- Exchange exchange,
- Map<String, Object> invContext) {
- //CHECKSTYLE:ON
- URI uri = getCurrentURI();
- Message m = createMessage(body, httpMethod, headers, uri, exchange,
- invContext, false);
- setSupportOnewayResponseProperty(m);
- if (inAnns != null) {
- m.put(Annotation.class.getName(), inAnns);
- }
- Map<String, Object> reqContext = getRequestContext(m);
- reqContext.put(Message.HTTP_REQUEST_METHOD, httpMethod);
- reqContext.put(REQUEST_CLASS, requestClass);
- reqContext.put(REQUEST_TYPE, inGenericType);
- reqContext.put(REQUEST_ANNS, inAnns);
- reqContext.put(RESPONSE_CLASS, responseClass);
- reqContext.put(RESPONSE_TYPE, outGenericType);
-
- if (body != null) {
- m.put(Type.class, inGenericType);
- }
- m.getInterceptorChain().add(bodyWriter);
-
- setWebClientOperationProperty(m, httpMethod);
-
- return m;
- }
-
- private void setWebClientOperationProperty(Message m, String httpMethod) {
- Object prop = m.getContextualProperty(WEB_CLIENT_OPERATION_REPORTING);
- // Enable the operation reporting by default
- if (prop == null || PropertyUtils.isTrue(prop)) {
- UriBuilder absPathUri = super.getCurrentBuilder().clone();
- absPathUri.replaceQuery(null);
- setPlainOperationNameProperty(m, httpMethod + ":" + absPathUri.build().toString());
- }
-
- }
-
- protected Response doResponse(Message m,
- Class<?> responseClass,
- Type outGenericType) {
- try {
- Object[] results = preProcessResult(m);
- if (results != null && results.length == 1) {
- return (Response)results[0];
- }
- } catch (WebApplicationException | ProcessingException ex) {
- throw ex;
- } catch (Exception ex) {
- throw new ProcessingException(ex);
- }
-
- try {
- return handleResponse(m, responseClass, outGenericType);
- } finally {
- completeExchange(m.getExchange(), false);
- }
- }
-
- protected Response handleResponse(Message outMessage, Class<?> responseClass, Type genericType) {
- try {
- ResponseBuilder rb = setResponseBuilder(outMessage, outMessage.getExchange());
- Response currentResponse = rb.clone().build();
- ((ResponseImpl)currentResponse).setOutMessage(outMessage);
-
- Object entity = readBody(currentResponse, outMessage, responseClass, genericType,
- new Annotation[]{});
-
- if (entity == null) {
- int status = currentResponse.getStatus();
- if (status >= 400) {
- entity = currentResponse.getEntity();
- }
- }
- rb = JAXRSUtils.fromResponse(currentResponse, false);
-
- rb.entity(entity instanceof Response
- ? ((Response)entity).getEntity() : entity);
-
- Response r = rb.build();
- getState().setResponse(r);
- ((ResponseImpl)r).setOutMessage(outMessage);
- return r;
- } catch (ProcessingException ex) {
- throw ex;
- } catch (Throwable ex) {
- throw new ProcessingException(ex);
- } finally {
- ClientProviderFactory.getInstance(outMessage).clearThreadLocalProxies();
- }
- }
-
-
- private class BodyWriter extends AbstractBodyWriter {
-
- protected void doWriteBody(Message outMessage,
- Object body,
- Type bodyType,
- Annotation[] customAnns,
- OutputStream os) throws Fault {
-
- Map<String, Object> requestContext = WebClient.this.getRequestContext(outMessage);
- Class<?> requestClass = null;
- Type requestType = null;
- if (requestContext != null) {
- requestClass = (Class<?>)requestContext.get(REQUEST_CLASS);
- requestType = (Type)requestContext.get(REQUEST_TYPE);
- }
- if (bodyType != null) {
- requestType = bodyType;
- }
-
- Annotation[] anns = customAnns != null ? customAnns : new Annotation[]{};
- boolean isAssignable = requestClass != null && requestClass.isAssignableFrom(body.getClass());
- try {
- writeBody(body, outMessage,
- requestClass == null || !isAssignable ? body.getClass() : requestClass,
- requestType == null || !isAssignable ? body.getClass() : requestType,
- anns, os);
- } catch (Exception ex) {
- throw new Fault(ex);
- }
- }
- }
-
- static void copyProperties(Client toClient, Client fromClient) {
- AbstractClient newClient = toAbstractClient(toClient);
- AbstractClient oldClient = toAbstractClient(fromClient);
- newClient.setConfiguration(oldClient.getConfiguration());
- }
-
- private static AbstractClient toAbstractClient(Object client) {
-
- if (client instanceof AbstractClient) {
- return (AbstractClient)client;
- } else if (client instanceof InvocationHandlerAware) {
- return (AbstractClient)((InvocationHandlerAware)client).getInvocationHandler();
- } else {
- Object realObject = ClassHelper.getRealObject(client);
- if (realObject instanceof AbstractClient) {
- return (AbstractClient)realObject;
- }
- }
- return null;
- }
-
- static JAXRSClientFactoryBean getBean(String baseAddress, String configLocation) {
- JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean();
-
- if (configLocation != null) {
- SpringBusFactory bf = new SpringBusFactory();
- Bus bus = bf.createBus(configLocation);
- bean.setBus(bus);
- }
- bean.setAddress(baseAddress);
- return bean;
- }
-
- static ClientState getClientState(Client client) {
- AbstractClient newClient = toAbstractClient(client);
- if (newClient == null) {
- return null;
- }
- return newClient.getState();
- }
-
- static URI convertStringToURI(String baseAddress) {
- try {
- return URI.create(baseAddress);
- } catch (RuntimeException ex) {
- // no need to check "https" scheme or indeed ':'
- // as the relative address will not work as the base address
- if (baseAddress.startsWith(HTTP_SCHEME)) {
- return new UriBuilderImpl().uriAsTemplate(baseAddress).build();
- }
- throw ex;
- }
- }
-
- // Link to JAX-RS 2.0 AsyncInvoker
- public AsyncInvoker async() {
- return new AsyncInvokerImpl(this);
- }
-
- // Link to JAX-RS 2.0 SyncInvoker
- public SyncInvoker sync() {
- return new SyncInvokerImpl(this);
- }
-
- // Link to JAX-RS 2.1 CompletionStageRxInvoker
- public CompletionStageRxInvoker rx() {
- return rx(lookUpExecutorService());
- }
-
- public CompletionStageRxInvoker rx(ExecutorService ex) {
- return new CompletionStageRxInvokerImpl(this, ex);
- }
- // Link to JAX-RS 2.1 RxInvoker extensions
- @SuppressWarnings("rawtypes")
- public <T extends RxInvoker> T rx(Class<T> rxCls) {
- return rx(rxCls, (ExecutorService)null);
- }
-
- @SuppressWarnings({
- "rawtypes", "unchecked"
- })
- public <T extends RxInvoker> T rx(Class<T> rxCls, ExecutorService executorService) {
- if (CompletionStageRxInvoker.class.isAssignableFrom(rxCls)) {
- return (T)rx(executorService);
- }
- ClientProviderFactory pf =
- ClientProviderFactory.getInstance(WebClient.getConfig(this).getEndpoint());
- RxInvokerProvider rxProvider = pf.getRxInvokerProvider();
- if (rxProvider != null && rxProvider.isProviderFor(rxCls)) {
- return (T)rxProvider.getRxInvoker(sync(), executorService);
- }
- throw new IllegalStateException("Provider for " + rxCls.getName() + " is not available");
- }
-
- private void setEntityHeaders(Entity<?> entity) {
- type(entity.getMediaType());
- if (entity.getLanguage() != null) {
- language(entity.getLanguage().toString());
- }
- if (entity.getEncoding() != null) {
- encoding(entity.getEncoding());
- }
- }
-
- private ExecutorService lookUpExecutorService() {
- try {
- javax.naming.InitialContext ic = new javax.naming.InitialContext();
- Object execService = ic.lookup("java:comp/DefaultManagedExecutorService");
- if (execService != null) {
- return (ExecutorService)execService;
- }
- } catch (Throwable ex) {
- // ignore
- }
- return null;
- }
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxrs/client/spec/ClientRequestContextImpl.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxrs/client/spec/ClientRequestContextImpl.java
deleted file mode 100644
index cddf5c6..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxrs/client/spec/ClientRequestContextImpl.java
+++ /dev/null
@@ -1,186 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.cxf.jaxrs.client.spec;
-
-import java.io.OutputStream;
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Type;
-import java.net.URI;
-import java.util.List;
-
-import javax.ws.rs.client.Client;
-import javax.ws.rs.client.ClientRequestContext;
-import javax.ws.rs.core.Configuration;
-import javax.ws.rs.core.GenericEntity;
-import javax.ws.rs.core.HttpHeaders;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.MultivaluedMap;
-
-import org.apache.cxf.jaxrs.client.ClientProviderFactory;
-import org.apache.cxf.jaxrs.impl.AbstractRequestContextImpl;
-import org.apache.cxf.jaxrs.utils.HttpUtils;
-import org.apache.cxf.jaxrs.utils.InjectionUtils;
-import org.apache.cxf.jaxrs.utils.JAXRSUtils;
-import org.apache.cxf.message.Message;
-import org.apache.cxf.message.MessageContentsList;
-
-
-public class ClientRequestContextImpl extends AbstractRequestContextImpl
- implements ClientRequestContext {
-
- public ClientRequestContextImpl(Message m,
- boolean responseContext) {
- super(m, responseContext);
- }
-
- @Override
- public MediaType getMediaType() {
- if (!hasEntity()) {
- return null;
- }
- Object mt = HttpUtils.getModifiableHeaders(m).getFirst(HttpHeaders.CONTENT_TYPE);
- return mt instanceof MediaType ? (MediaType)mt : JAXRSUtils.toMediaType(mt.toString());
- }
-
- @Override
- public Client getClient() {
- return (Client)m.getContextualProperty(Client.class.getName());
- }
-
- @Override
- public Configuration getConfiguration() {
- ClientProviderFactory cpf = ClientProviderFactory.getInstance(m);
- return cpf.getConfiguration(m);
- }
-
- private Object getMessageContent() {
- MessageContentsList objs = MessageContentsList.getContentsList(m);
- if (objs == null || objs.isEmpty()) {
- return null;
- }
- return objs.get(0);
- }
-
- @Override
- public Object getEntity() {
- return getMessageContent();
- }
-
- @Override
- public Annotation[] getEntityAnnotations() {
- Annotation[] anns = (Annotation[])m.get(Annotation.class.getName());
- return anns == null ? new Annotation[] {} : anns;
- }
-
- @Override
- public Class<?> getEntityClass() {
- Object entity = getEntity();
- return entity == null ? null : entity.getClass();
- }
-
- @Override
- public Type getEntityType() {
- Type t = m.get(Type.class);
- return t != null ? t : getEntityClass();
- }
-
- @Override
- public OutputStream getEntityStream() {
- return m.getContent(OutputStream.class);
- }
-
- @Override
- public boolean hasEntity() {
- return getEntity() != null;
- }
-
- @Override
- public void setEntity(Object entity, Annotation[] anns, MediaType mt) {
- if (mt != null) {
- MultivaluedMap<String, Object> headers = getHeaders();
- headers.putSingle(HttpHeaders.CONTENT_TYPE, mt);
- m.put(Message.CONTENT_TYPE, mt.toString());
- }
- if (anns != null) {
- m.put(Annotation.class.getName(), anns);
- }
- doSetEntity(entity);
- }
-
- @Override
- public void setEntity(Object entity) {
- doSetEntity(entity);
- }
-
- private void doSetEntity(Object entity) {
- Object actualEntity = InjectionUtils.getEntity(entity);
- m.setContent(List.class, actualEntity == null ? new MessageContentsList()
- : new MessageContentsList(actualEntity));
- if (entity != null) {
- final Type type;
- if (GenericEntity.class.isAssignableFrom(entity.getClass())) {
- type = ((GenericEntity<?>)entity).getType();
- } else {
- type = entity.getClass();
- }
- m.put(Type.class, type);
- m.remove("org.apache.cxf.empty.request");
- }
-
- }
-
- @Override
- public URI getUri() {
- String requestURI = (String)m.get(Message.REQUEST_URI);
- if (requestURI == null) {
- return null;
- }
- if (requestURI.startsWith("/")) {
- String endpointAddress = (String)m.get(Message.ENDPOINT_ADDRESS);
- requestURI = requestURI.length() == 1 ? endpointAddress : endpointAddress + requestURI;
- }
- return URI.create(requestURI);
- }
-
- @Override
- public void setEntityStream(OutputStream os) {
- m.setContent(OutputStream.class, os);
-
- }
-
- @Override
- public void setUri(URI requestURI) {
- m.put(Message.ENDPOINT_ADDRESS, requestURI.toString());
- m.put(Message.REQUEST_URI, requestURI.toString());
-
- }
-
- @Override
- public MultivaluedMap<String, Object> getHeaders() {
- h = null;
- return HttpUtils.getModifiableHeaders(m);
- }
-
- @Override
- public MultivaluedMap<String, String> getStringHeaders() {
- h = null;
- return HttpUtils.getModifiableStringHeaders(m);
- }
-
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxrs/client/spring/JAXRSClientFactoryBeanDefinitionParser.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxrs/client/spring/JAXRSClientFactoryBeanDefinitionParser.java
deleted file mode 100644
index 6543ddc..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxrs/client/spring/JAXRSClientFactoryBeanDefinitionParser.java
+++ /dev/null
@@ -1,187 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.cxf.jaxrs.client.spring;
-
-import java.io.IOException;
-import java.lang.annotation.Annotation;
-import java.util.Collection;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-
-import javax.ws.rs.Path;
-import javax.ws.rs.ext.Provider;
-import javax.xml.namespace.QName;
-
-import org.w3c.dom.Element;
-
-import org.apache.cxf.bus.spring.BusWiringBeanFactoryPostProcessor;
-import org.apache.cxf.common.util.ClasspathScanner;
-import org.apache.cxf.configuration.spring.AbstractFactoryBeanDefinitionParser;
-import org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean;
-import org.apache.cxf.jaxrs.model.UserResource;
-import org.apache.cxf.jaxrs.utils.ResourceUtils;
-import org.springframework.beans.BeansException;
-import org.springframework.beans.factory.BeanCreationException;
-import org.springframework.beans.factory.BeanDefinitionStoreException;
-import org.springframework.beans.factory.NoUniqueBeanDefinitionException;
-import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
-import org.springframework.beans.factory.support.BeanDefinitionBuilder;
-import org.springframework.beans.factory.xml.ParserContext;
-import org.springframework.context.ApplicationContext;
-import org.springframework.context.ApplicationContextAware;
-
-
-
-
-
-public class JAXRSClientFactoryBeanDefinitionParser extends AbstractFactoryBeanDefinitionParser {
-
- public JAXRSClientFactoryBeanDefinitionParser() {
- super();
- setBeanClass(Object.class);
- }
-
- @Override
- protected Class<?> getFactoryClass() {
- return JAXRSSpringClientFactoryBean.class;
- }
-
- @Override
- protected String getFactoryIdSuffix() {
- return ".proxyFactory";
- }
-
- @Override
- protected String getSuffix() {
- return ".jaxrs-client";
- }
-
- @Override
- protected void mapAttribute(BeanDefinitionBuilder bean, Element e, String name, String val) {
- if ("serviceName".equals(name)) {
- QName q = parseQName(e, val);
- bean.addPropertyValue(name, q);
- } else if ("basePackages".equals(name)) {
- bean.addPropertyValue("basePackages", ClasspathScanner.parsePackages(val));
- } else {
- mapToProperty(bean, name, val);
- }
- }
-
- @Override
- protected void mapElement(ParserContext ctx, BeanDefinitionBuilder bean, Element el, String name) {
- if ("properties".equals(name) || "headers".equals(name)) {
- Map<?, ?> map = ctx.getDelegate().parseMapElement(el, bean.getBeanDefinition());
- bean.addPropertyValue(name, map);
- } else if ("executor".equals(name)) {
- setFirstChildAsProperty(el, ctx, bean, "serviceFactory.executor");
- } else if ("binding".equals(name)) {
- setFirstChildAsProperty(el, ctx, bean, "bindingConfig");
- } else if ("inInterceptors".equals(name) || "inFaultInterceptors".equals(name)
- || "outInterceptors".equals(name) || "outFaultInterceptors".equals(name)) {
- List<?> list = ctx.getDelegate().parseListElement(el, bean.getBeanDefinition());
- bean.addPropertyValue(name, list);
- } else if ("features".equals(name) || "providers".equals(name)
- || "schemaLocations".equals(name) || "modelBeans".equals(name)) {
- List<?> list = ctx.getDelegate().parseListElement(el, bean.getBeanDefinition());
- bean.addPropertyValue(name, list);
- } else if ("model".equals(name)) {
- List<UserResource> resources = ResourceUtils.getResourcesFromElement(el);
- bean.addPropertyValue("modelBeans", resources);
- } else {
- setFirstChildAsProperty(el, ctx, bean, name);
- }
- }
-
- public static class JAXRSSpringClientFactoryBean extends JAXRSClientFactoryBean
- implements ApplicationContextAware {
-
- private List<String> basePackages;
-
- public JAXRSSpringClientFactoryBean() {
- super();
- }
-
- public void setBasePackages(List<String> basePackages) {
- this.basePackages = basePackages;
- }
-
- public void setApplicationContext(ApplicationContext ctx) throws BeansException {
- try {
- if (basePackages != null) {
- final Map< Class< ? extends Annotation >, Collection< Class< ? > > > classes =
- ClasspathScanner.findClasses(basePackages, Path.class, Provider.class);
-
- if (classes.get(Path.class).size() > 1) {
- throw new NoUniqueBeanDefinitionException(Path.class, classes.get(Path.class).size(),
- "More than one service class (@Path) has been discovered");
- }
- AutowireCapableBeanFactory beanFactory = ctx.getAutowireCapableBeanFactory();
- for (final Class< ? > providerClass: classes.get(Provider.class)) {
- Object bean;
- try {
- bean = beanFactory.createBean(providerClass,
- AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, true);
- } catch (Exception ex) {
- bean = beanFactory.createBean(providerClass);
- }
- setProvider(bean);
- }
-
- for (final Class< ? > serviceClass: classes.get(Path.class)) {
- setServiceClass(serviceClass);
- }
- }
- } catch (IOException ex) {
- throw new BeanDefinitionStoreException("I/O failure during classpath scanning", ex);
- } catch (ClassNotFoundException ex) {
- throw new BeanCreationException("Failed to create bean from classfile", ex);
- }
-
- if (bus == null) {
- setBus(BusWiringBeanFactoryPostProcessor.addDefaultBus(ctx));
- }
- }
- }
-
- static Class<?> getServiceClass(Collection<Class<?>> rootClasses) {
- for (Class<?> cls : rootClasses) {
- if (cls.isInterface()) {
- return cls;
- }
- }
- return rootClasses.iterator().next();
- }
- static List<Object> getProviders(ApplicationContext context, Collection<Class<?>> providerClasses) {
- List<Object> providers = new LinkedList<>();
- AutowireCapableBeanFactory beanFactory = context.getAutowireCapableBeanFactory();
- for (final Class< ? > providerClass: providerClasses) {
- Object bean;
- try {
- bean = beanFactory.createBean(providerClass,
- AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, true);
- } catch (Exception ex) {
- bean = beanFactory.createBean(providerClass);
- }
- providers.add(bean);
- }
- return providers;
- }
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxrs/impl/EntityTagHeaderProvider.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxrs/impl/EntityTagHeaderProvider.java
deleted file mode 100644
index 0deb1c3..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxrs/impl/EntityTagHeaderProvider.java
+++ /dev/null
@@ -1,77 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.cxf.jaxrs.impl;
-
-import javax.ws.rs.core.EntityTag;
-import javax.ws.rs.ext.RuntimeDelegate.HeaderDelegate;
-
-public class EntityTagHeaderProvider implements HeaderDelegate<EntityTag> {
-
- private static final String WEAK_PREFIX = "W/";
-
- public EntityTag fromString(String header) {
-
-
- if (header == null) {
- throw new IllegalArgumentException("ETag value can not be null");
- }
-
- if ("*".equals(header)) {
- return new EntityTag("*");
- }
-
- String tag;
- boolean weak = false;
- int i = header.indexOf(WEAK_PREFIX);
- if (i != -1) {
- weak = true;
- if (i + 2 < header.length()) {
- tag = header.substring(i + 2);
- } else {
- return new EntityTag("", weak);
- }
- } else {
- tag = header;
- }
- if (tag.length() > 0 && !tag.startsWith("\"") && !tag.endsWith("\"")) {
- return new EntityTag(tag, weak);
- }
- if (tag.length() < 2 || !tag.startsWith("\"") || !tag.endsWith("\"")) {
- throw new IllegalArgumentException("Misformatted ETag : " + header);
- }
- tag = tag.length() == 2 ? "" : tag.substring(1, tag.length() - 1);
- return new EntityTag(tag, weak);
- }
-
- public String toString(EntityTag tag) {
- StringBuilder sb = new StringBuilder();
- if (tag.isWeak()) {
- sb.append(WEAK_PREFIX);
- }
- String tagValue = tag.getValue();
- if (!tagValue.startsWith("\"")) {
- sb.append('"').append(tagValue).append('"');
- } else {
- sb.append(tagValue);
- }
- return sb.toString();
- }
-
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxrs/impl/MediaTypeHeaderProvider.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxrs/impl/MediaTypeHeaderProvider.java
deleted file mode 100644
index a885a33..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxrs/impl/MediaTypeHeaderProvider.java
+++ /dev/null
@@ -1,221 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.cxf.jaxrs.impl;
-
-import java.util.Collections;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.StringTokenizer;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.logging.Logger;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.ext.RuntimeDelegate.HeaderDelegate;
-
-import org.apache.cxf.common.logging.LogUtils;
-import org.apache.cxf.common.util.StringUtils;
-import org.apache.cxf.common.util.SystemPropertyAction;
-import org.apache.cxf.message.Message;
-import org.apache.cxf.message.MessageUtils;
-import org.apache.cxf.phase.PhaseInterceptorChain;
-
-public class MediaTypeHeaderProvider implements HeaderDelegate<MediaType> {
- private static final Logger LOG = LogUtils.getL7dLogger(MediaTypeHeaderProvider.class);
- private static final String STRICT_MEDIA_TYPE_CHECK =
- "org.apache.cxf.jaxrs.mediaTypeCheck.strict";
- private static final Pattern COMPLEX_PARAMETERS =
- Pattern.compile("(([\\w-]+=\"[^\"]*\")|([\\w-]+=[\\w-/\\+]+))");
-
- private static Map<String, MediaType> map = new ConcurrentHashMap<>();
- private static final int MAX_MT_CACHE_SIZE =
- SystemPropertyAction.getInteger("org.apache.cxf.jaxrs.max_mediatype_cache_size", 200);
-
- public MediaType fromString(String mType) {
-
- return valueOf(mType);
- }
-
- public static MediaType valueOf(String mType) {
- if (mType == null) {
- throw new IllegalArgumentException("Media type value can not be null");
- }
-
- MediaType result = map.get(mType);
- if (result == null) {
- result = internalValueOf(mType);
- final int size = map.size();
- if (size >= MAX_MT_CACHE_SIZE) {
- map.clear();
- }
- map.put(mType, result);
- }
- return result;
- }
-
- public static MediaType internalValueOf(String mType) {
-
- int i = mType.indexOf('/');
- if (i == -1) {
- return handleMediaTypeWithoutSubtype(mType.trim());
- } else if (i == 0) {
- throw new IllegalArgumentException("Invalid media type string: " + mType);
- }
-
- int paramsStart = mType.indexOf(';', i + 1);
- int end = paramsStart == -1 ? mType.length() : paramsStart;
-
- String type = mType.substring(0, i).trim();
- String subtype = mType.substring(i + 1, end).trim();
- if (!isValid(type) || !isValid(subtype)) {
- throw new IllegalArgumentException("Invalid media type string: " + mType);
- }
-
- Map<String, String> parameters = Collections.emptyMap();
- if (paramsStart != -1) {
-
- parameters = new LinkedHashMap<>();
-
- String paramString = mType.substring(paramsStart + 1);
- if (paramString.contains("\"")) {
- Matcher m = COMPLEX_PARAMETERS.matcher(paramString);
- while (m.find()) {
- String val = m.group().trim();
- addParameter(parameters, val);
- }
- } else {
- StringTokenizer st = new StringTokenizer(paramString, ";");
- while (st.hasMoreTokens()) {
- addParameter(parameters, st.nextToken());
- }
- }
- }
-
- return new MediaType(type.toLowerCase(),
- subtype.toLowerCase(),
- parameters);
- }
-
- private static void addParameter(Map<String, String> parameters, String token) {
- int equalSign = token.indexOf('=');
- if (equalSign == -1) {
- throw new IllegalArgumentException("Wrong media type parameter, separator is missing");
- }
- parameters.put(token.substring(0, equalSign).trim().toLowerCase(),
- token.substring(equalSign + 1).trim());
- }
-
- public String toString(MediaType type) {
- return typeToString(type);
- }
- public static String typeToString(MediaType type) {
- return typeToString(type, null);
- }
- // Max number of parameters that may be ignored is 3, at least as known
- // to the implementation
- public static String typeToString(MediaType type, List<String> ignoreParams) {
- if (type == null) {
- throw new IllegalArgumentException("MediaType parameter is null");
- }
- StringBuilder sb = new StringBuilder();
- sb.append(type.getType()).append('/').append(type.getSubtype());
-
- Map<String, String> params = type.getParameters();
- if (params != null) {
- for (Map.Entry<String, String> entry : params.entrySet()) {
- if (ignoreParams != null && ignoreParams.contains(entry.getKey())) {
- continue;
- }
- sb.append(';').append(entry.getKey()).append('=').append(entry.getValue());
- }
- }
-
- return sb.toString();
- }
-
- private static MediaType handleMediaTypeWithoutSubtype(String mType) {
- if (mType.startsWith(MediaType.MEDIA_TYPE_WILDCARD)) {
- String mTypeNext = mType.length() == 1 ? "" : mType.substring(1).trim();
- boolean mTypeNextEmpty = StringUtils.isEmpty(mTypeNext);
- if (mTypeNextEmpty || mTypeNext.startsWith(";")) {
- if (!mTypeNextEmpty) {
- Map<String, String> parameters = new LinkedHashMap<>();
- StringTokenizer st = new StringTokenizer(mType.substring(2).trim(), ";");
- while (st.hasMoreTokens()) {
- addParameter(parameters, st.nextToken());
- }
- return new MediaType(MediaType.MEDIA_TYPE_WILDCARD,
- MediaType.MEDIA_TYPE_WILDCARD,
- parameters);
- }
- return MediaType.WILDCARD_TYPE;
-
- }
- }
- Message message = PhaseInterceptorChain.getCurrentMessage();
- if (message != null
- && !MessageUtils.getContextualBoolean(message, STRICT_MEDIA_TYPE_CHECK, false)) {
- final MediaType mt;
- if (mType.equals(MediaType.TEXT_PLAIN_TYPE.getType())) {
- mt = MediaType.TEXT_PLAIN_TYPE;
- } else if (mType.equals(MediaType.APPLICATION_XML_TYPE.getSubtype())) {
- mt = MediaType.APPLICATION_XML_TYPE;
- } else {
- mt = MediaType.WILDCARD_TYPE;
- }
- LOG.fine("Converting a malformed media type '" + mType + "' to '" + typeToString(mt) + "'");
- return mt;
- }
- throw new IllegalArgumentException("Media type separator is missing");
- }
-
- // Determines whether the type or subtype contains any of the tspecials characters defined at:
- // https://tools.ietf.org/html/rfc2045#section-5.1
- private static boolean isValid(String str) {
- final int len = str.length();
- if (len == 0) {
- return false;
- }
- for (int i = 0; i < len; i++) {
- switch (str.charAt(i)) {
- case '/':
- case '\\':
- case '?':
- case ':':
- case '<':
- case '>':
- case ';':
- case '(':
- case ')':
- case '@':
- case ',':
- case '[':
- case ']':
- case '=':
- return false;
- default:
- continue;
- }
- }
- return true;
- }
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxrs/impl/RequestImpl.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxrs/impl/RequestImpl.java
deleted file mode 100644
index 5921f1a..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxrs/impl/RequestImpl.java
+++ /dev/null
@@ -1,388 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.cxf.jaxrs.impl;
-
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.Date;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Locale;
-
-import javax.ws.rs.HttpMethod;
-import javax.ws.rs.core.EntityTag;
-import javax.ws.rs.core.HttpHeaders;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Request;
-import javax.ws.rs.core.Response;
-import javax.ws.rs.core.Response.ResponseBuilder;
-import javax.ws.rs.core.Variant;
-
-import org.apache.cxf.common.util.StringUtils;
-import org.apache.cxf.jaxrs.utils.HttpUtils;
-import org.apache.cxf.jaxrs.utils.JAXRSUtils;
-import org.apache.cxf.message.Message;
-import org.apache.cxf.phase.PhaseInterceptorChain;
-
-/**
- * TODO : deal with InvalidStateExceptions
- *
- */
-
-
-public class RequestImpl implements Request {
- private final Message m;
- private final HttpHeaders headers;
-
- public RequestImpl(Message m) {
- this.m = m;
- this.headers = new HttpHeadersImpl(m);
- }
-
-
-
- public Variant selectVariant(List<Variant> vars) throws IllegalArgumentException {
- if (vars == null || vars.isEmpty()) {
- throw new IllegalArgumentException("List of Variants is either null or empty");
- }
- List<MediaType> acceptMediaTypes = headers.getAcceptableMediaTypes();
- List<Locale> acceptLangs = headers.getAcceptableLanguages();
- List<String> acceptEncs = parseAcceptEnc(
- headers.getRequestHeaders().getFirst(HttpHeaders.ACCEPT_ENCODING));
- List<Variant> requestVariants = sortAllCombinations(acceptMediaTypes, acceptLangs, acceptEncs);
- List<Object> varyValues = new LinkedList<>();
- for (Variant requestVar : requestVariants) {
- for (Variant var : vars) {
- MediaType mt = var.getMediaType();
- Locale lang = var.getLanguage();
- String enc = var.getEncoding();
-
- boolean mtMatched = mt == null || requestVar.getMediaType().isCompatible(mt);
- if (mtMatched) {
- handleVaryValues(varyValues, HttpHeaders.ACCEPT);
- }
-
- boolean langMatched = lang == null || isLanguageMatched(requestVar.getLanguage(), lang);
- if (langMatched) {
- handleVaryValues(varyValues, HttpHeaders.ACCEPT_LANGUAGE);
- }
-
- boolean encMatched = acceptEncs.isEmpty() || enc == null
- || isEncMatached(requestVar.getEncoding(), enc);
- if (encMatched) {
- handleVaryValues(varyValues, HttpHeaders.ACCEPT_ENCODING);
- }
-
- if (mtMatched && encMatched && langMatched) {
- addVaryHeader(varyValues);
- return var;
- }
- }
- }
- return null;
- }
-
- private static List<Variant> sortAllCombinations(List<MediaType> mediaTypes,
- List<Locale> langs,
- List<String> encs) {
- List<Variant> requestVars = new LinkedList<>();
- for (MediaType mt : mediaTypes) {
- for (Locale lang : langs) {
- if (encs.isEmpty()) {
- requestVars.add(new Variant(mt, lang, null));
- } else {
- for (String enc : encs) {
- requestVars.add(new Variant(mt, lang, enc));
- }
- }
- }
- }
- Collections.sort(requestVars, VariantComparator.INSTANCE);
- return requestVars;
- }
-
-
- private static void handleVaryValues(List<Object> varyValues, String ...values) {
- for (String v : values) {
- if (v != null && !varyValues.contains(v)) {
- varyValues.add(v);
- }
- }
- }
-
- private static void addVaryHeader(List<Object> varyValues) {
- // at this point we still have no out-bound message so lets
- // use HttpServletResponse. If needed we can save the header on the exchange
- // and then copy it into the out-bound message's headers
- Message message = PhaseInterceptorChain.getCurrentMessage();
- if (message != null) {
- Object httpResponse = message.get("HTTP.RESPONSE");
- if (httpResponse != null) {
- StringBuilder sb = new StringBuilder();
- for (int i = 0; i < varyValues.size(); i++) {
- if (i > 0) {
- sb.append(',');
- }
- sb.append(varyValues.get(i).toString());
- }
- ((javax.servlet.http.HttpServletResponse)httpResponse)
- .setHeader(HttpHeaders.VARY, sb.toString());
- }
- }
- }
-
- private static boolean isLanguageMatched(Locale locale, Locale l) {
-
- String language = locale.getLanguage();
- return "*".equals(language)
- || language.equalsIgnoreCase(l.getLanguage());
- }
-
- private static boolean isEncMatached(String accepts, String enc) {
- return accepts == null || "*".equals(accepts) || accepts.contains(enc);
- }
-
- private static List<String> parseAcceptEnc(String acceptEnc) {
- if (StringUtils.isEmpty(acceptEnc)) {
- return Collections.emptyList();
- }
- List<String> list = new LinkedList<>();
- String[] values = acceptEnc.split(",");
- for (String value : values) {
- String[] pair = value.trim().split(";");
- // ignore encoding qualifiers if any for now
- list.add(pair[0]);
- }
- return list;
- }
-
- public ResponseBuilder evaluatePreconditions(EntityTag eTag) {
- if (eTag == null) {
- throw new IllegalArgumentException("ETag is null");
- }
- return evaluateAll(eTag, null);
- }
-
- private ResponseBuilder evaluateAll(EntityTag eTag, Date lastModified) {
- // http://tools.ietf.org/search/draft-ietf-httpbis-p4-conditional-25#section-5
- // Check If-Match. If it is not available proceed to checking If-Not-Modified-Since
- // if it is available and the preconditions are not met - return, otherwise:
- // Check If-Not-Match. If it is not available proceed to checking If-Modified-Since
- // otherwise return the evaluation result
-
- ResponseBuilder rb = evaluateIfMatch(eTag, lastModified);
- if (rb == null) {
- rb = evaluateIfNonMatch(eTag, lastModified);
- }
- return rb;
- }
-
- private ResponseBuilder evaluateIfMatch(EntityTag eTag, Date date) {
- List<String> ifMatch = headers.getRequestHeader(HttpHeaders.IF_MATCH);
-
- if (ifMatch == null || ifMatch.isEmpty()) {
- return date == null ? null : evaluateIfNotModifiedSince(date);
- }
-
- try {
- for (String value : ifMatch) {
- if ("*".equals(value)) {
- return null;
- }
- EntityTag requestTag = EntityTag.valueOf(value);
- // must be a strong comparison
- if (!requestTag.isWeak() && !eTag.isWeak() && requestTag.equals(eTag)) {
- return null;
- }
- }
- } catch (IllegalArgumentException ex) {
- // ignore
- }
- return Response.status(Response.Status.PRECONDITION_FAILED).tag(eTag);
- }
-
- private ResponseBuilder evaluateIfNonMatch(EntityTag eTag, Date lastModified) {
- List<String> ifNonMatch = headers.getRequestHeader(HttpHeaders.IF_NONE_MATCH);
-
- if (ifNonMatch == null || ifNonMatch.isEmpty()) {
- return lastModified == null ? null : evaluateIfModifiedSince(lastModified);
- }
-
- String method = getMethod();
- boolean getOrHead = HttpMethod.GET.equals(method) || HttpMethod.HEAD.equals(method);
- try {
- for (String value : ifNonMatch) {
- boolean result = "*".equals(value);
- if (!result) {
- EntityTag requestTag = EntityTag.valueOf(value);
- result = getOrHead ? requestTag.equals(eTag)
- : !requestTag.isWeak() && !eTag.isWeak() && requestTag.equals(eTag);
- }
- if (result) {
- Response.Status status = getOrHead ? Response.Status.NOT_MODIFIED
- : Response.Status.PRECONDITION_FAILED;
- return Response.status(status).tag(eTag);
- }
- }
- } catch (IllegalArgumentException ex) {
- // ignore
- }
- return null;
- }
-
- public ResponseBuilder evaluatePreconditions(Date lastModified) {
- if (lastModified == null) {
- throw new IllegalArgumentException("Date is null");
- }
- ResponseBuilder rb = evaluateIfNotModifiedSince(lastModified);
- if (rb == null) {
- rb = evaluateIfModifiedSince(lastModified);
- }
- return rb;
- }
-
- private ResponseBuilder evaluateIfModifiedSince(Date lastModified) {
- List<String> ifModifiedSince = headers.getRequestHeader(HttpHeaders.IF_MODIFIED_SINCE);
-
- if (ifModifiedSince == null || ifModifiedSince.isEmpty()) {
- return null;
- }
-
- SimpleDateFormat dateFormat = HttpUtils.getHttpDateFormat();
-
- dateFormat.setLenient(false);
- final Date dateSince;
- try {
- dateSince = dateFormat.parse(ifModifiedSince.get(0));
- } catch (ParseException ex) {
- // invalid header value, request should continue
- return Response.status(Response.Status.PRECONDITION_FAILED);
- }
-
- if (dateSince.before(lastModified)) {
- // request should continue
- return null;
- }
-
- return Response.status(Response.Status.NOT_MODIFIED);
- }
-
- private ResponseBuilder evaluateIfNotModifiedSince(Date lastModified) {
- List<String> ifNotModifiedSince = headers.getRequestHeader(HttpHeaders.IF_UNMODIFIED_SINCE);
-
- if (ifNotModifiedSince == null || ifNotModifiedSince.isEmpty()) {
- return null;
- }
-
- SimpleDateFormat dateFormat = HttpUtils.getHttpDateFormat();
-
- dateFormat.setLenient(false);
- final Date dateSince;
- try {
- dateSince = dateFormat.parse(ifNotModifiedSince.get(0));
- } catch (ParseException ex) {
- // invalid header value, request should continue
- return Response.status(Response.Status.PRECONDITION_FAILED);
- }
-
- if (dateSince.before(lastModified)) {
- return Response.status(Response.Status.PRECONDITION_FAILED);
- }
-
- return null;
- }
-
-
-
- public ResponseBuilder evaluatePreconditions(Date lastModified, EntityTag eTag) {
- if (eTag == null || lastModified == null) {
- throw new IllegalArgumentException("ETag or Date is null");
- }
- return evaluateAll(eTag, lastModified);
- }
-
- public String getMethod() {
- return m.get(Message.HTTP_REQUEST_METHOD).toString();
- }
-
-
-
- public ResponseBuilder evaluatePreconditions() {
- List<String> ifMatch = headers.getRequestHeader(HttpHeaders.IF_MATCH);
- if (ifMatch != null) {
- for (String value : ifMatch) {
- if (!"*".equals(value)) {
- return Response.status(Response.Status.PRECONDITION_FAILED).tag(EntityTag.valueOf(value));
- }
- }
- }
- return null;
- }
-
- private static class VariantComparator implements Comparator<Variant> {
-
- static final VariantComparator INSTANCE = new VariantComparator();
-
- public int compare(Variant v1, Variant v2) {
- int result = compareMediaTypes(v1.getMediaType(), v2.getMediaType());
-
- if (result != 0) {
- return result;
- }
-
- result = compareLanguages(v1.getLanguage(), v2.getLanguage());
-
- if (result == 0) {
- result = compareEncodings(v1.getEncoding(), v2.getEncoding());
- }
-
- return result;
- }
-
- private static int compareMediaTypes(MediaType mt1, MediaType mt2) {
- if (mt1 != null && mt2 == null) {
- return -1;
- } else if (mt1 == null && mt2 != null) {
- return 1;
- }
- return JAXRSUtils.compareMediaTypes(mt1, mt2);
- }
-
- private static int compareLanguages(Locale l1, Locale l2) {
- if (l1 != null && l2 == null) {
- return -1;
- } else if (l1 == null && l2 != null) {
- return 1;
- }
- return 0;
- }
-
- private static int compareEncodings(String enc1, String enc2) {
- if (enc1 != null && enc2 == null) {
- return -1;
- } else if (enc1 == null && enc2 != null) {
- return 1;
- }
- return 0;
- }
- }
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxrs/impl/ResourceContextImpl.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxrs/impl/ResourceContextImpl.java
deleted file mode 100644
index ca1e629..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxrs/impl/ResourceContextImpl.java
+++ /dev/null
@@ -1,67 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.cxf.jaxrs.impl;
-
-import javax.ws.rs.container.ResourceContext;
-
-import org.apache.cxf.jaxrs.ext.ResourceContextProvider;
-import org.apache.cxf.jaxrs.lifecycle.PerRequestResourceProvider;
-import org.apache.cxf.jaxrs.lifecycle.ResourceProvider;
-import org.apache.cxf.jaxrs.model.ClassResourceInfo;
-import org.apache.cxf.jaxrs.model.OperationResourceInfo;
-import org.apache.cxf.jaxrs.provider.ServerProviderFactory;
-import org.apache.cxf.message.Message;
-
-public class ResourceContextImpl implements ResourceContext {
- private static final String CONTEXT_PROVIDER_PROP = "org.apache.cxf.jaxrs.resource.context.provider";
- private final ClassResourceInfo cri;
- private final Class<?> subClass;
- private final Message m;
- public ResourceContextImpl(Message m, OperationResourceInfo ori) {
- this.m = m;
- this.cri = ori.getClassResourceInfo();
- this.subClass = ori.getMethodToInvoke().getReturnType();
- }
-
- @Override
- public <T> T getResource(Class<T> cls) {
- final ResourceProvider rp;
-
- Object propValue = m.getContextualProperty(CONTEXT_PROVIDER_PROP);
- if (propValue instanceof ResourceContextProvider) {
- rp = ((ResourceContextProvider)propValue).getResourceProvider(cls);
- } else {
- rp = new PerRequestResourceProvider(cls);
- }
- T resource = cls.cast(rp.getInstance(m));
- return doInitResource(cls, resource);
- }
-
- @Override
- public <T> T initResource(T resource) {
- return doInitResource(resource.getClass(), resource);
- }
-
- private <T> T doInitResource(Class<?> cls, T resource) {
- ClassResourceInfo sub = cri.getSubResource(subClass, cls, resource, true, m);
- sub.initBeanParamInfo(ServerProviderFactory.getInstance(m));
- sub.injectContexts(resource, m.getExchange().get(OperationResourceInfo.class), m);
- return resource;
- }
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxrs/impl/ResponseImpl.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxrs/impl/ResponseImpl.java
deleted file mode 100644
index e240f50..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxrs/impl/ResponseImpl.java
+++ /dev/null
@@ -1,629 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.cxf.jaxrs.impl;
-
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.PushbackInputStream;
-import java.io.Reader;
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Type;
-import java.net.URI;
-import java.nio.charset.StandardCharsets;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.LinkedHashSet;
-import java.util.List;
-import java.util.Locale;
-import java.util.Map;
-import java.util.Set;
-import java.util.regex.Pattern;
-
-import javax.ws.rs.ProcessingException;
-import javax.ws.rs.client.ResponseProcessingException;
-import javax.ws.rs.core.EntityTag;
-import javax.ws.rs.core.GenericType;
-import javax.ws.rs.core.HttpHeaders;
-import javax.ws.rs.core.Link;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.MultivaluedMap;
-import javax.ws.rs.core.NewCookie;
-import javax.ws.rs.core.NoContentException;
-import javax.ws.rs.core.Response;
-import javax.ws.rs.core.Response.Status.Family;
-import javax.ws.rs.ext.ReaderInterceptor;
-import javax.ws.rs.ext.RuntimeDelegate.HeaderDelegate;
-import javax.xml.stream.XMLStreamReader;
-import javax.xml.transform.Source;
-
-import org.apache.cxf.helpers.IOUtils;
-import org.apache.cxf.io.ReaderInputStream;
-import org.apache.cxf.jaxrs.provider.ProviderFactory;
-import org.apache.cxf.jaxrs.utils.HttpUtils;
-import org.apache.cxf.jaxrs.utils.InjectionUtils;
-import org.apache.cxf.jaxrs.utils.JAXRSUtils;
-import org.apache.cxf.message.Message;
-import org.apache.cxf.message.MessageUtils;
-
-public final class ResponseImpl extends Response {
-
- private static final Pattern LINK_DELIMITER = Pattern.compile(",\\s*(?=\\<|$)");
-
- private StatusType status;
- private Object entity;
- private Annotation[] entityAnnotations;
- private MultivaluedMap<String, Object> metadata;
-
- private Message outMessage;
- private boolean entityClosed;
- private boolean entityBufferred;
- private Object lastEntity;
-
- ResponseImpl(int statusCode) {
- this.status = createStatusType(statusCode, null);
- }
-
- ResponseImpl(int statusCode, Object entity) {
- this(statusCode);
- this.entity = entity;
- }
-
- ResponseImpl(int statusCode, Object entity, String reasonPhrase) {
- this.status = createStatusType(statusCode, reasonPhrase);
- this.entity = entity;
- }
-
- public void addMetadata(MultivaluedMap<String, Object> meta) {
- this.metadata = meta;
- }
-
- public void setStatus(int statusCode) {
- this.status = createStatusType(statusCode, null);
- }
-
- public void setStatus(int statusCode, String reasonPhrase) {
- this.status = createStatusType(statusCode, reasonPhrase);
- }
-
- public void setEntity(Object e, Annotation[] anns) {
- this.entity = e;
- this.entityAnnotations = anns;
- }
-
- public void setEntityAnnotations(Annotation[] anns) {
- this.entityAnnotations = anns;
- }
-
- public Annotation[] getEntityAnnotations() {
- return entityAnnotations;
- }
-
- public void setOutMessage(Message message) {
- this.outMessage = message;
- }
-
- public Message getOutMessage() {
- return this.outMessage;
- }
-
- @Override
- public int getStatus() {
- return status.getStatusCode();
- }
-
- @Override
- public StatusType getStatusInfo() {
- return status;
- }
-
- public Object getActualEntity() {
- checkEntityIsClosed();
- return lastEntity != null ? lastEntity : entity;
- }
-
- @Override
- public Object getEntity() {
- return InjectionUtils.getEntity(getActualEntity());
- }
-
- @Override
- public boolean hasEntity() {
- // per spec, need to check if the stream exists and if it has data.
- Object actualEntity = getActualEntity();
- if (actualEntity == null) {
- return false;
- } else if (actualEntity instanceof InputStream) {
- final InputStream is = (InputStream) actualEntity;
- try {
- if (is.markSupported()) {
- is.mark(1);
- int i = is.read();
- is.reset();
- return i != -1;
- } else {
- try {
- if (is.available() > 0) {
- return true;
- }
- } catch (IOException ioe) {
- //Do nothing
- }
- int b = is.read();
- if (b == -1) {
- return false;
- }
- PushbackInputStream pbis;
- if (is instanceof PushbackInputStream) {
- pbis = (PushbackInputStream) is;
- } else {
- pbis = new PushbackInputStream(is, 1);
- if (lastEntity != null) {
- lastEntity = pbis;
- } else {
- entity = pbis;
- }
- }
- pbis.unread(b);
- return true;
- }
- } catch (IOException ex) {
- throw new ProcessingException(ex);
- }
- }
- return true;
- }
-
- @Override
- public MultivaluedMap<String, Object> getMetadata() {
- return getHeaders();
- }
-
- @Override
- public MultivaluedMap<String, Object> getHeaders() {
- return metadata;
- }
-
- @Override
- public MultivaluedMap<String, String> getStringHeaders() {
- MetadataMap<String, String> headers = new MetadataMap<>(metadata.size());
- for (Map.Entry<String, List<Object>> entry : metadata.entrySet()) {
- String headerName = entry.getKey();
- headers.put(headerName, toListOfStrings(entry.getValue()));
- }
- return headers;
- }
-
- @Override
- public String getHeaderString(String header) {
- List<Object> methodValues = metadata.get(header);
- return HttpUtils.getHeaderString(toListOfStrings(methodValues));
- }
-
- // This conversion is needed as some values may not be Strings
- private List<String> toListOfStrings(List<Object> values) {
- if (values == null) {
- return null;
- }
- List<String> stringValues = new ArrayList<>(values.size());
- HeaderDelegate<Object> hd = HttpUtils.getHeaderDelegate(values.get(0));
- for (Object value : values) {
- String actualValue = hd == null ? value.toString() : hd.toString(value);
- stringValues.add(actualValue);
- }
- return stringValues;
- }
-
- @Override
- public Set<String> getAllowedMethods() {
- List<Object> methodValues = metadata.get(HttpHeaders.ALLOW);
- if (methodValues == null) {
- return Collections.emptySet();
- }
- Set<String> methods = new HashSet<>();
- for (Object o : methodValues) {
- methods.add(o.toString());
- }
- return methods;
- }
-
- @Override
- public Map<String, NewCookie> getCookies() {
- List<Object> cookieValues = metadata.get(HttpHeaders.SET_COOKIE);
- if (cookieValues == null) {
- return Collections.emptyMap();
- }
- Map<String, NewCookie> cookies = new HashMap<>();
- for (Object o : cookieValues) {
- NewCookie newCookie = NewCookie.valueOf(o.toString());
- cookies.put(newCookie.getName(), newCookie);
- }
- return cookies;
- }
-
- @Override
- public Date getDate() {
- return doGetDate(HttpHeaders.DATE);
- }
-
- private Date doGetDate(String dateHeader) {
- Object value = metadata.getFirst(dateHeader);
- return value == null || value instanceof Date ? (Date)value
- : HttpUtils.getHttpDate(value.toString());
- }
-
- @Override
- public EntityTag getEntityTag() {
- Object header = metadata.getFirst(HttpHeaders.ETAG);
- return header == null || header instanceof EntityTag ? (EntityTag)header
- : EntityTag.valueOf(header.toString());
- }
-
- @Override
- public Locale getLanguage() {
- Object header = metadata.getFirst(HttpHeaders.CONTENT_LANGUAGE);
- return header == null || header instanceof Locale ? (Locale)header
- : HttpUtils.getLocale(header.toString());
- }
-
- @Override
- public Date getLastModified() {
- return doGetDate(HttpHeaders.LAST_MODIFIED);
- }
-
- @Override
- public int getLength() {
- Object header = metadata.getFirst(HttpHeaders.CONTENT_LENGTH);
- return HttpUtils.getContentLength(header == null ? null : header.toString());
- }
-
- @Override
- public URI getLocation() {
- Object header = metadata.getFirst(HttpHeaders.LOCATION);
- return header == null || header instanceof URI ? (URI)header
- : URI.create(header.toString());
- }
-
- @Override
- public MediaType getMediaType() {
- Object header = metadata.getFirst(HttpHeaders.CONTENT_TYPE);
- return header == null || header instanceof MediaType ? (MediaType)header
- : (MediaType)JAXRSUtils.toMediaType(header.toString());
- }
-
- @Override
- public boolean hasLink(String relation) {
- List<Object> linkValues = metadata.get(HttpHeaders.LINK);
- if (linkValues != null) {
- for (Object o : linkValues) {
- if (o instanceof Link && relation.equals(((Link)o).getRel())) {
- return true;
- }
-
- String[] links = LINK_DELIMITER.split(o.toString());
- for (String splitLink : links) {
- Link link = Link.valueOf(splitLink);
- if (relation.equals(link.getRel())) {
- return true;
- }
- }
- }
- }
- return false;
- }
-
- @Override
- public Link getLink(String relation) {
- Set<Link> links = getAllLinks();
- for (Link link : links) {
- if (link.getRel() != null && link.getRel().equals(relation)) {
- return link;
- }
- }
- return null;
- }
-
- @Override
- public Link.Builder getLinkBuilder(String relation) {
- Link link = getLink(relation);
- return link == null ? null : Link.fromLink(link);
- }
-
- @Override
- public Set<Link> getLinks() {
- return new HashSet<>(getAllLinks());
- }
-
- private Set<Link> getAllLinks() {
- List<Object> linkValues = metadata.get(HttpHeaders.LINK);
- if (linkValues == null) {
- return Collections.emptySet();
- }
- Set<Link> links = new LinkedHashSet<>();
- for (Object o : linkValues) {
- List<Link> parsedLinks = parseLink(o);
-
- links.addAll(parsedLinks);
- }
- return links;
- }
-
- private Link makeAbsoluteLink(Link link) {
- if (!link.getUri().isAbsolute()) {
- URI requestURI = URI.create((String)outMessage.get(Message.REQUEST_URI));
- link = Link.fromLink(link).baseUri(requestURI).build();
- }
-
- return link;
- }
-
- private List<Link> parseLink(Object o) {
- if (o instanceof Link) {
- return Collections.singletonList(makeAbsoluteLink((Link) o));
- }
-
- List<Link> links = new ArrayList<>();
- String[] linkArray = LINK_DELIMITER.split(o.toString());
-
- for (String textLink : linkArray) {
- Link link = Link.valueOf(textLink);
- links.add(makeAbsoluteLink(link));
- }
-
- return Collections.unmodifiableList(links);
- }
-
- @Override
- public <T> T readEntity(Class<T> cls) throws ProcessingException, IllegalStateException {
- return readEntity(cls, new Annotation[]{});
- }
-
- @Override
- public <T> T readEntity(GenericType<T> genType) throws ProcessingException, IllegalStateException {
- return readEntity(genType, new Annotation[]{});
- }
-
- @Override
- public <T> T readEntity(Class<T> cls, Annotation[] anns) throws ProcessingException, IllegalStateException {
- return doReadEntity(cls, cls, anns);
- }
-
- @Override
- @SuppressWarnings("unchecked")
- public <T> T readEntity(GenericType<T> genType, Annotation[] anns)
- throws ProcessingException, IllegalStateException {
- return doReadEntity((Class<T>) genType.getRawType(),
- genType.getType(), anns);
- }
-
- public <T> T doReadEntity(Class<T> cls, Type t, Annotation[] anns)
- throws ProcessingException, IllegalStateException {
-
- checkEntityIsClosed();
- //according to javadoc, should close when is not buffered.
- boolean shouldClose = !entityBufferred && !JAXRSUtils.isStreamingOutType(cls);
-
- if (lastEntity != null && cls.isAssignableFrom(lastEntity.getClass())
- && !(lastEntity instanceof InputStream)) {
- return cls.cast(lastEntity);
- }
-
- MediaType mediaType = getMediaType();
- if (mediaType == null) {
- mediaType = MediaType.WILDCARD_TYPE;
- }
-
- // the stream is available if entity is IS or
- // message contains XMLStreamReader or Reader
- boolean entityStreamAvailable = entityStreamAvailable();
- InputStream entityStream = null;
- if (!entityStreamAvailable) {
- // try create a stream if the entity is String or Number
- entityStream = convertEntityToStreamIfPossible();
- entityStreamAvailable = entityStream != null;
- } else if (entity instanceof InputStream) {
- entityStream = InputStream.class.cast(entity);
- } else {
- Message inMessage = getResponseMessage();
- Reader reader = inMessage.getContent(Reader.class);
- if (reader != null) {
- entityStream = InputStream.class.cast(new ReaderInputStream(reader));
- }
- }
-
- // we need to check for readers even if no IS is set - the readers may still do it
- List<ReaderInterceptor> readers = outMessage == null ? null : ProviderFactory.getInstance(outMessage)
- .createMessageBodyReaderInterceptor(cls, t, anns, mediaType, outMessage, entityStreamAvailable, null);
-
- if (readers != null) {
- try {
- if (entityBufferred) {
- InputStream.class.cast(entity).reset();
- }
-
- Message responseMessage = getResponseMessage();
- responseMessage.put(Message.PROTOCOL_HEADERS, getHeaders());
-
- lastEntity = JAXRSUtils.readFromMessageBodyReader(readers, cls, t,
- anns,
- entityStream,
- mediaType,
- responseMessage);
- // close the entity after readEntity is called.
- T tCastLastEntity = castLastEntity();
- shouldClose = shouldClose && !(tCastLastEntity instanceof AutoCloseable)
- && !(tCastLastEntity instanceof Source);
- if (shouldClose) {
- close();
- }
- return tCastLastEntity;
- } catch (NoContentException ex) {
- //when content is empty, return null instead of throw exception to pass TCK
- //check if basic type. Basic type throw exception, else return null.
- if (isBasicType(cls)) {
- autoClose(cls, true);
- reportMessageHandlerProblem("MSG_READER_PROBLEM", cls, mediaType, ex);
- } else {
- if (shouldClose) {
- close();
- }
- return null;
- }
- } catch (Exception ex) {
- autoClose(cls, true);
- reportMessageHandlerProblem("MSG_READER_PROBLEM", cls, mediaType, ex);
- } finally {
- ProviderFactory pf = ProviderFactory.getInstance(outMessage);
- if (pf != null) {
- pf.clearThreadLocalProxies();
- }
- }
- } else if (entity != null && cls.isAssignableFrom(entity.getClass())) {
- lastEntity = entity;
- return castLastEntity();
- } else if (entityStreamAvailable) {
- reportMessageHandlerProblem("NO_MSG_READER", cls, mediaType, null);
- }
-
- throw new IllegalStateException("The entity is not backed by an input stream, entity class is : "
- + (entity != null ? entity.getClass().getName() : cls.getName()));
-
- }
-
- @SuppressWarnings("unchecked")
- private <T> T castLastEntity() {
- return (T)lastEntity;
- }
-
- public InputStream convertEntityToStreamIfPossible() {
- String stringEntity = null;
- if (entity instanceof String || entity instanceof Number) {
- stringEntity = entity.toString();
- }
- if (stringEntity != null) {
- try {
- return new ByteArrayInputStream(stringEntity.getBytes(StandardCharsets.UTF_8));
- } catch (Exception ex) {
- throw new ProcessingException(ex);
- }
- }
- return null;
- }
-
- private boolean entityStreamAvailable() {
- if (entity == null) {
- Message inMessage = getResponseMessage();
- return inMessage != null && (inMessage.getContent(XMLStreamReader.class) != null
- || inMessage.getContent(Reader.class) != null);
- }
- return entity instanceof InputStream;
- }
-
- private Message getResponseMessage() {
- Message responseMessage = outMessage.getExchange().getInMessage();
- if (responseMessage == null) {
- responseMessage = outMessage.getExchange().getInFaultMessage();
- }
- return responseMessage;
- }
-
- private void reportMessageHandlerProblem(String name, Class<?> cls, MediaType ct, Throwable cause) {
- String errorMessage = JAXRSUtils.logMessageHandlerProblem(name, cls, ct);
- throw new ResponseProcessingException(this, errorMessage, cause);
- }
-
- protected void autoClose(Class<?> cls, boolean exception) {
- if (!entityBufferred && !JAXRSUtils.isStreamingOutType(cls)
- && (exception || MessageUtils.getContextualBoolean(outMessage, "response.stream.auto.close"))) {
- close();
- }
- }
-
- @Override
- public boolean bufferEntity() throws ProcessingException {
- checkEntityIsClosed();
- if (!entityBufferred && entity instanceof InputStream) {
- try {
- InputStream oldEntity = (InputStream)entity;
- entity = IOUtils.loadIntoBAIS(oldEntity);
- oldEntity.close();
- entityBufferred = true;
- } catch (IOException ex) {
- throw new ResponseProcessingException(this, ex);
- }
- }
- return entityBufferred;
- }
-
- @Override
- public void close() throws ProcessingException {
- if (!entityClosed) {
- if (!entityBufferred && entity instanceof InputStream) {
- try {
- ((InputStream)entity).close();
- } catch (IOException ex) {
- throw new ResponseProcessingException(this, ex);
- }
- }
- entity = null;
- entityClosed = true;
- }
-
- }
-
- private void checkEntityIsClosed() {
- if (entityClosed) {
- throw new IllegalStateException("Entity is not available");
- }
- }
-
- private Response.StatusType createStatusType(int statusCode, String reasonPhrase) {
- return new Response.StatusType() {
-
- @Override
- public Family getFamily() {
- return Response.Status.Family.familyOf(statusCode);
- }
-
- @Override
- public String getReasonPhrase() {
- if (reasonPhrase != null) {
- return reasonPhrase;
- }
- Response.Status statusEnum = Response.Status.fromStatusCode(statusCode);
- return statusEnum != null ? statusEnum.getReasonPhrase() : "";
- }
-
- @Override
- public int getStatusCode() {
- return statusCode;
- }
-
- };
- }
-
- private static boolean isBasicType(Class<?> type) {
- return type.isPrimitive() || Number.class.isAssignableFrom(type) || Boolean.class.isAssignableFrom(type)
- || Character.class.isAssignableFrom(type);
- }
-}
\ No newline at end of file
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxrs/impl/tl/ThreadLocalInvocationHandler.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxrs/impl/tl/ThreadLocalInvocationHandler.java
deleted file mode 100644
index bb27b5a..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxrs/impl/tl/ThreadLocalInvocationHandler.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.cxf.jaxrs.impl.tl;
-
-import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-
-
-public class ThreadLocalInvocationHandler<T> extends AbstractThreadLocalProxy<T>
- implements InvocationHandler {
-
- public Object invoke(Object proxy, Method m, Object[] args) throws Throwable {
- final Object target;
- if (m.getDeclaringClass() == ThreadLocalProxy.class) {
- target = this;
- } else {
- target = get();
- if (target == null) {
- if (m.getName().endsWith("toString")) {
- return null;
- }
- Class<?> contextCls = m.getDeclaringClass();
- throw new NullPointerException(
- contextCls.getName()
- + " context class has not been injected."
- + " Check if ContextProvider supporting this class is registered");
- }
- }
- try {
- return m.invoke(target, args);
- } catch (InvocationTargetException e) {
- throw e.getCause();
- }
- }
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxrs/interceptor/JAXRSInInterceptor.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxrs/interceptor/JAXRSInInterceptor.java
deleted file mode 100644
index 3c9c5d8..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxrs/interceptor/JAXRSInInterceptor.java
+++ /dev/null
@@ -1,274 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.cxf.jaxrs.interceptor;
-
-import java.io.IOException;
-import java.util.List;
-import java.util.Map;
-import java.util.ResourceBundle;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import javax.ws.rs.HttpMethod;
-import javax.ws.rs.NotFoundException;
-import javax.ws.rs.WebApplicationException;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.MultivaluedMap;
-import javax.ws.rs.core.Response;
-
-import org.apache.cxf.common.i18n.BundleUtils;
-import org.apache.cxf.common.logging.LogUtils;
-import org.apache.cxf.common.util.PropertyUtils;
-import org.apache.cxf.endpoint.Endpoint;
-import org.apache.cxf.helpers.CastUtils;
-import org.apache.cxf.interceptor.Fault;
-import org.apache.cxf.interceptor.OutgoingChainInterceptor;
-import org.apache.cxf.jaxrs.impl.MetadataMap;
-import org.apache.cxf.jaxrs.impl.RequestPreprocessor;
-import org.apache.cxf.jaxrs.impl.UriInfoImpl;
-import org.apache.cxf.jaxrs.lifecycle.ResourceProvider;
-import org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider;
-import org.apache.cxf.jaxrs.model.ClassResourceInfo;
-import org.apache.cxf.jaxrs.model.OperationResourceInfo;
-import org.apache.cxf.jaxrs.model.URITemplate;
-import org.apache.cxf.jaxrs.provider.ServerProviderFactory;
-import org.apache.cxf.jaxrs.utils.ExceptionUtils;
-import org.apache.cxf.jaxrs.utils.HttpUtils;
-import org.apache.cxf.jaxrs.utils.JAXRSUtils;
-import org.apache.cxf.message.Exchange;
-import org.apache.cxf.message.Message;
-import org.apache.cxf.message.MessageContentsList;
-import org.apache.cxf.phase.AbstractPhaseInterceptor;
-import org.apache.cxf.phase.Phase;
-
-public class JAXRSInInterceptor extends AbstractPhaseInterceptor<Message> {
-
- private static final Logger LOG = LogUtils.getL7dLogger(JAXRSInInterceptor.class);
- private static final ResourceBundle BUNDLE = BundleUtils.getBundle(JAXRSInInterceptor.class);
- private static final String RESOURCE_METHOD = "org.apache.cxf.resource.method";
- private static final String RESOURCE_OPERATION_NAME = "org.apache.cxf.resource.operation.name";
-
- public JAXRSInInterceptor() {
- super(Phase.UNMARSHAL);
- }
-
- public void handleMessage(Message message) {
- final Exchange exchange = message.getExchange();
-
- exchange.put(Message.REST_MESSAGE, Boolean.TRUE);
- Response response = exchange.get(Response.class);
- if (response == null) {
- try {
- processRequest(message, exchange);
- if (exchange.isOneWay()) {
- ServerProviderFactory.getInstance(message).clearThreadLocalProxies();
- }
- } catch (Fault ex) {
- convertExceptionToResponseIfPossible(ex.getCause(), message);
- } catch (RuntimeException ex) {
- convertExceptionToResponseIfPossible(ex, message);
- } catch (IOException ex) {
- convertExceptionToResponseIfPossible(ex, message);
- }
- }
-
- response = exchange.get(Response.class);
- if (response != null) {
- createOutMessage(message, response);
- message.getInterceptorChain().doInterceptStartingAt(message,
- OutgoingChainInterceptor.class.getName());
- }
- }
-
- private void processRequest(Message message, Exchange exchange) throws IOException {
-
- ServerProviderFactory providerFactory = ServerProviderFactory.getInstance(message);
-
- RequestPreprocessor rp = providerFactory.getRequestPreprocessor();
- if (rp != null) {
- rp.preprocess(message, new UriInfoImpl(message, null));
- }
-
- // Global pre-match request filters
- if (JAXRSUtils.runContainerRequestFilters(providerFactory, message, true, null)) {
- return;
- }
- // HTTP method
- String httpMethod = HttpUtils.getProtocolHeader(message, Message.HTTP_REQUEST_METHOD,
- HttpMethod.POST, true);
-
- // Path to match
- String rawPath = HttpUtils.getPathToMatch(message, true);
-
- Map<String, List<String>> protocolHeaders = CastUtils.cast((Map<?, ?>)message.get(Message.PROTOCOL_HEADERS));
-
- // Content-Type
- String requestContentType = null;
- List<String> ctHeaderValues = protocolHeaders.get(Message.CONTENT_TYPE);
- if (ctHeaderValues != null && !ctHeaderValues.isEmpty()) {
- requestContentType = ctHeaderValues.get(0);
- message.put(Message.CONTENT_TYPE, requestContentType);
- }
- if (requestContentType == null) {
- requestContentType = (String)message.get(Message.CONTENT_TYPE);
-
- if (requestContentType == null) {
- requestContentType = MediaType.WILDCARD;
- }
- }
-
- // Accept
- String acceptTypes = null;
- List<String> acceptHeaderValues = protocolHeaders.get(Message.ACCEPT_CONTENT_TYPE);
- if (acceptHeaderValues != null && !acceptHeaderValues.isEmpty()) {
- acceptTypes = acceptHeaderValues.get(0);
- message.put(Message.ACCEPT_CONTENT_TYPE, acceptTypes);
- }
-
- if (acceptTypes == null) {
- acceptTypes = HttpUtils.getProtocolHeader(message, Message.ACCEPT_CONTENT_TYPE, null);
- if (acceptTypes == null) {
- acceptTypes = "*/*";
- message.put(Message.ACCEPT_CONTENT_TYPE, acceptTypes);
- }
- }
- final List<MediaType> acceptContentTypes;
- try {
- acceptContentTypes = JAXRSUtils.sortMediaTypes(acceptTypes, JAXRSUtils.MEDIA_TYPE_Q_PARAM);
- } catch (IllegalArgumentException ex) {
- throw ExceptionUtils.toNotAcceptableException(null, null);
- }
- exchange.put(Message.ACCEPT_CONTENT_TYPE, acceptContentTypes);
-
- //1. Matching target resource class
- List<ClassResourceInfo> resources = JAXRSUtils.getRootResources(message);
- Map<ClassResourceInfo, MultivaluedMap<String, String>> matchedResources =
- JAXRSUtils.selectResourceClass(resources, rawPath, message);
- if (matchedResources == null) {
- org.apache.cxf.common.i18n.Message errorMsg =
- new org.apache.cxf.common.i18n.Message("NO_ROOT_EXC",
- BUNDLE,
- message.get(Message.REQUEST_URI),
- rawPath);
- Level logLevel = JAXRSUtils.getExceptionLogLevel(message, NotFoundException.class);
- LOG.log(logLevel == null ? Level.FINE : logLevel, errorMsg.toString());
- Response resp = JAXRSUtils.createResponse(resources, message, errorMsg.toString(),
- Response.Status.NOT_FOUND.getStatusCode(), false);
- throw ExceptionUtils.toNotFoundException(null, resp);
- }
-
- MultivaluedMap<String, String> matchedValues = new MetadataMap<>();
-
- final OperationResourceInfo ori;
-
- try {
- ori = JAXRSUtils.findTargetMethod(matchedResources, message,
- httpMethod, matchedValues, requestContentType, acceptContentTypes, true, true);
- setExchangeProperties(message, exchange, ori, matchedValues, resources.size());
- } catch (WebApplicationException ex) {
- if (JAXRSUtils.noResourceMethodForOptions(ex.getResponse(), httpMethod)) {
- Response response = JAXRSUtils.createResponse(resources, null, null, 200, true);
- exchange.put(Response.class, response);
- return;
- }
- throw ex;
- }
-
-
- if (LOG.isLoggable(Level.FINE)) {
- LOG.fine("Request path is: " + rawPath);
- LOG.fine("Request HTTP method is: " + httpMethod);
- LOG.fine("Request contentType is: " + requestContentType);
- LOG.fine("Accept contentType is: " + acceptTypes);
-
- LOG.fine("Found operation: " + ori.getMethodToInvoke().getName());
- }
-
- // Global and name-bound post-match request filters
- if (!ori.isSubResourceLocator()
- && JAXRSUtils.runContainerRequestFilters(providerFactory,
- message,
- false,
- ori.getNameBindings())) {
- return;
- }
-
-
- //Process parameters
- List<Object> params = JAXRSUtils.processParameters(ori, matchedValues, message);
- message.setContent(List.class, params);
- }
-
- private void convertExceptionToResponseIfPossible(Throwable ex, Message message) {
- Response excResponse = JAXRSUtils.convertFaultToResponse(ex, message);
- if (excResponse == null) {
- ServerProviderFactory.getInstance(message).clearThreadLocalProxies();
- message.getExchange().put(Message.PROPOGATE_EXCEPTION,
- ExceptionUtils.propogateException(message));
- throw ex instanceof RuntimeException ? (RuntimeException)ex
- : ExceptionUtils.toInternalServerErrorException(ex, null);
- }
- message.getExchange().put(Response.class, excResponse);
- message.getExchange().put(Throwable.class, ex);
- }
-
- private void setExchangeProperties(Message message,
- Exchange exchange,
- OperationResourceInfo ori,
- MultivaluedMap<String, String> values,
- int numberOfResources) {
- final ClassResourceInfo cri = ori.getClassResourceInfo();
- exchange.put(OperationResourceInfo.class, ori);
- exchange.put(JAXRSUtils.ROOT_RESOURCE_CLASS, cri);
- message.put(RESOURCE_METHOD, ori.getMethodToInvoke());
- message.put(URITemplate.TEMPLATE_PARAMETERS, values);
- message.put(URITemplate.URI_TEMPLATE, JAXRSUtils.getUriTemplate(message, cri, ori));
-
- String plainOperationName = ori.getMethodToInvoke().getName();
- if (numberOfResources > 1) {
- plainOperationName = cri.getServiceClass().getSimpleName() + "#" + plainOperationName;
- }
- exchange.put(RESOURCE_OPERATION_NAME, plainOperationName);
-
- if (ori.isOneway()
- || PropertyUtils.isTrue(HttpUtils.getProtocolHeader(message, Message.ONE_WAY_REQUEST, null))) {
- exchange.setOneWay(true);
- }
- ResourceProvider rp = cri.getResourceProvider();
- if (rp instanceof SingletonResourceProvider) {
- //cri.isSingleton is not guaranteed to indicate we have a 'pure' singleton
- exchange.put(Message.SERVICE_OBJECT, rp.getInstance(message));
- }
- }
-
- private Message createOutMessage(Message inMessage, Response r) {
- Endpoint e = inMessage.getExchange().getEndpoint();
- Message mout = e.getBinding().createMessage();
- mout.setContent(List.class, new MessageContentsList(r));
- mout.setExchange(inMessage.getExchange());
- mout.setInterceptorChain(
- OutgoingChainInterceptor.getOutInterceptorChain(inMessage.getExchange()));
- inMessage.getExchange().setOutMessage(mout);
- if (r.getStatus() >= Response.Status.BAD_REQUEST.getStatusCode()) {
- inMessage.getExchange().put("cxf.io.cacheinput", Boolean.FALSE);
- }
- return mout;
- }
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java
deleted file mode 100644
index ad75c0f..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java
+++ /dev/null
@@ -1,498 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.cxf.jaxrs.interceptor;
-
-import java.io.IOException;
-import java.io.OutputStream;
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Method;
-import java.lang.reflect.Type;
-import java.nio.charset.StandardCharsets;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
-import java.util.ResourceBundle;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import javax.servlet.http.HttpServletResponse;
-import javax.ws.rs.HttpMethod;
-import javax.ws.rs.Produces;
-import javax.ws.rs.core.HttpHeaders;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.MultivaluedMap;
-import javax.ws.rs.core.Response;
-import javax.ws.rs.ext.MessageBodyWriter;
-import javax.ws.rs.ext.WriterInterceptor;
-import javax.xml.stream.XMLStreamWriter;
-import javax.xml.stream.events.XMLEvent;
-
-import org.apache.cxf.common.i18n.BundleUtils;
-import org.apache.cxf.common.logging.LogUtils;
-import org.apache.cxf.common.util.PropertyUtils;
-import org.apache.cxf.interceptor.AbstractOutDatabindingInterceptor;
-import org.apache.cxf.interceptor.Fault;
-import org.apache.cxf.io.CachedOutputStream;
-import org.apache.cxf.jaxrs.impl.ResponseImpl;
-import org.apache.cxf.jaxrs.impl.WriterInterceptorMBW;
-import org.apache.cxf.jaxrs.model.OperationResourceInfo;
-import org.apache.cxf.jaxrs.provider.AbstractConfigurableProvider;
-import org.apache.cxf.jaxrs.provider.ServerProviderFactory;
-import org.apache.cxf.jaxrs.utils.AnnotationUtils;
-import org.apache.cxf.jaxrs.utils.ExceptionUtils;
-import org.apache.cxf.jaxrs.utils.HttpUtils;
-import org.apache.cxf.jaxrs.utils.InjectionUtils;
-import org.apache.cxf.jaxrs.utils.JAXRSUtils;
-import org.apache.cxf.message.Exchange;
-import org.apache.cxf.message.Message;
-import org.apache.cxf.message.MessageContentsList;
-import org.apache.cxf.message.MessageUtils;
-import org.apache.cxf.phase.Phase;
-import org.apache.cxf.staxutils.CachingXmlEventWriter;
-import org.apache.cxf.staxutils.StaxUtils;
-import org.apache.cxf.transport.http.AbstractHTTPDestination;
-
-public class JAXRSOutInterceptor extends AbstractOutDatabindingInterceptor {
- private static final Logger LOG = LogUtils.getL7dLogger(JAXRSOutInterceptor.class);
- private static final ResourceBundle BUNDLE = BundleUtils.getBundle(JAXRSOutInterceptor.class);
-
- public JAXRSOutInterceptor() {
- super(Phase.MARSHAL);
- }
-
- public void handleMessage(Message message) {
- ServerProviderFactory providerFactory = ServerProviderFactory.getInstance(message);
- try {
- processResponse(providerFactory, message);
- } finally {
- ServerProviderFactory.releaseRequestState(providerFactory, message);
- }
-
-
- }
-
- @SuppressWarnings("resource") // Response shouldn't be closed here
- private void processResponse(ServerProviderFactory providerFactory, Message message) {
-
- if (isResponseAlreadyHandled(message)) {
- return;
- }
- MessageContentsList objs = MessageContentsList.getContentsList(message);
- if (objs == null || objs.isEmpty()) {
- return;
- }
-
- Object responseObj = objs.get(0);
-
- final Response response;
- if (responseObj instanceof Response) {
- response = (Response)responseObj;
- if (response.getStatus() == 500
- && message.getExchange().get(JAXRSUtils.EXCEPTION_FROM_MAPPER) != null) {
- message.put(Message.RESPONSE_CODE, 500);
- return;
- }
- } else {
- int status = getStatus(message, responseObj != null ? 200 : 204);
- response = JAXRSUtils.toResponseBuilder(status).entity(responseObj).build();
- }
-
- Exchange exchange = message.getExchange();
- OperationResourceInfo ori = (OperationResourceInfo)exchange.get(OperationResourceInfo.class
- .getName());
-
- serializeMessage(providerFactory, message, response, ori, true);
- }
-
-
-
- private int getStatus(Message message, int defaultValue) {
- Object customStatus = message.getExchange().get(Message.RESPONSE_CODE);
- return customStatus == null ? defaultValue : (Integer)customStatus;
- }
-
- private void serializeMessage(ServerProviderFactory providerFactory,
- Message message,
- Response theResponse,
- OperationResourceInfo ori,
- boolean firstTry) {
-
- ResponseImpl response = (ResponseImpl)JAXRSUtils.copyResponseIfNeeded(theResponse);
-
- final Exchange exchange = message.getExchange();
-
- boolean headResponse = response.getStatus() == 200 && firstTry
- && ori != null && HttpMethod.HEAD.equals(ori.getHttpMethod());
- Object entity = response.getActualEntity();
- if (headResponse && entity != null) {
- LOG.info(new org.apache.cxf.common.i18n.Message("HEAD_WITHOUT_ENTITY", BUNDLE).toString());
- entity = null;
- }
-
-
- Method invoked = ori == null ? null : ori.getAnnotatedMethod() != null
- ? ori.getAnnotatedMethod() : ori.getMethodToInvoke();
-
- Annotation[] annotations;
- Annotation[] staticAnns = ori != null ? ori.getOutAnnotations() : new Annotation[]{};
- Annotation[] responseAnns = response.getEntityAnnotations();
- if (responseAnns != null) {
- annotations = new Annotation[staticAnns.length + responseAnns.length];
- System.arraycopy(staticAnns, 0, annotations, 0, staticAnns.length);
- System.arraycopy(responseAnns, 0, annotations, staticAnns.length, responseAnns.length);
- } else {
- annotations = staticAnns;
- }
-
- response.setStatus(getActualStatus(response.getStatus(), entity));
- response.setEntity(entity, annotations);
-
- // Prepare the headers
- MultivaluedMap<String, Object> responseHeaders =
- prepareResponseHeaders(message, response, entity, firstTry);
-
- // Run the filters
- try {
- JAXRSUtils.runContainerResponseFilters(providerFactory, response, message, ori, invoked);
- } catch (Throwable ex) {
- handleWriteException(providerFactory, message, ex, firstTry);
- return;
- }
-
- // Write the entity
- entity = InjectionUtils.getEntity(response.getActualEntity());
- setResponseStatus(message, getActualStatus(response.getStatus(), entity));
- if (entity == null) {
- if (!headResponse) {
- responseHeaders.putSingle(HttpHeaders.CONTENT_LENGTH, "0");
- if (MessageUtils.getContextualBoolean(message, "remove.content.type.for.empty.response", false)) {
- responseHeaders.remove(HttpHeaders.CONTENT_TYPE);
- message.remove(Message.CONTENT_TYPE);
- }
- }
- HttpUtils.convertHeaderValuesToString(responseHeaders, true);
- return;
- }
-
- Object ignoreWritersProp = exchange.get(JAXRSUtils.IGNORE_MESSAGE_WRITERS);
- boolean ignoreWriters =
- ignoreWritersProp != null && Boolean.valueOf(ignoreWritersProp.toString());
- if (ignoreWriters) {
- writeResponseToStream(message.getContent(OutputStream.class), entity);
- return;
- }
-
- MediaType responseMediaType =
- getResponseMediaType(responseHeaders.getFirst(HttpHeaders.CONTENT_TYPE));
-
- Class<?> serviceCls = invoked != null ? ori.getClassResourceInfo().getServiceClass() : null;
- Class<?> targetType = InjectionUtils.getRawResponseClass(entity);
- Type genericType = InjectionUtils.getGenericResponseType(invoked, serviceCls,
- response.getActualEntity(), targetType, exchange);
- targetType = InjectionUtils.updateParamClassToTypeIfNeeded(targetType, genericType);
- annotations = response.getEntityAnnotations();
-
- List<WriterInterceptor> writers = providerFactory
- .createMessageBodyWriterInterceptor(targetType, genericType, annotations, responseMediaType, message,
- ori == null ? null : ori.getNameBindings());
-
- OutputStream outOriginal = message.getContent(OutputStream.class);
- if (writers == null || writers.isEmpty()) {
- writeResponseErrorMessage(message, outOriginal, "NO_MSG_WRITER", targetType, responseMediaType);
- return;
- }
- try {
- boolean checkWriters = false;
- if (responseMediaType.isWildcardSubtype()) {
- Produces pM = AnnotationUtils.getMethodAnnotation(ori == null ? null : ori.getAnnotatedMethod(),
- Produces.class);
- Produces pC = AnnotationUtils.getClassAnnotation(serviceCls, Produces.class);
- checkWriters = pM == null && pC == null;
- }
- responseMediaType = checkFinalContentType(responseMediaType, writers, checkWriters);
- } catch (Throwable ex) {
- if (LOG.isLoggable(Level.FINE)) {
- LOG.log(Level.FINE, ex.getMessage(), ex);
- }
- handleWriteException(providerFactory, message, ex, firstTry);
- return;
- }
- String finalResponseContentType = JAXRSUtils.mediaTypeToString(responseMediaType);
- if (LOG.isLoggable(Level.FINE)) {
- LOG.fine("Response content type is: " + finalResponseContentType);
- }
- responseHeaders.putSingle(HttpHeaders.CONTENT_TYPE, finalResponseContentType);
- message.put(Message.CONTENT_TYPE, finalResponseContentType);
-
- boolean enabled = checkBufferingMode(message, writers, firstTry);
- try {
-
- try { // NOPMD
- JAXRSUtils.writeMessageBody(writers,
- entity,
- targetType,
- genericType,
- annotations,
- responseMediaType,
- responseHeaders,
- message);
-
- if (isResponseRedirected(message)) {
- return;
- }
- checkCachedStream(message, outOriginal, enabled);
- } finally {
- if (enabled) {
- OutputStream os = message.getContent(OutputStream.class);
- if (os != outOriginal && os instanceof CachedOutputStream) {
- os.close();
- }
- message.setContent(OutputStream.class, outOriginal);
- message.put(XMLStreamWriter.class.getName(), null);
- }
- }
-
- } catch (Throwable ex) {
- logWriteError(firstTry, targetType, responseMediaType);
- handleWriteException(providerFactory, message, ex, firstTry);
- }
- }
-
- private MultivaluedMap<String, Object> prepareResponseHeaders(Message message,
- ResponseImpl response,
- Object entity,
- boolean firstTry) {
- MultivaluedMap<String, Object> responseHeaders = response.getMetadata();
- @SuppressWarnings("unchecked")
- Map<String, List<Object>> userHeaders = (Map<String, List<Object>>)message.get(Message.PROTOCOL_HEADERS);
- if (firstTry && userHeaders != null) {
- responseHeaders.putAll(userHeaders);
- }
- if (entity != null) {
- Object customContentType = responseHeaders.getFirst(HttpHeaders.CONTENT_TYPE);
- if (customContentType == null) {
- String initialResponseContentType = (String)message.get(Message.CONTENT_TYPE);
- if (initialResponseContentType != null) {
- responseHeaders.putSingle(HttpHeaders.CONTENT_TYPE, initialResponseContentType);
- }
- } else {
- message.put(Message.CONTENT_TYPE, customContentType.toString());
- }
- }
- message.put(Message.PROTOCOL_HEADERS, responseHeaders);
- setResponseDate(responseHeaders, firstTry);
- return responseHeaders;
- }
-
- private MediaType getResponseMediaType(Object mediaTypeHeader) {
- MediaType responseMediaType;
- if (mediaTypeHeader instanceof MediaType) {
- responseMediaType = (MediaType)mediaTypeHeader;
- } else {
- responseMediaType = mediaTypeHeader == null ? MediaType.WILDCARD_TYPE
- : JAXRSUtils.toMediaType(mediaTypeHeader.toString());
- }
- return responseMediaType;
- }
-
- private int getActualStatus(int status, Object responseObj) {
- if (status == -1) {
- return responseObj == null ? 204 : 200;
- }
- return status;
- }
-
- private boolean checkBufferingMode(Message m, List<WriterInterceptor> writers, boolean firstTry) {
- if (!firstTry) {
- return false;
- }
- WriterInterceptor last = writers.get(writers.size() - 1);
- MessageBodyWriter<Object> w = ((WriterInterceptorMBW)last).getMBW();
- Object outBuf = m.getContextualProperty(OUT_BUFFERING);
- boolean enabled = PropertyUtils.isTrue(outBuf);
- boolean configurableProvider = w instanceof AbstractConfigurableProvider;
- if (!enabled && outBuf == null && configurableProvider) {
- enabled = ((AbstractConfigurableProvider)w).getEnableBuffering();
- }
- if (enabled) {
- boolean streamingOn = configurableProvider
- && ((AbstractConfigurableProvider)w).getEnableStreaming();
- if (streamingOn) {
- m.setContent(XMLStreamWriter.class, new CachingXmlEventWriter());
- } else {
- m.setContent(OutputStream.class, new CachedOutputStream());
- }
- }
- return enabled;
- }
-
- private void checkCachedStream(Message m, OutputStream osOriginal, boolean enabled) throws Exception {
- final XMLStreamWriter writer;
- if (enabled) {
- writer = m.getContent(XMLStreamWriter.class);
- } else {
- writer = (XMLStreamWriter)m.get(XMLStreamWriter.class.getName());
- }
- if (writer instanceof CachingXmlEventWriter) {
- CachingXmlEventWriter cache = (CachingXmlEventWriter)writer;
- if (!cache.getEvents().isEmpty()) {
- XMLStreamWriter origWriter = null;
- try {
- origWriter = StaxUtils.createXMLStreamWriter(osOriginal);
- for (XMLEvent event : cache.getEvents()) {
- StaxUtils.writeEvent(event, origWriter);
- }
- } finally {
- StaxUtils.close(origWriter);
- }
- }
- m.setContent(XMLStreamWriter.class, null);
- return;
- }
- if (enabled) {
- OutputStream os = m.getContent(OutputStream.class);
- if (os != osOriginal && os instanceof CachedOutputStream) {
- CachedOutputStream cos = (CachedOutputStream)os;
- if (cos.size() != 0) {
- cos.writeCacheTo(osOriginal);
- }
- }
- }
- }
-
- private void logWriteError(boolean firstTry, Class<?> cls, MediaType ct) {
- if (firstTry) {
- JAXRSUtils.logMessageHandlerProblem("MSG_WRITER_PROBLEM", cls, ct);
- }
- }
-
- private void handleWriteException(ServerProviderFactory pf,
- Message message,
- Throwable ex,
- boolean firstTry) {
- Response excResponse = null;
- if (firstTry) {
- excResponse = JAXRSUtils.convertFaultToResponse(ex, message);
- } else {
- message.getExchange().put(JAXRSUtils.SECOND_JAXRS_EXCEPTION, Boolean.TRUE);
- }
- if (excResponse == null) {
- setResponseStatus(message, 500);
- throw new Fault(ex);
- }
- serializeMessage(pf, message, excResponse, null, false);
-
- }
-
-
- private void writeResponseErrorMessage(Message message, OutputStream out,
- String name, Class<?> cls, MediaType ct) {
- message.put(Message.CONTENT_TYPE, "text/plain");
- message.put(Message.RESPONSE_CODE, 500);
- try {
- String errorMessage = JAXRSUtils.logMessageHandlerProblem(name, cls, ct);
- if (out != null) {
- out.write(errorMessage.getBytes(StandardCharsets.UTF_8));
- }
- } catch (IOException another) {
- // ignore
- }
- }
-
-
- private MediaType checkFinalContentType(MediaType mt, List<WriterInterceptor> writers, boolean checkWriters) {
- if (checkWriters) {
- int mbwIndex = writers.size() == 1 ? 0 : writers.size() - 1;
- MessageBodyWriter<Object> writer = ((WriterInterceptorMBW)writers.get(mbwIndex)).getMBW();
- Produces pm = writer.getClass().getAnnotation(Produces.class);
- if (pm != null) {
- List<MediaType> sorted =
- JAXRSUtils.sortMediaTypes(JAXRSUtils.getMediaTypes(pm.value()), JAXRSUtils.MEDIA_TYPE_QS_PARAM);
- mt = JAXRSUtils.intersectMimeTypes(sorted, mt).get(0);
- }
- }
- if (mt.isWildcardType() || mt.isWildcardSubtype()) {
- if ("application".equals(mt.getType()) || mt.isWildcardType()) {
- mt = MediaType.APPLICATION_OCTET_STREAM_TYPE;
- } else {
- throw ExceptionUtils.toNotAcceptableException(null, null);
- }
- }
- return mt;
- }
-
- private void setResponseDate(MultivaluedMap<String, Object> headers, boolean firstTry) {
- if (!firstTry || headers.containsKey(HttpHeaders.DATE)) {
- return;
- }
- SimpleDateFormat format = HttpUtils.getHttpDateFormat();
- headers.putSingle(HttpHeaders.DATE, format.format(new Date()));
- }
-
- private boolean isResponseAlreadyHandled(Message m) {
- return isResponseAlreadyCommited(m) || isResponseRedirected(m);
- }
-
- private boolean isResponseAlreadyCommited(Message m) {
- return Boolean.TRUE.equals(m.getExchange().get(AbstractHTTPDestination.RESPONSE_COMMITED));
- }
-
- private boolean isResponseRedirected(Message m) {
- return Boolean.TRUE.equals(m.getExchange().get(AbstractHTTPDestination.REQUEST_REDIRECTED));
- }
-
- private void writeResponseToStream(OutputStream os, Object responseObj) {
- try {
- byte[] bytes = responseObj.toString().getBytes(StandardCharsets.UTF_8);
- os.write(bytes, 0, bytes.length);
- } catch (Exception ex) {
- LOG.severe("Problem with writing the data to the output stream");
- ex.printStackTrace();
- throw new RuntimeException(ex);
- }
- }
-
- private void setResponseStatus(Message message, int status) {
- message.put(Message.RESPONSE_CODE, status);
- boolean responseHeadersCopied = isResponseHeadersCopied(message);
- if (responseHeadersCopied) {
- HttpServletResponse response =
- (HttpServletResponse)message.get(AbstractHTTPDestination.HTTP_RESPONSE);
- response.setStatus(status);
- }
- }
-
- // Some CXF interceptors such as FIStaxOutInterceptor will indirectly initiate
- // an early copying of response code and headers into the HttpServletResponse
- // TODO : Pushing the filter processing and copying response headers into say
- // PRE-LOGICAl and PREPARE_SEND interceptors will most likely be a good thing
- // however JAX-RS MessageBodyWriters are also allowed to add response headers
- // which is reason why a MultipartMap parameter in MessageBodyWriter.writeTo
- // method is modifiable. Thus we do need to know if the initial copy has already
- // occurred: for now we will just use to ensure the correct status is set
- private boolean isResponseHeadersCopied(Message message) {
- return PropertyUtils.isTrue(message.get(AbstractHTTPDestination.RESPONSE_HEADERS_COPIED));
- }
-
- public void handleFault(Message message) {
- // complete
- }
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxrs/model/AbstractResourceInfo.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxrs/model/AbstractResourceInfo.java
deleted file mode 100644
index edf010e..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxrs/model/AbstractResourceInfo.java
+++ /dev/null
@@ -1,389 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.cxf.jaxrs.model;
-
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.logging.Logger;
-
-import javax.ws.rs.core.Application;
-import javax.ws.rs.core.Context;
-
-import org.apache.cxf.Bus;
-import org.apache.cxf.BusFactory;
-import org.apache.cxf.common.logging.LogUtils;
-import org.apache.cxf.common.util.ReflectionUtil;
-import org.apache.cxf.jaxrs.impl.tl.ThreadLocalProxy;
-import org.apache.cxf.jaxrs.utils.InjectionUtils;
-
-public abstract class AbstractResourceInfo {
- public static final String CONSTRUCTOR_PROXY_MAP = "jaxrs-constructor-proxy-map";
- private static final Logger LOG = LogUtils.getL7dLogger(AbstractResourceInfo.class);
- private static final String FIELD_PROXY_MAP = "jaxrs-field-proxy-map";
- private static final String SETTER_PROXY_MAP = "jaxrs-setter-proxy-map";
-
- protected boolean root;
- protected Class<?> resourceClass;
- protected Class<?> serviceClass;
-
- private Map<Class<?>, List<Field>> contextFields;
- private Map<Class<?>, Map<Class<?>, Method>> contextMethods;
- private Bus bus;
- private boolean constructorProxiesAvailable;
- private boolean contextsAvailable;
-
- protected AbstractResourceInfo(Bus bus) {
- this.bus = bus;
- }
-
- protected AbstractResourceInfo(Class<?> resourceClass, Class<?> serviceClass,
- boolean isRoot, boolean checkContexts, Bus bus) {
- this(resourceClass, serviceClass, isRoot, checkContexts, null, bus, null);
- }
-
- protected AbstractResourceInfo(Class<?> resourceClass,
- Class<?> serviceClass,
- boolean isRoot,
- boolean checkContexts,
- Map<Class<?>, ThreadLocalProxy<?>> constructorProxies,
- Bus bus,
- Object provider) {
- this.bus = bus;
- this.serviceClass = serviceClass;
- this.resourceClass = resourceClass;
- root = isRoot;
- if (checkContexts && resourceClass != null) {
- findContexts(serviceClass, provider, constructorProxies);
- }
- }
-
- private void findContexts(Class<?> cls, Object provider,
- Map<Class<?>, ThreadLocalProxy<?>> constructorProxies) {
- findContextFields(cls, provider);
- findContextSetterMethods(cls, provider);
- if (constructorProxies != null) {
- Map<Class<?>, Map<Class<?>, ThreadLocalProxy<?>>> proxies = getConstructorProxyMap();
- proxies.put(serviceClass, constructorProxies);
- constructorProxiesAvailable = true;
- }
-
-
- contextsAvailable = contextFields != null && !contextFields.isEmpty()
- || contextMethods != null && !contextMethods.isEmpty()
- || constructorProxiesAvailable;
- }
-
- public boolean contextsAvailable() {
- return contextsAvailable;
- }
-
- public Bus getBus() {
- return bus;
- }
-
- public void setResourceClass(Class<?> rClass) {
- resourceClass = rClass;
- if (serviceClass.isInterface() && resourceClass != null && !resourceClass.isInterface()) {
- findContexts(resourceClass, null, null);
- }
- }
-
- public Class<?> getServiceClass() {
- return serviceClass;
- }
-
- private void findContextFields(Class<?> cls, Object provider) {
- if (cls == Object.class || cls == null) {
- return;
- }
- for (Field f : ReflectionUtil.getDeclaredFields(cls)) {
- for (Annotation a : f.getAnnotations()) {
- if (a.annotationType() == Context.class
- && (f.getType().isInterface() || f.getType() == Application.class)) {
- contextFields = addContextField(contextFields, f);
- checkContextClass(f.getType());
- if (!InjectionUtils.VALUE_CONTEXTS.contains(f.getType().getName())) {
- addToMap(getFieldProxyMap(true), f, getFieldThreadLocalProxy(f, provider));
- }
- }
- }
- }
- findContextFields(cls.getSuperclass(), provider);
- }
-
- private static ThreadLocalProxy<?> getFieldThreadLocalProxy(Field f, Object provider) {
- if (provider != null) {
- Object proxy = null;
- synchronized (provider) {
- try {
- proxy = InjectionUtils.extractFieldValue(f, provider);
- } catch (Throwable t) {
- // continue
- }
- if (!(proxy instanceof ThreadLocalProxy)) {
- proxy = InjectionUtils.createThreadLocalProxy(f.getType());
- InjectionUtils.injectFieldValue(f, provider, proxy);
- }
- }
- return (ThreadLocalProxy<?>)proxy;
- }
- return InjectionUtils.createThreadLocalProxy(f.getType());
- }
-
- private static ThreadLocalProxy<?> getMethodThreadLocalProxy(Method m, Object provider) {
- if (provider != null) {
- Object proxy = null;
- synchronized (provider) {
- try {
- proxy = InjectionUtils.extractFromMethod(provider,
- InjectionUtils.getGetterFromSetter(m),
- false);
- } catch (Throwable t) {
- // continue
- }
- if (!(proxy instanceof ThreadLocalProxy)) {
- proxy = InjectionUtils.createThreadLocalProxy(m.getParameterTypes()[0]);
- InjectionUtils.injectThroughMethod(provider, m, proxy);
- }
- }
- return (ThreadLocalProxy<?>)proxy;
- }
- return InjectionUtils.createThreadLocalProxy(m.getParameterTypes()[0]);
- }
-
- @SuppressWarnings("unchecked")
- private <T> Map<Class<?>, Map<T, ThreadLocalProxy<?>>> getProxyMap(String prop, boolean create) {
- // Avoid synchronizing on the bus for a ConcurrentHashMAp
- if (bus.getProperties() instanceof ConcurrentHashMap) {
- return (Map<Class<?>, Map<T, ThreadLocalProxy<?>>>) bus.getProperties().computeIfAbsent(prop, k ->
- new ConcurrentHashMap<Class<?>, Map<T, ThreadLocalProxy<?>>>(2)
- );
- }
-
- Object property;
- synchronized (bus) {
- property = bus.getProperty(prop);
- if (property == null && create) {
- Map<Class<?>, Map<T, ThreadLocalProxy<?>>> map
- = new ConcurrentHashMap<>(2);
- bus.setProperty(prop, map);
- property = map;
- }
- }
- return (Map<Class<?>, Map<T, ThreadLocalProxy<?>>>)property;
- }
-
- public Map<Class<?>, ThreadLocalProxy<?>> getConstructorProxies() {
- if (constructorProxiesAvailable) {
- return getConstructorProxyMap().get(serviceClass);
- }
- return null;
- }
-
- @SuppressWarnings("unchecked")
- private Map<Class<?>, Map<Class<?>, ThreadLocalProxy<?>>> getConstructorProxyMap() {
- Object property = bus.getProperty(CONSTRUCTOR_PROXY_MAP);
- if (property == null) {
- Map<Class<?>, Map<Class<?>, ThreadLocalProxy<?>>> map
- = new ConcurrentHashMap<>(2);
- bus.setProperty(CONSTRUCTOR_PROXY_MAP, map);
- property = map;
- }
- return (Map<Class<?>, Map<Class<?>, ThreadLocalProxy<?>>>)property;
- }
-
- private Map<Class<?>, Map<Field, ThreadLocalProxy<?>>> getFieldProxyMap(boolean create) {
- return getProxyMap(FIELD_PROXY_MAP, create);
- }
-
- private Map<Class<?>, Map<Method, ThreadLocalProxy<?>>> getSetterProxyMap(boolean create) {
- return getProxyMap(SETTER_PROXY_MAP, create);
- }
-
- private void findContextSetterMethods(Class<?> cls, Object provider) {
-
- for (Method m : cls.getMethods()) {
-
- if (!m.getName().startsWith("set") || m.getParameterTypes().length != 1) {
- continue;
- }
- for (Annotation a : m.getAnnotations()) {
- if (a.annotationType() == Context.class) {
- checkContextMethod(m, provider);
- break;
- }
- }
- }
- Class<?>[] interfaces = cls.getInterfaces();
- for (Class<?> i : interfaces) {
- findContextSetterMethods(i, provider);
- }
- Class<?> superCls = cls.getSuperclass();
- if (superCls != null && superCls != Object.class) {
- findContextSetterMethods(superCls, provider);
- }
- }
-
- private void checkContextMethod(Method m, Object provider) {
- Class<?> type = m.getParameterTypes()[0];
- if (type.isInterface() || type == Application.class) {
- checkContextClass(type);
- addContextMethod(type, m, provider);
- }
- }
- private void checkContextClass(Class<?> type) {
- if (!InjectionUtils.STANDARD_CONTEXT_CLASSES.contains(type.getName())) {
- LOG.fine("Injecting a custom context " + type.getName()
- + ", ContextProvider is required for this type");
- }
- }
-
- public Map<Class<?>, Method> getContextMethods() {
- Map<Class<?>, Method> methods = contextMethods == null ? null : contextMethods.get(getServiceClass());
- return methods == null ? Collections.emptyMap()
- : Collections.unmodifiableMap(methods);
- }
-
- private void addContextMethod(Class<?> contextClass, Method m, Object provider) {
- if (contextMethods == null) {
- contextMethods = new HashMap<>();
- }
- addToMap(contextMethods, contextClass, m);
- if (!InjectionUtils.VALUE_CONTEXTS.contains(m.getParameterTypes()[0].getName())) {
- addToMap(getSetterProxyMap(true), m, getMethodThreadLocalProxy(m, provider));
- }
- }
-
- public boolean isRoot() {
- return root;
- }
-
- public Class<?> getResourceClass() {
- return resourceClass;
- }
-
- public List<Field> getContextFields() {
- return getList(contextFields);
- }
-
- public ThreadLocalProxy<?> getContextFieldProxy(Field f) {
- return getProxy(getFieldProxyMap(true), f);
- }
-
- public ThreadLocalProxy<?> getContextSetterProxy(Method m) {
- return getProxy(getSetterProxyMap(true), m);
- }
-
- public abstract boolean isSingleton();
-
- @SuppressWarnings("rawtypes")
- public static void clearAllMaps() {
- Bus bus = BusFactory.getThreadDefaultBus(false);
- if (bus != null) {
- Object property = bus.getProperty(FIELD_PROXY_MAP);
- if (property != null) {
- ((Map)property).clear();
- }
- property = bus.getProperty(SETTER_PROXY_MAP);
- if (property != null) {
- ((Map)property).clear();
- }
- property = bus.getProperty(CONSTRUCTOR_PROXY_MAP);
- if (property != null) {
- ((Map)property).clear();
- }
- }
- }
-
- public void clearThreadLocalProxies() {
- clearProxies(getFieldProxyMap(false));
- clearProxies(getSetterProxyMap(false));
- clearProxies(getConstructorProxyMap());
- }
-
- private <T> void clearProxies(Map<Class<?>, Map<T, ThreadLocalProxy<?>>> tlps) {
- Map<T, ThreadLocalProxy<?>> proxies = tlps == null ? null : tlps.get(getServiceClass());
- if (proxies == null) {
- return;
- }
- for (ThreadLocalProxy<?> tlp : proxies.values()) {
- if (tlp != null) {
- tlp.remove();
- }
- }
- }
-
- private Map<Class<?>, List<Field>> addContextField(Map<Class<?>, List<Field>> theFields, Field f) {
- if (theFields == null) {
- theFields = new HashMap<>();
- }
-
- List<Field> fields = theFields.get(serviceClass);
- if (fields == null) {
- fields = new ArrayList<>();
- theFields.put(serviceClass, fields);
- }
- if (!fields.contains(f)) {
- fields.add(f);
- }
- return theFields;
- }
-
- private <T, V> void addToMap(Map<Class<?>, Map<T, V>> proxyMap,
- T f,
- V proxy) {
- Map<T, V> proxies = proxyMap.get(serviceClass);
- if (proxies == null) {
- proxies = new ConcurrentHashMap<>();
- proxyMap.put(serviceClass, proxies);
- }
- if (!proxies.containsKey(f)) {
- proxies.put(f, proxy);
- }
- }
-
- private List<Field> getList(Map<Class<?>, List<Field>> fields) {
- List<Field> ret = fields == null ? null : fields.get(getServiceClass());
- if (ret != null) {
- ret = Collections.unmodifiableList(ret);
- } else {
- ret = Collections.emptyList();
- }
- return ret;
- }
-
- private <T> ThreadLocalProxy<?> getProxy(Map<Class<?>, Map<T, ThreadLocalProxy<?>>> proxies,
- T key) {
-
- Map<?, ThreadLocalProxy<?>> theMap = proxies == null ? null : proxies.get(getServiceClass());
- ThreadLocalProxy<?> ret = null;
- if (theMap != null) {
- ret = theMap.get(key);
- }
- return ret;
- }
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxrs/model/ClassResourceInfo.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxrs/model/ClassResourceInfo.java
deleted file mode 100644
index a69cac1..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxrs/model/ClassResourceInfo.java
+++ /dev/null
@@ -1,366 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.cxf.jaxrs.model;
-
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-
-import javax.ws.rs.BeanParam;
-import javax.ws.rs.Consumes;
-import javax.ws.rs.Path;
-import javax.ws.rs.Produces;
-import javax.ws.rs.core.Application;
-import javax.ws.rs.core.MediaType;
-
-import org.apache.cxf.Bus;
-import org.apache.cxf.BusFactory;
-import org.apache.cxf.common.util.ClassHelper;
-import org.apache.cxf.jaxrs.lifecycle.ResourceProvider;
-import org.apache.cxf.jaxrs.provider.ServerProviderFactory;
-import org.apache.cxf.jaxrs.utils.AnnotationUtils;
-import org.apache.cxf.jaxrs.utils.InjectionUtils;
-import org.apache.cxf.jaxrs.utils.JAXRSUtils;
-import org.apache.cxf.jaxrs.utils.ResourceUtils;
-import org.apache.cxf.message.Message;
-
-public class ClassResourceInfo extends BeanResourceInfo {
-
- private URITemplate uriTemplate;
- private MethodDispatcher methodDispatcher;
- private ResourceProvider resourceProvider;
- private ConcurrentHashMap<SubresourceKey, ClassResourceInfo> subResources
- = new ConcurrentHashMap<>();
-
- private boolean enableStatic;
- private boolean createdFromModel;
- private String consumesTypes;
- private String producesTypes;
- private List<MediaType> defaultConsumes = Collections.singletonList(JAXRSUtils.ALL_TYPES);
- private List<MediaType> defaultProduces = Collections.singletonList(JAXRSUtils.ALL_TYPES);
- private Set<String> nameBindings = Collections.emptySet();
- private ClassResourceInfo parent;
- private Set<String> injectedSubInstances = new HashSet<>();
- public ClassResourceInfo(ClassResourceInfo cri) {
- super(cri.getBus());
- if (cri.isCreatedFromModel() && !InjectionUtils.isConcreteClass(cri.getServiceClass())) {
- this.root = cri.root;
- this.serviceClass = cri.serviceClass;
- this.uriTemplate = cri.uriTemplate;
- this.methodDispatcher = new MethodDispatcher(cri.methodDispatcher, this);
- this.subResources = cri.subResources;
- //CHECKSTYLE:OFF
- this.paramFields = cri.paramFields;
- this.paramMethods = cri.paramMethods;
- //CHECKSTYLE:ON
- this.enableStatic = true;
- this.nameBindings = cri.nameBindings;
- this.parent = cri.parent;
- } else {
- throw new IllegalArgumentException();
- }
-
- }
-
- public ClassResourceInfo(Class<?> theResourceClass, Class<?> theServiceClass,
- boolean theRoot, boolean enableStatic, Bus bus) {
- super(theResourceClass, theServiceClass, theRoot, theRoot || enableStatic, bus);
- this.enableStatic = enableStatic;
- if (resourceClass != null) {
- nameBindings = AnnotationUtils.getNameBindings(bus, serviceClass);
- }
- }
- //CHECKSTYLE:OFF
- public ClassResourceInfo(Class<?> theResourceClass, Class<?> theServiceClass,
- boolean theRoot, boolean enableStatic, Bus bus, List<MediaType> defaultProduces,
- List<MediaType> defaultConsumes) {
- //CHECKSTYLE:ON
- this(theResourceClass, theServiceClass, theRoot, enableStatic, bus);
- if (defaultProduces != null) {
- this.defaultProduces = defaultProduces;
- }
- if (defaultConsumes != null) {
- this.defaultConsumes = defaultConsumes;
- }
- }
- public ClassResourceInfo(Class<?> theResourceClass, Class<?> theServiceClass,
- boolean theRoot, boolean enableStatic, boolean createdFromModel, Bus bus) {
- this(theResourceClass, theServiceClass, theRoot, enableStatic, bus);
- this.createdFromModel = createdFromModel;
- }
- //CHECKSTYLE:OFF
- public ClassResourceInfo(Class<?> theResourceClass, Class<?> theServiceClass,
- boolean theRoot, boolean enableStatic, boolean createdFromModel,
- String consumesTypes, String producesTypes, Bus bus) {
- //CHECKSTYLE:ON
- this(theResourceClass, theServiceClass, theRoot, enableStatic, createdFromModel, bus);
- this.consumesTypes = consumesTypes;
- this.producesTypes = producesTypes;
- }
-
- // The following constructors are used by tests only
- public ClassResourceInfo(Class<?> theResourceClass) {
- this(theResourceClass, true);
- }
-
- public ClassResourceInfo(Class<?> theResourceClass, boolean theRoot) {
- this(theResourceClass, theResourceClass, theRoot);
- }
-
- public ClassResourceInfo(Class<?> theResourceClass, Class<?> theServiceClass) {
- this(theResourceClass, theServiceClass, false);
- }
-
- public ClassResourceInfo(Class<?> theResourceClass, Class<?> theServiceClass, boolean theRoot) {
- this(theResourceClass, theServiceClass, theRoot, false, BusFactory.getDefaultBus(true));
- }
-
- public ClassResourceInfo findResource(Class<?> typedClass, Class<?> instanceClass) {
- instanceClass = enableStatic ? typedClass : instanceClass;
- SubresourceKey key = new SubresourceKey(typedClass, instanceClass);
- return subResources.get(key);
- }
-
- @Override
- public boolean contextsAvailable() {
- // avoid re-injecting the contexts if the root acts as subresource
- return super.contextsAvailable() && (isRoot() || parent != null);
- }
-
- public ClassResourceInfo getSubResource(Class<?> typedClass, Class<?> instanceClass) {
- return getSubResource(typedClass, instanceClass, null, enableStatic, null);
- }
-
- public ClassResourceInfo getSubResource(Class<?> typedClass, Class<?> instanceClass, Object instance) {
- instanceClass = enableStatic && typedClass != Object.class ? typedClass : instanceClass;
- return getSubResource(typedClass, instanceClass, instance, enableStatic, JAXRSUtils.getCurrentMessage());
- }
-
- public ClassResourceInfo getSubResource(Class<?> typedClass,
- Class<?> instanceClass,
- Object instance,
- boolean resolveContexts,
- Message message) {
-
- SubresourceKey key = new SubresourceKey(typedClass, instanceClass);
- ClassResourceInfo cri = subResources.get(key);
- if (cri == null) {
- cri = ResourceUtils.createClassResourceInfo(typedClass, instanceClass, this, false, resolveContexts,
- getBus());
- if (cri != null) {
- if (message != null) {
- cri.initBeanParamInfo(ServerProviderFactory.getInstance(message));
- }
- subResources.putIfAbsent(key, cri);
- }
- }
- // this branch will run only if ResourceContext is used
- // or static resolution is enabled for subresources initialized
- // from within singleton root resources (not default)
- if (resolveContexts && cri != null && cri.isSingleton() && instance != null && cri.contextsAvailable()) {
- synchronized (this) {
- if (!injectedSubInstances.contains(instance.toString())) {
- Application app = null;
- if (message != null) {
- ProviderInfo<?> appProvider =
- (ProviderInfo<?>)message.getExchange().getEndpoint().get(Application.class.getName());
- if (appProvider != null) {
- app = (Application)appProvider.getProvider();
- }
- }
- InjectionUtils.injectContextProxiesAndApplication(cri, instance, app, null);
- injectedSubInstances.add(instance.toString());
- }
- }
- }
-
- return cri;
- }
-
- public void addSubClassResourceInfo(ClassResourceInfo cri) {
- subResources.putIfAbsent(new SubresourceKey(cri.getResourceClass(),
- cri.getServiceClass()),
- cri);
- }
-
- public Collection<ClassResourceInfo> getSubResources() {
- return Collections.unmodifiableCollection(subResources.values());
- }
-
- public Set<String> getNameBindings() {
- if (parent == null) {
- return nameBindings;
- }
- return parent.getNameBindings();
- }
-
- public void setNameBindings(Set<String> names) {
- nameBindings = names;
- }
-
- public Set<String> getAllowedMethods() {
- Set<String> methods = new HashSet<>();
- for (OperationResourceInfo o : methodDispatcher.getOperationResourceInfos()) {
- String method = o.getHttpMethod();
- if (method != null) {
- methods.add(method);
- }
- }
- return methods;
- }
-
-
-
- public URITemplate getURITemplate() {
- return uriTemplate;
- }
-
- public void setURITemplate(URITemplate u) {
- uriTemplate = u;
- }
-
- public MethodDispatcher getMethodDispatcher() {
- return methodDispatcher;
- }
-
- public void setMethodDispatcher(MethodDispatcher md) {
- methodDispatcher = md;
- }
-
- public boolean hasSubResources() {
- return !subResources.isEmpty();
- }
-
-
- public boolean isCreatedFromModel() {
- return createdFromModel;
- }
-
- public ResourceProvider getResourceProvider() {
- return resourceProvider;
- }
-
- public void setResourceProvider(ResourceProvider rp) {
- resourceProvider = rp;
- }
-
- public List<MediaType> getProduceMime() {
- if (producesTypes != null) {
- return JAXRSUtils.parseMediaTypes(producesTypes);
- }
- Produces produces = AnnotationUtils.getClassAnnotation(getServiceClass(), Produces.class);
- if (produces != null || parent == null) {
- return JAXRSUtils.getProduceTypes(produces, defaultProduces);
- }
- return parent.getProduceMime();
- }
-
- public List<MediaType> getConsumeMime() {
- if (consumesTypes != null) {
- return JAXRSUtils.parseMediaTypes(consumesTypes);
- }
- Consumes consumes = AnnotationUtils.getClassAnnotation(getServiceClass(), Consumes.class);
- if (consumes != null || parent == null) {
- return JAXRSUtils.getConsumeTypes(consumes, defaultConsumes);
- }
- return parent.getConsumeMime();
- }
-
- public Path getPath() {
- return AnnotationUtils.getClassAnnotation(getServiceClass(), Path.class);
- }
-
- @Override
- public boolean isSingleton() {
- if (parent == null) {
- return resourceProvider != null && resourceProvider.isSingleton();
- }
- return parent.isSingleton();
- }
-
- public void setParent(ClassResourceInfo parent) {
- this.parent = parent;
- }
-
- public ClassResourceInfo getParent() {
- return parent;
- }
-
- public void initBeanParamInfo(ServerProviderFactory factory) {
- if (factory != null) {
- Set<OperationResourceInfo> oris = getMethodDispatcher().getOperationResourceInfos();
- for (OperationResourceInfo ori : oris) {
- List<Parameter> params = ori.getParameters();
- for (Parameter param : params) {
- if (param.getType() == ParameterType.BEAN) {
- Class<?> cls = ori.getMethodToInvoke().getParameterTypes()[param.getIndex()];
- BeanParamInfo bpi = new BeanParamInfo(cls, getBus());
- factory.addBeanParamInfo(bpi);
- }
- }
- }
- List<Method> methods = super.getParameterMethods();
- for (Method m : methods) {
- if (m.getAnnotation(BeanParam.class) != null) {
- BeanParamInfo bpi = new BeanParamInfo(m.getParameterTypes()[0], getBus());
- factory.addBeanParamInfo(bpi);
- }
- }
- List<Field> fields = super.getParameterFields();
- for (Field f : fields) {
- if (f.getAnnotation(BeanParam.class) != null) {
- BeanParamInfo bpi = new BeanParamInfo(f.getType(), getBus());
- factory.addBeanParamInfo(bpi);
- }
- }
- }
- }
-
- @Override
- public void clearThreadLocalProxies() {
- super.clearThreadLocalProxies();
- if (!injectedSubInstances.isEmpty()) {
- for (ClassResourceInfo sub : subResources.values()) {
- if (sub != this) {
- sub.clearThreadLocalProxies();
- }
- }
- }
- }
-
- public void injectContexts(Object resourceObject, OperationResourceInfo ori, Message inMessage) {
- final boolean contextsAvailable = contextsAvailable();
- final boolean paramsAvailable = paramsAvailable();
- if (contextsAvailable || paramsAvailable) {
- Object realResourceObject = ClassHelper.getRealObject(resourceObject);
- if (paramsAvailable) {
- JAXRSUtils.injectParameters(ori, this, realResourceObject, inMessage);
- }
- if (contextsAvailable) {
- InjectionUtils.injectContexts(realResourceObject, this, inMessage);
- }
- }
- }
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxrs/model/URITemplate.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxrs/model/URITemplate.java
deleted file mode 100644
index 85fdd7e..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxrs/model/URITemplate.java
+++ /dev/null
@@ -1,627 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.cxf.jaxrs.model;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-import javax.ws.rs.Path;
-import javax.ws.rs.core.MultivaluedMap;
-import javax.ws.rs.core.PathSegment;
-
-import org.apache.cxf.common.util.SystemPropertyAction;
-import org.apache.cxf.jaxrs.utils.HttpUtils;
-import org.apache.cxf.jaxrs.utils.JAXRSUtils;
-
-public final class URITemplate {
-
- public static final String TEMPLATE_PARAMETERS = "jaxrs.template.parameters";
- public static final String URI_TEMPLATE = "jaxrs.template.uri";
- public static final String LIMITED_REGEX_SUFFIX = "(/.*)?";
- public static final String FINAL_MATCH_GROUP = "FINAL_MATCH_GROUP";
- private static final String DEFAULT_PATH_VARIABLE_REGEX = "([^/]+?)";
- private static final String CHARACTERS_TO_ESCAPE = ".*+$()";
- private static final String SLASH = "/";
- private static final String SLASH_QUOTE = "/;";
- private static final int MAX_URI_TEMPLATE_CACHE_SIZE =
- SystemPropertyAction.getInteger("org.apache.cxf.jaxrs.max_uri_template_cache_size", 2000);
- private static final Map<String, URITemplate> URI_TEMPLATE_CACHE = new ConcurrentHashMap<>();
-
- private final String template;
- private final List<String> variables = new ArrayList<>();
- private final List<String> customVariables = new ArrayList<>();
- private final Pattern templateRegexPattern;
- private final String literals;
- private final List<UriChunk> uriChunks;
-
- public URITemplate(String theTemplate) {
- template = theTemplate;
- StringBuilder literalChars = new StringBuilder();
- StringBuilder patternBuilder = new StringBuilder();
- CurlyBraceTokenizer tok = new CurlyBraceTokenizer(template);
- uriChunks = new ArrayList<>();
- while (tok.hasNext()) {
- String templatePart = tok.next();
- UriChunk chunk = UriChunk.createUriChunk(templatePart);
- uriChunks.add(chunk);
- if (chunk instanceof Literal) {
- String encodedValue = HttpUtils.encodePartiallyEncoded(chunk.getValue(), false);
- String substr = escapeCharacters(encodedValue);
- literalChars.append(substr);
- patternBuilder.append(substr);
- } else if (chunk instanceof Variable) {
- Variable var = (Variable)chunk;
- variables.add(var.getName());
- String pattern = var.getPattern();
- if (pattern != null) {
- customVariables.add(var.getName());
- // Add parenthesis to the pattern to identify a regex in the pattern,
- // however do not add them if they already exist since that will cause the Matcher
- // to create extraneous values. Parens identify a group so multiple parens would
- // indicate multiple groups.
- if (pattern.startsWith("(") && pattern.endsWith(")")) {
- patternBuilder.append(pattern);
- } else {
- patternBuilder.append('(');
- patternBuilder.append(pattern);
- patternBuilder.append(')');
- }
- } else {
- patternBuilder.append(DEFAULT_PATH_VARIABLE_REGEX);
- }
- }
- }
- literals = literalChars.toString();
-
- int endPos = patternBuilder.length() - 1;
- boolean endsWithSlash = (endPos >= 0) && patternBuilder.charAt(endPos) == '/';
- if (endsWithSlash) {
- patternBuilder.deleteCharAt(endPos);
- }
- patternBuilder.append(LIMITED_REGEX_SUFFIX);
-
- templateRegexPattern = Pattern.compile(patternBuilder.toString());
- }
-
- public String getLiteralChars() {
- return literals;
- }
-
- public String getValue() {
- return template;
- }
-
- public String getPatternValue() {
- return templateRegexPattern.toString();
- }
-
- /**
- * List of all variables in order of appearance in template.
- *
- * @return unmodifiable list of variable names w/o patterns, e.g. for "/foo/{v1:\\d}/{v2}" returned list
- * is ["v1","v2"].
- */
- public List<String> getVariables() {
- return Collections.unmodifiableList(variables);
- }
-
- /**
- * List of variables with patterns (regexps). List is subset of elements from {@link #getVariables()}.
- *
- * @return unmodifiable list of variables names w/o patterns.
- */
- public List<String> getCustomVariables() {
- return Collections.unmodifiableList(customVariables);
- }
-
- private static String escapeCharacters(String expression) {
-
- int length = expression.length();
- int i = 0;
- char ch = ' ';
- for (; i < length; ++i) {
- ch = expression.charAt(i);
- if (isReservedCharacter(ch)) {
- break;
- }
- }
-
- if (i == length) {
- return expression;
- }
-
- // Allows for up to 8 escaped characters before we start creating more
- // StringBuilders. 8 is an arbitrary limit, but it seems to be
- // sufficient in most cases.
- StringBuilder sb = new StringBuilder(length + 8);
- sb.append(expression, 0, i);
- sb.append('\\');
- sb.append(ch);
- ++i;
- for (; i < length; ++i) {
- ch = expression.charAt(i);
- if (isReservedCharacter(ch)) {
- sb.append('\\');
- }
- sb.append(ch);
- }
- return sb.toString();
- }
-
- private static boolean isReservedCharacter(char ch) {
- return CHARACTERS_TO_ESCAPE.indexOf(ch) != -1;
- }
-
- public boolean match(String uri, MultivaluedMap<String, String> templateVariableToValue) {
-
- if (uri == null) {
- return (templateRegexPattern == null) ? true : false;
- }
-
- if (templateRegexPattern == null) {
- return false;
- }
-
- Matcher m = templateRegexPattern.matcher(uri);
- if (!m.matches() || template.equals(SLASH) && uri.startsWith(SLASH_QUOTE)) {
- if (uri.contains(";")) {
- // we might be trying to match one or few path segments
- // containing matrix
- // parameters against a clear path segment as in @Path("base").
- List<PathSegment> pList = JAXRSUtils.getPathSegments(template, false);
- List<PathSegment> uList = JAXRSUtils.getPathSegments(uri, false);
- StringBuilder sb = new StringBuilder();
- for (int i = 0; i < uList.size(); i++) {
- final String segment;
- if (pList.size() > i && pList.get(i).getPath().indexOf('{') == -1) {
- segment = uList.get(i).getPath();
- } else {
- segment = HttpUtils.fromPathSegment(uList.get(i));
- }
- if (!segment.isEmpty()) {
- sb.append(SLASH);
- }
- sb.append(segment);
- }
- uri = sb.toString();
- if (uri.isEmpty()) {
- uri = SLASH;
- }
- m = templateRegexPattern.matcher(uri);
- if (!m.matches()) {
- return false;
- }
- } else {
- return false;
- }
- }
-
- // Assign the matched template values to template variables
- int groupCount = m.groupCount();
-
- int i = 1;
- for (String name : variables) {
- while (i <= groupCount) {
- String value = m.group(i++);
- if ((value == null || value.length() == 0 && i < groupCount)
- && variables.size() + 1 < groupCount) {
- continue;
- }
- templateVariableToValue.add(name, value);
- break;
- }
- }
- // The right hand side value, might be used to further resolve
- // sub-resources.
-
- String finalGroup = i > groupCount ? SLASH : m.group(groupCount);
- if (finalGroup == null || finalGroup.startsWith(SLASH_QUOTE)) {
- finalGroup = SLASH;
- }
-
- templateVariableToValue.putSingle(FINAL_MATCH_GROUP, finalGroup);
-
- return true;
- }
-
- /**
- * Substitutes template variables with listed values. List of values is counterpart for
- * {@link #getVariables() list of variables}. When list of value is shorter than variables substitution
- * is partial. When variable has pattern, value must fit to pattern, otherwise
- * {@link IllegalArgumentException} is thrown.
- * <p>
- * Example1: for template "/{a}/{b}/{a}" {@link #getVariables()} returns "[a, b, a]"; providing here list
- * of value "[foo, bar, baz]" results with "/foo/bar/baz".
- * <p>
- * Example2: for template "/{a}/{b}/{a}" providing list of values "[foo]" results with "/foo/{b}/{a}".
- *
- * @param values values for variables
- * @return template with bound variables.
- * @throws IllegalArgumentException when values is null, any value does not match pattern etc.
- */
- public String substitute(List<String> values) throws IllegalArgumentException {
- if (values == null) {
- throw new IllegalArgumentException("values is null");
- }
- Iterator<String> iter = values.iterator();
- StringBuilder sb = new StringBuilder();
- for (UriChunk chunk : uriChunks) {
- if (chunk instanceof Variable) {
- Variable var = (Variable)chunk;
- if (iter.hasNext()) {
- String value = iter.next();
- if (!var.matches(value)) {
- throw new IllegalArgumentException("Value '" + value + "' does not match variable "
- + var.getName() + " with pattern "
- + var.getPattern());
- }
- sb.append(value);
- } else {
- sb.append(var);
- }
- } else {
- sb.append(chunk);
- }
- }
- return sb.toString();
- }
-
- String substitute(Map<String, ? extends Object> valuesMap) throws IllegalArgumentException {
- return this.substitute(valuesMap, Collections.<String>emptySet(), false);
- }
-
- /**
- * Substitutes template variables with mapped values. Variables are mapped to values; if not all variables
- * are bound result will still contain variables. Note that all variables with the same name are replaced
- * by one value.
- * <p>
- * Example: for template "/{a}/{b}/{a}" {@link #getVariables()} returns "[a, b, a]"; providing here
- * mapping "[a: foo, b: bar]" results with "/foo/bar/foo" (full substitution) and for mapping "[b: baz]"
- * result is "{a}/baz/{a}" (partial substitution).
- *
- * @param valuesMap map variables to their values; on each value Object.toString() is called.
- * @return template with bound variables.
- */
- public String substitute(Map<String, ? extends Object> valuesMap,
- Set<String> encodePathSlashVars,
- boolean allowUnresolved) throws IllegalArgumentException {
- if (valuesMap == null) {
- throw new IllegalArgumentException("valuesMap is null");
- }
- StringBuilder sb = new StringBuilder();
- for (UriChunk chunk : uriChunks) {
- if (chunk instanceof Variable) {
- Variable var = (Variable)chunk;
- Object value = valuesMap.get(var.getName());
- if (value != null) {
- String sval = value.toString();
- if (!var.matches(sval)) {
- throw new IllegalArgumentException("Value '" + sval + "' does not match variable "
- + var.getName() + " with pattern "
- + var.getPattern());
- }
- if (encodePathSlashVars.contains(var.getName())) {
- sval = sval.replaceAll("/", "%2F");
- }
- sb.append(sval);
- } else if (allowUnresolved) {
- sb.append(chunk);
- } else {
- throw new IllegalArgumentException("Template variable " + var.getName()
- + " has no matching value");
- }
- } else {
- sb.append(chunk);
- }
- }
- return sb.toString();
- }
-
- /**
- * Encoded literal characters surrounding template variables,
- * ex. "a {id} b" will be encoded to "a%20{id}%20b"
- * @return encoded value
- */
- public String encodeLiteralCharacters(boolean isQuery) {
- final float encodedRatio = 1.5f;
- StringBuilder sb = new StringBuilder((int)(encodedRatio * template.length()));
- for (UriChunk chunk : uriChunks) {
- String val = chunk.getValue();
- if (chunk instanceof Literal) {
- sb.append(HttpUtils.encodePartiallyEncoded(val, isQuery));
- } else {
- sb.append(val);
- }
- }
- return sb.toString();
- }
-
- public static URITemplate createTemplate(Path path) {
-
- return createTemplate(path == null ? null : path.value());
- }
-
- public static URITemplate createTemplate(String pathValue) {
- if (pathValue == null) {
- pathValue = "/";
- } else if (!pathValue.startsWith("/")) {
- pathValue = "/" + pathValue;
- }
- return createExactTemplate(pathValue);
- }
-
- public static URITemplate createExactTemplate(String pathValue) {
- URITemplate template = URI_TEMPLATE_CACHE.get(pathValue);
- if (template == null) {
- template = new URITemplate(pathValue);
- if (URI_TEMPLATE_CACHE.size() >= MAX_URI_TEMPLATE_CACHE_SIZE) {
- URI_TEMPLATE_CACHE.clear();
- }
- URI_TEMPLATE_CACHE.put(pathValue, template);
- }
- return template;
- }
-
- public static int compareTemplates(URITemplate t1, URITemplate t2) {
- int l1 = t1.getLiteralChars().length();
- int l2 = t2.getLiteralChars().length();
- // descending order
- int result = l1 < l2 ? 1 : l1 > l2 ? -1 : 0;
- if (result == 0) {
- int g1 = t1.getVariables().size();
- int g2 = t2.getVariables().size();
- // descending order
- result = g1 < g2 ? 1 : g1 > g2 ? -1 : 0;
- if (result == 0) {
- int gCustom1 = t1.getCustomVariables().size();
- int gCustom2 = t2.getCustomVariables().size();
- result = gCustom1 < gCustom2 ? 1 : gCustom1 > gCustom2 ? -1 : 0;
- if (result == 0) {
- result = t1.getPatternValue().compareTo(t2.getPatternValue());
- }
- }
- }
-
- return result;
- }
-
- /**
- * Stringified part of URI. Chunk is not URI segment; chunk can span over multiple URI segments or one URI
- * segments can have multiple chunks. Chunk is used to decompose URI of {@link URITemplate} into literals
- * and variables. Example: "foo/bar/{baz}{blah}" is decomposed into chunks: "foo/bar", "{baz}" and
- * "{blah}".
- */
- private abstract static class UriChunk {
- /**
- * Creates object form string.
- *
- * @param uriChunk stringified uri chunk
- * @return If param has variable form then {@link Variable} instance is created, otherwise chunk is
- * treated as {@link Literal}.
- */
- public static UriChunk createUriChunk(String uriChunk) {
- if (uriChunk == null || "".equals(uriChunk)) {
- throw new IllegalArgumentException("uriChunk is empty");
- }
- UriChunk uriChunkRepresentation = Variable.create(uriChunk);
- if (uriChunkRepresentation == null) {
- uriChunkRepresentation = Literal.create(uriChunk);
- }
- return uriChunkRepresentation;
- }
-
- public abstract String getValue();
-
- @Override
- public String toString() {
- return getValue();
- }
- }
-
- private static final class Literal extends UriChunk {
- private String value;
-
- private Literal() {
- // empty constructor
- }
-
- public static Literal create(String uriChunk) {
- if (uriChunk == null || "".equals(uriChunk)) {
- throw new IllegalArgumentException("uriChunk is empty");
- }
- Literal literal = new Literal();
- literal.value = uriChunk;
- return literal;
- }
-
- @Override
- public String getValue() {
- return value;
- }
-
- }
-
- /**
- * Variable of URITemplate. Variable has either "{varname:pattern}" syntax or "{varname}".
- */
- private static final class Variable extends UriChunk {
- private static final Pattern VARIABLE_PATTERN = Pattern.compile("(\\w[-\\w\\.]*[ ]*)(\\:(.+))?");
- private String name;
- private Pattern pattern;
-
- private Variable() {
- // empty constructor
- }
-
- /**
- * Creates variable from stringified part of URI.
- *
- * @param uriChunk uriChunk chunk that depicts variable
- * @return Variable if variable was successfully created; null if uriChunk was not a variable
- */
- public static Variable create(String uriChunk) {
- Variable newVariable = new Variable();
- if (uriChunk == null || "".equals(uriChunk)) {
- return null;
- }
- if (CurlyBraceTokenizer.insideBraces(uriChunk)) {
- uriChunk = CurlyBraceTokenizer.stripBraces(uriChunk).trim();
- Matcher matcher = VARIABLE_PATTERN.matcher(uriChunk);
- if (matcher.matches()) {
- newVariable.name = matcher.group(1).trim();
- if (matcher.group(2) != null && matcher.group(3) != null) {
- String patternExpression = matcher.group(3).trim();
- newVariable.pattern = Pattern.compile(patternExpression);
- }
- return newVariable;
- }
- }
- return null;
- }
-
- public String getName() {
- return name;
- }
-
- public String getPattern() {
- return pattern != null ? pattern.pattern() : null;
- }
-
- /**
- * Checks whether value matches variable. If variable has pattern its checked against, otherwise true
- * is returned.
- *
- * @param value value of variable
- * @return true if value is valid for variable, false otherwise.
- */
- public boolean matches(String value) {
- if (pattern == null) {
- return true;
- }
- return pattern.matcher(value).matches();
- }
-
- @Override
- public String getValue() {
- if (pattern != null) {
- return "{" + name + ":" + pattern + "}";
- }
- return "{" + name + "}";
- }
- }
-
- /**
- * Splits string into parts inside and outside curly braces. Nested curly braces are ignored and treated
- * as part inside top-level curly braces. Example: string "foo{bar{baz}}blah" is split into three tokens,
- * "foo","{bar{baz}}" and "blah". When closed bracket is missing, whole unclosed part is returned as one
- * token, e.g.: "foo{bar" is split into "foo" and "{bar". When opening bracket is missing, closing
- * bracket is ignored and taken as part of current token e.g.: "foo{bar}baz}blah" is split into "foo",
- * "{bar}" and "baz}blah".
- * <p>
- * This is helper class for {@link URITemplate} that enables recurring literals appearing next to regular
- * expressions e.g. "/foo/{zipcode:[0-9]{5}}/". Nested expressions with closed sections, like open-closed
- * brackets causes expression to be out of regular grammar (is context-free grammar) which are not
- * supported by Java regexp version.
- */
- static class CurlyBraceTokenizer {
-
- private List<String> tokens = new ArrayList<>();
- private int tokenIdx;
-
- CurlyBraceTokenizer(String string) {
- boolean outside = true;
- int level = 0;
- int lastIdx = 0;
- int idx;
- for (idx = 0; idx < string.length(); idx++) {
- if (string.charAt(idx) == '{') {
- if (outside) {
- if (lastIdx < idx) {
- tokens.add(string.substring(lastIdx, idx));
- }
- lastIdx = idx;
- outside = false;
- } else {
- level++;
- }
- } else if (string.charAt(idx) == '}' && !outside) {
- if (level > 0) {
- level--;
- } else {
- if (lastIdx < idx) {
- tokens.add(string.substring(lastIdx, idx + 1));
- }
- lastIdx = idx + 1;
- outside = true;
- }
- }
- }
- if (lastIdx < idx) {
- tokens.add(string.substring(lastIdx, idx));
- }
- }
-
- /**
- * Token is enclosed by curly braces.
- *
- * @param token
- * text to verify
- * @return true if enclosed, false otherwise.
- */
- public static boolean insideBraces(String token) {
- return token.charAt(0) == '{' && token.charAt(token.length() - 1) == '}';
- }
-
- /**
- * Strips token from enclosed curly braces. If token is not enclosed method
- * has no side effect.
- *
- * @param token
- * text to verify
- * @return text stripped from curly brace begin-end pair.
- */
- public static String stripBraces(String token) {
- if (insideBraces(token)) {
- return token.substring(1, token.length() - 1);
- }
- return token;
- }
-
- public boolean hasNext() {
- return tokens.size() > tokenIdx;
- }
-
- public String next() {
- if (hasNext()) {
- return tokens.get(tokenIdx++);
- }
- throw new IllegalStateException("no more elements");
- }
- }
-}
-
-
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxrs/provider/CachingMessageBodyReader.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxrs/provider/CachingMessageBodyReader.java
deleted file mode 100644
index ecdc8f1..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxrs/provider/CachingMessageBodyReader.java
+++ /dev/null
@@ -1,100 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.cxf.jaxrs.provider;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Type;
-import java.util.Collections;
-import java.util.List;
-
-import javax.ws.rs.WebApplicationException;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.MultivaluedMap;
-import javax.ws.rs.ext.MessageBodyReader;
-import javax.ws.rs.ext.Provider;
-
-import org.apache.cxf.jaxrs.utils.ExceptionUtils;
-
-@Provider
-public class CachingMessageBodyReader<T> extends AbstractCachingMessageProvider<T>
- implements MessageBodyReader<T> {
-
- private List<MessageBodyReader<T>> delegatingReaders;
-
- public boolean isReadable(Class<?> type, Type gType, Annotation[] anns, MediaType mt) {
- if (delegatingReaders != null) {
- return getDelegatingReader(type, gType, anns, mt) != null;
- }
- return isProviderKeyNotSet();
- }
-
- private MessageBodyReader<T> getDelegatingReader(Class<?> type, Type gType, Annotation[] anns, MediaType mt) {
- for (MessageBodyReader<T> reader: delegatingReaders) {
- if (reader.isReadable(type, gType, anns, mt)) {
- return reader;
- }
- }
- return null;
- }
-
- public T readFrom(Class<T> type, Type gType, Annotation[] anns, MediaType mt,
- MultivaluedMap<String, String> theheaders, InputStream is)
- throws IOException, WebApplicationException {
- this.setObject(
- getReader(type, gType, anns, mt).readFrom(type, gType, anns, mt, theheaders, is));
- return getObject();
- }
-
-
- protected MessageBodyReader<T> getReader(Class<?> type, Type gType, Annotation[] anns, MediaType mt) {
- if (delegatingReaders != null) {
- return getDelegatingReader(type, gType, anns, mt);
- }
- final MessageBodyReader<T> r;
-
- mc.put(ACTIVE_JAXRS_PROVIDER_KEY, this);
- try {
- @SuppressWarnings("unchecked")
- Class<T> actualType = (Class<T>)type;
- r = mc.getProviders().getMessageBodyReader(actualType, gType, anns, mt);
- } finally {
- mc.put(ACTIVE_JAXRS_PROVIDER_KEY, null);
- }
-
- if (r == null) {
- org.apache.cxf.common.i18n.Message message =
- new org.apache.cxf.common.i18n.Message("NO_MSG_READER", BUNDLE, type);
- LOG.severe(message.toString());
- throw ExceptionUtils.toNotAcceptableException(null, null);
- }
- return r;
- }
-
- public void setDelegatingReader(MessageBodyReader<T> reader) {
- this.delegatingReaders = Collections.singletonList(reader);
- }
-
- public void setDelegatingReaders(List<MessageBodyReader<T>> readers) {
- this.delegatingReaders = readers;
- }
-
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxrs/provider/CachingMessageBodyWriter.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxrs/provider/CachingMessageBodyWriter.java
deleted file mode 100644
index 21eab42..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxrs/provider/CachingMessageBodyWriter.java
+++ /dev/null
@@ -1,102 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.cxf.jaxrs.provider;
-
-import java.io.IOException;
-import java.io.OutputStream;
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Type;
-import java.util.Collections;
-import java.util.List;
-
-import javax.ws.rs.WebApplicationException;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.MultivaluedMap;
-import javax.ws.rs.ext.MessageBodyWriter;
-import javax.ws.rs.ext.Provider;
-
-import org.apache.cxf.jaxrs.utils.ExceptionUtils;
-
-@Provider
-public class CachingMessageBodyWriter<T> extends AbstractCachingMessageProvider<T>
- implements MessageBodyWriter<T> {
-
- private List<MessageBodyWriter<T>> delegatingWriters;
-
- public long getSize(T t, Class<?> type, Type gType, Annotation[] anns, MediaType mediaType) {
- return -1;
- }
-
- public boolean isWriteable(Class<?> type, Type gType, Annotation[] anns, MediaType mt) {
- if (delegatingWriters != null) {
- return getDelegatingWriter(type, gType, anns, mt) != null;
- }
- return isProviderKeyNotSet();
- }
-
- private MessageBodyWriter<T> getDelegatingWriter(Class<?> type, Type gType, Annotation[] anns, MediaType mt) {
- for (MessageBodyWriter<T> writer: delegatingWriters) {
- if (writer.isWriteable(type, gType, anns, mt)) {
- return writer;
- }
- }
- return null;
- }
-
- public void writeTo(T obj, Class<?> type, Type gType, Annotation[] anns, MediaType mt,
- MultivaluedMap<String, Object> theheaders, OutputStream os)
- throws IOException, WebApplicationException {
- this.setObject(obj);
- getWriter(type, gType, anns, mt).writeTo(getObject(), type, gType, anns, mt, theheaders, os);
- }
-
-
- protected MessageBodyWriter<T> getWriter(Class<?> type, Type gType, Annotation[] anns, MediaType mt) {
- if (delegatingWriters != null) {
- return getDelegatingWriter(type, gType, anns, mt);
- }
- MessageBodyWriter<T> w;
-
- mc.put(ACTIVE_JAXRS_PROVIDER_KEY, this);
- try {
- @SuppressWarnings("unchecked")
- Class<T> actualType = (Class<T>)type;
- w = mc.getProviders().getMessageBodyWriter(actualType, gType, anns, mt);
- } finally {
- mc.put(ACTIVE_JAXRS_PROVIDER_KEY, null);
- }
-
- if (w == null) {
- org.apache.cxf.common.i18n.Message message =
- new org.apache.cxf.common.i18n.Message("NO_MSG_WRITER", BUNDLE, type);
- LOG.severe(message.toString());
- throw ExceptionUtils.toInternalServerErrorException(null, null);
- }
- return w;
- }
-
- public void setDelegatingWriter(MessageBodyWriter<T> writer) {
- this.delegatingWriters = Collections.singletonList(writer);
- }
-
- public void setDelegatingWriters(List<MessageBodyWriter<T>> writers) {
- this.delegatingWriters = writers;
- }
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxrs/provider/DataSourceProvider.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxrs/provider/DataSourceProvider.java
deleted file mode 100644
index efecac4..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxrs/provider/DataSourceProvider.java
+++ /dev/null
@@ -1,110 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.cxf.jaxrs.provider;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Type;
-import java.util.logging.Logger;
-
-import javax.activation.DataHandler;
-import javax.activation.DataSource;
-import javax.activation.FileDataSource;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.MultivaluedMap;
-import javax.ws.rs.ext.MessageBodyReader;
-import javax.ws.rs.ext.MessageBodyWriter;
-import javax.ws.rs.ext.Provider;
-
-import org.apache.cxf.common.logging.LogUtils;
-import org.apache.cxf.common.util.StringUtils;
-import org.apache.cxf.helpers.IOUtils;
-import org.apache.cxf.jaxrs.ext.multipart.InputStreamDataSource;
-import org.apache.cxf.jaxrs.utils.ExceptionUtils;
-import org.apache.cxf.jaxrs.utils.JAXRSUtils;
-
-@Provider
-public class DataSourceProvider<T> implements MessageBodyReader<T>, MessageBodyWriter<T> {
- protected static final Logger LOG = LogUtils.getL7dLogger(DataSourceProvider.class);
- private boolean useDataSourceContentType;
-
- public boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mt) {
- return isSupported(type);
- }
-
- public T readFrom(Class<T> cls, Type genericType, Annotation[] annotations,
- MediaType type,
- MultivaluedMap<String, String> headers, InputStream is)
- throws IOException {
-
- final DataSource ds;
- if (cls == FileDataSource.class) {
- File file = new BinaryDataProvider<File>().readFrom(File.class, File.class, annotations, type, headers, is);
- ds = new FileDataSource(file);
- } else if (cls == DataSource.class || cls == DataHandler.class) {
- ds = new InputStreamDataSource(is, type.toString());
- } else {
- LOG.warning("Unsupported DataSource class: " + cls.getName());
- throw ExceptionUtils.toWebApplicationException(null, null);
- }
- return cls.cast(DataSource.class.isAssignableFrom(cls) ? ds : new DataHandler(ds));
- }
-
- public long getSize(T t, Class<?> type, Type genericType, Annotation[] annotations,
- MediaType mt) {
- return -1;
- }
-
- public boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mt) {
- return isSupported(type);
- }
-
- private static boolean isSupported(Class<?> type) {
- return DataSource.class.isAssignableFrom(type) || DataHandler.class.isAssignableFrom(type);
- }
-
- public void writeTo(T src, Class<?> cls, Type genericType, Annotation[] annotations,
- MediaType type, MultivaluedMap<String, Object> headers, OutputStream os)
- throws IOException {
- DataSource ds = DataSource.class.isAssignableFrom(cls)
- ? (DataSource)src : ((DataHandler)src).getDataSource();
- if (useDataSourceContentType) {
- setContentTypeIfNeeded(type, headers, ds.getContentType());
- }
- IOUtils.copyAndCloseInput(ds.getInputStream(), os);
- }
-
- private void setContentTypeIfNeeded(MediaType type,
- MultivaluedMap<String, Object> headers, String ct) {
-
- if (!StringUtils.isEmpty(ct) && !type.equals(JAXRSUtils.toMediaType(ct))) {
- headers.putSingle("Content-Type", ct);
- }
- }
-
- public void setUseDataSourceContentType(boolean useDataSourceContentType) {
- this.useDataSourceContentType = useDataSourceContentType;
- }
-
-
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxrs/provider/FormEncodingProvider.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxrs/provider/FormEncodingProvider.java
deleted file mode 100644
index 0344592..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxrs/provider/FormEncodingProvider.java
+++ /dev/null
@@ -1,228 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.cxf.jaxrs.provider;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Type;
-import java.nio.charset.StandardCharsets;
-
-import javax.ws.rs.Consumes;
-import javax.ws.rs.Encoded;
-import javax.ws.rs.Produces;
-import javax.ws.rs.WebApplicationException;
-import javax.ws.rs.core.Context;
-import javax.ws.rs.core.Form;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.MultivaluedMap;
-import javax.ws.rs.ext.MessageBodyReader;
-import javax.ws.rs.ext.MessageBodyWriter;
-import javax.ws.rs.ext.Provider;
-
-import org.apache.cxf.jaxrs.ext.MessageContext;
-import org.apache.cxf.jaxrs.ext.multipart.Attachment;
-import org.apache.cxf.jaxrs.ext.multipart.MultipartBody;
-import org.apache.cxf.jaxrs.impl.MetadataMap;
-import org.apache.cxf.jaxrs.utils.AnnotationUtils;
-import org.apache.cxf.jaxrs.utils.ExceptionUtils;
-import org.apache.cxf.jaxrs.utils.FormUtils;
-import org.apache.cxf.jaxrs.utils.HttpUtils;
-import org.apache.cxf.jaxrs.utils.multipart.AttachmentUtils;
-import org.apache.cxf.message.Message;
-import org.apache.cxf.phase.PhaseInterceptorChain;
-
-@Produces({"application/x-www-form-urlencoded", "multipart/form-data" })
-@Consumes({"application/x-www-form-urlencoded", "multipart/form-data" })
-@Provider
-public class FormEncodingProvider<T> extends AbstractConfigurableProvider
- implements MessageBodyReader<T>, MessageBodyWriter<T> {
-
- private FormValidator validator;
- @Context private MessageContext mc;
- private String attachmentDir;
- private String attachmentThreshold;
- private String attachmentMaxSize;
-
- private boolean expectEncoded;
-
- public FormEncodingProvider() {
-
- }
-
- public FormEncodingProvider(boolean expectEncoded) {
- this.expectEncoded = expectEncoded;
- }
-
- public void setExpectedEncoded(boolean expect) {
- this.expectEncoded = expect;
- }
-
- public void setAttachmentDirectory(String dir) {
- attachmentDir = dir;
- }
-
- public void setAttachmentThreshold(String threshold) {
- attachmentThreshold = threshold;
- }
-
- public void setAttachmentMaxSize(String maxSize) {
- attachmentMaxSize = maxSize;
- }
-
- public void setValidator(FormValidator formValidator) {
- validator = formValidator;
- }
-
- public boolean isReadable(Class<?> type, Type genericType,
- Annotation[] annotations, MediaType mt) {
- return isSupported(type, mt);
- }
-
- public T readFrom(
- Class<T> clazz, Type genericType, Annotation[] annotations, MediaType mt,
- MultivaluedMap<String, String> headers, InputStream is)
- throws IOException {
- if (is == null) {
- return null;
- }
- try {
- if (mt.isCompatible(MediaType.MULTIPART_FORM_DATA_TYPE)) {
- MultipartBody body = AttachmentUtils.getMultipartBody(mc);
- if (MultipartBody.class.isAssignableFrom(clazz)) {
- return clazz.cast(body);
- } else if (Attachment.class.isAssignableFrom(clazz)) {
- return clazz.cast(body.getRootAttachment());
- }
- }
-
- MultivaluedMap<String, String> params = createMap(clazz);
- populateMap(params, annotations, is, mt, !keepEncoded(annotations));
- validateMap(params);
-
- persistParamsOnMessage(params);
-
- return getFormObject(clazz, params);
- } catch (WebApplicationException e) {
- throw e;
- } catch (Exception e) {
- throw ExceptionUtils.toBadRequestException(e, null);
- }
- }
-
- protected boolean keepEncoded(Annotation[] anns) {
- return AnnotationUtils.getAnnotation(anns, Encoded.class) != null
- || expectEncoded;
- }
-
- protected void persistParamsOnMessage(MultivaluedMap<String, String> params) {
- Message message = PhaseInterceptorChain.getCurrentMessage();
- if (message != null) {
- message.put(FormUtils.FORM_PARAM_MAP, params);
- }
- }
-
- @SuppressWarnings("unchecked")
- protected MultivaluedMap<String, String> createMap(Class<?> clazz) throws Exception {
- if (clazz == MultivaluedMap.class || clazz == Form.class) {
- return new MetadataMap<String, String>();
- }
- return (MultivaluedMap<String, String>)clazz.newInstance();
- }
-
- private T getFormObject(Class<T> clazz, MultivaluedMap<String, String> params) {
- return clazz.cast(Form.class.isAssignableFrom(clazz) ? new Form(params) : params);
- }
-
- /**
- * Retrieve map of parameters from the passed in message
- */
- protected void populateMap(MultivaluedMap<String, String> params,
- Annotation[] anns,
- InputStream is,
- MediaType mt,
- boolean decode) {
- if (mt.isCompatible(MediaType.MULTIPART_FORM_DATA_TYPE)) {
- MultipartBody body =
- AttachmentUtils.getMultipartBody(mc, attachmentDir, attachmentThreshold, attachmentMaxSize);
- FormUtils.populateMapFromMultipart(params, body, PhaseInterceptorChain.getCurrentMessage(),
- decode);
- } else {
- String enc = HttpUtils.getEncoding(mt, StandardCharsets.UTF_8.name());
-
- Object servletRequest = mc != null ? mc.getHttpServletRequest() : null;
- if (servletRequest == null) {
- FormUtils.populateMapFromString(params,
- PhaseInterceptorChain.getCurrentMessage(),
- FormUtils.readBody(is, enc),
- enc,
- decode);
- } else {
- FormUtils.populateMapFromString(params,
- PhaseInterceptorChain.getCurrentMessage(),
- FormUtils.readBody(is, enc),
- enc,
- decode,
- (javax.servlet.http.HttpServletRequest)servletRequest);
- }
- }
- }
-
- protected void validateMap(MultivaluedMap<String, String> params) {
- if (validator != null) {
- validator.validate(params);
- }
- }
-
- public long getSize(T t, Class<?> type,
- Type genericType, Annotation[] annotations,
- MediaType mediaType) {
- return -1;
- }
-
- public boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations,
- MediaType mt) {
- return isSupported(type, mt);
- }
-
- private static boolean isSupported(Class<?> type, MediaType mt) {
- return (MultivaluedMap.class.isAssignableFrom(type) || Form.class.isAssignableFrom(type))
- || ("multipart".equalsIgnoreCase(mt.getType())
- && mt.isCompatible(MediaType.MULTIPART_FORM_DATA_TYPE)
- && (MultivaluedMap.class.isAssignableFrom(type) || Form.class.isAssignableFrom(type)));
- }
-
- @SuppressWarnings("unchecked")
- public void writeTo(T obj, Class<?> c, Type t, Annotation[] anns,
- MediaType mt, MultivaluedMap<String, Object> headers, OutputStream os)
- throws IOException, WebApplicationException {
-
- MultivaluedMap<String, String> map =
- (MultivaluedMap<String, String>)(obj instanceof Form ? ((Form)obj).asMap() : obj);
- boolean encoded = keepEncoded(anns);
-
- String enc = HttpUtils.getSetEncoding(mt, headers, StandardCharsets.UTF_8.name());
-
- FormUtils.writeMapToOutputStream(map, os, enc, encoded);
-
- }
-
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java
deleted file mode 100644
index ab27e02..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java
+++ /dev/null
@@ -1,635 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.cxf.jaxrs.provider;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.io.Reader;
-import java.io.Writer;
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Type;
-import java.nio.charset.StandardCharsets;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-
-import javax.ws.rs.Consumes;
-import javax.ws.rs.Produces;
-import javax.ws.rs.WebApplicationException;
-import javax.ws.rs.core.Context;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.MultivaluedMap;
-import javax.ws.rs.core.Response;
-import javax.ws.rs.core.UriBuilder;
-import javax.ws.rs.ext.Provider;
-import javax.xml.bind.JAXBElement;
-import javax.xml.bind.JAXBException;
-import javax.xml.bind.Marshaller;
-import javax.xml.bind.Unmarshaller;
-import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
-import javax.xml.namespace.QName;
-import javax.xml.stream.XMLInputFactory;
-import javax.xml.stream.XMLOutputFactory;
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamReader;
-import javax.xml.stream.XMLStreamWriter;
-import javax.xml.transform.Source;
-
-import org.w3c.dom.Document;
-
-import org.apache.cxf.helpers.CastUtils;
-import org.apache.cxf.helpers.IOUtils;
-import org.apache.cxf.jaxrs.ext.MessageContext;
-import org.apache.cxf.jaxrs.ext.Nullable;
-import org.apache.cxf.jaxrs.ext.xml.XMLInstruction;
-import org.apache.cxf.jaxrs.ext.xml.XMLSource;
-import org.apache.cxf.jaxrs.ext.xml.XSISchemaLocation;
-import org.apache.cxf.jaxrs.ext.xml.XSLTTransform;
-import org.apache.cxf.jaxrs.utils.AnnotationUtils;
-import org.apache.cxf.jaxrs.utils.ExceptionUtils;
-import org.apache.cxf.jaxrs.utils.HttpUtils;
-import org.apache.cxf.jaxrs.utils.InjectionUtils;
-import org.apache.cxf.jaxrs.utils.JAXBUtils;
-import org.apache.cxf.jaxrs.utils.JAXRSUtils;
-import org.apache.cxf.message.Attachment;
-import org.apache.cxf.message.Message;
-import org.apache.cxf.staxutils.DepthExceededStaxException;
-import org.apache.cxf.staxutils.StaxUtils;
-import org.apache.cxf.staxutils.transform.TransformUtils;
-
-@Produces({"application/xml", "application/*+xml", "text/xml" })
-@Consumes({"application/xml", "application/*+xml", "text/xml" })
-@Provider
-public class JAXBElementProvider<T> extends AbstractJAXBProvider<T> {
- private static final String XML_PI_START = "<?xml version=\"1.0\" encoding=\"";
- private static final String XML_PI_PROPERTY_RI = "com.sun.xml.bind.xmlHeaders";
- private static final String XML_PI_PROPERTY_RI_INT = "com.sun.xml.internal.bind.xmlHeaders";
-
- private static final String[] MARSHALLER_PROPERTIES = {
- Marshaller.JAXB_ENCODING,
- Marshaller.JAXB_FORMATTED_OUTPUT,
- Marshaller.JAXB_FRAGMENT,
- Marshaller.JAXB_NO_NAMESPACE_SCHEMA_LOCATION,
- Marshaller.JAXB_SCHEMA_LOCATION,
- NS_MAPPER_PROPERTY_RI,
- NS_MAPPER_PROPERTY_RI_INT,
- XML_PI_PROPERTY_RI,
- XML_PI_PROPERTY_RI_INT
- };
-
- private Map<String, Object> mProperties = Collections.emptyMap();
- private Map<String, String> nsPrefixes = Collections.emptyMap();
- private String xmlResourceOffset = "";
- private String xmlPiPropertyName;
-
- public JAXBElementProvider() {
-
- }
-
- protected boolean objectFactoryOrIndexAvailable(Class<?> type) {
- return !Document.class.isAssignableFrom(type) && super.objectFactoryOrIndexAvailable(type);
- }
-
- public void setXmlResourceOffset(String value) {
- xmlResourceOffset = value;
- }
-
- public void setNamespacePrefixes(Map<String, String> prefixes) {
- nsPrefixes = prefixes;
- }
-
- protected void setXmlPiProperty(Marshaller ms, String value) throws Exception {
- if (xmlPiPropertyName != null) {
- setMarshallerProp(ms, value, xmlPiPropertyName, null);
- } else {
- setMarshallerProp(ms, value, XML_PI_PROPERTY_RI, XML_PI_PROPERTY_RI_INT);
- }
- }
-
- @Override
- protected boolean canBeReadAsJaxbElement(Class<?> type) {
- return super.canBeReadAsJaxbElement(type)
- && type != XMLSource.class && !Source.class.isAssignableFrom(type);
- }
-
- @Context
- public void setMessageContext(MessageContext mc) {
- super.setContext(mc);
- }
-
- public void setMarshallerProperties(Map<String, Object> marshallProperties) {
- mProperties = marshallProperties;
- }
-
- public void setSchemaLocation(String schemaLocation) {
- mProperties.put(Marshaller.JAXB_SCHEMA_LOCATION, schemaLocation);
- }
-
- public T readFrom(Class<T> type, Type genericType, Annotation[] anns, MediaType mt,
- MultivaluedMap<String, String> headers, InputStream is)
- throws IOException {
- if (isPayloadEmpty(headers)) {
- if (AnnotationUtils.getAnnotation(anns, Nullable.class) != null) {
- return null;
- }
- reportEmptyContentLength();
- }
-
- XMLStreamReader reader = null;
- Unmarshaller unmarshaller = null;
- try {
-
- boolean isCollection = InjectionUtils.isSupportedCollectionOrArray(type);
- Class<?> theGenericType = isCollection ? InjectionUtils.getActualType(genericType) : type;
- Class<?> theType = getActualType(theGenericType, genericType, anns);
-
- unmarshaller = createUnmarshaller(theType, genericType, isCollection);
- addAttachmentUnmarshaller(unmarshaller);
- Object response = null;
- if (JAXBElement.class.isAssignableFrom(type)
- || !isCollection && (unmarshalAsJaxbElement
- || jaxbElementClassMap != null && jaxbElementClassMap.containsKey(theType.getName()))) {
- try (InputStream in = IOUtils.nullOrNotEmptyStream(is)) {
- // The return value might be "null" in case of empty stream, in this
- // case the unmarshaller fails with javax.xml.bind.UnmarshalException instead
- // of returning empty response.
- if (in != null) {
- reader = getStreamReader(in, type, mt);
- reader = TransformUtils.createNewReaderIfNeeded(reader, in);
-
- if (JAXBElement.class.isAssignableFrom(type) && type == theType) {
- response = unmarshaller.unmarshal(reader);
- } else {
- response = unmarshaller.unmarshal(reader, theType);
- }
- }
- }
- } else {
- response = doUnmarshal(unmarshaller, type, is, anns, mt);
- }
-
- if (response instanceof JAXBElement && !JAXBElement.class.isAssignableFrom(type)) {
- response = ((JAXBElement<?>)response).getValue();
- }
- if (isCollection) {
- response = ((CollectionWrapper)response).getCollectionOrArray(
- unmarshaller, theType, type, genericType,
- org.apache.cxf.jaxrs.utils.JAXBUtils.getAdapter(theGenericType, anns));
- } else {
- response = checkAdapter(response, type, anns, false);
- }
- return type.cast(response);
-
- } catch (JAXBException e) {
- handleJAXBException(e, true);
- } catch (DepthExceededStaxException e) {
- throw ExceptionUtils.toWebApplicationException(null, JAXRSUtils.toResponse(413));
- } catch (WebApplicationException e) {
- throw e;
- } catch (Exception e) {
- LOG.warning(ExceptionUtils.getStackTrace(e));
- throw ExceptionUtils.toBadRequestException(e, null);
- } finally {
- try {
- StaxUtils.close(reader);
- } catch (XMLStreamException e) {
- // Ignore
- }
- JAXBUtils.closeUnmarshaller(unmarshaller);
- }
- // unreachable
- return null;
- }
-
- protected Object doUnmarshal(Unmarshaller unmarshaller, Class<?> type, InputStream is,
- Annotation[] anns, MediaType mt)
- throws JAXBException {
- XMLStreamReader reader = getStreamReader(is, type, mt);
- if (reader != null) {
- try {
- return unmarshalFromReader(unmarshaller, reader, anns, mt);
- } catch (JAXBException e) {
- throw e;
- } finally {
- try {
- StaxUtils.close(reader);
- } catch (XMLStreamException e) {
- // Ignore
- }
- }
- }
- return unmarshalFromInputStream(unmarshaller, is, anns, mt);
- }
-
- protected XMLStreamReader getStreamReader(InputStream is, Class<?> type, MediaType mt) {
- MessageContext mc = getContext();
- XMLStreamReader reader = mc != null ? mc.getContent(XMLStreamReader.class) : null;
- if (reader == null && mc != null) {
- XMLInputFactory factory = (XMLInputFactory)mc.get(XMLInputFactory.class.getName());
- if (factory != null) {
- try {
- reader = factory.createXMLStreamReader(is);
- } catch (XMLStreamException e) {
- throw ExceptionUtils.toInternalServerErrorException(
- new RuntimeException("Can not create XMLStreamReader", e), null);
- }
- }
- }
-
- if (reader == null && is == null) {
- reader = getStreamHandlerFromCurrentMessage(XMLStreamReader.class);
- }
-
- reader = createTransformReaderIfNeeded(reader, is);
- reader = createDepthReaderIfNeeded(reader, is);
- if (InjectionUtils.isSupportedCollectionOrArray(type)) {
- return new JAXBCollectionWrapperReader(TransformUtils.createNewReaderIfNeeded(reader, is));
- }
- return reader;
-
- }
-
- protected Object unmarshalFromInputStream(Unmarshaller unmarshaller, InputStream is,
- Annotation[] anns, MediaType mt)
- throws JAXBException {
- // Try to create the read before unmarshalling the stream
- XMLStreamReader xmlReader = null;
- try {
- if (is == null) {
- Reader reader = getStreamHandlerFromCurrentMessage(Reader.class);
- if (reader == null) {
- LOG.severe("No InputStream, Reader, or XMLStreamReader is available");
- throw ExceptionUtils.toInternalServerErrorException(null, null);
- }
- xmlReader = StaxUtils.createXMLStreamReader(reader);
- } else {
- xmlReader = StaxUtils.createXMLStreamReader(is);
- }
- configureReaderRestrictions(xmlReader);
- return unmarshaller.unmarshal(xmlReader);
- } finally {
- try {
- StaxUtils.close(xmlReader);
- } catch (XMLStreamException e) {
- // Ignore
- }
- }
- }
-
- protected Object unmarshalFromReader(Unmarshaller unmarshaller, XMLStreamReader reader,
- Annotation[] anns, MediaType mt)
- throws JAXBException {
- return unmarshaller.unmarshal(reader);
- }
-
- public void writeTo(T obj, Class<?> cls, Type genericType, Annotation[] anns,
- MediaType m, MultivaluedMap<String, Object> headers, OutputStream os)
- throws IOException {
- try {
- String encoding = HttpUtils.getSetEncoding(m, headers, StandardCharsets.UTF_8.name());
- if (InjectionUtils.isSupportedCollectionOrArray(cls)) {
- marshalCollection(cls, obj, genericType, encoding, os, m, anns);
- } else {
- Object actualObject = checkAdapter(obj, cls, anns, true);
- Class<?> actualClass = obj != actualObject || cls.isInterface()
- ? actualObject.getClass() : cls;
- marshal(actualObject, actualClass, genericType, encoding, os, m, anns);
- }
- } catch (JAXBException e) {
- handleJAXBException(e, false);
- } catch (WebApplicationException e) {
- throw e;
- } catch (Exception e) {
- LOG.warning(ExceptionUtils.getStackTrace(e));
- throw ExceptionUtils.toInternalServerErrorException(e, null);
- }
- }
-
- protected void marshalCollection(Class<?> originalCls, Object collection,
- Type genericType, String enc, OutputStream os,
- MediaType m, Annotation[] anns)
- throws Exception {
-
- Class<?> actualClass = InjectionUtils.getActualType(genericType);
- actualClass = getActualType(actualClass, genericType, anns);
-
- Collection<?> c = originalCls.isArray() ? Arrays.asList((Object[]) collection)
- : (Collection<?>) collection;
-
- Iterator<?> it = c.iterator();
-
- Object firstObj = it.hasNext() ? it.next() : null;
-
- final QName qname;
- if (firstObj instanceof JAXBElement) {
- JAXBElement<?> el = (JAXBElement<?>)firstObj;
- qname = el.getName();
- actualClass = el.getDeclaredType();
- } else {
- qname = getCollectionWrapperQName(actualClass, genericType, firstObj, true);
- }
- if (qname == null) {
- String message = new org.apache.cxf.common.i18n.Message("NO_COLLECTION_ROOT",
- BUNDLE).toString();
- throw new WebApplicationException(Response.serverError()
- .entity(message).build());
- }
-
- os.write((XML_PI_START + (enc == null ? StandardCharsets.UTF_8.name() : enc) + "\"?>").getBytes());
-
- final String startTag;
- final String endTag;
- if (!qname.getNamespaceURI().isEmpty()) {
- String prefix = nsPrefixes.get(qname.getNamespaceURI());
- if (prefix == null) {
- prefix = "ns1";
- }
- startTag = "<" + prefix + ':' + qname.getLocalPart() + " xmlns:" + prefix + "=\""
- + qname.getNamespaceURI() + "\">";
- endTag = "</" + prefix + ':' + qname.getLocalPart() + ">";
- } else {
- startTag = "<" + qname.getLocalPart() + ">";
- endTag = "</" + qname.getLocalPart() + ">";
- }
- os.write(startTag.getBytes());
- if (firstObj != null) {
- XmlJavaTypeAdapter adapter =
- org.apache.cxf.jaxrs.utils.JAXBUtils.getAdapter(firstObj.getClass(), anns);
- marshalCollectionMember(JAXBUtils.useAdapter(firstObj, adapter, true),
- actualClass, genericType, enc, os, anns, m,
- qname.getNamespaceURI());
- while (it.hasNext()) {
- marshalCollectionMember(JAXBUtils.useAdapter(it.next(), adapter, true), actualClass,
- genericType, enc, os, anns, m,
- qname.getNamespaceURI());
- }
- }
- os.write(endTag.getBytes());
- }
- //CHECKSTYLE:OFF
- protected void marshalCollectionMember(Object obj,
- Class<?> cls,
- Type genericType,
- String enc,
- OutputStream os,
- Annotation[] anns,
- MediaType mt,
- String ns) throws Exception {
- //CHECKSTYLE:ON
- if (!(obj instanceof JAXBElement)) {
- obj = convertToJaxbElementIfNeeded(obj, cls, genericType);
- }
-
- if (obj instanceof JAXBElement && cls != JAXBElement.class) {
- cls = JAXBElement.class;
- }
-
- Marshaller ms = createMarshaller(obj, cls, genericType, enc);
- ms.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
- if (ns.length() > 0) {
- Map<String, String> map = new HashMap<>();
- // set the default just in case
- if (!nsPrefixes.containsKey(ns)) {
- map.put(ns, "ns1");
- }
- map.putAll(nsPrefixes);
- setNamespaceMapper(ms, map);
- }
- marshal(obj, cls, genericType, enc, os, anns, mt, ms);
- }
-
- protected void marshal(Object obj, Class<?> cls, Type genericType,
- String enc, OutputStream os, MediaType mt) throws Exception {
- marshal(obj, cls, genericType, enc, os, mt, new Annotation[]{});
- }
-
- protected void marshal(Object obj, Class<?> cls, Type genericType,
- String enc, OutputStream os, MediaType mt,
- Annotation[] anns) throws Exception {
- obj = convertToJaxbElementIfNeeded(obj, cls, genericType);
- if (obj instanceof JAXBElement && cls != JAXBElement.class) {
- cls = JAXBElement.class;
- }
-
- Marshaller ms = createMarshaller(obj, cls, genericType, enc);
- if (!nsPrefixes.isEmpty()) {
- setNamespaceMapper(ms, nsPrefixes);
- }
- addAttachmentMarshaller(ms);
- processXmlAnnotations(ms, mt, anns);
- marshal(obj, cls, genericType, enc, os, anns, mt, ms);
- }
-
- private void processXmlAnnotations(Marshaller ms, MediaType mt, Annotation[] anns) throws Exception {
- if (anns == null) {
- return;
- }
- for (Annotation ann : anns) {
- if (ann.annotationType() == XMLInstruction.class) {
- addProcessingInstructions(ms, (XMLInstruction)ann);
- } else if (ann.annotationType() == XSISchemaLocation.class) {
- addSchemaLocation(ms, (XSISchemaLocation)ann);
- } else if (ann.annotationType() == XSLTTransform.class) {
- addXslProcessingInstruction(ms, mt, (XSLTTransform)ann);
- }
- }
- }
-
- private void addProcessingInstructions(Marshaller ms, XMLInstruction pi) throws Exception {
- String value = pi.value();
- int ind = value.indexOf("href='");
- if (ind > 0) {
- String relRef = value.substring(ind + 6);
- relRef = relRef.substring(0, relRef.length() - 3).trim();
- if (relRef.endsWith("'")) {
- relRef = relRef.substring(0, relRef.length() - 1);
- }
- String absRef = resolveXMLResourceURI(relRef);
- value = value.substring(0, ind + 6) + absRef + "'?>";
- }
- setXmlPiProperty(ms, value);
- }
-
- private void addXslProcessingInstruction(Marshaller ms, MediaType mt, XSLTTransform ann)
- throws Exception {
- if (ann.type() == XSLTTransform.TransformType.CLIENT
- || ann.type() == XSLTTransform.TransformType.BOTH && ann.mediaTypes().length > 0) {
- for (String s : ann.mediaTypes()) {
- if (mt.isCompatible(JAXRSUtils.toMediaType(s))) {
- return;
- }
- }
- String absRef = resolveXMLResourceURI(ann.value());
- String xslPi = "<?xml-stylesheet type=\"text/xsl\" href=\"" + absRef + "\"?>";
- setXmlPiProperty(ms, xslPi);
- }
- }
-
- private void addSchemaLocation(Marshaller ms, XSISchemaLocation sl) throws Exception {
- String value = sl.resolve() ? resolveXMLResourceURI(sl.value()) : sl.value();
- String propName = !sl.noNamespace()
- ? Marshaller.JAXB_SCHEMA_LOCATION : Marshaller.JAXB_NO_NAMESPACE_SCHEMA_LOCATION;
- ms.setProperty(propName, value);
- }
-
- protected String resolveXMLResourceURI(String path) {
- MessageContext mc = getContext();
- if (mc != null) {
- String httpBasePath = (String)mc.get("http.base.path");
- final UriBuilder builder;
- if (httpBasePath != null) {
- builder = UriBuilder.fromPath(httpBasePath);
- } else {
- builder = mc.getUriInfo().getBaseUriBuilder();
- }
- return builder.path(path).path(xmlResourceOffset).build().toString();
- }
- return path;
- }
-
-
-
- protected void addAttachmentMarshaller(Marshaller ms) {
- Collection<Attachment> attachments = getAttachments(true);
- if (attachments != null) {
- Object value = getContext().getContextualProperty(Message.MTOM_THRESHOLD);
- Integer threshold = value != null ? Integer.valueOf(value.toString()) : Integer.valueOf(0);
- ms.setAttachmentMarshaller(new JAXBAttachmentMarshaller(
- attachments, threshold));
- }
- }
-
- protected void addAttachmentUnmarshaller(Unmarshaller um) {
- Collection<Attachment> attachments = getAttachments(false);
- if (attachments != null) {
- um.setAttachmentUnmarshaller(new JAXBAttachmentUnmarshaller(
- attachments));
- }
- }
-
- private Collection<Attachment> getAttachments(boolean write) {
- MessageContext mc = getContext();
- if (mc != null) {
- // TODO: there has to be a better fix
- String propertyName = write ? "WRITE-" + Message.ATTACHMENTS : Message.ATTACHMENTS;
- return CastUtils.cast((Collection<?>)mc.get(propertyName));
- }
- return null;
- }
- //CHECKSTYLE:OFF
- protected final void marshal(Object obj, Class<?> cls, Type genericType,
- String enc, OutputStream os,
- Annotation[] anns, MediaType mt, Marshaller ms)
- throws Exception {
- //CHECKSTYLE:ON
- for (Map.Entry<String, Object> entry : mProperties.entrySet()) {
- ms.setProperty(entry.getKey(), entry.getValue());
- }
- MessageContext mc = getContext();
- if (mc != null) {
- // check Marshaller properties which might've been set earlier on,
- // they'll overwrite statically configured ones
- for (String key : MARSHALLER_PROPERTIES) {
- Object value = mc.get(key);
- if (value != null) {
- ms.setProperty(key, value);
- }
- }
-
- }
- XMLStreamWriter writer = getStreamWriter(obj, os, mt);
- if (writer != null) {
- if (os == null) {
- ms.setProperty(Marshaller.JAXB_FRAGMENT, true);
- } else if (mc != null) {
- if (mc.getContent(XMLStreamWriter.class) != null) {
- ms.setProperty(Marshaller.JAXB_FRAGMENT, true);
- }
- mc.put(XMLStreamWriter.class.getName(), writer);
- }
- marshalToWriter(ms, obj, writer, anns, mt);
- if (mc != null) {
- writer.writeEndDocument();
- }
- } else {
- marshalToOutputStream(ms, obj, os, anns, mt);
- }
- }
-
- protected XMLStreamWriter getStreamWriter(Object obj, OutputStream os, MediaType mt) {
- XMLStreamWriter writer = null;
- MessageContext mc = getContext();
- if (mc != null) {
- writer = mc.getContent(XMLStreamWriter.class);
- if (writer == null) {
- XMLOutputFactory factory = (XMLOutputFactory)mc.get(XMLOutputFactory.class.getName());
- if (factory != null) {
- try {
- writer = factory.createXMLStreamWriter(os);
- } catch (XMLStreamException e) {
- throw ExceptionUtils.toInternalServerErrorException(
- new RuntimeException("Cant' create XMLStreamWriter", e), null);
- }
- }
- }
- if (writer == null && getEnableStreaming()) {
- writer = StaxUtils.createXMLStreamWriter(os);
- }
- }
-
- if (writer == null && os == null) {
- writer = getStreamHandlerFromCurrentMessage(XMLStreamWriter.class);
- }
- return createTransformWriterIfNeeded(writer, os, true);
- }
-
- protected void marshalToOutputStream(Marshaller ms, Object obj, OutputStream os,
- Annotation[] anns, MediaType mt)
- throws Exception {
- org.apache.cxf.common.jaxb.JAXBUtils.setMinimumEscapeHandler(ms);
- if (os == null) {
- Writer writer = getStreamHandlerFromCurrentMessage(Writer.class);
- if (writer == null) {
- LOG.severe("No OutputStream, Writer, or XMLStreamWriter is available");
- throw ExceptionUtils.toInternalServerErrorException(null, null);
- }
- ms.marshal(obj, writer);
- writer.flush();
- } else {
- ms.marshal(obj, os);
- }
- }
-
- protected void marshalToWriter(Marshaller ms, Object obj, XMLStreamWriter writer,
- Annotation[] anns, MediaType mt)
- throws Exception {
- org.apache.cxf.common.jaxb.JAXBUtils.setNoEscapeHandler(ms);
- ms.marshal(obj, writer);
- }
-
- public void setXmlPiPropertyName(String xmlPiPropertyName) {
- this.xmlPiPropertyName = xmlPiPropertyName;
- }
-
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxrs/provider/MultipartProvider.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxrs/provider/MultipartProvider.java
deleted file mode 100644
index e129eff..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxrs/provider/MultipartProvider.java
+++ /dev/null
@@ -1,474 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.cxf.jaxrs.provider;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Type;
-import java.nio.file.Files;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.ResourceBundle;
-import java.util.Set;
-import java.util.logging.Logger;
-
-import javax.activation.DataHandler;
-import javax.activation.DataSource;
-import javax.ws.rs.Consumes;
-import javax.ws.rs.Produces;
-import javax.ws.rs.WebApplicationException;
-import javax.ws.rs.core.Context;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.MultivaluedMap;
-import javax.ws.rs.ext.MessageBodyReader;
-import javax.ws.rs.ext.MessageBodyWriter;
-import javax.ws.rs.ext.Provider;
-
-import org.apache.cxf.attachment.AttachmentUtil;
-import org.apache.cxf.attachment.ByteDataSource;
-import org.apache.cxf.common.i18n.BundleUtils;
-import org.apache.cxf.common.logging.LogUtils;
-import org.apache.cxf.common.util.PrimitiveUtils;
-import org.apache.cxf.common.util.PropertyUtils;
-import org.apache.cxf.helpers.CastUtils;
-import org.apache.cxf.jaxrs.ext.MessageContext;
-import org.apache.cxf.jaxrs.ext.multipart.Attachment;
-import org.apache.cxf.jaxrs.ext.multipart.ContentDisposition;
-import org.apache.cxf.jaxrs.ext.multipart.InputStreamDataSource;
-import org.apache.cxf.jaxrs.ext.multipart.Multipart;
-import org.apache.cxf.jaxrs.ext.multipart.MultipartBody;
-import org.apache.cxf.jaxrs.ext.multipart.MultipartOutputFilter;
-import org.apache.cxf.jaxrs.impl.MetadataMap;
-import org.apache.cxf.jaxrs.utils.AnnotationUtils;
-import org.apache.cxf.jaxrs.utils.ExceptionUtils;
-import org.apache.cxf.jaxrs.utils.InjectionUtils;
-import org.apache.cxf.jaxrs.utils.JAXRSUtils;
-import org.apache.cxf.jaxrs.utils.multipart.AttachmentUtils;
-import org.apache.cxf.message.Message;
-
-@Provider
-@Consumes({"multipart/related", "multipart/mixed", "multipart/alternative", "multipart/form-data" })
-@Produces({"multipart/related", "multipart/mixed", "multipart/alternative", "multipart/form-data" })
-public class MultipartProvider extends AbstractConfigurableProvider
- implements MessageBodyReader<Object>, MessageBodyWriter<Object> {
-
- private static final String SUPPORT_TYPE_AS_MULTIPART = "support.type.as.multipart";
- private static final String SINGLE_PART_IS_COLLECTION = "single.multipart.is.collection";
- private static final Logger LOG = LogUtils.getL7dLogger(MultipartProvider.class);
- private static final ResourceBundle BUNDLE = BundleUtils.getBundle(MultipartProvider.class);
- private static final Set<Class<?>> WELL_KNOWN_MULTIPART_CLASSES = new HashSet<>();
- private static final Set<String> MULTIPART_SUBTYPES = new HashSet<>();
- static {
- WELL_KNOWN_MULTIPART_CLASSES.add(MultipartBody.class);
- WELL_KNOWN_MULTIPART_CLASSES.add(Attachment.class);
-
- MULTIPART_SUBTYPES.add("form-data");
- MULTIPART_SUBTYPES.add("mixed");
- MULTIPART_SUBTYPES.add("related");
- MULTIPART_SUBTYPES.add("alternative");
- }
-
- @Context
- private MessageContext mc;
- private String attachmentDir;
- private String attachmentThreshold;
- private String attachmentMaxSize;
-
- public void setMessageContext(MessageContext context) {
- this.mc = context;
- }
-
- public void setAttachmentDirectory(String dir) {
- attachmentDir = dir;
- }
-
- public void setAttachmentThreshold(String threshold) {
- attachmentThreshold = threshold;
- }
-
- public void setAttachmentMaxSize(String maxSize) {
- attachmentMaxSize = maxSize;
- }
-
- public boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations,
- MediaType mt) {
- return isSupported(type, annotations, mt);
-
- }
-
- private boolean isSupported(Class<?> type, Annotation[] anns, MediaType mt) {
- return mediaTypeSupported(mt)
- && (WELL_KNOWN_MULTIPART_CLASSES.contains(type)
- || Collection.class.isAssignableFrom(type)
- || Map.class.isAssignableFrom(type) && type != MultivaluedMap.class
- || AnnotationUtils.getAnnotation(anns, Multipart.class) != null
- || PropertyUtils.isTrue(mc.getContextualProperty(SUPPORT_TYPE_AS_MULTIPART)));
- }
-
- protected void checkContentLength() {
- if (mc != null && isPayloadEmpty(mc.getHttpHeaders())) {
- String message = new org.apache.cxf.common.i18n.Message("EMPTY_BODY", BUNDLE).toString();
- LOG.warning(message);
- throw new WebApplicationException(400);
- }
- }
-
- public Object readFrom(Class<Object> c, Type t, Annotation[] anns, MediaType mt,
- MultivaluedMap<String, String> headers, InputStream is)
- throws IOException, WebApplicationException {
- checkContentLength();
- List<Attachment> infos = AttachmentUtils.getAttachments(
- mc, attachmentDir, attachmentThreshold, attachmentMaxSize);
-
- boolean collectionExpected = Collection.class.isAssignableFrom(c);
- if (collectionExpected
- && AnnotationUtils.getAnnotation(anns, Multipart.class) == null) {
- return getAttachmentCollection(t, infos, anns);
- }
- if (c.isAssignableFrom(Map.class)) {
- Map<String, Object> map = new LinkedHashMap<>(infos.size());
- Class<?> actual = getActualType(t, 1);
- for (Attachment a : infos) {
- map.put(a.getContentType().toString(), fromAttachment(a, actual, actual, anns));
- }
- return map;
- }
- if (MultipartBody.class.isAssignableFrom(c)) {
- return new MultipartBody(infos);
- }
-
- Multipart id = AnnotationUtils.getAnnotation(anns, Multipart.class);
- Attachment multipart = AttachmentUtils.getMultipart(id, mt, infos);
- if (multipart != null) {
- if (collectionExpected
- && !mediaTypeSupported(multipart.getContentType())
- && !PropertyUtils.isTrue(mc.getContextualProperty(SINGLE_PART_IS_COLLECTION))) {
- List<Attachment> allMultiparts = AttachmentUtils.getMatchingAttachments(id, infos);
- return getAttachmentCollection(t, allMultiparts, anns);
- }
- return fromAttachment(multipart, c, t, anns);
- }
-
- if (id != null && !id.required()) {
- /*
- * Return default value for a missing optional part
- */
- Object defaultValue = null;
- if (c.isPrimitive()) {
- defaultValue = PrimitiveUtils.read((Class<?>)c == boolean.class ? "false" : "0", c);
- }
- return defaultValue;
- }
-
- throw ExceptionUtils.toBadRequestException(null, null);
-
- }
-
- private Object getAttachmentCollection(Type t, List<Attachment> infos, Annotation[] anns) throws IOException {
- Class<?> actual = getActualType(t, 0);
- if (Attachment.class.isAssignableFrom(actual)) {
- return infos;
- }
- Collection<Object> objects = new ArrayList<>();
- for (Attachment a : infos) {
- objects.add(fromAttachment(a, actual, actual, anns));
- }
- return objects;
- }
-
- private Class<?> getActualType(Type type, int pos) {
- Class<?> actual = null;
- try {
- actual = InjectionUtils.getActualType(type, pos);
- } catch (Exception ex) {
- // ignore;
- }
- return actual != null && actual != Object.class ? actual : Attachment.class;
- }
-
- private <T> Object fromAttachment(Attachment multipart, Class<T> c, Type t, Annotation[] anns)
- throws IOException {
- if (DataHandler.class.isAssignableFrom(c)) {
- return multipart.getDataHandler();
- } else if (DataSource.class.isAssignableFrom(c)) {
- return multipart.getDataHandler().getDataSource();
- } else if (Attachment.class.isAssignableFrom(c)) {
- return multipart;
- } else {
- if (mediaTypeSupported(multipart.getContentType())) {
- mc.put("org.apache.cxf.multipart.embedded", true);
- mc.put("org.apache.cxf.multipart.embedded.ctype", multipart.getContentType());
- mc.put("org.apache.cxf.multipart.embedded.input",
- multipart.getDataHandler().getInputStream());
- anns = new Annotation[]{};
- }
- MessageBodyReader<T> r =
- mc.getProviders().getMessageBodyReader(c, t, anns, multipart.getContentType());
- if (r != null) {
- InputStream is = multipart.getDataHandler().getInputStream();
- return r.readFrom(c, t, anns, multipart.getContentType(), multipart.getHeaders(),
- is);
- }
- }
- return null;
- }
-
- private boolean mediaTypeSupported(MediaType mt) {
- return "multipart".equals(mt.getType()) && MULTIPART_SUBTYPES.contains(mt.getSubtype());
- }
-
- public long getSize(Object t, Class<?> type, Type genericType, Annotation[] annotations,
- MediaType mediaType) {
- return -1;
- }
-
- public boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations,
- MediaType mt) {
- return isSupported(type, annotations, mt);
- }
-
-
- public void writeTo(Object obj, Class<?> type, Type genericType, Annotation[] anns, MediaType mt,
- MultivaluedMap<String, Object> headers, OutputStream os)
- throws IOException, WebApplicationException {
-
- List<Attachment> handlers = convertToDataHandlers(obj, type, genericType, anns, mt);
- if (mc.get(AttachmentUtils.OUT_FILTERS) != null) {
- List<MultipartOutputFilter> filters = CastUtils.cast((List<?>)mc.get(AttachmentUtils.OUT_FILTERS));
- for (MultipartOutputFilter filter : filters) {
- filter.filter(handlers);
- }
- }
- mc.put(MultipartBody.OUTBOUND_MESSAGE_ATTACHMENTS, handlers);
- handlers.get(0).getDataHandler().writeTo(os);
- }
-
- private List<Attachment> convertToDataHandlers(Object obj,
- Class<?> type, Type genericType,
- Annotation[] anns, MediaType mt) throws IOException {
- if (Map.class.isAssignableFrom(obj.getClass())) {
- Map<Object, Object> objects = CastUtils.cast((Map<?, ?>)obj);
- List<Attachment> handlers = new ArrayList<>(objects.size());
- int i = 0;
- for (Iterator<Map.Entry<Object, Object>> iter = objects.entrySet().iterator();
- iter.hasNext();) {
- Map.Entry<Object, Object> entry = iter.next();
- Object value = entry.getValue();
- Attachment handler = createDataHandler(value, value.getClass(),
- new Annotation[]{},
- entry.getKey().toString(),
- mt.toString(),
- i++);
- handlers.add(handler);
- }
- return handlers;
- }
- String rootMediaType = getRootMediaType(anns, mt);
- if (List.class.isAssignableFrom(obj.getClass())) {
- return getAttachments((List<?>)obj, rootMediaType);
- }
- if (MultipartBody.class.isAssignableFrom(type)) {
- List<Attachment> atts = ((MultipartBody)obj).getAllAttachments();
- // these attachments may have no DataHandlers, but objects only
- return getAttachments(atts, rootMediaType);
- }
- Attachment handler = createDataHandler(obj,
- genericType, anns,
- rootMediaType, mt.toString(), 1);
- return Collections.singletonList(handler);
- }
-
- private List<Attachment> getAttachments(List<?> objects, String rootMediaType) throws IOException {
- List<Attachment> handlers = new ArrayList<>(objects.size());
- for (int i = 0; i < objects.size(); i++) {
- Object value = objects.get(i);
- Attachment handler = createDataHandler(value,
- value.getClass(), new Annotation[]{},
- rootMediaType, rootMediaType, i);
- handlers.add(handler);
- }
- return handlers;
- }
-
- private <T> Attachment createDataHandler(T obj,
- Type genericType,
- Annotation[] anns,
- String mimeType,
- String mainMediaType,
- int id) throws IOException {
- @SuppressWarnings("unchecked")
- Class<T> cls = (Class<T>)obj.getClass();
- return createDataHandler(obj, cls, genericType, anns, mimeType, mainMediaType, id);
- }
- private <T> Attachment createDataHandler(T obj,
- Class<T> cls,
- Type genericType,
- Annotation[] anns,
- String mimeType,
- String mainMediaType,
- int id) throws IOException {
- final DataHandler dh;
- if (InputStream.class.isAssignableFrom(obj.getClass())) {
- dh = createInputStreamDH((InputStream)obj, mimeType);
- } else if (DataHandler.class.isAssignableFrom(obj.getClass())) {
- dh = (DataHandler)obj;
- } else if (DataSource.class.isAssignableFrom(obj.getClass())) {
- dh = new DataHandler((DataSource)obj);
- } else if (File.class.isAssignableFrom(obj.getClass())) {
- File f = (File)obj;
- ContentDisposition cd = mainMediaType.startsWith(MediaType.MULTIPART_FORM_DATA)
- ? new ContentDisposition("form-data;name=file;filename=" + f.getName()) : null;
- return new Attachment(AttachmentUtil.BODY_ATTACHMENT_ID, Files.newInputStream(f.toPath()), cd);
- } else if (Attachment.class.isAssignableFrom(obj.getClass())) {
- Attachment att = (Attachment)obj;
- if (att.getObject() == null) {
- return att;
- }
- dh = getHandlerForObject(att.getObject(),
- att.getObject().getClass(), new Annotation[]{},
- att.getContentType().toString(), id);
- return new Attachment(att.getContentId(), dh, att.getHeaders());
- } else if (byte[].class.isAssignableFrom(obj.getClass())) {
- ByteDataSource source = new ByteDataSource((byte[])obj);
- source.setContentType(mimeType);
- dh = new DataHandler(source);
- } else {
- dh = getHandlerForObject(obj, cls, genericType, anns, mimeType);
- }
- String contentId = getContentId(anns, id);
- MultivaluedMap<String, String> headers = new MetadataMap<>();
- headers.putSingle("Content-Type", mimeType);
-
- return new Attachment(contentId, dh, headers);
- }
-
- private String getContentId(Annotation[] anns, int id) {
- Multipart part = AnnotationUtils.getAnnotation(anns, Multipart.class);
- if (part != null && !"".equals(part.value())) {
- return part.value();
- }
- return id == 0 ? AttachmentUtil.BODY_ATTACHMENT_ID : Integer.toString(id);
- }
-
- private <T> DataHandler getHandlerForObject(T obj,
- Class<T> cls, Type genericType,
- Annotation[] anns,
- String mimeType) {
- MediaType mt = JAXRSUtils.toMediaType(mimeType);
- mc.put(ProviderFactory.ACTIVE_JAXRS_PROVIDER_KEY, this);
-
- final MessageBodyWriter<T> r;
- try {
- r = mc.getProviders().getMessageBodyWriter(cls, genericType, anns, mt);
- } finally {
- mc.put(ProviderFactory.ACTIVE_JAXRS_PROVIDER_KEY, null);
- }
- if (r == null) {
- org.apache.cxf.common.i18n.Message message =
- new org.apache.cxf.common.i18n.Message("NO_MSG_WRITER",
- BUNDLE,
- cls);
- LOG.severe(message.toString());
- throw ExceptionUtils.toInternalServerErrorException(null, null);
- }
-
- return new MessageBodyWriterDataHandler<T>(r, obj, cls, genericType, anns, mt);
- }
- private <T> DataHandler getHandlerForObject(T obj,
- Type genericType,
- Annotation[] anns,
- String mimeType, int id) {
- @SuppressWarnings("unchecked")
- Class<T> cls = (Class<T>)obj.getClass();
- return getHandlerForObject(obj, cls, genericType, anns, mimeType);
- }
-
- private DataHandler createInputStreamDH(InputStream is, String mimeType) {
- return new DataHandler(new InputStreamDataSource(is, mimeType));
- }
-
- private String getRootMediaType(Annotation[] anns, MediaType mt) {
- String mimeType = mt.getParameters().get("type");
- if (mimeType != null) {
- return mimeType;
- }
- Multipart id = AnnotationUtils.getAnnotation(anns, Multipart.class);
- if (id != null && !MediaType.WILDCARD.equals(id.type())) {
- mimeType = id.type();
- }
- if (mimeType == null) {
- if (PropertyUtils.isTrue(mc.getContextualProperty(Message.MTOM_ENABLED))) {
- mimeType = "text/xml";
- } else {
- mimeType = MediaType.APPLICATION_OCTET_STREAM;
- }
- }
- return mimeType;
- }
-
- private static class MessageBodyWriterDataHandler<T> extends DataHandler {
- private MessageBodyWriter<T> writer;
- private T obj;
- private Class<T> cls;
- private Type genericType;
- private Annotation[] anns;
- private MediaType contentType;
- MessageBodyWriterDataHandler(MessageBodyWriter<T> writer,
- T obj,
- Class<T> cls,
- Type genericType,
- Annotation[] anns,
- MediaType contentType) {
- super(new ByteDataSource("1".getBytes(), contentType.toString()));
- this.writer = writer;
- this.obj = obj;
- this.cls = cls;
- this.genericType = genericType;
- this.anns = anns;
- this.contentType = contentType;
- }
-
- @Override
- public void writeTo(OutputStream os) {
- try {
- writer.writeTo(obj, cls, genericType, anns, contentType,
- new MetadataMap<String, Object>(), os);
- } catch (IOException ex) {
- throw ExceptionUtils.toInternalServerErrorException(ex, null);
- }
- }
-
- @Override
- public String getContentType() {
- return contentType.toString();
- }
-
- // TODO : throw UnsupportedOperationException for all other DataHandler methods
- }
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxrs/provider/SourceProvider.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxrs/provider/SourceProvider.java
deleted file mode 100644
index 76980b8..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxrs/provider/SourceProvider.java
+++ /dev/null
@@ -1,236 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.cxf.jaxrs.provider;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Type;
-import java.nio.charset.StandardCharsets;
-import java.util.logging.Logger;
-
-import javax.ws.rs.Consumes;
-import javax.ws.rs.Produces;
-import javax.ws.rs.core.Context;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.MultivaluedMap;
-import javax.ws.rs.ext.MessageBodyReader;
-import javax.ws.rs.ext.MessageBodyWriter;
-import javax.ws.rs.ext.Provider;
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamReader;
-import javax.xml.stream.XMLStreamWriter;
-import javax.xml.transform.Source;
-import javax.xml.transform.dom.DOMSource;
-import javax.xml.transform.sax.SAXSource;
-import javax.xml.transform.stream.StreamSource;
-
-import org.w3c.dom.Document;
-import org.w3c.dom.Node;
-
-import org.apache.cxf.common.logging.LogUtils;
-import org.apache.cxf.io.CachedOutputStream;
-import org.apache.cxf.jaxrs.ext.MessageContext;
-import org.apache.cxf.jaxrs.ext.xml.XMLSource;
-import org.apache.cxf.jaxrs.utils.ExceptionUtils;
-import org.apache.cxf.jaxrs.utils.HttpUtils;
-import org.apache.cxf.jaxrs.utils.JAXRSUtils;
-import org.apache.cxf.message.Message;
-import org.apache.cxf.phase.PhaseInterceptorChain;
-import org.apache.cxf.staxutils.DepthExceededStaxException;
-import org.apache.cxf.staxutils.StaxSource;
-import org.apache.cxf.staxutils.StaxUtils;
-
-@Provider
-@Produces({"application/xml", "application/*+xml", "text/xml" })
-@Consumes({"application/xml", "application/*+xml", "text/xml", "text/html" })
-public class SourceProvider<T> extends AbstractConfigurableProvider implements
- MessageBodyReader<T>, MessageBodyWriter<T> {
-
- private static final String PREFERRED_FORMAT = "source-preferred-format";
- private static final Logger LOG = LogUtils.getL7dLogger(SourceProvider.class);
- @Context
- private MessageContext context;
-
-
- public boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mt) {
- return Source.class.isAssignableFrom(type)
- || Node.class.isAssignableFrom(type);
- }
-
- public boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mt) {
- return Source.class.isAssignableFrom(type)
- || XMLSource.class.isAssignableFrom(type)
- || Document.class.isAssignableFrom(type);
- }
-
- public T readFrom(Class<T> source, Type genericType, Annotation[] annotations, MediaType m,
- MultivaluedMap<String, String> headers, InputStream is)
- throws IOException {
-
- Class<?> theSource = source;
- if (theSource == Source.class) {
- String s = getPreferredSource();
- if ("sax".equalsIgnoreCase(s) || "cxf.stax".equalsIgnoreCase(s)) {
- theSource = SAXSource.class;
- }
- }
- try {
- if (DOMSource.class.isAssignableFrom(theSource) || Document.class.isAssignableFrom(theSource)) {
-
- boolean docRequired = Document.class.isAssignableFrom(theSource);
- XMLStreamReader reader = getReader(is);
- try {
- Document doc = StaxUtils.read(reader);
- return source.cast(docRequired ? doc : new DOMSource(doc));
- } catch (DepthExceededStaxException e) {
- throw ExceptionUtils.toWebApplicationException(null, JAXRSUtils.toResponse(413));
- } catch (XMLStreamException e) {
- if (e.getMessage() != null && e.getMessage().startsWith("Maximum Number")) {
- throw ExceptionUtils.toWebApplicationException(null, JAXRSUtils.toResponse(413));
- }
- throw ExceptionUtils.toBadRequestException(e, null);
- } catch (Exception e) {
- IOException ioex = new IOException("Problem creating a Source object");
- ioex.setStackTrace(e.getStackTrace());
- throw ioex;
- } finally {
- try {
- reader.close();
- } catch (XMLStreamException e) {
- //ignore
- }
- }
- } else if (SAXSource.class.isAssignableFrom(theSource)
- || StaxSource.class.isAssignableFrom(theSource)) {
- return source.cast(new StaxSource(getReader(is)));
- } else if (StreamSource.class.isAssignableFrom(theSource)
- || Source.class.isAssignableFrom(theSource)) {
- return source.cast(new StreamSource(getRealStream(is)));
- } else if (XMLSource.class.isAssignableFrom(theSource)) {
- return source.cast(new XMLSource(getRealStream(is)));
- }
- } catch (ClassCastException e) {
- String msg = "Unsupported class: " + source.getName();
- LOG.warning(msg);
- throw ExceptionUtils.toInternalServerErrorException(null, null);
- }
-
- throw new IOException("Unrecognized source");
- }
-
- protected XMLStreamReader getReader(InputStream is) {
- XMLStreamReader reader = getReaderFromMessage();
- if (reader == null) {
- reader = StaxUtils.createXMLStreamReader(is);
- }
- return configureReaderRestrictions(reader);
- }
-
- protected XMLStreamReader configureReaderRestrictions(XMLStreamReader reader) {
- Message message = PhaseInterceptorChain.getCurrentMessage();
- if (message != null) {
- try {
- return StaxUtils.configureReader(reader, message);
- } catch (XMLStreamException ex) {
- throw ExceptionUtils.toInternalServerErrorException(ex, null);
- }
- }
- return reader;
- }
-
- protected InputStream getRealStream(InputStream is) throws IOException {
- XMLStreamReader reader = getReaderFromMessage();
- return reader == null ? is : getStreamFromReader(reader);
- }
-
- private InputStream getStreamFromReader(XMLStreamReader input)
- throws IOException {
-
- try (CachedOutputStream out = new CachedOutputStream()) {
- StaxUtils.copy(input, out);
- return out.getInputStream();
- } catch (XMLStreamException ex) {
- throw new IOException("XMLStreamException:" + ex.getMessage());
- }
- }
-
- protected XMLStreamReader getReaderFromMessage() {
- MessageContext mc = getContext();
- if (mc != null) {
- return mc.getContent(XMLStreamReader.class);
- }
- return null;
- }
-
- public void writeTo(T source, Class<?> clazz, Type genericType, Annotation[] annotations,
- MediaType mt, MultivaluedMap<String, Object> headers, OutputStream os)
- throws IOException {
-
- String encoding = HttpUtils.getSetEncoding(mt, headers, StandardCharsets.UTF_8.name());
-
- final XMLStreamReader reader;
- if (source instanceof Source) {
- reader = StaxUtils.createXMLStreamReader((Source)source);
- } else if (source instanceof Document) {
- reader = StaxUtils.createXMLStreamReader((Document)source);
- } else {
- reader = StaxUtils.createXMLStreamReader(new DOMSource((Node)source));
- }
- XMLStreamWriter writer = StaxUtils.createXMLStreamWriter(os, encoding);
- try {
- StaxUtils.copy(reader, writer);
- } catch (XMLStreamException e) {
- throw ExceptionUtils.toInternalServerErrorException(e, null);
- } finally {
- try {
- reader.close();
- } catch (XMLStreamException e) {
- //ignore
- }
- try {
- writer.flush();
- writer.close();
- } catch (XMLStreamException e) {
- //ignore
- }
- }
- }
-
- public long getSize(T source, Class<?> type, Type genericType, Annotation[] annotations,
- MediaType mt) {
- return -1;
- }
-
- protected String getPreferredSource() {
- MessageContext mc = getContext();
- String source = null;
- if (mc != null) {
- source = (String)mc.getContextualProperty(PREFERRED_FORMAT);
- }
- return source != null ? source : "sax";
-
- }
-
- protected MessageContext getContext() {
- return context;
- }
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxrs/provider/XSLTJaxbProvider.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxrs/provider/XSLTJaxbProvider.java
deleted file mode 100644
index 4250963..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxrs/provider/XSLTJaxbProvider.java
+++ /dev/null
@@ -1,588 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.cxf.jaxrs.provider;
-
-import java.io.BufferedReader;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.OutputStream;
-import java.io.Reader;
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Type;
-import java.net.URL;
-import java.nio.charset.StandardCharsets;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import javax.ws.rs.Consumes;
-import javax.ws.rs.Produces;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.MultivaluedMap;
-import javax.ws.rs.core.PathSegment;
-import javax.ws.rs.core.UriInfo;
-import javax.ws.rs.ext.Provider;
-import javax.xml.XMLConstants;
-import javax.xml.bind.JAXBException;
-import javax.xml.bind.Marshaller;
-import javax.xml.bind.Unmarshaller;
-import javax.xml.stream.XMLStreamReader;
-import javax.xml.stream.XMLStreamWriter;
-import javax.xml.transform.Result;
-import javax.xml.transform.Source;
-import javax.xml.transform.Templates;
-import javax.xml.transform.Transformer;
-import javax.xml.transform.TransformerConfigurationException;
-import javax.xml.transform.TransformerException;
-import javax.xml.transform.TransformerFactory;
-import javax.xml.transform.URIResolver;
-import javax.xml.transform.dom.DOMResult;
-import javax.xml.transform.sax.SAXSource;
-import javax.xml.transform.sax.SAXTransformerFactory;
-import javax.xml.transform.sax.TransformerHandler;
-import javax.xml.transform.stream.StreamResult;
-import javax.xml.transform.stream.StreamSource;
-
-import org.xml.sax.XMLFilter;
-import org.xml.sax.XMLReader;
-
-import org.apache.cxf.common.classloader.ClassLoaderUtils;
-import org.apache.cxf.common.logging.LogUtils;
-import org.apache.cxf.io.CachedOutputStream;
-import org.apache.cxf.jaxrs.ext.MessageContext;
-import org.apache.cxf.jaxrs.ext.xml.XSLTTransform;
-import org.apache.cxf.jaxrs.utils.AnnotationUtils;
-import org.apache.cxf.jaxrs.utils.ExceptionUtils;
-import org.apache.cxf.jaxrs.utils.InjectionUtils;
-import org.apache.cxf.jaxrs.utils.JAXRSUtils;
-import org.apache.cxf.jaxrs.utils.ResourceUtils;
-import org.apache.cxf.staxutils.StaxSource;
-import org.apache.cxf.staxutils.StaxUtils;
-
-@Produces({"application/xml", "application/*+xml", "text/xml", "text/html" })
-@Consumes({"application/xml", "application/*+xml", "text/xml", "text/html" })
-@Provider
-public class XSLTJaxbProvider<T> extends JAXBElementProvider<T> {
-
- private static final Logger LOG = LogUtils.getL7dLogger(XSLTJaxbProvider.class);
-
- private static final String ABSOLUTE_PATH_PARAMETER = "absolute.path";
- private static final String BASE_PATH_PARAMETER = "base.path";
- private static final String RELATIVE_PATH_PARAMETER = "relative.path";
- private static final String XSLT_TEMPLATE_PROPERTY = "xslt.template";
- private SAXTransformerFactory factory;
- private Templates inTemplates;
- private Templates outTemplates;
- private Map<String, Templates> inMediaTemplates;
- private Map<String, Templates> outMediaTemplates;
- private ConcurrentHashMap<String, Templates> annotationTemplates =
- new ConcurrentHashMap<>();
-
- private List<String> inClassesToHandle;
- private List<String> outClassesToHandle;
- private Map<String, Object> inParamsMap;
- private Map<String, Object> outParamsMap;
- private Map<String, String> inProperties;
- private Map<String, String> outProperties;
- private URIResolver uriResolver;
- private String systemId;
-
- private boolean supportJaxbOnly;
- private boolean refreshTemplates;
- private boolean secureProcessing = true;
-
- public void setSupportJaxbOnly(boolean support) {
- this.supportJaxbOnly = support;
- }
-
- @Override
- public boolean isReadable(Class<?> type, Type genericType, Annotation[] anns, MediaType mt) {
- if (!super.isReadable(type, genericType, anns, mt)) {
- return false;
- }
-
- if (InjectionUtils.isSupportedCollectionOrArray(type)) {
- return supportJaxbOnly;
- }
-
- // if the user has set the list of in classes and a given class
- // is in that list then it can only be handled by the template
- if (inClassCanBeHandled(type.getName()) || inClassesToHandle == null && !supportJaxbOnly) {
- return inTemplatesAvailable(type, anns, mt);
- }
- return supportJaxbOnly;
- }
-
- @Override
- public boolean isWriteable(Class<?> type, Type genericType, Annotation[] anns, MediaType mt) {
- // JAXB support is required
- if (!super.isWriteable(type, genericType, anns, mt)) {
- return false;
- }
- if (InjectionUtils.isSupportedCollectionOrArray(type)) {
- return supportJaxbOnly;
- }
-
- // if the user has set the list of out classes and a given class
- // is in that list then it can only be handled by the template
- if (outClassCanBeHandled(type.getName()) || outClassesToHandle == null && !supportJaxbOnly) {
- return outTemplatesAvailable(type, anns, mt);
- }
- return supportJaxbOnly;
- }
-
- protected boolean inTemplatesAvailable(Class<?> cls, Annotation[] anns, MediaType mt) {
- return inTemplates != null
- || inMediaTemplates != null && inMediaTemplates.containsKey(mt.getType() + "/"
- + mt.getSubtype())
- || getTemplatesFromAnnotation(cls, anns, mt) != null;
- }
-
- protected boolean outTemplatesAvailable(Class<?> cls, Annotation[] anns, MediaType mt) {
- return outTemplates != null
- || outMediaTemplates != null && outMediaTemplates.containsKey(mt.getType()
- + "/" + mt.getSubtype())
- || getTemplatesFromAnnotation(cls, anns, mt) != null;
- }
-
- protected Templates getTemplatesFromAnnotation(Class<?> cls,
- Annotation[] anns,
- MediaType mt) {
- Templates t = null;
- XSLTTransform ann = getXsltTransformAnn(anns, mt);
- if (ann != null) {
- t = annotationTemplates.get(ann.value());
- if (t == null || refreshTemplates) {
- String path = ann.value();
- final String cp = "classpath:";
- if (!path.startsWith(cp)) {
- path = cp + path;
- }
- t = createTemplates(path);
- if (t == null) {
- createTemplates(ClassLoaderUtils.getResource(ann.value(), cls));
- }
- if (t != null) {
- annotationTemplates.put(ann.value(), t);
- }
- }
- }
- return t;
-
- }
-
- protected Templates getAnnotationTemplates(Annotation[] anns) {
- Templates t = null;
- XSLTTransform ann = AnnotationUtils.getAnnotation(anns, XSLTTransform.class);
- if (ann != null) {
- t = annotationTemplates.get(ann.value());
- }
- return t;
-
- }
-
- protected XSLTTransform getXsltTransformAnn(Annotation[] anns, MediaType mt) {
- XSLTTransform ann = AnnotationUtils.getAnnotation(anns, XSLTTransform.class);
- if (ann != null && ann.type() != XSLTTransform.TransformType.CLIENT) {
- if (ann.mediaTypes().length > 0) {
- for (String s : ann.mediaTypes()) {
- if (mt.isCompatible(JAXRSUtils.toMediaType(s))) {
- return ann;
- }
- }
- return null;
- }
- return ann;
- }
- return null;
- }
-
-
-
- protected Templates getInTemplates(Annotation[] anns, MediaType mt) {
- Templates t = createTemplatesFromContext();
- if (t != null) {
- return t;
- }
- t = inTemplates != null ? inTemplates
- : inMediaTemplates != null ? inMediaTemplates.get(mt.getType() + "/" + mt.getSubtype()) : null;
- if (t == null) {
- t = getAnnotationTemplates(anns);
- }
- return t;
- }
-
- protected Templates getOutTemplates(Annotation[] anns, MediaType mt) {
- Templates t = createTemplatesFromContext();
- if (t != null) {
- return t;
- }
- t = outTemplates != null ? outTemplates
- : outMediaTemplates != null ? outMediaTemplates.get(mt.getType() + "/" + mt.getSubtype()) : null;
- if (t == null) {
- t = getAnnotationTemplates(anns);
- }
- return t;
- }
-
- @Override
- protected Object unmarshalFromInputStream(Unmarshaller unmarshaller, InputStream is,
- Annotation[] anns, MediaType mt)
- throws JAXBException {
- try {
-
- Templates t = createTemplates(getInTemplates(anns, mt), inParamsMap, inProperties);
- if (t == null && supportJaxbOnly) {
- return super.unmarshalFromInputStream(unmarshaller, is, anns, mt);
- }
-
- if (unmarshaller.getClass().getName().contains("eclipse")) {
- //eclipse MOXy doesn't work properly with the XMLFilter/Reader thing
- //so we need to bounce through a DOM
- Source reader = new StaxSource(StaxUtils.createXMLStreamReader(is));
- DOMResult dom = new DOMResult();
- t.newTransformer().transform(reader, dom);
- return unmarshaller.unmarshal(dom.getNode());
- }
- XMLFilter filter;
- try {
- filter = factory.newXMLFilter(t);
- } catch (TransformerConfigurationException ex) {
- TemplatesImpl ti = (TemplatesImpl)t;
- filter = factory.newXMLFilter(ti.getTemplates());
- trySettingProperties(filter, ti);
- }
- XMLReader reader = new StaxSource(StaxUtils.createXMLStreamReader(is));
- filter.setParent(reader);
- SAXSource source = new SAXSource();
- source.setXMLReader(filter);
- if (systemId != null) {
- source.setSystemId(systemId);
- }
- return unmarshaller.unmarshal(source);
- } catch (TransformerException ex) {
- LOG.warning("Transformation exception : " + ex.getMessage());
- throw ExceptionUtils.toInternalServerErrorException(ex, null);
- }
- }
-
- private void trySettingProperties(Object filter, TemplatesImpl ti) {
- try {
- //Saxon doesn't allow creating a Filter or Handler from anything other than it's original
- //Templates. That then requires setting the parameters after the fact, but there
- //isn't a standard API for that, so we have to grab the Transformer via reflection to
- //set the parameters.
- Transformer tr = (Transformer)filter.getClass().getMethod("getTransformer").invoke(filter);
- tr.setURIResolver(ti.resolver);
- for (Map.Entry<String, Object> entry : ti.transformParameters.entrySet()) {
- tr.setParameter(entry.getKey(), entry.getValue());
- }
- for (Map.Entry<String, String> entry : ti.outProps.entrySet()) {
- tr.setOutputProperty(entry.getKey(), entry.getValue());
- }
- } catch (Exception e) {
- LOG.log(Level.WARNING, "Could not set properties for transfomer", e);
- }
- }
-
- @Override
- protected Object unmarshalFromReader(Unmarshaller unmarshaller, XMLStreamReader reader,
- Annotation[] anns, MediaType mt)
- throws JAXBException {
- CachedOutputStream out = new CachedOutputStream();
- try {
- XMLStreamWriter writer = StaxUtils.createXMLStreamWriter(out);
- StaxUtils.copy(new StaxSource(reader), writer);
- writer.writeEndDocument();
- writer.flush();
- writer.close();
- return unmarshalFromInputStream(unmarshaller, out.getInputStream(), anns, mt);
- } catch (Exception ex) {
- throw ExceptionUtils.toBadRequestException(ex, null);
- }
- }
-
- @Override
- protected void marshalToWriter(Marshaller ms, Object obj, XMLStreamWriter writer,
- Annotation[] anns, MediaType mt)
- throws Exception {
- CachedOutputStream out = new CachedOutputStream();
- marshalToOutputStream(ms, obj, out, anns, mt);
-
- StaxUtils.copy(new StreamSource(out.getInputStream()), writer);
- }
-
- @Override
- protected void addAttachmentMarshaller(Marshaller ms) {
- // complete
- }
-
- protected Result getStreamResult(OutputStream os, Annotation[] anns, MediaType mt) throws Exception {
- return new StreamResult(os);
- }
-
- @Override
- protected void marshalToOutputStream(Marshaller ms, Object obj, OutputStream os,
- Annotation[] anns, MediaType mt)
- throws Exception {
-
- Templates t = createTemplates(getOutTemplates(anns, mt), outParamsMap, outProperties);
- if (t == null && supportJaxbOnly) {
- super.marshalToOutputStream(ms, obj, os, anns, mt);
- return;
- }
- org.apache.cxf.common.jaxb.JAXBUtils.setMinimumEscapeHandler(ms);
- TransformerHandler th;
- try {
- th = factory.newTransformerHandler(t);
- } catch (TransformerConfigurationException ex) {
- TemplatesImpl ti = (TemplatesImpl)t;
- th = factory.newTransformerHandler(ti.getTemplates());
- this.trySettingProperties(th, ti);
- }
- Result result = getStreamResult(os, anns, mt);
- if (systemId != null) {
- result.setSystemId(systemId);
- }
- th.setResult(result);
-
- if (getContext() == null) {
- th.startDocument();
- }
- ms.marshal(obj, th);
- if (getContext() == null) {
- th.endDocument();
- }
- }
-
- public void setOutTemplate(String loc) {
- outTemplates = createTemplates(loc);
- }
-
- public void setInTemplate(String loc) {
- inTemplates = createTemplates(loc);
- }
-
- public void setInMediaTemplates(Map<String, String> map) {
- inMediaTemplates = new HashMap<>();
- for (Map.Entry<String, String> entry : map.entrySet()) {
- inMediaTemplates.put(entry.getKey(), createTemplates(entry.getValue()));
- }
- }
-
- public void setOutMediaTemplates(Map<String, String> map) {
- outMediaTemplates = new HashMap<>();
- for (Map.Entry<String, String> entry : map.entrySet()) {
- outMediaTemplates.put(entry.getKey(), createTemplates(entry.getValue()));
- }
- }
-
- public void setResolver(URIResolver resolver) {
- uriResolver = resolver;
- if (factory != null) {
- factory.setURIResolver(uriResolver);
- }
- }
-
- public void setSystemId(String system) {
- systemId = system;
- }
-
- public void setInParameters(Map<String, Object> inParams) {
- this.inParamsMap = inParams;
- }
-
- public void setOutParameters(Map<String, Object> outParams) {
- this.outParamsMap = outParams;
- }
-
- public void setInProperties(Map<String, String> inProps) {
- this.inProperties = inProps;
- }
-
- public void setOutProperties(Map<String, String> outProps) {
- this.outProperties = outProps;
- }
-
- public void setInClassNames(List<String> classNames) {
- inClassesToHandle = classNames;
- }
-
- public boolean inClassCanBeHandled(String className) {
- return inClassesToHandle != null && inClassesToHandle.contains(className);
- }
-
- public void setOutClassNames(List<String> classNames) {
- outClassesToHandle = classNames;
- }
-
- public boolean outClassCanBeHandled(String className) {
- return outClassesToHandle != null && outClassesToHandle.contains(className);
- }
-
- protected Templates createTemplates(Templates templates,
- Map<String, Object> configuredParams,
- Map<String, String> outProps) {
- if (templates == null) {
- if (supportJaxbOnly) {
- return null;
- }
- LOG.severe("No template is available");
- throw ExceptionUtils.toInternalServerErrorException(null, null);
- }
-
- TemplatesImpl templ = new TemplatesImpl(templates, uriResolver);
- MessageContext mc = getContext();
- if (mc != null) {
- UriInfo ui = mc.getUriInfo();
- MultivaluedMap<String, String> params = ui.getPathParameters();
- for (Map.Entry<String, List<String>> entry : params.entrySet()) {
- String value = entry.getValue().get(0);
- int ind = value.indexOf(';');
- if (ind > 0) {
- value = value.substring(0, ind);
- }
- templ.setTransformerParameter(entry.getKey(), value);
- }
-
- List<PathSegment> segments = ui.getPathSegments();
- if (!segments.isEmpty()) {
- setTransformParameters(templ, segments.get(segments.size() - 1).getMatrixParameters());
- }
- setTransformParameters(templ, ui.getQueryParameters());
- templ.setTransformerParameter(ABSOLUTE_PATH_PARAMETER, ui.getAbsolutePath().toString());
- templ.setTransformerParameter(RELATIVE_PATH_PARAMETER, ui.getPath());
- templ.setTransformerParameter(BASE_PATH_PARAMETER, ui.getBaseUri().toString());
- if (configuredParams != null) {
- for (Map.Entry<String, Object> entry : configuredParams.entrySet()) {
- templ.setTransformerParameter(entry.getKey(), entry.getValue());
- }
- }
- }
- if (outProps != null) {
- templ.setOutProperties(outProps);
- }
-
- return templ;
- }
-
- private void setTransformParameters(TemplatesImpl templ, MultivaluedMap<String, String> params) {
- for (Map.Entry<String, List<String>> entry : params.entrySet()) {
- templ.setTransformerParameter(entry.getKey(), entry.getValue().get(0));
- }
- }
-
- protected Templates createTemplates(String loc) {
- try {
- return createTemplates(ResourceUtils.getResourceURL(loc, this.getBus()));
- } catch (Exception ex) {
- LOG.warning("No template can be created : " + ex.getMessage());
- }
- return null;
- }
-
- protected Templates createTemplatesFromContext() {
- MessageContext mc = getContext();
- if (mc != null) {
- String template = (String)mc.getContextualProperty(XSLT_TEMPLATE_PROPERTY);
- if (template != null) {
- return createTemplates(template);
- }
- }
- return null;
- }
-
- protected Templates createTemplates(URL urlStream) {
- if (urlStream == null) {
- return null;
- }
-
- try (Reader r = new BufferedReader(
- new InputStreamReader(urlStream.openStream(), StandardCharsets.UTF_8))) {
- Source source = new StreamSource(r);
- source.setSystemId(urlStream.toExternalForm());
- if (factory == null) {
- factory = (SAXTransformerFactory)TransformerFactory.newInstance();
- factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, secureProcessing);
- if (uriResolver != null) {
- factory.setURIResolver(uriResolver);
- }
- }
- return factory.newTemplates(source);
-
- } catch (Exception ex) {
- LOG.warning("No template can be created : " + ex.getMessage());
- }
- return null;
- }
-
- public void setRefreshTemplates(boolean refresh) {
- this.refreshTemplates = refresh;
- }
-
- public void setSecureProcessing(boolean secureProcessing) {
- this.secureProcessing = secureProcessing;
- }
-
- private static class TemplatesImpl implements Templates {
-
- private Templates templates;
- private URIResolver resolver;
- private Map<String, Object> transformParameters = new HashMap<>();
- private Map<String, String> outProps = new HashMap<>();
-
- TemplatesImpl(Templates templates, URIResolver resolver) {
- this.templates = templates;
- this.resolver = resolver;
- }
-
- public Templates getTemplates() {
- return templates;
- }
-
- public void setTransformerParameter(String name, Object value) {
- transformParameters.put(name, value);
- }
-
- public void setOutProperties(Map<String, String> props) {
- this.outProps = props;
- }
-
- public Properties getOutputProperties() {
- return templates.getOutputProperties();
- }
-
- public Transformer newTransformer() throws TransformerConfigurationException {
- Transformer tr = templates.newTransformer();
- tr.setURIResolver(resolver);
- for (Map.Entry<String, Object> entry : transformParameters.entrySet()) {
- tr.setParameter(entry.getKey(), entry.getValue());
- }
- for (Map.Entry<String, String> entry : outProps.entrySet()) {
- tr.setOutputProperty(entry.getKey(), entry.getValue());
- }
- return tr;
- }
-
- }
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxrs/security/JAASAuthenticationFilter.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxrs/security/JAASAuthenticationFilter.java
deleted file mode 100644
index 4dd05e3..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxrs/security/JAASAuthenticationFilter.java
+++ /dev/null
@@ -1,170 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.cxf.jaxrs.security;
-
-import java.net.URI;
-import java.util.Arrays;
-import java.util.List;
-
-import javax.annotation.Priority;
-import javax.security.auth.callback.CallbackHandler;
-import javax.security.auth.login.Configuration;
-import javax.ws.rs.Priorities;
-import javax.ws.rs.container.ContainerRequestContext;
-import javax.ws.rs.container.ContainerRequestFilter;
-import javax.ws.rs.container.PreMatching;
-import javax.ws.rs.core.HttpHeaders;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
-import javax.ws.rs.core.Response.ResponseBuilder;
-import javax.ws.rs.core.UriBuilder;
-
-import org.apache.cxf.interceptor.security.JAASLoginInterceptor;
-import org.apache.cxf.interceptor.security.NamePasswordCallbackHandler;
-import org.apache.cxf.jaxrs.impl.HttpHeadersImpl;
-import org.apache.cxf.jaxrs.utils.HttpUtils;
-import org.apache.cxf.jaxrs.utils.JAXRSUtils;
-import org.apache.cxf.message.Message;
-
-@PreMatching
-@Priority(Priorities.AUTHENTICATION)
-public class JAASAuthenticationFilter implements ContainerRequestFilter {
-
- private static final List<MediaType> HTML_MEDIA_TYPES =
- Arrays.asList(MediaType.APPLICATION_XHTML_XML_TYPE, MediaType.TEXT_HTML_TYPE);
-
- private URI redirectURI;
- private String realmName;
- private boolean ignoreBasePath = true;
-
- private JAASLoginInterceptor interceptor;
-
- public JAASAuthenticationFilter() {
- interceptor = new JAASLoginInterceptor() {
- protected CallbackHandler getCallbackHandler(String name, String password) {
- return JAASAuthenticationFilter.this.getCallbackHandler(name, password);
- }
- };
- interceptor.setUseDoAs(false);
- }
-
- @Deprecated
- public void setRolePrefix(String name) {
- interceptor.setRolePrefix(name);
- }
-
-
- public void setIgnoreBasePath(boolean ignore) {
- this.ignoreBasePath = ignore;
- }
-
- public void setContextName(String name) {
- interceptor.setContextName(name);
- }
-
- public void setLoginConfig(Configuration config) {
- interceptor.setLoginConfig(config);
- }
-
- public void setRoleClassifier(String rc) {
- interceptor.setRoleClassifier(rc);
- }
-
- public void setRoleClassifierType(String rct) {
- interceptor.setRoleClassifierType(rct);
- }
-
-
- public void setRedirectURI(String uri) {
- this.redirectURI = URI.create(uri);
- }
-
- public void setRealmName(String name) {
- this.realmName = name;
- }
-
- protected CallbackHandler getCallbackHandler(String name, String password) {
- return new NamePasswordCallbackHandler(name, password);
- }
-
- @Override
- public void filter(ContainerRequestContext context) {
- Message m = JAXRSUtils.getCurrentMessage();
- try {
- interceptor.handleMessage(m);
- } catch (SecurityException ex) {
- context.abortWith(handleAuthenticationException(ex, m));
- }
- }
-
- protected Response handleAuthenticationException(SecurityException ex, Message m) {
- HttpHeaders headers = new HttpHeadersImpl(m);
- if (redirectURI != null && isRedirectPossible(headers)) {
-
- final URI finalRedirectURI;
-
- if (!redirectURI.isAbsolute()) {
- String endpointAddress = HttpUtils.getEndpointAddress(m);
- Object basePathProperty = m.get(Message.BASE_PATH);
- if (ignoreBasePath && basePathProperty != null && !"/".equals(basePathProperty)) {
- int index = endpointAddress.lastIndexOf(basePathProperty.toString());
- if (index != -1) {
- endpointAddress = endpointAddress.substring(0, index);
- }
- }
- finalRedirectURI = UriBuilder.fromUri(endpointAddress).path(redirectURI.toString()).build();
- } else {
- finalRedirectURI = redirectURI;
- }
-
- return Response.status(getRedirectStatus()).
- header(HttpHeaders.LOCATION, finalRedirectURI).build();
- }
- ResponseBuilder builder = Response.status(Response.Status.UNAUTHORIZED);
-
- StringBuilder sb = new StringBuilder();
-
- List<String> authHeader = headers.getRequestHeader(HttpHeaders.AUTHORIZATION);
- if (authHeader != null && !authHeader.isEmpty()) {
- // should HttpHeadersImpl do it ?
- String[] authValues = authHeader.get(0).split(" ");
- if (authValues.length > 0) {
- sb.append(authValues[0]);
- }
- } else {
- sb.append("Basic");
- }
- if (realmName != null) {
- sb.append(" realm=\"").append(realmName).append('"');
- }
- builder.header(HttpHeaders.WWW_AUTHENTICATE, sb.toString());
-
- return builder.build();
- }
-
- protected Response.Status getRedirectStatus() {
- return Response.Status.TEMPORARY_REDIRECT;
- }
-
- protected boolean isRedirectPossible(HttpHeaders headers) {
- List<MediaType> clientTypes = headers.getAcceptableMediaTypes();
- return !JAXRSUtils.intersectMimeTypes(clientTypes, HTML_MEDIA_TYPES, false)
- .isEmpty();
- }
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxrs/security/KerberosAuthenticationFilter.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxrs/security/KerberosAuthenticationFilter.java
deleted file mode 100644
index 1c7a164..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxrs/security/KerberosAuthenticationFilter.java
+++ /dev/null
@@ -1,251 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.cxf.jaxrs.security;
-
-import java.security.PrivilegedActionException;
-import java.security.PrivilegedExceptionAction;
-import java.util.List;
-import java.util.logging.Logger;
-
-import javax.security.auth.Subject;
-import javax.security.auth.callback.CallbackHandler;
-import javax.security.auth.login.Configuration;
-import javax.security.auth.login.LoginContext;
-import javax.security.auth.login.LoginException;
-import javax.ws.rs.container.ContainerRequestContext;
-import javax.ws.rs.container.ContainerRequestFilter;
-import javax.ws.rs.container.PreMatching;
-import javax.ws.rs.core.Context;
-import javax.ws.rs.core.HttpHeaders;
-import javax.ws.rs.core.Response;
-
-import org.apache.cxf.common.logging.LogUtils;
-import org.apache.cxf.common.security.SimplePrincipal;
-import org.apache.cxf.common.security.SimpleSecurityContext;
-import org.apache.cxf.common.util.Base64Exception;
-import org.apache.cxf.common.util.Base64Utility;
-import org.apache.cxf.common.util.PropertyUtils;
-import org.apache.cxf.common.util.StringUtils;
-import org.apache.cxf.jaxrs.ext.MessageContext;
-import org.apache.cxf.jaxrs.utils.ExceptionUtils;
-import org.apache.cxf.jaxrs.utils.JAXRSUtils;
-import org.apache.cxf.message.Message;
-import org.apache.cxf.security.SecurityContext;
-import org.ietf.jgss.GSSContext;
-import org.ietf.jgss.GSSException;
-import org.ietf.jgss.GSSManager;
-import org.ietf.jgss.GSSName;
-import org.ietf.jgss.Oid;
-@PreMatching
-public class KerberosAuthenticationFilter implements ContainerRequestFilter {
-
- private static final Logger LOG = LogUtils.getL7dLogger(KerberosAuthenticationFilter.class);
-
- private static final String NEGOTIATE_SCHEME = "Negotiate";
- private static final String PROPERTY_USE_KERBEROS_OID = "auth.spnego.useKerberosOid";
- private static final String KERBEROS_OID = "1.2.840.113554.1.2.2";
- private static final String SPNEGO_OID = "1.3.6.1.5.5.2";
-
- private MessageContext messageContext;
- private CallbackHandler callbackHandler;
- private Configuration loginConfig;
- private String loginContextName = "";
- private String servicePrincipalName;
- private String realm;
-
- @Override
- public void filter(ContainerRequestContext context) {
-
- List<String> authHeaders = messageContext.getHttpHeaders()
- .getRequestHeader(HttpHeaders.AUTHORIZATION);
- if (authHeaders == null || authHeaders.size() != 1) {
- LOG.fine("No Authorization header is available");
- throw ExceptionUtils.toNotAuthorizedException(null, getFaultResponse());
- }
- String[] authPair = authHeaders.get(0).split(" ");
- if (authPair.length != 2 || !NEGOTIATE_SCHEME.equalsIgnoreCase(authPair[0])) {
- LOG.fine("Negotiate Authorization scheme is expected");
- throw ExceptionUtils.toNotAuthorizedException(null, getFaultResponse());
- }
-
- byte[] serviceTicket = getServiceTicket(authPair[1]);
-
- try {
- Subject serviceSubject = loginAndGetSubject();
-
- GSSContext gssContext = createGSSContext();
-
- Subject.doAs(serviceSubject, new ValidateServiceTicketAction(gssContext, serviceTicket));
-
- GSSName srcName = gssContext.getSrcName();
- if (srcName == null) {
- throw ExceptionUtils.toNotAuthorizedException(null, getFaultResponse());
- }
-
- String complexUserName = srcName.toString();
-
- String simpleUserName = complexUserName;
- int index = simpleUserName.lastIndexOf('@');
- if (index > 0) {
- simpleUserName = simpleUserName.substring(0, index);
- }
- Message m = JAXRSUtils.getCurrentMessage();
- m.put(SecurityContext.class, createSecurityContext(simpleUserName, complexUserName, gssContext));
-
- if (!gssContext.getCredDelegState()) {
- gssContext.dispose();
- }
-
- } catch (LoginException e) {
- LOG.fine("Unsuccessful JAAS login for the service principal: " + e.getMessage());
- throw ExceptionUtils.toNotAuthorizedException(e, getFaultResponse());
- } catch (GSSException e) {
- LOG.fine("GSS API exception: " + e.getMessage());
- throw ExceptionUtils.toNotAuthorizedException(e, getFaultResponse());
- } catch (PrivilegedActionException e) {
- LOG.fine("PrivilegedActionException: " + e.getMessage());
- throw ExceptionUtils.toNotAuthorizedException(e, getFaultResponse());
- }
- }
-
- protected SecurityContext createSecurityContext(String simpleUserName, String complexUserName,
- GSSContext gssContext) {
- return new KerberosSecurityContext(new KerberosPrincipal(simpleUserName, complexUserName), gssContext);
- }
-
- protected GSSContext createGSSContext() throws GSSException {
- boolean useKerberosOid = PropertyUtils.isTrue(
- messageContext.getContextualProperty(PROPERTY_USE_KERBEROS_OID));
- Oid oid = new Oid(useKerberosOid ? KERBEROS_OID : SPNEGO_OID);
-
- GSSManager gssManager = GSSManager.getInstance();
-
- String spn = getCompleteServicePrincipalName();
- GSSName gssService = gssManager.createName(spn, null);
-
- return gssManager.createContext(gssService.canonicalize(oid),
- oid, null, GSSContext.DEFAULT_LIFETIME);
- }
-
- protected Subject loginAndGetSubject() throws LoginException {
-
- // The login without a callback can work if
- // - Kerberos keytabs are used with a principal name set in the JAAS config
- // - Kerberos is integrated into the OS logon process
- // meaning that a process which runs this code has the
- // user identity
-
- final LoginContext lc;
- if (!StringUtils.isEmpty(loginContextName) || loginConfig != null) {
- lc = new LoginContext(loginContextName, null, callbackHandler, loginConfig);
- } else {
- LOG.fine("LoginContext can not be initialized");
- throw new LoginException();
- }
- lc.login();
- return lc.getSubject();
- }
-
- private byte[] getServiceTicket(String encodedServiceTicket) {
- try {
- return Base64Utility.decode(encodedServiceTicket);
- } catch (Base64Exception ex) {
- throw ExceptionUtils.toNotAuthorizedException(null, getFaultResponse());
- }
- }
-
- private static Response getFaultResponse() {
- return JAXRSUtils.toResponseBuilder(401).header(HttpHeaders.WWW_AUTHENTICATE, NEGOTIATE_SCHEME).build();
- }
-
- protected String getCompleteServicePrincipalName() {
- String name = servicePrincipalName == null
- ? "HTTP/" + messageContext.getUriInfo().getBaseUri().getHost() : servicePrincipalName;
- if (realm != null) {
- name += "@" + realm;
- }
- return name;
-
-
- }
-
- @Context
- public void setMessageContext(MessageContext context) {
- this.messageContext = context;
- }
-
- public void setLoginContextName(String contextName) {
- this.loginContextName = contextName;
- }
-
- public void setServicePrincipalName(String servicePrincipalName) {
- this.servicePrincipalName = servicePrincipalName;
- }
-
- public void setRealm(String realm) {
- this.realm = realm;
- }
-
- public void setCallbackHandler(CallbackHandler callbackHandler) {
- this.callbackHandler = callbackHandler;
- }
-
- private static final class ValidateServiceTicketAction implements PrivilegedExceptionAction<byte[]> {
- private final GSSContext context;
- private final byte[] token;
-
- private ValidateServiceTicketAction(GSSContext context, byte[] token) {
- this.context = context;
- this.token = token;
- }
-
- public byte[] run() throws GSSException {
- return context.acceptSecContext(token, 0, token.length);
- }
- }
-
- public static class KerberosPrincipal extends SimplePrincipal {
- private static final long serialVersionUID = 1L;
- private String complexName;
- public KerberosPrincipal(String simpleName, String complexName) {
- super(simpleName);
- this.complexName = complexName;
- }
-
- public String getKerberosName() {
- return complexName;
- }
- }
-
- public static class KerberosSecurityContext extends SimpleSecurityContext {
- private GSSContext context;
- public KerberosSecurityContext(KerberosPrincipal principal,
- GSSContext context) {
- super(principal);
- this.context = context;
- }
-
- public GSSContext getGSSContext() {
- return context;
- }
- }
-
-
-
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxrs/servlet/CXFNonSpringJaxrsServlet.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxrs/servlet/CXFNonSpringJaxrsServlet.java
deleted file mode 100644
index 290c223..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxrs/servlet/CXFNonSpringJaxrsServlet.java
+++ /dev/null
@@ -1,640 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.cxf.jaxrs.servlet;
-
-import java.lang.reflect.Constructor;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.logging.Logger;
-
-import javax.servlet.ServletConfig;
-import javax.servlet.ServletContext;
-import javax.servlet.ServletException;
-import javax.ws.rs.core.Application;
-
-import org.apache.cxf.Bus;
-import org.apache.cxf.common.classloader.ClassLoaderUtils;
-import org.apache.cxf.common.logging.LogUtils;
-import org.apache.cxf.common.util.PrimitiveUtils;
-import org.apache.cxf.common.util.PropertyUtils;
-import org.apache.cxf.common.util.StringUtils;
-import org.apache.cxf.feature.Feature;
-import org.apache.cxf.helpers.CastUtils;
-import org.apache.cxf.interceptor.Interceptor;
-import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;
-import org.apache.cxf.jaxrs.lifecycle.PerRequestResourceProvider;
-import org.apache.cxf.jaxrs.lifecycle.ResourceProvider;
-import org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider;
-import org.apache.cxf.jaxrs.model.ApplicationInfo;
-import org.apache.cxf.jaxrs.model.ProviderInfo;
-import org.apache.cxf.jaxrs.provider.ProviderFactory;
-import org.apache.cxf.jaxrs.utils.InjectionUtils;
-import org.apache.cxf.jaxrs.utils.ResourceUtils;
-import org.apache.cxf.message.Message;
-import org.apache.cxf.service.invoker.Invoker;
-import org.apache.cxf.transport.http.DestinationRegistry;
-import org.apache.cxf.transport.servlet.CXFNonSpringServlet;
-
-public class CXFNonSpringJaxrsServlet extends CXFNonSpringServlet {
-
- private static final long serialVersionUID = -8916352798780577499L;
-
- private static final Logger LOG = LogUtils.getL7dLogger(CXFNonSpringJaxrsServlet.class);
-
- private static final String USER_MODEL_PARAM = "user.model";
- private static final String SERVICE_ADDRESS_PARAM = "jaxrs.address";
- private static final String IGNORE_APP_PATH_PARAM = "jaxrs.application.address.ignore";
- private static final String SERVICE_CLASSES_PARAM = "jaxrs.serviceClasses";
- private static final String PROVIDERS_PARAM = "jaxrs.providers";
- private static final String FEATURES_PARAM = "jaxrs.features";
- private static final String OUT_INTERCEPTORS_PARAM = "jaxrs.outInterceptors";
- private static final String OUT_FAULT_INTERCEPTORS_PARAM = "jaxrs.outFaultInterceptors";
- private static final String IN_INTERCEPTORS_PARAM = "jaxrs.inInterceptors";
- private static final String INVOKER_PARAM = "jaxrs.invoker";
- private static final String SERVICE_SCOPE_PARAM = "jaxrs.scope";
- private static final String EXTENSIONS_PARAM = "jaxrs.extensions";
- private static final String LANGUAGES_PARAM = "jaxrs.languages";
- private static final String PROPERTIES_PARAM = "jaxrs.properties";
- private static final String SCHEMAS_PARAM = "jaxrs.schemaLocations";
- private static final String DOC_LOCATION_PARAM = "jaxrs.documentLocation";
- private static final String STATIC_SUB_RESOLUTION_PARAM = "jaxrs.static.subresources";
- private static final String SERVICE_SCOPE_SINGLETON = "singleton";
- private static final String SERVICE_SCOPE_REQUEST = "prototype";
-
- private static final String PARAMETER_SPLIT_CHAR = "class.parameter.split.char";
- private static final String DEFAULT_PARAMETER_SPLIT_CHAR = ",";
- private static final String SPACE_PARAMETER_SPLIT_CHAR = "space";
-
- private static final String JAXRS_APPLICATION_PARAM = "javax.ws.rs.Application";
-
- private ClassLoader classLoader;
- private Application application;
-
- public CXFNonSpringJaxrsServlet() {
-
- }
-
- public CXFNonSpringJaxrsServlet(Application app) {
- this.application = app;
- }
-
- public CXFNonSpringJaxrsServlet(Object singletonService) {
- this(Collections.singleton(singletonService));
- }
- public CXFNonSpringJaxrsServlet(Set<Object> applicationSingletons) {
- this(new ApplicationImpl(applicationSingletons));
- }
-
- public CXFNonSpringJaxrsServlet(Application app, DestinationRegistry destinationRegistry, Bus bus) {
- super(destinationRegistry, bus);
- this.application = app;
- }
-
- @Override
- public void init(ServletConfig servletConfig) throws ServletException {
- super.init(servletConfig);
-
- if (getApplication() != null) {
- createServerFromApplication(servletConfig);
- return;
- }
-
- String applicationClass = servletConfig.getInitParameter(JAXRS_APPLICATION_PARAM);
- if (applicationClass != null) {
- createServerFromApplication(applicationClass, servletConfig);
- return;
- }
-
- String splitChar = getParameterSplitChar(servletConfig);
- JAXRSServerFactoryBean bean = new JAXRSServerFactoryBean();
- bean.setBus(getBus());
-
- String address = servletConfig.getInitParameter(SERVICE_ADDRESS_PARAM);
- if (address == null) {
- address = "/";
- }
- bean.setAddress(address);
-
- bean.setStaticSubresourceResolution(getStaticSubResolutionValue(servletConfig));
-
- String modelRef = servletConfig.getInitParameter(USER_MODEL_PARAM);
- if (modelRef != null) {
- bean.setModelRef(modelRef.trim());
- }
- setDocLocation(bean, servletConfig);
- setSchemasLocations(bean, servletConfig);
- setAllInterceptors(bean, servletConfig, splitChar);
- setInvoker(bean, servletConfig);
-
- Map<Class<?>, Map<String, List<String>>> resourceClasses =
- getServiceClasses(servletConfig, modelRef != null, splitChar);
- Map<Class<?>, ResourceProvider> resourceProviders =
- getResourceProviders(servletConfig, resourceClasses);
-
- List<?> providers = getProviders(servletConfig, splitChar);
-
- bean.setResourceClasses(new ArrayList<Class<?>>(resourceClasses.keySet()));
- bean.setProviders(providers);
- for (Map.Entry<Class<?>, ResourceProvider> entry : resourceProviders.entrySet()) {
- bean.setResourceProvider(entry.getKey(), entry.getValue());
- }
- setExtensions(bean, servletConfig);
-
- List<? extends Feature> features = getFeatures(servletConfig, splitChar);
- bean.getFeatures().addAll(features);
-
- bean.create();
- }
-
- protected String getParameterSplitChar(ServletConfig servletConfig) {
- String param = servletConfig.getInitParameter(PARAMETER_SPLIT_CHAR);
- if (!StringUtils.isEmpty(param) && SPACE_PARAMETER_SPLIT_CHAR.equals(param.trim())) {
- return " ";
- }
- return DEFAULT_PARAMETER_SPLIT_CHAR;
- }
- protected boolean getStaticSubResolutionValue(ServletConfig servletConfig) {
- String param = servletConfig.getInitParameter(STATIC_SUB_RESOLUTION_PARAM);
- if (param != null) {
- return Boolean.valueOf(param.trim());
- }
- return false;
- }
-
- protected void setExtensions(JAXRSServerFactoryBean bean, ServletConfig servletConfig) {
- bean.setExtensionMappings(
- CastUtils.cast((Map<?, ?>)parseMapSequence(servletConfig.getInitParameter(EXTENSIONS_PARAM))));
- bean.setLanguageMappings(
- CastUtils.cast((Map<?, ?>)parseMapSequence(servletConfig.getInitParameter(LANGUAGES_PARAM))));
- Map<String, Object> properties = CastUtils.cast(
- parseMapSequence(servletConfig.getInitParameter(PROPERTIES_PARAM)),
- String.class, Object.class);
- if (properties != null) {
- bean.getProperties(true).putAll(properties);
- }
- }
-
- protected void setAllInterceptors(JAXRSServerFactoryBean bean, ServletConfig servletConfig,
- String splitChar)
- throws ServletException {
- setInterceptors(bean, servletConfig, OUT_INTERCEPTORS_PARAM, splitChar);
- setInterceptors(bean, servletConfig, OUT_FAULT_INTERCEPTORS_PARAM, splitChar);
- setInterceptors(bean, servletConfig, IN_INTERCEPTORS_PARAM, splitChar);
- }
-
- protected void setSchemasLocations(JAXRSServerFactoryBean bean, ServletConfig servletConfig) {
- String schemas = servletConfig.getInitParameter(SCHEMAS_PARAM);
- if (schemas == null) {
- return;
- }
- String[] locations = schemas.split(" ");
- List<String> list = new ArrayList<>();
- for (String loc : locations) {
- String theLoc = loc.trim();
- if (!theLoc.isEmpty()) {
- list.add(theLoc);
- }
- }
- if (!list.isEmpty()) {
- bean.setSchemaLocations(list);
- }
- }
-
- protected void setDocLocation(JAXRSServerFactoryBean bean, ServletConfig servletConfig) {
- String wadlLoc = servletConfig.getInitParameter(DOC_LOCATION_PARAM);
- if (wadlLoc != null) {
- bean.setDocLocation(wadlLoc);
- }
- }
-
- @SuppressWarnings("unchecked")
- protected void setInterceptors(JAXRSServerFactoryBean bean, ServletConfig servletConfig,
- String paramName,
- String splitChar) throws ServletException {
- String value = servletConfig.getInitParameter(paramName);
- if (value == null) {
- return;
- }
- String[] values = value.split(splitChar);
- List<Interceptor<? extends Message>> list = new ArrayList<>();
- for (String interceptorVal : values) {
- Map<String, List<String>> props = new HashMap<>();
- String theValue = getClassNameAndProperties(interceptorVal, props);
- if (!theValue.isEmpty()) {
- try {
- Class<?> intClass = loadClass(theValue, "Interceptor");
- Object object = intClass.newInstance();
- injectProperties(object, props);
- list.add((Interceptor<? extends Message>)object);
- } catch (ServletException ex) {
- throw ex;
- } catch (Exception ex) {
- LOG.warning("Interceptor class " + theValue + " can not be created");
- throw new ServletException(ex);
- }
- }
- }
- if (!list.isEmpty()) {
- if (OUT_INTERCEPTORS_PARAM.equals(paramName)) {
- bean.setOutInterceptors(list);
- } else if (OUT_FAULT_INTERCEPTORS_PARAM.equals(paramName)) {
- bean.setOutFaultInterceptors(list);
- } else {
- bean.setInInterceptors(list);
- }
- }
- }
-
- protected void setInvoker(JAXRSServerFactoryBean bean, ServletConfig servletConfig)
- throws ServletException {
- String value = servletConfig.getInitParameter(INVOKER_PARAM);
- if (value == null) {
- return;
- }
- Map<String, List<String>> props = new HashMap<>();
- String theValue = getClassNameAndProperties(value, props);
- if (!theValue.isEmpty()) {
- try {
- Class<?> intClass = loadClass(theValue, "Invoker");
- Object object = intClass.newInstance();
- injectProperties(object, props);
- bean.setInvoker((Invoker)object);
- } catch (ServletException ex) {
- throw ex;
- } catch (Exception ex) {
- LOG.warning("Invoker class " + theValue + " can not be created");
- throw new ServletException(ex);
- }
- }
-
-
- }
-
- protected Map<Class<?>, Map<String, List<String>>> getServiceClasses(ServletConfig servletConfig,
- boolean modelAvailable,
- String splitChar) throws ServletException {
- String serviceBeans = servletConfig.getInitParameter(SERVICE_CLASSES_PARAM);
- if (serviceBeans == null) {
- if (modelAvailable) {
- return Collections.emptyMap();
- }
- throw new ServletException("At least one resource class should be specified");
- }
- String[] classNames = serviceBeans.split(splitChar);
- Map<Class<?>, Map<String, List<String>>> map = new HashMap<>();
- for (String cName : classNames) {
- Map<String, List<String>> props = new HashMap<>();
- String theName = getClassNameAndProperties(cName, props);
- if (!theName.isEmpty()) {
- Class<?> cls = loadClass(theName);
- map.put(cls, props);
- }
- }
- if (map.isEmpty()) {
- throw new ServletException("At least one resource class should be specified");
- }
- return map;
- }
-
- protected List<? extends Feature> getFeatures(ServletConfig servletConfig, String splitChar)
- throws ServletException {
-
- String featuresList = servletConfig.getInitParameter(FEATURES_PARAM);
- if (featuresList == null) {
- return Collections.< Feature >emptyList();
- }
- String[] classNames = featuresList.split(splitChar);
- List< Feature > features = new ArrayList<>();
- for (String cName : classNames) {
- Map<String, List<String>> props = new HashMap<>();
- String theName = getClassNameAndProperties(cName, props);
- if (!theName.isEmpty()) {
- Class<?> cls = loadClass(theName);
- if (Feature.class.isAssignableFrom(cls)) {
- features.add((Feature)createSingletonInstance(cls, props, servletConfig));
- }
- }
- }
- return features;
- }
-
- protected List<?> getProviders(ServletConfig servletConfig, String splitChar) throws ServletException {
- String providersList = servletConfig.getInitParameter(PROVIDERS_PARAM);
- if (providersList == null) {
- return Collections.emptyList();
- }
- String[] classNames = providersList.split(splitChar);
- List<Object> providers = new ArrayList<>();
- for (String cName : classNames) {
- Map<String, List<String>> props = new HashMap<>();
- String theName = getClassNameAndProperties(cName, props);
- if (!theName.isEmpty()) {
- Class<?> cls = loadClass(theName);
- providers.add(createSingletonInstance(cls, props, servletConfig));
- }
- }
- return providers;
- }
-
- private String getClassNameAndProperties(String cName, Map<String, List<String>> props) {
- String theName = cName.trim();
- int ind = theName.indexOf('(');
- if (ind != -1 && theName.endsWith(")")) {
- props.putAll(parseMapListSequence(theName.substring(ind + 1, theName.length() - 1)));
- theName = theName.substring(0, ind).trim();
- }
- return theName;
- }
-
- protected static Map<String, List<String>> parseMapListSequence(String sequence) {
- if (sequence != null) {
- sequence = sequence.trim();
- Map<String, List<String>> map = new HashMap<>();
- String[] pairs = sequence.split(" ");
- for (String pair : pairs) {
- String thePair = pair.trim();
- if (thePair.length() == 0) {
- continue;
- }
- String[] values = thePair.split("=");
- String key;
- String value;
- if (values.length == 2) {
- key = values[0].trim();
- value = values[1].trim();
- } else {
- key = thePair;
- value = "";
- }
- List<String> list = map.get(key);
- if (list == null) {
- list = new LinkedList<>();
- map.put(key, list);
- }
- list.add(value);
- }
- return map;
- }
- return Collections.emptyMap();
- }
-
- protected Map<Class<?>, ResourceProvider> getResourceProviders(ServletConfig servletConfig,
- Map<Class<?>, Map<String, List<String>>> resourceClasses) throws ServletException {
- String scope = servletConfig.getInitParameter(SERVICE_SCOPE_PARAM);
- if (scope != null && !SERVICE_SCOPE_SINGLETON.equals(scope)
- && !SERVICE_SCOPE_REQUEST.equals(scope)) {
- throw new ServletException("Only singleton and prototype scopes are supported");
- }
- boolean isPrototype = SERVICE_SCOPE_REQUEST.equals(scope);
- Map<Class<?>, ResourceProvider> map = new HashMap<>();
- for (Map.Entry<Class<?>, Map<String, List<String>>> entry : resourceClasses.entrySet()) {
- Class<?> c = entry.getKey();
- map.put(c, isPrototype ? new PerRequestResourceProvider(c)
- : new SingletonResourceProvider(
- createSingletonInstance(c, entry.getValue(), servletConfig),
- true));
- }
- return map;
- }
-
- protected boolean isAppResourceLifecycleASingleton(Application app, ServletConfig servletConfig) {
- String scope = servletConfig.getInitParameter(SERVICE_SCOPE_PARAM);
- if (scope == null) {
- scope = (String)app.getProperties().get(SERVICE_SCOPE_PARAM);
- }
- return SERVICE_SCOPE_SINGLETON.equals(scope);
- }
-
- protected Object createSingletonInstance(Class<?> cls, Map<String, List<String>> props, ServletConfig sc)
- throws ServletException {
- Constructor<?> c = ResourceUtils.findResourceConstructor(cls, false);
- if (c == null) {
- throw new ServletException("No valid constructor found for " + cls.getName());
- }
- boolean isApplication = Application.class.isAssignableFrom(c.getDeclaringClass());
- try {
- final ProviderInfo<? extends Object> provider;
- if (c.getParameterTypes().length == 0) {
- if (isApplication) {
- provider = new ApplicationInfo((Application)c.newInstance(), getBus());
- } else {
- provider = new ProviderInfo<>(c.newInstance(), getBus(), false, true);
- }
- } else {
- Map<Class<?>, Object> values = new HashMap<>();
- values.put(ServletContext.class, sc.getServletContext());
- values.put(ServletConfig.class, sc);
- provider = ProviderFactory.createProviderFromConstructor(c, values, getBus(), isApplication, true);
- }
- Object instance = provider.getProvider();
- injectProperties(instance, props);
- configureSingleton(instance);
- return isApplication ? provider : instance;
- } catch (InstantiationException ex) {
- ex.printStackTrace();
- throw new ServletException("Resource class " + cls.getName()
- + " can not be instantiated");
- } catch (IllegalAccessException ex) {
- ex.printStackTrace();
- throw new ServletException("Resource class " + cls.getName()
- + " can not be instantiated due to IllegalAccessException");
- } catch (InvocationTargetException ex) {
- ex.printStackTrace();
- throw new ServletException("Resource class " + cls.getName()
- + " can not be instantiated due to InvocationTargetException");
- }
- }
-
- private void injectProperties(Object instance, Map<String, List<String>> props) {
- if (props == null || props.isEmpty()) {
- return;
- }
- Method[] methods = instance.getClass().getMethods();
- Map<String, Method> methodsMap = new HashMap<>();
- for (Method m : methods) {
- methodsMap.put(m.getName(), m);
- }
- for (Map.Entry<String, List<String>> entry : props.entrySet()) {
- Method m = methodsMap.get("set" + StringUtils.capitalize(entry.getKey()));
- if (m != null) {
- Class<?> type = m.getParameterTypes()[0];
- Object value;
- if (InjectionUtils.isPrimitive(type)) {
- value = PrimitiveUtils.read(entry.getValue().get(0), type);
- } else {
- value = entry.getValue();
- }
- InjectionUtils.injectThroughMethod(instance, m, value);
- }
- }
- }
-
- protected void configureSingleton(Object instance) {
-
- }
-
- protected void createServerFromApplication(String applicationNames, ServletConfig servletConfig)
- throws ServletException {
-
- boolean ignoreApplicationPath = isIgnoreApplicationPath(servletConfig);
-
- String[] classNames = applicationNames.split(getParameterSplitChar(servletConfig));
-
- if (classNames.length > 1 && ignoreApplicationPath) {
- throw new ServletException("\"" + IGNORE_APP_PATH_PARAM
- + "\" parameter must be set to false for multiple Applications be supported");
- }
-
- for (String cName : classNames) {
- ApplicationInfo providerApp = createApplicationInfo(cName, servletConfig);
-
- Application app = providerApp.getProvider();
- JAXRSServerFactoryBean bean = ResourceUtils.createApplication(
- app,
- ignoreApplicationPath,
- getStaticSubResolutionValue(servletConfig),
- isAppResourceLifecycleASingleton(app, servletConfig),
- getBus());
- String splitChar = getParameterSplitChar(servletConfig);
- setAllInterceptors(bean, servletConfig, splitChar);
- setInvoker(bean, servletConfig);
- setExtensions(bean, servletConfig);
- setDocLocation(bean, servletConfig);
- setSchemasLocations(bean, servletConfig);
-
- List<?> providers = getProviders(servletConfig, splitChar);
- bean.setProviders(providers);
- List<? extends Feature> features = getFeatures(servletConfig, splitChar);
- bean.getFeatures().addAll(features);
-
- bean.setBus(getBus());
- bean.setApplicationInfo(providerApp);
- bean.create();
- }
- }
-
- protected boolean isIgnoreApplicationPath(ServletConfig servletConfig) {
- String ignoreParam = servletConfig.getInitParameter(IGNORE_APP_PATH_PARAM);
- return ignoreParam == null || PropertyUtils.isTrue(ignoreParam);
- }
-
- protected void createServerFromApplication(ServletConfig servletConfig)
- throws ServletException {
-
- Application app = getApplication();
- JAXRSServerFactoryBean bean = ResourceUtils.createApplication(
- app,
- isIgnoreApplicationPath(servletConfig),
- getStaticSubResolutionValue(servletConfig),
- isAppResourceLifecycleASingleton(app, servletConfig),
- getBus());
- String splitChar = getParameterSplitChar(servletConfig);
- setAllInterceptors(bean, servletConfig, splitChar);
- setInvoker(bean, servletConfig);
- setExtensions(bean, servletConfig);
- setDocLocation(bean, servletConfig);
- setSchemasLocations(bean, servletConfig);
-
- List<?> providers = getProviders(servletConfig, splitChar);
- bean.setProviders(providers);
- List<? extends Feature> features = getFeatures(servletConfig, splitChar);
- bean.getFeatures().addAll(features);
-
- bean.setBus(getBus());
- bean.setApplication(getApplication());
- bean.create();
- }
-
- protected Application createApplicationInstance(String appClassName, ServletConfig servletConfig)
- throws ServletException {
- return null;
- }
- protected ApplicationInfo createApplicationInfo(String appClassName, ServletConfig servletConfig)
- throws ServletException {
-
- Application customApp = createApplicationInstance(appClassName, servletConfig);
- if (customApp != null) {
- return new ApplicationInfo(customApp, getBus());
- }
- Map<String, List<String>> props = new HashMap<>();
- appClassName = getClassNameAndProperties(appClassName, props);
- Class<?> appClass = loadApplicationClass(appClassName);
- ApplicationInfo appInfo = (ApplicationInfo)createSingletonInstance(appClass, props, servletConfig);
- Map<String, Object> servletProps = new HashMap<>();
- ServletContext servletContext = servletConfig.getServletContext();
- for (Enumeration<String> names = servletContext.getInitParameterNames(); names.hasMoreElements();) {
- String name = names.nextElement();
- servletProps.put(name, servletContext.getInitParameter(name));
- }
- for (Enumeration<String> names = servletConfig.getInitParameterNames(); names.hasMoreElements();) {
- String name = names.nextElement();
- servletProps.put(name, servletConfig.getInitParameter(name));
- }
- appInfo.setOverridingProps(servletProps);
- return appInfo;
- }
-
- protected Class<?> loadApplicationClass(String appClassName) throws ServletException {
- return loadClass(appClassName, "Application");
- }
-
- protected Class<?> loadClass(String cName) throws ServletException {
- return loadClass(cName, "Resource");
- }
-
- protected Class<?> loadClass(String cName, String classType) throws ServletException {
- try {
- final Class<?> cls;
- if (classLoader == null) {
- cls = ClassLoaderUtils.loadClass(cName, CXFNonSpringJaxrsServlet.class);
- } else {
- cls = classLoader.loadClass(cName);
- }
- return cls;
- } catch (ClassNotFoundException ex) {
- throw new ServletException("No " + classType + " class " + cName.trim() + " can be found", ex);
- }
- }
-
- public void setClassLoader(ClassLoader loader) {
- this.classLoader = loader;
- }
-
- protected Application getApplication() {
- return application;
- }
-
- private static class ApplicationImpl extends Application {
- private Set<Object> applicationSingletons;
- ApplicationImpl(Set<Object> applicationSingletons) {
- this.applicationSingletons = applicationSingletons;
- }
- public Set<Object> getSingletons() {
- return applicationSingletons;
- }
- }
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxrs/spring/JAXRSServerFactoryBeanDefinitionParser.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxrs/spring/JAXRSServerFactoryBeanDefinitionParser.java
deleted file mode 100644
index 2115f6d..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxrs/spring/JAXRSServerFactoryBeanDefinitionParser.java
+++ /dev/null
@@ -1,286 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.cxf.jaxrs.spring;
-
-import java.io.IOException;
-import java.lang.annotation.Annotation;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-import java.util.logging.Logger;
-
-import javax.ws.rs.Path;
-import javax.ws.rs.ext.Provider;
-import javax.xml.namespace.QName;
-
-import org.w3c.dom.Element;
-
-import org.apache.cxf.bus.spring.BusWiringBeanFactoryPostProcessor;
-import org.apache.cxf.common.classloader.ClassLoaderUtils;
-import org.apache.cxf.common.logging.LogUtils;
-import org.apache.cxf.common.util.ClasspathScanner;
-import org.apache.cxf.common.util.StringUtils;
-import org.apache.cxf.configuration.spring.AbstractBeanDefinitionParser;
-import org.apache.cxf.endpoint.Server;
-import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;
-import org.apache.cxf.jaxrs.JAXRSServiceFactoryBean;
-import org.apache.cxf.jaxrs.lifecycle.ResourceProvider;
-import org.apache.cxf.jaxrs.model.UserResource;
-import org.apache.cxf.jaxrs.utils.ExceptionUtils;
-import org.apache.cxf.jaxrs.utils.ResourceUtils;
-import org.springframework.beans.BeansException;
-import org.springframework.beans.factory.BeanCreationException;
-import org.springframework.beans.factory.BeanDefinitionStoreException;
-import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
-import org.springframework.beans.factory.support.AbstractBeanDefinition;
-import org.springframework.beans.factory.support.BeanDefinitionBuilder;
-import org.springframework.beans.factory.xml.ParserContext;
-import org.springframework.context.ApplicationContext;
-import org.springframework.context.ApplicationContextAware;
-
-
-
-public class JAXRSServerFactoryBeanDefinitionParser extends AbstractBeanDefinitionParser {
- private static final Logger LOG = LogUtils.getL7dLogger(JAXRSServerFactoryBeanDefinitionParser.class);
-
- public JAXRSServerFactoryBeanDefinitionParser() {
- super();
- setBeanClass(SpringJAXRSServerFactoryBean.class);
- }
-
- @Override
- protected void mapAttribute(BeanDefinitionBuilder bean, Element e, String name, String val) {
- if ("beanNames".equals(name)) {
- String[] values = val.split(" ");
- List<SpringResourceFactory> tempFactories = new ArrayList<>(values.length);
- for (String v : values) {
- String theValue = v.trim();
- if (theValue.length() > 0) {
- tempFactories.add(new SpringResourceFactory(theValue));
- }
- }
- bean.addPropertyValue("tempResourceProviders", tempFactories);
- } else if ("serviceName".equals(name)) {
- QName q = parseQName(e, val);
- bean.addPropertyValue(name, q);
- } else if ("basePackages".equals(name)) {
- bean.addPropertyValue("basePackages", ClasspathScanner.parsePackages(val));
- } else if ("serviceAnnotation".equals(name)) {
- bean.addPropertyValue("serviceAnnotation", val);
- } else if ("publish".equals(name)) {
- mapToProperty(bean, "start", val);
- } else {
- mapToProperty(bean, name, val);
- }
- }
-
- @Override
- protected void mapElement(ParserContext ctx, BeanDefinitionBuilder bean, Element el, String name) {
- if ("properties".equals(name)
- || "extensionMappings".equals(name)
- || "languageMappings".equals(name)) {
- Map<?, ?> map = ctx.getDelegate().parseMapElement(el, bean.getBeanDefinition());
- bean.addPropertyValue(name, map);
- } else if ("executor".equals(name)) {
- setFirstChildAsProperty(el, ctx, bean, "serviceFactory.executor");
- } else if ("invoker".equals(name)) {
- setFirstChildAsProperty(el, ctx, bean, "serviceFactory.invoker");
- } else if ("binding".equals(name)) {
- setFirstChildAsProperty(el, ctx, bean, "bindingConfig");
- } else if ("inInterceptors".equals(name) || "inFaultInterceptors".equals(name)
- || "outInterceptors".equals(name) || "outFaultInterceptors".equals(name)) {
- List<?> list = ctx.getDelegate().parseListElement(el, bean.getBeanDefinition());
- bean.addPropertyValue(name, list);
- } else if ("features".equals(name) || "schemaLocations".equals(name)
- || "providers".equals(name) || "serviceBeans".equals(name)
- || "modelBeans".equals(name)) {
- List<?> list = ctx.getDelegate().parseListElement(el, bean.getBeanDefinition());
- bean.addPropertyValue(name, list);
- } else if ("serviceFactories".equals(name)) {
- List<?> list = ctx.getDelegate().parseListElement(el, bean.getBeanDefinition());
- bean.addPropertyValue("resourceProviders", list);
- } else if ("model".equals(name)) {
- List<UserResource> resources = ResourceUtils.getResourcesFromElement(el);
- bean.addPropertyValue("modelBeans", resources);
- } else {
- setFirstChildAsProperty(el, ctx, bean, name);
- }
- }
-
-
- @Override
- protected void doParse(Element element, ParserContext ctx, BeanDefinitionBuilder bean) {
- super.doParse(element, ctx, bean);
-
- bean.setInitMethodName("create");
- bean.setDestroyMethodName("destroy");
-
- // We don't really want to delay the registration of our Server
- bean.setLazyInit(false);
- }
-
- @Override
- protected String resolveId(Element elem,
- AbstractBeanDefinition definition,
- ParserContext ctx)
- throws BeanDefinitionStoreException {
- String id = super.resolveId(elem, definition, ctx);
- if (StringUtils.isEmpty(id)) {
- id = getBeanClass().getName() + "--" + definition.hashCode();
- }
-
- return id;
- }
-
- @Override
- protected boolean hasBusProperty() {
- return true;
- }
-
- public static class SpringJAXRSServerFactoryBean extends JAXRSServerFactoryBean implements
- ApplicationContextAware {
-
- private List<SpringResourceFactory> tempFactories;
- private List<String> basePackages;
- private String serviceAnnotation;
- private ApplicationContext context;
- private boolean serviceBeansAvailable;
- private boolean providerBeansAvailable;
- private boolean resourceProvidersAvailable;
-
- public SpringJAXRSServerFactoryBean() {
- super();
- }
-
- public SpringJAXRSServerFactoryBean(JAXRSServiceFactoryBean sf) {
- super(sf);
- }
-
- public void destroy() {
- Server server = super.getServer();
- if (server != null && server.isStarted()) {
- server.destroy();
- }
- }
- @Override
- public void setServiceBeans(List<Object> beans) {
- super.setServiceBeans(beans);
- this.serviceBeansAvailable = true;
- }
- @Override
- public void setProviders(List<? extends Object> beans) {
- super.setProviders(beans);
- this.providerBeansAvailable = true;
- }
- public void setResourceProviders(List<ResourceProvider> rps) {
- super.setResourceProviders(rps);
- this.resourceProvidersAvailable = true;
- }
- public void setBasePackages(List<String> basePackages) {
- this.basePackages = basePackages;
- }
-
- public void setServiceAnnotation(String serviceAnnotation) {
- this.serviceAnnotation = serviceAnnotation;
- }
-
- public void setTempResourceProviders(List<SpringResourceFactory> providers) {
- tempFactories = providers;
- }
-
- public void setApplicationContext(ApplicationContext ctx) throws BeansException {
- this.context = ctx;
-
- if (tempFactories != null) {
- List<ResourceProvider> factories = new ArrayList<>(
- tempFactories.size());
- for (int i = 0; i < tempFactories.size(); i++) {
- SpringResourceFactory factory = tempFactories.get(i);
- factory.setApplicationContext(ctx);
- factories.add(factory);
- }
- tempFactories.clear();
- setResourceProviders(factories);
- }
- Class<? extends Annotation> serviceAnnotationClass = loadServiceAnnotationClass();
- if (basePackages != null) {
- try {
- final Map< Class< ? extends Annotation >, Collection< Class< ? > > > classes =
- ClasspathScanner.findClasses(basePackages, Provider.class, Path.class);
-
- this.setServiceBeans(createBeansFromDiscoveredClasses(context,
- classes.get(Path.class),
- serviceAnnotationClass));
- this.setProviders(createBeansFromDiscoveredClasses(context,
- classes.get(Provider.class),
- serviceAnnotationClass));
- } catch (IOException ex) {
- throw new BeanDefinitionStoreException("I/O failure during classpath scanning", ex);
- } catch (ClassNotFoundException ex) {
- throw new BeanCreationException("Failed to create bean from classfile", ex);
- }
- } else if (serviceAnnotationClass != null
- && !serviceBeansAvailable && !providerBeansAvailable && !resourceProvidersAvailable) {
- discoverContextResources(serviceAnnotationClass);
- }
- if (bus == null) {
- setBus(BusWiringBeanFactoryPostProcessor.addDefaultBus(ctx));
- }
- }
- private void discoverContextResources(Class<? extends Annotation> serviceAnnotationClass) {
- AbstractSpringComponentScanServer scanServer =
- new AbstractSpringComponentScanServer(serviceAnnotationClass) { };
- scanServer.setApplicationContext(context);
- scanServer.setJaxrsResources(this);
- }
- @SuppressWarnings("unchecked")
- private Class<? extends Annotation> loadServiceAnnotationClass() {
- if (serviceAnnotation != null) {
- try {
- return (Class<? extends Annotation>)ClassLoaderUtils.loadClass(serviceAnnotation, this.getClass());
- } catch (Exception ex) {
- throw new RuntimeException(ex);
- }
- }
- return null;
- }
- }
- static List<Object> createBeansFromDiscoveredClasses(ApplicationContext context,
- Collection<Class<?>> classes,
- Class<? extends Annotation> serviceClassAnnotation) {
- AutowireCapableBeanFactory beanFactory = context.getAutowireCapableBeanFactory();
- final List< Object > providers = new ArrayList<>();
- for (final Class< ? > clazz: classes) {
- if (serviceClassAnnotation != null && clazz.getAnnotation(serviceClassAnnotation) == null) {
- continue;
- }
- Object bean;
- try {
- bean = beanFactory.createBean(clazz, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, true);
- } catch (Exception ex) {
- String stackTrace = ExceptionUtils.getStackTrace(ex);
- LOG.fine("Autowire failure for a " + clazz.getName() + " bean: " + stackTrace);
- bean = beanFactory.createBean(clazz);
- }
- providers.add(bean);
- }
- return providers;
- }
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxrs/utils/AnnotationUtils.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxrs/utils/AnnotationUtils.java
deleted file mode 100644
index 8d49e2d..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxrs/utils/AnnotationUtils.java
+++ /dev/null
@@ -1,308 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.cxf.jaxrs.utils;
-
-import java.lang.annotation.Annotation;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.LinkedHashSet;
-import java.util.Set;
-import java.util.logging.Logger;
-
-import javax.ws.rs.BeanParam;
-import javax.ws.rs.Consumes;
-import javax.ws.rs.CookieParam;
-import javax.ws.rs.DefaultValue;
-import javax.ws.rs.FormParam;
-import javax.ws.rs.HeaderParam;
-import javax.ws.rs.HttpMethod;
-import javax.ws.rs.MatrixParam;
-import javax.ws.rs.NameBinding;
-import javax.ws.rs.Path;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.Priorities;
-import javax.ws.rs.Produces;
-import javax.ws.rs.QueryParam;
-import javax.ws.rs.core.Context;
-
-import org.apache.cxf.Bus;
-import org.apache.cxf.common.logging.LogUtils;
-import org.apache.cxf.common.util.ClassHelper;
-
-public final class AnnotationUtils {
- private static final Logger LOG = LogUtils.getL7dLogger(AnnotationUtils.class);
- private static final Class<? extends Annotation> PRIORITY_API =
- (Class<? extends Annotation>) loadClassOrNull("javax.annotation.Priority");
- private static final Method PRIORITY_VALUE = getMethodOrNull(PRIORITY_API, "value");
-
- private static final Set<Class<?>> PARAM_ANNOTATION_CLASSES;
- private static final Set<Class<?>> METHOD_ANNOTATION_CLASSES;
- static {
- PARAM_ANNOTATION_CLASSES = initParamAnnotationClasses();
- METHOD_ANNOTATION_CLASSES = initMethodAnnotationClasses();
- }
-
- private AnnotationUtils() {
-
- }
-
- private static Method getMethodOrNull(final Class<?> type, final String name) {
- if (type == null) {
- return null;
- }
- try {
- return type.getMethod(name);
- } catch (final NoSuchMethodException e) {
- return null;
- }
- }
-
- private static Class<? extends Annotation> loadClassOrNull(final String name) {
- try {
- return org.apache.cxf.common.classloader.ClassLoaderUtils.loadClass(
- name, AnnotationUtils.class, Annotation.class);
- } catch (final ClassNotFoundException e) {
- return null;
- }
- }
-
- private static Set<Class<?>> initParamAnnotationClasses() {
- Set<Class<?>> classes = new HashSet<>();
- classes.add(PathParam.class);
- classes.add(QueryParam.class);
- classes.add(MatrixParam.class);
- classes.add(HeaderParam.class);
- classes.add(CookieParam.class);
- classes.add(FormParam.class);
- classes.add(BeanParam.class);
- return classes;
- }
-
- private static Set<Class<?>> initMethodAnnotationClasses() {
- Set<Class<?>> classes = new HashSet<>();
- classes.add(HttpMethod.class);
- classes.add(Path.class);
- classes.add(Produces.class);
- classes.add(Consumes.class);
- return classes;
- }
-
- public static int getBindingPriority(Class<?> providerCls) {
- if (PRIORITY_API == null) {
- return Priorities.USER;
- }
- Annotation b = getClassAnnotation(providerCls, PRIORITY_API);
- try {
- return b == null ? Priorities.USER : Integer.class.cast(PRIORITY_VALUE.invoke(b));
- } catch (final IllegalAccessException | InvocationTargetException e) {
- return Priorities.USER;
- }
- }
-
- public static Set<String> getInstanceNameBindings(Bus bus, Object obj) {
- final Class<?> realClazz = ClassHelper.getRealClass(bus, obj);
- return getNameBindings(realClazz.getAnnotations());
- }
-
- public static Set<String> getNameBindings(Bus bus, Class<?> clazz) {
- final Class<?> realClazz = ClassHelper.getRealClassFromClass(bus, clazz);
- return getNameBindings(realClazz.getAnnotations());
- }
-
- public static Set<String> getNameBindings(Annotation[] targetAnns) {
- if (targetAnns.length == 0) {
- return Collections.emptySet();
- }
- Set<String> names = new LinkedHashSet<>();
- for (Annotation a : targetAnns) {
- NameBinding nb = a.annotationType().getAnnotation(NameBinding.class);
- if (nb != null) {
- names.add(a.annotationType().getName());
- }
- }
- return names;
- }
-
- public static boolean isParamAnnotationClass(Class<?> annotationClass) {
- return PARAM_ANNOTATION_CLASSES.contains(annotationClass);
- }
-
- public static boolean isValidParamAnnotationClass(Class<?> annotationClass) {
- return PARAM_ANNOTATION_CLASSES.contains(annotationClass) || Context.class == annotationClass;
- }
-
- public static boolean isValidParamAnnotations(Annotation[] paramAnnotations) {
- for (Annotation a : paramAnnotations) {
- if (AnnotationUtils.isValidParamAnnotationClass(a.annotationType())) {
- return true;
- }
- }
- return false;
- }
-
- public static boolean isMethodAnnotation(Annotation a) {
- return METHOD_ANNOTATION_CLASSES.contains(a.annotationType())
- || a.annotationType().getAnnotation(HttpMethod.class) != null;
- }
-
- public static String getAnnotationValue(Annotation a) {
- String value = null;
- if (a.annotationType() == PathParam.class) {
- value = ((PathParam)a).value();
- } else if (a.annotationType() == QueryParam.class) {
- value = ((QueryParam)a).value();
- } else if (a.annotationType() == MatrixParam.class) {
- value = ((MatrixParam)a).value();
- } else if (a.annotationType() == HeaderParam.class) {
- value = ((HeaderParam)a).value();
- } else if (a.annotationType() == CookieParam.class) {
- value = ((CookieParam)a).value();
- } else if (a.annotationType() == FormParam.class) {
- value = ((FormParam)a).value();
- }
- return value;
- }
-
- public static <T> T getAnnotation(Annotation[] anns, Class<T> type) {
- if (anns == null) {
- return null;
- }
- for (Annotation a : anns) {
- if (a.annotationType() == type) {
- return type.cast(a);
- }
- }
- return null;
- }
-
- public static Method getAnnotatedMethod(Class<?> serviceClass, Method m) {
- Method annotatedMethod = doGetAnnotatedMethod(serviceClass, m);
- return annotatedMethod == null ? m : annotatedMethod;
- }
-
- private static Method doGetAnnotatedMethod(Class<?> serviceClass, Method m) {
-
- if (m != null) {
- if (!m.isBridge() && !m.isSynthetic()) {
- //the bridge/synthetic methods may not have the parameter annotations
- //thus we will need to search the super classes/interfaces to make
- //sure we get the proper method that would also have the parameters annotated
- //properly
- for (Annotation a : m.getAnnotations()) {
- if (AnnotationUtils.isMethodAnnotation(a)) {
- return m;
- }
- }
- for (Annotation[] paramAnnotations : m.getParameterAnnotations()) {
- if (isValidParamAnnotations(paramAnnotations)) {
- LOG.warning("Method " + m.getName() + " in " + m.getDeclaringClass().getName()
- + " has no JAX-RS Path or HTTP Method annotations");
- return m;
- }
- }
- }
- Class<?> declaringClass = m.getDeclaringClass();
- Class<?> superC = declaringClass.getSuperclass();
- if (superC != null && Object.class != superC) {
- try {
- Method method = doGetAnnotatedMethod(serviceClass,
- superC.getMethod(m.getName(), m.getParameterTypes()));
- if (method != null) {
- return method;
- }
- } catch (NoSuchMethodException ex) {
- // ignore
- }
- }
- for (Class<?> i : declaringClass.getInterfaces()) {
- try {
- Method method = doGetAnnotatedMethod(serviceClass,
- i.getMethod(m.getName(), m.getParameterTypes()));
- if (method != null) {
- return method;
- }
- } catch (NoSuchMethodException ex) {
- // ignore
- }
- }
- if (declaringClass != serviceClass && !declaringClass.isInterface()) {
- for (Class<?> i : serviceClass.getInterfaces()) {
- try {
- Method method = doGetAnnotatedMethod(serviceClass,
- i.getMethod(m.getName(), m.getParameterTypes()));
- if (method != null) {
- return method;
- }
- } catch (NoSuchMethodException ex) {
- // ignore
- }
- }
- }
- }
- return null;
- }
-
- public static String getHttpMethodValue(Method m) {
- for (Annotation a : m.getAnnotations()) {
- HttpMethod httpM = a.annotationType().getAnnotation(HttpMethod.class);
- if (httpM != null) {
- return httpM.value();
- }
- }
- return null;
- }
-
- public static <A extends Annotation> A getMethodAnnotation(Method m, Class<A> aClass) {
- return m == null ? null : m.getAnnotation(aClass);
- }
-
- public static <A extends Annotation> A getClassAnnotation(Class<?> c, Class<A> aClass) {
- if (c == null) {
- return null;
- }
- A p = c.getAnnotation(aClass);
- if (p != null) {
- return p;
- }
-
- p = getClassAnnotation(c.getSuperclass(), aClass);
- if (p != null) {
- return p;
- }
-
- // finally try the first one on the interface
- for (Class<?> i : c.getInterfaces()) {
- p = getClassAnnotation(i, aClass);
- if (p != null) {
- return p;
- }
- }
- return null;
- }
-
- public static String getDefaultParameterValue(Annotation[] anns) {
-
- DefaultValue dv = AnnotationUtils.getAnnotation(anns, DefaultValue.class);
- return dv != null ? dv.value() : null;
- }
-
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxrs/utils/FormUtils.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxrs/utils/FormUtils.java
deleted file mode 100644
index 0c14eb0..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxrs/utils/FormUtils.java
+++ /dev/null
@@ -1,294 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.cxf.jaxrs.utils;
-
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.lang.annotation.Annotation;
-import java.nio.charset.StandardCharsets;
-import java.util.Arrays;
-import java.util.Enumeration;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.logging.Logger;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.ws.rs.HttpMethod;
-import javax.ws.rs.WebApplicationException;
-import javax.ws.rs.core.Form;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.MultivaluedMap;
-
-import org.apache.cxf.common.logging.LogUtils;
-import org.apache.cxf.common.util.StringUtils;
-import org.apache.cxf.helpers.IOUtils;
-import org.apache.cxf.io.CachedOutputStream;
-import org.apache.cxf.jaxrs.ext.multipart.Attachment;
-import org.apache.cxf.jaxrs.ext.multipart.ContentDisposition;
-import org.apache.cxf.jaxrs.ext.multipart.MultipartBody;
-import org.apache.cxf.jaxrs.impl.MetadataMap;
-import org.apache.cxf.jaxrs.provider.FormEncodingProvider;
-import org.apache.cxf.message.Message;
-import org.apache.cxf.message.MessageUtils;
-import org.apache.cxf.phase.PhaseInterceptorChain;
-import org.apache.cxf.transport.http.AbstractHTTPDestination;
-
-public final class FormUtils {
- public static final String FORM_PARAMS_FROM_HTTP_PARAMS = "set.form.parameters.from.http.parameters";
- public static final String FORM_PARAM_MAP = "org.apache.cxf.form_data";
- public static final String FORM_PARAM_MAP_DECODED = "org.apache.cxf.form_data.decoded";
-
- private static final Logger LOG = LogUtils.getL7dLogger(FormUtils.class);
- private static final String MULTIPART_FORM_DATA_TYPE = "form-data";
- private static final String MAX_FORM_PARAM_COUNT = "maxFormParameterCount";
- private static final String CONTENT_DISPOSITION_FILES_PARAM = "files";
- private FormUtils() {
-
- }
-
- public static String formToString(Form form) {
- try (ByteArrayOutputStream bos = new ByteArrayOutputStream()) {
- FormUtils.writeMapToOutputStream(form.asMap(), bos, StandardCharsets.UTF_8.name(), false);
- return bos.toString(StandardCharsets.UTF_8.name());
- } catch (Exception ex) {
- // will not happen
- }
- return "";
- }
-
- public static void restoreForm(FormEncodingProvider<Form> provider,
- Form form,
- Message message)
- throws Exception {
- CachedOutputStream os = new CachedOutputStream();
- writeForm(provider, form, os);
- message.setContent(InputStream.class, os.getInputStream());
- }
-
- public static void writeForm(FormEncodingProvider<Form> provider,
- Form form, OutputStream os)
- throws Exception {
- provider.writeTo(form, Form.class, Form.class, new Annotation[]{},
- MediaType.APPLICATION_FORM_URLENCODED_TYPE, new MetadataMap<String, Object>(), os);
- }
-
- public static Form readForm(FormEncodingProvider<Form> provider, Message message)
- throws Exception {
- return provider.readFrom(Form.class, Form.class,
- new Annotation[]{}, MediaType.APPLICATION_FORM_URLENCODED_TYPE,
- new MetadataMap<String, String>(),
- message.getContent(InputStream.class));
- }
-
- public static void addPropertyToForm(MultivaluedMap<String, String> map, String name, Object value) {
- if (!"".equals(name)) {
- map.add(name, value.toString());
- } else {
- MultivaluedMap<String, Object> values =
- InjectionUtils.extractValuesFromBean(value, "");
- for (Map.Entry<String, List<Object>> entry : values.entrySet()) {
- for (Object v : entry.getValue()) {
- map.add(entry.getKey(), v.toString());
- }
- }
- }
- }
-
- public static String readBody(InputStream is, String encoding) {
- try {
- ByteArrayOutputStream bos = new ByteArrayOutputStream();
- IOUtils.copy(is, bos, 1024);
- return new String(bos.toByteArray(), encoding);
- } catch (Exception ex) {
- throw ExceptionUtils.toInternalServerErrorException(ex, null);
- }
- }
-
- public static void populateMapFromString(MultivaluedMap<String, String> params,
- Message m,
- String postBody,
- String enc,
- boolean decode) {
- if (StringUtils.isEmpty(postBody)) {
- return;
- }
- String[] parts = postBody.split("&");
- checkNumberOfParts(m, parts.length);
- for (String part : parts) {
- String[] keyValue = new String[2];
- int index = part.indexOf('=');
- if (index != -1) {
- keyValue[0] = part.substring(0, index);
- keyValue[1] = index + 1 < part.length() ? part.substring(index + 1) : "";
- } else {
- keyValue[0] = part;
- keyValue[1] = "";
- }
- String name = HttpUtils.urlDecode(keyValue[0], enc);
- if (decode) {
- params.add(name, HttpUtils.urlDecode(keyValue[1], enc));
- } else {
- params.add(name, keyValue[1]);
- }
- }
-
- }
-
- public static void populateMapFromStringOrHttpRequest(MultivaluedMap<String, String> params,
- Message m,
- String postBody,
- String enc,
- boolean decode) {
- HttpServletRequest request = (HttpServletRequest)m.get(AbstractHTTPDestination.HTTP_REQUEST);
- populateMapFromString(params, m, postBody, enc, decode, request);
-
- }
-
- public static void populateMapFromString(MultivaluedMap<String, String> params,
- Message m,
- String postBody,
- String enc,
- boolean decode,
- javax.servlet.http.HttpServletRequest request) {
- if (!StringUtils.isEmpty(postBody)) {
- populateMapFromString(params, m, postBody, enc, decode);
- } else if (request != null
- && MessageUtils.getContextualBoolean(m, FORM_PARAMS_FROM_HTTP_PARAMS, true)) {
- for (Enumeration<String> en = request.getParameterNames(); en.hasMoreElements();) {
- String paramName = en.nextElement();
- String[] values = request.getParameterValues(paramName);
- params.put(HttpUtils.urlDecode(paramName), Arrays.asList(values));
- }
- logRequestParametersIfNeeded(params, enc);
- // The form params extracted from the HttpServelRequest are already decoded
- m.put(FORM_PARAM_MAP_DECODED, true);
- }
- }
-
- public static void logRequestParametersIfNeeded(Map<String, List<String>> params, String enc) {
- if ((PhaseInterceptorChain.getCurrentMessage() == null)
- || (PhaseInterceptorChain.getCurrentMessage().getInterceptorChain() == null)) {
- return;
- }
- String chain = PhaseInterceptorChain.getCurrentMessage().getInterceptorChain().toString();
- if (chain.contains("LoggingInInterceptor")) {
- ByteArrayOutputStream bos = new ByteArrayOutputStream();
- try {
- writeMapToOutputStream(params, bos, enc, false);
- LOG.info(bos.toString(enc));
- } catch (IOException ex) {
- // ignore
- }
- }
- }
-
- public static void writeMapToOutputStream(Map<String, List<String>> map,
- OutputStream os,
- String enc,
- boolean encoded) throws IOException {
- for (Iterator<Map.Entry<String, List<String>>> it = map.entrySet().iterator(); it.hasNext();) {
- Map.Entry<String, List<String>> entry = it.next();
-
- String key = entry.getKey();
- if (!encoded) {
- key = HttpUtils.urlEncode(key, enc);
- }
- for (Iterator<String> entryIterator = entry.getValue().iterator(); entryIterator.hasNext();) {
- os.write(key.getBytes(enc));
- os.write('=');
-
- String value = entryIterator.next();
- if (!encoded) {
- value = HttpUtils.urlEncode(value, enc);
- }
- os.write(value.getBytes(enc));
- if (entryIterator.hasNext()) {
- os.write('&');
- }
- }
- if (it.hasNext()) {
- os.write('&');
- }
-
- }
- }
-
- public static void populateMapFromMultipart(MultivaluedMap<String, String> params,
- MultipartBody body,
- Message m,
- boolean decode) {
- List<Attachment> atts = body.getAllAttachments();
- checkNumberOfParts(m, atts.size());
- for (Attachment a : atts) {
- ContentDisposition cd = a.getContentDisposition();
- if (cd != null && !MULTIPART_FORM_DATA_TYPE.equalsIgnoreCase(cd.getType())) {
- continue;
- }
- String cdName = cd == null ? null : cd.getParameter("name");
- String contentId = a.getContentId();
- String name = StringUtils.isEmpty(cdName) ? contentId : cdName.replace("\"", "").replace("'", "");
- if (StringUtils.isEmpty(name)) {
- throw ExceptionUtils.toBadRequestException(null, null);
- }
- if (CONTENT_DISPOSITION_FILES_PARAM.equals(name)) {
- // this is a reserved name in Content-Disposition for parts containing files
- continue;
- }
- try {
- String value = IOUtils.toString(a.getDataHandler().getInputStream());
- params.add(HttpUtils.urlDecode(name),
- decode ? HttpUtils.urlDecode(value) : value);
- } catch (IllegalArgumentException ex) {
- LOG.warning("Illegal URL-encoded characters, make sure that no "
- + "@FormParam and @Multipart annotations are mixed up");
- throw ExceptionUtils.toInternalServerErrorException(ex, null);
- } catch (IOException ex) {
- throw ExceptionUtils.toBadRequestException(null, null);
- }
- }
- }
-
- private static void checkNumberOfParts(Message m, int numberOfParts) {
- if (m == null || m.getExchange() == null || m.getExchange().getInMessage() == null) {
- return;
- }
- String maxPartsCountProp = (String)m.getExchange()
- .getInMessage().getContextualProperty(MAX_FORM_PARAM_COUNT);
- if (maxPartsCountProp == null) {
- return;
- }
- try {
- int maxPartsCount = Integer.parseInt(maxPartsCountProp);
- if (maxPartsCount != -1 && numberOfParts >= maxPartsCount) {
- throw new WebApplicationException(413);
- }
- } catch (NumberFormatException ex) {
- throw ExceptionUtils.toInternalServerErrorException(ex, null);
- }
- }
-
- public static boolean isFormPostRequest(Message m) {
- return MediaType.APPLICATION_FORM_URLENCODED.equals(m.get(Message.CONTENT_TYPE))
- && HttpMethod.POST.equals(m.get(Message.HTTP_REQUEST_METHOD));
- }
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxrs/utils/HttpUtils.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxrs/utils/HttpUtils.java
deleted file mode 100644
index ff6267a..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxrs/utils/HttpUtils.java
+++ /dev/null
@@ -1,733 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.cxf.jaxrs.utils;
-
-import java.io.UnsupportedEncodingException;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.nio.charset.StandardCharsets;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Date;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Locale;
-import java.util.Map;
-import java.util.ResourceBundle;
-import java.util.Set;
-import java.util.logging.Logger;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-import javax.servlet.ServletConfig;
-import javax.servlet.ServletContext;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import javax.ws.rs.core.HttpHeaders;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.MultivaluedMap;
-import javax.ws.rs.core.PathSegment;
-import javax.ws.rs.core.Response;
-import javax.ws.rs.core.UriBuilder;
-import javax.ws.rs.ext.RuntimeDelegate;
-import javax.ws.rs.ext.RuntimeDelegate.HeaderDelegate;
-
-import org.apache.cxf.common.i18n.BundleUtils;
-import org.apache.cxf.common.logging.LogUtils;
-import org.apache.cxf.common.util.PropertyUtils;
-import org.apache.cxf.common.util.StringUtils;
-import org.apache.cxf.common.util.UrlUtils;
-import org.apache.cxf.helpers.CastUtils;
-import org.apache.cxf.jaxrs.impl.HttpHeadersImpl;
-import org.apache.cxf.jaxrs.impl.HttpServletRequestFilter;
-import org.apache.cxf.jaxrs.impl.HttpServletResponseFilter;
-import org.apache.cxf.jaxrs.impl.MetadataMap;
-import org.apache.cxf.jaxrs.impl.PathSegmentImpl;
-import org.apache.cxf.jaxrs.impl.RuntimeDelegateImpl;
-import org.apache.cxf.jaxrs.model.ParameterType;
-import org.apache.cxf.message.Message;
-import org.apache.cxf.service.model.EndpointInfo;
-import org.apache.cxf.transport.Destination;
-import org.apache.cxf.transport.http.AbstractHTTPDestination;
-import org.apache.cxf.transport.http.Headers;
-import org.apache.cxf.transport.servlet.BaseUrlHelper;
-
-public final class HttpUtils {
-
- private static final ResourceBundle BUNDLE = BundleUtils.getBundle(HttpUtils.class);
- private static final Logger LOG = LogUtils.getL7dLogger(HttpUtils.class);
-
- private static final String REQUEST_PATH_TO_MATCH = "path_to_match";
- private static final String REQUEST_PATH_TO_MATCH_SLASH = "path_to_match_slash";
-
- private static final String HTTP_SCHEME = "http";
- private static final String LOCAL_HOST_IP_ADDRESS = "127.0.0.1";
- private static final String REPLACE_LOOPBACK_PROPERTY = "replace.loopback.address.with.localhost";
- private static final String LOCAL_HOST_IP_ADDRESS_SCHEME = "://" + LOCAL_HOST_IP_ADDRESS;
- private static final String ANY_IP_ADDRESS = "0.0.0.0";
- private static final String ANY_IP_ADDRESS_SCHEME = "://" + ANY_IP_ADDRESS;
- private static final int DEFAULT_HTTP_PORT = 80;
-
- private static final Pattern ENCODE_PATTERN = Pattern.compile("%[0-9a-fA-F][0-9a-fA-F]");
- private static final String CHARSET_PARAMETER = "charset";
- private static final String DOUBLE_QUOTE = "\"";
-
- // there are more of such characters, ex, '*' but '*' is not affected by UrlEncode
- private static final String PATH_RESERVED_CHARACTERS = "=@/:!$&\'(),;~";
- private static final String QUERY_RESERVED_CHARACTERS = "?/,";
-
- private static final Set<String> KNOWN_HTTP_VERBS_WITH_NO_REQUEST_CONTENT =
- new HashSet<>(Arrays.asList(new String[]{"GET", "HEAD", "OPTIONS", "TRACE"}));
- private static final Set<String> KNOWN_HTTP_VERBS_WITH_NO_RESPONSE_CONTENT =
- new HashSet<>(Arrays.asList(new String[]{"HEAD", "OPTIONS"}));
-
- private static final Pattern HTTP_SCHEME_PATTERN = Pattern.compile("^(?i)(http|https)$");
-
- private HttpUtils() {
- }
-
- public static String urlDecode(String value, String enc) {
- return UrlUtils.urlDecode(value, enc);
- }
-
- public static String urlDecode(String value) {
- return UrlUtils.urlDecode(value);
- }
-
- public static String pathDecode(String value) {
- return UrlUtils.pathDecode(value);
- }
-
- private static String componentEncode(String reservedChars, String value) {
-
- StringBuilder buffer = null;
- int length = value.length();
- int startingIndex = 0;
- for (int i = 0; i < length; i++) {
- char currentChar = value.charAt(i);
- if (reservedChars.indexOf(currentChar) != -1) {
- if (buffer == null) {
- buffer = new StringBuilder(length + 8);
- }
- // If it is going to be an empty string nothing to encode.
- if (i != startingIndex) {
- buffer.append(urlEncode(value.substring(startingIndex, i)));
- }
- buffer.append(currentChar);
- startingIndex = i + 1;
- }
- }
-
- if (buffer == null) {
- return urlEncode(value);
- }
- if (startingIndex < length) {
- buffer.append(urlEncode(value.substring(startingIndex, length)));
- }
-
- return buffer.toString();
- }
-
- public static String queryEncode(String value) {
-
- return componentEncode(QUERY_RESERVED_CHARACTERS, value);
- }
-
- public static String urlEncode(String value) {
-
- return urlEncode(value, StandardCharsets.UTF_8.name());
- }
-
- public static String urlEncode(String value, String enc) {
-
- return UrlUtils.urlEncode(value, enc);
- }
-
- public static String pathEncode(String value) {
-
- String result = componentEncode(PATH_RESERVED_CHARACTERS, value);
- // URLEncoder will encode '+' to %2B but will turn ' ' into '+'
- // We need to retain '+' and encode ' ' as %20
- if (result.indexOf('+') != -1) {
- result = result.replace("+", "%20");
- }
- if (result.indexOf("%2B") != -1) {
- result = result.replace("%2B", "+");
- }
-
- return result;
- }
-
- public static boolean isPartiallyEncoded(String value) {
- return ENCODE_PATTERN.matcher(value).find();
- }
-
- /**
- * Encodes partially encoded string. Encode all values but those matching pattern
- * "percent char followed by two hexadecimal digits".
- *
- * @param encoded fully or partially encoded string.
- * @return fully encoded string
- */
- public static String encodePartiallyEncoded(String encoded, boolean query) {
- if (encoded.length() == 0) {
- return encoded;
- }
- Matcher m = ENCODE_PATTERN.matcher(encoded);
-
- if (!m.find()) {
- return query ? HttpUtils.queryEncode(encoded) : HttpUtils.pathEncode(encoded);
- }
-
- int length = encoded.length();
- StringBuilder sb = new StringBuilder(length + 8);
- int i = 0;
- do {
- String before = encoded.substring(i, m.start());
- sb.append(query ? HttpUtils.queryEncode(before) : HttpUtils.pathEncode(before));
- sb.append(m.group());
- i = m.end();
- } while (m.find());
- String tail = encoded.substring(i, length);
- sb.append(query ? HttpUtils.queryEncode(tail) : HttpUtils.pathEncode(tail));
- return sb.toString();
- }
-
- public static SimpleDateFormat getHttpDateFormat() {
- return Headers.getHttpDateFormat();
- }
-
- public static String toHttpDate(Date date) {
- return Headers.toHttpDate(date);
- }
-
- public static RuntimeDelegate getOtherRuntimeDelegate() {
- try {
- RuntimeDelegate rd = RuntimeDelegate.getInstance();
- return rd instanceof RuntimeDelegateImpl ? null : rd;
- } catch (Throwable t) {
- return null;
- }
- }
-
- public static HeaderDelegate<Object> getHeaderDelegate(Object o) {
- return getHeaderDelegate(RuntimeDelegate.getInstance(), o);
- }
-
- @SuppressWarnings("unchecked")
- public static HeaderDelegate<Object> getHeaderDelegate(RuntimeDelegate rd, Object o) {
- return rd == null ? null : (HeaderDelegate<Object>)rd.createHeaderDelegate(o.getClass());
- }
-
- @SuppressWarnings("unchecked")
- public static <T> MultivaluedMap<String, T> getModifiableStringHeaders(Message m) {
- MultivaluedMap<String, Object> headers = getModifiableHeaders(m);
- convertHeaderValuesToString(headers, false);
- return (MultivaluedMap<String, T>)headers;
- }
-
- public static MultivaluedMap<String, Object> getModifiableHeaders(Message m) {
- Map<String, List<Object>> headers = CastUtils.cast((Map<?, ?>)m.get(Message.PROTOCOL_HEADERS));
- return new MetadataMap<String, Object>(headers, false, false, true);
- }
-
- public static void convertHeaderValuesToString(Map<String, List<Object>> headers, boolean delegateOnly) {
- if (headers == null) {
- return;
- }
- RuntimeDelegate rd = getOtherRuntimeDelegate();
- if (rd == null && delegateOnly) {
- return;
- }
- for (Map.Entry<String, List<Object>> entry : headers.entrySet()) {
- List<Object> values = entry.getValue();
- for (int i = 0; i < values.size(); i++) {
- Object value = values.get(i);
-
- if (value != null && !(value instanceof String)) {
-
- HeaderDelegate<Object> hd = getHeaderDelegate(rd, value);
-
- if (hd != null) {
- value = hd.toString(value);
- } else if (!delegateOnly) {
- value = value.toString();
- }
-
- try {
- values.set(i, value);
- } catch (UnsupportedOperationException ex) {
- // this may happen if an unmodifiable List was set via Map put
- List<Object> newList = new ArrayList<>(values);
- newList.set(i, value);
- // Won't help if the map is unmodifiable in which case it is a bug anyway
- headers.put(entry.getKey(), newList);
- }
-
- }
-
- }
- }
-
- }
-
- public static Date getHttpDate(String value) {
- if (value == null) {
- return null;
- }
- try {
- return Headers.getHttpDateFormat().parse(value);
- } catch (ParseException ex) {
- return null;
- }
- }
-
- public static Locale getLocale(String value) {
- if (value == null) {
- return null;
- }
- String language = null;
- String locale = null;
- int index = value.indexOf('-');
- if (index == 0 || index == value.length() - 1) {
- throw new IllegalArgumentException("Illegal locale value : " + value);
- }
-
- if (index > 0) {
- language = value.substring(0, index);
- locale = value.substring(index + 1);
- } else {
- language = value;
- }
-
- if (locale == null) {
- return new Locale(language);
- }
- return new Locale(language, locale);
-
- }
-
- public static int getContentLength(String value) {
- if (value == null) {
- return -1;
- }
- try {
- int len = Integer.parseInt(value);
- return len >= 0 ? len : -1;
- } catch (Exception ex) {
- return -1;
- }
- }
-
- public static String getHeaderString(List<String> values) {
- if (values == null) {
- return null;
- }
- StringBuilder sb = new StringBuilder();
- for (int i = 0; i < values.size(); i++) {
- String value = values.get(i);
- if (StringUtils.isEmpty(value)) {
- continue;
- }
- sb.append(value);
- if (i + 1 < values.size()) {
- sb.append(',');
- }
- }
- return sb.toString();
- }
-
- public static boolean isDateRelatedHeader(String headerName) {
- return HttpHeaders.DATE.equalsIgnoreCase(headerName)
- || HttpHeaders.IF_MODIFIED_SINCE.equalsIgnoreCase(headerName)
- || HttpHeaders.IF_UNMODIFIED_SINCE.equalsIgnoreCase(headerName)
- || HttpHeaders.EXPIRES.equalsIgnoreCase(headerName)
- || HttpHeaders.LAST_MODIFIED.equalsIgnoreCase(headerName);
- }
-
- public static boolean isHttpRequest(Message message) {
- return message.get(AbstractHTTPDestination.HTTP_REQUEST) != null;
- }
-
- public static URI toAbsoluteUri(String relativePath, Message message) {
- String base = BaseUrlHelper.getBaseURL(
- (HttpServletRequest)message.get(AbstractHTTPDestination.HTTP_REQUEST));
- return URI.create(base + relativePath);
- }
-
- public static void setHttpRequestURI(Message message, String uriTemplate) {
- HttpServletRequest request =
- (HttpServletRequest)message.get(AbstractHTTPDestination.HTTP_REQUEST);
- request.setAttribute("org.springframework.web.servlet.HandlerMapping.bestMatchingPattern", uriTemplate);
- }
-
-
- public static URI toAbsoluteUri(URI u, Message message) {
- HttpServletRequest request =
- (HttpServletRequest)message.get(AbstractHTTPDestination.HTTP_REQUEST);
- boolean absolute = u.isAbsolute();
- StringBuilder uriBuf = new StringBuilder();
- if (request != null && (!absolute || isLocalHostOrAnyIpAddress(u, uriBuf, message))) {
- String serverAndPort = request.getServerName();
- boolean localAddressUsed = false;
- if (absolute) {
- if (ANY_IP_ADDRESS.equals(serverAndPort)) {
- serverAndPort = request.getLocalAddr();
- localAddressUsed = true;
- }
- if (LOCAL_HOST_IP_ADDRESS.equals(serverAndPort)) {
- serverAndPort = "localhost";
- localAddressUsed = true;
- }
- }
-
-
- int port = localAddressUsed ? request.getLocalPort() : request.getServerPort();
- if (port != DEFAULT_HTTP_PORT) {
- serverAndPort += ":" + port;
- }
- String base = request.getScheme() + "://" + serverAndPort;
- if (!absolute) {
- u = URI.create(base + u.toString());
- } else {
- int originalPort = u.getPort();
- String hostValue = uriBuf.toString().contains(ANY_IP_ADDRESS_SCHEME)
- ? ANY_IP_ADDRESS : LOCAL_HOST_IP_ADDRESS;
- String replaceValue = originalPort == -1 ? hostValue : hostValue + ":" + originalPort;
- u = URI.create(u.toString().replace(replaceValue, serverAndPort));
- }
- }
- return u;
- }
-
- private static boolean isLocalHostOrAnyIpAddress(URI u, StringBuilder uriStringBuffer, Message m) {
- String uriString = u.toString();
- boolean result = uriString.contains(LOCAL_HOST_IP_ADDRESS_SCHEME) && replaceLoopBackAddress(m)
- || uriString.contains(ANY_IP_ADDRESS_SCHEME);
- uriStringBuffer.append(uriString);
- return result;
- }
-
- private static boolean replaceLoopBackAddress(Message m) {
- Object prop = m.getContextualProperty(REPLACE_LOOPBACK_PROPERTY);
- return prop == null || PropertyUtils.isTrue(prop);
- }
-
- public static void resetRequestURI(Message m, String requestURI) {
- m.remove(REQUEST_PATH_TO_MATCH_SLASH);
- m.remove(REQUEST_PATH_TO_MATCH);
- m.put(Message.REQUEST_URI, requestURI);
- }
-
-
- public static String getPathToMatch(Message m, boolean addSlash) {
- String var = addSlash ? REQUEST_PATH_TO_MATCH_SLASH : REQUEST_PATH_TO_MATCH;
- String pathToMatch = (String)m.get(var);
- if (pathToMatch != null) {
- return pathToMatch;
- }
- String requestAddress = getProtocolHeader(m, Message.REQUEST_URI, "/");
- if (m.get(Message.QUERY_STRING) == null) {
- int index = requestAddress.lastIndexOf('?');
- if (index > 0 && index < requestAddress.length()) {
- m.put(Message.QUERY_STRING, requestAddress.substring(index + 1));
- requestAddress = requestAddress.substring(0, index);
- }
- }
- String baseAddress = getBaseAddress(m);
- pathToMatch = getPathToMatch(requestAddress, baseAddress, addSlash);
- m.put(var, pathToMatch);
- return pathToMatch;
- }
-
- public static String getProtocolHeader(Message m, String name, String defaultValue) {
- return getProtocolHeader(m, name, defaultValue, false);
- }
-
- public static String getProtocolHeader(Message m, String name, String defaultValue, boolean setOnMessage) {
- String value = (String)m.get(name);
- if (value == null) {
- value = new HttpHeadersImpl(m).getRequestHeaders().getFirst(name);
- if (value != null && setOnMessage) {
- m.put(name, value);
- }
- }
- return value == null ? defaultValue : value;
- }
-
- public static String getBaseAddress(Message m) {
- String endpointAddress = getEndpointAddress(m);
- try {
- URI uri = new URI(endpointAddress);
- String path = uri.getRawPath();
- String scheme = uri.getScheme();
- // RFC-3986: the scheme and host are case-insensitive and therefore should
- // be normalized to lowercase.
- if (scheme != null && !scheme.toLowerCase().startsWith(HttpUtils.HTTP_SCHEME)
- && HttpUtils.isHttpRequest(m)) {
- path = HttpUtils.toAbsoluteUri(path, m).getRawPath();
- }
- return (path == null || path.length() == 0) ? "/" : path;
- } catch (URISyntaxException ex) {
- return endpointAddress;
- }
- }
-
- public static String getEndpointUri(Message m) {
- final Object servletRequest = m.get(AbstractHTTPDestination.HTTP_REQUEST);
-
- if (servletRequest != null) {
- final Object property = ((javax.servlet.http.HttpServletRequest)servletRequest)
- .getAttribute("org.apache.cxf.transport.endpoint.uri");
- if (property != null) {
- return property.toString();
- }
- }
-
- return getEndpointAddress(m);
- }
-
- public static String getEndpointAddress(Message m) {
- String address;
- Destination d = m.getExchange().getDestination();
- if (d != null) {
- if (d instanceof AbstractHTTPDestination) {
- EndpointInfo ei = ((AbstractHTTPDestination)d).getEndpointInfo();
- HttpServletRequest request = (HttpServletRequest)m.get(AbstractHTTPDestination.HTTP_REQUEST);
- Object property = request != null
- ? request.getAttribute("org.apache.cxf.transport.endpoint.address") : null;
- address = property != null ? property.toString() : ei.getAddress();
- } else {
- address = m.containsKey(Message.BASE_PATH)
- ? (String)m.get(Message.BASE_PATH) : d.getAddress().getAddress().getValue();
- }
- } else {
- address = (String)m.get(Message.ENDPOINT_ADDRESS);
- }
- if (address.startsWith("http") && address.endsWith("//")) {
- address = address.substring(0, address.length() - 1);
- }
- return address;
- }
-
- public static void updatePath(Message m, String path) {
- String baseAddress = getBaseAddress(m);
- boolean pathSlash = path.startsWith("/");
- boolean baseSlash = baseAddress.endsWith("/");
- if (pathSlash && baseSlash) {
- path = path.substring(1);
- } else if (!pathSlash && !baseSlash) {
- path = "/" + path;
- }
- m.put(Message.REQUEST_URI, baseAddress + path);
- m.remove(REQUEST_PATH_TO_MATCH);
- m.remove(REQUEST_PATH_TO_MATCH_SLASH);
- }
-
-
- public static String getPathToMatch(String path, String address, boolean addSlash) {
-
- int ind = path.indexOf(address);
- if (ind == -1 && address.equals(path + "/")) {
- path += "/";
- ind = 0;
- }
- if (ind == 0) {
- path = path.substring(address.length());
- }
- if (addSlash && !path.startsWith("/")) {
- path = "/" + path;
- }
-
- return path;
- }
-
- public static String getOriginalAddress(Message m) {
- Destination d = m.getDestination();
- return d == null ? "/" : d.getAddress().getAddress().getValue();
- }
-
- public static String fromPathSegment(PathSegment ps) {
- if (PathSegmentImpl.class.isAssignableFrom(ps.getClass())) {
- return ((PathSegmentImpl)ps).getOriginalPath();
- }
- StringBuilder sb = new StringBuilder();
- sb.append(ps.getPath());
- for (Map.Entry<String, List<String>> entry : ps.getMatrixParameters().entrySet()) {
- for (String value : entry.getValue()) {
- sb.append(';').append(entry.getKey());
- if (value != null) {
- sb.append('=').append(value);
- }
- }
- }
- return sb.toString();
- }
-
- public static Response.Status getParameterFailureStatus(ParameterType pType) {
- if (pType == ParameterType.MATRIX || pType == ParameterType.PATH
- || pType == ParameterType.QUERY) {
- return Response.Status.NOT_FOUND;
- }
- return Response.Status.BAD_REQUEST;
- }
-
- public static String getSetEncoding(MediaType mt, MultivaluedMap<String, Object> headers,
- String defaultEncoding) {
- String enc = getMediaTypeCharsetParameter(mt);
- if (enc == null) {
- return defaultEncoding;
- }
- try {
- "0".getBytes(enc);
- return enc;
- } catch (UnsupportedEncodingException ex) {
- String message = new org.apache.cxf.common.i18n.Message("UNSUPPORTED_ENCODING",
- BUNDLE, enc, defaultEncoding).toString();
- LOG.warning(message);
- headers.putSingle(HttpHeaders.CONTENT_TYPE,
- JAXRSUtils.mediaTypeToString(mt, CHARSET_PARAMETER)
- + ';' + CHARSET_PARAMETER + "="
- + (defaultEncoding == null ? StandardCharsets.UTF_8 : defaultEncoding));
- }
- return defaultEncoding;
- }
-
- public static String getEncoding(MediaType mt, String defaultEncoding) {
- String charset = mt == null ? defaultEncoding : getMediaTypeCharsetParameter(mt);
- return charset == null ? defaultEncoding : charset;
- }
-
- public static String getMediaTypeCharsetParameter(MediaType mt) {
- String charset = mt.getParameters().get(CHARSET_PARAMETER);
- if (charset != null && charset.startsWith(DOUBLE_QUOTE)
- && charset.endsWith(DOUBLE_QUOTE) && charset.length() > 1) {
- charset = charset.substring(1, charset.length() - 1);
- }
- return charset;
- }
-
- public static URI resolve(UriBuilder baseBuilder, URI uri) {
- if (!uri.isAbsolute()) {
- return baseBuilder.build().resolve(uri);
- }
- return uri;
- }
-
- public static URI relativize(URI base, URI uri) {
- // quick bail-out
- if (!(base.isAbsolute()) || !(uri.isAbsolute())) {
- return uri;
- }
- if (base.isOpaque() || uri.isOpaque()) {
- // Unlikely case of an URN which can't deal with
- // relative path, such as urn:isbn:0451450523
- return uri;
- }
- // Check for common root
- URI root = base.resolve("/");
- if (!(root.equals(uri.resolve("/")))) {
- // Different protocol/auth/host/port, return as is
- return uri;
- }
-
- // Ignore hostname bits for the following , but add "/" in the beginning
- // so that in worst case we'll still return "/fred" rather than
- // "http://example.com/fred".
- URI baseRel = URI.create("/").resolve(root.relativize(base));
- URI uriRel = URI.create("/").resolve(root.relativize(uri));
-
- // Is it same path?
- if (baseRel.getPath().equals(uriRel.getPath())) {
- return baseRel.relativize(uriRel);
- }
-
- // Direct siblings? (ie. in same folder)
- URI commonBase = baseRel.resolve("./");
- if (commonBase.equals(uriRel.resolve("./"))) {
- return commonBase.relativize(uriRel);
- }
-
- // No, then just keep climbing up until we find a common base.
- URI relative = URI.create("");
- while (!(uriRel.getPath().startsWith(commonBase.getPath())) && !"/".equals(commonBase.getPath())) {
- commonBase = commonBase.resolve("../");
- relative = relative.resolve("../");
- }
-
- // Now we can use URI.relativize
- URI relToCommon = commonBase.relativize(uriRel);
- // and prepend the needed ../
- return relative.resolve(relToCommon);
-
- }
-
- public static String toHttpLanguage(Locale locale) {
- return Headers.toHttpLanguage(locale);
- }
-
- public static boolean isPayloadEmpty(MultivaluedMap<String, String> headers) {
- if (headers != null) {
- String value = headers.getFirst(HttpHeaders.CONTENT_LENGTH);
- if (value != null) {
- try {
- Long len = Long.valueOf(value);
- return len <= 0;
- } catch (NumberFormatException ex) {
- // ignore
- }
- }
- }
-
- return false;
- }
-
- public static <T> T createServletResourceValue(Message m, Class<T> clazz) {
-
- Object value = null;
- if (clazz == HttpServletRequest.class) {
- HttpServletRequest request = (HttpServletRequest)m.get(AbstractHTTPDestination.HTTP_REQUEST);
- value = request != null ? new HttpServletRequestFilter(request, m) : null;
- } else if (clazz == HttpServletResponse.class) {
- HttpServletResponse response = (HttpServletResponse)m.get(AbstractHTTPDestination.HTTP_RESPONSE);
- value = response != null ? new HttpServletResponseFilter(response, m) : null;
- } else if (clazz == ServletContext.class) {
- value = m.get(AbstractHTTPDestination.HTTP_CONTEXT);
- } else if (clazz == ServletConfig.class) {
- value = m.get(AbstractHTTPDestination.HTTP_CONFIG);
- }
-
- return clazz.cast(value);
- }
-
- public static boolean isMethodWithNoRequestContent(String method) {
- return KNOWN_HTTP_VERBS_WITH_NO_REQUEST_CONTENT.contains(method);
- }
-
- public static boolean isMethodWithNoResponseContent(String method) {
- return KNOWN_HTTP_VERBS_WITH_NO_RESPONSE_CONTENT.contains(method);
- }
-
- public static boolean isHttpScheme(final String scheme) {
- return scheme != null && HTTP_SCHEME_PATTERN.matcher(scheme).matches();
- }
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
deleted file mode 100644
index 89cdae5..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
+++ /dev/null
@@ -1,2027 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.cxf.jaxrs.utils;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.io.Reader;
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-import java.lang.reflect.ParameterizedType;
-import java.lang.reflect.Type;
-import java.nio.charset.StandardCharsets;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.HashSet;
-import java.util.LinkedHashMap;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.ResourceBundle;
-import java.util.Set;
-import java.util.SortedMap;
-import java.util.TreeMap;
-import java.util.function.Supplier;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-import java.util.stream.Collectors;
-
-import javax.activation.DataSource;
-import javax.ws.rs.ClientErrorException;
-import javax.ws.rs.Consumes;
-import javax.ws.rs.HttpMethod;
-import javax.ws.rs.Produces;
-import javax.ws.rs.WebApplicationException;
-import javax.ws.rs.container.AsyncResponse;
-import javax.ws.rs.container.ContainerRequestContext;
-import javax.ws.rs.container.ContainerRequestFilter;
-import javax.ws.rs.container.ContainerResponseContext;
-import javax.ws.rs.container.ContainerResponseFilter;
-import javax.ws.rs.container.ResourceContext;
-import javax.ws.rs.container.ResourceInfo;
-import javax.ws.rs.core.Application;
-import javax.ws.rs.core.Configuration;
-import javax.ws.rs.core.Cookie;
-import javax.ws.rs.core.HttpHeaders;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.MultivaluedMap;
-import javax.ws.rs.core.NoContentException;
-import javax.ws.rs.core.PathSegment;
-import javax.ws.rs.core.Request;
-import javax.ws.rs.core.Response;
-import javax.ws.rs.core.Response.ResponseBuilder;
-import javax.ws.rs.core.SecurityContext;
-import javax.ws.rs.core.StreamingOutput;
-import javax.ws.rs.core.UriInfo;
-import javax.ws.rs.ext.ContextResolver;
-import javax.ws.rs.ext.MessageBodyReader;
-import javax.ws.rs.ext.MessageBodyWriter;
-import javax.ws.rs.ext.Providers;
-import javax.ws.rs.ext.ReaderInterceptor;
-import javax.ws.rs.ext.ReaderInterceptorContext;
-import javax.ws.rs.ext.WriterInterceptor;
-import javax.ws.rs.ext.WriterInterceptorContext;
-import javax.xml.namespace.QName;
-
-import org.apache.cxf.common.i18n.BundleUtils;
-import org.apache.cxf.common.logging.LogUtils;
-import org.apache.cxf.common.util.PackageUtils;
-import org.apache.cxf.common.util.PropertyUtils;
-import org.apache.cxf.common.util.ReflectionUtil;
-import org.apache.cxf.common.util.StringUtils;
-import org.apache.cxf.helpers.DOMUtils;
-import org.apache.cxf.helpers.IOUtils;
-import org.apache.cxf.helpers.LoadingByteArrayOutputStream;
-import org.apache.cxf.interceptor.Fault;
-import org.apache.cxf.io.CacheAndWriteOutputStream;
-import org.apache.cxf.io.ReaderInputStream;
-import org.apache.cxf.jaxrs.JAXRSServiceImpl;
-import org.apache.cxf.jaxrs.ext.ContextProvider;
-import org.apache.cxf.jaxrs.ext.DefaultMethod;
-import org.apache.cxf.jaxrs.ext.MessageContext;
-import org.apache.cxf.jaxrs.ext.MessageContextImpl;
-import org.apache.cxf.jaxrs.ext.ProtocolHeaders;
-import org.apache.cxf.jaxrs.ext.ProtocolHeadersImpl;
-import org.apache.cxf.jaxrs.ext.multipart.MultipartBody;
-import org.apache.cxf.jaxrs.impl.AsyncResponseImpl;
-import org.apache.cxf.jaxrs.impl.ContainerRequestContextImpl;
-import org.apache.cxf.jaxrs.impl.ContainerResponseContextImpl;
-import org.apache.cxf.jaxrs.impl.HttpHeadersImpl;
-import org.apache.cxf.jaxrs.impl.MediaTypeHeaderProvider;
-import org.apache.cxf.jaxrs.impl.MetadataMap;
-import org.apache.cxf.jaxrs.impl.PathSegmentImpl;
-import org.apache.cxf.jaxrs.impl.ProvidersImpl;
-import org.apache.cxf.jaxrs.impl.ReaderInterceptorContextImpl;
-import org.apache.cxf.jaxrs.impl.ReaderInterceptorMBR;
-import org.apache.cxf.jaxrs.impl.RequestImpl;
-import org.apache.cxf.jaxrs.impl.ResourceContextImpl;
-import org.apache.cxf.jaxrs.impl.ResourceInfoImpl;
-import org.apache.cxf.jaxrs.impl.ResponseBuilderImpl;
-import org.apache.cxf.jaxrs.impl.ResponseImpl;
-import org.apache.cxf.jaxrs.impl.SecurityContextImpl;
-import org.apache.cxf.jaxrs.impl.UriInfoImpl;
-import org.apache.cxf.jaxrs.impl.WriterInterceptorContextImpl;
-import org.apache.cxf.jaxrs.impl.WriterInterceptorMBW;
-import org.apache.cxf.jaxrs.model.BeanParamInfo;
-import org.apache.cxf.jaxrs.model.BeanResourceInfo;
-import org.apache.cxf.jaxrs.model.ClassResourceInfo;
-import org.apache.cxf.jaxrs.model.ClassResourceInfoComparator;
-import org.apache.cxf.jaxrs.model.MethodInvocationInfo;
-import org.apache.cxf.jaxrs.model.OperationResourceInfo;
-import org.apache.cxf.jaxrs.model.OperationResourceInfoComparator;
-import org.apache.cxf.jaxrs.model.OperationResourceInfoStack;
-import org.apache.cxf.jaxrs.model.Parameter;
-import org.apache.cxf.jaxrs.model.ParameterType;
-import org.apache.cxf.jaxrs.model.ProviderInfo;
-import org.apache.cxf.jaxrs.model.URITemplate;
-import org.apache.cxf.jaxrs.provider.AbstractConfigurableProvider;
-import org.apache.cxf.jaxrs.provider.ProviderFactory;
-import org.apache.cxf.jaxrs.provider.ServerProviderFactory;
-import org.apache.cxf.jaxrs.utils.multipart.AttachmentUtils;
-import org.apache.cxf.message.Exchange;
-import org.apache.cxf.message.Message;
-import org.apache.cxf.message.MessageUtils;
-import org.apache.cxf.phase.PhaseInterceptorChain;
-import org.apache.cxf.service.Service;
-
-public final class JAXRSUtils {
-
- public static final MediaType ALL_TYPES = new MediaType();
- public static final String ROOT_RESOURCE_CLASS = "root.resource.class";
- public static final String IGNORE_MESSAGE_WRITERS = "ignore.message.writers";
- public static final String ROOT_INSTANCE = "service.root.instance";
- public static final String ROOT_PROVIDER = "service.root.provider";
- public static final String EXCEPTION_FROM_MAPPER = "exception.from.mapper";
- public static final String SECOND_JAXRS_EXCEPTION = "second.jaxrs.exception";
- public static final String PARTIAL_HIERARCHICAL_MEDIA_SUBTYPE_CHECK =
- "media.subtype.partial.check";
- public static final String DOC_LOCATION = "wadl.location";
- public static final String MEDIA_TYPE_Q_PARAM = "q";
- public static final String MEDIA_TYPE_QS_PARAM = "qs";
- private static final String MEDIA_TYPE_DISTANCE_PARAM = "d";
- private static final String DEFAULT_CONTENT_TYPE = "default.content.type";
- private static final String KEEP_SUBRESOURCE_CANDIDATES = "keep.subresource.candidates";
- private static final Logger LOG = LogUtils.getL7dLogger(JAXRSUtils.class);
- private static final ResourceBundle BUNDLE = BundleUtils.getBundle(JAXRSUtils.class);
- private static final String PATH_SEGMENT_SEP = "/";
- private static final String REPORT_FAULT_MESSAGE_PROPERTY = "org.apache.cxf.jaxrs.report-fault-message";
- private static final String NO_CONTENT_EXCEPTION = NoContentException.class.getName();
- private static final String HTTP_CHARSET_PARAM = "charset";
- private static final Annotation[] EMPTY_ANNOTATIONS = new Annotation[0];
- private static final Set<Class<?>> STREAMING_OUT_TYPES = new HashSet<>(
- Arrays.asList(InputStream.class, Reader.class, StreamingOutput.class, DataSource.class));
-
- private JAXRSUtils() {
- }
-
- public static boolean isStreamingOutType(Class<?> type) {
- return STREAMING_OUT_TYPES.contains(type);
- }
-
- public static List<PathSegment> getPathSegments(String thePath, boolean decode) {
- return getPathSegments(thePath, decode, true);
- }
-
- public static List<PathSegment> getPathSegments(String thePath, boolean decode,
- boolean ignoreLastSlash) {
- List<PathSegment> theList =
- Arrays.asList(thePath.split("/")).stream()
- .filter(StringUtils.notEmpty())
- .map(p -> new PathSegmentImpl(p, decode))
- .collect(Collectors.toList());
-
- int len = thePath.length();
- if (len > 0 && thePath.charAt(len - 1) == '/') {
- String value = ignoreLastSlash ? "" : "/";
- theList.add(new PathSegmentImpl(value, false));
- }
- return theList;
- }
-
- private static String[] getUserMediaTypes(Object provider, boolean consumes) {
- String[] values = null;
- if (AbstractConfigurableProvider.class.isAssignableFrom(provider.getClass())) {
- final List<String> types;
- if (consumes) {
- types = ((AbstractConfigurableProvider)provider).getConsumeMediaTypes();
- } else {
- types = ((AbstractConfigurableProvider)provider).getProduceMediaTypes();
- }
- if (types != null) {
- values = !types.isEmpty() ? types.toArray(new String[0])
- : new String[]{"*/*"};
- }
- }
- return values;
- }
-
- public static List<MediaType> getProviderConsumeTypes(MessageBodyReader<?> provider) {
- String[] values = getUserMediaTypes(provider, true);
-
- if (values == null) {
- return getConsumeTypes(provider.getClass().getAnnotation(Consumes.class));
- }
- return JAXRSUtils.getMediaTypes(values);
- }
-
- public static List<MediaType> getProviderProduceTypes(MessageBodyWriter<?> provider) {
- String[] values = getUserMediaTypes(provider, false);
- if (values == null) {
- return getProduceTypes(provider.getClass().getAnnotation(Produces.class));
- }
- return JAXRSUtils.getMediaTypes(values);
- }
-
- public static List<MediaType> getMediaTypes(String[] values) {
- List<MediaType> supportedMimeTypes = new ArrayList<>(values.length);
- for (int i = 0; i < values.length; i++) {
- supportedMimeTypes.addAll(parseMediaTypes(values[i]));
- }
- return supportedMimeTypes;
- }
-
- public static void injectParameters(OperationResourceInfo ori,
- Object requestObject,
- Message message) {
- injectParameters(ori, ori.getClassResourceInfo(), requestObject, message);
- }
-
- @SuppressWarnings("unchecked")
- public static void injectParameters(OperationResourceInfo ori,
- BeanResourceInfo bri,
- Object requestObject,
- Message message) {
-
- if (bri.isSingleton()
- && (!bri.getParameterMethods().isEmpty() || !bri.getParameterFields().isEmpty())) {
- LOG.fine("Injecting request parameters into singleton resource is not thread-safe");
- }
- // Param methods
- MultivaluedMap<String, String> values =
- (MultivaluedMap<String, String>)message.get(URITemplate.TEMPLATE_PARAMETERS);
- for (Method m : bri.getParameterMethods()) {
- Parameter p = ResourceUtils.getParameter(0, m.getAnnotations(),
- m.getParameterTypes()[0]);
- Object o;
-
- if (p.getType() == ParameterType.BEAN) {
- o = createBeanParamValue(message, m.getParameterTypes()[0], ori);
- } else {
- o = createHttpParameterValue(p,
- m.getParameterTypes()[0],
- m.getGenericParameterTypes()[0],
- m.getParameterAnnotations()[0],
- message,
- values,
- ori);
- }
- InjectionUtils.injectThroughMethod(requestObject, m, o, message);
- }
- // Param fields
- for (Field f : bri.getParameterFields()) {
- Parameter p = ResourceUtils.getParameter(0, f.getAnnotations(),
- f.getType());
- final Object o;
-
- if (p.getType() == ParameterType.BEAN) {
- o = createBeanParamValue(message, f.getType(), ori);
- } else {
- o = createHttpParameterValue(p,
- f.getType(),
- f.getGenericType(),
- f.getAnnotations(),
- message,
- values,
- ori);
- }
- InjectionUtils.injectFieldValue(f, requestObject, o);
- }
- }
-
- public static Map<ClassResourceInfo, MultivaluedMap<String, String>> selectResourceClass(
- List<ClassResourceInfo> resources, String path, Message message) {
-
- LOG.fine(() -> new org.apache.cxf.common.i18n.Message("START_CRI_MATCH",
- BUNDLE,
- path).toString());
- if (resources.size() == 1) {
- MultivaluedMap<String, String> values = new MetadataMap<>();
- return resources.get(0).getURITemplate().match(path, values)
- ? Collections.singletonMap(resources.get(0), values) : null;
- }
-
- SortedMap<ClassResourceInfo, MultivaluedMap<String, String>> candidateList =
- new TreeMap<ClassResourceInfo, MultivaluedMap<String, String>>(
- new ClassResourceInfoComparator(message));
-
- for (ClassResourceInfo cri : resources) {
- MultivaluedMap<String, String> map = new MetadataMap<>();
- if (cri.getURITemplate().match(path, map)) {
- candidateList.put(cri, map);
- LOG.fine(() -> new org.apache.cxf.common.i18n.Message("CRI_SELECTED_POSSIBLY",
- BUNDLE,
- cri.getServiceClass().getName(),
- path,
- cri.getURITemplate().getValue()).toString());
- } else {
- LOG.fine(() -> new org.apache.cxf.common.i18n.Message("CRI_NO_MATCH",
- BUNDLE,
- path,
- cri.getServiceClass().getName()).toString());
- }
- }
-
- if (!candidateList.isEmpty()) {
- Map<ClassResourceInfo, MultivaluedMap<String, String>> cris =
- new LinkedHashMap<>(candidateList.size());
- ClassResourceInfo firstCri = null;
- for (Map.Entry<ClassResourceInfo, MultivaluedMap<String, String>> entry : candidateList.entrySet()) {
- ClassResourceInfo cri = entry.getKey();
- if (cris.isEmpty()) {
- firstCri = cri;
- cris.put(cri, entry.getValue());
- } else if (firstCri != null
- && URITemplate.compareTemplates(firstCri.getURITemplate(), cri.getURITemplate()) == 0) {
- cris.put(cri, entry.getValue());
- } else {
- break;
- }
- LOG.fine(() -> new org.apache.cxf.common.i18n.Message("CRI_SELECTED",
- BUNDLE,
- cri.getServiceClass().getName(),
- path, cri.getURITemplate().getValue()).toString());
- }
- return cris;
- }
-
- return null;
- }
- public static OperationResourceInfo findTargetMethod(
- Map<ClassResourceInfo, MultivaluedMap<String, String>> matchedResources,
- Message message,
- String httpMethod,
- MultivaluedMap<String, String> matchedValues,
- String requestContentType,
- List<MediaType> acceptContentTypes) {
- return findTargetMethod(matchedResources, message, httpMethod, matchedValues,
- requestContentType, acceptContentTypes, true, true);
- }
- //CHECKSTYLE:OFF
- public static OperationResourceInfo findTargetMethod(
- Map<ClassResourceInfo, MultivaluedMap<String, String>> matchedResources,
- Message message,
- String httpMethod,
- MultivaluedMap<String, String> matchedValues,
- String requestContentType,
- List<MediaType> acceptContentTypes,
- boolean throwException,
- boolean recordMatchedUri) {
- //CHECKSTYLE:ON
- final boolean getMethod = HttpMethod.GET.equals(httpMethod);
-
- MediaType requestType;
- try {
- requestType = toMediaType(requestContentType);
- } catch (IllegalArgumentException ex) {
- throw ExceptionUtils.toNotSupportedException(ex, null);
- }
-
- SortedMap<OperationResourceInfo, MultivaluedMap<String, String>> candidateList =
- new TreeMap<OperationResourceInfo, MultivaluedMap<String, String>>(
- new OperationResourceInfoComparator(message, httpMethod,
- getMethod, requestType, acceptContentTypes));
-
- int pathMatched = 0;
- int methodMatched = 0;
- int consumeMatched = 0;
-
- boolean resourceMethodsAdded = false;
- boolean generateOptionsResponse = false;
- List<OperationResourceInfo> finalPathSubresources = null;
- for (Map.Entry<ClassResourceInfo, MultivaluedMap<String, String>> rEntry : matchedResources.entrySet()) {
- ClassResourceInfo resource = rEntry.getKey();
- MultivaluedMap<String, String> values = rEntry.getValue();
-
- String path = getCurrentPath(values);
- LOG.fine(() -> new org.apache.cxf.common.i18n.Message("START_OPER_MATCH",
- BUNDLE,
- resource.getServiceClass().getName()).toString());
-
- for (OperationResourceInfo ori : resource.getMethodDispatcher().getOperationResourceInfos()) {
- boolean added = false;
-
- URITemplate uriTemplate = ori.getURITemplate();
- MultivaluedMap<String, String> map = new MetadataMap<>(values);
- if (uriTemplate != null && uriTemplate.match(path, map)) {
- String finalGroup = map.getFirst(URITemplate.FINAL_MATCH_GROUP);
- boolean finalPath = StringUtils.isEmpty(finalGroup) || PATH_SEGMENT_SEP.equals(finalGroup);
-
- if (ori.isSubResourceLocator()) {
- candidateList.put(ori, map);
- if (finalPath) {
- if (finalPathSubresources == null) {
- finalPathSubresources = new LinkedList<>();
- }
- finalPathSubresources.add(ori);
- }
- added = true;
- } else if (finalPath) {
- pathMatched++;
- if (matchHttpMethod(ori.getHttpMethod(), httpMethod)) {
- methodMatched++;
- //CHECKSTYLE:OFF
- if (getMethod || matchConsumeTypes(requestType, ori)) {
- consumeMatched++;
- for (MediaType acceptType : acceptContentTypes) {
- if (matchProduceTypes(acceptType, ori)) {
- candidateList.put(ori, map);
- added = true;
- resourceMethodsAdded = true;
- break;
- }
- }
- }
- //CHECKSTYLE:ON
- } else if ("OPTIONS".equalsIgnoreCase(httpMethod)) {
- generateOptionsResponse = true;
- }
- }
- }
- LOG.fine(matchMessageLogSupplier(ori, path, httpMethod, requestType, acceptContentTypes, added));
- }
- }
- if (finalPathSubresources != null && (resourceMethodsAdded || generateOptionsResponse)
- && !MessageUtils.getContextualBoolean(message, KEEP_SUBRESOURCE_CANDIDATES, false)) {
- for (OperationResourceInfo key : finalPathSubresources) {
- candidateList.remove(key);
- }
- }
- if (!candidateList.isEmpty()) {
- Map.Entry<OperationResourceInfo, MultivaluedMap<String, String>> firstEntry =
- candidateList.entrySet().iterator().next();
- matchedValues.clear();
- matchedValues.putAll(firstEntry.getValue());
- OperationResourceInfo ori = firstEntry.getKey();
- if (headMethodPossible(ori.getHttpMethod(), httpMethod)) {
- LOG.info(new org.apache.cxf.common.i18n.Message("GET_INSTEAD_OF_HEAD",
- BUNDLE, ori.getClassResourceInfo().getServiceClass().getName(),
- ori.getMethodToInvoke().getName()).toString());
- }
- LOG.fine(() -> new org.apache.cxf.common.i18n.Message("OPER_SELECTED",
- BUNDLE, ori.getMethodToInvoke().getName(),
- ori.getClassResourceInfo().getServiceClass().getName()).toString());
- if (!ori.isSubResourceLocator()) {
- MediaType responseMediaType = intersectSortMediaTypes(acceptContentTypes,
- ori.getProduceTypes(),
- false).get(0);
- message.getExchange().put(Message.CONTENT_TYPE, mediaTypeToString(responseMediaType,
- MEDIA_TYPE_Q_PARAM,
- MEDIA_TYPE_QS_PARAM));
- }
- if (recordMatchedUri) {
- pushOntoStack(ori, matchedValues, message);
- }
- return ori;
- }
-
- if (!throwException) {
- return null;
- }
-
- int status;
-
- // criteria matched the least number of times will determine the error code;
- // priority : path, method, consumes, produces;
- if (pathMatched == 0) {
- status = 404;
- } else if (methodMatched == 0) {
- status = 405;
- } else if (consumeMatched == 0) {
- status = 415;
- } else {
- // Not a single Produces match
- status = 406;
- }
- Map.Entry<ClassResourceInfo, MultivaluedMap<String, String>> firstCri =
- matchedResources.entrySet().iterator().next();
- String name = firstCri.getKey().isRoot() ? "NO_OP_EXC" : "NO_SUBRESOURCE_METHOD_FOUND";
- org.apache.cxf.common.i18n.Message errorMsg =
- new org.apache.cxf.common.i18n.Message(name,
- BUNDLE,
- message.get(Message.REQUEST_URI),
- getCurrentPath(firstCri.getValue()),
- httpMethod,
- mediaTypeToString(requestType),
- convertTypesToString(acceptContentTypes));
- if (!"OPTIONS".equalsIgnoreCase(httpMethod)) {
- Level logLevel = getExceptionLogLevel(message, ClientErrorException.class);
- LOG.log(logLevel == null ? Level.FINE : logLevel, () -> errorMsg.toString());
- }
- Response response =
- createResponse(getRootResources(message), message, errorMsg.toString(), status, methodMatched == 0);
- throw ExceptionUtils.toHttpException(null, response);
-
- }
-
-
-
- public static Level getExceptionLogLevel(Message message, Class<? extends WebApplicationException> exClass) {
- Level logLevel = null;
- Object logLevelProp = message.get(exClass.getName() + ".log.level");
- if (logLevelProp != null) {
- if (logLevelProp instanceof Level) {
- logLevel = (Level)logLevelProp;
- } else {
- try {
- logLevel = Level.parse(logLevelProp.toString());
- } catch (Exception ex) {
- // ignore
- }
- }
- }
- return logLevel;
- }
-
- private static List<MediaType> intersectSortMediaTypes(List<MediaType> acceptTypes,
- List<MediaType> producesTypes,
- final boolean checkDistance) {
- List<MediaType> all = intersectMimeTypes(acceptTypes, producesTypes, true, checkDistance);
- if (all.size() > 1) {
- all.sort(new Comparator<MediaType>() {
-
- public int compare(MediaType mt1, MediaType mt2) {
- int result = compareMediaTypes(mt1, mt2, null);
- if (result == 0) {
- result = compareQualityAndDistance(mt1, mt2, checkDistance);
- }
- return result;
- }
-
- });
- }
- return all;
- }
-
- private static int compareQualityAndDistance(MediaType mt1, MediaType mt2, boolean checkDistance) {
- int result = compareMediaTypesQualityFactors(mt1, mt2, MEDIA_TYPE_Q_PARAM);
- if (result == 0) {
- result = compareMediaTypesQualityFactors(mt1, mt2, MEDIA_TYPE_QS_PARAM);
- }
- if (result == 0 && checkDistance) {
- Integer dist1 = Integer.valueOf(mt1.getParameters().get(MEDIA_TYPE_DISTANCE_PARAM));
- Integer dist2 = Integer.valueOf(mt2.getParameters().get(MEDIA_TYPE_DISTANCE_PARAM));
- result = dist1.compareTo(dist2);
- }
- return result;
- }
-
- private static String getCurrentPath(MultivaluedMap<String, String> values) {
- String path = values.getFirst(URITemplate.FINAL_MATCH_GROUP);
- return path == null ? "/" : path;
- }
-
- public static List<ClassResourceInfo> getRootResources(Message message) {
- Service service = message.getExchange().getService();
- return ((JAXRSServiceImpl)service).getClassResourceInfos();
- }
-
- public static boolean noResourceMethodForOptions(Response exResponse, String httpMethod) {
- return exResponse != null && exResponse.getStatus() == 405
- && "OPTIONS".equalsIgnoreCase(httpMethod);
- }
-
- private static Supplier<String> matchMessageLogSupplier(OperationResourceInfo ori,
- String path, String httpMethod, MediaType requestType, List<MediaType> acceptContentTypes,
- boolean added) {
- org.apache.cxf.common.i18n.Message errorMsg = added
- ? new org.apache.cxf.common.i18n.Message("OPER_SELECTED_POSSIBLY",
- BUNDLE, ori.getMethodToInvoke().getName())
- : new org.apache.cxf.common.i18n.Message("OPER_NO_MATCH",
- BUNDLE,
- ori.getMethodToInvoke().getName(),
- path,
- ori.getURITemplate().getValue(),
- httpMethod,
- ori.getHttpMethod(),
- requestType.toString(),
- convertTypesToString(ori.getConsumeTypes()),
- convertTypesToString(acceptContentTypes),
- convertTypesToString(ori.getProduceTypes()));
- return () -> errorMsg.toString();
- }
-
- public static Response createResponse(List<ClassResourceInfo> cris, Message msg,
- String responseMessage, int status, boolean addAllow) {
- ResponseBuilder rb = toResponseBuilder(status);
- if (addAllow) {
- Set<String> allowedMethods = new HashSet<>();
- for (ClassResourceInfo cri : cris) {
- allowedMethods.addAll(cri.getAllowedMethods());
- }
-
- for (String m : allowedMethods) {
- rb.header("Allow", m);
- }
- // "OPTIONS" are supported all the time really
- if (!allowedMethods.contains("OPTIONS")) {
- rb.header("Allow", "OPTIONS");
- }
- if (!allowedMethods.contains("HEAD") && allowedMethods.contains("GET")) {
- rb.header("Allow", "HEAD");
- }
- }
- if (msg != null && MessageUtils.getContextualBoolean(msg, REPORT_FAULT_MESSAGE_PROPERTY)) {
- rb.type(MediaType.TEXT_PLAIN_TYPE).entity(responseMessage);
- }
- return rb.build();
- }
-
- private static boolean matchHttpMethod(String expectedMethod, String httpMethod) {
- return expectedMethod.equalsIgnoreCase(httpMethod)
- || headMethodPossible(expectedMethod, httpMethod)
- || expectedMethod.equals(DefaultMethod.class.getSimpleName());
- }
-
- public static boolean headMethodPossible(String expectedMethod, String httpMethod) {
- return HttpMethod.HEAD.equalsIgnoreCase(httpMethod) && HttpMethod.GET.equals(expectedMethod);
- }
-
- private static String convertTypesToString(List<MediaType> types) {
- StringBuilder sb = new StringBuilder();
- for (MediaType type : types) {
- sb.append(mediaTypeToString(type)).append(',');
- }
- return sb.toString();
- }
-
- public static List<MediaType> getConsumeTypes(Consumes cm) {
- return getConsumeTypes(cm, Collections.singletonList(ALL_TYPES));
- }
-
- public static List<MediaType> getConsumeTypes(Consumes cm, List<MediaType> defaultTypes) {
- return cm == null ? defaultTypes
- : getMediaTypes(cm.value());
- }
-
- public static List<MediaType> getProduceTypes(Produces pm) {
- return getProduceTypes(pm, Collections.singletonList(ALL_TYPES));
- }
-
- public static List<MediaType> getProduceTypes(Produces pm, List<MediaType> defaultTypes) {
- return pm == null ? defaultTypes
- : getMediaTypes(pm.value());
- }
-
- public static int compareSortedConsumesMediaTypes(List<MediaType> mts1, List<MediaType> mts2, MediaType ct) {
- List<MediaType> actualMts1 = getCompatibleMediaTypes(mts1, ct);
- List<MediaType> actualMts2 = getCompatibleMediaTypes(mts2, ct);
- return compareSortedMediaTypes(actualMts1, actualMts2, null);
- }
-
- public static int compareSortedAcceptMediaTypes(List<MediaType> mts1, List<MediaType> mts2,
- List<MediaType> acceptTypes) {
- List<MediaType> actualMts1 = intersectSortMediaTypes(mts1, acceptTypes, true);
- List<MediaType> actualMts2 = intersectSortMediaTypes(mts2, acceptTypes, true);
- int size1 = actualMts1.size();
- int size2 = actualMts2.size();
- for (int i = 0; i < size1 && i < size2; i++) {
- int result = compareMediaTypes(actualMts1.get(i), actualMts2.get(i), null);
- if (result == 0) {
- result = compareQualityAndDistance(actualMts1.get(i), actualMts2.get(i), true);
- }
- if (result != 0) {
- return result;
- }
- }
- return size1 == size2 ? 0 : size1 < size2 ? -1 : 1;
- }
-
- private static List<MediaType> getCompatibleMediaTypes(List<MediaType> mts, MediaType ct) {
- List<MediaType> actualMts;
- if (mts.size() == 1) {
- actualMts = mts;
- } else {
- actualMts = new LinkedList<>();
- for (MediaType mt : mts) {
- if (isMediaTypeCompatible(mt, ct)) {
- actualMts.add(mt);
- }
- }
- }
- return actualMts;
- }
-
- public static int compareSortedMediaTypes(List<MediaType> mts1, List<MediaType> mts2, String qs) {
- int size1 = mts1.size();
- int size2 = mts2.size();
- for (int i = 0; i < size1 && i < size2; i++) {
- int result = compareMediaTypes(mts1.get(i), mts2.get(i), qs);
- if (result != 0) {
- return result;
- }
- }
- return size1 == size2 ? 0 : size1 < size2 ? -1 : 1;
- }
-
- public static int compareMethodParameters(Class<?>[] paraList1, Class<?>[] paraList2) {
- int size1 = paraList1.length;
- int size2 = paraList2.length;
- for (int i = 0; i < size1 && i < size2; i++) {
- if (!paraList1[i].equals(paraList2[i])) {
- // Handling the case when bridge / synthetic methods may be taken
- // into account (f.e. when service implements generic interfaces or
- // extends the generic classes).
- if (paraList1[i].isAssignableFrom(paraList2[i])) {
- return 1;
- } else if (paraList2[i].isAssignableFrom(paraList1[i])) {
- return -1;
- } else {
- int result = paraList1[i].getName().compareTo(paraList2[i].getName());
- if (result != 0) {
- return result;
- }
- }
- }
- }
- return size1 == size2 ? 0 : size1 < size2 ? -1 : 1;
- }
- public static int compareMediaTypes(MediaType mt1, MediaType mt2) {
- return compareMediaTypes(mt1, mt2, MEDIA_TYPE_Q_PARAM);
- }
- public static int compareMediaTypes(MediaType mt1, MediaType mt2, String qs) {
-
- boolean mt1TypeWildcard = mt1.isWildcardType();
- boolean mt2TypeWildcard = mt2.isWildcardType();
- if (mt1TypeWildcard && !mt2TypeWildcard) {
- return 1;
- }
- if (!mt1TypeWildcard && mt2TypeWildcard) {
- return -1;
- }
-
- boolean mt1SubTypeWildcard = mt1.getSubtype().contains(MediaType.MEDIA_TYPE_WILDCARD);
- boolean mt2SubTypeWildcard = mt2.getSubtype().contains(MediaType.MEDIA_TYPE_WILDCARD);
- if (mt1SubTypeWildcard && !mt2SubTypeWildcard) {
- return 1;
- }
- if (!mt1SubTypeWildcard && mt2SubTypeWildcard) {
- return -1;
- }
-
- return qs != null ? compareMediaTypesQualityFactors(mt1, mt2, qs) : 0;
- }
-
- public static int compareMediaTypesQualityFactors(MediaType mt1, MediaType mt2) {
- float q1 = getMediaTypeQualityFactor(mt1.getParameters().get(MEDIA_TYPE_Q_PARAM));
- float q2 = getMediaTypeQualityFactor(mt2.getParameters().get(MEDIA_TYPE_Q_PARAM));
- return Float.compare(q1, q2) * -1;
- }
-
- public static int compareMediaTypesQualityFactors(MediaType mt1, MediaType mt2, String qs) {
- float q1 = getMediaTypeQualityFactor(mt1.getParameters().get(qs));
- float q2 = getMediaTypeQualityFactor(mt2.getParameters().get(qs));
- return Float.compare(q1, q2) * -1;
- }
-
- public static float getMediaTypeQualityFactor(String q) {
- if (q == null) {
- return 1;
- }
- if (q.charAt(0) == '.') {
- q = '0' + q;
- }
- try {
- return Float.parseFloat(q);
- } catch (NumberFormatException ex) {
- // default value will do
- }
- return 1;
- }
-
- //Message contains following information: PATH, HTTP_REQUEST_METHOD, CONTENT_TYPE, InputStream.
- public static List<Object> processParameters(OperationResourceInfo ori,
- MultivaluedMap<String, String> values,
- Message message)
- throws IOException, WebApplicationException {
-
- Class<?>[] parameterTypes = ori.getInParameterTypes();
- List<Parameter> paramsInfo = ori.getParameters();
- boolean preferModelParams = paramsInfo.size() > parameterTypes.length
- && !PropertyUtils.isTrue(message.getContextualProperty("org.apache.cxf.preferMethodParameters"));
-
- final int parameterTypesLength = preferModelParams ? paramsInfo.size() : parameterTypes.length;
- if (parameterTypesLength < 1) {
- return Collections.emptyList();
- }
-
- Type[] genericParameterTypes = ori.getInGenericParameterTypes();
- Annotation[][] anns = ori.getInParameterAnnotations();
- Object[] params = new Object[parameterTypesLength];
-
- // Ensure we process all request-body parameters first, then all @*Params, etc.
- ParamTuple[] tuple = new ParamTuple[parameterTypesLength];
- for (int i = 0; i < parameterTypesLength; i++) {
- tuple[i] = new ParamTuple();
- if (!preferModelParams) {
- tuple[i].param = parameterTypes[i];
- tuple[i].genericParam = InjectionUtils.processGenericTypeIfNeeded(
- ori.getClassResourceInfo().getServiceClass(), tuple[i].param, genericParameterTypes[i]);
- tuple[i].param = InjectionUtils.updateParamClassToTypeIfNeeded(tuple[i].param,
- tuple[i].genericParam);
- tuple[i].paramAnns = anns == null ? EMPTY_ANNOTATIONS : anns[i];
- } else {
- tuple[i].param = paramsInfo.get(i).getJavaType();
- tuple[i].genericParam = tuple[i].param;
- tuple[i].paramAnns = EMPTY_ANNOTATIONS;
- }
- if (paramsInfo.get(i).getType() == ParameterType.REQUEST_BODY) {
- params[i] = processRequestBodyParameter(tuple[i].param,
- tuple[i].genericParam,
- tuple[i].paramAnns,
- message,
- ori);
- }
- }
- for (int i = 0; i < parameterTypesLength; i++) {
-
- if (paramsInfo.get(i).getType() != ParameterType.REQUEST_BODY) {
- params[i] = processParameter(tuple[i].param,
- tuple[i].genericParam,
- tuple[i].paramAnns,
- paramsInfo.get(i),
- values,
- message,
- ori);
- }
- }
-
- return Arrays.asList(params);
- }
-
- private static class ParamTuple {
- private Class<?> param;
- private Type genericParam;
- private Annotation[] paramAnns;
- }
-
- private static Object processRequestBodyParameter(Class<?> parameterClass,
- Type parameterType,
- Annotation[] parameterAnns,
- Message message,
- OperationResourceInfo ori)
- throws IOException, WebApplicationException {
-
- if (parameterClass == AsyncResponse.class) {
- return new AsyncResponseImpl(message);
- }
-
- String contentType = (String)message.get(Message.CONTENT_TYPE);
-
- if (contentType == null) {
- String defaultCt = (String)message.getContextualProperty(DEFAULT_CONTENT_TYPE);
- contentType = defaultCt == null ? MediaType.APPLICATION_OCTET_STREAM : defaultCt;
- }
-
- final MediaType contentTypeMt = toMediaType(contentType);
- final MessageContext mc = new MessageContextImpl(message);
-
- MediaType mt = mc.getHttpHeaders().getMediaType();
- if (mt == null) {
- mt = contentTypeMt;
- }
-
- InputStream is;
- if (mt.isCompatible(MediaType.APPLICATION_FORM_URLENCODED_TYPE)) {
- is = copyAndGetEntityStream(message);
- } else {
- is = message.getContent(InputStream.class);
- }
-
- if (is == null) {
- Reader reader = message.getContent(Reader.class);
- if (reader != null) {
- is = new ReaderInputStream(reader);
- }
- }
-
- return readFromMessageBody(parameterClass,
- parameterType,
- parameterAnns,
- is,
- contentTypeMt,
- ori,
- message);
- }
-
- private static Object processParameter(Class<?> parameterClass,
- Type parameterType,
- Annotation[] parameterAnns,
- Parameter parameter,
- MultivaluedMap<String, String> values,
- Message message,
- OperationResourceInfo ori)
- throws IOException, WebApplicationException {
-
- if (parameter.getType() == ParameterType.REQUEST_BODY) {
- return processRequestBodyParameter(parameterClass, parameterType, parameterAnns, message, ori);
- } else if (parameter.getType() == ParameterType.CONTEXT) {
- return createContextValue(message, parameterType, parameterClass);
- } else if (parameter.getType() == ParameterType.BEAN) {
- return createBeanParamValue(message, parameterClass, ori);
- } else {
-
- return createHttpParameterValue(parameter,
- parameterClass,
- parameterType,
- parameterAnns,
- message,
- values,
- ori);
- }
- }
-
- public static Object createHttpParameterValue(Parameter parameter,
- Class<?> parameterClass,
- Type genericParam,
- Annotation[] paramAnns,
- Message message,
- MultivaluedMap<String, String> values,
- OperationResourceInfo ori) {
-
- boolean isEncoded = parameter.isEncoded() || ori != null && ori.isEncodedEnabled();
- String defaultValue = parameter.getDefaultValue();
- if (defaultValue == null && ori != null) {
- defaultValue = ori.getDefaultParameterValue();
- }
-
- if (parameter.getType() == ParameterType.PATH) {
- return readFromUriParam(message, parameter.getName(), parameterClass, genericParam,
- paramAnns, values, defaultValue, !isEncoded);
- }
-
- if (parameter.getType() == ParameterType.QUERY) {
- return readQueryString(parameter.getName(), parameterClass, genericParam,
- paramAnns, message, defaultValue, !isEncoded);
- }
-
- if (parameter.getType() == ParameterType.MATRIX) {
- return processMatrixParam(message, parameter.getName(), parameterClass, genericParam,
- paramAnns, defaultValue, !isEncoded);
- }
-
- if (parameter.getType() == ParameterType.FORM) {
- return processFormParam(message, parameter.getName(), parameterClass, genericParam,
- paramAnns, defaultValue, !isEncoded);
- }
-
- if (parameter.getType() == ParameterType.COOKIE) {
- return processCookieParam(message, parameter.getName(), parameterClass, genericParam,
- paramAnns, defaultValue);
- }
-
- Object result = null;
- if (parameter.getType() == ParameterType.HEADER) {
- result = processHeaderParam(message, parameter.getName(), parameterClass, genericParam,
- paramAnns, defaultValue);
- }
- return result;
- }
-
- private static Object processMatrixParam(Message m, String key,
- Class<?> pClass, Type genericType,
- Annotation[] paramAnns,
- String defaultValue,
- boolean decode) {
- List<PathSegment> segments = JAXRSUtils.getPathSegments(
- (String)m.get(Message.REQUEST_URI), decode);
- if (!segments.isEmpty()) {
- MultivaluedMap<String, String> params = new MetadataMap<>();
- for (PathSegment ps : segments) {
- MultivaluedMap<String, String> matrix = ps.getMatrixParameters();
- for (Map.Entry<String, List<String>> entry : matrix.entrySet()) {
- for (String value : entry.getValue()) {
- params.add(entry.getKey(), value);
- }
- }
- }
-
- if ("".equals(key)) {
- return InjectionUtils.handleBean(pClass, paramAnns, params, ParameterType.MATRIX, m, false);
- }
- List<String> values = params.get(key);
- return InjectionUtils.createParameterObject(values,
- pClass,
- genericType,
- paramAnns,
- defaultValue,
- false,
- ParameterType.MATRIX,
- m);
- }
-
- return null;
- }
-
- private static Object processFormParam(Message m, String key,
- Class<?> pClass, Type genericType,
- Annotation[] paramAnns,
- String defaultValue,
- boolean decode) {
-
- MessageContext mc = new MessageContextImpl(m);
- MediaType mt = mc.getHttpHeaders().getMediaType();
-
- @SuppressWarnings("unchecked")
- MultivaluedMap<String, String> params =
- (MultivaluedMap<String, String>)m.get(FormUtils.FORM_PARAM_MAP);
-
- String enc = HttpUtils.getEncoding(mt, StandardCharsets.UTF_8.name());
- if (params == null) {
- params = new MetadataMap<>();
- m.put(FormUtils.FORM_PARAM_MAP, params);
-
- if (mt == null || mt.isCompatible(MediaType.APPLICATION_FORM_URLENCODED_TYPE)) {
- InputStream entityStream = copyAndGetEntityStream(m);
- String body = FormUtils.readBody(entityStream, enc);
- // Do not decode unless the key is empty value, fe @FormParam("")
- FormUtils.populateMapFromStringOrHttpRequest(params, m, body, enc, StringUtils.isEmpty(key) && decode);
- } else {
- if ("multipart".equalsIgnoreCase(mt.getType())
- && MediaType.MULTIPART_FORM_DATA_TYPE.isCompatible(mt)) {
- MultipartBody body = AttachmentUtils.getMultipartBody(mc);
- FormUtils.populateMapFromMultipart(params, body, m, decode);
- } else {
- org.apache.cxf.common.i18n.Message errorMsg =
- new org.apache.cxf.common.i18n.Message("WRONG_FORM_MEDIA_TYPE",
- BUNDLE,
- mt.toString());
- LOG.warning(errorMsg.toString());
- throw ExceptionUtils.toNotSupportedException(null, null);
- }
- }
- }
-
- if (decode && !MessageUtils.getContextualBoolean(m, FormUtils.FORM_PARAM_MAP_DECODED, false)) {
- List<String> values = params.get(key);
- if (values != null) {
- values = values.stream().map(value -> HttpUtils.urlDecode(value, enc)).collect(Collectors.toList());
- params.replace(key, values);
- }
- }
-
- if ("".equals(key)) {
- return InjectionUtils.handleBean(pClass, paramAnns, params, ParameterType.FORM, m, false);
- }
- List<String> results = params.get(key);
-
- return InjectionUtils.createParameterObject(results,
- pClass,
- genericType,
- paramAnns,
- defaultValue,
- false,
- ParameterType.FORM,
- m);
- }
-
-
- public static MultivaluedMap<String, String> getMatrixParams(String path, boolean decode) {
- int index = path.indexOf(';');
- return index == -1 ? new MetadataMap<String, String>()
- : JAXRSUtils.getStructuredParams(path.substring(index + 1), ";", decode, false);
- }
-
- private static Object processHeaderParam(Message m,
- String header,
- Class<?> pClass,
- Type genericType,
- Annotation[] paramAnns,
- String defaultValue) {
-
- List<String> values = new HttpHeadersImpl(m).getRequestHeader(header);
- if (values != null && values.isEmpty()) {
- values = null;
- }
- return InjectionUtils.createParameterObject(values,
- pClass,
- genericType,
- paramAnns,
- defaultValue,
- false,
- ParameterType.HEADER,
- m);
-
-
- }
-
- private static Object processCookieParam(Message m, String cookieName,
- Class<?> pClass, Type genericType,
- Annotation[] paramAnns, String defaultValue) {
- Cookie c = new HttpHeadersImpl(m).getCookies().get(cookieName);
-
- if (c == null && defaultValue != null) {
- c = Cookie.valueOf(cookieName + '=' + defaultValue);
- }
- if (c == null) {
- return null;
- }
-
- if (pClass.isAssignableFrom(Cookie.class)) {
- return c;
- }
- String value = InjectionUtils.isSupportedCollectionOrArray(pClass)
- && InjectionUtils.getActualType(genericType) == Cookie.class
- ? c.toString() : c.getValue();
- return InjectionUtils.createParameterObject(Collections.singletonList(value),
- pClass,
- genericType,
- paramAnns,
- null,
- false,
- ParameterType.COOKIE,
- m);
- }
-
- public static Object createBeanParamValue(Message m, Class<?> clazz, OperationResourceInfo ori) {
- BeanParamInfo bmi = ServerProviderFactory.getInstance(m).getBeanParamInfo(clazz);
- if (bmi == null) {
- // we could've started introspecting now but the fact no bean info
- // is available indicates that the one created at start up has been
- // lost and hence it is 500
- LOG.warning("Bean parameter info is not available");
- throw ExceptionUtils.toInternalServerErrorException(null, null);
- }
- Object instance;
- try {
- instance = clazz.newInstance();
- } catch (Throwable t) {
- throw ExceptionUtils.toInternalServerErrorException(t, null);
- }
- JAXRSUtils.injectParameters(ori, bmi, instance, m);
-
- InjectionUtils.injectContexts(instance, bmi, m);
-
- return instance;
- }
-
- public static Message getContextMessage(Message m) {
-
- Message contextMessage = m.getExchange() != null ? m.getExchange().getInMessage() : m;
- if (contextMessage == null && !PropertyUtils.isTrue(m.get(Message.INBOUND_MESSAGE))) {
- contextMessage = m;
- }
- return contextMessage;
- }
-
- public static <T> T createContextValue(Message m, Type genericType, Class<T> clazz) {
-
- Message contextMessage = getContextMessage(m);
- Object o = null;
- if (UriInfo.class.isAssignableFrom(clazz)) {
- o = createUriInfo(contextMessage);
- } else if (HttpHeaders.class.isAssignableFrom(clazz)
- || ProtocolHeaders.class.isAssignableFrom(clazz)) {
- o = createHttpHeaders(contextMessage, clazz);
- } else if (SecurityContext.class.isAssignableFrom(clazz)) {
- SecurityContext customContext = contextMessage.get(SecurityContext.class);
- o = customContext == null ? new SecurityContextImpl(contextMessage) : customContext;
- } else if (MessageContext.class.isAssignableFrom(clazz)) {
- o = new MessageContextImpl(m);
- } else if (ResourceInfo.class.isAssignableFrom(clazz)) {
- o = new ResourceInfoImpl(contextMessage);
- } else if (ResourceContext.class.isAssignableFrom(clazz)) {
- OperationResourceInfo operationResourceInfo = contextMessage.getExchange().get(OperationResourceInfo.class);
- if (operationResourceInfo != null) {
- o = new ResourceContextImpl(contextMessage, operationResourceInfo);
- }
- } else if (Request.class.isAssignableFrom(clazz)) {
- o = new RequestImpl(contextMessage);
- } else if (Providers.class.isAssignableFrom(clazz)) {
- o = new ProvidersImpl(contextMessage);
- } else if (ContextResolver.class.isAssignableFrom(clazz)) {
- o = createContextResolver(genericType, contextMessage);
- } else if (Configuration.class.isAssignableFrom(clazz)) {
- o = ProviderFactory.getInstance(contextMessage).getConfiguration(contextMessage);
- } else if (Application.class.isAssignableFrom(clazz)) {
- ProviderInfo<?> providerInfo =
- (ProviderInfo<?>)contextMessage.getExchange().getEndpoint().get(Application.class.getName());
- o = providerInfo == null ? null : providerInfo.getProvider();
- } else if (contextMessage != null) {
- ContextProvider<?> provider =
- ProviderFactory.getInstance(contextMessage).createContextProvider(clazz, contextMessage);
- if (provider != null) {
- o = provider.createContext(contextMessage);
- }
- }
- if (o == null && contextMessage != null && !MessageUtils.isRequestor(contextMessage)) {
- o = HttpUtils.createServletResourceValue(contextMessage, clazz);
- }
- return clazz.cast(o);
- }
-
- @SuppressWarnings("unchecked")
- private static UriInfo createUriInfo(Message m) {
- if (MessageUtils.isRequestor(m)) {
- m = m.getExchange() != null ? m.getExchange().getOutMessage() : m;
- }
- MultivaluedMap<String, String> templateParams =
- (MultivaluedMap<String, String>)m.get(URITemplate.TEMPLATE_PARAMETERS);
- return new UriInfoImpl(m, templateParams);
- }
-
- private static Object createHttpHeaders(Message m, Class<?> ctxClass) {
- if (MessageUtils.isRequestor(m)) {
- m = m.getExchange() != null ? m.getExchange().getOutMessage() : m;
- }
- return HttpHeaders.class.isAssignableFrom(ctxClass) ? new HttpHeadersImpl(m)
- : new ProtocolHeadersImpl(m);
- }
-
- public static ContextResolver<?> createContextResolver(Type genericType, Message m) {
- if (genericType instanceof ParameterizedType) {
- return ProviderFactory.getInstance(m).createContextResolver(
- ((ParameterizedType)genericType).getActualTypeArguments()[0], m);
- } else if (m != null) {
- return ProviderFactory.getInstance(m).createContextResolver(genericType, m);
- } else {
- return null;
- }
- }
-
- public static Object createResourceValue(Message m, Type genericType, Class<?> clazz) {
-
- // lets assume we're aware of servlet types only that can be @Resource-annotated
- return createContextValue(m, genericType, clazz);
- }
-
-
- //CHECKSTYLE:OFF
- private static Object readFromUriParam(Message m,
- String parameterName,
- Class<?> paramType,
- Type genericType,
- Annotation[] paramAnns,
- MultivaluedMap<String, String> values,
- String defaultValue,
- boolean decoded) {
- //CHECKSTYLE:ON
- if ("".equals(parameterName)) {
- return InjectionUtils.handleBean(paramType, paramAnns, values, ParameterType.PATH, m, decoded);
- }
- List<String> results = values.get(parameterName);
- return InjectionUtils.createParameterObject(results,
- paramType,
- genericType,
- paramAnns,
- defaultValue,
- decoded,
- ParameterType.PATH,
- m);
- }
-
-
-
- //TODO : multiple query string parsing, do it once
- private static Object readQueryString(String queryName,
- Class<?> paramType,
- Type genericType,
- Annotation[] paramAnns,
- Message m,
- String defaultValue,
- boolean decode) {
-
- MultivaluedMap<String, String> queryMap = new UriInfoImpl(m, null).getQueryParameters(decode);
-
- if ("".equals(queryName)) {
- return InjectionUtils.handleBean(paramType, paramAnns, queryMap, ParameterType.QUERY, m, false);
- }
- return InjectionUtils.createParameterObject(queryMap.get(queryName),
- paramType,
- genericType,
- paramAnns,
- defaultValue,
- false,
- ParameterType.QUERY, m);
- }
-
-
-
- /**
- * Retrieve map of query parameters from the passed in message
- * @return a Map of query parameters.
- */
- public static MultivaluedMap<String, String> getStructuredParams(String query,
- String sep,
- boolean decode,
- boolean decodePlus) {
- MultivaluedMap<String, String> map =
- new MetadataMap<>(new LinkedHashMap<String, List<String>>());
-
- getStructuredParams(map, query, sep, decode, decodePlus);
-
- return map;
- }
-
- public static void getStructuredParams(MultivaluedMap<String, String> queries,
- String query,
- String sep,
- boolean decode,
- boolean decodePlus) {
- getStructuredParams(queries, query, sep, decode, decodePlus, false);
- }
-
- public static void getStructuredParams(MultivaluedMap<String, String> queries,
- String query,
- String sep,
- boolean decode,
- boolean decodePlus,
- boolean valueIsCollection) {
- if (!StringUtils.isEmpty(query)) {
- for (String part : query.split(sep)) { // fastpath expected
- int index = part.indexOf('=');
- final String name;
- String value = null;
- if (index == -1) {
- name = part;
- } else {
- name = part.substring(0, index);
- value = index < part.length() ? part.substring(index + 1) : "";
- }
- if (valueIsCollection) {
- if (value != null) {
- for (String s : value.split(",")) {
- addStructuredPartToMap(queries, sep, name, s, decode, decodePlus);
- }
- }
- } else {
- addStructuredPartToMap(queries, sep, name, value, decode, decodePlus);
- }
- }
- }
- }
-
- private static void addStructuredPartToMap(MultivaluedMap<String, String> queries,
- String sep,
- String name,
- String value,
- boolean decode,
- boolean decodePlus) {
-
- if (value != null) {
- if (decodePlus && value.contains("+")) {
- value = value.replace('+', ' ');
- }
- if (decode) {
- value = (";".equals(sep))
- ? HttpUtils.pathDecode(value) : HttpUtils.urlDecode(value);
- }
- }
-
- queries.add(HttpUtils.urlDecode(name), value);
- }
-
- private static Object readFromMessageBody(Class<?> targetTypeClass,
- Type parameterType,
- Annotation[] parameterAnnotations,
- InputStream is,
- MediaType contentType,
- OperationResourceInfo ori,
- Message m) throws IOException, WebApplicationException {
-
- List<MediaType> types = JAXRSUtils.intersectMimeTypes(ori.getConsumeTypes(), contentType);
-
- final ProviderFactory pf = ServerProviderFactory.getInstance(m);
- for (MediaType type : types) {
- List<ReaderInterceptor> readers = pf.createMessageBodyReaderInterceptor(
- targetTypeClass,
- parameterType,
- parameterAnnotations,
- type,
- m,
- true,
- ori.getNameBindings());
- if (readers != null) {
- try {
- return readFromMessageBodyReader(readers,
- targetTypeClass,
- parameterType,
- parameterAnnotations,
- is,
- type,
- m);
- } catch (IOException e) {
- if (e.getClass().getName().equals(NO_CONTENT_EXCEPTION)) {
- throw ExceptionUtils.toBadRequestException(e, null);
- }
- throw e;
- } catch (WebApplicationException ex) {
- throw ex;
- } catch (Exception ex) {
- throw new Fault(ex);
- }
- }
- }
-
- logMessageHandlerProblem("NO_MSG_READER", targetTypeClass, contentType);
- throw new WebApplicationException(Response.Status.UNSUPPORTED_MEDIA_TYPE);
- }
-
- @SuppressWarnings("unchecked")
- public static Object readFromMessageBodyReader(List<ReaderInterceptor> readers,
- Class<?> targetTypeClass,
- Type parameterType,
- Annotation[] parameterAnnotations,
- InputStream is,
- MediaType mediaType,
- Message m) throws IOException, WebApplicationException {
-
- // Verbose but avoids an extra context instantiation for the typical path
- if (readers.size() > 1) {
- ReaderInterceptor first = readers.remove(0);
- ReaderInterceptorContext context = new ReaderInterceptorContextImpl(targetTypeClass,
- parameterType,
- parameterAnnotations,
- is,
- m,
- readers);
-
- return first.aroundReadFrom(context);
- }
- MessageBodyReader<?> provider = ((ReaderInterceptorMBR)readers.get(0)).getMBR();
- @SuppressWarnings("rawtypes")
- Class cls = targetTypeClass;
- return provider.readFrom(
- cls, parameterType, parameterAnnotations, mediaType,
- new HttpHeadersImpl(m).getRequestHeaders(), is);
- }
-
-
- //CHECKSTYLE:OFF
- public static void writeMessageBody(List<WriterInterceptor> writers,
- Object entity,
- Class<?> type, Type genericType,
- Annotation[] annotations,
- MediaType mediaType,
- MultivaluedMap<String, Object> httpHeaders,
- Message message)
- throws WebApplicationException, IOException {
-
- OutputStream entityStream = message.getContent(OutputStream.class);
- if ("org.apache.cxf.jaxrs.reactivestreams.server.StreamingAsyncSubscriber$StreamingResponseImpl".equals(
- entity.getClass().getName())) {
- //cache the OutputStream when it's reactive response
- entityStream = new CacheAndWriteOutputStream(entityStream);
- }
-
- if (writers.size() > 1) {
- WriterInterceptor first = writers.remove(0);
- WriterInterceptorContext context = new WriterInterceptorContextImpl(entity,
- type,
- genericType,
- annotations,
- entityStream,
- message,
- writers);
-
- first.aroundWriteTo(context);
- } else {
- MessageBodyWriter<Object> writer = ((WriterInterceptorMBW)writers.get(0)).getMBW();
- if (type == byte[].class) {
- long size = writer.getSize(entity, type, genericType, annotations, mediaType);
- if (size != -1) {
- httpHeaders.putSingle(HttpHeaders.CONTENT_LENGTH, Long.toString(size));
- }
- }
- HttpUtils.convertHeaderValuesToString(httpHeaders, true);
- writer.writeTo(entity, type, genericType, annotations, mediaType,
- httpHeaders,
- entityStream);
- }
- }
- //CHECKSTYLE:ON
-
-
- public static boolean matchConsumeTypes(MediaType requestContentType,
- OperationResourceInfo ori) {
-
- return doMimeTypesIntersect(ori.getConsumeTypes(), requestContentType);
- }
-
- public static boolean matchProduceTypes(MediaType acceptContentType,
- OperationResourceInfo ori) {
-
- return doMimeTypesIntersect(ori.getProduceTypes(), acceptContentType);
- }
-
- public static boolean matchMimeTypes(MediaType requestContentType,
- MediaType acceptContentType,
- OperationResourceInfo ori) {
-
- return doMimeTypesIntersect(ori.getConsumeTypes(), requestContentType)
- && doMimeTypesIntersect(ori.getProduceTypes(), acceptContentType);
- }
-
- public static List<MediaType> parseMediaTypes(String types) {
- List<MediaType> acceptValues = new ArrayList<>();
-
- if (types != null) {
- int x = 0;
- int y = types.indexOf(',');
- while (y > 0) {
- acceptValues.add(toMediaType(types.substring(x, y).trim()));
- x = y + 1;
- y = types.indexOf(',', x);
- }
- String lastMediaType = types.substring(x).trim();
- if (!lastMediaType.isEmpty()) {
- acceptValues.add(toMediaType(lastMediaType));
- }
- } else {
- acceptValues.add(ALL_TYPES);
- }
-
- return acceptValues;
- }
-
- public static boolean doMimeTypesIntersect(List<MediaType> mimeTypesA, MediaType mimeTypeB) {
- return doMimeTypesIntersect(mimeTypesA, Collections.singletonList(mimeTypeB));
- }
-
- public static boolean doMimeTypesIntersect(List<MediaType> requiredMediaTypes, List<MediaType> userMediaTypes) {
- final NonAccumulatingIntersector intersector = new NonAccumulatingIntersector();
- intersectMimeTypes(requiredMediaTypes, userMediaTypes, intersector);
- return intersector.doIntersect();
- }
-
- /**
- * intersect two mime types
- *
- * @param requiredMediaTypes
- * @param userMediaTypes
- * @param addRequiredParamsIfPossible
- * @return return a list of intersected mime types
- */
- public static List<MediaType> intersectMimeTypes(List<MediaType> requiredMediaTypes,
- List<MediaType> userMediaTypes,
- boolean addRequiredParamsIfPossible) {
- return intersectMimeTypes(requiredMediaTypes, userMediaTypes, addRequiredParamsIfPossible, false);
- }
-
- public static List<MediaType> intersectMimeTypes(List<MediaType> requiredMediaTypes,
- List<MediaType> userMediaTypes,
- boolean addRequiredParamsIfPossible,
- boolean addDistanceParameter) {
- final AccumulatingIntersector intersector = new AccumulatingIntersector(addRequiredParamsIfPossible,
- addDistanceParameter);
- intersectMimeTypes(requiredMediaTypes, userMediaTypes, intersector);
- return new ArrayList<>(intersector.getSupportedMimeTypeList());
- }
-
- private static void intersectMimeTypes(List<MediaType> requiredMediaTypes, List<MediaType> userMediaTypes,
- MimeTypesIntersector intersector) {
-
- for (MediaType requiredType : requiredMediaTypes) {
- for (MediaType userType : userMediaTypes) {
- boolean isCompatible = isMediaTypeCompatible(requiredType, userType);
- if (isCompatible) {
- boolean parametersMatched = true;
- for (Map.Entry<String, String> entry : userType.getParameters().entrySet()) {
- String value = requiredType.getParameters().get(entry.getKey());
- if (value != null && entry.getValue() != null && !(stripDoubleQuotesIfNeeded(value)
- .equals(stripDoubleQuotesIfNeeded(entry.getValue())))) {
-
- if (HTTP_CHARSET_PARAM.equals(entry.getKey()) && value.equalsIgnoreCase(entry.getValue())) {
- continue;
- }
- parametersMatched = false;
- break;
- }
- }
- if (!parametersMatched) {
- continue;
- }
-
- if (!intersector.intersect(requiredType, userType)) {
- return;
- }
- }
- }
- }
- }
-
- private static String stripDoubleQuotesIfNeeded(String value) {
- if (value != null && value.startsWith("\"")
- && value.endsWith("\"") && value.length() > 1) {
- value = value.substring(1, value.length() - 1);
- }
- return value;
- }
-
- private static boolean isMediaTypeCompatible(MediaType requiredType, MediaType userType) {
- boolean isCompatible = requiredType.isCompatible(userType);
- if (!isCompatible && requiredType.getType().equalsIgnoreCase(userType.getType())) {
- isCompatible = compareCompositeSubtypes(requiredType, userType,
- PhaseInterceptorChain.getCurrentMessage());
- }
- return isCompatible;
- }
-
- static boolean compareCompositeSubtypes(String requiredType, String userType,
- Message message) {
- return compareCompositeSubtypes(toMediaType(requiredType), toMediaType(userType), message);
- }
-
- private static boolean compareCompositeSubtypes(MediaType requiredType, MediaType userType,
- Message message) {
- boolean isCompatible = false;
- // check if we have composite subtypes
- String subType1 = requiredType.getSubtype();
- String subType2 = userType.getSubtype();
-
- String subTypeAfterPlus1 = splitMediaSubType(subType1, true);
- String subTypeAfterPlus2 = splitMediaSubType(subType2, true);
- if (message != null && MessageUtils.getContextualBoolean(message, PARTIAL_HIERARCHICAL_MEDIA_SUBTYPE_CHECK)) {
- if (subTypeAfterPlus1 != null || subTypeAfterPlus2 != null) {
- boolean nullPossible = subTypeAfterPlus1 == null || subTypeAfterPlus2 == null;
- isCompatible = subTypeAfterPlus1 == null && subTypeAfterPlus2.equals(subType1)
- || subTypeAfterPlus2 == null && subTypeAfterPlus1.equals(subType2);
- if (!isCompatible && !nullPossible) {
- isCompatible = subTypeAfterPlus1.equalsIgnoreCase(subTypeAfterPlus2)
- && (subType1.charAt(0) == '*' || subType2.charAt(0) == '*');
- }
-
- if (!isCompatible) {
- String subTypeBeforePlus1 = splitMediaSubType(subType1, false);
- String subTypeBeforePlus2 = splitMediaSubType(subType2, false);
- nullPossible = subTypeBeforePlus1 == null || subTypeBeforePlus2 == null;
- isCompatible = subTypeBeforePlus1 == null && subTypeBeforePlus2 != null
- && subTypeBeforePlus2.equals(subType1)
- || subTypeBeforePlus2 == null && subTypeBeforePlus1 != null
- && subTypeBeforePlus1.equals(subType2);
- if (!isCompatible && !nullPossible) {
- isCompatible = subTypeBeforePlus1.equalsIgnoreCase(subTypeBeforePlus2)
- && (subType1.charAt(subType1.length() - 1) == '*'
- || subType2.charAt(subType2.length() - 1) == '*');
- }
- }
- }
- } else {
- if (subTypeAfterPlus1 != null && subTypeAfterPlus2 != null) {
-
- isCompatible = subTypeAfterPlus1.equalsIgnoreCase(subTypeAfterPlus2)
- && (subType1.charAt(0) == '*' || subType2.charAt(0) == '*');
-
- if (!isCompatible) {
- String subTypeBeforePlus1 = splitMediaSubType(subType1, false);
- String subTypeBeforePlus2 = splitMediaSubType(subType2, false);
-
- isCompatible = subTypeBeforePlus1 != null && subTypeBeforePlus1.equalsIgnoreCase(subTypeBeforePlus2)
- && (subType1.charAt(subType1.length() - 1) == '*'
- || subType2.charAt(subType2.length() - 1) == '*');
- }
- }
- }
- return isCompatible;
- }
-
- private static String splitMediaSubType(String type, boolean after) {
- int index = type.indexOf('+');
- return index == -1 ? null : after ? type.substring(index + 1) : type.substring(0, index);
- }
-
- public static List<MediaType> intersectMimeTypes(List<MediaType> mimeTypesA,
- MediaType mimeTypeB) {
- return intersectMimeTypes(mimeTypesA,
- Collections.singletonList(mimeTypeB), false);
- }
-
- public static List<MediaType> intersectMimeTypes(String mimeTypesA,
- String mimeTypesB) {
- return intersectMimeTypes(parseMediaTypes(mimeTypesA),
- parseMediaTypes(mimeTypesB),
- false);
- }
-
- public static List<MediaType> sortMediaTypes(String mediaTypes, String qs) {
- return sortMediaTypes(JAXRSUtils.parseMediaTypes(mediaTypes), qs);
- }
- public static List<MediaType> sortMediaTypes(List<MediaType> types, final String qs) {
- if (types.size() > 1) {
- Collections.sort(types, new Comparator<MediaType>() {
-
- public int compare(MediaType mt1, MediaType mt2) {
- return JAXRSUtils.compareMediaTypes(mt1, mt2, qs);
- }
-
- });
- }
- return types;
- }
-
-
- public static <T extends Throwable> Response convertFaultToResponse(T ex, Message currentMessage) {
- return ExceptionUtils.convertFaultToResponse(ex, currentMessage);
- }
-
- public static void setMessageContentType(Message message, Response response) {
- if (response != null) {
- Object ct = response.getMetadata().getFirst(HttpHeaders.CONTENT_TYPE);
- if (ct != null) {
- Exchange ex = message.getExchange();
- if (ex.getInMessage() == message) {
- ex.put(Message.CONTENT_TYPE, ct.toString());
- } else {
- message.put(Message.CONTENT_TYPE, ct.toString());
- }
- }
- }
-
- }
-
- public static QName getClassQName(Class<?> type) {
- String nsURI = PackageUtils.getNamespace(PackageUtils.getPackageName(type));
- if (nsURI.endsWith("/")) {
- nsURI = nsURI.substring(0, nsURI.length() - 1);
- }
- return new QName(nsURI, type.getSimpleName(), "ns1");
- }
-
- public static QName convertStringToQName(String name) {
- return DOMUtils.convertStringToQName(name, "");
- }
-
- public static boolean runContainerRequestFilters(ServerProviderFactory pf,
- Message m,
- boolean preMatch,
- Set<String> names) throws IOException {
- List<ProviderInfo<ContainerRequestFilter>> containerFilters = preMatch
- ? pf.getPreMatchContainerRequestFilters() : pf.getPostMatchContainerRequestFilters(names);
- if (!containerFilters.isEmpty()) {
- ContainerRequestContext context = new ContainerRequestContextImpl(m, preMatch, false);
- for (ProviderInfo<ContainerRequestFilter> filter : containerFilters) {
- InjectionUtils.injectContexts(filter.getProvider(), filter, m);
- filter.getProvider().filter(context);
- Response response = m.getExchange().get(Response.class);
- if (response != null) {
- setMessageContentType(m, response);
- return true;
- }
- }
- }
- return false;
- }
-
- public static void runContainerResponseFilters(ServerProviderFactory pf,
- ResponseImpl r,
- Message m,
- OperationResourceInfo ori,
- Method invoked) throws IOException, Throwable {
- List<ProviderInfo<ContainerResponseFilter>> containerFilters =
- pf.getContainerResponseFilters(ori == null ? null : ori.getNameBindings());
- if (!containerFilters.isEmpty()) {
- ContainerRequestContext requestContext =
- new ContainerRequestContextImpl(m.getExchange().getInMessage(),
- false,
- true);
- ContainerResponseContext responseContext =
- new ContainerResponseContextImpl(r, m,
- ori == null ? null : ori.getClassResourceInfo().getServiceClass(), invoked);
- for (ProviderInfo<ContainerResponseFilter> filter : containerFilters) {
- InjectionUtils.injectContexts(filter.getProvider(), filter, m);
- filter.getProvider().filter(requestContext, responseContext);
- }
- }
- }
-
- public static String mediaTypeToString(MediaType mt, String... ignoreParams) {
- List<String> list = ignoreParams == null || ignoreParams.length == 0 ? null
- : Arrays.asList(ignoreParams);
-
- return MediaTypeHeaderProvider.typeToString(mt, list);
- }
-
- public static MediaType toMediaType(String value) {
- if (value == null) {
- return ALL_TYPES;
- }
- return MediaTypeHeaderProvider.valueOf(value);
- }
-
- public static Response toResponse(int status) {
- return toResponseBuilder(status).build();
- }
-
- public static Response toResponse(Response.Status status) {
- return toResponse(status.getStatusCode());
- }
-
- public static ResponseBuilder toResponseBuilder(int status) {
- return new ResponseBuilderImpl().status(status);
- }
-
- public static ResponseBuilder toResponseBuilder(Response.Status status) {
- return toResponseBuilder(status.getStatusCode());
- }
-
- public static ResponseBuilder fromResponse(Response response) {
- return fromResponse(response, true);
- }
-
- public static ResponseBuilder fromResponse(Response response, boolean copyEntity) {
- ResponseBuilder rb = toResponseBuilder(response.getStatus());
- if (copyEntity) {
- rb.entity(response.getEntity());
- }
- for (Map.Entry<String, List<Object>> entry : response.getMetadata().entrySet()) {
- List<Object> values = entry.getValue();
- for (Object value : values) {
- rb.header(entry.getKey(), value);
- }
- }
- return rb;
- }
-
- public static Response copyResponseIfNeeded(Response response) {
- if (!(response instanceof ResponseImpl)) {
- Response r = fromResponse(response).build();
- Field[] declaredFields = ReflectionUtil.getDeclaredFields(response.getClass());
- for (Field f : declaredFields) {
- Class<?> declClass = f.getType();
- if (declClass == Annotation[].class) {
- try {
- Annotation[] fieldAnnotations =
- ReflectionUtil.accessDeclaredField(f, response, Annotation[].class);
- ((ResponseImpl)r).setEntityAnnotations(fieldAnnotations);
- } catch (Throwable ex) {
- LOG.warning("Custom annotations if any can not be copied");
- }
- break;
- }
- }
- return r;
- }
- return response;
- }
-
- public static Message getCurrentMessage() {
- return PhaseInterceptorChain.getCurrentMessage();
- }
-
- public static ClassResourceInfo getRootResource(Message m) {
- return (ClassResourceInfo)m.getExchange().get(JAXRSUtils.ROOT_RESOURCE_CLASS);
- }
-
- public static void pushOntoStack(OperationResourceInfo ori,
- MultivaluedMap<String, String> params,
- Message msg) {
- OperationResourceInfoStack stack = msg.get(OperationResourceInfoStack.class);
- if (stack == null) {
- stack = new OperationResourceInfoStack();
- msg.put(OperationResourceInfoStack.class, stack);
- }
-
-
- final List<String> values;
- if (params.size() <= 1) {
- values = Collections.emptyList();
- } else {
- values = new ArrayList<>(params.size() - 1);
- addTemplateVarValues(values, params, ori.getClassResourceInfo().getURITemplate());
- addTemplateVarValues(values, params, ori.getURITemplate());
- }
- Class<?> realClass = ori.getClassResourceInfo().getServiceClass();
- stack.push(new MethodInvocationInfo(ori, realClass, values));
- }
-
- private static void addTemplateVarValues(List<String> values,
- MultivaluedMap<String, String> params,
- URITemplate template) {
- if (template != null) {
- for (String var : template.getVariables()) {
- List<String> paramValues = params.get(var);
- if (paramValues != null) {
- values.addAll(paramValues);
- }
- }
- }
- }
-
- public static String logMessageHandlerProblem(String name, Class<?> cls, MediaType ct) {
- org.apache.cxf.common.i18n.Message errorMsg =
- new org.apache.cxf.common.i18n.Message(name, BUNDLE, cls.getName(), mediaTypeToString(ct));
- String errorMessage = errorMsg.toString();
- LOG.severe(errorMessage);
- return errorMessage;
- }
-
- /**
- * Get path URI template, combining base path, class & method & subresource templates
- * @param message message instance
- * @param cri class resource info
- * @param ori operation resource info
- * @param subOri operation subresource info
- * @return the URI template for the method in question
- */
- public static String getUriTemplate(Message message, ClassResourceInfo cri, OperationResourceInfo ori,
- OperationResourceInfo subOri) {
- final String template = getUriTemplate(message, cri, ori);
- final String methodPathTemplate = getUriTemplate(subOri);
- return combineUriTemplates(template, methodPathTemplate);
- }
-
- /**
- * Get path URI template, combining base path, class & method templates
- * @param message message instance
- * @param cri class resource info
- * @param ori operation resource info
- * @return the URI template for the method in question
- */
- public static String getUriTemplate(Message message, ClassResourceInfo cri, OperationResourceInfo ori) {
- final String basePath = (String)message.get(Message.BASE_PATH);
- final String classPathTemplate = getUriTemplate(cri);
- final String methodPathTemplate = getUriTemplate(ori);
-
- // The application path (@ApplicationPath) is incorporated into Message.BASE_PATH,
- // since it is part of the address.
- String template = basePath;
- if (StringUtils.isEmpty(template)) {
- template = "/";
- } else if (!template.startsWith("/")) {
- template = "/" + template;
- }
-
- template = combineUriTemplates(template, classPathTemplate);
- return combineUriTemplates(template, methodPathTemplate);
- }
-
- /**
- * Gets the URI template of the operation from its resource info
- * to assemble final URI template
- * @param ori operation resource info
- * @return URI template
- */
- private static String getUriTemplate(OperationResourceInfo ori) {
- final URITemplate template = ori.getURITemplate();
- if (template != null) {
- return template.getValue();
- } else {
- return null;
- }
- }
-
- /**
- * Goes over sub-resource class resource templates (through parent chain) if necessary
- * to assemble final URI template
- * @param cri root or subresource class resource info
- * @return URI template chain
- */
- private static String getUriTemplate(ClassResourceInfo cri) {
- final URITemplate template = cri.getURITemplate();
- if (template != null) {
- return template.getValue();
- } else if (cri.getParent() != null) { /* probably subresource */
- return getUriTemplate(cri.getParent());
- } else {
- return null; /* should not happen */
- }
- }
-
- /**
- * Combines two URI templates together
- * @param parent parent URI template
- * @param child child URI template
- * @return the URI template combined from the parent and child
- */
- private static String combineUriTemplates(final String parent, final String child) {
- if (StringUtils.isEmpty(child)) {
- return parent;
- }
-
- // The way URI templates are normalized in org.apache.cxf.jaxrs.model.URITemplate:
- // - empty or null become "/"
- // - "/" is added at the start if not present
- if ("/".equals(parent)) {
- return child;
- } else if ("/".equals(child)) {
- return parent;
- } else if (parent.endsWith("/")) {
- // Remove only last slash
- return parent.replaceAll("/$", "") + child;
- } else {
- return parent + child;
- }
- }
-
- // copy the input stream so that it is not inadvertently closed
- private static InputStream copyAndGetEntityStream(Message m) {
- LoadingByteArrayOutputStream baos = new LoadingByteArrayOutputStream();
- try (InputStream in = m.getContent(InputStream.class)) {
- IOUtils.copy(in, baos);
- } catch (IOException e) {
- throw ExceptionUtils.toInternalServerErrorException(e, null);
- }
- m.setContent(InputStream.class, baos.createInputStream());
- return baos.createInputStream();
- }
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java
deleted file mode 100644
index fb53bd6..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java
+++ /dev/null
@@ -1,1044 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.cxf.jaxrs.utils;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.Method;
-import java.lang.reflect.Modifier;
-import java.lang.reflect.Type;
-import java.lang.reflect.TypeVariable;
-import java.net.URL;
-import java.nio.charset.StandardCharsets;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-import java.util.ResourceBundle;
-import java.util.Set;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import javax.annotation.PostConstruct;
-import javax.annotation.PreDestroy;
-import javax.ws.rs.ApplicationPath;
-import javax.ws.rs.BeanParam;
-import javax.ws.rs.CookieParam;
-import javax.ws.rs.Encoded;
-import javax.ws.rs.FormParam;
-import javax.ws.rs.HeaderParam;
-import javax.ws.rs.MatrixParam;
-import javax.ws.rs.Path;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.QueryParam;
-import javax.ws.rs.container.AsyncResponse;
-import javax.ws.rs.container.Suspended;
-import javax.ws.rs.core.Application;
-import javax.ws.rs.core.Context;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.MultivaluedMap;
-import javax.ws.rs.core.Response;
-import javax.ws.rs.ext.MessageBodyWriter;
-import javax.ws.rs.ext.Provider;
-import javax.xml.namespace.QName;
-
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-
-import org.apache.cxf.Bus;
-import org.apache.cxf.BusFactory;
-import org.apache.cxf.common.classloader.ClassLoaderUtils;
-import org.apache.cxf.common.i18n.BundleUtils;
-import org.apache.cxf.common.logging.LogUtils;
-import org.apache.cxf.common.util.StringUtils;
-import org.apache.cxf.feature.Feature;
-import org.apache.cxf.helpers.CastUtils;
-import org.apache.cxf.helpers.DOMUtils;
-import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;
-import org.apache.cxf.jaxrs.ext.DefaultMethod;
-import org.apache.cxf.jaxrs.ext.xml.ElementClass;
-import org.apache.cxf.jaxrs.ext.xml.XMLName;
-import org.apache.cxf.jaxrs.lifecycle.PerRequestResourceProvider;
-import org.apache.cxf.jaxrs.lifecycle.ResourceProvider;
-import org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider;
-import org.apache.cxf.jaxrs.model.ClassResourceInfo;
-import org.apache.cxf.jaxrs.model.MethodDispatcher;
-import org.apache.cxf.jaxrs.model.OperationResourceInfo;
-import org.apache.cxf.jaxrs.model.Parameter;
-import org.apache.cxf.jaxrs.model.ParameterType;
-import org.apache.cxf.jaxrs.model.ResourceTypes;
-import org.apache.cxf.jaxrs.model.URITemplate;
-import org.apache.cxf.jaxrs.model.UserOperation;
-import org.apache.cxf.jaxrs.model.UserResource;
-import org.apache.cxf.jaxrs.provider.JAXBElementProvider;
-import org.apache.cxf.message.Message;
-import org.apache.cxf.message.MessageImpl;
-import org.apache.cxf.resource.ResourceManager;
-import org.apache.cxf.staxutils.StaxUtils;
-
-public final class ResourceUtils {
-
- private static final Logger LOG = LogUtils.getL7dLogger(ResourceUtils.class);
- private static final ResourceBundle BUNDLE = BundleUtils.getBundle(ResourceUtils.class);
- private static final String CLASSPATH_PREFIX = "classpath:";
- private static final String NOT_RESOURCE_METHOD_MESSAGE_ID = "NOT_RESOURCE_METHOD";
- private static final String NOT_SUSPENDED_ASYNC_MESSAGE_ID = "NOT_SUSPENDED_ASYNC_METHOD";
- private static final String NO_VOID_RETURN_ASYNC_MESSAGE_ID = "NO_VOID_RETURN_ASYNC_METHOD";
- private static final Set<String> SERVER_PROVIDER_CLASS_NAMES;
- static {
- SERVER_PROVIDER_CLASS_NAMES = new HashSet<>();
- SERVER_PROVIDER_CLASS_NAMES.add("javax.ws.rs.ext.MessageBodyWriter");
- SERVER_PROVIDER_CLASS_NAMES.add("javax.ws.rs.ext.MessageBodyReader");
- SERVER_PROVIDER_CLASS_NAMES.add("javax.ws.rs.ext.ExceptionMapper");
- SERVER_PROVIDER_CLASS_NAMES.add("javax.ws.rs.ext.ContextResolver");
- SERVER_PROVIDER_CLASS_NAMES.add("javax.ws.rs.ext.ReaderInterceptor");
- SERVER_PROVIDER_CLASS_NAMES.add("javax.ws.rs.ext.WriterInterceptor");
- SERVER_PROVIDER_CLASS_NAMES.add("javax.ws.rs.ext.ParamConverterProvider");
- SERVER_PROVIDER_CLASS_NAMES.add("javax.ws.rs.container.ContainerRequestFilter");
- SERVER_PROVIDER_CLASS_NAMES.add("javax.ws.rs.container.ContainerResponseFilter");
- SERVER_PROVIDER_CLASS_NAMES.add("javax.ws.rs.container.DynamicFeature");
- SERVER_PROVIDER_CLASS_NAMES.add("javax.ws.rs.core.Feature");
- SERVER_PROVIDER_CLASS_NAMES.add("org.apache.cxf.jaxrs.ext.ContextProvider");
-
- }
-
- private ResourceUtils() {
- }
-
- private static Method[] getDeclaredMethods(final Class<?> c) {
- return AccessController.doPrivileged(new PrivilegedAction<Method[]>() {
- @Override
- public Method[] run() {
- return c.getDeclaredMethods();
- }
- });
- }
- public static Method findPostConstructMethod(Class<?> c) {
- return findPostConstructMethod(c, null);
- }
- public static Method findPostConstructMethod(Class<?> c, String name) {
- if (Object.class == c || null == c) {
- return null;
- }
- for (Method m : getDeclaredMethods(c)) {
- if (name != null) {
- if (m.getName().equals(name)) {
- return m;
- }
- } else if (m.getAnnotation(PostConstruct.class) != null) {
- return m;
- }
- }
- Method m = findPostConstructMethod(c.getSuperclass(), name);
- if (m != null) {
- return m;
- }
- for (Class<?> i : c.getInterfaces()) {
- m = findPostConstructMethod(i, name);
- if (m != null) {
- return m;
- }
- }
- return null;
- }
-
- public static Method findPreDestroyMethod(Class<?> c) {
- return findPreDestroyMethod(c, null);
- }
-
- public static Method findPreDestroyMethod(Class<?> c, String name) {
- if (Object.class == c || null == c) {
- return null;
- }
- for (Method m : getDeclaredMethods(c)) {
- if (name != null) {
- if (m.getName().equals(name)) {
- return m;
- }
- } else if (m.getAnnotation(PreDestroy.class) != null) {
- return m;
- }
- }
- Method m = findPreDestroyMethod(c.getSuperclass(), name);
- if (m != null) {
- return m;
- }
- for (Class<?> i : c.getInterfaces()) {
- m = findPreDestroyMethod(i, name);
- if (m != null) {
- return m;
- }
- }
- return null;
- }
-
- public static ClassResourceInfo createClassResourceInfo(
- Map<String, UserResource> resources, UserResource model,
- Class<?> defaultClass,
- boolean isRoot, boolean enableStatic,
- Bus bus) {
- final boolean isDefaultClass = defaultClass != null;
- Class<?> sClass = !isDefaultClass ? loadClass(model.getName()) : defaultClass;
- return createServiceClassResourceInfo(resources, model, sClass, isRoot, enableStatic, bus);
- }
-
- public static ClassResourceInfo createServiceClassResourceInfo(
- Map<String, UserResource> resources, UserResource model,
- Class<?> sClass, boolean isRoot, boolean enableStatic, Bus bus) {
- if (model == null) {
- throw new RuntimeException("Resource class " + sClass.getName() + " has no model info");
- }
- ClassResourceInfo cri =
- new ClassResourceInfo(sClass, sClass, isRoot, enableStatic, true,
- model.getConsumes(), model.getProduces(), bus);
- URITemplate t = URITemplate.createTemplate(model.getPath());
- cri.setURITemplate(t);
-
- MethodDispatcher md = new MethodDispatcher();
- Map<String, UserOperation> ops = model.getOperationsAsMap();
-
- Method defaultMethod = null;
- Map<String, Method> methodNames = new HashMap<>();
- for (Method m : cri.getServiceClass().getMethods()) {
- if (m.getAnnotation(DefaultMethod.class) != null) {
- // if needed we can also support multiple default methods
- defaultMethod = m;
- }
- methodNames.put(m.getName(), m);
- }
-
- for (Map.Entry<String, UserOperation> entry : ops.entrySet()) {
- UserOperation op = entry.getValue();
- Method actualMethod = methodNames.get(op.getName());
- if (actualMethod == null) {
- actualMethod = defaultMethod;
- }
- if (actualMethod == null) {
- continue;
- }
- OperationResourceInfo ori =
- new OperationResourceInfo(actualMethod, cri, URITemplate.createTemplate(op.getPath()),
- op.getVerb(), op.getConsumes(), op.getProduces(),
- op.getParameters(),
- op.isOneway());
- String rClassName = actualMethod.getReturnType().getName();
- if (op.getVerb() == null) {
- if (resources.containsKey(rClassName)) {
- ClassResourceInfo subCri = rClassName.equals(model.getName()) ? cri
- : createServiceClassResourceInfo(resources, resources.get(rClassName),
- actualMethod.getReturnType(), false, enableStatic, bus);
- if (subCri != null) {
- cri.addSubClassResourceInfo(subCri);
- md.bind(ori, actualMethod);
- }
- }
- } else {
- md.bind(ori, actualMethod);
- }
- }
-
- cri.setMethodDispatcher(md);
- return checkMethodDispatcher(cri) ? cri : null;
-
- }
-
- public static ClassResourceInfo createClassResourceInfo(final Class<?> rClass,
- final Class<?> sClass,
- boolean root,
- boolean enableStatic) {
- return createClassResourceInfo(rClass, sClass, root, enableStatic, BusFactory.getThreadDefaultBus());
-
- }
-
- public static ClassResourceInfo createClassResourceInfo(final Class<?> rClass,
- final Class<?> sClass,
- boolean root,
- boolean enableStatic,
- Bus bus) {
- return createClassResourceInfo(rClass, sClass, null, root, enableStatic, bus);
- }
-
- public static ClassResourceInfo createClassResourceInfo(final Class<?> rClass,
- final Class<?> sClass,
- ClassResourceInfo parent,
- boolean root,
- boolean enableStatic,
- Bus bus) {
- return createClassResourceInfo(rClass, sClass, parent, root, enableStatic, bus, null, null);
- }
-
- //CHECKSTYLE:OFF
- public static ClassResourceInfo createClassResourceInfo(final Class<?> rClass,
- final Class<?> sClass,
- ClassResourceInfo parent,
- boolean root,
- boolean enableStatic,
- Bus bus,
- List<MediaType> defaultConsumes,
- List<MediaType> defaultProduces) {
- //CHECKSTYLE:ON
- ClassResourceInfo cri = new ClassResourceInfo(rClass, sClass, root, enableStatic, bus,
- defaultConsumes, defaultProduces);
- cri.setParent(parent);
-
- if (root) {
- URITemplate t = URITemplate.createTemplate(cri.getPath());
- cri.setURITemplate(t);
- }
-
- evaluateResourceClass(cri, enableStatic);
- return checkMethodDispatcher(cri) ? cri : null;
- }
-
- private static void evaluateResourceClass(ClassResourceInfo cri, boolean enableStatic) {
- MethodDispatcher md = new MethodDispatcher();
- Class<?> serviceClass = cri.getServiceClass();
-
- final Set<Method> annotatedMethods = new HashSet<>();
-
- for (Method m : serviceClass.getMethods()) {
- if (!m.isBridge() && !m.isSynthetic()) {
- //do real methods first
- Method annotatedMethod = AnnotationUtils.getAnnotatedMethod(serviceClass, m);
- if (!annotatedMethods.contains(annotatedMethod)) {
- evaluateResourceMethod(cri, enableStatic, md, m, annotatedMethod);
- annotatedMethods.add(annotatedMethod);
- }
- }
- }
- for (Method m : serviceClass.getMethods()) {
- if (m.isBridge() || m.isSynthetic()) {
- //if a bridge/synthetic method isn't already mapped to something, go ahead and do it
- Method annotatedMethod = AnnotationUtils.getAnnotatedMethod(serviceClass, m);
- if (!annotatedMethods.contains(annotatedMethod)) {
- evaluateResourceMethod(cri, enableStatic, md, m, annotatedMethod);
- annotatedMethods.add(annotatedMethod);
- }
- }
- }
- cri.setMethodDispatcher(md);
- }
-
- private static void evaluateResourceMethod(ClassResourceInfo cri, boolean enableStatic, MethodDispatcher md,
- Method m, Method annotatedMethod) {
- String httpMethod = AnnotationUtils.getHttpMethodValue(annotatedMethod);
- Path path = AnnotationUtils.getMethodAnnotation(annotatedMethod, Path.class);
-
- if (httpMethod != null || path != null) {
- if (!checkAsyncResponse(annotatedMethod)) {
- return;
- }
-
- md.bind(createOperationInfo(m, annotatedMethod, cri, path, httpMethod), m);
- if (httpMethod == null) {
- // subresource locator
- Class<?> subClass = m.getReturnType();
- if (subClass == Class.class) {
- subClass = InjectionUtils.getActualType(m.getGenericReturnType());
- }
- if (enableStatic) {
- ClassResourceInfo subCri = cri.findResource(subClass, subClass);
- if (subCri == null) {
- ClassResourceInfo ancestor = getAncestorWithSameServiceClass(cri, subClass);
- subCri = ancestor != null ? ancestor
- : createClassResourceInfo(subClass, subClass, cri, false, enableStatic,
- cri.getBus());
- }
-
- if (subCri != null) {
- cri.addSubClassResourceInfo(subCri);
- }
- }
- }
- } else {
- reportInvalidResourceMethod(m, NOT_RESOURCE_METHOD_MESSAGE_ID, Level.FINE);
- }
- }
-
- private static void reportInvalidResourceMethod(Method m, String messageId, Level logLevel) {
- if (LOG.isLoggable(logLevel)) {
- LOG.log(logLevel, new org.apache.cxf.common.i18n.Message(messageId,
- BUNDLE,
- m.getDeclaringClass().getName(),
- m.getName()).toString());
- }
- }
-
- private static boolean checkAsyncResponse(Method m) {
- Class<?>[] types = m.getParameterTypes();
- for (int i = 0; i < types.length; i++) {
- if (types[i] == AsyncResponse.class) {
- if (AnnotationUtils.getAnnotation(m.getParameterAnnotations()[i], Suspended.class) == null) {
- reportInvalidResourceMethod(m, NOT_SUSPENDED_ASYNC_MESSAGE_ID, Level.FINE);
- return false;
- }
- if (m.getReturnType() == Void.TYPE || m.getReturnType() == Void.class) {
- return true;
- }
- reportInvalidResourceMethod(m, NO_VOID_RETURN_ASYNC_MESSAGE_ID, Level.WARNING);
- return false;
- }
- }
- return true;
- }
-
- private static ClassResourceInfo getAncestorWithSameServiceClass(ClassResourceInfo parent, Class<?> subClass) {
- if (parent == null) {
- return null;
- }
- if (parent.getServiceClass() == subClass) {
- return parent;
- }
- return getAncestorWithSameServiceClass(parent.getParent(), subClass);
- }
-
- public static Constructor<?> findResourceConstructor(Class<?> resourceClass, boolean perRequest) {
- List<Constructor<?>> cs = new LinkedList<>();
- for (Constructor<?> c : resourceClass.getConstructors()) {
- Class<?>[] params = c.getParameterTypes();
- Annotation[][] anns = c.getParameterAnnotations();
- boolean match = true;
- for (int i = 0; i < params.length; i++) {
- if (!perRequest) {
- if (AnnotationUtils.getAnnotation(anns[i], Context.class) == null) {
- match = false;
- break;
- }
- } else if (!AnnotationUtils.isValidParamAnnotations(anns[i])) {
- match = false;
- break;
- }
- }
- if (match) {
- cs.add(c);
- }
- }
- Collections.sort(cs, new Comparator<Constructor<?>>() {
-
- public int compare(Constructor<?> c1, Constructor<?> c2) {
- int p1 = c1.getParameterTypes().length;
- int p2 = c2.getParameterTypes().length;
- return p1 > p2 ? -1 : p1 < p2 ? 1 : 0;
- }
-
- });
- return cs.isEmpty() ? null : cs.get(0);
- }
-
- public static List<Parameter> getParameters(Method resourceMethod) {
- Annotation[][] paramAnns = resourceMethod.getParameterAnnotations();
- if (paramAnns.length == 0) {
- return CastUtils.cast(Collections.emptyList(), Parameter.class);
- }
- Class<?>[] types = resourceMethod.getParameterTypes();
- List<Parameter> params = new ArrayList<>(paramAnns.length);
- for (int i = 0; i < paramAnns.length; i++) {
- Parameter p = getParameter(i, paramAnns[i], types[i]);
- params.add(p);
- }
- return params;
- }
-
- //CHECKSTYLE:OFF
- public static Parameter getParameter(int index, Annotation[] anns, Class<?> type) {
-
- Context ctx = AnnotationUtils.getAnnotation(anns, Context.class);
- if (ctx != null) {
- return new Parameter(ParameterType.CONTEXT, index, null);
- }
-
- boolean isEncoded = AnnotationUtils.getAnnotation(anns, Encoded.class) != null;
-
- BeanParam bp = AnnotationUtils.getAnnotation(anns, BeanParam.class);
- if (bp != null) {
- return new Parameter(ParameterType.BEAN, index, null, isEncoded, null);
- }
-
- String dValue = AnnotationUtils.getDefaultParameterValue(anns);
-
- PathParam a = AnnotationUtils.getAnnotation(anns, PathParam.class);
- if (a != null) {
- return new Parameter(ParameterType.PATH, index, a.value(), isEncoded, dValue);
- }
- QueryParam q = AnnotationUtils.getAnnotation(anns, QueryParam.class);
- if (q != null) {
- return new Parameter(ParameterType.QUERY, index, q.value(), isEncoded, dValue);
- }
- MatrixParam m = AnnotationUtils.getAnnotation(anns, MatrixParam.class);
- if (m != null) {
- return new Parameter(ParameterType.MATRIX, index, m.value(), isEncoded, dValue);
- }
-
- FormParam f = AnnotationUtils.getAnnotation(anns, FormParam.class);
- if (f != null) {
- return new Parameter(ParameterType.FORM, index, f.value(), isEncoded, dValue);
- }
-
- HeaderParam h = AnnotationUtils.getAnnotation(anns, HeaderParam.class);
- if (h != null) {
- return new Parameter(ParameterType.HEADER, index, h.value(), isEncoded, dValue);
- }
-
- CookieParam c = AnnotationUtils.getAnnotation(anns, CookieParam.class);
- if (c != null) {
- return new Parameter(ParameterType.COOKIE, index, c.value(), isEncoded, dValue);
- }
-
- return new Parameter(ParameterType.REQUEST_BODY, index, null);
-
- }
- //CHECKSTYLE:ON
-
- private static OperationResourceInfo createOperationInfo(Method m, Method annotatedMethod,
- ClassResourceInfo cri, Path path, String httpMethod) {
- OperationResourceInfo ori = new OperationResourceInfo(m, annotatedMethod, cri);
- URITemplate t = URITemplate.createTemplate(path);
- ori.setURITemplate(t);
- ori.setHttpMethod(httpMethod);
- return ori;
- }
-
-
- private static boolean checkMethodDispatcher(ClassResourceInfo cr) {
- if (cr.getMethodDispatcher().getOperationResourceInfos().isEmpty()) {
- LOG.warning(new org.apache.cxf.common.i18n.Message("NO_RESOURCE_OP_EXC",
- BUNDLE,
- cr.getServiceClass().getName()).toString());
- return false;
- }
- return true;
- }
-
-
- private static Class<?> loadClass(String cName) {
- try {
- return ClassLoaderUtils.loadClass(cName.trim(), ResourceUtils.class);
- } catch (ClassNotFoundException ex) {
- throw new RuntimeException("No class " + cName.trim() + " can be found", ex);
- }
- }
-
-
- public static List<UserResource> getUserResources(String loc, Bus bus) {
- try (InputStream is = ResourceUtils.getResourceStream(loc, bus)) {
- if (is == null) {
- return null;
- }
- return getUserResources(is);
- } catch (Exception ex) {
- LOG.warning("Problem with processing a user model at " + loc);
- }
-
- return null;
- }
-
- public static InputStream getResourceStream(String loc, Bus bus) throws IOException {
- URL url = getResourceURL(loc, bus);
- return url == null ? null : url.openStream();
- }
-
- public static URL getResourceURL(String loc, Bus bus) throws IOException {
- URL url;
- if (loc.startsWith(CLASSPATH_PREFIX)) {
- String path = loc.substring(CLASSPATH_PREFIX.length());
- url = ResourceUtils.getClasspathResourceURL(path, ResourceUtils.class, bus);
- } else {
- try {
- url = new URL(loc);
- } catch (Exception ex) {
- // it can be either a classpath or file resource without a scheme
- url = ResourceUtils.getClasspathResourceURL(loc, ResourceUtils.class, bus);
- if (url == null) {
- File file = new File(loc);
- if (file.exists()) {
- url = file.toURI().toURL();
- }
- }
- }
- }
- if (url == null) {
- LOG.warning("No resource " + loc + " is available");
- }
- return url;
- }
-
- public static InputStream getClasspathResourceStream(String path, Class<?> callingClass, Bus bus) {
- InputStream is = ClassLoaderUtils.getResourceAsStream(path, callingClass);
- return is == null ? getResource(path, InputStream.class, bus) : is;
- }
-
- public static URL getClasspathResourceURL(String path, Class<?> callingClass, Bus bus) {
- URL url = ClassLoaderUtils.getResource(path, callingClass);
- return url == null ? getResource(path, URL.class, bus) : url;
- }
-
- public static <T> T getResource(String path, Class<T> resourceClass, Bus bus) {
- if (bus != null) {
- ResourceManager rm = bus.getExtension(ResourceManager.class);
- if (rm != null) {
- return rm.resolveResource(path, resourceClass);
- }
- }
- return null;
- }
-
- public static Properties loadProperties(String propertiesLocation, Bus bus) throws IOException {
- Properties props = new Properties();
- try (InputStream is = getResourceStream(propertiesLocation, bus)) {
- props.load(is);
- }
- return props;
- }
-
- public static List<UserResource> getUserResources(String loc) {
- return getUserResources(loc, BusFactory.getThreadDefaultBus());
- }
-
- public static List<UserResource> getUserResources(InputStream is) throws Exception {
- Document doc = StaxUtils.read(new InputStreamReader(is, StandardCharsets.UTF_8));
- return getResourcesFromElement(doc.getDocumentElement());
- }
-
- public static List<UserResource> getResourcesFromElement(Element modelEl) {
- List<UserResource> resources = new ArrayList<>();
- List<Element> resourceEls =
- DOMUtils.findAllElementsByTagNameNS(modelEl,
- "http://cxf.apache.org/jaxrs", "resource");
- for (Element e : resourceEls) {
- resources.add(getResourceFromElement(e));
- }
- return resources;
- }
-
-
- public static ResourceTypes getAllRequestResponseTypes(List<ClassResourceInfo> cris,
- boolean jaxbOnly) {
- return getAllRequestResponseTypes(cris, jaxbOnly, null);
- }
-
- public static ResourceTypes getAllRequestResponseTypes(List<ClassResourceInfo> cris,
- boolean jaxbOnly,
- MessageBodyWriter<?> jaxbWriter) {
- ResourceTypes types = new ResourceTypes();
- for (ClassResourceInfo resource : cris) {
- getAllTypesForResource(resource, types, jaxbOnly, jaxbWriter);
- }
- return types;
- }
-
- public static Class<?> getActualJaxbType(Class<?> type, Method resourceMethod, boolean inbound) {
- ElementClass element = resourceMethod.getAnnotation(ElementClass.class);
- if (element != null) {
- Class<?> cls = inbound ? element.request() : element.response();
- if (cls != Object.class) {
- return cls;
- }
- }
- return type;
- }
-
- private static void getAllTypesForResource(ClassResourceInfo resource,
- ResourceTypes types,
- boolean jaxbOnly,
- MessageBodyWriter<?> jaxbWriter) {
- Class<?> jaxbElement = null;
- try {
- jaxbElement = ClassLoaderUtils.loadClass("javax.xml.bind.JAXBElement", ResourceUtils.class);
- } catch (final ClassNotFoundException e) {
- // no-op
- }
-
- for (OperationResourceInfo ori : resource.getMethodDispatcher().getOperationResourceInfos()) {
- Method method = ori.getAnnotatedMethod() == null ? ori.getMethodToInvoke() : ori.getAnnotatedMethod();
- Class<?> realReturnType = method.getReturnType();
- Class<?> cls = realReturnType;
- if (cls == Response.class || ori.isAsync()) {
- cls = getActualJaxbType(cls, method, false);
- }
- Type type = method.getGenericReturnType();
- if (jaxbOnly) {
- checkJaxbType(resource.getServiceClass(), cls, realReturnType == Response.class || ori.isAsync()
- ? cls : type, types, method.getAnnotations(), jaxbWriter, jaxbElement);
- } else {
- types.getAllTypes().put(cls, type);
- }
-
- for (Parameter pm : ori.getParameters()) {
- if (pm.getType() == ParameterType.REQUEST_BODY) {
- Class<?> inType = method.getParameterTypes()[pm.getIndex()];
- if (inType != AsyncResponse.class) {
- Type paramType = method.getGenericParameterTypes()[pm.getIndex()];
- if (jaxbOnly) {
- checkJaxbType(resource.getServiceClass(), inType, paramType, types,
- method.getParameterAnnotations()[pm.getIndex()], jaxbWriter, jaxbElement);
- } else {
- types.getAllTypes().put(inType, paramType);
- }
- }
- }
- }
-
- }
-
- for (ClassResourceInfo sub : resource.getSubResources()) {
- if (!isRecursiveSubResource(resource, sub)) {
- getAllTypesForResource(sub, types, jaxbOnly, jaxbWriter);
- }
- }
- }
-
- private static boolean isRecursiveSubResource(ClassResourceInfo parent, ClassResourceInfo sub) {
- if (parent == null) {
- return false;
- }
- if (parent == sub) {
- return true;
- }
- return isRecursiveSubResource(parent.getParent(), sub);
- }
-
- private static void checkJaxbType(Class<?> serviceClass,
- Class<?> type,
- Type genericType,
- ResourceTypes types,
- Annotation[] anns,
- MessageBodyWriter<?> jaxbWriter,
- Class<?> jaxbElement) {
- boolean isCollection = false;
- if (InjectionUtils.isSupportedCollectionOrArray(type)) {
- type = InjectionUtils.getActualType(genericType);
- isCollection = true;
- }
- if (type == Object.class && !(genericType instanceof Class)
- || genericType instanceof TypeVariable) {
- Type theType = InjectionUtils.processGenericTypeIfNeeded(serviceClass,
- Object.class,
- genericType);
- type = InjectionUtils.getActualType(theType);
- }
- if (type == null
- || InjectionUtils.isPrimitive(type)
- || (jaxbElement != null && jaxbElement.isAssignableFrom(type))
- || Response.class.isAssignableFrom(type)
- || type.isInterface()) {
- return;
- }
-
- MessageBodyWriter<?> writer = jaxbWriter;
- if (writer == null) {
- JAXBElementProvider<Object> defaultWriter = new JAXBElementProvider<>();
- defaultWriter.setMarshallAsJaxbElement(true);
- defaultWriter.setXmlTypeAsJaxbElementOnly(true);
- writer = defaultWriter;
- }
- if (writer.isWriteable(type, type, anns, MediaType.APPLICATION_XML_TYPE)) {
- types.getAllTypes().put(type, type);
- Class<?> genCls = InjectionUtils.getActualType(genericType);
- if (genCls != type && genCls != null && genCls != Object.class
- && !InjectionUtils.isSupportedCollectionOrArray(genCls)) {
- types.getAllTypes().put(genCls, genCls);
- }
-
- XMLName name = AnnotationUtils.getAnnotation(anns, XMLName.class);
- QName qname = name != null ? JAXRSUtils.convertStringToQName(name.value()) : null;
- if (isCollection) {
- types.getCollectionMap().put(type, qname);
- } else {
- types.getXmlNameMap().put(type, qname);
- }
- }
- }
-
- private static UserResource getResourceFromElement(Element e) {
- UserResource resource = new UserResource();
- resource.setName(e.getAttribute("name"));
- resource.setPath(e.getAttribute("path"));
- resource.setConsumes(e.getAttribute("consumes"));
- resource.setProduces(e.getAttribute("produces"));
- List<Element> operEls =
- DOMUtils.findAllElementsByTagNameNS(e,
- "http://cxf.apache.org/jaxrs", "operation");
- List<UserOperation> opers = new ArrayList<>(operEls.size());
- for (Element operEl : operEls) {
- opers.add(getOperationFromElement(operEl));
- }
- resource.setOperations(opers);
- return resource;
- }
-
- private static UserOperation getOperationFromElement(Element e) {
- UserOperation op = new UserOperation();
- op.setName(e.getAttribute("name"));
- op.setVerb(e.getAttribute("verb"));
- op.setPath(e.getAttribute("path"));
- op.setOneway(Boolean.parseBoolean(e.getAttribute("oneway")));
- op.setConsumes(e.getAttribute("consumes"));
- op.setProduces(e.getAttribute("produces"));
- List<Element> paramEls =
- DOMUtils.findAllElementsByTagNameNS(e,
- "http://cxf.apache.org/jaxrs", "param");
- List<Parameter> params = new ArrayList<>(paramEls.size());
- for (int i = 0; i < paramEls.size(); i++) {
- Element paramEl = paramEls.get(i);
- Parameter p = new Parameter(paramEl.getAttribute("type"), i, paramEl.getAttribute("name"));
- p.setEncoded(Boolean.valueOf(paramEl.getAttribute("encoded")));
- p.setDefaultValue(paramEl.getAttribute("defaultValue"));
- String pClass = paramEl.getAttribute("class");
- if (!StringUtils.isEmpty(pClass)) {
- try {
- p.setJavaType(ClassLoaderUtils.loadClass(pClass, ResourceUtils.class));
- } catch (Exception ex) {
- throw new RuntimeException(ex);
- }
- }
- params.add(p);
- }
- op.setParameters(params);
- return op;
- }
-
- public static Object[] createConstructorArguments(Constructor<?> c,
- Message m,
- boolean perRequest) {
- return createConstructorArguments(c, m, perRequest, null);
- }
-
- public static Object[] createConstructorArguments(Constructor<?> c,
- Message m,
- boolean perRequest,
- Map<Class<?>, Object> contextValues) {
- Class<?>[] params = c.getParameterTypes();
- Annotation[][] anns = c.getParameterAnnotations();
- Type[] genericTypes = c.getGenericParameterTypes();
- return createConstructorArguments(c, m, perRequest, contextValues, params, anns, genericTypes);
- }
-
- public static Object[] createConstructorArguments(Constructor<?> c,
- Message m,
- boolean perRequest,
- Map<Class<?>,
- Object> contextValues,
- Class<?>[] params,
- Annotation[][] anns,
- Type[] genericTypes) {
- if (m == null) {
- m = new MessageImpl();
- }
- @SuppressWarnings("unchecked")
- MultivaluedMap<String, String> templateValues =
- (MultivaluedMap<String, String>)m.get(URITemplate.TEMPLATE_PARAMETERS);
- Object[] values = new Object[params.length];
- for (int i = 0; i < params.length; i++) {
- if (AnnotationUtils.getAnnotation(anns[i], Context.class) != null) {
- Object contextValue = contextValues != null ? contextValues.get(params[i]) : null;
- if (contextValue == null) {
- if (perRequest || InjectionUtils.VALUE_CONTEXTS.contains(params[i].getName())) {
- values[i] = JAXRSUtils.createContextValue(m, genericTypes[i], params[i]);
- } else {
- values[i] = InjectionUtils.createThreadLocalProxy(params[i]);
- }
- } else {
- values[i] = contextValue;
- }
- } else {
- // this branch won't execute for singletons given that the found constructor
- // is guaranteed to have only Context parameters, if any, for singletons
- Parameter p = ResourceUtils.getParameter(i, anns[i], params[i]);
- values[i] = JAXRSUtils.createHttpParameterValue(
- p, params[i], genericTypes[i], anns[i], m, templateValues, null);
- }
- }
- return values;
- }
-
- @SuppressWarnings("unchecked")
- public static JAXRSServerFactoryBean createApplication(Application app,
- boolean ignoreAppPath,
- boolean staticSubresourceResolution,
- boolean useSingletonResourceProvider,
- Bus bus) {
-
- Set<Object> singletons = app.getSingletons();
- verifySingletons(singletons);
-
- List<Class<?>> resourceClasses = new ArrayList<>();
- List<Object> providers = new ArrayList<>();
- List<Feature> features = new ArrayList<>();
- Map<Class<?>, ResourceProvider> map = new HashMap<>();
-
- // Note, app.getClasses() returns a list of per-request classes
- // or singleton provider classes
- for (Class<?> cls : app.getClasses()) {
- if (isValidApplicationClass(cls, singletons)) {
- if (isValidProvider(cls)) {
- providers.add(createProviderInstance(cls));
- } else if (Feature.class.isAssignableFrom(cls)) {
- features.add(createFeatureInstance((Class<? extends Feature>) cls));
- } else {
- resourceClasses.add(cls);
- if (useSingletonResourceProvider) {
- map.put(cls, new SingletonResourceProvider(createProviderInstance(cls)));
- } else {
- map.put(cls, new PerRequestResourceProvider(cls));
- }
- }
- }
- }
-
- // we can get either a provider or resource class here
- for (Object o : singletons) {
- if (isValidProvider(o.getClass())) {
- providers.add(o);
- } else if (o instanceof Feature) {
- features.add((Feature) o);
- } else {
- resourceClasses.add(o.getClass());
- map.put(o.getClass(), new SingletonResourceProvider(o));
- }
- }
-
- JAXRSServerFactoryBean bean = new JAXRSServerFactoryBean();
- if (bus != null) {
- bean.setBus(bus);
- }
-
- String address = "/";
- if (!ignoreAppPath) {
- ApplicationPath appPath = locateApplicationPath(app.getClass());
- if (appPath != null) {
- address = appPath.value();
- }
- }
- if (!address.startsWith("/")) {
- address = "/" + address;
- }
- bean.setAddress(address);
- bean.setStaticSubresourceResolution(staticSubresourceResolution);
- bean.setResourceClasses(resourceClasses);
- bean.setProviders(providers);
- bean.getFeatures().addAll(features);
- for (Map.Entry<Class<?>, ResourceProvider> entry : map.entrySet()) {
- bean.setResourceProvider(entry.getKey(), entry.getValue());
- }
- Map<String, Object> appProps = app.getProperties();
- if (appProps != null) {
- bean.getProperties(true).putAll(appProps);
- }
- bean.setApplication(app);
- return bean;
- }
-
- public static Object createProviderInstance(Class<?> cls) {
- try {
- Constructor<?> c = ResourceUtils.findResourceConstructor(cls, false);
- if (c != null && c.getParameterTypes().length == 0) {
- return c.newInstance();
- }
- return c;
- } catch (Throwable ex) {
- throw new RuntimeException("Provider " + cls.getName() + " can not be created", ex);
- }
- }
-
- public static Feature createFeatureInstance(Class<? extends Feature> cls) {
- try {
- Constructor<?> c = ResourceUtils.findResourceConstructor(cls, false);
-
- if (c == null) {
- throw new RuntimeException("No valid constructor found for " + cls.getName());
- }
-
- return (Feature) c.newInstance();
- } catch (Throwable ex) {
- throw new RuntimeException("Feature " + cls.getName() + " can not be created", ex);
- }
- }
-
- private static boolean isValidProvider(Class<?> c) {
- if (c == null || c == Object.class) {
- return false;
- }
- if (c.getAnnotation(Provider.class) != null) {
- return true;
- }
- for (Class<?> itf : c.getInterfaces()) {
- if (SERVER_PROVIDER_CLASS_NAMES.contains(itf.getName())) {
- return true;
- }
- }
- return isValidProvider(c.getSuperclass());
- }
-
- private static void verifySingletons(Set<Object> singletons) {
- if (singletons.isEmpty()) {
- return;
- }
- Set<String> map = new HashSet<>();
- for (Object s : singletons) {
- if (map.contains(s.getClass().getName())) {
- throw new RuntimeException("More than one instance of the same singleton class "
- + s.getClass().getName() + " is available");
- }
- map.add(s.getClass().getName());
- }
- }
-
- public static boolean isValidResourceClass(Class<?> c) {
- if (c.isInterface() || Modifier.isAbstract(c.getModifiers())) {
- LOG.info("Ignoring invalid resource class " + c.getName());
- return false;
- }
- return true;
- }
-
- public static ApplicationPath locateApplicationPath(Class<?> appClass) {
- ApplicationPath appPath = appClass.getAnnotation(ApplicationPath.class);
- if (appPath == null && appClass.getSuperclass() != Application.class) {
- return locateApplicationPath(appClass.getSuperclass());
- }
- return appPath;
- }
-
- private static boolean isValidApplicationClass(Class<?> c, Set<Object> singletons) {
- if (!isValidResourceClass(c)) {
- return false;
- }
- for (Object s : singletons) {
- if (c == s.getClass()) {
- LOG.info("Ignoring per-request resource class " + c.getName()
- + " as it is also registered as singleton");
- return false;
- }
- }
- return true;
- }
-
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/message/MessageUtils.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/message/MessageUtils.java
deleted file mode 100644
index e7f7523..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/message/MessageUtils.java
+++ /dev/null
@@ -1,261 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.cxf.message;
-
-import java.lang.reflect.Method;
-import java.net.HttpURLConnection;
-import java.util.Optional;
-import java.util.logging.Logger;
-
-import org.w3c.dom.Node;
-
-import org.apache.cxf.common.logging.LogUtils;
-import org.apache.cxf.common.util.PropertyUtils;
-import org.apache.cxf.service.invoker.MethodDispatcher;
-import org.apache.cxf.service.model.BindingOperationInfo;
-
-
-/**
- * Holder for utility methods relating to messages.
- */
-public final class MessageUtils {
-
- private static final Logger LOG = LogUtils.getL7dLogger(MessageUtils.class);
-
- /**
- * Prevents instantiation.
- */
- private MessageUtils() {
- }
-
- /**
- * Determine if message is outbound.
- *
- * @param message the current Message
- * @return true if the message direction is outbound
- */
- public static boolean isOutbound(Message message) {
- if (message == null) {
- return false;
- }
-
- Exchange exchange = message.getExchange();
- return exchange != null
- && (message == exchange.getOutMessage() || message == exchange.getOutFaultMessage());
- }
-
- /**
- * Determine if message is fault.
- *
- * @param message the current Message
- * @return true if the message is a fault
- */
- public static boolean isFault(Message message) {
- return message != null
- && message.getExchange() != null
- && (message == message.getExchange().getInFaultMessage() || message == message.getExchange()
- .getOutFaultMessage());
- }
-
- /**
- * Determine the fault mode for the underlying (fault) message
- * (for use on server side only).
- *
- * @param message the fault message
- * @return the FaultMode
- */
- public static FaultMode getFaultMode(Message message) {
- if (message != null
- && message.getExchange() != null
- && message == message.getExchange().getOutFaultMessage()) {
- FaultMode mode = message.get(FaultMode.class);
- if (null != mode) {
- return mode;
- }
- return FaultMode.RUNTIME_FAULT;
- }
- return null;
- }
-
- /**
- * Determine if current messaging role is that of requestor.
- *
- * @param message the current Message
- * @return true if the current messaging role is that of requestor
- */
- public static boolean isRequestor(Message message) {
- if (message != null) {
- Boolean requestor = (Boolean) message.get(Message.REQUESTOR_ROLE);
- return requestor != null && requestor;
- }
- return false;
- }
-
- /**
- * Determine if the current message is a partial response.
- *
- * @param message the current message
- * @return true if the current messags is a partial response
- */
- public static boolean isPartialResponse(Message message) {
- return message != null && Boolean.TRUE.equals(message.get(Message.PARTIAL_RESPONSE_MESSAGE));
- }
-
- /**
- * Determines if the current message is an empty partial response, which
- * is a partial response with an empty content.
- *
- * @param message the current message
- * @return true if the current messags is a partial empty response
- */
- public static boolean isEmptyPartialResponse(Message message) {
- return message != null && Boolean.TRUE.equals(message.get(Message.EMPTY_PARTIAL_RESPONSE_MESSAGE));
- }
-
- /**
- * Returns true if a value is either the String "true" (regardless of case) or Boolean.TRUE.
- * @param value
- * @return true if value is either the String "true" or Boolean.TRUE
- * @deprecated replaced by {@link #PropertyUtils#isTrue(Object)}
- */
- @Deprecated
- public static boolean isTrue(Object value) {
- return PropertyUtils.isTrue(value);
- }
-
- public static boolean getContextualBoolean(Message m, String key) {
- return getContextualBoolean(m, key, false);
- }
- public static boolean getContextualBoolean(Message m, String key, boolean defaultValue) {
- if (m != null) {
- Object o = m.getContextualProperty(key);
- if (o != null) {
- return PropertyUtils.isTrue(o);
- }
- }
- return defaultValue;
- }
-
- public static int getContextualInteger(Message m, String key, int defaultValue) {
- if (m != null) {
- Object o = m.getContextualProperty(key);
- if (o instanceof String) {
- try {
- int i = Integer.parseInt((String)o);
- if (i > 0) {
- return i;
- }
- } catch (NumberFormatException ex) {
- LOG.warning("Incorrect integer value of " + o + " specified for: " + key);
- }
- }
- }
- return defaultValue;
- }
-
- public static Object getContextualProperty(Message m, String propPreferred, String propDefault) {
- Object prop = null;
- if (m != null) {
- prop = m.getContextualProperty(propPreferred);
- if (prop == null && propDefault != null) {
- prop = m.getContextualProperty(propDefault);
- }
- }
- return prop;
- }
-
- /**
- * Returns true if the underlying content format is a W3C DOM or a SAAJ message.
- */
- public static boolean isDOMPresent(Message m) {
- return m != null && m.getContent(Node.class) != null;
- /*
- for (Class c : m.getContentFormats()) {
- if (c.equals(Node.class) || "javax.xml.soap.SOAPMessage".equals(c.getName())) {
- return true;
- }
- }
- return false;
- */
- }
-
- public static Optional<Method> getTargetMethod(Message m) {
- Method method;
- BindingOperationInfo bop = m.getExchange().getBindingOperationInfo();
- if (bop != null) {
- MethodDispatcher md = (MethodDispatcher) m.getExchange().getService().get(MethodDispatcher.class.getName());
- method = md.getMethod(bop);
- } else {
- // See please JAXRSInInterceptor#RESOURCE_METHOD for the reference
- method = (Method) m.get("org.apache.cxf.resource.method");
- }
- return Optional.ofNullable(method);
- }
-
- /**
- * Gets the response code from the message and tries to deduct one if it
- * is not set yet.
- * @param message message to get response code from
- * @return response code (or deducted value assuming success)
- */
- public static int getReponseCodeFromMessage(Message message) {
- Integer i = (Integer)message.get(Message.RESPONSE_CODE);
- if (i != null) {
- return i.intValue();
- }
- int code = hasNoResponseContent(message) ? HttpURLConnection.HTTP_ACCEPTED : HttpURLConnection.HTTP_OK;
- // put the code in the message so that others can get it
- message.put(Message.RESPONSE_CODE, code);
- return code;
- }
-
- /**
- * Determines if the current message has no response content.
- * The message has no response content if either:
- * - the request is oneway and the current message is no partial
- * response or an empty partial response.
- * - the request is not oneway but the current message is an empty partial
- * response.
- * @param message
- * @return
- */
- public static boolean hasNoResponseContent(Message message) {
- final boolean ow = isOneWay(message);
- final boolean pr = MessageUtils.isPartialResponse(message);
- final boolean epr = MessageUtils.isEmptyPartialResponse(message);
-
- //REVISIT may need to provide an option to choose other behavior?
- // old behavior not suppressing any responses => ow && !pr
- // suppress empty responses for oneway calls => ow && (!pr || epr)
- // suppress additionally empty responses for decoupled twoway calls =>
- return (ow && !pr) || epr;
- }
-
- /**
- * Checks if the message is oneway or not
- * @param message the message under consideration
- * @return true if the message has been marked as oneway
- */
- public static boolean isOneWay(Message message) {
- final Exchange ex = message.getExchange();
- return ex != null && ex.isOneWay();
- }
-
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/phase/PhaseChainCache.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/phase/PhaseChainCache.java
deleted file mode 100644
index ccd12d2..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/phase/PhaseChainCache.java
+++ /dev/null
@@ -1,137 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.cxf.phase;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.ListIterator;
-import java.util.SortedSet;
-import java.util.concurrent.atomic.AtomicReference;
-
-import org.apache.cxf.common.util.ModCountCopyOnWriteArrayList;
-import org.apache.cxf.interceptor.Interceptor;
-import org.apache.cxf.message.Message;
-
-/**
- * The PhaseChainCache provides default interceptor chains for SOAP requests
- * and responses, both from the client and web service side. The list of
- * phases supplied in the get() methods of this class are defined by default
- * within org.apache.cxf.phase.PhaseManagerImpl. For an example of this class
- * in use, check the sourcecode of org.apache.cxf.endpoint.ClientImpl.
- */
-public final class PhaseChainCache {
- AtomicReference<ChainHolder> lastData = new AtomicReference<>();
-
- public PhaseInterceptorChain get(SortedSet<Phase> phaseList,
- List<Interceptor<? extends Message>> p1) {
- return getChain(lastData, phaseList, p1);
- }
-
- public PhaseInterceptorChain get(SortedSet<Phase> phaseList,
- List<Interceptor<? extends Message>> p1,
- List<Interceptor<? extends Message>> p2) {
- return getChain(lastData, phaseList, p1, p2);
- }
- public PhaseInterceptorChain get(SortedSet<Phase> phaseList,
- List<Interceptor<? extends Message>> p1,
- List<Interceptor<? extends Message>> p2,
- List<Interceptor<? extends Message>> p3) {
- return getChain(lastData, phaseList, p1, p2, p3);
- }
- public PhaseInterceptorChain get(SortedSet<Phase> phaseList,
- List<Interceptor<? extends Message>> p1,
- List<Interceptor<? extends Message>> p2,
- List<Interceptor<? extends Message>> p3,
- List<Interceptor<? extends Message>> p4) {
- return getChain(lastData, phaseList, p1, p2, p3, p4);
- }
- public PhaseInterceptorChain get(SortedSet<Phase> phaseList,
- List<Interceptor<? extends Message>> p1,
- List<Interceptor<? extends Message>> p2,
- List<Interceptor<? extends Message>> p3,
- List<Interceptor<? extends Message>> p4,
- List<Interceptor<? extends Message>> p5) {
- return getChain(lastData, phaseList, p1, p2, p3, p4, p5);
- }
-
- @SafeVarargs
- static PhaseInterceptorChain getChain(AtomicReference<ChainHolder> lastData,
- SortedSet<Phase> phaseList,
- List<Interceptor<? extends Message>> ... providers) {
- ChainHolder last = lastData.get();
-
- if (last == null
- || !last.matches(providers)) {
-
- PhaseInterceptorChain chain = new PhaseInterceptorChain(phaseList);
- List<ModCountCopyOnWriteArrayList<Interceptor<? extends Message>>> copy
- = new ArrayList<>(providers.length);
- for (List<Interceptor<? extends Message>> p : providers) {
- copy.add(new ModCountCopyOnWriteArrayList<>(p));
- chain.add(p);
- }
- last = new ChainHolder(chain, copy);
- lastData.set(last);
- }
-
-
- return last.chain.cloneChain();
- }
-
- private static class ChainHolder {
- List<ModCountCopyOnWriteArrayList<Interceptor<? extends Message>>> lists;
- PhaseInterceptorChain chain;
-
- ChainHolder(PhaseInterceptorChain c,
- List<ModCountCopyOnWriteArrayList<Interceptor<? extends Message>>> l) {
- lists = l;
- chain = c;
- }
-
- @SafeVarargs
- final boolean matches(List<Interceptor<? extends Message>> ... providers) {
- if (lists.size() == providers.length) {
- for (int x = 0; x < providers.length; x++) {
- if (lists.get(x).size() != providers[x].size()) {
- return false;
- }
-
- if (providers[x].getClass() == ModCountCopyOnWriteArrayList.class) {
- if (((ModCountCopyOnWriteArrayList<?>)providers[x]).getModCount()
- != lists.get(x).getModCount()) {
- return false;
- }
- } else {
- ListIterator<Interceptor<? extends Message>> i1 = lists.get(x).listIterator();
- ListIterator<Interceptor<? extends Message>> i2 = providers[x].listIterator();
-
- while (i1.hasNext()) {
- if (i1.next() != i2.next()) {
- return false;
- }
- }
- }
- }
- return true;
- }
- return false;
- }
- }
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/phase/PhaseInterceptorChain.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/phase/PhaseInterceptorChain.java
deleted file mode 100644
index c8a52a8..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/phase/PhaseInterceptorChain.java
+++ /dev/null
@@ -1,857 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.cxf.phase;
-
-import java.lang.ref.WeakReference;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.ListIterator;
-import java.util.Map;
-import java.util.NoSuchElementException;
-import java.util.Set;
-import java.util.SortedSet;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import org.apache.cxf.common.logging.LogUtils;
-import org.apache.cxf.common.util.PropertyUtils;
-import org.apache.cxf.common.util.StringUtils;
-import org.apache.cxf.continuations.SuspendedInvocationException;
-import org.apache.cxf.interceptor.Fault;
-import org.apache.cxf.interceptor.Interceptor;
-import org.apache.cxf.interceptor.InterceptorChain;
-import org.apache.cxf.interceptor.ServiceInvokerInterceptor;
-import org.apache.cxf.logging.FaultListener;
-import org.apache.cxf.message.Exchange;
-import org.apache.cxf.message.FaultMode;
-import org.apache.cxf.message.Message;
-import org.apache.cxf.message.MessageUtils;
-import org.apache.cxf.service.Service;
-import org.apache.cxf.service.model.BindingOperationInfo;
-import org.apache.cxf.service.model.OperationInfo;
-import org.apache.cxf.transport.MessageObserver;
-
-/**
- * A PhaseInterceptorChain orders Interceptors according to the phase they
- * participate in and also according to the before & after properties on an
- * Interceptor.
- * <p>
- * A List of phases is supplied to the PhaseInterceptorChain in the constructor.
- * This class is typically instantiated from the PhaseChainCache class in this
- * package. Interceptors that are added to the chain are ordered by phase.
- * Within a phase, interceptors can order themselves. Each PhaseInterceptor
- * has an ID. PhaseInterceptors can supply a Collection of IDs which they
- * should run before or after, supplying fine grained ordering.
- * <p>
- *
- */
-public class PhaseInterceptorChain implements InterceptorChain {
- public static final String PREVIOUS_MESSAGE = PhaseInterceptorChain.class.getName() + ".PREVIOUS_MESSAGE";
-
- private static final Logger LOG = LogUtils.getL7dLogger(PhaseInterceptorChain.class);
-
- private static final ThreadLocal<Message> CURRENT_MESSAGE = new ThreadLocal<>();
-
- private final Map<String, Integer> nameMap;
- private final Phase[] phases;
-
- // heads[phase] refers to the first interceptor of the given phase
- private InterceptorHolder[] heads;
- // tails[phase] refers to the last interceptor of the given phase
- private InterceptorHolder[] tails;
- // hasAfters[phase] indicates that the given phase has already inserted
- // interceptors that may need to be placed after future to-be-inserted
- // interceptors. This flag is used to activate ordering of interceptors
- // when new ones are added to the list for this phase.
- // Note no hasBefores[] is needed because implementation adds subsequent
- // interceptors to the end of the list by default.
- private boolean[] hasAfters;
-
-
- private State state;
- private Message pausedMessage;
- private MessageObserver faultObserver;
- private PhaseInterceptorIterator iterator;
- private final boolean isFineLogging;
-
- // currently one chain for one request/response, use below as signal
- // to avoid duplicate fault processing on nested calling of
- // doIntercept(), which will throw same fault multi-times
- private boolean faultOccurred;
- private boolean chainReleased;
-
-
- private PhaseInterceptorChain(PhaseInterceptorChain src) {
- isFineLogging = LOG.isLoggable(Level.FINE);
-
- //only used for clone
- state = State.EXECUTING;
-
- //immutable, just repoint
- nameMap = src.nameMap;
- phases = src.phases;
-
- int length = phases.length;
- hasAfters = new boolean[length];
- System.arraycopy(src.hasAfters, 0, hasAfters, 0, length);
-
- heads = new InterceptorHolder[length];
- tails = new InterceptorHolder[length];
-
- InterceptorHolder last = null;
- for (int x = 0; x < length; x++) {
- InterceptorHolder ih = src.heads[x];
- while (ih != null
- && ih.phaseIdx == x) {
- InterceptorHolder ih2 = new InterceptorHolder(ih);
- ih2.prev = last;
- if (last != null) {
- last.next = ih2;
- }
- if (heads[x] == null) {
- heads[x] = ih2;
- }
- tails[x] = ih2;
- last = ih2;
- ih = ih.next;
- }
- }
- }
-
- public PhaseInterceptorChain(SortedSet<Phase> ps) {
- state = State.EXECUTING;
- isFineLogging = LOG.isLoggable(Level.FINE);
-
- int numPhases = ps.size();
- phases = new Phase[numPhases];
- nameMap = new HashMap<>();
-
- heads = new InterceptorHolder[numPhases];
- tails = new InterceptorHolder[numPhases];
- hasAfters = new boolean[numPhases];
-
- int idx = 0;
- for (Phase phase : ps) {
- phases[idx] = phase;
- nameMap.put(phase.getName(), idx);
- ++idx;
- }
- }
-
- public static Message getCurrentMessage() {
- return CURRENT_MESSAGE.get();
- }
-
- public static boolean setCurrentMessage(PhaseInterceptorChain chain, Message m) {
- if (getCurrentMessage() == m) {
- return false;
- }
- if (chain.iterator.hasPrevious()) {
- chain.iterator.previous();
- if (chain.iterator.next() instanceof ServiceInvokerInterceptor) {
- CURRENT_MESSAGE.set(m);
- return true;
- }
- String error = "Only ServiceInvokerInterceptor can update the current chain message";
- LOG.warning(error);
- throw new IllegalStateException(error);
- }
- return false;
-
- }
-
- public synchronized State getState() {
- return state;
- }
-
- public synchronized void releaseAndAcquireChain() {
- while (!chainReleased) {
- try {
- this.wait();
- } catch (InterruptedException ex) {
- // ignore
- }
- }
- chainReleased = false;
- }
-
- public synchronized void releaseChain() {
- this.chainReleased = true;
- this.notifyAll();
- }
-
- public PhaseInterceptorChain cloneChain() {
- return new PhaseInterceptorChain(this);
- }
-
- private void updateIterator() {
- if (iterator == null) {
- iterator = new PhaseInterceptorIterator(heads);
- outputChainToLog(false);
- }
- }
-
- public void add(Collection<Interceptor<? extends Message>> newhandlers) {
- add(newhandlers, false);
- }
-
- public void add(Collection<Interceptor<? extends Message>> newhandlers, boolean force) {
- if (newhandlers == null) {
- return;
- }
-
- for (Interceptor<? extends Message> handler : newhandlers) {
- add(handler, force);
- }
- }
-
- public void add(Interceptor<? extends Message> i) {
- add(i, false);
- }
-
- public void add(Interceptor<? extends Message> i, boolean force) {
- PhaseInterceptor<? extends Message> pi = (PhaseInterceptor<? extends Message>)i;
-
- String phaseName = pi.getPhase();
- Integer phase = nameMap.get(phaseName);
-
- if (phase == null) {
- LOG.warning("Skipping interceptor " + i.getClass().getName()
- + ((phaseName == null) ? ": Phase declaration is missing."
- : ": Phase " + phaseName + " specified does not exist."));
- } else {
- if (isFineLogging) {
- LOG.fine("Adding interceptor " + i + " to phase " + phaseName);
- }
-
- insertInterceptor(phase, pi, force);
- }
- Collection<PhaseInterceptor<? extends Message>> extras
- = pi.getAdditionalInterceptors();
- if (extras != null) {
- for (PhaseInterceptor<? extends Message> p : extras) {
- add(p, force);
- }
- }
- }
-
- public synchronized void pause() {
- state = State.PAUSED;
- pausedMessage = CURRENT_MESSAGE.get();
- }
- public synchronized void unpause() {
- if (state == State.PAUSED || state == State.SUSPENDED) {
- state = State.EXECUTING;
- pausedMessage = null;
- }
- }
-
- public synchronized void suspend() {
- state = State.SUSPENDED;
- pausedMessage = CURRENT_MESSAGE.get();
- }
-
- public synchronized void resume() {
- if (state == State.PAUSED || state == State.SUSPENDED) {
- state = State.EXECUTING;
- Message m = pausedMessage;
- pausedMessage = null;
- doIntercept(m);
- }
- }
-
- /**
- * Intercept a message, invoking each phase's handlers in turn.
- *
- * @param message the message
- * @throws Exception
- */
- @SuppressWarnings("unchecked")
- public synchronized boolean doIntercept(Message message) {
- updateIterator();
-
- Message oldMessage = CURRENT_MESSAGE.get();
- try {
- CURRENT_MESSAGE.set(message);
- if (oldMessage != null
- && !message.containsKey(PREVIOUS_MESSAGE)
- && message != oldMessage
- && message.getExchange() != oldMessage.getExchange()) {
- message.put(PREVIOUS_MESSAGE, new WeakReference<Message>(oldMessage));
- }
- while (state == State.EXECUTING && iterator.hasNext()) {
- try {
- Interceptor<Message> currentInterceptor = (Interceptor<Message>)iterator.next();
- if (isFineLogging) {
- LOG.fine("Invoking handleMessage on interceptor " + currentInterceptor);
- }
- //System.out.println("-----------" + currentInterceptor);
- currentInterceptor.handleMessage(message);
- if (state == State.SUSPENDED) {
- // throw the exception to make sure thread exit without interrupt
- throw new SuspendedInvocationException();
- }
-
- } catch (SuspendedInvocationException ex) {
-
- // Moving the chain iterator to the previous interceptor is needed
- // for the invocation to be resumed from the same interceptor which
- // suspended the invocation.
- // If "suspend.chain.on.current.interceptor" is set to true then
- // the chain will be resumed from the interceptor which follows
- // the interceptor which suspended the invocation.
- Object suspendProp = message.remove("suspend.chain.on.current.interceptor");
- if ((suspendProp == null || PropertyUtils.isFalse(suspendProp))
- && iterator.hasPrevious()) {
- iterator.previous();
- }
- pause();
- throw ex;
- } catch (RuntimeException ex) {
- if (!faultOccurred) {
- faultOccurred = true;
- wrapExceptionAsFault(message, ex);
- }
- state = State.ABORTED;
- }
- }
- if (state == State.EXECUTING) {
- state = State.COMPLETE;
- }
- return state == State.COMPLETE;
- } finally {
- CURRENT_MESSAGE.set(oldMessage);
- }
- }
-
- private void wrapExceptionAsFault(Message message, RuntimeException ex) {
- String description = getServiceInfo(message);
-
- message.setContent(Exception.class, ex);
- unwind(message);
- Exception ex2 = message.getContent(Exception.class);
- if (ex2 == null) {
- ex2 = ex;
- }
-
- FaultListener flogger = (FaultListener)
- message.getContextualProperty(FaultListener.class.getName());
- boolean useDefaultLogging = true;
- if (flogger != null) {
- useDefaultLogging = flogger.faultOccurred(ex2, description, message);
- }
- if (useDefaultLogging) {
- doDefaultLogging(message, ex2, description);
- }
-
- if (message.getExchange() != null && message.getContent(Exception.class) != null) {
- message.getExchange().put(Exception.class, ex2);
- }
-
- if (faultObserver != null && !isOneWay(message)) {
- // CXF-5629. when exchange is one way and robust, it becomes req-resp in order to
- // send the fault
- message.getExchange().setOneWay(false);
- faultObserver.onMessage(message);
- }
- }
-
- private String getServiceInfo(Message message) {
- StringBuilder description = new StringBuilder();
- if (message.getExchange() != null) {
- Exchange exchange = message.getExchange();
- Service service = exchange.getService();
- if (service != null) {
- description.append('\'');
- description.append(service.getName());
- BindingOperationInfo boi = exchange.getBindingOperationInfo();
- OperationInfo opInfo = boi != null ? boi.getOperationInfo() : null;
- if (opInfo != null) {
- description.append('#').append(opInfo.getName());
- }
- description.append("\' ");
- }
- }
- return description.toString();
- }
-
- private void doDefaultLogging(Message message, Exception ex, String description) {
- FaultMode mode = message.get(FaultMode.class);
- if (mode == FaultMode.CHECKED_APPLICATION_FAULT) {
- if (isFineLogging) {
- LogUtils.log(LOG, Level.FINE,
- "Application " + description
- + "has thrown exception, unwinding now", ex);
- } else if (LOG.isLoggable(Level.INFO)) {
- Throwable t = ex;
- if (ex instanceof Fault
- && ex.getCause() != null) {
- t = ex.getCause();
- }
-
- LogUtils.log(LOG, Level.INFO,
- "Application " + description
- + "has thrown exception, unwinding now: "
- + t.getClass().getName()
- + ": " + ex.getMessage());
- }
- } else if (LOG.isLoggable(Level.WARNING)) {
- if (mode == FaultMode.UNCHECKED_APPLICATION_FAULT) {
- LogUtils.log(LOG, Level.WARNING,
- "Application " + description
- + "has thrown exception, unwinding now", ex);
- } else {
- LogUtils.log(LOG, Level.WARNING,
- "Interceptor for " + description
- + "has thrown exception, unwinding now", ex);
- }
- }
- }
-
- private boolean isOneWay(Message message) {
- return (message.getExchange() != null) && message.getExchange().isOneWay() && !isRobustOneWay(message);
- }
-
- private boolean isRobustOneWay(Message message) {
- return MessageUtils.getContextualBoolean(message, Message.ROBUST_ONEWAY, false);
- }
-
- /**
- * Intercept a message, invoking each phase's handlers in turn,
- * starting after the specified interceptor.
- *
- * @param message the message
- * @param startingAfterInterceptorID the id of the interceptor
- * @throws Exception
- */
- public synchronized boolean doInterceptStartingAfter(Message message,
- String startingAfterInterceptorID) {
- updateIterator();
- while (state == State.EXECUTING && iterator.hasNext()) {
- PhaseInterceptor<? extends Message> currentInterceptor
- = (PhaseInterceptor<? extends Message>)iterator.next();
- if (currentInterceptor.getId().equals(startingAfterInterceptorID)) {
- break;
- }
- }
- return doIntercept(message);
- }
-
- /**
- * Intercept a message, invoking each phase's handlers in turn,
- * starting at the specified interceptor.
- *
- * @param message the message
- * @param startingAtInterceptorID the id of the interceptor
- * @throws Exception
- */
- public synchronized boolean doInterceptStartingAt(Message message,
- String startingAtInterceptorID) {
- updateIterator();
- while (state == State.EXECUTING && iterator.hasNext()) {
- PhaseInterceptor<? extends Message> currentInterceptor
- = (PhaseInterceptor<? extends Message>)iterator.next();
- if (currentInterceptor.getId().equals(startingAtInterceptorID)) {
- iterator.previous();
- break;
- }
- }
- return doIntercept(message);
- }
-
- public synchronized void reset() {
- updateIterator();
- if (state == State.COMPLETE) {
- state = State.EXECUTING;
- iterator.reset();
- } else {
- iterator.reset();
- }
- }
-
- @SuppressWarnings("unchecked")
- public void unwind(Message message) {
- while (iterator.hasPrevious()) {
- Interceptor<Message> currentInterceptor = (Interceptor<Message>)iterator.previous();
- if (isFineLogging) {
- LOG.fine("Invoking handleFault on interceptor " + currentInterceptor);
- }
- try {
- currentInterceptor.handleFault(message);
- } catch (RuntimeException e) {
- LOG.log(Level.WARNING, "Exception in handleFault on interceptor " + currentInterceptor, e);
- throw e;
- } catch (Exception e) {
- LOG.log(Level.WARNING, "Exception in handleFault on interceptor " + currentInterceptor, e);
- throw new RuntimeException(e);
- }
- }
- }
-
- public void remove(Interceptor<? extends Message> i) {
- PhaseInterceptorIterator it = new PhaseInterceptorIterator(heads);
- while (it.hasNext()) {
- InterceptorHolder holder = it.nextInterceptorHolder();
- if (holder.interceptor == i) {
- remove(holder);
- return;
- }
- }
- }
-
- public synchronized void abort() {
- this.state = InterceptorChain.State.ABORTED;
- }
-
- public Iterator<Interceptor<? extends Message>> iterator() {
- return getIterator();
- }
- public ListIterator<Interceptor<? extends Message>> getIterator() {
- return new PhaseInterceptorIterator(heads);
- }
-
- private void remove(InterceptorHolder i) {
- if (i.prev != null) {
- i.prev.next = i.next;
- }
- if (i.next != null) {
- i.next.prev = i.prev;
- }
- int ph = i.phaseIdx;
- if (heads[ph] == i) {
- if (i.next != null
- && i.next.phaseIdx == ph) {
- heads[ph] = i.next;
- } else {
- heads[ph] = null;
- tails[ph] = null;
- }
- }
- if (tails[ph] == i) {
- if (i.prev != null
- && i.prev.phaseIdx == ph) {
- tails[ph] = i.prev;
- } else {
- heads[ph] = null;
- tails[ph] = null;
- }
- }
- }
-
- private void insertInterceptor(int phase, PhaseInterceptor<? extends Message> interc, boolean force) {
- InterceptorHolder ih = new InterceptorHolder(interc, phase);
- if (heads[phase] == null) {
- // no interceptors yet in this phase
- heads[phase] = ih;
- tails[phase] = ih;
- hasAfters[phase] = !interc.getAfter().isEmpty();
-
- int idx = phase - 1;
- while (idx >= 0) {
- if (tails[idx] != null) {
- break;
- }
- --idx;
- }
- if (idx >= 0) {
- //found something before us, in an earlier phase
- ih.prev = tails[idx];
- ih.next = tails[idx].next;
- if (ih.next != null) {
- ih.next.prev = ih;
- }
- tails[idx].next = ih;
- } else {
- //did not find something before us, try after
- idx = phase + 1;
- while (idx < heads.length) {
- if (heads[idx] != null) {
- break;
- }
- ++idx;
- }
-
- if (idx != heads.length) {
- //found something after us
- ih.next = heads[idx];
- heads[idx].prev = ih;
- }
- }
- } else { // this phase already has interceptors attached
-
- // list of interceptors that the new interceptor should precede
- Set<String> beforeList = interc.getBefore();
-
- // list of interceptors that the new interceptor should be after
- Set<String> afterList = interc.getAfter();
-
- // firstBefore will hold the first interceptor of a given phase
- // that the interceptor to be added must precede
- InterceptorHolder firstBefore = null;
-
- // lastAfter will hold the last interceptor of a given phase
- // that the interceptor to be added must come after
- InterceptorHolder lastAfter = null;
-
- String id = interc.getId();
- if (hasAfters[phase] || !beforeList.isEmpty()) {
-
- InterceptorHolder ih2 = heads[phase];
- while (ih2 != tails[phase].next) {
- PhaseInterceptor<? extends Message> cmp = ih2.interceptor;
- String cmpId = cmp.getId();
- if (cmpId != null && firstBefore == null
- && (beforeList.contains(cmpId)
- || cmp.getAfter().contains(id))) {
- firstBefore = ih2;
- }
- if (cmp.getBefore().contains(id)
- || (cmpId != null && afterList.contains(cmpId))) {
- lastAfter = ih2;
- }
- if (!force && cmpId.equals(id)) {
- // interceptor is already in chain
- return;
- }
- ih2 = ih2.next;
- }
- if (lastAfter == null && beforeList.contains("*")) {
- firstBefore = heads[phase];
- }
-
- } else if (!force) {
- // skip interceptor if already in chain
- InterceptorHolder ih2 = heads[phase];
- while (ih2 != tails[phase].next) {
- if (ih2.interceptor.getId().equals(id)) {
- return;
- }
- ih2 = ih2.next;
- }
-
- }
- hasAfters[phase] |= !afterList.isEmpty();
-
- if (firstBefore == null
- && lastAfter == null
- && !beforeList.isEmpty()
- && afterList.isEmpty()) {
- //if this interceptor has stuff it MUST be before,
- //but nothing it must be after, just
- //stick it at the beginning
- firstBefore = heads[phase];
- }
-
- if (firstBefore == null) {
- //just add new interceptor at the end
- ih.prev = tails[phase];
- ih.next = tails[phase].next;
- tails[phase].next = ih;
-
- if (ih.next != null) {
- ih.next.prev = ih;
- }
- tails[phase] = ih;
- } else {
- ih.prev = firstBefore.prev;
- if (ih.prev != null) {
- ih.prev.next = ih;
- }
- ih.next = firstBefore;
- firstBefore.prev = ih;
-
- if (heads[phase] == firstBefore) {
- heads[phase] = ih;
- }
- }
- }
- if (iterator != null) {
- outputChainToLog(true);
- }
- }
-
- public String toString() {
- return toString("");
- }
- private String toString(String message) {
- StringBuilder chain = new StringBuilder(128);
-
- chain.append("Chain ")
- .append(super.toString())
- .append(message)
- .append(". Current flow:\n");
-
- for (int x = 0; x < phases.length; x++) {
- if (heads[x] != null) {
- chain.append(" ");
- printPhase(x, chain);
- }
- }
- return chain.toString();
- }
- private void printPhase(int ph, StringBuilder chain) {
-
- chain.append(phases[ph].getName())
- .append(" [");
- InterceptorHolder i = heads[ph];
- boolean first = true;
- while (i != tails[ph].next) {
- if (first) {
- first = false;
- } else {
- chain.append(", ");
- }
- String nm = i.interceptor.getClass().getSimpleName();
- if (StringUtils.isEmpty(nm)) {
- nm = i.interceptor.getId();
- }
- chain.append(nm);
- i = i.next;
- }
- chain.append("]\n");
- }
-
- private void outputChainToLog(boolean modified) {
- if (isFineLogging) {
- if (modified) {
- LOG.fine(toString(" was modified"));
- } else {
- LOG.fine(toString(" was created"));
- }
- }
- }
-
- public MessageObserver getFaultObserver() {
- return faultObserver;
- }
-
- public void setFaultObserver(MessageObserver faultObserver) {
- this.faultObserver = faultObserver;
- }
-
- static final class PhaseInterceptorIterator implements ListIterator<Interceptor<? extends Message>> {
- InterceptorHolder[] heads;
- InterceptorHolder prev;
- InterceptorHolder first;
-
- PhaseInterceptorIterator(InterceptorHolder[] h) {
- heads = h;
- first = findFirst();
- }
-
- public void reset() {
- prev = null;
- first = findFirst();
- }
-
- private InterceptorHolder findFirst() {
- for (int x = 0; x < heads.length; x++) {
- if (heads[x] != null) {
- return heads[x];
- }
- }
- return null;
- }
-
-
- public boolean hasNext() {
- if (prev == null) {
- return first != null;
- }
- return prev.next != null;
- }
-
- public Interceptor<? extends Message> next() {
- if (prev == null) {
- if (first == null) {
- throw new NoSuchElementException();
- }
- prev = first;
- } else {
- if (prev.next == null) {
- throw new NoSuchElementException();
- }
- prev = prev.next;
- }
- return prev.interceptor;
- }
- public InterceptorHolder nextInterceptorHolder() {
- if (prev == null) {
- if (first == null) {
- throw new NoSuchElementException();
- }
- prev = first;
- } else {
- if (prev.next == null) {
- throw new NoSuchElementException();
- }
- prev = prev.next;
- }
- return prev;
- }
-
- public boolean hasPrevious() {
- return prev != null;
- }
- public Interceptor<? extends Message> previous() {
- if (prev == null) {
- throw new NoSuchElementException();
- }
- InterceptorHolder tmp = prev;
- prev = prev.prev;
- return tmp.interceptor;
- }
-
- public int nextIndex() {
- throw new UnsupportedOperationException();
- }
- public int previousIndex() {
- throw new UnsupportedOperationException();
- }
- public void add(Interceptor<? extends Message> o) {
- throw new UnsupportedOperationException();
- }
- public void set(Interceptor<? extends Message> o) {
- throw new UnsupportedOperationException();
- }
- public void remove() {
- throw new UnsupportedOperationException();
- }
- }
-
-
- static final class InterceptorHolder {
- PhaseInterceptor<? extends Message> interceptor;
- InterceptorHolder next;
- InterceptorHolder prev;
- int phaseIdx;
-
- InterceptorHolder(PhaseInterceptor<? extends Message> i, int p) {
- interceptor = i;
- phaseIdx = p;
- }
- InterceptorHolder(InterceptorHolder p) {
- interceptor = p.interceptor;
- phaseIdx = p.phaseIdx;
- }
- }
-
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/service/factory/FactoryBeanListener.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/service/factory/FactoryBeanListener.java
deleted file mode 100644
index 687f211..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/service/factory/FactoryBeanListener.java
+++ /dev/null
@@ -1,145 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.cxf.service.factory;
-
-/**
- *
- */
-public interface FactoryBeanListener {
- enum Event {
- /**
- * Event fired at the very start of processing. No parameters. Useful
- * for setting up any state the listener may need to maintain.
- */
- START_CREATE,
-
- /**
- * Event fired at the very end of processing. One parameter is passed
- * in which is the Service object that was created.
- */
- END_CREATE,
-
- /**
- * Called at the start of processing when it detects that the service
- * is to be created based on a wsdl contract. One String parameter
- * of the URL of the wsdl.
- */
- CREATE_FROM_WSDL,
-
- /**
- * Called at the start of processing when it detects that the service
- * is to be created based on a Java class. One Class<?> parameter
- * of the class that is being analyzed.
- */
- CREATE_FROM_CLASS,
-
- /**
- * Called after the wsdl is loaded/parsed. Single parameter of the
- * WSS4J Definition of the WSDL.
- */
- WSDL_LOADED,
-
- /**
- * Called after the Service is set into the Factory after which the getService()
- * call will return a valid value. One parameter of the Service object.
- */
- SERVICE_SET,
-
-
- /**
- * OperationInfo, Method
- */
- INTERFACE_OPERATION_BOUND,
-
- /**
- * OperationInfo, Method, MessageInfo
- */
- OPERATIONINFO_IN_MESSAGE_SET,
- OPERATIONINFO_OUT_MESSAGE_SET,
-
- /**
- * OperationInfo, Class<? extends Throwable>, FaultInfo
- */
- OPERATIONINFO_FAULT,
-
- /**
- * InterfaceInfo, Class<?>
- */
- INTERFACE_CREATED,
-
- /**
- * DataBinding
- */
- DATABINDING_INITIALIZED,
-
- /**
- * EndpointInfo, Endpoint, Class
- */
- ENDPOINT_CREATED,
-
- /**
- * Server, targetObject, Class
- */
- PRE_SERVER_CREATE,
-
- /**
- * Server, targetObject, Class
- */
- SERVER_CREATED,
-
- /**
- * BindingInfo, BindingOperationInfo, Implementation Method
- */
- BINDING_OPERATION_CREATED,
-
- /**
- * BindingInfo
- */
- BINDING_CREATED,
-
- /**
- * Endpoint
- */
- PRE_CLIENT_CREATE,
-
- /**
- * Endpoint, Client
- */
- CLIENT_CREATED,
-
- /**
- * EndpointInfo, Endpoint, SEI Class, Class
- */
- ENDPOINT_SELECTED,
-
- /**
- * EndpointInfo
- */
- ENDPOINTINFO_CREATED,
-
- /**
- * Class[], InvokationHandler, Proxy
- */
- PROXY_CREATED,
- }
-
-
- void handleEvent(Event ev, AbstractServiceFactoryBean factory, Object ... args);
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/service/invoker/FactoryInvoker.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/service/invoker/FactoryInvoker.java
deleted file mode 100644
index 465046b..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/service/invoker/FactoryInvoker.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.cxf.service.invoker;
-
-import java.util.ResourceBundle;
-
-import org.apache.cxf.common.i18n.BundleUtils;
-import org.apache.cxf.common.i18n.Message;
-import org.apache.cxf.interceptor.Fault;
-import org.apache.cxf.message.Exchange;
-
-/**
- * This invoker implementation calls a Factory to create the service object.
- *
- */
-public class FactoryInvoker extends AbstractInvoker {
- static final ResourceBundle BUNDLE = BundleUtils.getBundle(FactoryInvoker.class);
-
- protected Factory factory;
-
- /**
- * Create a FactoryInvoker object.
- *
- * @param factory the factory used to create service object.
- */
- public FactoryInvoker(Factory factory) {
- this.factory = factory;
- }
- public FactoryInvoker() {
- }
- public void setFactory(Factory f) {
- this.factory = f;
- }
-
- public Object getServiceObject(Exchange ex) {
- try {
- return factory.create(ex);
- } catch (Fault e) {
- throw e;
- } catch (Throwable e) {
- throw new Fault(new Message("CREATE_SERVICE_OBJECT_EXC", BUNDLE), e);
- }
- }
-
- @Override
- public void releaseServiceObject(final Exchange ex, Object obj) {
- factory.release(ex, obj);
- }
-
- public boolean isSingletonFactory() {
- return factory instanceof SingletonFactory;
- }
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/service/model/AbstractPropertiesHolder.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/service/model/AbstractPropertiesHolder.java
deleted file mode 100644
index d80e02d..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/service/model/AbstractPropertiesHolder.java
+++ /dev/null
@@ -1,271 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.cxf.service.model;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.atomic.AtomicReference;
-
-import javax.xml.namespace.QName;
-
-public abstract class AbstractPropertiesHolder implements Extensible {
- private AbstractPropertiesHolder delegate;
- private boolean delegateProperties;
-
- private AtomicReference<Map<String, Object>> propertyMap = new AtomicReference<>();
- private AtomicReference<Object[]> extensors = new AtomicReference<>();
- private Map<QName, Object> extensionAttributes;
- private String documentation;
-
-
- public final void setDelegate(AbstractPropertiesHolder p, boolean props) {
- delegate = p;
- delegateProperties = props;
- if (delegate == null) {
- return;
- }
- if (documentation != null) {
- delegate.setDocumentation(documentation);
- documentation = null;
- }
- if (extensionAttributes != null) {
- delegate.setExtensionAttributes(extensionAttributes);
- extensionAttributes = null;
- }
- if (extensors.get() != null) {
- for (Object el : extensors.get()) {
- delegate.addExtensor(el);
- }
- extensors.set(null);
- }
- if (delegateProperties && propertyMap.get() != null) {
- for (Map.Entry<String, Object> p2 : propertyMap.get().entrySet()) {
- delegate.setProperty(p2.getKey(), p2.getValue());
- }
- propertyMap.set(null);
- }
- }
-
- public String getDocumentation() {
- if (delegate != null) {
- return delegate.getDocumentation();
- }
- return documentation;
- }
- public void setDocumentation(String s) {
- if (delegate != null) {
- delegate.setDocumentation(s);
- } else {
- documentation = s;
- }
- }
- public Map<String, Object> getProperties() {
- if (delegate != null && delegateProperties) {
- return delegate.getProperties();
- }
- return propertyMap.get();
- }
- public Object getProperty(String name) {
- if (delegate != null && delegateProperties) {
- return delegate.getProperty(name);
- }
- if (null == propertyMap.get()) {
- return null;
- }
- return propertyMap.get().get(name);
- }
- public Object removeProperty(String name) {
- if (delegate != null && delegateProperties) {
- delegate.removeProperty(name);
- }
- if (null == propertyMap.get()) {
- return null;
- }
- return propertyMap.get().remove(name);
- }
-
- public <T> T getProperty(String name, Class<T> cls) {
- return cls.cast(getProperty(name));
- }
- public boolean hasProperty(String name) {
- if (delegate != null && delegateProperties) {
- return delegate.hasProperty(name);
- }
- Map<String, Object> map = propertyMap.get();
- if (map != null) {
- return map.containsKey(name);
- }
- return false;
- }
-
- public void setProperty(String name, Object v) {
- if (delegate != null && delegateProperties) {
- delegate.setProperty(name, v);
- return;
- }
- if (null == propertyMap.get()) {
- propertyMap.compareAndSet(null, new ConcurrentHashMap<>(4, 0.75f, 2));
- }
- if (v == null) {
- propertyMap.get().remove(name);
- } else {
- propertyMap.get().put(name, v);
- }
- }
-
- public boolean containsExtensor(Object el) {
- if (delegate != null) {
- return delegate.containsExtensor(el);
- }
-
- Object[] exts = extensors.get();
- if (exts != null) {
- for (Object o : exts) {
- if (o == el) {
- return true;
- }
- }
- }
- return false;
- }
- public void addExtensor(Object el) {
- if (delegate != null) {
- delegate.addExtensor(el);
- return;
- }
- Object[] exts = extensors.get();
- Object[] exts2;
- if (exts == null) {
- exts2 = new Object[1];
- } else {
- exts2 = new Object[exts.length + 1];
- System.arraycopy(exts, 0, exts2, 0, exts.length);
- }
- exts2[exts2.length - 1] = el;
- if (!extensors.compareAndSet(exts, exts2)) {
- //keep trying
- addExtensor(el);
- }
- }
-
- public <T> T getExtensor(Class<T> cls) {
- if (delegate != null) {
- return delegate.getExtensor(cls);
- }
- Object[] exts = extensors.get();
- if (exts == null) {
- return null;
- }
- for (int x = 0; x < exts.length; x++) {
- if (cls.isInstance(exts[x])) {
- return cls.cast(exts[x]);
- }
- }
- return null;
- }
- public <T> List<T> getExtensors(Class<T> cls) {
- if (delegate != null) {
- return delegate.getExtensors(cls);
- }
-
- Object[] exts = extensors.get();
- if (exts == null) {
- return null;
- }
- List<T> list = new ArrayList<>(exts.length);
- for (int x = 0; x < exts.length; x++) {
- if (cls.isInstance(exts[x])) {
- list.add(cls.cast(exts[x]));
- }
- }
- return list;
- }
-
- public AtomicReference<Object[]> getExtensors() {
- if (delegate != null) {
- return delegate.getExtensors();
- }
- return extensors;
- }
-
-
- public Object getExtensionAttribute(QName name) {
- if (delegate != null) {
- return delegate.getExtensionAttribute(name);
- }
- return null == extensionAttributes ? null : extensionAttributes.get(name);
- }
-
- public Map<QName, Object> getExtensionAttributes() {
- if (delegate != null) {
- return delegate.getExtensionAttributes();
- }
- return extensionAttributes;
- }
-
- public void addExtensionAttribute(QName name, Object attr) {
- if (delegate != null) {
- delegate.addExtensionAttribute(name, attr);
- return;
- }
- if (null == extensionAttributes) {
- extensionAttributes = new HashMap<>();
- }
- extensionAttributes.put(name, attr);
- }
-
- public void setExtensionAttributes(Map<QName, Object> attrs) {
- if (delegate != null) {
- delegate.setExtensionAttributes(attrs);
- return;
- }
- extensionAttributes = attrs;
- }
-
- /**
- * Lookup a configuration value. This may be found in the properties holder supplied
- * (i.e. an EndpointInfo or ServiceInfo), or it may be a property on the Bus itself.
- * If no value is found, the defaultValue is returned.
- *
- * @param defaultValue the default value
- * @param type the extensor type
- * @return the configuration value or the default
- */
- public <T> T getTraversedExtensor(T defaultValue, Class<T> type) {
- if (delegate != null) {
- return delegate.getTraversedExtensor(defaultValue, type);
- }
- T extensor = getExtensor(type);
- if (extensor == null) {
- return defaultValue;
- }
- return extensor;
- }
-
-
- protected static final boolean equals(Object o1, Object o2) {
- return Objects.equals(o1, o2);
- }
-
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/service/model/FaultInfo.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/service/model/FaultInfo.java
deleted file mode 100644
index f2f240f..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/service/model/FaultInfo.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.cxf.service.model;
-
-import javax.xml.namespace.QName;
-
-public class FaultInfo extends AbstractMessageContainer {
- private QName faultName;
-
- public FaultInfo(QName fname, QName mname, OperationInfo info) {
- super(info, mname);
- faultName = fname;
- }
-
- public QName getFaultName() {
- return faultName;
- }
- public void setFaultName(QName fname) {
- faultName = fname;
- }
-
-
-
- @Override
- public int hashCode() {
- return faultName == null ? -1 : faultName.hashCode();
- }
-
- @Override
- public boolean equals(Object o) {
- if (o == this) {
- return true;
- }
-
- if (!(o instanceof FaultInfo)) {
- return false;
- }
- FaultInfo oi = (FaultInfo)o;
- return equals(faultName, oi.faultName)
- && super.equals(o);
- }
-
-
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/service/model/InterfaceInfo.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/service/model/InterfaceInfo.java
deleted file mode 100644
index a5c3f26..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/service/model/InterfaceInfo.java
+++ /dev/null
@@ -1,124 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.cxf.service.model;
-
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.logging.Logger;
-
-import javax.xml.namespace.QName;
-
-import org.apache.cxf.common.i18n.Message;
-import org.apache.cxf.common.logging.LogUtils;
-
-public class InterfaceInfo extends AbstractDescriptionElement implements NamedItem {
- private static final Logger LOG = LogUtils.getL7dLogger(InterfaceInfo.class);
-
- QName name;
- ServiceInfo service;
-
- Map<QName, OperationInfo> operations = new ConcurrentHashMap<>(4, 0.75f, 2);
-
- public InterfaceInfo(ServiceInfo info, QName q) {
- name = q;
- service = info;
- info.setInterface(this);
- }
- public DescriptionInfo getDescription() {
- if (service == null) {
- return null;
- }
- return service.getDescription();
- }
-
- public ServiceInfo getService() {
- return service;
- }
-
- public void setName(QName n) {
- name = n;
- }
- public QName getName() {
- return name;
- }
-
-
- /**
- * Adds an operation to this service.
- *
- * @param oname the qualified name of the operation.
- * @return the operation.
- */
- public OperationInfo addOperation(QName oname) {
- if (oname == null) {
- throw new NullPointerException(
- new Message("OPERATION.NAME.NOT.NULL", LOG).toString());
- }
- if (operations.containsKey(oname)) {
- throw new IllegalArgumentException(
- new Message("DUPLICATED.OPERATION.NAME", LOG, oname).toString());
- }
-
- OperationInfo operation = new OperationInfo(this, oname);
- addOperation(operation);
- return operation;
- }
-
- /**
- * Adds an operation to this service.
- *
- * @param operation the operation.
- */
- void addOperation(OperationInfo operation) {
- operations.put(operation.getName(), operation);
- }
-
- /**
- * Removes an operation from this service.
- *
- * @param operation the operation.
- */
- public void removeOperation(OperationInfo operation) {
- operations.remove(operation.getName());
- }
-
- /**
- * Returns the operation info with the given name, if found.
- *
- * @param oname the name.
- * @return the operation; or <code>null</code> if not found.
- */
- public OperationInfo getOperation(QName oname) {
- return operations.get(oname);
- }
-
- /**
- * Returns all operations for this service.
- *
- * @return all operations.
- */
- public Collection<OperationInfo> getOperations() {
- return Collections.unmodifiableCollection(operations.values());
- }
-
-
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/service/model/OperationInfo.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/service/model/OperationInfo.java
deleted file mode 100644
index d5fe4d3..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/service/model/OperationInfo.java
+++ /dev/null
@@ -1,242 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.cxf.service.model;
-
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.logging.Logger;
-
-import javax.xml.namespace.QName;
-
-import org.apache.cxf.common.i18n.Message;
-import org.apache.cxf.common.logging.LogUtils;
-
-public class OperationInfo extends AbstractPropertiesHolder implements NamedItem {
- private static final Logger LOG = LogUtils.getL7dLogger(OperationInfo.class);
- InterfaceInfo intf;
- QName opName;
- String inName;
- MessageInfo inputMessage;
- String outName;
- MessageInfo outputMessage;
- Map<QName, FaultInfo> faults;
- OperationInfo unwrappedOperation;
- List<String> parameterOrdering;
-
- public OperationInfo() {
- }
-
- OperationInfo(InterfaceInfo it, QName n) {
- intf = it;
- setName(n);
- }
- OperationInfo(OperationInfo op) {
- intf = op.getInterface();
- setName(op.getName());
- }
-
- /**
- * Returns the name of the Operation.
- * @return the name of the Operation
- */
- public QName getName() {
- return opName;
- }
- /**
- * Sets the name of the operation.
- * @param name the new name of the operation
- */
- public final void setName(QName name) {
- if (name == null) {
- throw new NullPointerException("Operation Name cannot be null.");
- }
- opName = name;
- }
- public InterfaceInfo getInterface() {
- return intf;
- }
-
-
- public MessageInfo createMessage(QName nm, MessageInfo.Type type) {
- return new MessageInfo(this, type, nm);
- }
-
- public MessageInfo getOutput() {
- return outputMessage;
- }
- public String getOutputName() {
- return outName;
- }
- public void setOutput(String nm, MessageInfo out) {
- outName = nm;
- outputMessage = out;
- if (unwrappedOperation != null && unwrappedOperation.getOutput() != null) {
- unwrappedOperation.getOutput().setDelegate(out, false);
- }
- }
- public boolean hasOutput() {
- return outputMessage != null;
- }
-
- public MessageInfo getInput() {
- return inputMessage;
- }
- public String getInputName() {
- return inName;
- }
- public void setInput(String nm, MessageInfo in) {
- inName = nm;
- inputMessage = in;
- if (unwrappedOperation != null && unwrappedOperation.getInput() != null) {
- unwrappedOperation.getInput().setDelegate(in, false);
- }
- }
- public boolean hasInput() {
- return inputMessage != null;
- }
-
- public boolean isOneWay() {
- return inputMessage != null && outputMessage == null;
- }
-
- public boolean isUnwrappedCapable() {
- return unwrappedOperation != null;
- }
-
- public OperationInfo getUnwrappedOperation() {
- return unwrappedOperation;
- }
- public void setUnwrappedOperation(OperationInfo op) {
- unwrappedOperation = op;
- }
- public boolean isUnwrapped() {
- return false;
- }
-
-
- /**
- * Adds an fault to this operation.
- *
- * @param name the fault name.
- */
- public FaultInfo addFault(QName name, QName message) {
- if (name == null) {
- throw new NullPointerException(new Message("FAULT.NAME.NOT.NULL", LOG).toString());
- }
- if (faults != null && faults.containsKey(name)) {
- throw new IllegalArgumentException(
- new Message("DUPLICATED.FAULT.NAME", LOG, name).toString());
- }
- FaultInfo fault = new FaultInfo(name, message, this);
- addFault(fault);
- return fault;
- }
-
- /**
- * Adds a fault to this operation.
- *
- * @param fault the fault.
- */
- public synchronized void addFault(FaultInfo fault) {
- if (faults == null) {
- faults = new ConcurrentHashMap<>(4, 0.75f, 2);
- }
- faults.put(fault.getFaultName(), fault);
- }
-
- /**
- * Removes a fault from this operation.
- *
- * @param name the qualified fault name.
- */
- public void removeFault(QName name) {
- if (faults != null) {
- faults.remove(name);
- }
- }
-
- /**
- * Returns the fault with the given name, if found.
- *
- * @param name the name.
- * @return the fault; or <code>null</code> if not found.
- */
- public FaultInfo getFault(QName name) {
- if (faults != null) {
- return faults.get(name);
- }
- return null;
- }
-
- public boolean hasFaults() {
- return faults != null && !faults.isEmpty();
- }
-
- /**
- * Returns all faults for this operation.
- *
- * @return all faults.
- */
- public Collection<FaultInfo> getFaults() {
- if (faults == null) {
- return Collections.emptyList();
- }
- return Collections.unmodifiableCollection(faults.values());
- }
-
- public void setParameterOrdering(List<String> o) {
- this.parameterOrdering = o;
- }
-
- public List<String> getParameterOrdering() {
- return parameterOrdering;
- }
-
- @Override
- public String toString() {
- return new StringBuilder("[OperationInfo: ")
- .append(opName)
- .append(']').toString();
- }
-
- public int hashCode() {
- return opName == null ? -1 : opName.hashCode();
- }
-
- public boolean equals(Object o) {
- if (o == this) {
- return true;
- }
-
- if (!(o instanceof OperationInfo)) {
- return false;
- }
- OperationInfo oi = (OperationInfo)o;
- return equals(opName, oi.opName)
- && equals(inputMessage, oi.inputMessage)
- && equals(outputMessage, oi.outputMessage)
- && equals(faults, oi.faults)
- && equals(intf.getName(), oi.intf.getName());
- }
-
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/service/model/UnwrappedOperationInfo.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/service/model/UnwrappedOperationInfo.java
deleted file mode 100644
index 31ed72c..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/service/model/UnwrappedOperationInfo.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.cxf.service.model;
-
-import java.util.Collection;
-
-import javax.xml.namespace.QName;
-
-public class UnwrappedOperationInfo extends OperationInfo {
- OperationInfo wrappedOp;
-
- public UnwrappedOperationInfo(OperationInfo op) {
- super(op);
- wrappedOp = op;
- setDelegate(wrappedOp, true);
- }
-
- public OperationInfo getWrappedOperation() {
- return wrappedOp;
- }
-
- @Override
- public boolean isUnwrapped() {
- return true;
- }
-
- @Override
- public FaultInfo addFault(QName name, QName message) {
- return wrappedOp.addFault(name, message);
- }
-
- @Override
- public FaultInfo getFault(QName name) {
- return wrappedOp.getFault(name);
- }
-
- @Override
- public Collection<FaultInfo> getFaults() {
- return wrappedOp.getFaults();
- }
-
-
- @Override
- public void setOutput(String nm, MessageInfo out) {
- super.setOutput(nm, out);
- out.setDelegate(wrappedOp.getOutput(), false);
- }
-
- @Override
- public void setInput(String nm, MessageInfo in) {
- super.setInput(nm, in);
- in.setDelegate(wrappedOp.getInput(), false);
- }
-
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/staxutils/StaxUtils.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/staxutils/StaxUtils.java
deleted file mode 100644
index 440968c..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/staxutils/StaxUtils.java
+++ /dev/null
@@ -1,2222 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.cxf.staxutils;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.io.Reader;
-import java.io.StringWriter;
-import java.io.Writer;
-import java.net.URL;
-import java.nio.charset.StandardCharsets;
-import java.nio.file.Files;
-import java.util.ArrayDeque;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Deque;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Queue;
-import java.util.concurrent.ArrayBlockingQueue;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import javax.xml.namespace.NamespaceContext;
-import javax.xml.namespace.QName;
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.stream.Location;
-import javax.xml.stream.StreamFilter;
-import javax.xml.stream.XMLEventFactory;
-import javax.xml.stream.XMLInputFactory;
-import javax.xml.stream.XMLOutputFactory;
-import javax.xml.stream.XMLResolver;
-import javax.xml.stream.XMLStreamConstants;
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamReader;
-import javax.xml.stream.XMLStreamWriter;
-import javax.xml.stream.events.Attribute;
-import javax.xml.stream.events.Characters;
-import javax.xml.stream.events.DTD;
-import javax.xml.stream.events.Namespace;
-import javax.xml.stream.events.StartDocument;
-import javax.xml.stream.events.StartElement;
-import javax.xml.stream.events.XMLEvent;
-import javax.xml.transform.Result;
-import javax.xml.transform.Source;
-import javax.xml.transform.dom.DOMResult;
-import javax.xml.transform.dom.DOMSource;
-import javax.xml.transform.sax.SAXSource;
-import javax.xml.transform.stax.StAXSource;
-import javax.xml.transform.stream.StreamSource;
-
-import org.w3c.dom.Attr;
-import org.w3c.dom.CDATASection;
-import org.w3c.dom.Comment;
-import org.w3c.dom.Document;
-import org.w3c.dom.DocumentFragment;
-import org.w3c.dom.DocumentType;
-import org.w3c.dom.Element;
-import org.w3c.dom.EntityReference;
-import org.w3c.dom.NamedNodeMap;
-import org.w3c.dom.Node;
-import org.w3c.dom.ProcessingInstruction;
-import org.w3c.dom.Text;
-import org.w3c.dom.UserDataHandler;
-
-import org.xml.sax.InputSource;
-import org.xml.sax.XMLReader;
-
-import org.apache.cxf.common.logging.LogUtils;
-import org.apache.cxf.common.util.PropertyUtils;
-import org.apache.cxf.common.util.StringUtils;
-import org.apache.cxf.common.util.SystemPropertyAction;
-import org.apache.cxf.helpers.CastUtils;
-import org.apache.cxf.helpers.DOMUtils;
-import org.apache.cxf.message.Message;
-
-public final class StaxUtils {
- // System properties for defaults, but also contextual properties usable
- // for StaxInInterceptor
- public static final String MAX_CHILD_ELEMENTS =
- "org.apache.cxf.stax.maxChildElements";
- public static final String MAX_ELEMENT_DEPTH =
- "org.apache.cxf.stax.maxElementDepth";
- public static final String MAX_ATTRIBUTE_COUNT =
- "org.apache.cxf.stax.maxAttributeCount";
- public static final String MAX_ATTRIBUTE_SIZE =
- "org.apache.cxf.stax.maxAttributeSize";
- public static final String MAX_TEXT_LENGTH =
- "org.apache.cxf.stax.maxTextLength";
- public static final String MIN_TEXT_SEGMENT =
- "org.apache.cxf.stax.minTextSegment";
- public static final String MAX_ELEMENT_COUNT =
- "org.apache.cxf.stax.maxElementCount";
- public static final String MAX_XML_CHARACTERS =
- "org.apache.cxf.stax.maxXMLCharacters";
-
- public static final String ALLOW_INSECURE_PARSER =
- "org.apache.cxf.stax.allowInsecureParser";
-
- private static final String INNER_ELEMENT_COUNT_SYSTEM_PROP =
- "org.apache.cxf.staxutils.innerElementCountThreshold";
- private static final String INNER_ELEMENT_LEVEL_SYSTEM_PROP =
- "org.apache.cxf.staxutils.innerElementLevelThreshold";
- private static final String AUTO_CLOSE_INPUT_SOURCE_PROP =
- "org.apache.cxf.staxutils.autoCloseInputSource";
-
- private static final Logger LOG = LogUtils.getL7dLogger(StaxUtils.class);
-
- private static final Queue<XMLInputFactory> NS_AWARE_INPUT_FACTORY_POOL;
- private static final XMLInputFactory SAFE_INPUT_FACTORY;
- private static final Queue<XMLOutputFactory> OUTPUT_FACTORY_POOL;
- private static final XMLOutputFactory SAFE_OUTPUT_FACTORY;
-
- private static final String XML_NS = "http://www.w3.org/2000/xmlns/";
- private static final String[] DEF_PREFIXES = new String[] {
- "ns1".intern(), "ns2".intern(), "ns3".intern(),
- "ns4".intern(), "ns5".intern(), "ns6".intern(),
- "ns7".intern(), "ns8".intern(), "ns9".intern()
- };
-
- private static final int MAX_ATTR_COUNT_VAL =
- getInteger(MAX_ATTRIBUTE_COUNT, 500);
- private static final int MAX_ATTR_SIZE_VAL =
- getInteger(MAX_ATTRIBUTE_SIZE, 64 * 1024); //64K per attribute, likely just "list" will hit
- private static final int MAX_TEXT_LENGTH_VAL =
- getInteger(MAX_TEXT_LENGTH, 128 * 1024 * 1024); //128M - more than this should DEFINITELY use MTOM
- private static final int MIN_TEXT_SEGMENT_VAL =
- getInteger(MIN_TEXT_SEGMENT, 64); // Same default as woodstox
- private static final long MAX_ELEMENT_COUNT_VAL =
- getLong(MAX_ELEMENT_COUNT, Long.MAX_VALUE);
- private static final long MAX_XML_CHARS_VAL =
- getLong(MAX_XML_CHARACTERS, Long.MAX_VALUE);
- private static final int PARSER_POOL_SIZE_VAL =
- getInteger("org.apache.cxf.staxutils.pool-size", 20);
- private static final boolean ALLOW_INSECURE_PARSER_VAL;
- private static final boolean AUTO_CLOSE_INPUT_SOURCE;
-
- // Here we check old names first and then new names for the threshold properties
- private static final int MAX_ELEMENT_DEPTH_VAL =
- getInteger(MAX_ELEMENT_DEPTH, getInteger(INNER_ELEMENT_LEVEL_SYSTEM_PROP, 100));
- private static final int MAX_CHILD_ELEMENTS_VAL =
- getInteger(MAX_CHILD_ELEMENTS, getInteger(INNER_ELEMENT_COUNT_SYSTEM_PROP, 50000));
-
- // Variables from Woodstox
- private static final String P_MAX_ATTRIBUTES_PER_ELEMENT = "com.ctc.wstx.maxAttributesPerElement";
- private static final String P_MAX_ATTRIBUTE_SIZE = "com.ctc.wstx.maxAttributeSize";
- private static final String P_MAX_TEXT_LENGTH = "com.ctc.wstx.maxTextLength";
- private static final String P_MAX_ELEMENT_COUNT = "com.ctc.wstx.maxElementCount";
- private static final String P_MAX_CHARACTERS = "com.ctc.wstx.maxCharacters";
- private static final String P_MAX_ELEMENT_DEPTH = "com.ctc.wstx.maxElementDepth";
- private static final String P_MAX_CHILDREN_PER_ELEMENT = "com.ctc.wstx.maxChildrenPerElement";
- private static final String P_MIN_TEXT_SEGMENT = "com.ctc.wstx.minTextSegment";
-
-
- static {
- NS_AWARE_INPUT_FACTORY_POOL = new ArrayBlockingQueue<>(PARSER_POOL_SIZE_VAL);
- OUTPUT_FACTORY_POOL = new ArrayBlockingQueue<>(PARSER_POOL_SIZE_VAL);
-
- String allowInsecureParser = SystemPropertyAction.getPropertyOrNull(ALLOW_INSECURE_PARSER);
- if (!StringUtils.isEmpty(allowInsecureParser)) {
- ALLOW_INSECURE_PARSER_VAL = "1".equals(allowInsecureParser) || Boolean.parseBoolean(allowInsecureParser);
- } else {
- ALLOW_INSECURE_PARSER_VAL = false;
- }
-
- String autoCloseInputSource = SystemPropertyAction.getPropertyOrNull(AUTO_CLOSE_INPUT_SOURCE_PROP);
- if (!StringUtils.isEmpty(autoCloseInputSource)) {
- AUTO_CLOSE_INPUT_SOURCE = "1".equals(autoCloseInputSource) || Boolean.parseBoolean(autoCloseInputSource);
- } else {
- AUTO_CLOSE_INPUT_SOURCE = false; /* set 'false' by default */
- }
-
- XMLInputFactory xif = null;
- try {
- xif = createXMLInputFactory(true);
- String xifClassName = xif.getClass().getName();
- if (!xifClassName.contains("ctc.wstx") && !xifClassName.contains("xml.xlxp")
- && !xifClassName.contains("xml.xlxp2") && !xifClassName.contains("bea.core")) {
- xif = null;
- }
- } catch (Throwable t) {
- //ignore, can always drop down to the pooled factories
- }
- SAFE_INPUT_FACTORY = xif;
-
- XMLOutputFactory xof = null;
- try {
- xof = XMLOutputFactory.newInstance();
- String xofClassName = xof.getClass().getName();
- if (!xofClassName.contains("ctc.wstx") && !xofClassName.contains("xml.xlxp")
- && !xofClassName.contains("xml.xlxp2") && !xofClassName.contains("bea.core")) {
- xof = null;
- }
- } catch (Throwable t) {
- //ignore, can always drop down to the pooled factories
- }
- SAFE_OUTPUT_FACTORY = xof;
-
- }
-
- private StaxUtils() {
- }
- private static int getInteger(String prop, int def) {
- try {
- String s = SystemPropertyAction.getPropertyOrNull(prop);
- if (StringUtils.isEmpty(s)) {
- return def;
- }
- int i = Integer.parseInt(s);
- if (i < 0) {
- i = def;
- }
- return i;
- } catch (Throwable t) {
- //ignore
- }
- return def;
- }
- private static long getLong(String prop, long def) {
- try {
- String s = SystemPropertyAction.getPropertyOrNull(prop);
- if (StringUtils.isEmpty(s)) {
- return def;
- }
- long i = Long.parseLong(s);
- if (i < 0) {
- i = def;
- }
- return i;
- } catch (Throwable t) {
- //ignore
- }
- return def;
- }
-
- /**
- * Return a cached, namespace-aware, factory.
- */
- private static XMLInputFactory getXMLInputFactory() {
- if (SAFE_INPUT_FACTORY != null) {
- return SAFE_INPUT_FACTORY;
- }
- XMLInputFactory f = NS_AWARE_INPUT_FACTORY_POOL.poll();
- if (f == null) {
- f = createXMLInputFactory(true);
- }
- return f;
- }
-
- private static void returnXMLInputFactory(XMLInputFactory factory) {
- if (SAFE_INPUT_FACTORY != factory) {
- NS_AWARE_INPUT_FACTORY_POOL.offer(factory);
- }
- }
-
- private static XMLOutputFactory getXMLOutputFactory() {
- if (SAFE_OUTPUT_FACTORY != null) {
- return SAFE_OUTPUT_FACTORY;
- }
- XMLOutputFactory f = OUTPUT_FACTORY_POOL.poll();
- if (f == null) {
- f = XMLOutputFactory.newInstance();
- }
- return f;
- }
-
- private static void returnXMLOutputFactory(XMLOutputFactory factory) {
- if (SAFE_OUTPUT_FACTORY != factory) {
- OUTPUT_FACTORY_POOL.offer(factory);
- }
- }
-
- /**
- * Return a new factory so that the caller can set sticky parameters.
- * @param nsAware
- * @throws XMLStreamException
- */
- public static XMLInputFactory createXMLInputFactory(boolean nsAware) {
- XMLInputFactory factory = null;
- try {
- factory = XMLInputFactory.newInstance();
- } catch (Throwable t) {
- if (LOG.isLoggable(Level.FINE)) {
- LOG.log(Level.FINE, "XMLInputFactory.newInstance() failed with: ", t);
- }
- }
- if (factory == null || !setRestrictionProperties(factory)) {
- try {
- factory = createWoodstoxFactory();
- } catch (Throwable t) {
- if (LOG.isLoggable(Level.FINE)) {
- LOG.log(Level.FINE, "Cannot create Woodstox XMLInputFactory: ", t);
- }
- }
-
- if (factory == null) {
- throw new RuntimeException("Failed to create XMLInputFactory.");
- }
-
- if (!setRestrictionProperties(factory)) {
- if (ALLOW_INSECURE_PARSER_VAL) {
- LOG.log(Level.WARNING, "INSECURE_PARSER_DETECTED", factory.getClass().getName());
- } else {
- throw new RuntimeException("Cannot create a secure XMLInputFactory, "
- + "you should either add woodstox or set " + ALLOW_INSECURE_PARSER
- + " system property to true if an unsafe mode is acceptable.");
- }
- }
- }
- setProperty(factory, XMLInputFactory.IS_NAMESPACE_AWARE, nsAware);
- setProperty(factory, XMLInputFactory.SUPPORT_DTD, Boolean.FALSE);
- setProperty(factory, XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, Boolean.FALSE);
- setProperty(factory, XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, Boolean.FALSE);
- factory.setXMLResolver(new XMLResolver() {
- public Object resolveEntity(String publicID, String systemID,
- String baseURI, String namespace)
- throws XMLStreamException {
- throw new XMLStreamException("Reading external entities is disabled");
- }
- });
-
- return factory;
- }
-
- private static XMLInputFactory createWoodstoxFactory() {
- return WoodstoxHelper.createInputFactory();
- }
-
- public static XMLEventFactory createWoodstoxEventFactory() {
- return WoodstoxHelper.createEventFactory();
- }
-
- private static boolean setRestrictionProperties(XMLInputFactory factory) {
- //For now, we can only support Woodstox 4.2.x and newer as none of the other
- //stax parsers support these settings
- final boolean wstxMaxs = setProperty(factory, P_MAX_ATTRIBUTES_PER_ELEMENT, MAX_ATTR_COUNT_VAL)
- && setProperty(factory, P_MAX_ATTRIBUTE_SIZE, MAX_ATTR_SIZE_VAL)
- && setProperty(factory, P_MAX_CHILDREN_PER_ELEMENT, MAX_CHILD_ELEMENTS_VAL)
- && setProperty(factory, P_MAX_ELEMENT_COUNT, MAX_ELEMENT_COUNT_VAL)
- && setProperty(factory, P_MAX_ELEMENT_DEPTH, MAX_ELEMENT_DEPTH_VAL)
- && setProperty(factory, P_MAX_CHARACTERS, MAX_XML_CHARS_VAL)
- && setProperty(factory, P_MAX_TEXT_LENGTH, MAX_TEXT_LENGTH_VAL);
- return wstxMaxs
- && setProperty(factory, P_MIN_TEXT_SEGMENT, MIN_TEXT_SEGMENT_VAL);
- }
-
- private static boolean setProperty(XMLInputFactory f, String p, Object o) {
- try {
- f.setProperty(p, o);
- return true;
- } catch (Throwable t) {
- //ignore
- }
- return false;
- }
-
-
-
- public static XMLStreamWriter createXMLStreamWriter(Writer out) {
- XMLOutputFactory factory = getXMLOutputFactory();
- try {
- return factory.createXMLStreamWriter(out);
- } catch (XMLStreamException e) {
- throw new RuntimeException("Cant' create XMLStreamWriter", e);
- } finally {
- returnXMLOutputFactory(factory);
- }
- }
-
- public static XMLStreamWriter createXMLStreamWriter(OutputStream out) {
- return createXMLStreamWriter(out, null);
- }
-
- public static XMLStreamWriter createXMLStreamWriter(OutputStream out, String encoding) {
- XMLOutputFactory factory = getXMLOutputFactory();
- try {
- return factory.createXMLStreamWriter(out, encoding != null ? encoding : StandardCharsets.UTF_8.name());
- } catch (XMLStreamException e) {
- throw new RuntimeException("Cant' create XMLStreamWriter", e);
- } finally {
- returnXMLOutputFactory(factory);
- }
- }
-
- public static XMLStreamWriter createXMLStreamWriter(Result r) {
- if (r instanceof DOMResult) {
- //use our own DOM writer to avoid issues with Sun's
- //version that doesn't support getNamespaceContext
- DOMResult dr = (DOMResult)r;
- Node nd = dr.getNode();
- if (nd instanceof Document) {
- return new W3CDOMStreamWriter((Document)nd);
- } else if (nd instanceof Element) {
- return new W3CDOMStreamWriter((Element)nd);
- } else if (nd instanceof DocumentFragment) {
- return new W3CDOMStreamWriter((DocumentFragment)nd);
- }
- }
- XMLOutputFactory factory = getXMLOutputFactory();
- try {
- return factory.createXMLStreamWriter(r);
- } catch (XMLStreamException e) {
- throw new RuntimeException("Cant' create XMLStreamWriter", e);
- } finally {
- returnXMLOutputFactory(factory);
- }
- }
-
- public static XMLStreamReader createFilteredReader(XMLStreamReader reader, StreamFilter filter) {
- XMLInputFactory factory = getXMLInputFactory();
- try {
- return factory.createFilteredReader(reader, filter);
- } catch (XMLStreamException e) {
- throw new RuntimeException("Cant' create XMLStreamReader", e);
- } finally {
- returnXMLInputFactory(factory);
- }
- }
-
-
- public static void nextEvent(XMLStreamReader dr) {
- try {
- dr.next();
- } catch (XMLStreamException e) {
- throw new RuntimeException("Couldn't parse stream.", e);
- }
- }
-
- public static boolean toNextText(DepthXMLStreamReader reader) {
- if (reader.getEventType() == XMLStreamConstants.CHARACTERS) {
- return true;
- }
-
- try {
- int depth = reader.getDepth();
- int event = reader.getEventType();
- while (reader.getDepth() >= depth && reader.hasNext()) {
- if (event == XMLStreamConstants.CHARACTERS && reader.getDepth() == depth + 1) {
- return true;
- }
- event = reader.next();
- }
- return false;
- } catch (XMLStreamException e) {
- throw new RuntimeException("Couldn't parse stream.", e);
- }
- }
- public static boolean toNextTag(XMLStreamReader reader) {
- try {
- // advance to first tag.
- int x = reader.getEventType();
- while (x != XMLStreamConstants.START_ELEMENT
- && x != XMLStreamConstants.END_ELEMENT
- && reader.hasNext()) {
- x = reader.next();
- }
- } catch (XMLStreamException e) {
- throw new RuntimeException("Couldn't parse stream.", e);
- }
- return true;
- }
-
- public static boolean toNextTag(DepthXMLStreamReader reader, QName endTag) {
- try {
- int depth = reader.getDepth();
- int event = reader.getEventType();
- while (reader.getDepth() >= depth && reader.hasNext()) {
- if (event == XMLStreamConstants.START_ELEMENT && reader.getName().equals(endTag)
- && reader.getDepth() == depth + 1) {
- return true;
- }
- event = reader.next();
- }
- return false;
- } catch (XMLStreamException e) {
- throw new RuntimeException("Couldn't parse stream.", e);
- }
- }
-
- public static void writeStartElement(XMLStreamWriter writer, String prefix, String name, String namespace)
- throws XMLStreamException {
- if (prefix == null) {
- prefix = "";
- }
-
- if (!namespace.isEmpty()) {
- writer.writeStartElement(prefix, name, namespace);
- if (!prefix.isEmpty()) {
- writer.writeNamespace(prefix, namespace);
- writer.setPrefix(prefix, namespace);
- } else {
- writer.writeDefaultNamespace(namespace);
- writer.setDefaultNamespace(namespace);
- }
- } else {
- writer.writeStartElement(name);
- writer.writeDefaultNamespace("");
- writer.setDefaultNamespace("");
- }
- }
-
- /**
- * Returns true if currently at the start of an element, otherwise move
- * forwards to the next element start and return true, otherwise false is
- * returned if the end of the stream is reached.
- */
- public static boolean skipToStartOfElement(XMLStreamReader in) throws XMLStreamException {
- for (int code = in.getEventType(); code != XMLStreamConstants.END_DOCUMENT; code = in.next()) {
- if (code == XMLStreamConstants.START_ELEMENT) {
- return true;
- }
- }
- return false;
- }
-
- public static boolean toNextElement(DepthXMLStreamReader dr) {
- if (dr.getEventType() == XMLStreamConstants.START_ELEMENT) {
- return true;
- }
- if (dr.getEventType() == XMLStreamConstants.END_ELEMENT) {
- return false;
- }
- try {
- int depth = dr.getDepth();
-
- for (int event = dr.getEventType(); dr.getDepth() >= depth && dr.hasNext(); event = dr.next()) {
- if (event == XMLStreamConstants.START_ELEMENT && dr.getDepth() == depth + 1) {
- return true;
- } else if (event == XMLStreamConstants.END_ELEMENT) {
- depth--;
- }
- }
-
- return false;
- } catch (XMLStreamException e) {
- throw new RuntimeException("Couldn't parse stream.", e);
- }
- }
-
- public static boolean skipToStartOfElement(DepthXMLStreamReader in) throws XMLStreamException {
- for (int code = in.getEventType(); code != XMLStreamConstants.END_DOCUMENT; code = in.next()) {
- if (code == XMLStreamConstants.START_ELEMENT) {
- return true;
- }
- }
- return false;
- }
- public static void copy(Source source, OutputStream os) throws XMLStreamException {
- XMLStreamWriter writer = createXMLStreamWriter(os);
- try {
- copy(source, writer);
- } finally {
- try {
- writer.flush();
- } catch (XMLStreamException ex) {
- //ignore
- }
- StaxUtils.close(writer);
- }
- }
- public static void copy(Source source, XMLStreamWriter writer) throws XMLStreamException {
- if (source instanceof StaxSource) {
- StaxSource ss = (StaxSource)source;
- if (ss.getXMLStreamReader() == null) {
- return;
- }
- } else if (source instanceof StAXSource) {
- StAXSource ss = (StAXSource)source;
- if (ss.getXMLStreamReader() == null) {
- return;
- }
- } else if (source instanceof SAXSource) {
- SAXSource ss = (SAXSource)source;
- InputSource src = ss.getInputSource();
- if (src == null || (src.getSystemId() == null && src.getPublicId() == null)) {
- if (ss.getXMLReader() != null) {
- //OK - reader is OK. We'll use that out
- StreamWriterContentHandler ch = new StreamWriterContentHandler(writer);
- XMLReader reader = ((SAXSource)source).getXMLReader();
- reader.setContentHandler(ch);
- try {
- try {
- reader.setFeature("http://xml.org/sax/features/namespaces", true);
- } catch (Throwable t) {
- //ignore
- }
- try {
- reader.setProperty("http://xml.org/sax/properties/lexical-handler", ch);
- } catch (Throwable t) {
- //ignore
- }
- reader.parse(((SAXSource)source).getInputSource());
- return;
- } catch (Exception e) {
- throw new XMLStreamException(e.getMessage(), e);
- }
- } else if (ss.getInputSource() == null) {
- //nothing to copy, just return
- return;
- }
- }
-
- } else if (source instanceof StreamSource) {
- StreamSource ss = (StreamSource)source;
- if (ss.getInputStream() == null
- && ss.getReader() == null
- && ss.getSystemId() == null) {
- //nothing to copy, just return
- return;
- }
- }
- XMLStreamReader reader = createXMLStreamReader(source);
- copy(reader, writer);
- reader.close();
- }
-
- public static Document copy(Document doc)
- throws XMLStreamException, ParserConfigurationException {
-
- XMLStreamReader reader = createXMLStreamReader(doc);
- W3CDOMStreamWriter writer = new W3CDOMStreamWriter();
- copy(reader, writer);
- Document d = writer.getDocument();
- try {
- d.setDocumentURI(doc.getDocumentURI());
- } catch (Exception ex) {
- //ignore - probably not DOM level 3
- }
- return d;
- }
- public static void copy(Document doc, XMLStreamWriter writer) throws XMLStreamException {
- XMLStreamReader reader = createXMLStreamReader(doc);
- copy(reader, writer);
- }
- public static void copy(Element node, XMLStreamWriter writer) throws XMLStreamException {
- XMLStreamReader reader = createXMLStreamReader(node);
- copy(reader, writer);
- }
-
- public static void copy(XMLStreamReader reader, OutputStream os)
- throws XMLStreamException {
- XMLStreamWriter xsw = StaxUtils.createXMLStreamWriter(os);
- StaxUtils.copy(reader, xsw);
- xsw.close();
- }
-
- public static void writeTo(Node node, OutputStream os) throws XMLStreamException {
- copy(new DOMSource(node), os);
- }
- public static void writeTo(Node node, OutputStream os, int indent) throws XMLStreamException {
- if (indent > 0) {
- XMLStreamWriter writer = new PrettyPrintXMLStreamWriter(createXMLStreamWriter(os), indent);
- try {
- copy(new DOMSource(node), writer);
- } finally {
- writer.close();
- }
- } else {
- copy(new DOMSource(node), os);
- }
- }
- public static void writeTo(Node node, Writer os) throws XMLStreamException {
- writeTo(node, os, 0);
- }
- public static void writeTo(Node node, Writer os, int indent) throws XMLStreamException {
- XMLStreamWriter writer = createXMLStreamWriter(os);
- if (indent > 0) {
- writer = new PrettyPrintXMLStreamWriter(writer, indent);
- }
- try {
- copy(new DOMSource(node), writer);
- } finally {
- writer.close();
- }
- }
-
-
- /**
- * Copies the reader to the writer. The start and end document methods must
- * be handled on the writer manually.
- *
- * @param reader
- * @param writer
- * @throws XMLStreamException
- */
- public static void copy(XMLStreamReader reader, XMLStreamWriter writer) throws XMLStreamException {
- copy(reader, writer, false, false);
- }
- public static void copy(XMLStreamReader reader, XMLStreamWriter writer, boolean fragment)
- throws XMLStreamException {
- copy(reader, writer, fragment, false);
- }
- public static void copy(XMLStreamReader reader,
- XMLStreamWriter writer,
- boolean fragment,
- boolean isThreshold) throws XMLStreamException {
- // number of elements read in
- int read = 0;
- int elementCount = 0;
- final Deque<Integer> countStack = new ArrayDeque<>();
- int event = reader.getEventType();
-
- while (reader.hasNext()) {
- switch (event) {
- case XMLStreamConstants.START_ELEMENT:
- read++;
- if (isThreshold) {
- elementCount++;
-
- if (MAX_ELEMENT_DEPTH_VAL != -1 && read >= MAX_ELEMENT_DEPTH_VAL) {
- throw new DepthExceededStaxException("reach the innerElementLevelThreshold:"
- + MAX_ELEMENT_DEPTH_VAL);
- }
- if (MAX_CHILD_ELEMENTS_VAL != -1 && elementCount >= MAX_CHILD_ELEMENTS_VAL) {
- throw new DepthExceededStaxException("reach the innerElementCountThreshold:"
- + MAX_CHILD_ELEMENTS_VAL);
- }
- countStack.push(elementCount);
- elementCount = 0;
- }
- writeStartElement(reader, writer);
- break;
- case XMLStreamConstants.END_ELEMENT:
- if (read > 0) {
- writer.writeEndElement();
- }
- read--;
- if (read < 0 && fragment) {
- return;
- }
- if (isThreshold && !countStack.isEmpty()) {
- elementCount = countStack.pop();
- }
- break;
- case XMLStreamConstants.CHARACTERS:
- case XMLStreamConstants.SPACE:
- String s = reader.getText();
- if (s != null) {
- writer.writeCharacters(s);
- }
- break;
- case XMLStreamConstants.COMMENT:
- writer.writeComment(reader.getText());
- break;
- case XMLStreamConstants.CDATA:
- writer.writeCData(reader.getText());
- break;
- case XMLStreamConstants.START_DOCUMENT:
- case XMLStreamConstants.END_DOCUMENT:
- case XMLStreamConstants.ATTRIBUTE:
- case XMLStreamConstants.NAMESPACE:
- break;
- default:
- break;
- }
- event = reader.next();
- }
- }
-
- private static void writeStartElement(XMLStreamReader reader, XMLStreamWriter writer)
- throws XMLStreamException {
- String uri = reader.getNamespaceURI();
- String prefix = reader.getPrefix();
- String local = reader.getLocalName();
-
- if (prefix == null) {
- prefix = "";
- }
-
- boolean writeElementNS = false;
-
- if (uri != null) {
- writeElementNS = true;
- Iterator<String> it = CastUtils.cast(writer.getNamespaceContext().getPrefixes(uri));
- if (!it.hasNext() && StringUtils.isEmpty(prefix) && StringUtils.isEmpty(uri)
- && StringUtils.isEmpty(writer.getNamespaceContext().getNamespaceURI(""))) {
- writeElementNS = false;
- }
- while (it.hasNext()) {
- String s = it.next();
- if (s == null) {
- s = "";
- }
- if (s.equals(prefix)) {
- writeElementNS = false;
- }
- }
- }
-
- // Write out the element name
- if (uri != null) {
- if (prefix.isEmpty() && StringUtils.isEmpty(uri)) {
- writer.writeStartElement(local);
- } else {
- writer.writeStartElement(prefix, local, uri);
- }
- } else {
- writer.writeStartElement(local);
- }
-
- // Write out the namespaces
- for (int i = 0; i < reader.getNamespaceCount(); i++) {
- String nsURI = reader.getNamespaceURI(i);
- String nsPrefix = reader.getNamespacePrefix(i);
- if (nsPrefix == null) {
- nsPrefix = "";
- }
- if (nsURI == null) {
- nsURI = "";
- }
- if (nsPrefix.isEmpty()) {
- writer.writeDefaultNamespace(nsURI);
- writer.setDefaultNamespace(nsURI);
- } else {
- writer.writeNamespace(nsPrefix, nsURI);
- writer.setPrefix(nsPrefix, nsURI);
- }
-
- if (nsURI.equals(uri) && nsPrefix.equals(prefix)) {
- writeElementNS = false;
- }
- }
-
- // Check if the namespace still needs to be written.
- // We need this check because namespace writing works
- // different on Woodstox and the RI.
- if (writeElementNS) {
- if (prefix.isEmpty()) {
- writer.writeDefaultNamespace(uri);
- writer.setDefaultNamespace(uri);
- } else {
- writer.writeNamespace(prefix, uri);
- writer.setPrefix(prefix, uri);
- }
- }
-
- // Write out attributes
- for (int i = 0; i < reader.getAttributeCount(); i++) {
- String ns = reader.getAttributeNamespace(i);
- String nsPrefix = reader.getAttributePrefix(i);
- if (ns == null || ns.isEmpty()) {
- writer.writeAttribute(reader.getAttributeLocalName(i), reader.getAttributeValue(i));
- } else if (nsPrefix == null || nsPrefix.isEmpty()) {
- writer.writeAttribute(reader.getAttributeNamespace(i), reader.getAttributeLocalName(i),
- reader.getAttributeValue(i));
- } else {
- Iterator<String> it = CastUtils.cast(writer.getNamespaceContext().getPrefixes(ns));
- boolean writeNs = true;
- while (it != null && it.hasNext()) {
- String s = it.next();
- if (s == null) {
- s = "";
- }
- if (s.equals(nsPrefix)) {
- writeNs = false;
- }
- }
- if (writeNs) {
- writer.writeNamespace(nsPrefix, ns);
- writer.setPrefix(nsPrefix, ns);
- }
- writer.writeAttribute(reader.getAttributePrefix(i), reader.getAttributeNamespace(i), reader
- .getAttributeLocalName(i), reader.getAttributeValue(i));
- }
-
- }
- }
-
- public static void writeDocument(Document d, XMLStreamWriter writer, boolean repairing)
- throws XMLStreamException {
- writeDocument(d, writer, true, repairing);
- }
-
- public static void writeDocument(Document d, XMLStreamWriter writer, boolean writeProlog,
- boolean repairing) throws XMLStreamException {
- if (writeProlog) {
- writer.writeStartDocument();
- }
-
- Node node = d.getFirstChild();
- while (node != null) {
- if (writeProlog || node.getNodeType() == Node.ELEMENT_NODE) {
- writeNode(node, writer, repairing);
- }
- node = node.getNextSibling();
- }
-
- if (writeProlog) {
- writer.writeEndDocument();
- }
- }
-
- /**
- * Writes an Element to an XMLStreamWriter. The writer must already have
- * started the document (via writeStartDocument()). Also, this probably
- * won't work with just a fragment of a document. The Element should be the
- * root element of the document.
- *
- * @param e
- * @param writer
- * @throws XMLStreamException
- */
- public static void writeElement(Element e, XMLStreamWriter writer, boolean repairing)
- throws XMLStreamException {
- writeElement(e, writer, repairing, true);
- }
-
- /**
- * Writes an Element to an XMLStreamWriter. The writer must already have
- * started the document (via writeStartDocument()). Also, this probably
- * won't work with just a fragment of a document. The Element should be the
- * root element of the document.
- *
- * @param e
- * @param writer
- * @param endElement true if the element should be ended
- * @throws XMLStreamException
- */
- public static void writeElement(Element e,
- XMLStreamWriter writer,
- boolean repairing,
- boolean endElement)
- throws XMLStreamException {
- String prefix = e.getPrefix();
- String ns = e.getNamespaceURI();
- String localName = e.getLocalName();
-
- if (prefix == null) {
- prefix = "";
- }
- if (localName == null) {
- localName = e.getNodeName();
-
- if (localName == null) {
- throw new IllegalStateException("Element's local name cannot be null!");
- }
- }
-
- String decUri = writer.getNamespaceContext().getNamespaceURI(prefix);
- boolean declareNamespace = decUri == null || !decUri.equals(ns);
-
- if (ns == null || ns.isEmpty()) {
- writer.writeStartElement(localName);
- if (StringUtils.isEmpty(decUri)) {
- declareNamespace = false;
- }
- } else {
- writer.writeStartElement(prefix, localName, ns);
- }
-
- for (Node attr : sortElementAttributes(e.getAttributes())) {
-
- String name = attr.getLocalName();
- String attrPrefix = attr.getPrefix();
- if (attrPrefix == null) {
- attrPrefix = "";
- }
- if (name == null) {
- name = attr.getNodeName();
- }
-
- if ("xmlns".equals(attrPrefix)) {
- writer.writeNamespace(name, attr.getNodeValue());
- writer.setPrefix(name, attr.getNodeValue());
- if (name.equals(prefix) && attr.getNodeValue().equals(ns)) {
- declareNamespace = false;
- }
- } else {
- if ("xmlns".equals(name) && "".equals(attrPrefix)) {
- writer.writeDefaultNamespace(attr.getNodeValue());
- writer.setDefaultNamespace(attr.getNodeValue());
- if (attr.getNodeValue().equals(ns)) {
- declareNamespace = false;
- } else if (StringUtils.isEmpty(attr.getNodeValue())
- && StringUtils.isEmpty(ns)) {
- declareNamespace = false;
- }
- } else {
- String attns = attr.getNamespaceURI();
- String value = attr.getNodeValue();
- if (attns == null || attns.isEmpty()) {
- writer.writeAttribute(name, value);
- } else if (attrPrefix.isEmpty()) {
- writer.writeAttribute(attns, name, value);
- } else {
- if (repairing && writer.getNamespaceContext().getNamespaceURI(attrPrefix) == null) {
- writer.writeNamespace(attrPrefix, attns);
- }
- writer.writeAttribute(attrPrefix, attns, name, value);
- }
- }
- }
- }
-
- if (declareNamespace && repairing) {
- if (ns == null) {
- writer.writeNamespace(prefix, "");
- writer.setPrefix(prefix, "");
- } else {
- writer.writeNamespace(prefix, ns);
- writer.setPrefix(prefix, ns);
- }
- }
-
- Node nd = e.getFirstChild();
- while (nd != null) {
- writeNode(nd, writer, repairing);
- nd = nd.getNextSibling();
- }
-
- if (endElement) {
- writer.writeEndElement();
- }
- }
-
- private static List<Node> sortElementAttributes(NamedNodeMap attrs) {
- if (attrs.getLength() == 0) {
- return Collections.<Node> emptyList();
- }
- List<Node> sortedAttrs = new ArrayList<>(attrs.getLength());
- for (int i = 0; i < attrs.getLength(); i++) {
- Node attr = attrs.item(i);
- String name = attr.getLocalName();
- if (name == null) {
- name = attr.getNodeName();
- }
- if ("xmlns".equals(attr.getPrefix()) || "xmlns".equals(name)) {
- sortedAttrs.add(0, attr);
- } else {
- sortedAttrs.add(attr);
- }
- }
-
- return sortedAttrs;
- }
-
- public static void writeNode(Node n, XMLStreamWriter writer, boolean repairing)
- throws XMLStreamException {
-
- switch (n.getNodeType()) {
- case Node.ELEMENT_NODE:
- writeElement((Element)n, writer, repairing);
- break;
- case Node.TEXT_NODE:
- writer.writeCharacters(((Text)n).getNodeValue());
- break;
- case Node.COMMENT_NODE:
- writer.writeComment(((Comment)n).getData());
- break;
- case Node.CDATA_SECTION_NODE:
- writer.writeCData(((CDATASection)n).getData());
- break;
- case Node.ENTITY_REFERENCE_NODE:
- writer.writeEntityRef(((EntityReference)n).getNodeValue());
- break;
- case Node.PROCESSING_INSTRUCTION_NODE:
- ProcessingInstruction pi = (ProcessingInstruction)n;
- writer.writeProcessingInstruction(pi.getTarget(), pi.getData());
- break;
- case Node.DOCUMENT_NODE:
- writeDocument((Document)n, writer, repairing);
- break;
- case Node.DOCUMENT_FRAGMENT_NODE: {
- DocumentFragment frag = (DocumentFragment)n;
- Node child = frag.getFirstChild();
- while (child != null) {
- writeNode(child, writer, repairing);
- child = child.getNextSibling();
- }
- break;
- }
- case Node.DOCUMENT_TYPE_NODE:
- try {
- if (((DocumentType)n).getTextContent() != null) {
- writer.writeDTD(((DocumentType)n).getTextContent());
- }
- } catch (UnsupportedOperationException ex) {
- //can we ignore? DOM writers really don't allow this
- //as there isn't a way to write a DTD in dom
- }
- break;
- default:
- throw new IllegalStateException("Found type: " + n.getClass().getName());
- }
- }
-
- public static Document read(Source s) throws XMLStreamException {
- XMLStreamReader reader = createXMLStreamReader(s);
- try {
- return read(reader);
- } finally {
- try {
- reader.close();
- } catch (Exception ex) {
- //ignore
- }
- }
- }
- public static Document read(InputStream s) throws XMLStreamException {
- XMLStreamReader reader = createXMLStreamReader(s);
- try {
- return read(reader);
- } finally {
- try {
- reader.close();
- } catch (Exception ex) {
- //ignore
- }
- }
- }
- public static Document read(Reader s) throws XMLStreamException {
- XMLStreamReader reader = createXMLStreamReader(s);
- try {
- return read(reader);
- } finally {
- try {
- reader.close();
- } catch (Exception ex) {
- //ignore
- }
- }
- }
- public static Document read(File is) throws XMLStreamException, IOException {
- try (InputStream fin = Files.newInputStream(is.toPath())) {
- return read(fin);
- }
- }
- public static Document read(InputSource s) throws XMLStreamException {
- XMLStreamReader reader = null;
- try {
- reader = createXMLStreamReader(s);
- return read(reader);
- } finally {
- StaxUtils.close(reader);
- }
- }
- public static Document read(XMLStreamReader reader) throws XMLStreamException {
- return read(reader, false);
- }
- public static Document read(XMLStreamReader reader, boolean recordLoc) throws XMLStreamException {
- Document doc = DOMUtils.createDocument();
- if (reader.getLocation().getSystemId() != null) {
- try {
- doc.setDocumentURI(reader.getLocation().getSystemId());
- } catch (Exception e) {
- //ignore - probably not DOM level 3
- }
- }
- readDocElements(doc, doc, reader, true, recordLoc);
- return doc;
- }
-
- public static Document read(DocumentBuilder builder, XMLStreamReader reader, boolean repairing)
- throws XMLStreamException {
-
- Document doc = builder == null ? DOMUtils.createDocument() : builder.newDocument();
- if (reader.getLocation().getSystemId() != null) {
- try {
- doc.setDocumentURI(reader.getLocation().getSystemId());
- } catch (Exception e) {
- //ignore - probably not DOM level 3
- }
- }
- readDocElements(doc, reader, repairing);
- return doc;
- }
-
- /**
- * @param parent
- */
- private static Document getDocument(Node parent) {
- return (parent instanceof Document) ? (Document)parent : parent.getOwnerDocument();
- }
-
- private static boolean isDeclared(Element e, String namespaceURI, String prefix) {
- while (e != null) {
- Attr att;
- if (prefix != null && !prefix.isEmpty()) {
- att = e.getAttributeNodeNS(XML_NS, prefix);
- } else {
- att = e.getAttributeNode("xmlns");
- }
-
- if (att != null && att.getNodeValue().equals(namespaceURI)) {
- return true;
- }
-
- if (e.getParentNode() instanceof Element) {
- e = (Element)e.getParentNode();
- } else if (StringUtils.isEmpty(prefix) && StringUtils.isEmpty(namespaceURI)) {
- //A document that probably doesn't have any namespace qualifies elements
- return true;
- } else {
- break;
- }
- }
- return false;
- }
-
- public static void readDocElements(Node parent, XMLStreamReader reader, boolean repairing)
- throws XMLStreamException {
- Document doc = getDocument(parent);
- readDocElements(doc, parent, reader, repairing, false);
- }
-
- public static void readDocElements(Node parent, XMLStreamReader reader, boolean repairing,
- boolean isThreshold)
- throws XMLStreamException {
- Document doc = getDocument(parent);
- readDocElements(doc, parent, reader, repairing, false, isThreshold);
- }
-
- /**
- * @param parent
- * @param reader
- * @throws XMLStreamException
- */
- public static void readDocElements(Document doc, Node parent,
- XMLStreamReader reader, boolean repairing, boolean recordLoc)
- throws XMLStreamException {
- readDocElements(doc, parent, reader, repairing, recordLoc, false);
- }
-
- /**
- * @param parent
- * @param reader
- * @throws XMLStreamException
- */
- public static void readDocElements(Document doc, Node parent,
- XMLStreamReader reader, boolean repairing, boolean recordLoc,
- boolean isThreshold)
- throws XMLStreamException {
- final Deque<Node> stack = new ArrayDeque<>();
- int event = reader.getEventType();
- int elementCount = 0;
- while (reader.hasNext()) {
- switch (event) {
- case XMLStreamConstants.START_ELEMENT: {
- elementCount++;
- Element e;
- if (!StringUtils.isEmpty(reader.getPrefix())) {
- e = doc.createElementNS(reader.getNamespaceURI(),
- reader.getPrefix() + ':' + reader.getLocalName());
- } else {
- e = doc.createElementNS(reader.getNamespaceURI(), reader.getLocalName());
- }
- e = (Element)parent.appendChild(e);
- recordLoc = addLocation(doc, e, reader, recordLoc);
-
- for (int ns = 0; ns < reader.getNamespaceCount(); ns++) {
- String uri = reader.getNamespaceURI(ns);
- String prefix = reader.getNamespacePrefix(ns);
-
- declare(e, uri, prefix);
- }
-
- for (int att = 0; att < reader.getAttributeCount(); att++) {
- String name = reader.getAttributeLocalName(att);
- String prefix = reader.getAttributePrefix(att);
- if (prefix != null && !prefix.isEmpty()) {
- name = prefix + ':' + name;
- }
-
- Attr attr = doc.createAttributeNS(reader.getAttributeNamespace(att), name);
- attr.setValue(reader.getAttributeValue(att));
- e.setAttributeNode(attr);
- }
-
- if (repairing && !isDeclared(e, reader.getNamespaceURI(), reader.getPrefix())) {
- declare(e, reader.getNamespaceURI(), reader.getPrefix());
- }
- stack.push(parent);
- if (isThreshold && MAX_ELEMENT_DEPTH_VAL != -1
- && stack.size() >= MAX_ELEMENT_DEPTH_VAL) {
- throw new DepthExceededStaxException("reach the innerElementLevelThreshold:"
- + MAX_ELEMENT_DEPTH_VAL);
- }
- if (isThreshold && MAX_CHILD_ELEMENTS_VAL != -1
- && elementCount >= MAX_CHILD_ELEMENTS_VAL) {
- throw new DepthExceededStaxException("reach the innerElementCountThreshold:"
- + MAX_CHILD_ELEMENTS_VAL);
- }
- parent = e;
- break;
- }
- case XMLStreamConstants.END_ELEMENT:
- if (stack.isEmpty()) {
- return;
- }
- parent = stack.pop();
- if (parent instanceof Document || parent instanceof DocumentFragment) {
- return;
- }
- break;
- case XMLStreamConstants.NAMESPACE:
- break;
- case XMLStreamConstants.ATTRIBUTE:
- break;
- case XMLStreamConstants.CHARACTERS:
- if (parent != null) {
- recordLoc = addLocation(doc,
- parent.appendChild(doc.createTextNode(reader.getText())),
- reader, recordLoc);
- }
- break;
- case XMLStreamConstants.COMMENT:
- if (parent != null) {
- parent.appendChild(doc.createComment(reader.getText()));
- }
- break;
- case XMLStreamConstants.CDATA:
- recordLoc = addLocation(doc,
- parent.appendChild(doc.createCDATASection(reader.getText())),
- reader, recordLoc);
- break;
- case XMLStreamConstants.PROCESSING_INSTRUCTION:
- parent.appendChild(doc.createProcessingInstruction(reader.getPITarget(), reader.getPIData()));
- break;
- case XMLStreamConstants.ENTITY_REFERENCE:
- parent.appendChild(doc.createProcessingInstruction(reader.getPITarget(), reader.getPIData()));
- break;
- default:
- break;
- }
-
- if (reader.hasNext()) {
- event = reader.next();
- }
- }
- }
-
- public static class StreamToDOMContext {
- private final Deque<Node> stack = new ArrayDeque<>();
- private int elementCount;
- private boolean repairing;
- private boolean recordLoc;
- private boolean threshold;
-
- public StreamToDOMContext(boolean repairing, boolean recordLoc, boolean threshold) {
- this.repairing = repairing;
- this.recordLoc = recordLoc;
- this.threshold = threshold;
- }
-
- public void setRecordLoc(boolean recordLoc) {
- this.recordLoc = recordLoc;
- }
-
- public boolean isRecordLoc() {
- return this.recordLoc;
- }
-
- public boolean isRepairing() {
- return this.repairing;
- }
-
- public boolean isThreshold() {
- return this.threshold;
- }
-
- public int incrementCount() {
- return ++elementCount;
- }
-
- public int decreaseCount() {
- return --elementCount;
- }
-
- public int getCount() {
- return elementCount;
- }
-
- public void pushToStack(Node node) {
- stack.push(node);
- }
-
- public Node popFromStack() {
- return stack.pop();
- }
-
- public int getStackSize() {
- return stack.size();
- }
-
- public boolean isStackEmpty() {
- return stack.isEmpty();
- }
- }
-
- public static void readDocElements(Document doc, Node parent, XMLStreamReader reader, StreamToDOMContext context)
- throws XMLStreamException {
- int event = reader.getEventType();
- while (reader.hasNext()) {
- switch (event) {
- case XMLStreamConstants.START_ELEMENT: {
- context.incrementCount();
- Element e;
- if (!StringUtils.isEmpty(reader.getPrefix())) {
- e = doc.createElementNS(reader.getNamespaceURI(),
- reader.getPrefix() + ":" + reader.getLocalName());
- } else {
- e = doc.createElementNS(reader.getNamespaceURI(), reader.getLocalName());
- }
- e = (Element)parent.appendChild(e);
- if (context.isRecordLoc()) {
- context.setRecordLoc(addLocation(doc, e, reader.getLocation(), context.isRecordLoc()));
- }
-
- for (int ns = 0; ns < reader.getNamespaceCount(); ns++) {
- String uri = reader.getNamespaceURI(ns);
- String prefix = reader.getNamespacePrefix(ns);
-
- declare(e, uri, prefix);
- }
-
- for (int att = 0; att < reader.getAttributeCount(); att++) {
- String name = reader.getAttributeLocalName(att);
- String prefix = reader.getAttributePrefix(att);
- if (prefix != null && prefix.length() > 0) {
- name = prefix + ":" + name;
- }
-
- Attr attr = doc.createAttributeNS(reader.getAttributeNamespace(att), name);
- attr.setValue(reader.getAttributeValue(att));
- e.setAttributeNode(attr);
- }
-
- if (context.isRepairing() && !isDeclared(e, reader.getNamespaceURI(), reader.getPrefix())) {
- declare(e, reader.getNamespaceURI(), reader.getPrefix());
- }
- context.pushToStack(parent);
- if (context.isThreshold() && MAX_ELEMENT_DEPTH_VAL != -1
- && context.getStackSize() >= MAX_ELEMENT_DEPTH_VAL) {
- throw new DepthExceededStaxException("reach the innerElementLevelThreshold:"
- + MAX_ELEMENT_DEPTH_VAL);
- }
- if (context.isThreshold() && MAX_CHILD_ELEMENTS_VAL != -1
- && context.getCount() >= MAX_CHILD_ELEMENTS_VAL) {
- throw new DepthExceededStaxException("reach the innerElementCountThreshold:"
- + MAX_CHILD_ELEMENTS_VAL);
- }
- parent = e;
- break;
- }
- case XMLStreamConstants.END_ELEMENT:
- if (context.isStackEmpty()) {
- return;
- }
- parent = context.popFromStack();
- if (parent instanceof Document || parent instanceof DocumentFragment) {
- return;
- }
- break;
- case XMLStreamConstants.NAMESPACE:
- break;
- case XMLStreamConstants.ATTRIBUTE:
- break;
- case XMLStreamConstants.CHARACTERS:
- if (parent != null) {
- context.setRecordLoc(addLocation(doc,
- parent.appendChild(doc.createTextNode(reader.getText())),
- reader.getLocation(), context.isRecordLoc()));
- }
- break;
- case XMLStreamConstants.COMMENT:
- if (parent != null) {
- parent.appendChild(doc.createComment(reader.getText()));
- }
- break;
- case XMLStreamConstants.CDATA:
- context.setRecordLoc(addLocation(doc,
- parent.appendChild(doc.createCDATASection(reader.getText())),
- reader.getLocation(), context.isRecordLoc()));
- break;
- case XMLStreamConstants.PROCESSING_INSTRUCTION:
- parent.appendChild(doc.createProcessingInstruction(reader.getPITarget(), reader.getPIData()));
- break;
- case XMLStreamConstants.ENTITY_REFERENCE:
- parent.appendChild(doc.createProcessingInstruction(reader.getPITarget(), reader.getPIData()));
- break;
- default:
- break;
- }
-
- if (reader.hasNext()) {
- event = reader.next();
- }
- }
- }
-
- public static Node readDocElement(Document doc, Node parent, XMLEvent ev, StreamToDOMContext context)
- throws XMLStreamException {
- switch (ev.getEventType()) {
- case XMLStreamConstants.START_ELEMENT: {
- context.incrementCount();
- Element e;
- StartElement startElem = ev.asStartElement();
- QName name = startElem.getName();
- if (!StringUtils.isEmpty(name.getPrefix())) {
- e = doc.createElementNS(name.getNamespaceURI(),
- name.getPrefix() + ":" + name.getLocalPart());
- } else {
- e = doc.createElementNS(name.getNamespaceURI(), name.getLocalPart());
- }
- e = (Element)parent.appendChild(e);
- if (context.isRecordLoc()) {
- context.setRecordLoc(addLocation(doc, e, startElem.getLocation(), context.isRecordLoc()));
- }
-
- if (context.isRepairing() && !isDeclared(e, name.getNamespaceURI(), name.getPrefix())) {
- declare(e, name.getNamespaceURI(), name.getPrefix());
- }
- context.pushToStack(parent);
- if (context.isThreshold() && MAX_ELEMENT_DEPTH_VAL != -1
- && context.getStackSize() >= MAX_ELEMENT_DEPTH_VAL) {
- throw new DepthExceededStaxException("reach the innerElementLevelThreshold:"
- + MAX_ELEMENT_DEPTH_VAL);
- }
- if (context.isThreshold() && MAX_CHILD_ELEMENTS_VAL != -1
- && context.getCount() >= MAX_CHILD_ELEMENTS_VAL) {
- throw new DepthExceededStaxException("reach the innerElementCountThreshold:"
- + MAX_CHILD_ELEMENTS_VAL);
- }
- parent = e;
- break;
- }
- case XMLStreamConstants.END_ELEMENT:
- if (context.isStackEmpty()) {
- return parent;
- }
- parent = context.popFromStack();
- if (parent instanceof Document || parent instanceof DocumentFragment) {
- return parent;
- }
- break;
- case XMLStreamConstants.NAMESPACE:
- Namespace ns = (Namespace)ev;
- declare((Element)parent, ns.getNamespaceURI(), ns.getPrefix());
- break;
- case XMLStreamConstants.ATTRIBUTE:
- Attribute at = (Attribute)ev;
- QName qname = at.getName();
- String attName = qname.getLocalPart();
- String attPrefix = qname.getPrefix();
- if (attPrefix != null && attPrefix.length() > 0) {
- attName = attPrefix + ":" + attName;
- }
- Attr attr = doc.createAttributeNS(qname.getNamespaceURI(), attName);
- attr.setValue(at.getValue());
- ((Element)parent).setAttributeNode(attr);
- break;
- case XMLStreamConstants.CHARACTERS:
- Characters characters = ev.asCharacters();
- context.setRecordLoc(addLocation(doc,
- parent.appendChild(doc.createTextNode(characters.getData())),
- characters.getLocation(), context.isRecordLoc()));
- break;
- case XMLStreamConstants.COMMENT:
- parent.appendChild(doc.createComment(((javax.xml.stream.events.Comment)ev).getText()));
- break;
- case XMLStreamConstants.CDATA:
- Characters cdata = ev.asCharacters();
- context.setRecordLoc(addLocation(doc,
- parent.appendChild(doc.createCDATASection(cdata.getData())),
- cdata.getLocation(), context.isRecordLoc()));
- break;
- case XMLStreamConstants.PROCESSING_INSTRUCTION:
- parent.appendChild(doc.createProcessingInstruction(((ProcessingInstruction)ev).getTarget(),
- ((ProcessingInstruction)ev).getData()));
- break;
- case XMLStreamConstants.ENTITY_REFERENCE:
- javax.xml.stream.events.EntityReference er = (javax.xml.stream.events.EntityReference)ev;
- parent.appendChild(doc.createEntityReference(er.getName()));
- break;
- default:
- break;
- }
- return parent;
- }
-
- private static boolean addLocation(Document doc, Node node,
- Location loc,
- boolean recordLoc) {
- if (recordLoc && loc != null && (loc.getColumnNumber() != 0 || loc.getLineNumber() != 0)) {
- try {
- final int charOffset = loc.getCharacterOffset();
- final int colNum = loc.getColumnNumber();
- final int linNum = loc.getLineNumber();
- final String pubId = loc.getPublicId() == null ? doc.getDocumentURI() : loc.getPublicId();
- final String sysId = loc.getSystemId() == null ? doc.getDocumentURI() : loc.getSystemId();
- Location loc2 = new Location() {
- public int getCharacterOffset() {
- return charOffset;
- }
- public int getColumnNumber() {
- return colNum;
- }
- public int getLineNumber() {
- return linNum;
- }
- public String getPublicId() {
- return pubId;
- }
- public String getSystemId() {
- return sysId;
- }
- };
- node.setUserData("location", loc2, LocationUserDataHandler.INSTANCE);
- } catch (Throwable ex) {
- //possibly not DOM level 3, won't be able to record this then
- return false;
- }
- }
- return recordLoc;
- }
-
- private static boolean addLocation(Document doc, Node node,
- XMLStreamReader reader,
- boolean recordLoc) {
- return addLocation(doc, node, reader.getLocation(), recordLoc);
- }
-
- private static class LocationUserDataHandler implements UserDataHandler {
- public static final LocationUserDataHandler INSTANCE = new LocationUserDataHandler();
-
- public void handle(short operation, String key, Object data, Node src, Node dst) {
- if (operation == NODE_CLONED) {
- dst.setUserData(key, data, this);
- }
- }
- }
-
- private static void declare(Element node, String uri, String prefix) {
- String qualname;
- if (prefix != null && prefix.length() > 0) {
- qualname = "xmlns:" + prefix;
- } else {
- qualname = "xmlns";
- }
- Attr attr = node.getOwnerDocument().createAttributeNS(XML_NS, qualname);
- attr.setValue(uri);
- node.setAttributeNodeNS(attr);
- }
- public static XMLStreamReader createXMLStreamReader(InputSource src) {
- String sysId = src.getSystemId() == null ? null : src.getSystemId();
- String pubId = src.getPublicId() == null ? null : src.getPublicId();
- if (src.getByteStream() != null) {
- final InputStream is = src.getByteStream();
-
- if (src.getEncoding() == null) {
- final StreamSource ss = new StreamSource(is, sysId);
- ss.setPublicId(pubId);
-
- final XMLStreamReader xmlStreamReader = createXMLStreamReader(ss);
- if (AUTO_CLOSE_INPUT_SOURCE) {
- return new AutoCloseableXMLStreamReader(xmlStreamReader, is);
- } else {
- return xmlStreamReader;
- }
- }
-
- return new AutoCloseableXMLStreamReader(createXMLStreamReader(is, src.getEncoding()), is);
- } else if (src.getCharacterStream() != null) {
- final Reader reader = src.getCharacterStream();
- final StreamSource ss = new StreamSource(reader, sysId);
- ss.setPublicId(pubId);
- final XMLStreamReader xmlStreamReader = createXMLStreamReader(ss);
- if (AUTO_CLOSE_INPUT_SOURCE) {
- return new AutoCloseableXMLStreamReader(xmlStreamReader, reader);
- } else {
- return xmlStreamReader;
- }
- } else {
- try {
- final URL url = new URL(sysId);
- final InputStream is = url.openStream();
- final StreamSource ss = new StreamSource(is, sysId);
- ss.setPublicId(pubId);
- return new AutoCloseableXMLStreamReader(createXMLStreamReader(ss), is);
- } catch (Exception ex) {
- //ignore - not a valid URL
- }
- }
- throw new IllegalArgumentException("InputSource must have a ByteStream or CharacterStream");
- }
- /**
- * @param in
- * @param encoding
- */
- public static XMLStreamReader createXMLStreamReader(InputStream in, String encoding) {
- XMLInputFactory factory = getXMLInputFactory();
- try {
- return factory.createXMLStreamReader(in, encoding != null ? encoding : StandardCharsets.UTF_8.name());
- } catch (XMLStreamException e) {
- throw new RuntimeException("Couldn't parse stream.", e);
- } finally {
- returnXMLInputFactory(factory);
- }
- }
-
- /**
- * @param in
- */
- public static XMLStreamReader createXMLStreamReader(InputStream in) {
- XMLInputFactory factory = getXMLInputFactory();
- try {
- return factory.createXMLStreamReader(in);
- } catch (XMLStreamException e) {
- throw new RuntimeException("Couldn't parse stream.", e);
- } finally {
- returnXMLInputFactory(factory);
- }
- }
- public static XMLStreamReader createXMLStreamReader(String systemId, InputStream in) {
- XMLInputFactory factory = getXMLInputFactory();
- try {
- return factory.createXMLStreamReader(systemId, in);
- } catch (XMLStreamException e) {
- throw new RuntimeException("Couldn't parse stream.", e);
- } finally {
- returnXMLInputFactory(factory);
- }
- }
-
- public static XMLStreamReader createXMLStreamReader(Element el) {
- return new W3CDOMStreamReader(el);
- }
- public static XMLStreamReader createXMLStreamReader(Document doc) {
- return new W3CDOMStreamReader(doc.getDocumentElement());
- }
- public static XMLStreamReader createXMLStreamReader(Element el, String sysId) {
- return new W3CDOMStreamReader(el, sysId);
- }
- public static XMLStreamReader createXMLStreamReader(Document doc, String sysId) {
- return new W3CDOMStreamReader(doc.getDocumentElement(), sysId);
- }
-
- public static XMLStreamReader createXMLStreamReader(Source source) {
- try {
- if (source instanceof DOMSource) {
- DOMSource ds = (DOMSource)source;
- Node nd = ds.getNode();
- Element el = null;
- if (nd instanceof Document) {
- el = ((Document)nd).getDocumentElement();
- } else if (nd instanceof Element) {
- el = (Element)nd;
- }
-
- if (null != el) {
- return new W3CDOMStreamReader(el, source.getSystemId());
- }
- } else if (source instanceof StAXSource) {
- return ((StAXSource)source).getXMLStreamReader();
- } else if (source instanceof StaxSource) {
- return ((StaxSource)source).getXMLStreamReader();
- } else if (source instanceof SAXSource) {
- SAXSource ss = (SAXSource)source;
- if (ss.getXMLReader() == null) {
- return createXMLStreamReader(((SAXSource)source).getInputSource());
- }
- }
-
- XMLInputFactory factory = getXMLInputFactory();
- try {
- XMLStreamReader reader = null;
-
- try {
- reader = factory.createXMLStreamReader(source);
- } catch (UnsupportedOperationException e) {
- //ignore
- }
- if (reader == null && source instanceof StreamSource) {
- //createXMLStreamReader from Source is optional, we'll try and map it
- StreamSource ss = (StreamSource)source;
- if (ss.getInputStream() != null) {
- reader = factory.createXMLStreamReader(ss.getSystemId(),
- ss.getInputStream());
- } else {
- reader = factory.createXMLStreamReader(ss.getSystemId(),
- ss.getReader());
- }
- }
- return reader;
- } finally {
- returnXMLInputFactory(factory);
- }
- } catch (XMLStreamException e) {
- throw new RuntimeException("Couldn't parse stream.", e);
- }
- }
-
- /**
- * @param reader
- */
- public static XMLStreamReader createXMLStreamReader(Reader reader) {
- XMLInputFactory factory = getXMLInputFactory();
- try {
- return factory.createXMLStreamReader(reader);
- } catch (XMLStreamException e) {
- throw new RuntimeException("Couldn't parse stream.", e);
- } finally {
- returnXMLInputFactory(factory);
- }
- }
-
- /**
- * Reads a QName from the element text. Reader must be positioned at the
- * start tag.
- */
- public static QName readQName(XMLStreamReader reader) throws XMLStreamException {
- String value = reader.getElementText();
- if (value == null) {
- return null;
- }
- value = value.trim();
-
- int index = value.indexOf(':');
-
- if (index == -1) {
- return new QName(value);
- }
-
- String prefix = value.substring(0, index);
- String localName = value.substring(index + 1);
- String ns = reader.getNamespaceURI(prefix);
-
- if (!StringUtils.isEmpty(prefix) && ns == null) {
- throw new RuntimeException("Invalid QName in mapping: " + value);
- }
-
- if (ns == null) {
- return new QName(localName);
- }
-
- return new QName(ns, localName, prefix);
- }
-
- /**
- * Create a unique namespace uri/prefix combination.
- *
- * @return The namespace with the specified URI. If one doesn't exist, one
- * is created.
- * @throws XMLStreamException
- */
- public static String getUniquePrefix(XMLStreamWriter writer, String namespaceURI, boolean declare)
- throws XMLStreamException {
- String prefix = writer.getPrefix(namespaceURI);
- if (prefix == null) {
- prefix = getUniquePrefix(writer);
-
- if (declare) {
- writer.setPrefix(prefix, namespaceURI);
- writer.writeNamespace(prefix, namespaceURI);
- }
- }
- return prefix;
- }
- public static String getUniquePrefix(XMLStreamWriter writer, String namespaceURI)
- throws XMLStreamException {
- return getUniquePrefix(writer, namespaceURI, false);
- }
- public static String getUniquePrefix(XMLStreamWriter writer) {
- NamespaceContext nc = writer.getNamespaceContext();
- if (nc == null) {
- return DEF_PREFIXES[0];
- }
- for (String t : DEF_PREFIXES) {
- String uri = nc.getNamespaceURI(t);
- if (StringUtils.isEmpty(uri)) {
- return t;
- }
- }
-
- int n = 10;
- while (true) {
- String nsPrefix = "ns" + n;
- String uri = nc.getNamespaceURI(nsPrefix);
- if (StringUtils.isEmpty(uri)) {
- return nsPrefix;
- }
- n++;
- }
- }
-
-
- public static void printXmlFragment(XMLStreamReader reader) {
- try {
- StringWriter sw = new StringWriter(1024);
- XMLStreamWriter writer = null;
- try {
- writer = new PrettyPrintXMLStreamWriter(createXMLStreamWriter(sw), 4);
- copy(reader, writer);
- writer.flush();
- } finally {
- StaxUtils.close(writer);
- }
- LOG.info(sw.toString());
- } catch (XMLStreamException e) {
- LOG.severe(e.getMessage());
- }
- }
-
-
- private static void writeStartElementEvent(XMLEvent event, XMLStreamWriter writer)
- throws XMLStreamException {
- StartElement start = event.asStartElement();
- QName name = start.getName();
- String nsURI = name.getNamespaceURI();
- String localName = name.getLocalPart();
- String prefix = name.getPrefix();
-
- if (prefix != null) {
- writer.writeStartElement(prefix, localName, nsURI);
- } else if (nsURI != null) {
- writer.writeStartElement(localName, nsURI);
- } else {
- writer.writeStartElement(localName);
- }
- Iterator<XMLEvent> it = CastUtils.cast(start.getNamespaces());
- while (it != null && it.hasNext()) {
- writeEvent(it.next(), writer);
- }
-
- it = CastUtils.cast(start.getAttributes());
- while (it != null && it.hasNext()) {
- writeAttributeEvent(it.next(), writer);
- }
- }
- private static void writeAttributeEvent(XMLEvent event, XMLStreamWriter writer)
- throws XMLStreamException {
-
- Attribute attr = (Attribute)event;
- QName name = attr.getName();
- String nsURI = name.getNamespaceURI();
- String localName = name.getLocalPart();
- String prefix = name.getPrefix();
- String value = attr.getValue();
-
- if (prefix != null) {
- writer.writeAttribute(prefix, nsURI, localName, value);
- } else if (nsURI != null) {
- writer.writeAttribute(nsURI, localName, value);
- } else {
- writer.writeAttribute(localName, value);
- }
- }
-
- public static void writeEvent(XMLEvent event, XMLStreamWriter writer)
- throws XMLStreamException {
-
- switch (event.getEventType()) {
- case XMLStreamConstants.START_ELEMENT:
- writeStartElementEvent(event, writer);
- break;
- case XMLStreamConstants.END_ELEMENT:
- writer.writeEndElement();
- break;
- case XMLStreamConstants.ATTRIBUTE:
- writeAttributeEvent(event, writer);
- break;
- case XMLStreamConstants.ENTITY_REFERENCE:
- writer.writeEntityRef(((javax.xml.stream.events.EntityReference)event).getName());
- break;
- case XMLStreamConstants.DTD:
- writer.writeDTD(((DTD)event).getDocumentTypeDeclaration());
- break;
- case XMLStreamConstants.PROCESSING_INSTRUCTION:
- if (((javax.xml.stream.events.ProcessingInstruction)event).getData() != null) {
- writer.writeProcessingInstruction(
- ((javax.xml.stream.events.ProcessingInstruction)event).getTarget(),
- ((javax.xml.stream.events.ProcessingInstruction)event).getData());
- } else {
- writer.writeProcessingInstruction(
- ((javax.xml.stream.events.ProcessingInstruction)event).getTarget());
- }
- break;
- case XMLStreamConstants.NAMESPACE:
- if (((Namespace)event).isDefaultNamespaceDeclaration()) {
- writer.writeDefaultNamespace(((Namespace)event).getNamespaceURI());
- writer.setDefaultNamespace(((Namespace)event).getNamespaceURI());
- } else {
- writer.writeNamespace(((Namespace)event).getPrefix(),
- ((Namespace)event).getNamespaceURI());
- writer.setPrefix(((Namespace)event).getPrefix(),
- ((Namespace)event).getNamespaceURI());
- }
- break;
- case XMLStreamConstants.COMMENT:
- writer.writeComment(((javax.xml.stream.events.Comment)event).getText());
- break;
- case XMLStreamConstants.CHARACTERS:
- case XMLStreamConstants.SPACE:
- writer.writeCharacters(event.asCharacters().getData());
- break;
- case XMLStreamConstants.CDATA:
- writer.writeCData(event.asCharacters().getData());
- break;
- case XMLStreamConstants.START_DOCUMENT:
- if (((StartDocument)event).encodingSet()) {
- writer.writeStartDocument(((StartDocument)event).getCharacterEncodingScheme(),
- ((StartDocument)event).getVersion());
-
- } else {
- writer.writeStartDocument(((StartDocument)event).getVersion());
- }
- break;
- case XMLStreamConstants.END_DOCUMENT:
- writer.writeEndDocument();
- break;
- default:
- //shouldn't get here
- }
- }
- public static void print(Node node) {
- XMLStreamWriter writer = null;
- try {
- writer = createXMLStreamWriter(System.out);
- copy(new DOMSource(node), writer);
- writer.flush();
- } catch (XMLStreamException e) {
- throw new RuntimeException(e);
- } finally {
- StaxUtils.close(writer);
- }
- }
-
- public static String toString(Source src) {
- StringWriter sw = new StringWriter(1024);
- XMLStreamWriter writer = null;
- try {
- writer = createXMLStreamWriter(sw);
- copy(src, writer);
- writer.flush();
- } catch (XMLStreamException e) {
- throw new RuntimeException(e);
- } finally {
- StaxUtils.close(writer);
- }
- return sw.toString();
- }
- public static String toString(Node src) {
- return toString(new DOMSource(src));
- }
- public static String toString(Document doc) {
- StringWriter sw = new StringWriter(1024);
- XMLStreamWriter writer = null;
- try {
- writer = createXMLStreamWriter(sw);
- copy(doc, writer);
- writer.flush();
- } catch (XMLStreamException e) {
- throw new RuntimeException(e);
- } finally {
- StaxUtils.close(writer);
- }
- return sw.toString();
- }
- public static String toString(Element el) {
- return toString(el, 0);
- }
- public static String toString(Element el, int indent) {
- StringWriter sw = new StringWriter(1024);
- XMLStreamWriter writer = null;
- try {
- writer = createXMLStreamWriter(sw);
- if (indent > 0) {
- writer = new PrettyPrintXMLStreamWriter(writer, indent);
- }
- copy(el, writer);
- writer.flush();
- } catch (XMLStreamException e) {
- throw new RuntimeException(e);
- } finally {
- StaxUtils.close(writer);
- }
- return sw.toString();
- }
- public static void close(XMLStreamReader reader) throws XMLStreamException {
- if (reader != null) {
- reader.close();
- }
- }
-
- public static void close(XMLStreamWriter writer) {
- if (writer != null) {
- try {
- writer.close();
- } catch (Exception e) {
- //ignore
- }
- }
- }
-
- public static boolean isSecureReader(XMLStreamReader reader, Message message) {
- if (reader instanceof DocumentDepthProperties) {
- return true;
- }
- try {
- if (reader.getProperty(P_MAX_CHILDREN_PER_ELEMENT) != null) {
- return true;
- }
- } catch (Exception ex) {
- //ignore
- }
- return false;
- }
-
- public static XMLStreamReader configureReader(XMLStreamReader xreader, Message message) throws XMLStreamException {
- Integer messageMaxChildElements = PropertyUtils.getInteger(message, MAX_CHILD_ELEMENTS);
- Integer messageMaxElementDepth = PropertyUtils.getInteger(message, MAX_ELEMENT_DEPTH);
- Integer messageMaxAttributeCount = PropertyUtils.getInteger(message, MAX_ATTRIBUTE_COUNT);
- Integer messageMaxAttributeSize = PropertyUtils.getInteger(message, MAX_ATTRIBUTE_SIZE);
- Integer messageMaxTextLength = PropertyUtils.getInteger(message, MAX_TEXT_LENGTH);
- Long messageMaxElementCount = PropertyUtils.getLong(message, MAX_ELEMENT_COUNT);
- Long messageMaxXMLCharacters = PropertyUtils.getLong(message, MAX_XML_CHARACTERS);
- return configureReader(xreader, messageMaxChildElements, messageMaxElementDepth,
- messageMaxAttributeCount, messageMaxAttributeSize, messageMaxTextLength,
- messageMaxElementCount, messageMaxXMLCharacters);
- }
-
- //CHECKSTYLE:OFF - lots of params to configure
- public static XMLStreamReader configureReader(XMLStreamReader reader, Integer maxChildElements,
- Integer maxElementDepth, Integer maxAttributeCount,
- Integer maxAttributeSize, Integer maxTextLength,
- Long maxElementCount, Long maxXMLCharacters)
- throws XMLStreamException {
- //CHECKSTYLE:ON
-
- // We currently ONLY support Woodstox 4.2.x for most of this other than a few things
- // that we can handle via a wrapper.
- try {
- DocumentDepthProperties p = null;
- if (maxChildElements != null) {
- try {
- setProperty(reader, P_MAX_CHILDREN_PER_ELEMENT, maxChildElements);
- } catch (Throwable t) {
- //we can handle this via a wrapper
- p = new DocumentDepthProperties();
- p.setInnerElementCountThreshold(maxChildElements);
- }
- }
- if (maxElementDepth != null) {
- try {
- setProperty(reader, P_MAX_ELEMENT_DEPTH, maxElementDepth);
- } catch (Throwable t) {
- //we can handle this via a wrapper
- if (p == null) {
- p = new DocumentDepthProperties();
- }
- p.setInnerElementLevelThreshold(maxElementDepth);
- }
- }
- if (maxAttributeCount != null) {
- setProperty(reader, P_MAX_ATTRIBUTES_PER_ELEMENT, maxAttributeCount);
- }
- if (maxAttributeSize != null) {
- setProperty(reader, P_MAX_ATTRIBUTE_SIZE, maxAttributeSize);
- }
- if (maxTextLength != null) {
- setProperty(reader, P_MAX_TEXT_LENGTH, maxTextLength);
- }
- if (maxElementCount != null) {
- try {
- setProperty(reader, P_MAX_ELEMENT_COUNT, maxElementCount);
- } catch (Throwable t) {
- //we can handle this via a wrapper
- if (p == null) {
- p = new DocumentDepthProperties();
- }
- p.setElementCountThreshold(maxElementCount.intValue());
- }
- }
- if (maxXMLCharacters != null) {
- setProperty(reader, P_MAX_CHARACTERS, maxXMLCharacters);
- }
- if (p != null) {
- reader = new DepthRestrictingStreamReader(reader, p);
- }
- } catch (ClassCastException cce) {
- //not an XMLStreamReader2
- if (ALLOW_INSECURE_PARSER_VAL) {
- LOG.warning("INSTANCE_NOT_XMLSTREAMREADER2");
- } else {
- throw new XMLStreamException(cce.getMessage(), cce);
- }
- } catch (IllegalArgumentException cce) {
- //not a property supported by this version of woodstox
- if (ALLOW_INSECURE_PARSER_VAL) {
- LOG.log(Level.WARNING, "SECURE_PROPERTY_NOT_SUPPORTED", cce.getMessage());
- } else {
- throw new XMLStreamException(cce.getMessage(), cce);
- }
- }
- return reader;
- }
- private static void setProperty(XMLStreamReader reader, String p, Object v) {
- WoodstoxHelper.setProperty(reader, p, v);
- }
-
-
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/staxutils/W3CDOMStreamReader.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/staxutils/W3CDOMStreamReader.java
deleted file mode 100644
index 03b1992..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/staxutils/W3CDOMStreamReader.java
+++ /dev/null
@@ -1,429 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.cxf.staxutils;
-
-import java.util.ArrayList;
-
-import javax.xml.namespace.NamespaceContext;
-import javax.xml.namespace.QName;
-import javax.xml.stream.Location;
-import javax.xml.stream.XMLStreamException;
-
-import org.w3c.dom.Attr;
-import org.w3c.dom.Comment;
-import org.w3c.dom.Document;
-import org.w3c.dom.DocumentFragment;
-import org.w3c.dom.Element;
-import org.w3c.dom.NamedNodeMap;
-import org.w3c.dom.Node;
-import org.w3c.dom.ProcessingInstruction;
-import org.w3c.dom.Text;
-import org.w3c.dom.TypeInfo;
-
-import org.apache.cxf.helpers.DOMUtils;
-
-public class W3CDOMStreamReader extends AbstractDOMStreamReader<Node, Node> {
- private Node content;
-
- private Document document;
-
- private W3CNamespaceContext context;
-
- private String sysId;
-
- /**
- * @param element
- */
- public W3CDOMStreamReader(Element element) {
- super(new ElementFrame<Node, Node>(element, null));
- content = element;
- newFrame(getCurrentFrame());
-
- this.document = element.getOwnerDocument();
- }
- public W3CDOMStreamReader(Element element, String systemId) {
- this(element);
- sysId = systemId;
- }
- public W3CDOMStreamReader(Document doc) {
- super(new ElementFrame<Node, Node>(doc, false) {
- public boolean isDocument() {
- return true;
- }
- });
- this.document = doc;
- }
- public W3CDOMStreamReader(DocumentFragment docfrag) {
- super(new ElementFrame<Node, Node>(docfrag, true) {
- public boolean isDocumentFragment() {
- return true;
- }
- });
- this.document = docfrag.getOwnerDocument();
- }
-
- /**
- * Get the document associated with this stream.
- */
- public Document getDocument() {
- return document;
- }
- public String getSystemId() {
- try {
- return sysId == null ? document.getDocumentURI() : sysId;
- } catch (Throwable ex) {
- //ignore, probably not DOM level 3
- }
- return sysId;
- }
- /**
- * Find name spaces declaration in atrributes and move them to separate
- * collection.
- */
- @Override
- protected final void newFrame(ElementFrame<Node, Node> frame) {
- Node element = getCurrentNode();
- frame.uris = new ArrayList<>();
- frame.prefixes = new ArrayList<>();
- frame.attributes = new ArrayList<>();
-
- if (context == null) {
- context = new W3CNamespaceContext();
- }
- if (element instanceof Element) {
- context.setElement((Element)element);
- }
-
- NamedNodeMap nodes = element.getAttributes();
-
- if (nodes != null) {
- for (int i = 0; i < nodes.getLength(); i++) {
- Node node = nodes.item(i);
- String prefix = node.getPrefix();
- String localName = node.getLocalName();
- String value = node.getNodeValue();
- String name = node.getNodeName();
-
- if (prefix == null) {
- prefix = "";
- }
-
- if ("xmlns".equals(name)) {
- frame.uris.add(value);
- frame.prefixes.add("");
- } else if (!prefix.isEmpty() && "xmlns".equals(prefix)) {
- frame.uris.add(value);
- frame.prefixes.add(localName);
- } else if (name.startsWith("xmlns:")) {
- frame.uris.add(value);
- frame.prefixes.add(name.substring(6));
- } else {
- frame.attributes.add(node);
- }
- }
- }
- }
-
- public final Node getCurrentNode() {
- return getCurrentFrame().element;
- }
- public final Element getCurrentElement() {
- return (Element)getCurrentFrame().element;
- }
-
- @Override
- protected ElementFrame<Node, Node> getChildFrame() {
- return new ElementFrame<Node, Node>(getCurrentFrame().currentChild,
- getCurrentFrame());
- }
-
- @Override
- protected boolean hasMoreChildren() {
- if (getCurrentFrame().currentChild == null) {
- return getCurrentNode().getFirstChild() != null;
- }
- return getCurrentFrame().currentChild.getNextSibling() != null;
- }
-
- @Override
- protected int nextChild() {
- ElementFrame<Node, Node> frame = getCurrentFrame();
- if (frame.currentChild == null) {
- content = getCurrentNode().getFirstChild();
- } else {
- content = frame.currentChild.getNextSibling();
- }
-
- frame.currentChild = content;
- switch (content.getNodeType()) {
- case Node.ELEMENT_NODE:
- return START_ELEMENT;
- case Node.TEXT_NODE:
- return CHARACTERS;
- case Node.COMMENT_NODE:
- return COMMENT;
- case Node.CDATA_SECTION_NODE:
- return CDATA;
- case Node.ENTITY_REFERENCE_NODE:
- return ENTITY_REFERENCE;
- case Node.PROCESSING_INSTRUCTION_NODE:
- return PROCESSING_INSTRUCTION;
- default:
- throw new IllegalStateException("Found type: " + content.getClass().getName());
- }
- }
-
- @Override
- public String getElementText() throws XMLStreamException {
- String result = DOMUtils.getRawContent(content);
-
- ElementFrame<Node, Node> frame = getCurrentFrame();
- frame.ended = true;
- currentEvent = END_ELEMENT;
- endElement();
-
- // we should not return null according to the StAx API javadoc
- return result != null ? result : "";
- }
-
- @Override
- public String getNamespaceURI(String prefix) {
- ElementFrame<Node, Node> frame = getCurrentFrame();
-
- while (null != frame) {
- int index = frame.prefixes.indexOf(prefix);
- if (index != -1) {
- return frame.uris.get(index);
- }
-
- if (frame.parent == null && frame.getElement() instanceof Element) {
- return ((Element)frame.getElement()).lookupNamespaceURI(prefix);
- }
- frame = frame.parent;
- }
-
- return null;
- }
-
- public String getAttributeValue(String ns, String local) {
- Attr at;
- if (ns == null || ns.isEmpty()) {
- at = getCurrentElement().getAttributeNode(local);
- } else {
- at = getCurrentElement().getAttributeNodeNS(ns, local);
- }
-
- if (at == null) {
- return null;
- }
- return at.getNodeValue();
- }
-
- public int getAttributeCount() {
- return getCurrentFrame().attributes.size();
- }
-
- Attr getAttribute(int i) {
- return (Attr)getCurrentFrame().attributes.get(i);
- }
-
- private String getLocalName(Attr attr) {
-
- String name = attr.getLocalName();
- if (name == null) {
- name = attr.getNodeName();
- }
- return name;
- }
-
- public QName getAttributeName(int i) {
- Attr at = getAttribute(i);
-
- String prefix = at.getPrefix();
- String ln = getLocalName(at);
- // at.getNodeName();
- String ns = at.getNamespaceURI();
-
- if (prefix == null) {
- return new QName(ns, ln);
- }
- return new QName(ns, ln, prefix);
- }
-
- public String getAttributeNamespace(int i) {
- return getAttribute(i).getNamespaceURI();
- }
-
- public String getAttributeLocalName(int i) {
- Attr attr = getAttribute(i);
- return getLocalName(attr);
- }
-
- public String getAttributePrefix(int i) {
- return getAttribute(i).getPrefix();
- }
-
- public String getAttributeType(int i) {
- Attr attr = getAttribute(i);
- if (attr.isId()) {
- return "ID";
- }
- TypeInfo schemaType = null;
- try {
- schemaType = attr.getSchemaTypeInfo();
- } catch (Throwable t) {
- //DOM level 2?
- }
- return (schemaType == null) ? "CDATA"
- : schemaType.getTypeName() == null ? "CDATA" : schemaType.getTypeName();
- }
-
-
- public String getAttributeValue(int i) {
- return getAttribute(i).getValue();
- }
-
- public boolean isAttributeSpecified(int i) {
- return getAttribute(i).getValue() != null;
- }
-
- public int getNamespaceCount() {
- return getCurrentFrame().prefixes.size();
- }
-
- public String getNamespacePrefix(int i) {
- return getCurrentFrame().prefixes.get(i);
- }
-
- public String getNamespaceURI(int i) {
- return getCurrentFrame().uris.get(i);
- }
-
- public NamespaceContext getNamespaceContext() {
- return context;
- }
-
- public String getText() {
- if (content instanceof Text) {
- return ((Text)content).getData();
- } else if (content instanceof Comment) {
- return ((Comment)content).getData();
- }
- return DOMUtils.getRawContent(getCurrentNode());
- }
-
- public char[] getTextCharacters() {
- return getText().toCharArray();
- }
-
- public int getTextStart() {
- return 0;
- }
-
- public int getTextLength() {
- return getText().length();
- }
-
- public String getEncoding() {
- return null;
- }
-
- public QName getName() {
- Node el = getCurrentNode();
-
- String prefix = getPrefix();
- String ln = getLocalName();
-
- return new QName(el.getNamespaceURI(), ln, prefix);
- }
-
- public String getLocalName() {
- String ln = getCurrentNode().getLocalName();
- if (ln == null) {
- ln = getCurrentNode().getNodeName();
- if (ln.indexOf(':') != -1) {
- ln = ln.substring(ln.indexOf(':') + 1);
- }
- }
- return ln;
- }
-
- public String getNamespaceURI() {
- String ln = getCurrentNode().getLocalName();
- if (ln == null) {
- ln = getCurrentNode().getNodeName();
- if (ln.indexOf(':') == -1) {
- ln = getNamespaceURI("");
- } else {
- ln = getNamespaceURI(ln.substring(0, ln.indexOf(':')));
- }
- return ln;
- }
- return getCurrentNode().getNamespaceURI();
- }
-
- public String getPrefix() {
- String prefix = getCurrentNode().getPrefix();
- if (prefix == null) {
- String nodeName = getCurrentNode().getNodeName();
- if (nodeName.indexOf(':') != -1) {
- prefix = nodeName.substring(0, nodeName.indexOf(':'));
- } else {
- prefix = "";
- }
- }
- return prefix;
- }
-
- public String getPITarget() {
- return ((ProcessingInstruction)content).getTarget();
- }
-
- public String getPIData() {
- return ((ProcessingInstruction)content).getData();
- }
- public Location getLocation() {
- try {
- Object o = getCurrentNode().getUserData("location");
- if (o instanceof Location) {
- return (Location)o;
- }
- } catch (Throwable ex) {
- //ignore, probably not DOM level 3
- }
- return super.getLocation();
- }
-
- public String toString() {
- if (document == null) {
- return "<null>";
- }
- if (document.getDocumentElement() == null) {
- return "<null document element>";
- }
- try {
- return StaxUtils.toString(document);
- } catch (Throwable t) {
- t.printStackTrace();
- return super.toString();
- }
- }
-
-
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/transport/ChainInitiationObserver.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/transport/ChainInitiationObserver.java
deleted file mode 100644
index a4b8aa3..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/transport/ChainInitiationObserver.java
+++ /dev/null
@@ -1,197 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.cxf.transport;
-
-
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.util.Collection;
-
-import javax.xml.namespace.QName;
-
-import org.apache.cxf.Bus;
-import org.apache.cxf.BusFactory;
-import org.apache.cxf.binding.Binding;
-import org.apache.cxf.common.classloader.ClassLoaderUtils;
-import org.apache.cxf.common.classloader.ClassLoaderUtils.ClassLoaderHolder;
-import org.apache.cxf.endpoint.Endpoint;
-import org.apache.cxf.helpers.CastUtils;
-import org.apache.cxf.interceptor.Interceptor;
-import org.apache.cxf.interceptor.InterceptorChain;
-import org.apache.cxf.interceptor.InterceptorProvider;
-import org.apache.cxf.message.Exchange;
-import org.apache.cxf.message.ExchangeImpl;
-import org.apache.cxf.message.Message;
-import org.apache.cxf.phase.PhaseChainCache;
-import org.apache.cxf.phase.PhaseManager;
-import org.apache.cxf.service.Service;
-import org.apache.cxf.service.model.EndpointInfo;
-
-public class ChainInitiationObserver implements MessageObserver {
- protected Endpoint endpoint;
- protected Bus bus;
- protected ClassLoader loader;
-
- private PhaseChainCache chainCache = new PhaseChainCache();
-
- public ChainInitiationObserver(Endpoint endpoint, Bus bus) {
- super();
- this.endpoint = endpoint;
- this.bus = bus;
- if (bus != null) {
- loader = bus.getExtension(ClassLoader.class);
- }
- }
-
- public void onMessage(Message m) {
- Bus origBus = BusFactory.getAndSetThreadDefaultBus(bus);
- ClassLoaderHolder origLoader = null;
- try {
- if (loader != null) {
- origLoader = ClassLoaderUtils.setThreadContextClassloader(loader);
- }
- InterceptorChain phaseChain;
-
- if (m.getInterceptorChain() != null) {
- phaseChain = m.getInterceptorChain();
- // To make sure the phase chain is run by one thread once
- synchronized (phaseChain) {
- if (phaseChain.getState() == InterceptorChain.State.PAUSED
- || phaseChain.getState() == InterceptorChain.State.SUSPENDED) {
- phaseChain.resume();
- return;
- }
- }
- }
-
- Message message = getBinding().createMessage(m);
- Exchange exchange = message.getExchange();
- if (exchange == null) {
- exchange = new ExchangeImpl();
- m.setExchange(exchange);
- }
- exchange.setInMessage(message);
- setExchangeProperties(exchange, message);
-
- InterceptorProvider dbp = null;
- if (endpoint.getService().getDataBinding() instanceof InterceptorProvider) {
- dbp = (InterceptorProvider)endpoint.getService().getDataBinding();
- }
- // setup chain
- if (dbp == null) {
- phaseChain = chainCache.get(bus.getExtension(PhaseManager.class).getInPhases(),
- bus.getInInterceptors(),
- endpoint.getService().getInInterceptors(),
- endpoint.getInInterceptors(),
- getBinding().getInInterceptors());
- } else {
- phaseChain = chainCache.get(bus.getExtension(PhaseManager.class).getInPhases(),
- bus.getInInterceptors(),
- endpoint.getService().getInInterceptors(),
- endpoint.getInInterceptors(),
- getBinding().getInInterceptors(),
- dbp.getInInterceptors());
- }
-
-
-
- message.setInterceptorChain(phaseChain);
-
- phaseChain.setFaultObserver(endpoint.getOutFaultObserver());
-
- addToChain(phaseChain, message);
-
- phaseChain.doIntercept(message);
-
- } finally {
- if (origBus != bus) {
- BusFactory.setThreadDefaultBus(origBus);
- }
- if (origLoader != null) {
- origLoader.reset();
- }
- }
- }
- private void addToChain(InterceptorChain chain, Message m) {
- Collection<InterceptorProvider> providers
- = CastUtils.cast((Collection<?>)m.get(Message.INTERCEPTOR_PROVIDERS));
- if (providers != null) {
- for (InterceptorProvider p : providers) {
- chain.add(p.getInInterceptors());
- }
- }
- Collection<Interceptor<? extends Message>> is
- = CastUtils.cast((Collection<?>)m.get(Message.IN_INTERCEPTORS));
- if (is != null) {
- chain.add(is);
- }
- if (m.getDestination() instanceof InterceptorProvider) {
- chain.add(((InterceptorProvider)m.getDestination()).getInInterceptors());
- }
- }
-
- protected Binding getBinding() {
- return endpoint.getBinding();
- }
-
- protected void setExchangeProperties(Exchange exchange, Message m) {
- exchange.put(Endpoint.class, endpoint);
- exchange.put(Binding.class, getBinding());
- exchange.put(Bus.class, bus);
- if (exchange.getDestination() == null) {
- exchange.setDestination(m.getDestination());
- }
- if (endpoint != null && endpoint.getService() != null) {
- exchange.put(Service.class, endpoint.getService());
-
- EndpointInfo endpointInfo = endpoint.getEndpointInfo();
-
- if (endpointInfo.getService() != null) {
- QName serviceQName = endpointInfo.getService().getName();
- exchange.put(Message.WSDL_SERVICE, serviceQName);
-
- QName interfaceQName = endpointInfo.getService().getInterface().getName();
- exchange.put(Message.WSDL_INTERFACE, interfaceQName);
-
-
- QName portQName = endpointInfo.getName();
- exchange.put(Message.WSDL_PORT, portQName);
- URI wsdlDescription = endpointInfo.getProperty("URI", URI.class);
- if (wsdlDescription == null && !endpointInfo.hasProperty("URI")) {
- String address = endpointInfo.getAddress();
- try {
- wsdlDescription = new URI(address + "?wsdl");
- } catch (URISyntaxException e) {
- // do nothing
- }
- endpointInfo.setProperty("URI", wsdlDescription);
- }
- exchange.put(Message.WSDL_DESCRIPTION, wsdlDescription);
- }
- } else {
- exchange.put(Service.class, null);
- }
- }
-
- public Endpoint getEndpoint() {
- return endpoint;
- }
-
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java
deleted file mode 100644
index 4bee0d3..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java
+++ /dev/null
@@ -1,956 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.cxf.transport.http;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.net.ServerSocket;
-import java.net.URL;
-import java.nio.charset.StandardCharsets;
-import java.security.Principal;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Map;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import javax.servlet.ServletConfig;
-import javax.servlet.ServletContext;
-import javax.servlet.ServletRequest;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import javax.xml.namespace.QName;
-
-import org.apache.cxf.Bus;
-import org.apache.cxf.attachment.AttachmentDataSource;
-import org.apache.cxf.common.logging.LogUtils;
-import org.apache.cxf.common.util.Base64Exception;
-import org.apache.cxf.common.util.Base64Utility;
-import org.apache.cxf.common.util.PropertyUtils;
-import org.apache.cxf.common.util.StringUtils;
-import org.apache.cxf.configuration.Configurable;
-import org.apache.cxf.configuration.security.AuthorizationPolicy;
-import org.apache.cxf.continuations.ContinuationProvider;
-import org.apache.cxf.continuations.SuspendedInvocationException;
-import org.apache.cxf.helpers.HttpHeaderHelper;
-import org.apache.cxf.helpers.IOUtils;
-import org.apache.cxf.interceptor.Fault;
-import org.apache.cxf.interceptor.Interceptor;
-import org.apache.cxf.io.AbstractWrappedOutputStream;
-import org.apache.cxf.io.CopyingOutputStream;
-import org.apache.cxf.io.DelegatingInputStream;
-import org.apache.cxf.message.Attachment;
-import org.apache.cxf.message.Exchange;
-import org.apache.cxf.message.ExchangeImpl;
-import org.apache.cxf.message.Message;
-import org.apache.cxf.message.MessageImpl;
-import org.apache.cxf.message.MessageUtils;
-import org.apache.cxf.policy.PolicyDataEngine;
-import org.apache.cxf.security.SecurityContext;
-import org.apache.cxf.security.transport.TLSSessionInfo;
-import org.apache.cxf.service.model.EndpointInfo;
-import org.apache.cxf.transport.AbstractDestination;
-import org.apache.cxf.transport.AbstractMultiplexDestination;
-import org.apache.cxf.transport.Assertor;
-import org.apache.cxf.transport.Conduit;
-import org.apache.cxf.transport.http.policy.impl.ServerPolicyCalculator;
-import org.apache.cxf.transport.https.CertConstraints;
-import org.apache.cxf.transport.https.CertConstraintsInterceptor;
-import org.apache.cxf.transports.http.configuration.HTTPServerPolicy;
-import org.apache.cxf.ws.addressing.AddressingProperties;
-import org.apache.cxf.ws.addressing.ContextUtils;
-import org.apache.cxf.ws.addressing.EndpointReferenceType;
-import org.apache.cxf.ws.addressing.EndpointReferenceUtils;
-
-/**
- * Common base for HTTP Destination implementations.
- */
-public abstract class AbstractHTTPDestination
- extends AbstractMultiplexDestination
- implements Configurable, Assertor {
-
- public static final String HTTP_REQUEST = "HTTP.REQUEST";
- public static final String HTTP_RESPONSE = "HTTP.RESPONSE";
- public static final String HTTP_CONTEXT = "HTTP.CONTEXT";
- public static final String HTTP_CONFIG = "HTTP.CONFIG";
- public static final String HTTP_CONTEXT_MATCH_STRATEGY = "HTTP_CONTEXT_MATCH_STRATEGY";
-
- public static final String RESPONSE_HEADERS_COPIED = "http.headers.copied";
- public static final String RESPONSE_COMMITED = "http.response.done";
- public static final String REQUEST_REDIRECTED = "http.request.redirected";
- public static final String CXF_CONTINUATION_MESSAGE = "cxf.continuation.message";
- public static final String CXF_ASYNC_CONTEXT = "cxf.async.context";
-
- public static final String SERVICE_REDIRECTION = "http.service.redirection";
- private static final String HTTP_BASE_PATH = "http.base.path";
-
- private static final String SSL_CIPHER_SUITE_ATTRIBUTE = "javax.servlet.request.cipher_suite";
- private static final String SSL_PEER_CERT_CHAIN_ATTRIBUTE = "javax.servlet.request.X509Certificate";
-
- private static final String DECODE_BASIC_AUTH_WITH_ISO8859 = "decode.basicauth.with.iso8859";
-
- private static final Logger LOG = LogUtils.getL7dLogger(AbstractHTTPDestination.class);
-
- protected final Bus bus;
- protected DestinationRegistry registry;
- protected final String path;
-
- // Configuration values
- protected volatile HTTPServerPolicy serverPolicy;
- protected String contextMatchStrategy = "stem";
- protected boolean fixedParameterOrder;
- protected boolean multiplexWithAddress;
- protected CertConstraints certConstraints;
- protected boolean isServlet3;
- protected boolean decodeBasicAuthWithIso8859;
- protected ContinuationProviderFactory cproviderFactory;
- protected boolean enableWebSocket;
-
- private volatile boolean serverPolicyCalced;
-
- /**
- * Constructor
- *
- * @param b the associated Bus
- * @param registry the destination registry
- * @param ei the endpoint info of the destination
- * @param path the path
- * @param dp true for adding the default port if it is missing
- * @throws IOException
- */
- public AbstractHTTPDestination(Bus b,
- DestinationRegistry registry,
- EndpointInfo ei,
- String path,
- boolean dp)
- throws IOException {
- super(b, getTargetReference(getAddressValue(ei, dp), b), ei);
- this.bus = b;
- this.registry = registry;
- this.path = path;
- try {
- ServletRequest.class.getMethod("isAsyncSupported");
- isServlet3 = true;
- } catch (Throwable t) {
- //servlet 2.5 or earlier, no async support
- }
- decodeBasicAuthWithIso8859 = PropertyUtils.isTrue(bus.getProperty(DECODE_BASIC_AUTH_WITH_ISO8859));
-
- initConfig();
- }
-
- public Bus getBus() {
- return bus;
- }
-
- private AuthorizationPolicy getAuthorizationPolicyFromMessage(String credentials, SecurityContext sc) {
- if (credentials == null || StringUtils.isEmpty(credentials.trim())) {
- return null;
- }
-
- final String[] creds = credentials.split(" ");
- String authType = creds[0];
- if ("Basic".equals(authType) && creds.length == 2) {
- String authEncoded = creds[1];
- try {
- byte[] authBytes = Base64Utility.decode(authEncoded);
-
- if (authBytes == null) {
- throw new Base64Exception(new Throwable("Invalid Base64 data."));
- }
-
- String authDecoded = decodeBasicAuthWithIso8859
- ? new String(authBytes, StandardCharsets.ISO_8859_1) : new String(authBytes);
-
- int idx = authDecoded.indexOf(':');
- final String username;
- String password = null;
- if (idx == -1) {
- username = authDecoded;
- } else {
- username = authDecoded.substring(0, idx);
- if (idx < (authDecoded.length() - 1)) {
- password = authDecoded.substring(idx + 1);
- }
- }
-
- AuthorizationPolicy policy = sc.getUserPrincipal() == null
- ? new AuthorizationPolicy() : new PrincipalAuthorizationPolicy(sc);
- policy.setUserName(username);
- policy.setPassword(password);
- policy.setAuthorizationType(authType);
- return policy;
- } catch (Base64Exception ex) {
- // Invalid authentication => treat as not authenticated or use the Principal
- }
- }
- if (sc.getUserPrincipal() != null) {
- AuthorizationPolicy policy = new PrincipalAuthorizationPolicy(sc);
- policy.setAuthorization(credentials);
- policy.setAuthorizationType(authType);
- return policy;
- }
- return null;
- }
- public static final class PrincipalAuthorizationPolicy extends AuthorizationPolicy {
- final SecurityContext sc;
- public PrincipalAuthorizationPolicy(SecurityContext sc) {
- this.sc = sc;
- }
- public Principal getPrincipal() {
- return sc.getUserPrincipal();
- }
- @Override
- public String getUserName() {
- String name = super.getUserName();
- if (name != null) {
- return name;
- }
- Principal pp = getPrincipal();
- return pp != null ? pp.getName() : null;
- }
- }
-
- /**
- * @param message the message under consideration
- * @return true iff the message has been marked as oneway
- */
- protected final boolean isOneWay(Message message) {
- return MessageUtils.isOneWay(message);
- }
-
- public void invoke(final ServletConfig config,
- final ServletContext context,
- final HttpServletRequest req,
- final HttpServletResponse resp) throws IOException {
- Message inMessage = retrieveFromContinuation(req);
- if (inMessage == null) {
- LOG.fine("Create a new message for processing");
- inMessage = new MessageImpl();
- ExchangeImpl exchange = new ExchangeImpl();
- exchange.setInMessage(inMessage);
- setupMessage(inMessage,
- config,
- context,
- req,
- resp);
-
- exchange.setSession(new HTTPSession(req));
- ((MessageImpl)inMessage).setDestination(this);
- } else {
- LOG.fine("Get the message from the request for processing");
- }
-
- copyKnownRequestAttributes(req, inMessage);
-
- try {
- incomingObserver.onMessage(inMessage);
- invokeComplete(context, req, resp, inMessage);
- } catch (SuspendedInvocationException ex) {
- if (ex.getRuntimeException() != null) {
- throw ex.getRuntimeException();
- }
- //else nothing to do, just finishing the processing
- } catch (Fault ex) {
- Throwable cause = ex.getCause();
- if (cause instanceof RuntimeException) {
- throw (RuntimeException)cause;
- }
- throw ex;
- } catch (RuntimeException ex) {
- throw ex;
- } finally {
- if (LOG.isLoggable(Level.FINE)) {
- LOG.fine("Finished servicing http request on thread: " + Thread.currentThread());
- }
- }
- }
-
- protected void invokeComplete(final ServletContext context,
- final HttpServletRequest req,
- final HttpServletResponse resp,
- Message m) throws IOException {
- ContinuationProvider p = m.get(ContinuationProvider.class);
- if (p != null) {
- p.complete();
- }
- }
-
- private void copyKnownRequestAttributes(HttpServletRequest request, Message message) {
- message.put(SERVICE_REDIRECTION, request.getAttribute(SERVICE_REDIRECTION));
- }
-
- protected void setupMessage(final Message inMessage,
- final ServletConfig config,
- final ServletContext context,
- final HttpServletRequest req,
- final HttpServletResponse resp) throws IOException {
- setupContinuation(inMessage,
- req,
- resp);
-
- final Exchange exchange = inMessage.getExchange();
- DelegatingInputStream in = new DelegatingInputStream(req.getInputStream()) {
- public void cacheInput() {
- if (!cached && (exchange.isOneWay() || isWSAddressingReplyToSpecified(exchange))) {
- //For one-ways and WS-Addressing invocations with ReplyTo address,
- //we need to cache the values of the HttpServletRequest
- //so they can be queried later for things like paths and schemes
- //and such like that.
- //Please note, exchange used to always get the "current" message
- exchange.getInMessage().put(HTTP_REQUEST, new HttpServletRequestSnapshot(req));
- }
- super.cacheInput();
- }
- private boolean isWSAddressingReplyToSpecified(Exchange ex) {
- AddressingProperties map = ContextUtils.retrieveMAPs(ex.getInMessage(), false, false, false);
- return map != null && !ContextUtils.isGenericAddress(map.getReplyTo());
- }
- };
-
- inMessage.setContent(DelegatingInputStream.class, in);
- inMessage.setContent(InputStream.class, in);
- inMessage.put(HTTP_REQUEST, req);
- inMessage.put(HTTP_RESPONSE, resp);
- inMessage.put(HTTP_CONTEXT, context);
- inMessage.put(HTTP_CONFIG, config);
- inMessage.put(HTTP_CONTEXT_MATCH_STRATEGY, contextMatchStrategy);
-
- inMessage.put(Message.HTTP_REQUEST_METHOD, req.getMethod());
- String requestURI = req.getRequestURI();
- inMessage.put(Message.REQUEST_URI, requestURI);
- String requestURL = req.getRequestURL().toString();
- inMessage.put(Message.REQUEST_URL, requestURL);
- String contextPath = req.getContextPath();
- if (contextPath == null) {
- contextPath = "";
- }
- String servletPath = req.getServletPath();
- if (servletPath == null) {
- servletPath = "";
- }
- String contextServletPath = contextPath + servletPath;
- String pathInfo = req.getPathInfo();
- if (pathInfo != null) {
- inMessage.put(Message.PATH_INFO, contextServletPath + pathInfo);
- } else {
- inMessage.put(Message.PATH_INFO, requestURI);
- }
- if (!StringUtils.isEmpty(requestURI)) {
- int index = requestURL.indexOf(requestURI);
- if (index > 0) {
- // Can be useful for referencing resources with URIs not covered by CXFServlet.
- // For example, if we a have web application name 'app' and CXFServlet listening
- // on "/services/*" then having HTTP_BASE_PATH pointing to say
- // http://localhost:8080/app will make it easy to refer to non CXF resources
- String schemaInfo = requestURL.substring(0, index);
- String basePathWithContextOnly = schemaInfo + contextPath;
- inMessage.put(HTTP_BASE_PATH, basePathWithContextOnly);
- }
- } else if (!StringUtils.isEmpty(servletPath) && requestURL.endsWith(servletPath)) {
- int index = requestURL.lastIndexOf(servletPath);
- if (index > 0) {
- inMessage.put(HTTP_BASE_PATH, requestURL.substring(0, index));
- }
- }
- String contentType = req.getContentType();
- inMessage.put(Message.CONTENT_TYPE, contentType);
- setEncoding(inMessage, req, contentType);
-
- inMessage.put(Message.QUERY_STRING, req.getQueryString());
-
- inMessage.put(Message.ACCEPT_CONTENT_TYPE, req.getHeader("Accept"));
- String basePath = getBasePath(contextServletPath);
- if (!StringUtils.isEmpty(basePath)) {
- inMessage.put(Message.BASE_PATH, basePath);
- }
- inMessage.put(Message.FIXED_PARAMETER_ORDER, isFixedParameterOrder());
- inMessage.put(Message.ASYNC_POST_RESPONSE_DISPATCH, Boolean.TRUE);
-
- SecurityContext httpSecurityContext = new SecurityContext() {
- public Principal getUserPrincipal() {
- return req.getUserPrincipal();
- }
- public boolean isUserInRole(String role) {
- return req.isUserInRole(role);
- }
- };
-
- inMessage.put(SecurityContext.class, httpSecurityContext);
-
-
- Headers headers = new Headers(inMessage);
- headers.copyFromRequest(req);
- String credentials = headers.getAuthorization();
- AuthorizationPolicy authPolicy = getAuthorizationPolicyFromMessage(credentials,
- httpSecurityContext);
- inMessage.put(AuthorizationPolicy.class, authPolicy);
-
- propogateSecureSession(req, inMessage);
-
- inMessage.put(CertConstraints.class.getName(), certConstraints);
- inMessage.put(Message.IN_INTERCEPTORS,
- Arrays.asList(new Interceptor[] {CertConstraintsInterceptor.INSTANCE}));
-
- }
- /**
- * Propogate in the message a TLSSessionInfo instance representative
- * of the TLS-specific information in the HTTP request.
- *
- * @param request the Jetty request
- * @param message the Message
- */
- private static void propogateSecureSession(HttpServletRequest request,
- Message message) {
- final String cipherSuite =
- (String) request.getAttribute(SSL_CIPHER_SUITE_ATTRIBUTE);
- if (cipherSuite != null) {
- final java.security.cert.Certificate[] certs =
- (java.security.cert.Certificate[]) request.getAttribute(SSL_PEER_CERT_CHAIN_ATTRIBUTE);
- message.put(TLSSessionInfo.class,
- new TLSSessionInfo(cipherSuite,
- null,
- certs));
- }
- }
- private String setEncoding(final Message inMessage,
- final HttpServletRequest req,
- final String contentType) throws IOException {
-
- String enc = HttpHeaderHelper.findCharset(contentType);
- if (enc == null) {
- enc = req.getCharacterEncoding();
- }
- // work around a bug with Jetty which results in the character
- // encoding not being trimmed correctly.
- if (enc != null && enc.endsWith("\"")) {
- enc = enc.substring(0, enc.length() - 1);
- }
- if (enc != null || "POST".equals(req.getMethod()) || "PUT".equals(req.getMethod())) {
- //allow gets/deletes/options to not specify an encoding
- String normalizedEncoding = HttpHeaderHelper.mapCharset(enc);
- if (normalizedEncoding == null) {
- String m = new org.apache.cxf.common.i18n.Message("INVALID_ENCODING_MSG",
- LOG, enc).toString();
- LOG.log(Level.WARNING, m);
- throw new IOException(m);
- }
- inMessage.put(Message.ENCODING, normalizedEncoding);
- }
- return contentType;
- }
- protected Message retrieveFromContinuation(HttpServletRequest req) {
- if (!isServlet3) {
- if (cproviderFactory != null) {
- return cproviderFactory.retrieveFromContinuation(req);
- }
- return null;
- }
- return retrieveFromServlet3Async(req);
- }
-
- protected Message retrieveFromServlet3Async(HttpServletRequest req) {
- try {
- return (Message)req.getAttribute(CXF_CONTINUATION_MESSAGE);
- } catch (Throwable ex) {
- // the request may not implement the Servlet3 API
- }
- return null;
- }
-
- protected void setupContinuation(Message inMessage,
- final HttpServletRequest req,
- final HttpServletResponse resp) {
- try {
- if (isServlet3 && req.isAsyncSupported()) {
- inMessage.put(ContinuationProvider.class.getName(),
- new Servlet3ContinuationProvider(req, resp, inMessage));
- } else if (cproviderFactory != null) {
- ContinuationProvider p = cproviderFactory.createContinuationProvider(inMessage, req, resp);
- if (p != null) {
- inMessage.put(ContinuationProvider.class.getName(), p);
- }
- }
- } catch (Throwable ex) {
- // the request may not implement the Servlet3 API
- }
- }
- protected String getBasePath(String contextPath) throws IOException {
- if (StringUtils.isEmpty(endpointInfo.getAddress())) {
- return "";
- }
- return new URL(endpointInfo.getAddress()).getPath();
- }
-
- protected static EndpointInfo getAddressValue(EndpointInfo ei) {
- return getAddressValue(ei, true);
- }
-
- protected static EndpointInfo getAddressValue(EndpointInfo ei, boolean dp) {
- if (dp) {
-
- String eiAddress = ei.getAddress();
- if (eiAddress == null) {
- try {
- ServerSocket s = new ServerSocket(0);
- ei.setAddress("http://localhost:" + s.getLocalPort());
- s.close();
- return ei;
- } catch (IOException ex) {
- // problem allocating a random port, go to the default one
- ei.setAddress("http://localhost");
- }
- }
-
- String addr = StringUtils.addDefaultPortIfMissing(ei.getAddress());
- if (addr != null) {
- ei.setAddress(addr);
- }
- }
- return ei;
- }
-
- /**
- * @param inMessage the incoming message
- * @return the inbuilt backchannel
- */
- protected Conduit getInbuiltBackChannel(Message inMessage) {
- HttpServletResponse response = (HttpServletResponse)inMessage.get(HTTP_RESPONSE);
- return new BackChannelConduit(response);
- }
-
- private void initConfig() {
-
- cproviderFactory = bus.getExtension(ContinuationProviderFactory.class);
- }
-
- private synchronized HTTPServerPolicy calcServerPolicyInternal(Message m) {
- HTTPServerPolicy sp = serverPolicy;
- if (!serverPolicyCalced) {
- PolicyDataEngine pde = bus.getExtension(PolicyDataEngine.class);
- if (pde != null) {
- sp = pde.getServerEndpointPolicy(m, endpointInfo, this, new ServerPolicyCalculator());
- }
- if (null == sp) {
- sp = endpointInfo.getTraversedExtensor(
- new HTTPServerPolicy(), HTTPServerPolicy.class);
- }
- serverPolicy = sp;
- serverPolicyCalced = true;
- }
- return sp;
- }
- private HTTPServerPolicy calcServerPolicy(Message m) {
- HTTPServerPolicy sp = serverPolicy;
- if (!serverPolicyCalced) {
- sp = calcServerPolicyInternal(m);
- }
- return sp;
- }
-
- /**
- * On first write, we need to make sure any attachments and such that are still on the incoming stream
- * are read in. Otherwise we can get into a deadlock where the client is still trying to send the
- * request, but the server is trying to send the response. Neither side is reading and both blocked
- * on full buffers. Not a good situation.
- * @param outMessage
- */
- private void cacheInput(Message outMessage) {
- if (outMessage.getExchange() == null) {
- return;
- }
- Message inMessage = outMessage.getExchange().getInMessage();
- if (inMessage == null) {
- return;
- }
- Object o = inMessage.get("cxf.io.cacheinput");
- DelegatingInputStream in = inMessage.getContent(DelegatingInputStream.class);
- if (PropertyUtils.isTrue(o)) {
- Collection<Attachment> atts = inMessage.getAttachments();
- if (atts != null) {
- for (Attachment a : atts) {
- if (a.getDataHandler().getDataSource() instanceof AttachmentDataSource) {
- try {
- ((AttachmentDataSource)a.getDataHandler().getDataSource()).cache(inMessage);
- } catch (IOException e) {
- throw new Fault(e);
- }
- }
- }
- }
- if (in != null) {
- in.cacheInput();
- }
- } else if (in != null) {
- //We don't need to cache it, but we may need to consume it in order for the client
- // to be able to receive a response. (could be blocked sending)
- //However, also don't want to consume indefinitely. We'll limit to 16M.
- try {
- IOUtils.consume(in, 16 * 1024 * 1024);
- } catch (Exception ioe) {
- //ignore
- }
- }
- }
-
- protected OutputStream flushHeaders(Message outMessage) throws IOException {
- return flushHeaders(outMessage, true);
- }
- protected OutputStream flushHeaders(Message outMessage, boolean getStream) throws IOException {
- if (isResponseRedirected(outMessage)) {
- return null;
- }
-
- cacheInput(outMessage);
- HTTPServerPolicy sp = calcServerPolicy(outMessage);
- if (sp != null) {
- new Headers(outMessage).setFromServerPolicy(sp);
- }
-
- OutputStream responseStream = null;
- boolean oneWay = isOneWay(outMessage);
-
- HttpServletResponse response = getHttpResponseFromMessage(outMessage);
-
- int responseCode = MessageUtils.getReponseCodeFromMessage(outMessage);
- if (responseCode >= 300) {
- String ec = (String)outMessage.get(Message.ERROR_MESSAGE);
- if (!StringUtils.isEmpty(ec)) {
- response.sendError(responseCode, ec);
- return null;
- }
- }
- response.setStatus(responseCode);
- new Headers(outMessage).copyToResponse(response);
-
- outMessage.put(RESPONSE_HEADERS_COPIED, "true");
-
- if (MessageUtils.hasNoResponseContent(outMessage)) {
- response.setContentLength(0);
- response.flushBuffer();
- closeResponseOutputStream(response);
- } else if (!getStream) {
- closeResponseOutputStream(response);
- } else {
- responseStream = response.getOutputStream();
- }
-
- if (oneWay) {
- outMessage.remove(HTTP_RESPONSE);
- }
- return responseStream;
- }
-
- private void closeResponseOutputStream(HttpServletResponse response) throws IOException {
- try {
- response.getOutputStream().close();
- } catch (IllegalStateException ex) {
- // response.getWriter() has already been called
- }
- }
-
-
- private HttpServletResponse getHttpResponseFromMessage(Message message) throws IOException {
- Object responseObj = message.get(HTTP_RESPONSE);
- if (responseObj instanceof HttpServletResponse) {
- return (HttpServletResponse)responseObj;
- } else if (null != responseObj) {
- String m = (new org.apache.cxf.common.i18n.Message("UNEXPECTED_RESPONSE_TYPE_MSG",
- LOG, responseObj.getClass())).toString();
- LOG.log(Level.WARNING, m);
- throw new IOException(m);
- } else {
- String m = (new org.apache.cxf.common.i18n.Message("NULL_RESPONSE_MSG", LOG)).toString();
- LOG.log(Level.WARNING, m);
- throw new IOException(m);
- }
- }
-
- private boolean isResponseRedirected(Message outMessage) {
- Exchange exchange = outMessage.getExchange();
- return exchange != null
- && Boolean.TRUE.equals(exchange.get(REQUEST_REDIRECTED));
- }
-
- /**
- * Backchannel conduit.
- */
- public class BackChannelConduit
- extends AbstractDestination.AbstractBackChannelConduit {
-
- protected HttpServletResponse response;
-
- BackChannelConduit(HttpServletResponse resp) {
- response = resp;
- }
-
- /**
- * Send an outbound message, assumed to contain all the name-value
- * mappings of the corresponding input message (if any).
- *
- * @param message the message to be sent.
- */
- public void prepare(Message message) throws IOException {
- message.put(HTTP_RESPONSE, response);
- OutputStream os = message.getContent(OutputStream.class);
- if (os == null) {
- message.setContent(OutputStream.class,
- new WrappedOutputStream(message));
- }
- }
-
- @Override
- public void close(Message msg) throws IOException {
- super.close(msg);
- if (msg.getExchange() == null) {
- return;
- }
- Message m = msg.getExchange().getInMessage();
- if (m == null) {
- return;
- }
- InputStream is = m.getContent(InputStream.class);
- if (is != null) {
- try {
- is.close();
- m.removeContent(InputStream.class);
- } catch (IOException ioex) {
- //ignore
- }
- }
- }
- }
-
- /**
- * Wrapper stream responsible for flushing headers and committing outgoing
- * HTTP-level response.
- */
- private class WrappedOutputStream extends AbstractWrappedOutputStream implements CopyingOutputStream {
-
- private Message outMessage;
-
- WrappedOutputStream(Message m) {
- super();
- this.outMessage = m;
- }
-
-
- @Override
- public int copyFrom(InputStream in) throws IOException {
- if (!written) {
- onFirstWrite();
- written = true;
- }
- if (wrappedStream != null) {
- return IOUtils.copy(in, wrappedStream);
- }
- return IOUtils.copy(in, this, IOUtils.DEFAULT_BUFFER_SIZE);
- }
-
- /**
- * Perform any actions required on stream flush (freeze headers,
- * reset output stream ... etc.)
- */
- protected void onFirstWrite() throws IOException {
- OutputStream responseStream = flushHeaders(outMessage);
- if (null != responseStream) {
- wrappedStream = responseStream;
- }
- }
-
- /**
- * Perform any actions required on stream closure (handle response etc.)
- */
- public void close() throws IOException {
- if (!written && wrappedStream == null) {
- OutputStream responseStream = flushHeaders(outMessage, false);
- if (null != responseStream) {
- wrappedStream = responseStream;
- }
- }
- if (wrappedStream != null) {
- // closing the stream should indirectly call the servlet response's flushBuffer
- wrappedStream.close();
- }
- /*
- try {
- //make sure the input stream is also closed in this
- //case so that any resources it may have is cleaned up
- Message m = outMessage.getExchange().getInMessage();
- if (m != null) {
- InputStream ins = m.getContent(InputStream.class);
- if (ins != null) {
- ins.close();
- }
- }
- } catch (IOException ex) {
- //ignore
- }
- */
- }
-
- }
-
- protected boolean contextMatchOnExact() {
- return "exact".equals(contextMatchStrategy);
- }
-
- public void finalizeConfig() {
- }
-
- public String getBeanName() {
- String beanName = null;
- if (endpointInfo.getName() != null) {
- beanName = endpointInfo.getName().toString() + ".http-destination";
- }
- return beanName;
- }
-
- /*
- * Implement multiplex via the address URL to avoid the need for ws-a.
- * Requires contextMatchStrategy of stem.
- *
- * @see org.apache.cxf.transport.AbstractMultiplexDestination#getAddressWithId(java.lang.String)
- */
- public EndpointReferenceType getAddressWithId(String id) {
- final EndpointReferenceType ref;
-
- if (isMultiplexWithAddress()) {
- String address = EndpointReferenceUtils.getAddress(reference);
- ref = EndpointReferenceUtils.duplicate(reference);
- if (address.endsWith("/")) {
- EndpointReferenceUtils.setAddress(ref, address + id);
- } else {
- EndpointReferenceUtils.setAddress(ref, address + "/" + id);
- }
- } else {
- ref = super.getAddressWithId(id);
- }
- return ref;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.apache.cxf.transport.AbstractMultiplexDestination#getId(java.util.Map)
- */
- @Override
- public String getId(Map<String, Object> context) {
- String id = null;
-
- if (isMultiplexWithAddress()) {
- String address = (String)context.get(Message.PATH_INFO);
- if (null != address) {
- int afterLastSlashIndex = address.lastIndexOf('/') + 1;
- if (afterLastSlashIndex > 0
- && afterLastSlashIndex < address.length()) {
- id = address.substring(afterLastSlashIndex);
- }
- } else {
- getLogger().log(Level.WARNING,
- new org.apache.cxf.common.i18n.Message(
- "MISSING_PATH_INFO", LOG).toString());
- }
- } else {
- return super.getId(context);
- }
- return id;
- }
-
- public String getContextMatchStrategy() {
- return contextMatchStrategy;
- }
-
- public void setContextMatchStrategy(String contextMatchStrategy) {
- this.contextMatchStrategy = contextMatchStrategy;
- }
-
- public boolean isFixedParameterOrder() {
- return fixedParameterOrder;
- }
-
- public void setFixedParameterOrder(boolean fixedParameterOrder) {
- this.fixedParameterOrder = fixedParameterOrder;
- }
-
- public boolean isMultiplexWithAddress() {
- return multiplexWithAddress;
- }
-
- public void setMultiplexWithAddress(boolean multiplexWithAddress) {
- this.multiplexWithAddress = multiplexWithAddress;
- }
-
- public HTTPServerPolicy getServer() {
- return calcServerPolicy(null);
- }
-
- public void setServer(HTTPServerPolicy server) {
- this.serverPolicy = server;
- if (server != null) {
- serverPolicyCalced = true;
- }
- }
-
- public void assertMessage(Message message) {
- PolicyDataEngine pde = bus.getExtension(PolicyDataEngine.class);
- pde.assertMessage(message, calcServerPolicy(message), new ServerPolicyCalculator());
- }
-
- public boolean canAssert(QName type) {
- return new ServerPolicyCalculator().getDataClassName().equals(type);
- }
-
- public void releaseRegistry() {
- registry = null;
- }
-
- public String getPath() {
- return path;
- }
-
- @Override
- protected void activate() {
- synchronized (this) {
- if (registry != null) {
- registry.addDestination(this);
- }
- }
- }
- @Override
- protected void deactivate() {
- synchronized (this) {
- if (registry != null) {
- registry.removeDestination(path);
- }
- }
- }
-
- @Override
- public void shutdown() {
- synchronized (this) {
- if (registry != null) {
- registry.removeDestination(path);
- }
- }
- super.shutdown();
- }
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/transport/http/CXFAuthenticator.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/transport/http/CXFAuthenticator.java
deleted file mode 100644
index 6b968f6..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/transport/http/CXFAuthenticator.java
+++ /dev/null
@@ -1,177 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.cxf.transport.http;
-
-import java.io.InputStream;
-import java.lang.reflect.Field;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.net.Authenticator;
-import java.net.PasswordAuthentication;
-import java.net.URL;
-import java.net.URLClassLoader;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
-
-import org.apache.cxf.common.util.ReflectionUtil;
-import org.apache.cxf.helpers.IOUtils;
-import org.apache.cxf.helpers.JavaUtils;
-import org.apache.cxf.message.Exchange;
-import org.apache.cxf.message.Message;
-import org.apache.cxf.phase.PhaseInterceptorChain;
-import org.apache.cxf.transport.Conduit;
-
-/**
- *
- */
-public class CXFAuthenticator extends Authenticator {
- static CXFAuthenticator instance;
-
-
- public CXFAuthenticator() {
- }
-
- public static synchronized void addAuthenticator() {
- if (instance == null) {
- instance = new CXFAuthenticator();
- Authenticator wrapped = null;
- if (JavaUtils.isJava9Compatible()) {
- try {
- Method m = ReflectionUtil.getMethod(Authenticator.class, "getDefault");
- wrapped = (Authenticator)m.invoke(null);
- } catch (Exception e) {
- // ignore
- }
-
-
- } else {
- for (final Field f : ReflectionUtil.getDeclaredFields(Authenticator.class)) {
- if (f.getType().equals(Authenticator.class)) {
- ReflectionUtil.setAccessible(f);
- try {
- wrapped = (Authenticator)f.get(null);
- if (wrapped != null && wrapped.getClass().getName()
- .equals(ReferencingAuthenticator.class.getName())) {
- Method m = wrapped.getClass().getMethod("check");
- m.setAccessible(true);
- m.invoke(wrapped);
- }
- wrapped = (Authenticator)f.get(null);
- } catch (Exception e) {
- // ignore
- }
- }
- }
- }
-
- try {
- Class<?> cls;
- InputStream ins = ReferencingAuthenticator.class
- .getResourceAsStream("ReferencingAuthenticator.class");
- byte[] b = IOUtils.readBytesFromStream(ins);
- if (JavaUtils.isJava9Compatible()) {
- Class<?> methodHandles = Class.forName("java.lang.invoke.MethodHandles");
- Method m = ReflectionUtil.getMethod(methodHandles, "lookup");
- Object lookup = m.invoke(null);
- m = ReflectionUtil.getMethod(lookup.getClass(), "findClass", String.class);
- try {
- cls = (Class<?>)m.invoke(lookup, "org.apache.cxf.transport.http.ReferencingAuthenticator");
- } catch (InvocationTargetException e) {
- //use defineClass as fallback
- m = ReflectionUtil.getMethod(lookup.getClass(), "defineClass", byte[].class);
- cls = (Class<?>)m.invoke(lookup, b);
- }
- } else {
- ClassLoader loader = AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() {
- public ClassLoader run() {
- return new URLClassLoader(new URL[0], ClassLoader.getSystemClassLoader());
- }
- }, null);
- Method m = ReflectionUtil.getDeclaredMethod(ClassLoader.class, "defineClass",
- String.class, byte[].class, Integer.TYPE,
- Integer.TYPE);
-
- ReflectionUtil.setAccessible(m).invoke(loader, ReferencingAuthenticator.class.getName(),
- b, 0, b.length);
- cls = loader.loadClass(ReferencingAuthenticator.class.getName());
- try {
- //clear the acc field that can hold onto the webapp classloader
- Field f = ReflectionUtil.getDeclaredField(loader.getClass(), "acc");
- ReflectionUtil.setAccessible(f).set(loader, null);
- } catch (Throwable t) {
- //ignore
- }
- }
- final Authenticator auth = (Authenticator)cls.getConstructor(Authenticator.class, Authenticator.class)
- .newInstance(instance, wrapped);
-
- if (System.getSecurityManager() == null) {
- Authenticator.setDefault(auth);
- } else {
- AccessController.doPrivileged(new PrivilegedAction<Boolean>() {
- public Boolean run() {
- Authenticator.setDefault(auth);
- return true;
- }
- });
-
- }
-
- } catch (Throwable t) {
- //ignore
- }
- }
- }
-
- protected PasswordAuthentication getPasswordAuthentication() {
- PasswordAuthentication auth = null;
- Message m = PhaseInterceptorChain.getCurrentMessage();
- if (m != null) {
- Exchange exchange = m.getExchange();
- Conduit conduit = exchange.getConduit(m);
- if (conduit instanceof HTTPConduit) {
- HTTPConduit httpConduit = (HTTPConduit)conduit;
- if (getRequestorType() == RequestorType.PROXY
- && httpConduit.getProxyAuthorization() != null) {
- String un = httpConduit.getProxyAuthorization().getUserName();
- String pwd = httpConduit.getProxyAuthorization().getPassword();
- if (un != null && pwd != null) {
- auth = new PasswordAuthentication(un, pwd.toCharArray());
- }
- } else if (getRequestorType() == RequestorType.SERVER
- && httpConduit.getAuthorization() != null) {
-
- if ("basic".equals(getRequestingScheme()) || "digest".equals(getRequestingScheme())) {
- return null;
- }
-
- String un = httpConduit.getAuthorization().getUserName();
- String pwd = httpConduit.getAuthorization().getPassword();
- if (un != null && pwd != null) {
- auth = new PasswordAuthentication(un, pwd.toCharArray());
- }
- }
- }
- }
- // else PhaseInterceptorChain.getCurrentMessage() is null,
- // this HTTP call has therefore not been generated by CXF
- return auth;
- }
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/transport/http/HTTPConduit.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/transport/http/HTTPConduit.java
deleted file mode 100644
index 3904b10..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/transport/http/HTTPConduit.java
+++ /dev/null
@@ -1,1952 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.cxf.transport.http;
-
-import java.beans.PropertyChangeEvent;
-import java.beans.PropertyChangeListener;
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.io.PrintWriter;
-import java.io.StringWriter;
-import java.net.HttpRetryException;
-import java.net.HttpURLConnection;
-import java.net.MalformedURLException;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.Executor;
-import java.util.concurrent.RejectedExecutionException;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import javax.xml.namespace.QName;
-
-import org.apache.cxf.Bus;
-import org.apache.cxf.common.injection.NoJSR250Annotations;
-import org.apache.cxf.common.logging.LogUtils;
-import org.apache.cxf.common.util.PropertyUtils;
-import org.apache.cxf.configuration.Configurable;
-import org.apache.cxf.configuration.jsse.TLSClientParameters;
-import org.apache.cxf.configuration.security.AuthorizationPolicy;
-import org.apache.cxf.configuration.security.CertificateConstraintsType;
-import org.apache.cxf.configuration.security.ProxyAuthorizationPolicy;
-import org.apache.cxf.endpoint.ClientCallback;
-import org.apache.cxf.endpoint.Endpoint;
-import org.apache.cxf.helpers.CastUtils;
-import org.apache.cxf.helpers.HttpHeaderHelper;
-import org.apache.cxf.helpers.IOUtils;
-import org.apache.cxf.helpers.LoadingByteArrayOutputStream;
-import org.apache.cxf.io.AbstractThresholdOutputStream;
-import org.apache.cxf.io.CacheAndWriteOutputStream;
-import org.apache.cxf.io.CachedOutputStream;
-import org.apache.cxf.message.Exchange;
-import org.apache.cxf.message.ExchangeImpl;
-import org.apache.cxf.message.Message;
-import org.apache.cxf.message.MessageContentsList;
-import org.apache.cxf.message.MessageImpl;
-import org.apache.cxf.message.MessageUtils;
-import org.apache.cxf.phase.PhaseInterceptorChain;
-import org.apache.cxf.policy.PolicyDataEngine;
-import org.apache.cxf.service.model.EndpointInfo;
-import org.apache.cxf.transport.AbstractConduit;
-import org.apache.cxf.transport.Assertor;
-import org.apache.cxf.transport.Conduit;
-import org.apache.cxf.transport.MessageObserver;
-import org.apache.cxf.transport.http.auth.CustomAuthSupplier;
-import org.apache.cxf.transport.http.auth.DefaultBasicAuthSupplier;
-import org.apache.cxf.transport.http.auth.DigestAuthSupplier;
-import org.apache.cxf.transport.http.auth.HttpAuthHeader;
-import org.apache.cxf.transport.http.auth.HttpAuthSupplier;
-import org.apache.cxf.transport.http.auth.SpnegoAuthSupplier;
-import org.apache.cxf.transport.http.policy.impl.ClientPolicyCalculator;
-import org.apache.cxf.transport.https.CertConstraints;
-import org.apache.cxf.transport.https.CertConstraintsInterceptor;
-import org.apache.cxf.transport.https.CertConstraintsJaxBUtils;
-import org.apache.cxf.transport.https.HttpsURLConnectionInfo;
-import org.apache.cxf.transports.http.configuration.HTTPClientPolicy;
-import org.apache.cxf.workqueue.AutomaticWorkQueue;
-import org.apache.cxf.workqueue.WorkQueueManager;
-import org.apache.cxf.ws.addressing.EndpointReferenceType;
-
-/*
- * HTTP Conduit implementation.
- * <p>
- * This implementation is a based on the java.net.URLConnection interface and
- * dependent upon installed implementations of that URLConnection,
- * HttpURLConnection, and HttpsURLConnection. Currently, this implementation
- * has been known to work with the Sun JDK 1.5 default implementations. The
- * HttpsURLConnection is part of Sun's implementation of the JSSE.
- * Presently, the source code for the Sun JSSE implementation is unavailable
- * and therefore we may only lay a guess of whether its HttpsURLConnection
- * implementation correctly works as far as security is concerned.
- * <p>
- * The Trust Decision. If a MessageTrustDecider is configured/set for the
- * Conduit, it is called upon the first flush of the headers in the
- * WrappedOutputStream. This reason for this approach is two-fold.
- * Theoretically, in order to get connection information out of the
- * URLConnection, it must be "connected". We assume that its implementation will
- * only follow through up to the point at which it will be ready to send
- * one byte of data down to the endpoint, but through proxies, and the
- * commpletion of a TLS handshake in the case of HttpsURLConnection.
- * However, if we force the connect() call right away, the default
- * implementations will not allow any calls to add/setRequestProperty,
- * throwing an exception that the URLConnection is already connected.
- * <p>
- * We need to keep the semantic that later CXF interceptors may add to the
- * PROTOCOL_HEADERS in the Message. This architectual decision forces us to
- * delay the connection until after that point, then pulling the trust decision.
- * <p>
- * The security caveat is that we don't really know when the connection is
- * really established. The call to "connect" is stated to force the
- * "connection," but it is a no-op if the connection was already established.
- * It is entirely possible that an implementation of an URLConnection may
- * indeed connect at will and start sending the headers down the connection
- * during calls to add/setRequestProperty!
- * <p>
- * We know that the JDK 1.5 sun.com.net.www.HttpURLConnection does not send
- * this information before the "connect" call, because we can look at the
- * source code. However, we can only assume, not verify, that the JSSE 1.5
- * HttpsURLConnection does the same, in that it is probable that the
- * HttpsURLConnection shares the HttpURLConnection implementation.
- * <p>
- * Due to these implementations following redirects without trust checks, we
- * force the URLConnection implementations not to follow redirects. If
- * client side policy dictates that we follow redirects, trust decisions are
- * placed before each retransmit. On a redirect, any authorization information
- * dynamically acquired by a BasicAuth UserPass supplier is removed before
- * being retransmitted, as it may no longer be applicable to the new url to
- * which the connection is redirected.
- */
-
-/**
- * This Conduit handles the "http" and "https" transport protocols. An
- * instance is governed by policies either explicitly set or by
- * configuration.
- */
-@NoJSR250Annotations
-public abstract class HTTPConduit
- extends AbstractConduit
- implements Configurable, Assertor, PropertyChangeListener {
-
-
- /**
- * This constant is the Message(Map) key for the HttpURLConnection that
- * is used to get the response.
- */
- public static final String KEY_HTTP_CONNECTION = "http.connection";
- public static final String KEY_HTTP_CONNECTION_ADDRESS = "http.connection.address";
-
- public static final String SET_HTTP_RESPONSE_MESSAGE = "org.apache.cxf.transport.http.set.response.message";
- public static final String HTTP_RESPONSE_MESSAGE = "http.responseMessage";
-
- public static final String PROCESS_FAULT_ON_HTTP_400 = "org.apache.cxf.transport.process_fault_on_http_400";
- public static final String NO_IO_EXCEPTIONS = "org.apache.cxf.transport.no_io_exceptions";
- /**
- * The Logger for this class.
- */
- protected static final Logger LOG = LogUtils.getL7dLogger(HTTPConduit.class);
-
- private static boolean hasLoggedAsyncWarning;
-
- /**
- * This constant holds the suffix ".http-conduit" that is appended to the
- * Endpoint Qname to give the configuration name of this conduit.
- */
- private static final String SC_HTTP_CONDUIT_SUFFIX = ".http-conduit";
-
- private static final String AUTO_REDIRECT_SAME_HOST_ONLY = "http.redirect.same.host.only";
- private static final String AUTO_REDIRECT_ALLOW_REL_URI = "http.redirect.relative.uri";
- private static final String AUTO_REDIRECT_ALLOWED_URI = "http.redirect.allowed.uri";
- private static final String AUTO_REDIRECT_MAX_SAME_URI_COUNT = "http.redirect.max.same.uri.count";
-
- private static final String HTTP_POST_METHOD = "POST";
- private static final String HTTP_GET_METHOD = "GET";
- private static final Set<String> KNOWN_HTTP_VERBS_WITH_NO_CONTENT =
- new HashSet<>(Arrays.asList(new String[]{"GET", "HEAD", "OPTIONS", "TRACE"}));
- /**
- * This constant is the Message(Map) key for a list of visited URLs that
- * is used in redirect loop protection.
- */
- private static final String KEY_VISITED_URLS = "VisitedURLs";
-
- /**
- * This constant is the Message(Map) key for a list of URLs that
- * is used in authorization loop protection.
- */
- private static final String KEY_AUTH_URLS = "AuthURLs";
-
- /**
- * This field holds a reference to the CXF bus associated this conduit.
- */
- protected final Bus bus;
-
- /**
- * This field is used for two reasons. First it provides the base name for
- * the conduit for Spring configuration. The other is to hold default
- * address information, should it not be supplied in the Message Map, by the
- * Message.ENDPOINT_ADDRESS property.
- */
- protected final EndpointInfo endpointInfo;
-
-
- /**
- * This field holds the "default" URI for this particular conduit, which
- * is created on demand.
- */
- protected volatile Address defaultAddress;
-
- protected boolean fromEndpointReferenceType;
-
- protected ProxyFactory proxyFactory;
-
- // Configurable values
-
- /**
- * This field holds the QoS configuration settings for this conduit.
- * This field is injected via spring configuration based on the conduit
- * name.
- */
- protected HTTPClientPolicy clientSidePolicy;
-
- /**
- * This field holds the password authorization configuration.
- * This field is injected via spring configuration based on the conduit
- * name.
- */
- protected AuthorizationPolicy authorizationPolicy;
-
- /**
- * This field holds the password authorization configuration for the
- * configured proxy. This field is injected via spring configuration based
- * on the conduit name.
- */
- protected ProxyAuthorizationPolicy proxyAuthorizationPolicy;
-
- /**
- * This field holds the configuration TLS configuration which
- * is programmatically configured.
- */
- protected TLSClientParameters tlsClientParameters;
-
- /**
- * This field contains the MessageTrustDecider.
- */
- protected MessageTrustDecider trustDecider;
-
- /**
- * Implements the authentication handling when talking to a server. If it is not set
- * it will be created from the authorizationPolicy.authType
- */
- protected volatile HttpAuthSupplier authSupplier;
-
- /**
- * Implements the proxy authentication handling. If it is not set
- * it will be created from the proxyAuthorizationPolicy.authType
- */
- protected volatile HttpAuthSupplier proxyAuthSupplier;
-
- protected Cookies cookies;
-
- protected CertConstraints certConstraints;
-
- private volatile boolean clientSidePolicyCalced;
-
-
- /**
- * Constructor
- *
- * @param b the associated Bus
- * @param ei the endpoint info of the initiator
- * @throws IOException
- */
- public HTTPConduit(Bus b, EndpointInfo ei) throws IOException {
- this(b,
- ei,
- null);
- }
-
- /**
- * Constructor
- *
- * @param b the associated Bus.
- * @param ei the endpoint info of the initiator.
- * @param t the endpoint reference of the target.
- * @throws IOException
- */
- public HTTPConduit(Bus b,
- EndpointInfo ei,
- EndpointReferenceType t) throws IOException {
- super(getTargetReference(ei, t, b));
-
- bus = b;
- endpointInfo = ei;
-
- if (t != null) {
- fromEndpointReferenceType = true;
- }
- proxyFactory = new ProxyFactory();
- cookies = new Cookies();
- }
-
- /**
- * updates the HTTPClientPolicy that is compatible with the assertions
- * included in the service, endpoint, operation and message policy subjects
- * if a PolicyDataEngine is installed
- *
- * wsdl extensors are superseded by policies which in
- * turn are superseded by injection
- */
- private void updateClientPolicy(Message m) {
- if (!clientSidePolicyCalced) {
- PolicyDataEngine policyEngine = bus.getExtension(PolicyDataEngine.class);
- if (policyEngine != null && endpointInfo.getService() != null) {
- clientSidePolicy = policyEngine.getClientEndpointPolicy(m,
- endpointInfo,
- this,
- new ClientPolicyCalculator());
- if (clientSidePolicy != null) {
- clientSidePolicy.removePropertyChangeListener(this); //make sure we aren't added twice
- clientSidePolicy.addPropertyChangeListener(this);
- }
- }
- }
- clientSidePolicyCalced = true;
- }
-
- private void updateClientPolicy() {
- if (!clientSidePolicyCalced) {
- //do no spend time on building Message and Exchange (which basically
- //are ConcurrentHashMap instances) if the policy is already available
- Message m = new MessageImpl();
- m.setExchange(new ExchangeImpl());
- m.getExchange().put(EndpointInfo.class, this.endpointInfo);
- updateClientPolicy(m);
- }
- }
-
- /**
- * This method returns the registered Logger for this conduit.
- */
- protected Logger getLogger() {
- return LOG;
- }
-
- /**
- * This method returns the name of the conduit, which is based on the
- * endpoint name plus the SC_HTTP_CONDUIT_SUFFIX.
- * @return
- */
- public final String getConduitName() {
- return endpointInfo.getName() + SC_HTTP_CONDUIT_SUFFIX;
- }
-
- private static void configureConduitFromEndpointInfo(HTTPConduit conduit,
- EndpointInfo endpointInfo) {
- if (conduit.getClient() == null) {
- conduit.setClient(endpointInfo.getTraversedExtensor(
- new HTTPClientPolicy(), HTTPClientPolicy.class));
- }
- if (conduit.getAuthorization() == null) {
- conduit.setAuthorization(endpointInfo.getTraversedExtensor(
- new AuthorizationPolicy(), AuthorizationPolicy.class));
-
- }
- if (conduit.getProxyAuthorization() == null) {
- conduit.setProxyAuthorization(endpointInfo.getTraversedExtensor(
- new ProxyAuthorizationPolicy(),
- ProxyAuthorizationPolicy.class));
-
- }
- if (conduit.getTlsClientParameters() == null) {
- conduit.setTlsClientParameters(endpointInfo.getTraversedExtensor(
- null, TLSClientParameters.class));
- }
- if (conduit.getTrustDecider() == null) {
- conduit.setTrustDecider(endpointInfo.getTraversedExtensor(null,
- MessageTrustDecider.class));
- }
- if (conduit.getAuthSupplier() == null) {
- conduit.setAuthSupplier(endpointInfo.getTraversedExtensor(null,
- HttpAuthSupplier.class));
- }
- }
-
- private void logConfig() {
- if (!LOG.isLoggable(Level.FINE)) {
- return;
- }
- if (trustDecider == null) {
- LOG.log(Level.FINE,
- "No Trust Decider configured for Conduit '"
- + getConduitName() + "'");
- } else {
- LOG.log(Level.FINE, "Message Trust Decider of class '"
- + trustDecider.getClass().getName()
- + "' with logical name of '"
- + trustDecider.getLogicalName()
- + "' has been configured for Conduit '"
- + getConduitName()
- + "'");
- }
- if (authSupplier == null) {
- LOG.log(Level.FINE,
- "No Auth Supplier configured for Conduit '"
- + getConduitName() + "'");
- } else {
- LOG.log(Level.FINE, "HttpAuthSupplier of class '"
- + authSupplier.getClass().getName()
- + "' has been configured for Conduit '"
- + getConduitName()
- + "'");
- }
- if (this.tlsClientParameters != null) {
- LOG.log(Level.FINE, "Conduit '" + getConduitName()
- + "' has been configured for TLS "
- + "keyManagers " + Arrays.toString(tlsClientParameters.getKeyManagers())
- + "trustManagers " + Arrays.toString(tlsClientParameters.getTrustManagers())
- + "secureRandom " + tlsClientParameters.getSecureRandom()
- + "Disable Common Name (CN) Check: " + tlsClientParameters.isDisableCNCheck());
-
- } else {
- LOG.log(Level.FINE, "Conduit '" + getConduitName()
- + "' has been configured for plain http.");
- }
- }
-
- /**
- * This call gets called by the HTTPTransportFactory after it
- * causes an injection of the Spring configuration properties
- * of this Conduit.
- */
- public void finalizeConfig() {
- // See if not set by configuration, if there are defaults
- // in order from the Endpoint, Service, or Bus.
-
- configureConduitFromEndpointInfo(this, endpointInfo);
- logConfig();
-
- if (getClient().getDecoupledEndpoint() != null) {
- this.endpointInfo.setProperty("org.apache.cxf.ws.addressing.replyto",
- getClient().getDecoupledEndpoint());
- }
- }
-
- /**
- * Allow access to the cookies that the conduit is maintaining
- * @return the sessionCookies map
- */
- public Map<String, Cookie> getCookies() {
- return cookies.getSessionCookies();
- }
-
-
- protected abstract void setupConnection(Message message, Address address, HTTPClientPolicy csPolicy)
- throws IOException;
-
- /**
- * Prepare to send an outbound HTTP message over this http conduit to a
- * particular endpoint.
- * <P>
- * If the Message.PATH_INFO property is set it gets appended
- * to the Conduit's endpoint URL. If the Message.QUERY_STRING
- * property is set, it gets appended to the resultant URL following
- * a "?".
- * <P>
- * If the Message.HTTP_REQUEST_METHOD property is NOT set, the
- * Http request method defaults to "POST".
- * <P>
- * If the Message.PROTOCOL_HEADERS is not set on the message, it is
- * initialized to an empty map.
- * <P>
- * This call creates the OutputStream for the content of the message.
- * It also assigns the created Http(s)URLConnection to the Message
- * Map.
- *
- * @param message The message to be sent.
- */
- public void prepare(Message message) throws IOException {
- // This call can possibly change the conduit endpoint address and
- // protocol from the default set in EndpointInfo that is associated
- // with the Conduit.
- Address currentAddress;
- try {
- currentAddress = setupAddress(message);
- } catch (URISyntaxException e) {
- throw new IOException(e);
- }
-
- // The need to cache the request is off by default
- boolean needToCacheRequest = false;
-
- HTTPClientPolicy csPolicy = getClient(message);
- setupConnection(message, currentAddress, csPolicy);
-
- // If the HTTP_REQUEST_METHOD is not set, the default is "POST".
- String httpRequestMethod =
- (String)message.get(Message.HTTP_REQUEST_METHOD);
- if (httpRequestMethod == null) {
- httpRequestMethod = "POST";
- message.put(Message.HTTP_REQUEST_METHOD, "POST");
- }
-
- boolean isChunking = false;
- int chunkThreshold = 0;
- final AuthorizationPolicy effectiveAuthPolicy = getEffectiveAuthPolicy(message);
- if (this.authSupplier == null) {
- this.authSupplier = createAuthSupplier(effectiveAuthPolicy);
- }
-
- if (this.proxyAuthSupplier == null) {
- this.proxyAuthSupplier = createAuthSupplier(proxyAuthorizationPolicy);
- }
-
- if (this.authSupplier.requiresRequestCaching()) {
- needToCacheRequest = true;
- isChunking = false;
- LOG.log(Level.FINE,
- "Auth Supplier, but no Preemptive User Pass or Digest auth (nonce may be stale)"
- + " We must cache request.");
- }
- if (csPolicy.isAutoRedirect()) {
- needToCacheRequest = true;
- LOG.log(Level.FINE, "AutoRedirect is turned on.");
- }
- if (csPolicy.getMaxRetransmits() > 0) {
- needToCacheRequest = true;
- LOG.log(Level.FINE, "MaxRetransmits is set > 0.");
- }
- // DELETE does not work and empty PUTs cause misleading exceptions
- // if chunking is enabled
- // TODO : ensure chunking can be enabled for non-empty PUTs - if requested
- if (csPolicy.isAllowChunking()
- && isChunkingSupported(message, httpRequestMethod)) {
- //TODO: The chunking mode be configured or at least some
- // documented client constant.
- //use -1 and allow the URL connection to pick a default value
- isChunking = true;
- chunkThreshold = csPolicy.getChunkingThreshold();
- }
- cookies.writeToMessageHeaders(message);
-
- // The trust decision is relegated to after the "flushing" of the
- // request headers.
-
-
-
- if (certConstraints != null) {
- message.put(CertConstraints.class.getName(), certConstraints);
- message.getInterceptorChain().add(CertConstraintsInterceptor.INSTANCE);
- }
-
- setHeadersByAuthorizationPolicy(message, currentAddress.getURI());
- new Headers(message).setFromClientPolicy(getClient(message));
-
- // set the OutputStream on the ProxyOutputStream
- ProxyOutputStream pos = message.getContent(ProxyOutputStream.class);
- if (pos != null && message.getContent(OutputStream.class) != null) {
- pos.setWrappedOutputStream(createOutputStream(message,
- needToCacheRequest,
- isChunking,
- chunkThreshold));
- } else {
- message.setContent(OutputStream.class,
- createOutputStream(message,
- needToCacheRequest,
- isChunking,
- chunkThreshold));
- }
- // We are now "ready" to "send" the message.
- }
-
- protected boolean isChunkingSupported(Message message, String httpMethod) {
- if (HTTP_POST_METHOD.equals(httpMethod)) {
- return true;
- } else if (!HTTP_GET_METHOD.equals(httpMethod)) {
- MessageContentsList objs = MessageContentsList.getContentsList(message);
- if (objs != null && !objs.isEmpty()) {
- Object obj = objs.get(0);
- return obj.getClass() != String.class
- || (obj.getClass() == String.class && ((String)obj).length() > 0);
- }
- }
- return false;
- }
-
- protected abstract OutputStream createOutputStream(Message message,
- boolean needToCacheRequest,
- boolean isChunking,
- int chunkThreshold) throws IOException;
-
- private HttpAuthSupplier createAuthSupplier(AuthorizationPolicy authzPolicy) {
- String authType = authzPolicy.getAuthorizationType();
- if (HttpAuthHeader.AUTH_TYPE_NEGOTIATE.equals(authType)) {
- return new SpnegoAuthSupplier();
- } else if (HttpAuthHeader.AUTH_TYPE_DIGEST.equals(authType)) {
- return new DigestAuthSupplier();
- } else if (authType != null && !HttpAuthHeader.AUTH_TYPE_BASIC.equals(authType)
- && authzPolicy.getAuthorization() != null) {
- return new CustomAuthSupplier();
- } else {
- return new DefaultBasicAuthSupplier();
- }
- }
-
- protected static int determineReceiveTimeout(Message message,
- HTTPClientPolicy csPolicy) {
- long rtimeout = csPolicy.getReceiveTimeout();
- if (message.get(Message.RECEIVE_TIMEOUT) != null) {
- Object obj = message.get(Message.RECEIVE_TIMEOUT);
- try {
- rtimeout = Long.parseLong(obj.toString());
- } catch (NumberFormatException e) {
- LOG.log(Level.WARNING, "INVALID_TIMEOUT_FORMAT", new Object[] {
- Message.RECEIVE_TIMEOUT, obj.toString()
- });
- }
- }
- if (rtimeout > Integer.MAX_VALUE) {
- rtimeout = Integer.MAX_VALUE;
- }
- return (int)rtimeout;
- }
-
- protected static int determineConnectionTimeout(Message message,
- HTTPClientPolicy csPolicy) {
- long ctimeout = csPolicy.getConnectionTimeout();
- if (message.get(Message.CONNECTION_TIMEOUT) != null) {
- Object obj = message.get(Message.CONNECTION_TIMEOUT);
- try {
- ctimeout = Long.parseLong(obj.toString());
- } catch (NumberFormatException e) {
- LOG.log(Level.WARNING, "INVALID_TIMEOUT_FORMAT", new Object[] {
- Message.CONNECTION_TIMEOUT, obj.toString()
- });
- }
- }
- if (ctimeout > Integer.MAX_VALUE) {
- ctimeout = Integer.MAX_VALUE;
- }
- return (int)ctimeout;
- }
-
- public void close(Message msg) throws IOException {
- InputStream in = msg.getContent(InputStream.class);
- try {
- if (in != null) {
- int count = 0;
- byte[] buffer = new byte[1024];
- while (in.read(buffer) != -1
- && count < 25) {
- //don't do anything, we just need to pull off the unread data (like
- //closing tags that we didn't need to read
-
- //however, limit it so we don't read off gigabytes of data we won't use.
- ++count;
- }
- }
- } finally {
- super.close(msg);
- }
- }
-
- /**
- * This function sets up a URL based on ENDPOINT_ADDRESS, PATH_INFO,
- * and QUERY_STRING properties in the Message. The QUERY_STRING gets
- * added with a "?" after the PATH_INFO. If the ENDPOINT_ADDRESS is not
- * set on the Message, the endpoint address is taken from the
- * "defaultEndpointURL".
- * <p>
- * The PATH_INFO is only added to the endpoint address string should
- * the PATH_INFO not equal the end of the endpoint address string.
- *
- * @param message The message holds the addressing information.
- *
- * @return The full URL specifying the HTTP request to the endpoint.
- *
- * @throws MalformedURLException
- * @throws URISyntaxException
- */
- private Address setupAddress(Message message) throws URISyntaxException {
- String result = (String)message.get(Message.ENDPOINT_ADDRESS);
- String pathInfo = (String)message.get(Message.PATH_INFO);
- String queryString = (String)message.get(Message.QUERY_STRING);
- setAndGetDefaultAddress();
- if (result == null) {
- if (pathInfo == null && queryString == null) {
- if (defaultAddress != null) {
- message.put(Message.ENDPOINT_ADDRESS, defaultAddress.getString());
- }
- return defaultAddress;
- }
- if (defaultAddress != null) {
- result = defaultAddress.getString();
- message.put(Message.ENDPOINT_ADDRESS, result);
- }
- }
-
- // REVISIT: is this really correct?
- if (null != pathInfo && !result.endsWith(pathInfo)) {
- result = result + pathInfo;
- }
- if (queryString != null) {
- result = result + "?" + queryString;
- }
- if (defaultAddress == null) {
- return setAndGetDefaultAddress(result);
- }
- return result.equals(defaultAddress.getString()) ? defaultAddress : new Address(result);
- }
-
- /**
- * Close the conduit
- */
- public void close() {
- if (clientSidePolicy != null) {
- clientSidePolicy.removePropertyChangeListener(this);
- }
- }
-
- /**
- * @return the default target address
- */
- public String getAddress() {
- if (defaultAddress != null) {
- return defaultAddress.getString();
- } else if (fromEndpointReferenceType) {
- return getTarget().getAddress().getValue();
- }
- return endpointInfo.getAddress();
- }
-
- /**
- * @return the default target URL
- */
- protected URI getURI() throws URISyntaxException {
- return setAndGetDefaultAddress().getURI();
- }
-
- private Address setAndGetDefaultAddress() throws URISyntaxException {
- if (defaultAddress == null) {
- synchronized (this) {
- if (defaultAddress == null) {
- if (fromEndpointReferenceType && getTarget().getAddress().getValue() != null) {
- defaultAddress = new Address(this.getTarget().getAddress().getValue());
- } else if (endpointInfo.getAddress() != null) {
- defaultAddress = new Address(endpointInfo.getAddress());
- }
- }
- }
- }
- return defaultAddress;
- }
-
- private Address setAndGetDefaultAddress(String curAddr) throws URISyntaxException {
- if (defaultAddress == null) {
- synchronized (this) {
- if (defaultAddress == null) {
- if (curAddr != null) {
- defaultAddress = new Address(curAddr);
- } else {
- throw new URISyntaxException("<null>",
- "Invalid address. Endpoint address cannot be null.", 0);
- }
- }
- }
- }
- return defaultAddress;
- }
- /**
- * This call places HTTP Header strings into the headers that are relevant
- * to the Authorization policies that are set on this conduit by
- * configuration.
- * <p>
- * An AuthorizationPolicy may also be set on the message. If so, those
- * policies are merged. A user name or password set on the messsage
- * overrides settings in the AuthorizationPolicy is retrieved from the
- * configuration.
- * <p>
- * The precedence is as follows:
- * 1. AuthorizationPolicy that is set on the Message, if exists.
- * 2. Authorization from AuthSupplier, if exists.
- * 3. AuthorizationPolicy set/configured for conduit.
- *
- * REVISIT: Since the AuthorizationPolicy is set on the message by class, then
- * how does one override the ProxyAuthorizationPolicy which is the same
- * type?
- *
- * @param message
- * @param currentURI
- */
- protected void setHeadersByAuthorizationPolicy(
- Message message,
- URI currentURI
- ) {
- Headers headers = new Headers(message);
- AuthorizationPolicy effectiveAuthPolicy = getEffectiveAuthPolicy(message);
- String authString = authSupplier.getAuthorization(effectiveAuthPolicy, currentURI, message, null);
- if (authString != null) {
- headers.setAuthorization(authString);
- }
-
- String proxyAuthString = proxyAuthSupplier.getAuthorization(proxyAuthorizationPolicy,
- currentURI, message, null);
- if (proxyAuthString != null) {
- headers.setProxyAuthorization(proxyAuthString);
- }
- }
-
- /**
- * This is part of the Configurable interface which retrieves the
- * configuration from spring injection.
- */
- // REVISIT:What happens when the endpoint/bean name is null?
- public String getBeanName() {
- if (endpointInfo.getName() != null) {
- return endpointInfo.getName().toString() + ".http-conduit";
- }
- return null;
- }
-
- /**
- * Determines effective auth policy from message, conduit and empty default
- * with priority from first to last
- *
- * @param message
- * @return effective AthorizationPolicy
- */
- public AuthorizationPolicy getEffectiveAuthPolicy(Message message) {
- AuthorizationPolicy authPolicy = getAuthorization();
- AuthorizationPolicy newPolicy = message.get(AuthorizationPolicy.class);
- AuthorizationPolicy effectivePolicy = newPolicy;
- if (effectivePolicy == null) {
- effectivePolicy = authPolicy;
- }
- if (effectivePolicy == null) {
- effectivePolicy = new AuthorizationPolicy();
- }
- return effectivePolicy;
- }
-
- /**
- * This method gets the Authorization Policy that was configured or
- * explicitly set for this HTTPConduit.
- */
- public AuthorizationPolicy getAuthorization() {
- return authorizationPolicy;
- }
-
- /**
- * This method is used to set the Authorization Policy for this conduit.
- * Using this method will override any Authorization Policy set in
- * configuration.
- */
- public void setAuthorization(AuthorizationPolicy authorization) {
- this.authorizationPolicy = authorization;
- }
-
- public HTTPClientPolicy getClient(Message message) {
- ClientPolicyCalculator cpc = new ClientPolicyCalculator();
- HTTPClientPolicy pol = message.get(HTTPClientPolicy.class);
- updateClientPolicy(message);
- if (pol != null) {
- pol = cpc.intersect(pol, clientSidePolicy);
- } else {
- pol = clientSidePolicy;
- }
-
- PolicyDataEngine policyDataEngine = bus.getExtension(PolicyDataEngine.class);
- if (policyDataEngine == null) {
- return pol;
- }
- return policyDataEngine.getPolicy(message, pol, cpc);
- }
-
- /**
- * This method retrieves the Client Side Policy set/configured for this
- * HTTPConduit.
- */
- public HTTPClientPolicy getClient() {
- updateClientPolicy();
- return clientSidePolicy;
- }
-
- /**
- * This method sets the Client Side Policy for this HTTPConduit. Using this
- * method will override any HTTPClientPolicy set in configuration.
- */
- public void setClient(HTTPClientPolicy client) {
- if (this.clientSidePolicy != null) {
- this.clientSidePolicy.removePropertyChangeListener(this);
- }
- this.clientSidePolicyCalced = true;
- this.clientSidePolicy = client;
- clientSidePolicy.removePropertyChangeListener(this); //make sure we aren't added twice
- clientSidePolicy.addPropertyChangeListener(this);
- endpointInfo.setProperty("org.apache.cxf.ws.addressing.replyto", client.getDecoupledEndpoint());
- }
-
- /**
- * This method retrieves the Proxy Authorization Policy for a proxy that is
- * set/configured for this HTTPConduit.
- */
- public ProxyAuthorizationPolicy getProxyAuthorization() {
- return proxyAuthorizationPolicy;
- }
-
- /**
- * This method sets the Proxy Authorization Policy for a specified proxy.
- * Using this method overrides any Authorization Policy for the proxy
- * that is set in the configuration.
- */
- public void setProxyAuthorization(
- ProxyAuthorizationPolicy proxyAuthorization
- ) {
- this.proxyAuthorizationPolicy = proxyAuthorization;
- }
-
- /**
- * This method returns the TLS Client Parameters that is set/configured
- * for this HTTPConduit.
- */
- public TLSClientParameters getTlsClientParameters() {
- return tlsClientParameters;
- }
-
- /**
- * This method sets the TLS Client Parameters for this HTTPConduit.
- * Using this method overrides any TLS Client Parameters that is configured
- * for this HTTPConduit.
- */
- public void setTlsClientParameters(TLSClientParameters params) {
- this.tlsClientParameters = params;
- if (this.tlsClientParameters != null) {
- if (LOG.isLoggable(Level.FINE)) {
- LOG.log(Level.FINE, "Conduit '" + getConduitName()
- + "' has been (re) configured for TLS "
- + "keyManagers " + Arrays.toString(tlsClientParameters.getKeyManagers())
- + "trustManagers " + Arrays.toString(tlsClientParameters.getTrustManagers())
- + "secureRandom " + tlsClientParameters.getSecureRandom());
- }
- CertificateConstraintsType constraints = params.getCertConstraints();
- if (constraints != null) {
- certConstraints = CertConstraintsJaxBUtils.createCertConstraints(constraints);
- }
- } else {
- if (LOG.isLoggable(Level.FINE)) {
- LOG.log(Level.FINE, "Conduit '" + getConduitName()
- + "' has been (re)configured for plain http.");
- }
- }
- }
-
- /**
- * This method gets the Trust Decider that was set/configured for this
- * HTTPConduit.
- * @return The Message Trust Decider or null.
- */
- public MessageTrustDecider getTrustDecider() {
- return this.trustDecider;
- }
-
- /**
- * This method sets the Trust Decider for this HTTP Conduit.
- * Using this method overrides any trust decider configured for this
- * HTTPConduit.
- */
- public void setTrustDecider(MessageTrustDecider decider) {
- this.trustDecider = decider;
- }
-
- /**
- * This method gets the Auth Supplier that was set/configured for this
- * HTTPConduit.
- * @return The Auth Supplier or null.
- */
- public HttpAuthSupplier getAuthSupplier() {
- return this.authSupplier;
- }
-
- public void setAuthSupplier(HttpAuthSupplier supplier) {
- this.authSupplier = supplier;
- }
-
- public HttpAuthSupplier getProxyAuthSupplier() {
- return proxyAuthSupplier;
- }
-
- public void setProxyAuthSupplier(HttpAuthSupplier proxyAuthSupplier) {
- this.proxyAuthSupplier = proxyAuthSupplier;
- }
-
-
- /**
- * This method extracts the value of the "Location" Http
- * Response header.
- *
- * @param headers The Http response headers.
- * @return The value of the "Location" header, null if non-existent.
- * @throws MalformedURLException
- */
- protected String extractLocation(Map<String, List<String>> headers) throws MalformedURLException {
- for (Map.Entry<String, List<String>> head : headers.entrySet()) {
- if ("Location".equalsIgnoreCase(head.getKey())) {
- List<String> locs = head.getValue();
- if (locs != null && !locs.isEmpty()) {
- String location = locs.get(0);
- if (location != null) {
- return location;
- }
- return null;
- }
- }
- }
- return null;
- }
-
-
- /**
- * Used to set appropriate message properties, exchange etc.
- * as required for an incoming decoupled response (as opposed
- * what's normally set by the Destination for an incoming
- * request).
- */
- protected class InterposedMessageObserver implements MessageObserver {
- /**
- * Called for an incoming message.
- *
- * @param inMessage
- */
- public void onMessage(Message inMessage) {
- // disposable exchange, swapped with real Exchange on correlation
- inMessage.setExchange(new ExchangeImpl());
- inMessage.getExchange().put(Bus.class, bus);
- inMessage.put(Message.DECOUPLED_CHANNEL_MESSAGE, Boolean.TRUE);
- // REVISIT: how to get response headers?
- //inMessage.put(Message.PROTOCOL_HEADERS, req.getXXX());
- Headers.getSetProtocolHeaders(inMessage);
- inMessage.put(Message.RESPONSE_CODE, HttpURLConnection.HTTP_OK);
-
- // remove server-specific properties
- inMessage.remove(AbstractHTTPDestination.HTTP_REQUEST);
- inMessage.remove(AbstractHTTPDestination.HTTP_RESPONSE);
- inMessage.remove(Message.ASYNC_POST_RESPONSE_DISPATCH);
-
- //cache this inputstream since it's defer to use in case of async
- try {
- InputStream in = inMessage.getContent(InputStream.class);
- if (in != null) {
- CachedOutputStream cos = new CachedOutputStream();
- IOUtils.copy(in, cos);
- inMessage.setContent(InputStream.class, cos.getInputStream());
- }
- incomingObserver.onMessage(inMessage);
- } catch (IOException e) {
- logStackTrace(e);
- }
- }
- }
-
- protected void logStackTrace(Throwable ex) {
- StringWriter sw = new StringWriter();
- ex.printStackTrace(new PrintWriter(sw));
- LOG.warning(sw.toString());
- }
-
- public void assertMessage(Message message) {
- PolicyDataEngine policyDataEngine = bus.getExtension(PolicyDataEngine.class);
- policyDataEngine.assertMessage(message, getClient(), new ClientPolicyCalculator());
- }
-
- public boolean canAssert(QName type) {
- return type.equals(new QName("http://cxf.apache.org/transports/http/configuration", "client"));
- }
-
- public void propertyChange(PropertyChangeEvent evt) {
- if (evt.getSource() == clientSidePolicy
- && "decoupledEndpoint".equals(evt.getPropertyName())) {
- this.endpointInfo.setProperty("org.apache.cxf.ws.addressing.replyto",
- evt.getNewValue());
- }
- }
-
-
-
- /**
- * Wrapper output stream responsible for flushing headers and handling
- * the incoming HTTP-level response (not necessarily the MEP response).
- */
- protected abstract class WrappedOutputStream extends AbstractThresholdOutputStream {
- /**
- * This boolean is true if the request must be cached.
- */
- protected boolean cachingForRetransmission;
-
- /**
- * If we are going to be chunking, we won't flush till close which causes
- * new chunks, small network packets, etc..
- */
- protected final boolean chunking;
-
- /**
- * This field contains the output stream with which we cache
- * the request. It maybe null if we are not caching.
- */
- protected CacheAndWriteOutputStream cachedStream;
-
- protected Message outMessage;
-
- protected String conduitName;
-
- protected URI url;
-
- protected WrappedOutputStream(
- Message outMessage,
- boolean possibleRetransmit,
- boolean isChunking,
- int chunkThreshold,
- String conduitName,
- URI url
- ) {
- super(chunkThreshold);
- this.outMessage = outMessage;
- this.cachingForRetransmission = possibleRetransmit;
- this.chunking = isChunking;
- this.conduitName = conduitName;
- this.url = url;
- }
-
- // This construction makes extending the HTTPConduit more easier
- protected WrappedOutputStream(WrappedOutputStream wos) {
- super(wos.threshold);
- this.outMessage = wos.outMessage;
- this.cachingForRetransmission = wos.cachingForRetransmission;
- this.chunking = wos.chunking;
- this.conduitName = wos.conduitName;
- this.url = wos.url;
- }
-
- @Override
- public void thresholdNotReached() {
- if (chunking) {
- setFixedLengthStreamingMode(buffer.size());
- }
- }
-
- // methods used for the outgoing side
- protected abstract void setupWrappedStream() throws IOException;
- protected abstract HttpsURLConnectionInfo getHttpsURLConnectionInfo() throws IOException;
- protected abstract void setProtocolHeaders() throws IOException;
- protected abstract void setFixedLengthStreamingMode(int i);
-
-
- // methods used for the incoming side
- protected abstract int getResponseCode() throws IOException;
- protected abstract String getResponseMessage() throws IOException;
- protected abstract void updateResponseHeaders(Message inMessage) throws IOException;
- protected abstract void handleResponseAsync() throws IOException;
- protected abstract void closeInputStream() throws IOException;
- protected abstract boolean usingProxy();
- protected abstract InputStream getInputStream() throws IOException;
- protected abstract InputStream getPartialResponse() throws IOException;
-
- //methods to support retransmission for auth or redirects
- protected abstract void setupNewConnection(String newURL) throws IOException;
- protected abstract void retransmitStream() throws IOException;
- protected abstract void updateCookiesBeforeRetransmit() throws IOException;
-
-
- protected void handleNoOutput() throws IOException {
- //For GET and DELETE and such, this will be called
- //For some implementations, this notice may be required to
- //actually execute the request
- }
-
-
- protected void handleResponseOnWorkqueue(boolean allowCurrentThread, boolean forceWQ) throws IOException {
- Runnable runnable = new Runnable() {
- public void run() {
- try {
- handleResponseInternal();
- } catch (Throwable e) {
- ((PhaseInterceptorChain)outMessage.getInterceptorChain()).abort();
- outMessage.setContent(Exception.class, e);
- ((PhaseInterceptorChain)outMessage.getInterceptorChain()).unwind(outMessage);
- MessageObserver mo = outMessage.getInterceptorChain().getFaultObserver();
- if (mo == null) {
- mo = outMessage.getExchange().get(MessageObserver.class);
- }
- mo.onMessage(outMessage);
- }
- }
- };
- HTTPClientPolicy policy = getClient(outMessage);
- boolean exceptionSet = outMessage.getContent(Exception.class) != null;
- if (!exceptionSet) {
- try {
- Executor ex = outMessage.getExchange().get(Executor.class);
- if (forceWQ && ex != null) {
- final Executor ex2 = ex;
- final Runnable origRunnable = runnable;
- runnable = new Runnable() {
- public void run() {
- outMessage.getExchange().put(Executor.class.getName()
- + ".USING_SPECIFIED", Boolean.TRUE);
- ex2.execute(origRunnable);
- }
- };
- }
- if (ex == null || forceWQ) {
- WorkQueueManager mgr = outMessage.getExchange().getBus()
- .getExtension(WorkQueueManager.class);
- AutomaticWorkQueue qu = mgr.getNamedWorkQueue("http-conduit");
- if (qu == null) {
- qu = mgr.getAutomaticWorkQueue();
- }
- long timeout = 1000;
- if (policy != null && policy.isSetAsyncExecuteTimeout()) {
- timeout = policy.getAsyncExecuteTimeout();
- }
- if (timeout > 0) {
- qu.execute(runnable, timeout);
- } else {
- qu.execute(runnable);
- }
- } else {
- outMessage.getExchange().put(Executor.class.getName()
- + ".USING_SPECIFIED", Boolean.TRUE);
- ex.execute(runnable);
- }
- } catch (RejectedExecutionException rex) {
- if (!allowCurrentThread
- || (policy != null
- && policy.isSetAsyncExecuteTimeoutRejection()
- && policy.isAsyncExecuteTimeoutRejection())) {
- throw rex;
- }
- if (!hasLoggedAsyncWarning) {
- LOG.warning("EXECUTOR_FULL_WARNING");
- hasLoggedAsyncWarning = true;
- }
- LOG.fine("EXECUTOR_FULL");
- handleResponseInternal();
- }
- }
- }
-
-
- protected void retransmit(String newURL) throws IOException {
- setupNewConnection(newURL);
- if (cachedStream != null && cachedStream.size() < Integer.MAX_VALUE) {
- setFixedLengthStreamingMode((int)cachedStream.size());
- }
- setProtocolHeaders();
-
- //
- // This point is where the trust decision is made because the
- // Sun implementation of URLConnection will not let us
- // set/addRequestProperty after a connect() call, and
- // makeTrustDecision needs to make a connect() call to
- // make sure the proper information is available.
- //
- makeTrustDecision();
-
- // If this is a GET method we must not touch the output
- // stream as this automagically turns the request into a POST.
- if ("GET".equals(getMethod()) || cachedStream == null) {
- handleNoOutput();
- return;
- }
-
- // Trust is okay, write the cached request
- retransmitStream();
-
- if (LOG.isLoggable(Level.FINE)) {
- LOG.fine("Conduit \""
- + getConduitName()
- + "\" Retransmit message to: "
- + newURL
- + ": "
- + new String(cachedStream.getBytes()));
- }
- }
-
-
- /**
- * Perform any actions required on stream flush (freeze headers,
- * reset output stream ... etc.)
- */
- @Override
- protected void onFirstWrite() throws IOException {
- try {
- handleHeadersTrustCaching();
- } catch (IOException e) {
- if (e.getMessage() != null && e.getMessage().contains("HTTPS hostname wrong:")) {
- throw new IOException("The https URL hostname does not match the "
- + "Common Name (CN) on the server certificate in the client's truststore. "
- + "Make sure server certificate is correct, or to disable this check "
- + "(NOT recommended for production) set the CXF client TLS "
- + "configuration property \"disableCNCheck\" to true.");
- }
- throw e;
- }
- }
- protected String getMethod() {
- return (String)outMessage.get(Message.HTTP_REQUEST_METHOD);
- }
-
-
- protected void handleHeadersTrustCaching() throws IOException {
- // Need to set the headers before the trust decision
- // because they are set before the connect().
- setProtocolHeaders();
-
- //
- // This point is where the trust decision is made because the
- // Sun implementation of URLConnection will not let us
- // set/addRequestProperty after a connect() call, and
- // makeTrustDecision needs to make a connect() call to
- // make sure the proper information is available.
- //
- makeTrustDecision();
-
- // Trust is okay, set up for writing the request.
-
- String method = getMethod();
- if (KNOWN_HTTP_VERBS_WITH_NO_CONTENT.contains(method)
- || PropertyUtils.isTrue(outMessage.get(Headers.EMPTY_REQUEST_PROPERTY))) {
- handleNoOutput();
- return;
- }
- setupWrappedStream();
- }
-
-
- /**
- * Perform any actions required on stream closure (handle response etc.)
- */
- public void close() throws IOException {
- try {
- if (buffer != null && buffer.size() > 0) {
- thresholdNotReached();
- LoadingByteArrayOutputStream tmp = buffer;
- buffer = null;
- super.write(tmp.getRawBytes(), 0, tmp.size());
- }
- boolean exceptionSet = outMessage.getContent(Exception.class) != null;
- if (!written && !exceptionSet) {
- handleHeadersTrustCaching();
- }
- if (!cachingForRetransmission) {
- super.close();
- } else if (cachedStream != null) {
- super.flush();
- cachedStream.getOut().close();
- cachedStream.closeFlowthroughStream();
- }
-
- try {
- handleResponse();
- } finally {
- if (cachingForRetransmission && cachedStream != null) {
- cachedStream.close();
- }
- }
- } catch (HttpRetryException e) {
- handleHttpRetryException(e);
- } catch (IOException e) {
- String origMessage = e.getMessage();
- if (origMessage != null && origMessage.contains(url.toString())) {
- throw e;
- }
- throw mapException(e.getClass().getSimpleName()
- + " invoking " + url + ": "
- + e.getMessage(), e,
- IOException.class);
- } catch (RuntimeException e) {
- throw mapException(e.getClass().getSimpleName()
- + " invoking " + url + ": "
- + e.getMessage(), e,
- RuntimeException.class);
- }
- }
-
- private <T extends Exception> T mapException(String msg,
- T ex, Class<T> cls) {
- T ex2;
- try {
- ex2 = cls.cast(ex.getClass().getConstructor(String.class).newInstance(msg));
- ex2.initCause(ex);
- } catch (Throwable e) {
- ex2 = ex;
- }
-
- return ex2;
- }
-
- /**
- * This procedure handles all retransmits, if any.
- *
- * @throws IOException
- */
- protected void handleRetransmits() throws IOException {
- // If we have a cachedStream, we are caching the request.
- if (cachedStream != null
- || getClient().isAutoRedirect() && KNOWN_HTTP_VERBS_WITH_NO_CONTENT.contains(getMethod())
- || authSupplier != null && authSupplier.requiresRequestCaching()) {
-
- if (LOG.isLoggable(Level.FINE) && cachedStream != null) {
- StringBuilder b = new StringBuilder(4096);
- b.append("Conduit \"").append(getConduitName())
- .append("\" Transmit cached message to: ")
- .append(url)
- .append(": ");
- cachedStream.writeCacheTo(b, 16L * 1024L);
- LOG.fine(b.toString());
- }
-
-
- int maxRetransmits = getMaxRetransmits();
- updateCookiesBeforeRetransmit();
- int nretransmits = 0;
- while ((maxRetransmits < 0 || nretransmits < maxRetransmits) && processRetransmit()) {
- nretransmits++;
- }
- }
- }
- /**
- * This function processes any retransmits at the direction of redirections
- * or "unauthorized" responses.
- *
- * @return true if there was a retransmit
- * @throws IOException
- */
- protected boolean processRetransmit() throws IOException {
- int responseCode = getResponseCode();
- if ((outMessage != null) && (outMessage.getExchange() != null)) {
- outMessage.getExchange().put(Message.RESPONSE_CODE, responseCode);
- }
- // Process Redirects first.
- switch(responseCode) {
- case HttpURLConnection.HTTP_MOVED_PERM:
- case HttpURLConnection.HTTP_MOVED_TEMP:
- case HttpURLConnection.HTTP_SEE_OTHER:
- case 307:
- case 308:
- return redirectRetransmit();
- case HttpURLConnection.HTTP_UNAUTHORIZED:
- case HttpURLConnection.HTTP_PROXY_AUTH:
- return authorizationRetransmit();
- default:
- break;
- }
- return false;
- }
- protected boolean redirectRetransmit() throws IOException {
- // If we are not redirecting by policy, then we don't.
- if (!getClient(outMessage).isAutoRedirect()) {
- return false;
- }
- Message m = new MessageImpl();
- updateResponseHeaders(m);
-
- String newURL = extractLocation(Headers.getSetProtocolHeaders(m));
- String urlString = url.toString();
-
- try {
- newURL = convertToAbsoluteUrlIfNeeded(conduitName, urlString, newURL, outMessage);
- detectRedirectLoop(conduitName, urlString, newURL, outMessage);
- checkAllowedRedirectUri(conduitName, urlString, newURL, outMessage);
- } catch (IOException ex) {
- // Consider introducing ClientRedirectException instead - it will require
- // those client runtimes which want to check for it have a direct link to it
- outMessage.getExchange().put("client.redirect.exception", "true");
- throw ex;
- }
-
- if (newURL != null) {
- new Headers(outMessage).removeAuthorizationHeaders();
-
- // If user configured this Conduit with preemptive authorization
- // it is meant to make it to the end. (Too bad that information
- // went to every URL along the way, but that's what the user
- // wants!
- try {
- setHeadersByAuthorizationPolicy(outMessage, new URI(newURL));
- } catch (URISyntaxException e) {
- throw new IOException(e);
- }
- cookies.writeToMessageHeaders(outMessage);
- outMessage.put("transport.retransmit.url", newURL);
- retransmit(newURL);
- return true;
- }
- return false;
- }
-
- /**
- * This method performs a retransmit for authorization information.
- *
- * @return true if there was a retransmit
- * @throws IOException
- */
- protected boolean authorizationRetransmit() throws IOException {
- Message m = new MessageImpl();
- updateResponseHeaders(m);
- List<String> authHeaderValues = Headers.getSetProtocolHeaders(m).get("WWW-Authenticate");
- if (authHeaderValues == null) {
- LOG.warning("WWW-Authenticate response header is not set");
- return false;
- }
- HttpAuthHeader authHeader = new HttpAuthHeader(authHeaderValues);
- URI currentURI = url;
- String realm = authHeader.getRealm();
- detectAuthorizationLoop(getConduitName(), outMessage, currentURI, realm);
- AuthorizationPolicy effectiveAthPolicy = getEffectiveAuthPolicy(outMessage);
- String authorizationToken =
- authSupplier.getAuthorization(
- effectiveAthPolicy, currentURI, outMessage, authHeader.getFullHeader());
- if (authorizationToken == null) {
- // authentication not possible => we give up
- return false;
- }
-
- try {
- closeInputStream();
- } catch (Throwable t) {
- //ignore
- }
- new Headers(outMessage).setAuthorization(authorizationToken);
- cookies.writeToMessageHeaders(outMessage);
- retransmit(url.toString());
- return true;
- }
-
-
-
-
- private int getMaxRetransmits() {
- HTTPClientPolicy policy = getClient(outMessage);
- // Default MaxRetransmits is -1 which means unlimited.
- return (policy == null) ? -1 : policy.getMaxRetransmits();
- }
-
- /**
- * This procedure is called on the close of the output stream so
- * we are ready to handle the response from the connection.
- * We may retransmit until we finally get a response.
- *
- * @throws IOException
- */
- protected void handleResponse() throws IOException {
- // Process retransmits until we fall out.
- handleRetransmits();
-
- if (outMessage == null
- || outMessage.getExchange() == null
- || outMessage.getExchange().isSynchronous()) {
- handleResponseInternal();
- } else {
- handleResponseAsync();
- }
- }
-
- /**
- * This predicate returns true if the exchange indicates
- * a oneway MEP.
- *
- * @param exchange The exchange in question
- */
- private boolean isOneway(Exchange exchange) {
- return exchange != null && exchange.isOneWay();
- }
-
- private boolean doProcessResponse(Message message, int responseCode) {
- // 1. Not oneWay
- if (!isOneway(message.getExchange())) {
- return true;
- }
- // 2. Robust OneWays could have a fault
- return responseCode == 500 && MessageUtils.getContextualBoolean(message, Message.ROBUST_ONEWAY, false);
- }
-
- protected int doProcessResponseCode() throws IOException {
- Exchange exchange = outMessage.getExchange();
- int rc = getResponseCode();
- if (rc == -1) {
- LOG.warning("HTTP Response code appears to be corrupted");
- }
- if (exchange != null) {
- exchange.put(Message.RESPONSE_CODE, rc);
- if (rc == 404 || rc == 503 || rc == 429) {
- exchange.put("org.apache.cxf.transport.service_not_available", true);
- }
- }
-
- // "org.apache.cxf.transport.no_io_exceptions" property should be set in case the exceptions
- // should not be handled here; for example jax rs uses this
-
- // "org.apache.cxf.transport.process_fault_on_http_400" property should be set in case a
- // soap fault because of a HTTP 400 should be returned back to the client (SOAP 1.2 spec)
-
- if (rc >= 400 && rc != 500
- && !MessageUtils.getContextualBoolean(outMessage, NO_IO_EXCEPTIONS)
- && (rc > 400 || !MessageUtils.getContextualBoolean(outMessage, PROCESS_FAULT_ON_HTTP_400))) {
-
- throw new HTTPException(rc, getResponseMessage(), url.toURL());
- }
- return rc;
- }
-
- protected void handleResponseInternal() throws IOException {
- Exchange exchange = outMessage.getExchange();
- int responseCode = doProcessResponseCode();
-
- InputStream in = null;
- // oneway or decoupled twoway calls may expect HTTP 202 with no content
-
- Message inMessage = new MessageImpl();
- inMessage.setExchange(exchange);
- updateResponseHeaders(inMessage);
- inMessage.put(Message.RESPONSE_CODE, responseCode);
- if (MessageUtils.getContextualBoolean(outMessage, SET_HTTP_RESPONSE_MESSAGE, false)) {
- inMessage.put(HTTP_RESPONSE_MESSAGE, getResponseMessage());
- }
- propagateConduit(exchange, inMessage);
-
- if ((!doProcessResponse(outMessage, responseCode)
- || HttpURLConnection.HTTP_ACCEPTED == responseCode)
- && MessageUtils.getContextualBoolean(outMessage,
- Message.PROCESS_202_RESPONSE_ONEWAY_OR_PARTIAL, true)) {
- in = getPartialResponse();
- if (in == null
- || !MessageUtils.getContextualBoolean(outMessage, Message.PROCESS_ONEWAY_RESPONSE, false)) {
- // oneway operation or decoupled MEP without
- // partial response
- closeInputStream();
- if (isOneway(exchange) && responseCode > 300) {
- throw new HTTPException(responseCode, getResponseMessage(), url.toURL());
- }
- //REVISIT move the decoupled destination property name into api
- Endpoint ep = exchange.getEndpoint();
- if (null != ep && null != ep.getEndpointInfo() && null == ep.getEndpointInfo().
- getProperty("org.apache.cxf.ws.addressing.MAPAggregator.decoupledDestination")) {
- // remove callback so that it won't be invoked twice
- ClientCallback cc = exchange.remove(ClientCallback.class);
- if (null != cc) {
- cc.handleResponse(null, null);
- }
- }
- exchange.put("IN_CHAIN_COMPLETE", Boolean.TRUE);
-
- exchange.setInMessage(inMessage);
- return;
- }
- } else {
- //not going to be resending or anything, clear out the stuff in the out message
- //to free memory
- outMessage.removeContent(OutputStream.class);
- if (cachingForRetransmission && cachedStream != null) {
- cachedStream.close();
- }
- cachedStream = null;
- }
-
- String charset = HttpHeaderHelper.findCharset((String)inMessage.get(Message.CONTENT_TYPE));
- String normalizedEncoding = HttpHeaderHelper.mapCharset(charset);
- if (normalizedEncoding == null) {
- String m = new org.apache.cxf.common.i18n.Message("INVALID_ENCODING_MSG",
- LOG, charset).toString();
- LOG.log(Level.WARNING, m);
- throw new IOException(m);
- }
- inMessage.put(Message.ENCODING, normalizedEncoding);
- if (in == null) {
- in = getInputStream();
- }
- if (in == null) {
- // Create an empty stream to avoid NullPointerExceptions
- in = new ByteArrayInputStream(new byte[] {});
- }
- inMessage.setContent(InputStream.class, in);
-
-
- incomingObserver.onMessage(inMessage);
-
- }
-
- protected void propagateConduit(Exchange exchange, Message in) {
- if (exchange != null) {
- Message out = exchange.getOutMessage();
- if (out != null) {
- in.put(Conduit.class, out.get(Conduit.class));
- }
- }
- }
-
- protected void handleHttpRetryException(HttpRetryException e) throws IOException {
- String msg = "HTTP response '" + e.responseCode() + ": "
- + getResponseMessage() + "' invoking " + url;
- switch (e.responseCode()) {
- case HttpURLConnection.HTTP_MOVED_PERM: // 301
- case HttpURLConnection.HTTP_MOVED_TEMP: // 302
- case HttpURLConnection.HTTP_SEE_OTHER: // 303
- case 307:
- msg += " that returned location header '" + e.getLocation() + "'";
- break;
- case HttpURLConnection.HTTP_UNAUTHORIZED: // 401
- if (authorizationPolicy == null || authorizationPolicy.getUserName() == null) {
- msg += " with NO authorization username configured in conduit " + getConduitName();
- } else {
- msg += " with authorization username '" + authorizationPolicy.getUserName() + "'";
- }
- break;
- case HttpURLConnection.HTTP_PROXY_AUTH: // 407
- if (proxyAuthorizationPolicy == null || proxyAuthorizationPolicy.getUserName() == null) {
- msg += " with NO proxy authorization configured in conduit " + getConduitName();
- } else {
- msg += " with proxy authorization username '"
- + proxyAuthorizationPolicy.getUserName() + "'";
- }
- if (clientSidePolicy == null || clientSidePolicy.getProxyServer() == null) {
- if (usingProxy()) {
- msg += " using a proxy even if NONE is configured in CXF conduit "
- + getConduitName()
- + " (maybe one is configured by java.net.ProxySelector)";
- } else {
- msg += " but NO proxy was used by the connection (none configured in cxf "
- + "conduit and none selected by java.net.ProxySelector)";
- }
- } else {
- msg += " using " + clientSidePolicy.getProxyServerType() + " proxy "
- + clientSidePolicy.getProxyServer() + ":"
- + clientSidePolicy.getProxyServerPort();
- }
- break;
- default:
- // No other type of HttpRetryException should be thrown
- break;
- }
- throw new IOException(msg, e);
- }
-
- /**
- * This call must take place before anything is written to the
- * URLConnection. The URLConnection.connect() will be called in order
- * to get the connection information.
- *
- * This method is invoked just after setURLRequestHeaders() from the
- * WrappedOutputStream before it writes data to the URLConnection.
- *
- * If trust cannot be established the Trust Decider implemenation
- * throws an IOException.
- *
- * @throws IOException This exception is thrown if trust cannot be
- * established by the configured MessageTrustDecider.
- * @see MessageTrustDecider
- */
- protected void makeTrustDecision() throws IOException {
-
- MessageTrustDecider decider2 = outMessage.get(MessageTrustDecider.class);
- if (trustDecider != null || decider2 != null) {
- try {
- // We must connect or we will not get the credentials.
- // The call is (said to be) ignored internally if
- // already connected.
- HttpsURLConnectionInfo info = getHttpsURLConnectionInfo();
- if (trustDecider != null) {
- trustDecider.establishTrust(conduitName,
- info,
- outMessage);
- if (LOG.isLoggable(Level.FINE)) {
- LOG.log(Level.FINE, "Trust Decider "
- + trustDecider.getLogicalName()
- + " considers Conduit "
- + conduitName
- + " trusted.");
- }
- }
- if (decider2 != null) {
- decider2.establishTrust(conduitName,
- info,
- outMessage);
- if (LOG.isLoggable(Level.FINE)) {
- LOG.log(Level.FINE, "Trust Decider "
- + decider2.getLogicalName()
- + " considers Conduit "
- + conduitName
- + " trusted.");
- }
- }
- } catch (UntrustedURLConnectionIOException untrustedEx) {
- if (LOG.isLoggable(Level.FINE)) {
- LOG.log(Level.FINE, "Trust Decider "
- + (trustDecider != null ? trustDecider.getLogicalName() : decider2.getLogicalName())
- + " considers Conduit "
- + conduitName
- + " untrusted.", untrustedEx);
- }
- throw untrustedEx;
- }
- } else {
- // This case, when there is no trust decider, a trust
- // decision should be a matter of policy.
- if (LOG.isLoggable(Level.FINE)) {
- LOG.log(Level.FINE, "No Trust Decider for Conduit '"
- + conduitName
- + "'. An affirmative Trust Decision is assumed.");
- }
- }
- }
- }
-
- private static void checkAllowedRedirectUri(String conduitName,
- String lastURL,
- String newURL,
- Message message) throws IOException {
- if (newURL != null) {
- URI newUri = URI.create(newURL);
-
- if (MessageUtils.getContextualBoolean(message, AUTO_REDIRECT_SAME_HOST_ONLY)) {
-
- URI lastUri = URI.create(lastURL);
-
- // This can be further restricted to make sure newURL completely contains lastURL
- // though making sure the same HTTP scheme and host are preserved should be enough
-
- if (!newUri.getScheme().equals(lastUri.getScheme())
- || !newUri.getHost().equals(lastUri.getHost())) {
- String msg = "Different HTTP Scheme or Host Redirect detected on Conduit '"
- + conduitName + "' on '" + newURL + "'";
- LOG.log(Level.INFO, msg);
- throw new IOException(msg);
- }
- }
-
- String allowedRedirectURI = (String)message.getContextualProperty(AUTO_REDIRECT_ALLOWED_URI);
- if (allowedRedirectURI != null && !newURL.startsWith(allowedRedirectURI)) {
- String msg = "Forbidden Redirect URI " + newURL + "detected on Conduit '" + conduitName;
- LOG.log(Level.INFO, msg);
- throw new IOException(msg);
- }
-
- }
- }
-
- // http://tools.ietf.org/html/draft-ietf-httpbis-p2-semantics-23#section-7.1.2
- // Relative Location values are also supported
- private static String convertToAbsoluteUrlIfNeeded(String conduitName,
- String lastURL,
- String newURL,
- Message message) throws IOException {
- if (newURL != null && !newURL.startsWith("http")) {
-
- if (MessageUtils.getContextualBoolean(message, AUTO_REDIRECT_ALLOW_REL_URI)) {
- return URI.create(lastURL).resolve(newURL).toString();
- }
- String msg = "Relative Redirect detected on Conduit '"
- + conduitName + "' on '" + newURL + "'";
- LOG.log(Level.INFO, msg);
- throw new IOException(msg);
- }
- return newURL;
-
- }
-
- private static void detectRedirectLoop(String conduitName,
- String lastURL,
- String newURL,
- Message message) throws IOException {
- Map<String, Integer> visitedURLs = CastUtils.cast((Map<?, ?>)message.get(KEY_VISITED_URLS));
- if (visitedURLs == null) {
- visitedURLs = new HashMap<>();
- message.put(KEY_VISITED_URLS, visitedURLs);
- }
- Integer visitCount = visitedURLs.get(lastURL);
- if (visitCount == null) {
- visitCount = 1;
- } else {
- visitCount++;
- }
- visitedURLs.put(lastURL, visitCount);
-
- Integer newURLCount = visitedURLs.get(newURL);
- if (newURL != null && newURLCount != null) {
- // See if we are being redirected in a loop as best we can,
- // using string equality on URL.
- boolean invalidLoopDetected = newURL.equals(lastURL);
-
- Integer maxSameURICount = PropertyUtils.getInteger(message, AUTO_REDIRECT_MAX_SAME_URI_COUNT);
-
- if (!invalidLoopDetected) {
- // This new URI was already recorded earlier even though it is not equal to the last URI
- // Example: a-b-a, where 'a' is the new URI. Check if a limited number of occurrences of this URI
- // is allowed, fail by default.
- if (maxSameURICount == null || newURLCount > maxSameURICount) {
- invalidLoopDetected = true;
- }
- } else if (maxSameURICount != null && newURLCount <= maxSameURICount) {
- // This new URI was already recorded earlier and is the same as the last URI.
- // Example: a-a. But we have a property supporting a limited number of occurrences of this URI.
- // Continue the invocation.
- invalidLoopDetected = false;
- }
- if (invalidLoopDetected) {
- // We are in a redirect loop; -- bail
- String msg = "Redirect loop detected on Conduit '"
- + conduitName + "' on '" + newURL + "'";
- LOG.log(Level.INFO, msg);
- throw new IOException(msg);
- }
- }
- }
- private static void detectAuthorizationLoop(String conduitName, Message message,
- URI currentURL, String realm) throws IOException {
- @SuppressWarnings("unchecked")
- Set<String> authURLs = (Set<String>) message.get(KEY_AUTH_URLS);
- if (authURLs == null) {
- authURLs = new HashSet<>();
- message.put(KEY_AUTH_URLS, authURLs);
- }
- // If we have been here (URL & Realm) before for this particular message
- // retransmit, it means we have already supplied information
- // which must have been wrong, or we wouldn't be here again.
- // Otherwise, the server may be 401 looping us around the realms.
- if (!authURLs.add(currentURL.toString() + realm)) {
- String logMessage = "Authorization loop detected on Conduit \""
- + conduitName
- + "\" on URL \""
- + currentURL
- + "\" with realm \""
- + realm
- + "\"";
- if (LOG.isLoggable(Level.INFO)) {
- LOG.log(Level.INFO, logMessage);
- }
-
- throw new IOException(logMessage);
- }
- }
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/transport/http/HTTPTransportFactory.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/transport/http/HTTPTransportFactory.java
deleted file mode 100644
index b9088b9..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/transport/http/HTTPTransportFactory.java
+++ /dev/null
@@ -1,297 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.cxf.transport.http;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Set;
-import java.util.concurrent.locks.Lock;
-import java.util.concurrent.locks.ReadWriteLock;
-import java.util.concurrent.locks.ReentrantReadWriteLock;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import org.apache.cxf.Bus;
-import org.apache.cxf.common.injection.NoJSR250Annotations;
-import org.apache.cxf.common.logging.LogUtils;
-import org.apache.cxf.configuration.Configurer;
-import org.apache.cxf.service.Service;
-import org.apache.cxf.service.model.BindingInfo;
-import org.apache.cxf.service.model.EndpointInfo;
-import org.apache.cxf.service.model.ServiceInfo;
-import org.apache.cxf.transport.AbstractTransportFactory;
-import org.apache.cxf.transport.Conduit;
-import org.apache.cxf.transport.ConduitInitiator;
-import org.apache.cxf.transport.Destination;
-import org.apache.cxf.transport.DestinationFactory;
-import org.apache.cxf.transport.servlet.ServletDestinationFactory;
-import org.apache.cxf.ws.addressing.EndpointReferenceType;
-import org.apache.cxf.wsdl.http.AddressType;
-
-/**
- *
- */
-@NoJSR250Annotations
-public class HTTPTransportFactory
- extends AbstractTransportFactory
- implements ConduitInitiator, DestinationFactory {
-
-
- public static final List<String> DEFAULT_NAMESPACES
- = Collections.unmodifiableList(Arrays.asList(
- "http://cxf.apache.org/transports/http",
- "http://cxf.apache.org/transports/http/configuration",
- "http://schemas.xmlsoap.org/wsdl/http",
- "http://schemas.xmlsoap.org/wsdl/http/"
- ));
-
- private static final Logger LOG = LogUtils.getL7dLogger(HTTPTransportFactory.class);
-
- /**
- * This constant holds the prefixes served by this factory.
- */
- private static final Set<String> URI_PREFIXES = new HashSet<>();
- static {
- URI_PREFIXES.add("http://");
- URI_PREFIXES.add("https://");
- }
-
- protected DestinationRegistry registry;
-
- private final ReadWriteLock lock = new ReentrantReadWriteLock();
- private final Lock r = lock.readLock();
- private final Lock w = lock.writeLock();
-
- public HTTPTransportFactory() {
- this(new DestinationRegistryImpl());
- }
-
- public HTTPTransportFactory(DestinationRegistry registry) {
- this(DEFAULT_NAMESPACES, registry);
- }
-
- protected HTTPTransportFactory(List<String> transportIds, DestinationRegistry registry) {
- super(transportIds);
- if (registry == null) {
- registry = new DestinationRegistryImpl();
- }
- this.registry = registry;
- }
-
- public DestinationRegistry getRegistry() {
- return registry;
- }
-
- public void setRegistry(DestinationRegistry newRegistry) {
- w.lock();
- try {
- if (registry.getDestinations().isEmpty()) {
- this.registry = newRegistry;
- } else {
- String m = new org.apache.cxf.common.i18n.Message("CANNOT_CHANGE_REGISTRY_ALREADY_IN_USE",
- LOG).toString();
- LOG.log(Level.SEVERE, m);
- throw new RuntimeException(m);
- }
- } finally {
- w.unlock();
- }
- }
-
- /**
- * This call is used by CXF ExtensionManager to inject the activationNamespaces
- * @param ans The transport ids.
- */
- public void setActivationNamespaces(Collection<String> ans) {
- setTransportIds(new ArrayList<>(ans));
- }
-
- public EndpointInfo createEndpointInfo(
- ServiceInfo serviceInfo,
- BindingInfo b,
- List<?> ees
- ) {
- if (ees != null) {
- for (Iterator<?> itr = ees.iterator(); itr.hasNext();) {
- Object extensor = itr.next();
-
- if (extensor instanceof AddressType) {
- final AddressType httpAdd = (AddressType)extensor;
-
- EndpointInfo info =
- new HttpEndpointInfo(serviceInfo,
- "http://schemas.xmlsoap.org/wsdl/http/");
- info.setAddress(httpAdd.getLocation());
- info.addExtensor(httpAdd);
- return info;
- }
- }
- }
-
- HttpEndpointInfo hei = new HttpEndpointInfo(serviceInfo,
- "http://schemas.xmlsoap.org/wsdl/http/");
- AddressType at = new AddressType();
- hei.addExtensor(at);
-
- return hei;
- }
-
- public void createPortExtensors(EndpointInfo ei, Service service) {
- // TODO
- }
-
- public Set<String> getUriPrefixes() {
- return URI_PREFIXES;
- }
-
- /**
- * This call uses the Configurer from the bus to configure
- * a bean.
- *
- * @param bean
- */
- protected void configure(Bus b, Object bean) {
- configure(b, bean, null, null);
- }
-
- protected void configure(Bus bus, Object bean, String name, String extraName) {
- Configurer configurer = bus.getExtension(Configurer.class);
- if (null != configurer) {
- configurer.configureBean(name, bean);
- if (extraName != null) {
- configurer.configureBean(extraName, bean);
- }
- }
- }
-
- private static class HttpEndpointInfo extends EndpointInfo {
- AddressType saddress;
- HttpEndpointInfo(ServiceInfo serv, String trans) {
- super(serv, trans);
- }
- public void setAddress(String s) {
- super.setAddress(s);
- if (saddress != null) {
- saddress.setLocation(s);
- }
- }
-
- public void addExtensor(Object el) {
- super.addExtensor(el);
- if (el instanceof AddressType) {
- saddress = (AddressType)el;
- }
- }
- }
-
- /**
- * This call creates a new HTTPConduit for the endpoint. It is equivalent
- * to calling getConduit without an EndpointReferenceType.
- */
- public Conduit getConduit(EndpointInfo endpointInfo, Bus bus) throws IOException {
- return getConduit(endpointInfo, endpointInfo.getTarget(), bus);
- }
-
- /**
- * This call creates a new HTTP Conduit based on the EndpointInfo and
- * EndpointReferenceType.
- * TODO: What are the formal constraints on EndpointInfo and
- * EndpointReferenceType values?
- */
- public Conduit getConduit(
- EndpointInfo endpointInfo,
- EndpointReferenceType target,
- Bus bus
- ) throws IOException {
-
- HTTPConduitFactory factory = findFactory(endpointInfo, bus);
- HTTPConduit conduit = null;
- if (factory != null) {
- conduit = factory.createConduit(this, bus, endpointInfo, target);
- }
- if (conduit == null) {
- conduit = new URLConnectionHTTPConduit(bus, endpointInfo, target);
- }
-
- // Spring configure the conduit.
- String address = conduit.getAddress();
- if (address != null && address.indexOf('?') != -1) {
- address = address.substring(0, address.indexOf('?'));
- }
- HTTPConduitConfigurer c1 = bus.getExtension(HTTPConduitConfigurer.class);
- if (c1 != null) {
- c1.configure(conduit.getBeanName(), address, conduit);
- }
- configure(bus, conduit, conduit.getBeanName(), address);
- conduit.finalizeConfig();
- return conduit;
- }
-
- protected HTTPConduitFactory findFactory(EndpointInfo endpointInfo, Bus bus) {
- HTTPConduitFactory f = endpointInfo.getProperty(HTTPConduitFactory.class.getName(), HTTPConduitFactory.class);
- if (f == null) {
- f = bus.getExtension(HTTPConduitFactory.class);
- }
- return f;
- }
- public Destination getDestination(EndpointInfo endpointInfo, Bus bus) throws IOException {
- if (endpointInfo == null) {
- throw new IllegalArgumentException("EndpointInfo cannot be null");
- }
- r.lock();
- try {
- synchronized (registry) {
- AbstractHTTPDestination d = registry.getDestinationForPath(endpointInfo.getAddress());
- if (d == null) {
- HttpDestinationFactory jettyFactory = bus.getExtension(HttpDestinationFactory.class);
- String addr = endpointInfo.getAddress();
- if (jettyFactory == null && addr != null && addr.startsWith("http")) {
- String m =
- new org.apache.cxf.common.i18n.Message("NO_HTTP_DESTINATION_FACTORY_FOUND",
- LOG).toString();
- LOG.log(Level.SEVERE, m);
- throw new IOException(m);
- }
- final HttpDestinationFactory factory;
- if (jettyFactory != null && (addr == null || addr.startsWith("http"))) {
- factory = jettyFactory;
- } else {
- factory = new ServletDestinationFactory();
- }
-
- d = factory.createDestination(endpointInfo, bus, registry);
- registry.addDestination(d);
- configure(bus, d);
- d.finalizeConfig();
- }
- return d;
- }
- } finally {
- r.unlock();
- }
- }
-
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/transport/http/Headers.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/transport/http/Headers.java
deleted file mode 100644
index db2dbff..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/transport/http/Headers.java
+++ /dev/null
@@ -1,583 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.cxf.transport.http;
-
-import java.io.IOException;
-import java.net.HttpURLConnection;
-import java.net.URLConnection;
-import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.Date;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Locale;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.TimeZone;
-import java.util.TreeMap;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.apache.cxf.common.logging.LogUtils;
-import org.apache.cxf.common.util.PropertyUtils;
-import org.apache.cxf.helpers.CastUtils;
-import org.apache.cxf.helpers.HttpHeaderHelper;
-import org.apache.cxf.message.Message;
-import org.apache.cxf.message.MessageUtils;
-import org.apache.cxf.transports.http.configuration.HTTPClientPolicy;
-import org.apache.cxf.transports.http.configuration.HTTPServerPolicy;
-import org.apache.cxf.version.Version;
-
-public class Headers {
- /**
- * This constant is the Message(Map) key for the HttpURLConnection that
- * is used to get the response.
- */
- public static final String KEY_HTTP_CONNECTION = "http.connection";
- /**
- * Each header value is added as a separate HTTP header, example, given A header with 'a' and 'b'
- * values, two A headers will be added as opposed to a single A header with the "a,b" value.
- */
- public static final String ADD_HEADERS_PROPERTY = "org.apache.cxf.http.add-headers";
-
- public static final String PROTOCOL_HEADERS_CONTENT_TYPE = Message.CONTENT_TYPE.toLowerCase();
- public static final String HTTP_HEADERS_SETCOOKIE = "Set-Cookie";
- public static final String HTTP_HEADERS_LINK = "Link";
- public static final String EMPTY_REQUEST_PROPERTY = "org.apache.cxf.empty.request";
- private static final String SET_EMPTY_REQUEST_CT_PROPERTY = "set.content.type.for.empty.request";
- private static final TimeZone TIME_ZONE_GMT = TimeZone.getTimeZone("GMT");
- private static final Logger LOG = LogUtils.getL7dLogger(Headers.class);
-
- private static final List<String> SENSITIVE_HEADERS = Arrays.asList("Authorization", "Proxy-Authorization");
- private static final List<Object> SENSITIVE_HEADER_MARKER = Arrays.asList("***");
- private static final String ALLOW_LOGGING_SENSITIVE_HEADERS = "allow.logging.sensitive.headers";
- private static final String USER_AGENT = initUserAgent();
-
- private final Message message;
- private final Map<String, List<String>> headers;
-
- public Headers(Message message) {
- this.message = message;
- this.headers = getSetProtocolHeaders(message);
- }
- public Headers() {
- this.headers = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
- this.message = null;
- }
-
- public static String getUserAgent() {
- return USER_AGENT;
- }
-
- private static String initUserAgent() {
- String name = Version.getName();
- if ("Apache CXF".equals(name)) {
- name = "Apache-CXF";
- }
- String version = Version.getCurrentVersion();
- return name + "/" + version;
- }
-
- /**
- * Returns a traceable string representation of the passed-in headers map.
- * The value for any keys in the map that are in the <code>SENSITIVE_HEADERS</code>
- * array will be filtered out of the returned string.
- * Note that this method is expensive as it will copy the map (except for the
- * filtered keys), so it should be used sparingly - i.e. only when debug is
- * enabled.
- */
- static String toString(Map<String, List<Object>> headers, boolean logSensitiveHeaders) {
- Map<String, List<Object>> filteredHeaders = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
- filteredHeaders.putAll(headers);
- if (!logSensitiveHeaders) {
- for (String filteredKey : SENSITIVE_HEADERS) {
- filteredHeaders.put(filteredKey, SENSITIVE_HEADER_MARKER);
- }
- }
- return filteredHeaders.toString();
- }
-
- public Map<String, List<String>> headerMap() {
- return headers;
- }
-
-
- /**
- * Write cookie header from given session cookies
- *
- * @param sessionCookies
- */
- public void writeSessionCookies(Map<String, Cookie> sessionCookies) {
- List<String> cookies = null;
- for (String s : headers.keySet()) {
- if (HttpHeaderHelper.COOKIE.equalsIgnoreCase(s)) {
- cookies = headers.remove(s);
- break;
- }
- }
- if (cookies == null) {
- cookies = new ArrayList<>();
- } else {
- cookies = new ArrayList<>(cookies);
- }
- headers.put(HttpHeaderHelper.COOKIE, cookies);
- for (Cookie c : sessionCookies.values()) {
- cookies.add(c.requestCookieHeader());
- }
- }
-
- /**
- * This call places HTTP Header strings into the headers that are relevant
- * to the ClientPolicy that is set on this conduit by configuration.
- *
- * REVISIT: A cookie is set statically from configuration?
- */
- void setFromClientPolicy(HTTPClientPolicy policy) {
- if (policy == null) {
- return;
- }
- if (policy.isSetCacheControl()) {
- headers.put("Cache-Control",
- createMutableList(policy.getCacheControl()));
- }
- if (policy.isSetHost()) {
- headers.put("Host",
- createMutableList(policy.getHost()));
- }
- if (policy.isSetConnection()) {
- headers.put("Connection",
- createMutableList(policy.getConnection().value()));
- }
- if (policy.isSetAccept()) {
- headers.put("Accept",
- createMutableList(policy.getAccept()));
- } else if (!headers.containsKey("Accept")) {
- headers.put("Accept", createMutableList("*/*"));
- }
- if (policy.isSetAcceptEncoding()) {
- headers.put("Accept-Encoding",
- createMutableList(policy.getAcceptEncoding()));
- }
- if (policy.isSetAcceptLanguage()) {
- headers.put("Accept-Language",
- createMutableList(policy.getAcceptLanguage()));
- }
- if (policy.isSetContentType()) {
- message.put(Message.CONTENT_TYPE, policy.getContentType());
- }
- if (policy.isSetCookie()) {
- headers.put("Cookie",
- createMutableList(policy.getCookie()));
- }
- if (policy.isSetBrowserType()) {
- headers.put("User-Agent",
- createMutableList(policy.getBrowserType()));
- }
- if (policy.isSetReferer()) {
- headers.put("Referer",
- createMutableList(policy.getReferer()));
- }
- }
-
- void setFromServerPolicy(HTTPServerPolicy policy) {
- if (policy.isSetCacheControl()) {
- headers.put("Cache-Control",
- createMutableList(policy.getCacheControl()));
- }
- if (policy.isSetContentLocation()) {
- headers.put("Content-Location",
- createMutableList(policy.getContentLocation()));
- }
- if (policy.isSetContentEncoding()) {
- headers.put("Content-Encoding",
- createMutableList(policy.getContentEncoding()));
- }
- if (policy.isSetContentType()) {
- headers.put(HttpHeaderHelper.CONTENT_TYPE,
- createMutableList(policy.getContentType()));
- }
- if (policy.isSetServerType()) {
- headers.put("Server",
- createMutableList(policy.getServerType()));
- }
- if (policy.isSetHonorKeepAlive() && !policy.isHonorKeepAlive()) {
- headers.put("Connection",
- createMutableList("close"));
- } else if (policy.isSetKeepAliveParameters()) {
- headers.put("Keep-Alive", createMutableList(policy.getKeepAliveParameters()));
- }
-
-
- /*
- * TODO - hook up these policies
- <xs:attribute name="SuppressClientSendErrors" type="xs:boolean" use="optional" default="false">
- <xs:attribute name="SuppressClientReceiveErrors" type="xs:boolean" use="optional" default="false">
- */
- }
-
- public void removeAuthorizationHeaders() {
- headers.remove("Authorization");
- headers.remove("Proxy-Authorization");
- }
-
- public void setAuthorization(String authorization) {
- headers.put("Authorization",
- createMutableList(authorization));
- }
-
- public void setProxyAuthorization(String authorization) {
- headers.put("Proxy-Authorization",
- createMutableList(authorization));
- }
-
-
- /**
- * While extracting the Message.PROTOCOL_HEADERS property from the Message,
- * this call ensures that the Message.PROTOCOL_HEADERS property is
- * set on the Message. If it is not set, an empty map is placed there, and
- * then returned.
- *
- * @param message The outbound message
- * @return The PROTOCOL_HEADERS map
- */
- public static Map<String, List<String>> getSetProtocolHeaders(final Message message) {
- Map<String, List<String>> headers =
- CastUtils.cast((Map<?, ?>)message.get(Message.PROTOCOL_HEADERS));
- if (null == headers) {
- headers = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
- } else if (headers instanceof HashMap) {
- Map<String, List<String>> headers2
- = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
- headers2.putAll(headers);
- headers = headers2;
- }
- message.put(Message.PROTOCOL_HEADERS, headers);
- return headers;
- }
-
- public void readFromConnection(HttpURLConnection connection) {
- Map<String, List<String>> origHeaders = connection.getHeaderFields();
- headers.clear();
- for (Entry<String, List<String>> entry : origHeaders.entrySet()) {
- if (entry.getKey() != null) {
- String key = HttpHeaderHelper.getHeaderKey(entry.getKey());
- List<String> old = headers.get(key);
- if (old != null) {
- List<String> nl = new ArrayList<>(old.size() + entry.getValue().size());
- nl.addAll(old);
- nl.addAll(entry.getValue());
- headers.put(key, nl);
- } else {
- headers.put(key, entry.getValue());
- }
- }
- }
- }
-
- private static List<String> createMutableList(String val) {
- return new ArrayList<>(Arrays.asList(val));
- }
-
- /**
- * This procedure logs the PROTOCOL_HEADERS from the
- * Message at the specified logging level.
- *
- * @param logger The Logger to log to.
- * @param level The Logging Level.
- * @param headersMap The Message protocol headers.
- * @param logSensitiveHeaders whether to log sensitive headers
- */
- static void logProtocolHeaders(Logger logger, Level level,
- Map<String, List<Object>> headersMap,
- boolean logSensitiveHeaders) {
- if (logger.isLoggable(level)) {
- for (Map.Entry<String, List<Object>> entry : headersMap.entrySet()) {
- String key = entry.getKey();
- boolean sensitive = !logSensitiveHeaders && SENSITIVE_HEADERS.contains(key);
- List<Object> headerList = sensitive ? SENSITIVE_HEADER_MARKER : entry.getValue();
- for (Object value : headerList) {
- logger.log(level, key + ": "
- + (value == null ? "<null>" : value.toString()));
- }
- }
- }
- }
-
- /**
- * Set content type and protocol headers (Message.PROTOCOL_HEADERS) headers into the URL
- * connection.
- * Note, this does not mean they immediately get written to the output
- * stream or the wire. They just just get set on the HTTP request.
- *
- * @param connection
- * @throws IOException
- */
- public void setProtocolHeadersInConnection(HttpURLConnection connection) throws IOException {
- // If no Content-Type is set for empty requests then HttpUrlConnection:
- // - sets a form Content-Type for empty POST
- // - replaces custom Accept value with */* if HTTP proxy is used
- boolean contentTypeSet = headers.containsKey(Message.CONTENT_TYPE);
- if (!contentTypeSet) {
- // if CT is not set then assume it has to be set by default
- boolean dropContentType = false;
- boolean getRequest = "GET".equals(message.get(Message.HTTP_REQUEST_METHOD));
- boolean emptyRequest = getRequest || PropertyUtils.isTrue(message.get(EMPTY_REQUEST_PROPERTY));
- // If it is an empty request (without a request body) then check further if CT still needs be set
- if (emptyRequest) {
- Object setCtForEmptyRequestProp = message.getContextualProperty(SET_EMPTY_REQUEST_CT_PROPERTY);
- if (setCtForEmptyRequestProp != null) {
- // If SET_EMPTY_REQUEST_CT_PROPERTY is set then do as a user prefers.
- // CT will be dropped if setting CT for empty requests was explicitly disabled
- dropContentType = PropertyUtils.isFalse(setCtForEmptyRequestProp);
- } else if (getRequest) {
- // otherwise if it is GET then just drop it
- dropContentType = true;
- }
- }
- if (!dropContentType) {
- String ct = emptyRequest && !contentTypeSet ? "*/*" : determineContentType();
- connection.setRequestProperty(HttpHeaderHelper.CONTENT_TYPE, ct);
- }
- } else {
- connection.setRequestProperty(HttpHeaderHelper.CONTENT_TYPE, determineContentType());
- }
-
- transferProtocolHeadersToURLConnection(connection);
-
- Map<String, List<Object>> theHeaders = CastUtils.cast(headers);
- logProtocolHeaders(LOG, Level.FINE, theHeaders, logSensitiveHeaders());
- }
-
- public String determineContentType() {
- String ct;
- List<Object> ctList = CastUtils.cast(headers.get(Message.CONTENT_TYPE));
- if (ctList != null && ctList.size() == 1 && ctList.get(0) != null) {
- ct = ctList.get(0).toString();
- } else {
- ct = (String)message.get(Message.CONTENT_TYPE);
- }
-
- String enc = (String)message.get(Message.ENCODING);
-
- if (null != ct) {
- if (enc != null
- && ct.indexOf("charset=") == -1
- && !ct.toLowerCase().contains("multipart/related")) {
- ct = ct + "; charset=" + enc;
- }
- } else if (enc != null) {
- ct = "text/xml; charset=" + enc;
- } else {
- ct = "text/xml";
- }
- return ct;
- }
-
- /**
- * This procedure sets the URLConnection request properties
- * from the PROTOCOL_HEADERS in the message.
- */
- private void transferProtocolHeadersToURLConnection(URLConnection connection) {
- boolean addHeaders = MessageUtils.getContextualBoolean(message, ADD_HEADERS_PROPERTY, false);
- for (Map.Entry<String, List<String>> entry : headers.entrySet()) {
- String header = entry.getKey();
- if (HttpHeaderHelper.CONTENT_TYPE.equalsIgnoreCase(header)) {
- continue;
- }
-
- List<String> headerList = entry.getValue();
- if (addHeaders || HttpHeaderHelper.COOKIE.equalsIgnoreCase(header)) {
- headerList.forEach(s -> connection.addRequestProperty(header, s));
- } else {
- connection.setRequestProperty(header, String.join(",", headerList));
- }
- }
- // make sure we don't add more than one User-Agent header
- if (connection.getRequestProperty("User-Agent") == null) {
- connection.addRequestProperty("User-Agent", USER_AGENT);
- }
- }
-
- /**
- * Copy the request headers into the message.
- *
- * @param req the current servlet request
- */
- protected void copyFromRequest(HttpServletRequest req) {
-
- //TODO how to deal with the fields
- for (Enumeration<String> e = req.getHeaderNames(); e.hasMoreElements();) {
- String fname = e.nextElement();
- String mappedName = HttpHeaderHelper.getHeaderKey(fname);
- List<String> values = headers.get(mappedName);
- if (values == null) {
- values = new ArrayList<>();
- headers.put(mappedName, values);
- }
- for (Enumeration<String> e2 = req.getHeaders(fname); e2.hasMoreElements();) {
- String val = e2.nextElement();
- if ("Accept".equals(mappedName) && !values.isEmpty()) {
- //ensure we collapse Accept into first line
- String firstAccept = values.get(0);
- firstAccept = firstAccept + ", " + val;
- values.set(0, firstAccept);
- }
- values.add(val);
- }
- }
- if (!headers.containsKey(Message.CONTENT_TYPE)) {
- headers.put(Message.CONTENT_TYPE, Collections.singletonList(req.getContentType()));
- }
- if (LOG.isLoggable(Level.FINE)) {
- Map<String, List<Object>> theHeaders = CastUtils.cast(headers);
- LOG.log(Level.FINE, "Request Headers: " + toString(theHeaders,
- logSensitiveHeaders()));
- }
- }
-
- private boolean logSensitiveHeaders() {
- // Not allowed by default
- return PropertyUtils.isTrue(message.getContextualProperty(ALLOW_LOGGING_SENSITIVE_HEADERS));
- }
-
- private String getContentTypeFromMessage() {
- final String ct = (String)message.get(Message.CONTENT_TYPE);
- final String enc = (String)message.get(Message.ENCODING);
-
- if (null != ct
- && null != enc
- && ct.indexOf("charset=") == -1
- && !ct.toLowerCase().contains("multipart/related")) {
- return ct + "; charset=" + enc;
- }
- return ct;
- }
-
- // Assumes that response body is not available only
- // if Content-Length is available and set to 0
- private boolean isResponseBodyAvailable() {
- List<String> ctLen = headers.get("Content-Length");
- if (ctLen == null || ctLen.size() != 1) {
- return true;
- }
- try {
- if (Integer.parseInt(ctLen.get(0)) == 0) {
- return false;
- }
- } catch (NumberFormatException ex) {
- // ignore
- }
- return true;
- }
-
- private boolean isSingleHeader(String header) {
- return HTTP_HEADERS_SETCOOKIE.equalsIgnoreCase(header) || HTTP_HEADERS_LINK.equalsIgnoreCase(header);
- }
-
- /**
- * Copy the response headers into the response.
- *
- * @param response the current ServletResponse
- */
- protected void copyToResponse(HttpServletResponse response) {
- String contentType = getContentTypeFromMessage();
-
- if (!headers.containsKey(Message.CONTENT_TYPE) && contentType != null
- && isResponseBodyAvailable()) {
- response.setContentType(contentType);
- }
-
- boolean addHeaders = MessageUtils.getContextualBoolean(message, ADD_HEADERS_PROPERTY, false);
- for (Map.Entry<String, List<String>> entry : headers.entrySet()) {
- String header = entry.getKey();
- List<?> headerList = entry.getValue();
-
- if (addHeaders || isSingleHeader(header)) {
- for (int i = 0; i < headerList.size(); i++) {
- Object headerObject = headerList.get(i);
- if (headerObject != null) {
- response.addHeader(header, headerObjectToString(headerObject));
- }
- }
- } else {
- StringBuilder sb = new StringBuilder();
- for (int i = 0; i < headerList.size(); i++) {
- Object headerObject = headerList.get(i);
- if (headerObject != null) {
- sb.append(headerObjectToString(headerObject));
- }
-
- if (i + 1 < headerList.size()) {
- sb.append(',');
- }
- }
- response.setHeader(header, sb.toString());
- }
- }
- }
-
- private String headerObjectToString(Object headerObject) {
- if (headerObject.getClass() == String.class) {
- // Most likely
- return headerObject.toString();
- }
- String headerString;
- if (headerObject instanceof Date) {
- headerString = toHttpDate((Date)headerObject);
- } else if (headerObject instanceof Locale) {
- headerString = toHttpLanguage((Locale)headerObject);
- } else {
- headerString = headerObject.toString();
- }
- return headerString;
- }
-
- void removeContentType() {
- headers.remove(PROTOCOL_HEADERS_CONTENT_TYPE);
- }
-
- public String getAuthorization() {
- List<String> authorizationLines = headers.get("Authorization");
- if (authorizationLines != null && !authorizationLines.isEmpty()) {
- return authorizationLines.get(0);
- }
- return null;
- }
-
- public static SimpleDateFormat getHttpDateFormat() {
- SimpleDateFormat dateFormat = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US);
- dateFormat.setTimeZone(TIME_ZONE_GMT);
- return dateFormat;
- }
-
- public static String toHttpDate(Date date) {
- SimpleDateFormat format = getHttpDateFormat();
- return format.format(date);
- }
-
- public static String toHttpLanguage(Locale locale) {
- return locale.toString().replace('_', '-');
- }
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/transport/http/HttpServletRequestSnapshot.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/transport/http/HttpServletRequestSnapshot.java
deleted file mode 100644
index 6ae7a19..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/transport/http/HttpServletRequestSnapshot.java
+++ /dev/null
@@ -1,277 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.cxf.transport.http;
-
-import java.security.Principal;
-import java.util.Enumeration;
-import java.util.Locale;
-import java.util.Map;
-
-import javax.servlet.http.Cookie;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletRequestWrapper;
-import javax.servlet.http.HttpSession;
-
-public class HttpServletRequestSnapshot extends HttpServletRequestWrapper {
- private String authType;
- private String characterEncoding;
- private int contentLength;
- private String contentType;
- private String contextPath;
- private Cookie[] cookies;
- private String localAddr;
- private Locale local;
- @SuppressWarnings("rawtypes")
- private Enumeration locals;
- private String localName;
- private final int localPort;
- private String method;
- private String pathInfo;
- private String pathTranslated;
- private String protocol;
- private String queryString;
- private String remoteAddr;
- private String remoteHost;
- private final int remotePort;
- private String remoteUser;
- private String requestURI;
- private StringBuffer requestURL;
- private String schema;
- private String serverName;
- private final int serverPort;
- private String servletPath;
- private HttpSession session;
- private Principal principal;
- private Enumeration<String> requestHeaderNames;
- private Map<String, Enumeration<String>> headersMap =
- new java.util.concurrent.ConcurrentHashMap<>();
- private String requestedSessionId;
-
- public HttpServletRequestSnapshot(HttpServletRequest request) {
- super(request);
- authType = request.getAuthType();
- characterEncoding = request.getCharacterEncoding();
- contentLength = request.getContentLength();
- contentType = request.getContentType();
- contextPath = request.getContextPath();
- cookies = request.getCookies();
- requestHeaderNames = request.getHeaderNames();
- Enumeration<String> tmp = request.getHeaderNames();
- while (tmp.hasMoreElements()) {
- String key = tmp.nextElement();
- headersMap.put(key, request.getHeaders(key));
- }
- localAddr = request.getLocalAddr();
- local = request.getLocale();
- localName = request.getLocalName();
- localPort = request.getLocalPort();
- method = request.getMethod();
- pathInfo = request.getPathInfo();
- pathTranslated = request.getPathTranslated();
- protocol = request.getProtocol();
- queryString = request.getQueryString();
- remoteAddr = request.getRemoteAddr();
- remoteHost = request.getRemoteHost();
- remotePort = request.getRemotePort();
- remoteUser = request.getRemoteUser();
- requestURI = request.getRequestURI();
- requestURL = request.getRequestURL();
- requestedSessionId = request.getRequestedSessionId();
- schema = request.getScheme();
- serverName = request.getServerName();
- serverPort = request.getServerPort();
- servletPath = request.getServletPath();
- if (request.isRequestedSessionIdValid()) {
- session = request.getSession();
- }
- principal = request.getUserPrincipal();
- }
-
- @Override
- public String getAuthType() {
- return this.authType;
- }
-
- @Override
- public String getContextPath() {
- return this.contextPath;
- }
-
- @Override
- public Cookie[] getCookies() {
- return this.cookies;
- }
-
- @Override
- public String getHeader(String name) {
- if (headersMap.get(name) != null && headersMap.get(name).hasMoreElements()) {
- return headersMap.get(name).nextElement();
- }
- return null;
- }
-
- @SuppressWarnings({
- "unchecked", "rawtypes"
- })
- @Override
- public Enumeration getHeaderNames() {
- return this.requestHeaderNames;
- }
-
- @SuppressWarnings({
- "unchecked", "rawtypes"
- })
- @Override
- public Enumeration getHeaders(String name) {
- return headersMap.get(name);
- }
-
- @Override
- public String getMethod() {
- return this.method;
- }
-
- @Override
- public String getPathInfo() {
- return this.pathInfo;
- }
-
- @Override
- public String getPathTranslated() {
- return this.pathTranslated;
- }
-
- @Override
- public String getQueryString() {
- return this.queryString;
- }
-
- @Override
- public String getRemoteUser() {
- return this.remoteUser;
- }
-
- @Override
- public String getRequestURI() {
- return this.requestURI;
- }
-
- @Override
- public StringBuffer getRequestURL() {
- return this.requestURL;
- }
-
- @Override
- public String getRequestedSessionId() {
- return this.requestedSessionId;
- }
-
- @Override
- public String getServletPath() {
- return this.servletPath;
- }
-
- @Override
- public HttpSession getSession() {
- return this.session;
- }
-
- @Override
- public Principal getUserPrincipal() {
- return this.principal;
- }
-
- @Override
- public String getCharacterEncoding() {
- return this.characterEncoding;
- }
-
- @Override
- public int getContentLength() {
- return this.contentLength;
- }
-
- @Override
- public String getContentType() {
- return this.contentType;
- }
-
- @Override
- public String getLocalAddr() {
- return this.localAddr;
- }
-
- @Override
- public String getLocalName() {
- return this.localName;
- }
-
- @Override
- public int getLocalPort() {
- return this.localPort;
- }
-
- @Override
- public Locale getLocale() {
- return this.local;
- }
-
- @SuppressWarnings({
- "unchecked", "rawtypes"
- })
- @Override
- public Enumeration getLocales() {
- return this.locals;
- }
-
- @Override
- public String getProtocol() {
- return this.protocol;
- }
-
- @Override
- public String getRemoteAddr() {
- return this.remoteAddr;
- }
-
- @Override
- public String getRemoteHost() {
- return this.remoteHost;
- }
-
- @Override
- public int getRemotePort() {
- return this.remotePort;
- }
-
- @Override
- public String getScheme() {
- return this.schema;
- }
-
- @Override
- public String getServerName() {
- return this.serverName;
- }
-
- @Override
- public int getServerPort() {
- return this.serverPort;
- }
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/transport/http/ReferencingAuthenticator.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/transport/http/ReferencingAuthenticator.java
deleted file mode 100644
index 7872015..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/transport/http/ReferencingAuthenticator.java
+++ /dev/null
@@ -1,234 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.cxf.transport.http;
-
-import java.lang.invoke.MethodHandle;
-import java.lang.invoke.MethodHandles;
-import java.lang.invoke.MethodType;
-import java.lang.ref.Reference;
-import java.lang.ref.WeakReference;
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-import java.lang.reflect.Modifier;
-import java.net.Authenticator;
-import java.net.InetAddress;
-import java.net.PasswordAuthentication;
-import java.net.URL;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
-
-public class ReferencingAuthenticator extends Authenticator {
- private static final boolean SKIPCHECK = System.getSecurityManager() == null;
- final Reference<Authenticator> auth;
- final Authenticator wrapped;
-
- public ReferencingAuthenticator(Authenticator cxfauth, Authenticator wrapped) {
- this.auth = new WeakReference<>(cxfauth);
- this.wrapped = wrapped;
- }
-
- @Override
- protected PasswordAuthentication getPasswordAuthentication() {
- Authenticator cxfauth = auth.get();
- if (cxfauth == null) {
- remove();
- }
- PasswordAuthentication pauth = null;
- if (wrapped != null) {
- try {
- pauth = tryWith(wrapped);
- if (pauth != null) {
- return pauth;
- }
- } catch (Exception e) {
- pauth = null;
- }
- }
- if (cxfauth != null) {
- try {
- pauth = tryWith(cxfauth);
- } catch (Exception e1) {
- pauth = null;
- }
- }
- return pauth;
- }
-
- public final void check() {
- Authenticator cxfauth = auth.get();
- if (cxfauth == null) {
- remove();
- }
- if (wrapped != null && wrapped.getClass().getName().equals(ReferencingAuthenticator.class.getName())) {
- try {
- Method m = wrapped.getClass().getMethod("check");
- m.setAccessible(true);
- m.invoke(wrapped);
- } catch (Throwable t) {
- //ignore
- }
- }
- }
-
- private void remove() {
- try {
- // Try Authenticator.getDefault() first, JDK9+
- final MethodHandle mt = MethodHandles
- .lookup()
- .findStatic(Authenticator.class, "getDefault", MethodType.methodType(Authenticator.class));
- removeInternal((Authenticator)mt.invoke());
- } catch (final NoSuchMethodException | IllegalAccessException ex) {
- removeInternal();
- } catch (Throwable e) {
- //ignore
- }
- }
-
- private void removeInternal(final Authenticator def) {
- try {
- if (def == this) {
- //this is at the root of any chain of authenticators
- Authenticator.setDefault(wrapped);
- } else {
- removeFromChain(def);
- }
- } catch (Throwable t) {
- //ignore
- }
- }
-
- private void removeInternal() {
- try {
- for (final Field f : Authenticator.class.getDeclaredFields()) {
- if (f.getType().equals(Authenticator.class)) {
- try {
- f.setAccessible(true);
- Authenticator o = (Authenticator) f.get(null);
- if (o == this) {
- //this is at the root of any chain of authenticators
- Authenticator.setDefault(wrapped);
- } else {
- removeFromChain(o);
- }
- } catch (Exception e) {
- //ignore
- }
- }
- }
- } catch (Throwable t) {
- //ignore
- }
- }
-
- private void removeFromChain(Authenticator a) {
- try {
- if (a.getClass().getName().equals(ReferencingAuthenticator.class.getName())) {
- //multiple referencing authenticators, we can remove ourself
- Field f2 = a.getClass().getDeclaredField("wrapped");
- f2.setAccessible(true);
- Authenticator a2 = (Authenticator) f2.get(a);
- if (a2 == this) {
- f2.set(a, wrapped);
- } else {
- removeFromChain(a2);
- }
- }
- } catch (Throwable t) {
- //ignore
- }
- }
-
- PasswordAuthentication tryWith(Authenticator a) throws Exception {
- if (a == null) {
- return null;
- }
-
- try {
- // Try Authenticator.requestPasswordAuthentication() first, JDK9+
- final MethodHandle mt = MethodHandles
- .lookup()
- .findStatic(Authenticator.class, "requestPasswordAuthentication",
- MethodType.methodType(PasswordAuthentication.class, new Class<?>[] {
- Authenticator.class,
- String.class,
- InetAddress.class,
- int.class,
- String.class,
- String.class,
- String.class,
- URL.class,
- RequestorType.class
- }));
-
- return (PasswordAuthentication)mt.invoke(a, getRequestingHost(), getRequestingSite(),
- getRequestingPort(), getRequestingProtocol(), getRequestingPrompt(), getRequestingScheme(),
- getRequestingURL(), getRequestorType());
- } catch (final NoSuchMethodException | IllegalAccessException ex) {
- return tryWithInternal(a);
- } catch (final Throwable ex) {
- if (ex instanceof Exception) {
- throw (Exception)ex;
- } else {
- throw new Exception(ex);
- }
- }
- }
-
- private PasswordAuthentication tryWithInternal(Authenticator a) throws Exception {
- if (a == null) {
- return null;
- }
- final Field[] fields;
- if (SKIPCHECK) {
- fields = Authenticator.class.getDeclaredFields();
- } else {
- fields = AccessController.doPrivileged(
- (PrivilegedAction<Field[]>) () -> Authenticator.class.getDeclaredFields());
-
- }
-
- for (final Field f : fields) {
- if (!Modifier.isStatic(f.getModifiers())) {
- f.setAccessible(true);
- Object o = f.get(this);
- f.set(a, o);
- }
- }
- Method method;
- if (SKIPCHECK) {
- method = Authenticator.class.getDeclaredMethod("getPasswordAuthentication");
- method.setAccessible(true);
- } else {
- method = AccessController.doPrivileged(
- (PrivilegedAction<Method>) () -> {
- try {
- return Authenticator.class.getDeclaredMethod("getPasswordAuthentication");
- } catch (NoSuchMethodException e) {
- throw new RuntimeException(e);
- }
- });
- AccessController.doPrivileged((PrivilegedAction<Object>) () -> {
- method.setAccessible(true);
- return null;
- });
- }
-
- return (PasswordAuthentication) method.invoke(a);
- }
-}
\ No newline at end of file
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/transport/http/Servlet3ContinuationProvider.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/transport/http/Servlet3ContinuationProvider.java
deleted file mode 100644
index f593a3f..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/transport/http/Servlet3ContinuationProvider.java
+++ /dev/null
@@ -1,281 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.cxf.transport.http;
-
-import java.io.IOException;
-
-import javax.servlet.AsyncContext;
-import javax.servlet.AsyncEvent;
-import javax.servlet.AsyncListener;
-import javax.servlet.ServletOutputStream;
-import javax.servlet.WriteListener;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.apache.cxf.common.classloader.ClassLoaderUtils;
-import org.apache.cxf.common.util.PropertyUtils;
-import org.apache.cxf.continuations.Continuation;
-import org.apache.cxf.continuations.ContinuationCallback;
-import org.apache.cxf.continuations.ContinuationProvider;
-import org.apache.cxf.message.Message;
-import org.apache.cxf.phase.PhaseInterceptorChain;
-
-/**
- *
- */
-public class Servlet3ContinuationProvider implements ContinuationProvider {
- static final boolean IS_31;
- static {
- boolean is31;
- try {
- ClassLoaderUtils.loadClass("javax.servlet.WriteListener", HttpServletRequest.class);
- is31 = true;
- } catch (Throwable t) {
- is31 = false;
- }
- IS_31 = is31;
- }
-
- HttpServletRequest req;
- HttpServletResponse resp;
- Message inMessage;
- Servlet3Continuation continuation;
-
- public Servlet3ContinuationProvider(HttpServletRequest req,
- HttpServletResponse resp,
- Message inMessage) {
- this.inMessage = inMessage;
- this.req = req;
- this.resp = resp;
- }
-
- public void complete() {
- if (continuation != null) {
- continuation.reset();
- continuation = null;
- }
- }
-
-
- /** {@inheritDoc}*/
- public Continuation getContinuation() {
- if (inMessage.getExchange().isOneWay()) {
- return null;
- }
-
- if (continuation == null) {
- continuation = IS_31 ? new Servlet31Continuation() : new Servlet3Continuation();
- } else {
- continuation.startAsyncAgain();
- }
- return continuation;
- }
-
- public class Servlet3Continuation implements Continuation, AsyncListener {
- private static final String BLOCK_RESTART = "org.apache.cxf.continuation.block.restart";
- AsyncContext context;
- volatile boolean isNew = true;
- volatile boolean isResumed;
- volatile boolean isPending;
- volatile boolean isComplete;
- volatile boolean isTimeout;
- volatile Object obj;
- private ContinuationCallback callback;
- private boolean blockRestart;
-
- public Servlet3Continuation() {
- req.setAttribute(AbstractHTTPDestination.CXF_CONTINUATION_MESSAGE,
- inMessage.getExchange().getInMessage());
- callback = inMessage.getExchange().get(ContinuationCallback.class);
- blockRestart = PropertyUtils.isTrue(inMessage.getContextualProperty(BLOCK_RESTART));
- context = req.startAsync();
- context.addListener(this);
- }
-
- void startAsyncAgain() {
- if (blockRestart) {
- return;
- }
- AsyncContext old = context;
- try {
- context = req.startAsync();
- context.addListener(this);
- isComplete = false;
- } catch (IllegalStateException ex) {
- context = old;
- }
- }
-
- public boolean suspend(long timeout) {
- if (isPending && timeout != 0) {
- long currentTimeout = context.getTimeout();
- timeout = currentTimeout + timeout;
- } else {
- isPending = true;
- }
- isNew = false;
- isResumed = false;
-
- context.setTimeout(timeout);
-
- updateMessageForSuspend();
- return true;
- }
- protected void updateMessageForSuspend() {
- inMessage.getExchange().getInMessage().getInterceptorChain().suspend();
- }
- public void redispatch() {
- if (!isComplete) {
- context.dispatch();
- }
- }
- public void resume() {
- isResumed = true;
- isPending = false;
- redispatch();
- }
-
- public void reset() {
- isComplete = true;
- try {
- context.complete();
- } catch (IllegalStateException ex) {
- // ignore
- }
- isPending = false;
- isResumed = false;
- isNew = false;
- isTimeout = false;
- obj = null;
- if (callback != null) {
- final Exception ex = inMessage.getExchange().get(Exception.class);
- Throwable cause = isCausedByIO(ex);
-
- if (cause != null && isClientDisconnected(cause)) {
- callback.onDisconnect();
- }
- }
- }
-
- public boolean isNew() {
- return isNew;
- }
-
- public boolean isPending() {
- return isPending;
- }
-
- public boolean isResumed() {
- return isResumed;
- }
-
- public Object getObject() {
- return obj;
- }
-
- public void setObject(Object o) {
- obj = o;
- }
-
- public void onComplete(AsyncEvent event) throws IOException {
- inMessage.getExchange().getInMessage()
- .remove(AbstractHTTPDestination.CXF_CONTINUATION_MESSAGE);
- if (callback != null) {
- final Exception ex = inMessage.getExchange().get(Exception.class);
- if (ex == null) {
- callback.onComplete();
- } else {
- callback.onError(ex);
- }
- }
- isResumed = false;
- isPending = false;
- }
- public void onError(AsyncEvent event) throws IOException {
- if (callback != null) {
- callback.onError(event.getThrowable());
- }
- }
- public void onStartAsync(AsyncEvent event) throws IOException {
- }
- public void onTimeout(AsyncEvent event) throws IOException {
- resume();
- isTimeout = true;
- }
-
- private Throwable isCausedByIO(final Exception ex) {
- Throwable cause = ex;
-
- while (cause != null && !(cause instanceof IOException)) {
- cause = cause.getCause();
- }
-
- return cause;
- }
-
- private boolean isClientDisconnected(Throwable ex) {
- String exName = (String)inMessage.getContextualProperty("disconnected.client.exception.class");
- if (exName != null) {
- return exName.equals(IOException.class.getName()) || exName.equals(ex.getClass().getName());
- }
- return false;
- }
-
- @Override
- public boolean isReadyForWrite() {
- return true;
- }
-
- protected ServletOutputStream getOutputStream() {
- try {
- return resp.getOutputStream();
- } catch (IOException ex) {
- throw new RuntimeException(ex);
- }
- }
-
- @Override
- public boolean isTimeout() {
- return isTimeout;
- }
- }
- public class Servlet31Continuation extends Servlet3Continuation {
- public Servlet31Continuation() {
- }
-
- @Override
- protected void updateMessageForSuspend() {
- Message currentMessage = PhaseInterceptorChain.getCurrentMessage();
- if (currentMessage.get(WriteListener.class) != null) {
- // CXF Continuation WriteListener will likely need to be introduced
- // for NIO supported with non-Servlet specific mechanisms
- getOutputStream().setWriteListener(currentMessage.get(WriteListener.class));
- currentMessage.getInterceptorChain().suspend();
- } else {
- inMessage.getExchange().getInMessage().getInterceptorChain().suspend();
- }
- }
-
- @Override
- public boolean isReadyForWrite() {
- return getOutputStream().isReady();
- }
- }
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/transport/http/URLConnectionHTTPConduit.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/transport/http/URLConnectionHTTPConduit.java
deleted file mode 100644
index e31b2c5..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/transport/http/URLConnectionHTTPConduit.java
+++ /dev/null
@@ -1,439 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.cxf.transport.http;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.net.HttpURLConnection;
-import java.net.ProtocolException;
-import java.net.Proxy;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.net.URL;
-import java.net.URLConnection;
-import java.security.AccessController;
-import java.security.PrivilegedActionException;
-import java.security.PrivilegedExceptionAction;
-import java.util.logging.Level;
-
-import javax.net.ssl.HttpsURLConnection;
-
-import org.apache.cxf.Bus;
-import org.apache.cxf.common.util.ReflectionUtil;
-import org.apache.cxf.common.util.SystemPropertyAction;
-import org.apache.cxf.configuration.jsse.TLSClientParameters;
-import org.apache.cxf.helpers.IOUtils;
-import org.apache.cxf.io.CacheAndWriteOutputStream;
-import org.apache.cxf.message.Message;
-import org.apache.cxf.message.MessageUtils;
-import org.apache.cxf.service.model.EndpointInfo;
-import org.apache.cxf.transport.https.HttpsURLConnectionFactory;
-import org.apache.cxf.transport.https.HttpsURLConnectionInfo;
-import org.apache.cxf.transports.http.configuration.HTTPClientPolicy;
-import org.apache.cxf.ws.addressing.EndpointReferenceType;
-
-/**
- *
- */
-public class URLConnectionHTTPConduit extends HTTPConduit {
- public static final String HTTPURL_CONNECTION_METHOD_REFLECTION = "use.httpurlconnection.method.reflection";
- public static final String SET_REASON_PHRASE_NOT_NULL = "set.reason.phrase.not.null";
-
- private static final boolean DEFAULT_USE_REFLECTION;
- private static final boolean SET_REASON_PHRASE;
- static {
- DEFAULT_USE_REFLECTION =
- Boolean.valueOf(SystemPropertyAction.getProperty(HTTPURL_CONNECTION_METHOD_REFLECTION, "false"));
- SET_REASON_PHRASE =
- Boolean.valueOf(SystemPropertyAction.getProperty(SET_REASON_PHRASE_NOT_NULL, "false"));
- }
-
- /**
- * This field holds the connection factory, which primarily is used to
- * factor out SSL specific code from this implementation.
- * <p>
- * This field is "protected" to facilitate some contrived UnitTesting so
- * that an extended class may alter its value with an EasyMock URLConnection
- * Factory.
- */
- protected HttpsURLConnectionFactory connectionFactory;
-
-
- public URLConnectionHTTPConduit(Bus b, EndpointInfo ei) throws IOException {
- super(b, ei);
- connectionFactory = new HttpsURLConnectionFactory();
- CXFAuthenticator.addAuthenticator();
- }
-
- public URLConnectionHTTPConduit(Bus b, EndpointInfo ei, EndpointReferenceType t) throws IOException {
- super(b, ei, t);
- connectionFactory = new HttpsURLConnectionFactory();
- CXFAuthenticator.addAuthenticator();
- }
-
- /**
- * Close the conduit
- */
- public void close() {
- super.close();
- if (defaultAddress != null) {
- try {
- URLConnection connect = defaultAddress.getURL().openConnection();
- if (connect instanceof HttpURLConnection) {
- ((HttpURLConnection)connect).disconnect();
- }
- } catch (IOException ex) {
- //ignore
- }
- //defaultEndpointURL = null;
- }
- }
-
- private HttpURLConnection createConnection(Message message, Address address, HTTPClientPolicy csPolicy)
- throws IOException {
- URL url = address.getURL();
- URI uri = address.getURI();
- Proxy proxy = proxyFactory.createProxy(csPolicy, uri);
- message.put("http.scheme", uri.getScheme());
- // check tlsClientParameters from message header
- TLSClientParameters clientParameters = message.get(TLSClientParameters.class);
- if (clientParameters == null) {
- clientParameters = tlsClientParameters;
- }
- return connectionFactory.createConnection(clientParameters,
- proxy != null ? proxy : address.getDefaultProxy(), url);
- }
- protected void setupConnection(Message message, Address address, HTTPClientPolicy csPolicy) throws IOException {
- HttpURLConnection connection = createConnection(message, address, csPolicy);
- connection.setDoOutput(true);
-
- int ctimeout = determineConnectionTimeout(message, csPolicy);
- connection.setConnectTimeout(ctimeout);
-
- int rtimeout = determineReceiveTimeout(message, csPolicy);
- connection.setReadTimeout(rtimeout);
-
- connection.setUseCaches(false);
- // We implement redirects in this conduit. We do not
- // rely on the underlying URLConnection implementation
- // because of trust issues.
- connection.setInstanceFollowRedirects(false);
-
- // If the HTTP_REQUEST_METHOD is not set, the default is "POST".
- String httpRequestMethod =
- (String)message.get(Message.HTTP_REQUEST_METHOD);
- if (httpRequestMethod == null) {
- httpRequestMethod = "POST";
- message.put(Message.HTTP_REQUEST_METHOD, "POST");
- }
- try {
- connection.setRequestMethod(httpRequestMethod);
- } catch (java.net.ProtocolException ex) {
- boolean b = MessageUtils.getContextualBoolean(message,
- HTTPURL_CONNECTION_METHOD_REFLECTION,
- DEFAULT_USE_REFLECTION);
- if (b) {
- try {
- java.lang.reflect.Field f = ReflectionUtil.getDeclaredField(HttpURLConnection.class, "method");
- if (connection instanceof HttpsURLConnection) {
- try {
- java.lang.reflect.Field f2 = ReflectionUtil.getDeclaredField(connection.getClass(),
- "delegate");
- Object c = ReflectionUtil.setAccessible(f2).get(connection);
- if (c instanceof HttpURLConnection) {
- ReflectionUtil.setAccessible(f).set(c, httpRequestMethod);
- }
-
- f2 = ReflectionUtil.getDeclaredField(c.getClass(), "httpsURLConnection");
- HttpsURLConnection c2 = (HttpsURLConnection)ReflectionUtil.setAccessible(f2)
- .get(c);
-
- ReflectionUtil.setAccessible(f).set(c2, httpRequestMethod);
- } catch (Throwable t) {
- //ignore
- logStackTrace(t);
- }
- }
- ReflectionUtil.setAccessible(f).set(connection, httpRequestMethod);
- message.put(HTTPURL_CONNECTION_METHOD_REFLECTION, true);
- } catch (Throwable t) {
- logStackTrace(t);
- throw ex;
- }
- } else {
- throw ex;
- }
- }
-
- // We place the connection on the message to pick it up
- // in the WrappedOutputStream.
- message.put(KEY_HTTP_CONNECTION, connection);
- message.put(KEY_HTTP_CONNECTION_ADDRESS, address);
- }
-
-
- protected OutputStream createOutputStream(Message message,
- boolean needToCacheRequest,
- boolean isChunking,
- int chunkThreshold) throws IOException {
- HttpURLConnection connection = (HttpURLConnection)message.get(KEY_HTTP_CONNECTION);
-
- if (isChunking && chunkThreshold <= 0) {
- chunkThreshold = 0;
- connection.setChunkedStreamingMode(-1);
- }
- try {
- return new URLConnectionWrappedOutputStream(message, connection,
- needToCacheRequest,
- isChunking,
- chunkThreshold,
- getConduitName());
- } catch (URISyntaxException e) {
- throw new IOException(e);
- }
- }
-
- private static URI computeURI(Message message, HttpURLConnection connection) throws URISyntaxException {
- Address address = (Address)message.get(KEY_HTTP_CONNECTION_ADDRESS);
- return address != null ? address.getURI() : connection.getURL().toURI();
- }
-
- class URLConnectionWrappedOutputStream extends WrappedOutputStream {
- HttpURLConnection connection;
- URLConnectionWrappedOutputStream(Message message, HttpURLConnection connection,
- boolean needToCacheRequest, boolean isChunking,
- int chunkThreshold, String conduitName) throws URISyntaxException {
- super(message, needToCacheRequest, isChunking,
- chunkThreshold, conduitName,
- computeURI(message, connection));
- this.connection = connection;
- }
-
- // This construction makes extending the HTTPConduit more easier
- protected URLConnectionWrappedOutputStream(URLConnectionWrappedOutputStream wos) {
- super(wos);
- this.connection = wos.connection;
- }
- private OutputStream connectAndGetOutputStream(Boolean b) throws IOException {
- OutputStream cout = null;
-
- if (b != null && b) {
- String method = connection.getRequestMethod();
- connection.connect();
- try {
- java.lang.reflect.Field f = ReflectionUtil.getDeclaredField(HttpURLConnection.class, "method");
- ReflectionUtil.setAccessible(f).set(connection, "POST");
- cout = connection.getOutputStream();
- ReflectionUtil.setAccessible(f).set(connection, method);
- } catch (Throwable t) {
- logStackTrace(t);
- }
-
- } else {
- cout = connection.getOutputStream();
- }
- return cout;
- }
- protected void setupWrappedStream() throws IOException {
- // If we need to cache for retransmission, store data in a
- // CacheAndWriteOutputStream. Otherwise write directly to the output stream.
- OutputStream cout;
- try {
- try {
-// cout = connection.getOutputStream();
- if (System.getSecurityManager() != null) {
- try {
- cout = AccessController.doPrivileged(new PrivilegedExceptionAction<OutputStream>() {
- @Override
- public OutputStream run() throws IOException {
- return connection.getOutputStream();
- }
- });
- } catch (PrivilegedActionException e) {
- throw (IOException) e.getException();
- }
- } else {
- cout = connection.getOutputStream();
- }
- } catch (ProtocolException pe) {
- Boolean b = (Boolean)outMessage.get(HTTPURL_CONNECTION_METHOD_REFLECTION);
- cout = connectAndGetOutputStream(b);
- }
- } catch (Exception e) {
- if ("Socket Closed".equals(e.getMessage())
- || "HostnameVerifier, socket reset for TTL".equals(e.getMessage())) {
- connection.connect();
- cout = connectAndGetOutputStream((Boolean)outMessage.get(HTTPURL_CONNECTION_METHOD_REFLECTION));
- } else {
- throw e;
- }
- }
- if (cachingForRetransmission) {
- cachedStream =
- new CacheAndWriteOutputStream(cout);
- wrappedStream = cachedStream;
- } else {
- wrappedStream = cout;
- }
- }
-
- @Override
- public void thresholdReached() {
- if (chunking) {
- connection.setChunkedStreamingMode(
- URLConnectionHTTPConduit.this.getClient().getChunkLength());
- }
- }
- @Override
- protected void onFirstWrite() throws IOException {
- super.onFirstWrite();
- if (LOG.isLoggable(Level.FINE)) {
- LOG.fine("Sending "
- + connection.getRequestMethod()
- + " Message with Headers to "
- + url
- + " Conduit :"
- + conduitName
- + "\n");
- }
- }
- protected void setProtocolHeaders() throws IOException {
- new Headers(outMessage).setProtocolHeadersInConnection(connection);
- }
-
- protected HttpsURLConnectionInfo getHttpsURLConnectionInfo() throws IOException {
- connection.connect();
- return new HttpsURLConnectionInfo(connection);
- }
- protected void updateResponseHeaders(Message inMessage) {
- Headers h = new Headers(inMessage);
- h.readFromConnection(connection);
- inMessage.put(Message.CONTENT_TYPE, connection.getContentType());
- cookies.readFromHeaders(h);
- }
- protected void handleResponseAsync() throws IOException {
- handleResponseOnWorkqueue(true, false);
- }
- protected void updateCookiesBeforeRetransmit() {
- Headers h = new Headers();
- h.readFromConnection(connection);
- cookies.readFromHeaders(h);
- }
-
- protected InputStream getInputStream() throws IOException {
- InputStream in;
- if (getResponseCode() >= HttpURLConnection.HTTP_BAD_REQUEST) {
- in = connection.getErrorStream();
- if (in == null) {
- try {
- // just in case - but this will most likely cause an exception
- in = connection.getInputStream();
- } catch (IOException ex) {
- // ignore
- }
- }
- } else {
- in = connection.getInputStream();
- }
- return in;
- }
-
-
- protected void closeInputStream() throws IOException {
- //try and consume any content so that the connection might be reusable
- InputStream ins = connection.getErrorStream();
- if (ins == null) {
- ins = connection.getInputStream();
- }
- if (ins != null) {
- IOUtils.consume(ins);
- ins.close();
- }
- }
- protected int getResponseCode() throws IOException {
- try {
- return AccessController.doPrivileged(new PrivilegedExceptionAction<Integer>() {
-
- @Override
- public Integer run() throws IOException {
- return connection.getResponseCode();
- } });
- } catch (PrivilegedActionException e) {
- Throwable t = e.getCause();
- if (t instanceof IOException) {
- throw (IOException) t;
- }
- throw new RuntimeException(t);
- }
- }
- protected String getResponseMessage() throws IOException {
- boolean b = MessageUtils.getContextualBoolean(this.outMessage,
- SET_REASON_PHRASE_NOT_NULL,
- SET_REASON_PHRASE);
- if (connection.getResponseMessage() == null && b) {
- //some http server like tomcat 8.5+ won't return the
- //reason phrase in response, return a informative value
- //to tell user no reason phrase in the response instead of null
- return "no reason phrase in the response";
- }
- return connection.getResponseMessage();
- }
- protected InputStream getPartialResponse() throws IOException {
- return ChunkedUtil.getPartialResponse(connection, connection.getResponseCode());
- }
- protected boolean usingProxy() {
- return connection.usingProxy();
- }
- protected void setFixedLengthStreamingMode(int i) {
- // [CXF-6227] do not call connection.setFixedLengthStreamingMode(i)
- // to prevent https://bugs.openjdk.java.net/browse/JDK-8044726
- }
- protected void handleNoOutput() throws IOException {
- if ("POST".equals(getMethod())) {
- connection.getOutputStream().close();
- }
- }
- protected void setupNewConnection(String newURL) throws IOException {
- HTTPClientPolicy cp = getClient(outMessage);
- Address address;
- try {
- if (defaultAddress.getString().equals(newURL)) {
- address = defaultAddress;
- } else {
- address = new Address(newURL);
- }
- } catch (URISyntaxException e) {
- throw new IOException(e);
- }
- setupConnection(outMessage, address, cp);
- this.url = address.getURI();
- connection = (HttpURLConnection)outMessage.get(KEY_HTTP_CONNECTION);
- }
-
- @Override
- protected void retransmitStream() throws IOException {
- Boolean b = (Boolean)outMessage.get(HTTPURL_CONNECTION_METHOD_REFLECTION);
- OutputStream out = connectAndGetOutputStream(b);
- cachedStream.writeCacheTo(out);
- }
- }
-
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/transport/https/HttpsURLConnectionFactory.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/transport/https/HttpsURLConnectionFactory.java
deleted file mode 100644
index d42549d..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/transport/https/HttpsURLConnectionFactory.java
+++ /dev/null
@@ -1,247 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.cxf.transport.https;
-
-import java.io.IOException;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.Method;
-import java.net.HttpURLConnection;
-import java.net.Proxy;
-import java.net.URL;
-import java.security.AccessController;
-import java.security.GeneralSecurityException;
-import java.security.PrivilegedAction;
-import java.util.logging.Handler;
-import java.util.logging.Logger;
-
-import javax.net.ssl.HostnameVerifier;
-import javax.net.ssl.HttpsURLConnection;
-import javax.net.ssl.SSLContext;
-import javax.net.ssl.SSLSocketFactory;
-
-import org.apache.cxf.common.logging.LogUtils;
-import org.apache.cxf.common.util.ReflectionInvokationHandler;
-import org.apache.cxf.common.util.ReflectionUtil;
-import org.apache.cxf.configuration.jsse.SSLUtils;
-import org.apache.cxf.configuration.jsse.TLSClientParameters;
-
-
-/**
- * This HttpsURLConnectionFactory implements the HttpURLConnectionFactory
- * for using the given SSL Policy to configure TLS connections for "https:"
- * URLs.
- */
-public class HttpsURLConnectionFactory {
-
- /**
- * This constant holds the URL Protocol Identifier for HTTPS
- */
- public static final String HTTPS_URL_PROTOCOL_ID = "https";
-
- private static final Logger LOG =
- LogUtils.getL7dLogger(HttpsURLConnectionFactory.class);
-
- private static boolean weblogicWarned;
-
- /**
- * Cache the last SSLContext to avoid recreation
- */
- SSLSocketFactory socketFactory;
- int lastTlsHash;
-
- /**
- * This constructor initialized the factory with the configured TLS
- * Client Parameters for the HTTPConduit for which this factory is used.
- */
- public HttpsURLConnectionFactory() {
- }
-
- /**
- * Create a HttpURLConnection, proxified if necessary.
- *
- *
- * @param proxy This parameter is non-null if connection should be proxied.
- * @param url The target URL.
- *
- * @return The HttpURLConnection for the given URL.
- * @throws IOException
- */
- public HttpURLConnection createConnection(TLSClientParameters tlsClientParameters,
- Proxy proxy, URL url) throws IOException {
-
- HttpURLConnection connection =
- (HttpURLConnection) (proxy != null
- ? url.openConnection(proxy)
- : url.openConnection());
- if (HTTPS_URL_PROTOCOL_ID.equals(url.getProtocol())) {
-
- if (tlsClientParameters == null) {
- tlsClientParameters = new TLSClientParameters();
- }
-
- try {
- decorateWithTLS(tlsClientParameters, connection);
- } catch (Throwable ex) {
- throw new IOException("Error while initializing secure socket", ex);
- }
- }
-
- return connection;
- }
-
- /**
- * This method assigns the various TLS parameters on the HttpsURLConnection
- * from the TLS Client Parameters. Connection parameter is of supertype HttpURLConnection,
- * which allows internal cast to potentially divergent subtype (https) implementations.
- */
- protected synchronized void decorateWithTLS(TLSClientParameters tlsClientParameters,
- HttpURLConnection connection) throws GeneralSecurityException {
-
-
- int hash = tlsClientParameters.hashCode();
- if (hash != lastTlsHash) {
- lastTlsHash = hash;
- socketFactory = null;
- }
-
- // always reload socketFactory from HttpsURLConnection.defaultSSLSocketFactory and
- // tlsClientParameters.sslSocketFactory to allow runtime configuration change
- if (tlsClientParameters.isUseHttpsURLConnectionDefaultSslSocketFactory()) {
- socketFactory = HttpsURLConnection.getDefaultSSLSocketFactory();
-
- } else if (tlsClientParameters.getSSLSocketFactory() != null) {
- // see if an SSLSocketFactory was set. This allows easy interop
- // with not-yet-commons-ssl.jar, or even just people who like doing their
- // own JSSE.
- socketFactory = tlsClientParameters.getSSLSocketFactory();
-
- } else if (socketFactory == null) {
-
- final SSLContext ctx;
- if (tlsClientParameters.getSslContext() != null) {
- // Use the SSLContext which was set
- ctx = tlsClientParameters.getSslContext();
- } else {
- // Create socketfactory with tlsClientParameters's Trust Managers, Key Managers, etc
- ctx = org.apache.cxf.transport.https.SSLUtils.getSSLContext(tlsClientParameters);
- }
-
- String[] cipherSuites =
- SSLUtils.getCiphersuitesToInclude(tlsClientParameters.getCipherSuites(),
- tlsClientParameters.getCipherSuitesFilter(),
- ctx.getSocketFactory().getDefaultCipherSuites(),
- SSLUtils.getSupportedCipherSuites(ctx),
- LOG);
-
- // The SSLSocketFactoryWrapper enables certain cipher suites from the policy.
- String protocol = tlsClientParameters.getSecureSocketProtocol() != null ? tlsClientParameters
- .getSecureSocketProtocol() : ctx.getProtocol();
- socketFactory = new SSLSocketFactoryWrapper(ctx.getSocketFactory(), cipherSuites,
- protocol);
- //recalc the hashcode since some of the above MAY have changed the tlsClientParameters
- lastTlsHash = tlsClientParameters.hashCode();
- } else {
- // ssl socket factory already initialized, reuse it to benefit of keep alive
- }
-
-
- HostnameVerifier verifier = org.apache.cxf.transport.https.SSLUtils
- .getHostnameVerifier(tlsClientParameters);
-
- if (connection instanceof HttpsURLConnection) {
- // handle the expected case (javax.net.ssl)
- HttpsURLConnection conn = (HttpsURLConnection) connection;
- conn.setHostnameVerifier(verifier);
- AccessController.doPrivileged(new PrivilegedAction<Void>() {
-
- @Override
- public Void run() {
- conn.setSSLSocketFactory(socketFactory);
- return null;
- } });
- } else {
- // handle the deprecated sun case and other possible hidden API's
- // that are similar to the Sun cases
- try {
- Method method = connection.getClass().getMethod("getHostnameVerifier");
-
- InvocationHandler handler = new ReflectionInvokationHandler(verifier) {
- public Object invoke(Object proxy,
- Method method,
- Object[] args) throws Throwable {
- try {
- return super.invoke(proxy, method, args);
- } catch (Exception ex) {
- return false;
- }
- }
- };
- Object proxy = java.lang.reflect.Proxy.newProxyInstance(this.getClass().getClassLoader(),
- new Class[] {method.getReturnType()},
- handler);
-
- method = connection.getClass().getMethod("setHostnameVerifier", method.getReturnType());
- method.invoke(connection, proxy);
- } catch (Exception ex) {
- //Ignore this one
- }
- try {
- Method getSSLSocketFactory = connection.getClass().getMethod("getSSLSocketFactory");
- Method setSSLSocketFactory = connection.getClass()
- .getMethod("setSSLSocketFactory", getSSLSocketFactory.getReturnType());
- if (getSSLSocketFactory.getReturnType().isInstance(socketFactory)) {
- setSSLSocketFactory.invoke(connection, socketFactory);
- } else {
- //need to see if we can create one - mostly the weblogic case. The
- //weblogic SSLSocketFactory has a protected constructor that can take
- //a JSSE SSLSocketFactory so we'll try and use that
- Constructor<?> c = getSSLSocketFactory.getReturnType()
- .getDeclaredConstructor(SSLSocketFactory.class);
- ReflectionUtil.setAccessible(c);
- setSSLSocketFactory.invoke(connection, c.newInstance(socketFactory));
- }
- } catch (Exception ex) {
- if (connection.getClass().getName().contains("weblogic")) {
- if (!weblogicWarned) {
- weblogicWarned = true;
- LOG.warning("Could not configure SSLSocketFactory on Weblogic. "
- + " Use the Weblogic control panel to configure the SSL settings.");
- }
- return;
- }
- //if we cannot set the SSLSocketFactory, we're in serious trouble.
- throw new IllegalArgumentException("Error decorating connection class "
- + connection.getClass().getName(), ex);
- }
- }
- }
-
- /*
- * For development and testing only
- */
- protected void addLogHandler(Handler handler) {
- LOG.addHandler(handler);
- }
-
-}
-
-
-
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/transport/servlet/servicelist/ServiceListJAASAuthenticator.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/transport/servlet/servicelist/ServiceListJAASAuthenticator.java
deleted file mode 100644
index 8562cd3..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/transport/servlet/servicelist/ServiceListJAASAuthenticator.java
+++ /dev/null
@@ -1,160 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.cxf.transport.servlet.servicelist;
-
-import java.io.IOException;
-import java.nio.charset.StandardCharsets;
-import java.security.GeneralSecurityException;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import javax.security.auth.Subject;
-import javax.security.auth.callback.Callback;
-import javax.security.auth.callback.CallbackHandler;
-import javax.security.auth.callback.NameCallback;
-import javax.security.auth.callback.PasswordCallback;
-import javax.security.auth.callback.UnsupportedCallbackException;
-import javax.security.auth.login.AccountException;
-import javax.security.auth.login.FailedLoginException;
-import javax.security.auth.login.LoginContext;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.apache.cxf.common.logging.LogUtils;
-import org.apache.cxf.common.util.Base64Exception;
-import org.apache.cxf.common.util.Base64Utility;
-import org.apache.cxf.transport.http.blueprint.HttpDestinationBPBeanDefinitionParser;
-
-
-
-public class ServiceListJAASAuthenticator {
-
- private static final Logger LOG = LogUtils.getL7dLogger(HttpDestinationBPBeanDefinitionParser.class);
-
- private static final String HEADER_WWW_AUTHENTICATE = "WWW-Authenticate";
-
- private static final String HEADER_AUTHORIZATION = "Authorization";
-
- private static final String AUTHENTICATION_SCHEME_BASIC = "Basic";
-
- private String realm;
-
- public String getRealm() {
- return realm;
- }
-
- public void setRealm(String realm) {
- this.realm = realm;
- }
-
-
- public Object authenticate(final String username, final String password) {
- return doAuthenticate(username, password);
- }
-
- public Subject doAuthenticate(final String username, final String password) {
- try {
- Subject subject = new Subject();
- LoginContext loginContext = new LoginContext(realm, subject, new CallbackHandler() {
- public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
- for (int i = 0; i < callbacks.length; i++) {
- if (callbacks[i] instanceof NameCallback) {
- ((NameCallback)callbacks[i]).setName(username);
- } else if (callbacks[i] instanceof PasswordCallback) {
- ((PasswordCallback)callbacks[i]).setPassword(password.toCharArray());
- } else {
- throw new UnsupportedCallbackException(callbacks[i]);
- }
- }
- }
- });
- loginContext.login();
- return subject;
- } catch (FailedLoginException e) {
- LOG.log(Level.FINE, "Login failed ", e);
- return null;
- } catch (AccountException e) {
- LOG.log(Level.WARNING, "Account failure ", e);
- return null;
- } catch (GeneralSecurityException e) {
- LOG.log(Level.SEVERE, "General Security Exception ", e);
- return null;
- }
- }
-
- public boolean authenticate(HttpServletRequest request, HttpServletResponse response) {
- // Return immediately if the header is missing
- String authHeader = request.getHeader(HEADER_AUTHORIZATION);
- if (authHeader != null && authHeader.length() > 0) {
-
- // Get the authType (Basic, Digest) and authInfo (user/password)
- // from the header
- authHeader = authHeader.trim();
- int blank = authHeader.indexOf(' ');
- if (blank > 0) {
- String authType = authHeader.substring(0, blank);
- String authInfo = authHeader.substring(blank).trim();
-
-
- if (authType.equalsIgnoreCase(AUTHENTICATION_SCHEME_BASIC)) {
- try {
- String srcString = base64Decode(authInfo);
-
- int i = srcString.indexOf(':');
- String username = srcString.substring(0, i);
- String password = srcString.substring(i + 1);
-
- // authenticate
- Subject subject = doAuthenticate(username, password);
- if (subject != null) {
- return true;
- }
-
- } catch (Exception e) {
- // Ignore
- }
- }
- }
- }
-
- // request authentication
- try {
- response.setHeader(HEADER_WWW_AUTHENTICATE, AUTHENTICATION_SCHEME_BASIC + " realm=\""
- + this.realm + "\"");
- response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
- response.setContentLength(0);
- response.flushBuffer();
- } catch (IOException ioe) {
- // failed sending the response ... cannot do anything about it
- }
-
- // inform HttpService that authentication failed
- return false;
- }
-
- private static String base64Decode(String srcString) {
- try {
- byte[] transformed = Base64Utility.decode(srcString);
- return new String(transformed, StandardCharsets.ISO_8859_1);
- } catch (Base64Exception e) {
- return srcString;
- }
- }
-
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/validation/AbstractBeanValidationInterceptor.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/validation/AbstractBeanValidationInterceptor.java
deleted file mode 100644
index 3fecf1a..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/validation/AbstractBeanValidationInterceptor.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.cxf.validation;
-
-import java.lang.reflect.Method;
-import java.util.List;
-
-import javax.validation.ValidationException;
-
-import org.apache.cxf.message.Message;
-
-public abstract class AbstractBeanValidationInterceptor extends AbstractValidationInterceptor {
- protected AbstractBeanValidationInterceptor(String phase) {
- super(phase);
- }
-
- @Override
- protected Object getServiceObject(Message message) {
- return checkNotNull(super.getServiceObject(message), "SERVICE_OBJECT_NULL");
- }
-
- @Override
- protected Method getServiceMethod(Message message) {
- return (Method)checkNotNull(super.getServiceMethod(message), "SERVICE_METHOD_NULL");
- }
-
- private Object checkNotNull(Object object, String name) {
- if (object == null) {
- String message = new org.apache.cxf.common.i18n.Message(name, BUNDLE).toString();
- LOG.severe(message);
- throw new ValidationException(message);
- }
- return object;
- }
-
- @Override
- protected void handleValidation(final Message message, final Object resourceInstance,
- final Method method, final List<Object> arguments) {
- if (!arguments.isEmpty()) {
- BeanValidationProvider provider = getProvider(message);
- provider.validateParameters(resourceInstance, method, unwrapArgs(arguments).toArray());
- message.getExchange().put(BeanValidationProvider.class, provider);
- }
- }
-
- protected List<Object> unwrapArgs(List<Object> arguments) {
- return arguments;
- }
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/workqueue/AutomaticWorkQueueImpl.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/workqueue/AutomaticWorkQueueImpl.java
deleted file mode 100644
index bff113e..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/workqueue/AutomaticWorkQueueImpl.java
+++ /dev/null
@@ -1,619 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.cxf.workqueue;
-
-import java.beans.PropertyChangeEvent;
-import java.beans.PropertyChangeListener;
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
-import java.text.NumberFormat;
-import java.util.ArrayList;
-import java.util.Dictionary;
-import java.util.Hashtable;
-import java.util.List;
-import java.util.concurrent.DelayQueue;
-import java.util.concurrent.Delayed;
-import java.util.concurrent.LinkedBlockingQueue;
-import java.util.concurrent.RejectedExecutionException;
-import java.util.concurrent.ThreadFactory;
-import java.util.concurrent.ThreadPoolExecutor;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.atomic.AtomicBoolean;
-import java.util.concurrent.atomic.AtomicInteger;
-import java.util.concurrent.locks.ReentrantLock;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import org.apache.cxf.common.classloader.ClassLoaderUtils;
-import org.apache.cxf.common.classloader.ClassLoaderUtils.ClassLoaderHolder;
-import org.apache.cxf.common.injection.NoJSR250Annotations;
-import org.apache.cxf.common.logging.LogUtils;
-import org.apache.cxf.common.util.ReflectionUtil;
-
-@NoJSR250Annotations
-public class AutomaticWorkQueueImpl implements AutomaticWorkQueue {
- public static final String PROPERTY_NAME = "name";
- static final int DEFAULT_MAX_QUEUE_SIZE = 256;
- private static final Logger LOG =
- LogUtils.getL7dLogger(AutomaticWorkQueueImpl.class);
-
-
- String name = "default";
- int maxQueueSize;
- int initialThreads;
- int lowWaterMark;
- int highWaterMark;
- long dequeueTimeout;
- AtomicInteger approxThreadCount = new AtomicInteger();
-
- ThreadPoolExecutor executor;
- Method addWorkerMethod;
- Object[] addWorkerArgs;
-
- AWQThreadFactory threadFactory;
- ReentrantLock mainLock;
- final ReentrantLock addThreadLock = new ReentrantLock();
-
- DelayQueue<DelayedTaskWrapper> delayQueue;
- WatchDog watchDog;
-
- boolean shared;
- int sharedCount;
-
- private List<PropertyChangeListener> changeListenerList;
-
- public AutomaticWorkQueueImpl() {
- this(DEFAULT_MAX_QUEUE_SIZE);
- }
- public AutomaticWorkQueueImpl(String name) {
- this(DEFAULT_MAX_QUEUE_SIZE, name);
- }
- public AutomaticWorkQueueImpl(int max) {
- this(max, "default");
- }
- public AutomaticWorkQueueImpl(int max, String name) {
- this(max,
- 0,
- 25,
- 5,
- 2 * 60 * 1000L,
- name);
- }
- public AutomaticWorkQueueImpl(int mqs,
- int initialThreads,
- int highWaterMark,
- int lowWaterMark,
- long dequeueTimeout) {
- this(mqs, initialThreads, highWaterMark, lowWaterMark, dequeueTimeout, "default");
- }
- public AutomaticWorkQueueImpl(int mqs,
- int initialThreads,
- int highWaterMark,
- int lowWaterMark,
- long dequeueTimeout,
- String name) {
- this.maxQueueSize = mqs == -1 ? DEFAULT_MAX_QUEUE_SIZE : mqs;
- this.initialThreads = initialThreads;
- this.highWaterMark = -1 == highWaterMark ? Integer.MAX_VALUE : highWaterMark;
- this.lowWaterMark = -1 == lowWaterMark ? Integer.MAX_VALUE : lowWaterMark;
- this.dequeueTimeout = dequeueTimeout;
- this.name = name;
- this.changeListenerList = new ArrayList<>();
- }
-
- public void addChangeListener(PropertyChangeListener listener) {
- this.changeListenerList.add(listener);
- }
-
- public void removeChangeListener(PropertyChangeListener listener) {
- this.changeListenerList.remove(listener);
- }
-
- public void notifyChangeListeners(PropertyChangeEvent event) {
- for (PropertyChangeListener listener : changeListenerList) {
- listener.propertyChange(event);
- }
- }
-
- public void setShared(boolean shared) {
- this.shared = shared;
- }
- public boolean isShared() {
- return shared;
- }
- public void addSharedUser() {
- sharedCount++;
- }
- public void removeSharedUser() {
- sharedCount--;
- }
- public int getShareCount() {
- return sharedCount;
- }
-
- protected synchronized ThreadPoolExecutor getExecutor() {
- if (executor == null) {
- threadFactory = createThreadFactory(name);
- executor = new ThreadPoolExecutor(lowWaterMark,
- highWaterMark,
- TimeUnit.MILLISECONDS.toMillis(dequeueTimeout),
- TimeUnit.MILLISECONDS,
- new LinkedBlockingQueue<Runnable>(maxQueueSize),
- threadFactory) {
- @Override
- protected void terminated() {
- ThreadFactory f = executor.getThreadFactory();
- if (f instanceof AWQThreadFactory) {
- ((AWQThreadFactory)f).shutdown();
- }
- if (watchDog != null) {
- watchDog.shutdown();
- }
- }
- };
-
-
- if (LOG.isLoggable(Level.FINE)) {
- StringBuilder buf = new StringBuilder(128).append("Constructing automatic work queue with:\n")
- .append("max queue size: ").append(maxQueueSize).append('\n')
- .append("initialThreads: ").append(initialThreads).append('\n')
- .append("lowWaterMark: ").append(lowWaterMark).append('\n')
- .append("highWaterMark: ").append(highWaterMark).append('\n');
- LOG.fine(buf.toString());
- }
-
- if (initialThreads > highWaterMark) {
- initialThreads = highWaterMark;
- }
-
- // as we cannot prestart more core than corePoolSize initial threads, we temporarily
- // change the corePoolSize to the number of initial threads
- // this is important as otherwise these threads will be created only when
- // the queue has filled up,
- // potentially causing problems with starting up under heavy load
- if (initialThreads < Integer.MAX_VALUE && initialThreads > 0) {
- executor.setCorePoolSize(initialThreads);
- int started = executor.prestartAllCoreThreads();
- if (started < initialThreads) {
- LOG.log(Level.WARNING, "THREAD_START_FAILURE_MSG",
- new Object[] {started, initialThreads});
- }
- executor.setCorePoolSize(lowWaterMark);
- }
-
- ReentrantLock l;
- try {
- Field f = ThreadPoolExecutor.class.getDeclaredField("mainLock");
- ReflectionUtil.setAccessible(f);
- l = (ReentrantLock)f.get(executor);
- } catch (Throwable t) {
- l = new ReentrantLock();
- }
- mainLock = l;
-
-
- try {
- //java 7
- addWorkerMethod = ThreadPoolExecutor.class.getDeclaredMethod("addWorker",
- Runnable.class, Boolean.TYPE);
- addWorkerArgs = new Object[] {null, Boolean.FALSE};
- } catch (Throwable t2) {
- //nothing we cando
- }
- }
- return executor;
- }
- private AWQThreadFactory createThreadFactory(final String nm) {
- ThreadGroup group;
- try {
- //Try and find the highest level ThreadGroup that we're allowed to use.
- //That SHOULD allow the default classloader and thread locals and such
- //to be the least likely to cause issues down the road.
- group = AccessController.doPrivileged(
- new PrivilegedAction<ThreadGroup>() {
- public ThreadGroup run() {
- ThreadGroup group = Thread.currentThread().getThreadGroup();
- ThreadGroup parent = group;
- try {
- while (parent != null) {
- group = parent;
- parent = parent.getParent();
- }
- } catch (SecurityException se) {
- //ignore - if we get here, the "group" is as high as
- //the security manager will allow us to go. Use that one.
- }
- return new ThreadGroup(group, nm + "-workqueue");
- }
- }
- );
- } catch (SecurityException e) {
- group = new ThreadGroup(nm + "-workqueue");
- }
- return new AWQThreadFactory(group, nm);
- }
-
- static class DelayedTaskWrapper implements Delayed, Runnable {
- long trigger;
- Runnable work;
-
- DelayedTaskWrapper(Runnable work, long delay) {
- this.work = work;
- trigger = System.currentTimeMillis() + delay;
- }
-
- public long getDelay(TimeUnit unit) {
- long n = trigger - System.currentTimeMillis();
- return unit.convert(n, TimeUnit.MILLISECONDS);
- }
-
- public int compareTo(Delayed delayed) {
- long other = ((DelayedTaskWrapper)delayed).trigger;
- int returnValue;
- if (this.trigger < other) {
- returnValue = -1;
- } else if (this.trigger > other) {
- returnValue = 1;
- } else {
- returnValue = 0;
- }
- return returnValue;
- }
-
- public void run() {
- work.run();
- }
-
- }
-
- class WatchDog extends Thread {
- DelayQueue<DelayedTaskWrapper> delayQueue;
- AtomicBoolean shutdown = new AtomicBoolean(false);
-
- WatchDog(DelayQueue<DelayedTaskWrapper> queue) {
- delayQueue = queue;
- }
-
- public void shutdown() {
- shutdown.set(true);
- // to exit the waiting thread
- interrupt();
- }
-
- public void run() {
- DelayedTaskWrapper task;
- try {
- while (!shutdown.get()) {
- task = delayQueue.take();
- if (task != null) {
- try {
- execute(task);
- } catch (Exception ex) {
- LOG.warning("Executing the task from DelayQueue with exception: " + ex);
- }
- }
- }
- } catch (InterruptedException e) {
- if (LOG.isLoggable(Level.FINE)) {
- LOG.finer("The DelayQueue watchdog Task is stopping");
- }
- }
-
- }
-
- }
- class AWQThreadFactory implements ThreadFactory {
- final AtomicInteger threadNumber = new AtomicInteger(1);
- ThreadGroup group;
- String name;
- ClassLoader loader;
-
- AWQThreadFactory(ThreadGroup gp, String nm) {
- group = gp;
- name = nm;
- //force the loader to be the loader of CXF, not the application loader
- loader = AutomaticWorkQueueImpl.class.getClassLoader();
- }
-
- public Thread newThread(final Runnable r) {
- if (group.isDestroyed()) {
- group = new ThreadGroup(group.getParent(), name + "-workqueue");
- }
- Runnable wrapped = new Runnable() {
- public void run() {
- approxThreadCount.incrementAndGet();
- try {
- r.run();
- } finally {
- approxThreadCount.decrementAndGet();
- }
- }
- };
- final Thread t = new Thread(group,
- wrapped,
- name + "-workqueue-" + threadNumber.getAndIncrement(),
- 0);
- AccessController.doPrivileged(new PrivilegedAction<Boolean>() {
- public Boolean run() {
- t.setContextClassLoader(loader);
- return true;
- }
- });
- t.setDaemon(true);
- if (t.getPriority() != Thread.NORM_PRIORITY) {
- t.setPriority(Thread.NORM_PRIORITY);
- }
- return t;
- }
- public void setName(String s) {
- name = s;
- }
- public void shutdown() {
- if (!group.isDestroyed()) {
- try {
- group.destroy();
- group.setDaemon(true);
- } catch (Throwable t) {
- //ignore
- }
- }
- }
- }
-
- public void setName(String s) {
- name = s;
- if (threadFactory != null) {
- threadFactory.setName(s);
- }
- }
- public String getName() {
- return name;
- }
-
- public String toString() {
- return new StringBuilder(super.toString())
- .append(" [queue size: ").append(getSize())
- .append(", max size: ").append(maxQueueSize)
- .append(", threads: ").append(getPoolSize())
- .append(", active threads: ").append(getActiveCount())
- .append(", low water mark: ").append(getLowWaterMark())
- .append(", high water mark: ").append(getHighWaterMark())
- .append(']').toString();
- }
-
- public void execute(final Runnable command) {
- //Grab the context classloader of this thread. We'll make sure we use that
- //on the thread the runnable actually runs on.
-
- final ClassLoader loader = Thread.currentThread().getContextClassLoader();
- Runnable r = new Runnable() {
- public void run() {
- ClassLoaderHolder orig = ClassLoaderUtils.setThreadContextClassloader(loader);
- try {
- command.run();
- } finally {
- if (orig != null) {
- orig.reset();
- }
- }
- }
- };
- //The ThreadPoolExecutor in the JDK doesn't expand the number
- //of threads until the queue is full. However, we would
- //prefer the number of threads to expand immediately and
- //only uses the queue if we've reached the maximum number
- //of threads.
- ThreadPoolExecutor ex = getExecutor();
- ex.execute(r);
- if (addWorkerMethod != null
- && !ex.getQueue().isEmpty()
- && this.approxThreadCount.get() < highWaterMark
- && addThreadLock.tryLock()) {
- try {
- mainLock.lock();
- try {
- int ps = this.getPoolSize();
- int sz = executor.getQueue().size();
- int sz2 = this.getActiveCount();
-
- if ((sz + sz2) > ps) {
- // Needs --add-opens java.base/java.util.concurrent=ALL-UNNAMED for JDK16+
- ReflectionUtil.setAccessible(addWorkerMethod).invoke(executor, addWorkerArgs);
- }
- } catch (Exception exc) {
- //ignore
- } finally {
- mainLock.unlock();
- }
- } finally {
- addThreadLock.unlock();
- }
- }
- }
-
- // WorkQueue interface
- public void execute(Runnable work, long timeout) {
- try {
- execute(work);
- } catch (RejectedExecutionException ree) {
- try {
- if (!getExecutor().getQueue().offer(work, timeout, TimeUnit.MILLISECONDS)) {
- throw ree;
- }
- } catch (InterruptedException ie) {
- throw ree;
- }
- }
- }
-
- public synchronized void schedule(final Runnable work, final long delay) {
- if (delayQueue == null) {
- delayQueue = new DelayQueue<>();
- watchDog = new WatchDog(delayQueue);
- watchDog.setDaemon(true);
- watchDog.start();
- }
- delayQueue.put(new DelayedTaskWrapper(work, delay));
- }
-
- // AutomaticWorkQueue interface
-
- public void shutdown(boolean processRemainingWorkItems) {
- if (executor != null) {
- if (!processRemainingWorkItems) {
- executor.getQueue().clear();
- }
- executor.shutdown();
- }
- }
-
-
- /**
- * Gets the maximum size (capacity) of the backing queue.
- * @return the maximum size (capacity) of the backing queue.
- */
- public long getMaxSize() {
- return maxQueueSize;
- }
-
- /**
- * Gets the current size of the backing queue.
- * @return the current size of the backing queue.
- */
- public long getSize() {
- return executor == null ? 0 : executor.getQueue().size();
- }
-
-
- public boolean isEmpty() {
- return executor == null || executor.getQueue().isEmpty();
- }
-
- public boolean isFull() {
- return executor != null && executor.getQueue().remainingCapacity() == 0;
- }
-
- public int getHighWaterMark() {
- int hwm = executor == null ? highWaterMark : executor.getMaximumPoolSize();
- return hwm == Integer.MAX_VALUE ? -1 : hwm;
- }
-
- public int getLowWaterMark() {
- int lwm = executor == null ? lowWaterMark : executor.getCorePoolSize();
- return lwm == Integer.MAX_VALUE ? -1 : lwm;
- }
-
- public int getInitialSize() {
- return this.initialThreads;
- }
-
- public void setHighWaterMark(int hwm) {
- highWaterMark = hwm < 0 ? Integer.MAX_VALUE : hwm;
- if (executor != null) {
- notifyChangeListeners(new PropertyChangeEvent(this, "highWaterMark",
- this.executor.getMaximumPoolSize(), hwm));
- executor.setMaximumPoolSize(highWaterMark);
- }
- }
-
- public void setLowWaterMark(int lwm) {
- lowWaterMark = lwm < 0 ? 0 : lwm;
- if (executor != null) {
- notifyChangeListeners(new PropertyChangeEvent(this, "lowWaterMark",
- this.executor.getCorePoolSize(), lwm));
- executor.setCorePoolSize(lowWaterMark);
- }
- }
-
- public void setInitialSize(int initialSize) {
- notifyChangeListeners(new PropertyChangeEvent(this, "initialSize", this.initialThreads, initialSize));
- this.initialThreads = initialSize;
- }
-
- public void setQueueSize(int size) {
- notifyChangeListeners(new PropertyChangeEvent(this, "queueSize", this.maxQueueSize, size));
- this.maxQueueSize = size;
- }
-
- public void setDequeueTimeout(long l) {
- notifyChangeListeners(new PropertyChangeEvent(this, "dequeueTimeout", this.dequeueTimeout, l));
- this.dequeueTimeout = l;
- }
-
- public boolean isShutdown() {
- if (executor == null) {
- return false;
- }
- return executor.isShutdown();
- }
- public int getLargestPoolSize() {
- if (executor == null) {
- return 0;
- }
- return executor.getLargestPoolSize();
- }
- public int getPoolSize() {
- if (executor == null) {
- return 0;
- }
- return executor.getPoolSize();
- }
- public int getActiveCount() {
- if (executor == null) {
- return 0;
- }
- return executor.getActiveCount();
- }
- public void update(Dictionary<String, String> config) {
- String s = config.get("highWaterMark");
- if (s != null) {
- this.highWaterMark = Integer.parseInt(s);
- }
- s = config.get("lowWaterMark");
- if (s != null) {
- this.lowWaterMark = Integer.parseInt(s);
- }
- s = config.get("initialSize");
- if (s != null) {
- this.initialThreads = Integer.parseInt(s);
- }
- s = config.get("dequeueTimeout");
- if (s != null) {
- this.dequeueTimeout = Long.parseLong(s);
- }
- s = config.get("queueSize");
- if (s != null) {
- this.maxQueueSize = Integer.parseInt(s);
- }
- }
- public Dictionary<String, String> getProperties() {
- Dictionary<String, String> properties = new Hashtable<>();
- NumberFormat nf = NumberFormat.getIntegerInstance();
- properties.put("name", nf.format(getName()));
- properties.put("highWaterMark", nf.format(getHighWaterMark()));
- properties.put("lowWaterMark", nf.format(getLowWaterMark()));
- properties.put("initialSize", nf.format(getLowWaterMark()));
- properties.put("dequeueTimeout", nf.format(getLowWaterMark()));
- properties.put("queueSize", nf.format(getLowWaterMark()));
- return properties;
- }
-}
diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/ws/addressing/MAPAggregator.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/ws/addressing/MAPAggregator.java
deleted file mode 100644
index 206494d..0000000
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/ws/addressing/MAPAggregator.java
+++ /dev/null
@@ -1,224 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.cxf.ws.addressing;
-
-import java.util.Collection;
-
-import org.apache.cxf.message.Message;
-import org.apache.cxf.phase.AbstractPhaseInterceptor;
-import org.apache.cxf.phase.Phase;
-import org.apache.cxf.phase.PhaseInterceptor;
-
-/**
- * Logical Handler responsible for aggregating the Message Addressing
- * Properties for outgoing messages.
- */
-public class MAPAggregator extends AbstractPhaseInterceptor<Message> {
- public static final String USING_ADDRESSING = MAPAggregator.class.getName() + ".usingAddressing";
- public static final String ADDRESSING_DISABLED = MAPAggregator.class.getName() + ".addressingDisabled";
- public static final String DECOUPLED_DESTINATION = MAPAggregator.class.getName()
- + ".decoupledDestination";
- public static final String ACTION_VERIFIED = MAPAggregator.class.getName() + ".actionVerified";
- public static final String ADDRESSING_NAMESPACE = MAPAggregator.class.getName() + ".addressingNamespace";
-
- public interface MAPAggregatorLoader {
- MAPAggregator createImplementation(MAPAggregator mag);
- }
-
- protected MessageIdCache messageIdCache;
- protected boolean usingAddressingAdvisory = true;
- protected boolean addressingRequired;
- protected boolean allowDuplicates = true;
- protected WSAddressingFeature.AddressingResponses addressingResponses
- = WSAddressingFeature.AddressingResponses.ALL;
-
- /**
- * The real implementation of the MAPAggregator interceptor
- */
- private MAPAggregator impl;
-
- /**
- * Constructor.
- */
- public MAPAggregator() {
- super(MAPAggregator.class.getName(), Phase.PRE_LOGICAL);
- addBefore("org.apache.cxf.interceptor.OneWayProcessorInterceptor");
- }
-
- /**
- * Indicates if duplicate messageIDs are allowed.
- * @return true if duplicate messageIDs are allowed
- */
- public boolean allowDuplicates() {
- if (impl != null) {
- return impl.allowDuplicates();
- }
- return allowDuplicates;
- }
-
- /**
- * Allows/disallows duplicate messageIdDs.
- * @param ad whether duplicate messageIDs are allowed
- */
- public void setAllowDuplicates(boolean ad) {
- if (impl != null) {
- impl.setAllowDuplicates(ad);
- }
- allowDuplicates = ad;
- }
-
- /**
- * Whether the presence of the <wsaw:UsingAddressing> element
- * in the WSDL is purely advisory, i.e. its absence doesn't prevent
- * the encoding of WS-A headers.
- *
- * @return true if the presence of the <wsaw:UsingAddressing> element is
- * advisory
- */
- public boolean isUsingAddressingAdvisory() {
- if (impl != null) {
- return impl.isUsingAddressingAdvisory();
- }
- return usingAddressingAdvisory;
- }
-
- /**
- * Controls whether the presence of the <wsaw:UsingAddressing> element
- * in the WSDL is purely advisory, i.e. its absence doesn't prevent
- * the encoding of WS-A headers.
- *
- * @param advisory true if the presence of the <wsaw:UsingAddressing>
- * element is to be advisory
- */
- public void setUsingAddressingAdvisory(boolean advisory) {
- if (impl != null) {
- impl.setUsingAddressingAdvisory(advisory);
- }
- usingAddressingAdvisory = advisory;
- }
-
- /**
- * Whether the use of addressing is completely required for this endpoint
- *
- * @return true if addressing is required
- */
- public boolean isAddressingRequired() {
- if (impl != null) {
- return impl.addressingRequired;
- }
- return addressingRequired;
- }
- /**
- * Sets whether the use of addressing is completely required for this endpoint
- *
- */
- public void setAddressingRequired(boolean required) {
- if (impl != null) {
- impl.setAddressingRequired(required);
- }
- addressingRequired = required;
- }
-
- /**
- * Sets Addresing Response
- *
- */
- public void setAddressingResponses(WSAddressingFeature.AddressingResponses responses) {
- if (impl != null) {
- impl.setAddressingResponses(responses);
- }
- addressingResponses = responses;
- }
-
- /**
- * Returns the cache used to enforce duplicate message IDs when
- * {@link #allowDuplicates()} returns {@code false}.
- *
- * @return the cache used to enforce duplicate message IDs
- */
- public MessageIdCache getMessageIdCache() {
- if (impl != null) {
- return impl.getMessageIdCache();
- }
- return messageIdCache;
- }
-
- /**
- * Sets the cache used to enforce duplicate message IDs when
- * {@link #allowDuplicates()} returns {@code false}.
- *
- * @param messageIdCache the cache to use
- *
- * @throws NullPointerException if {@code messageIdCache} is {@code null}
- */
- public void setMessageIdCache(MessageIdCache messageIdCache) {
- if (messageIdCache == null) {
- throw new NullPointerException("messageIdCache cannot be null.");
- }
- if (impl != null) {
- impl.setMessageIdCache(messageIdCache);
- }
- this.messageIdCache = messageIdCache;
- }
-
- /**
- * Sets Addressing Response
- *
- */
- public WSAddressingFeature.AddressingResponses getAddressingResponses() {
- if (impl != null) {
- return impl.getAddressingResponses();
- }
- return addressingResponses;
- }
-
- /**
- * Invoked for normal processing of inbound and outbound messages.
- *
- * @param message the current message
- */
- public void handleMessage(Message message) {
- if (impl == null) {
- //load impl
- MAPAggregatorLoader loader = message.getExchange().getBus()
- .getExtension(MAPAggregatorLoader.class);
- impl = loader.createImplementation(this);
- }
- impl.handleMessage(message);
- }
-
- @Override
- public void handleFault(Message message) {
- if (impl != null) {
- impl.handleFault(message);
- }
- }
-
-
- @Override
- public Collection<PhaseInterceptor<? extends Message>> getAdditionalInterceptors() {
- if (impl != null) {
- return impl.getAdditionalInterceptors();
- }
- return super.getAdditionalInterceptors();
- }
-
-
-}