diff --git a/.hgtags b/.hgtags index b2848339b59530a47de2f1ed3a497ae02850c5e8..1e461f74587dabdb8a16ae61d00773200e454279 100644 --- a/.hgtags +++ b/.hgtags @@ -700,6 +700,8 @@ c0091a673d766ce2e76a945bab6de325fe78dd88 jdk8u131-b10 3ab471c4760a808e39406303ff33a25a542b9c75 jdk8u131-b11 d50ccb38def5968145fd3f6e0579416bb027e85c jdk8u131-b31 e54624a8ebe3639d3b2360adb9ae0fa32f1bef57 jdk8u131-b32 +15006e8dc79bd0005d264bff0b1677a109cf5a02 jdk8u131-b33 +e6e35f065443533c81db69022a272927b0b20f69 jdk8u131-b34 a160009bbe1417d85f1c0eec890fdb17391b3637 jdk8u141-b00 e95a13de2d36050302a1af422967f5260fc8eabd jdk8u141-b01 936085d9aff0554a3bdab2fcbbec1d1864e656a2 jdk8u141-b02 diff --git a/make/lib/CoreLibraries.gmk b/make/lib/CoreLibraries.gmk index 1aaf4fd8c7084c3f03ac13b47ec0063000edb7d0..5174b721e47130c4b3b0a59f1cffa4948d019ae9 100644 --- a/make/lib/CoreLibraries.gmk +++ b/make/lib/CoreLibraries.gmk @@ -23,6 +23,9 @@ # questions. # +# Include custom extensions if available. +-include $(CUSTOM_MAKE_DIR)/lib/CoreLibraries.gmk + WIN_VERIFY_LIB := $(JDK_OUTPUTDIR)/objs/libverify/verify.lib ########################################################################################## @@ -114,7 +117,8 @@ BUILD_LIBRARIES += $(BUILD_LIBVERIFY) ########################################################################################## -LIBJAVA_SRC_DIRS := $(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/native/java/lang \ +# Allow a custom makefile to add extra src dirs +LIBJAVA_SRC_DIRS += $(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/native/java/lang \ $(JDK_TOPDIR)/src/share/native/java/lang \ $(JDK_TOPDIR)/src/share/native/java/lang/reflect \ $(JDK_TOPDIR)/src/share/native/java/io \ @@ -140,6 +144,9 @@ ifeq ($(OPENJDK_TARGET_OS), windows) $(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/native/sun/io endif +# Make it possible to override this variable +LIBJAVA_MAPFILE ?= $(JDK_TOPDIR)/make/mapfiles/libjava/mapfile-vers + LIBJAVA_CFLAGS := $(foreach dir, $(LIBJAVA_SRC_DIRS), -I$(dir)) \ -I$(JDK_TOPDIR)/src/share/native/java/lang/fdlibm/include \ -DARCHPROPNAME='"$(OPENJDK_TARGET_CPU_OSARCH)"' @@ -193,7 +200,7 @@ $(eval $(call SetupNativeCompilation,BUILD_LIBJAVA, \ OPTIMIZATION := HIGH, \ CFLAGS := $(CFLAGS_JDKLIB) \ $(LIBJAVA_CFLAGS), \ - MAPFILE := $(JDK_TOPDIR)/make/mapfiles/libjava/mapfile-vers, \ + MAPFILE := $(LIBJAVA_MAPFILE), \ LDFLAGS := $(LDFLAGS_JDKLIB) \ $(call SET_SHARED_LIBRARY_ORIGIN), \ LDFLAGS_SUFFIX_posix := -ljvm -lverify, \ diff --git a/src/aix/native/java/net/aix_close.c b/src/aix/native/java/net/aix_close.c index 303ddf98a2407b762299b96b35b1462bb5bff9b3..8c070e4b76bd8b51015413abdf6d98acb1c28eef 100644 --- a/src/aix/native/java/net/aix_close.c +++ b/src/aix/native/java/net/aix_close.c @@ -1,5 +1,6 @@ /* - * Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2001, 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2016, SAP SE and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -328,6 +329,10 @@ int NET_Read(int s, void* buf, size_t len) { BLOCKING_IO_RETURN_INT( s, recv(s, buf, len, 0) ); } +int NET_NonBlockingRead(int s, void* buf, size_t len) { + BLOCKING_IO_RETURN_INT(s, recv(s, buf, len, MSG_NONBLOCK)); +} + int NET_ReadV(int s, const struct iovec * vector, int count) { BLOCKING_IO_RETURN_INT( s, readv(s, vector, count) ); } @@ -429,8 +434,8 @@ int NET_Select(int s, fd_set *readfds, fd_set *writefds, * Auto restarts with adjusted timeout if interrupted by * signal other than our wakeup signal. */ -int NET_Timeout(int s, long timeout) { - long prevtime = 0, newtime; +int NET_Timeout0(int s, long timeout, long currentTime) { + long prevtime = currentTime, newtime; struct timeval t; fdEntry_t *fdEntry = getFdEntry(s); @@ -442,14 +447,6 @@ int NET_Timeout(int s, long timeout) { return -1; } - /* - * Pick up current time as may need to adjust timeout - */ - if (timeout > 0) { - gettimeofday(&t, NULL); - prevtime = t.tv_sec * 1000 + t.tv_usec / 1000; - } - for(;;) { struct pollfd pfd; int rv; diff --git a/src/macosx/native/sun/awt/CPrinterJob.m b/src/macosx/native/sun/awt/CPrinterJob.m index fdd56fd41998e64773fe0c044b21fe9ea5019a29..d9154fa4f9263278dad7ff619acfe6a3bb102f77 100644 --- a/src/macosx/native/sun/awt/CPrinterJob.m +++ b/src/macosx/native/sun/awt/CPrinterJob.m @@ -365,7 +365,7 @@ static void javaPrinterJobToNSPrintInfo(JNIEnv* env, jobject srcPrinterJob, jobj static JNF_MEMBER_CACHE(jm_getMaxPage, sjc_CPrinterJob, "getMaxPageAttrib", "()I"); static JNF_MEMBER_CACHE(jm_getSelectAttrib, sjc_CPrinterJob, "getSelectAttrib", "()I"); static JNF_MEMBER_CACHE(jm_getNumberOfPages, jc_Pageable, "getNumberOfPages", "()I"); - static JNF_MEMBER_CACHE(jm_getPageFormat, sjc_CPrinterJob, "getPageFormat", "(I)Ljava/awt/print/PageFormat;"); + static JNF_MEMBER_CACHE(jm_getPageFormat, sjc_CPrinterJob, "getPageFormatFromAttributes", "()Ljava/awt/print/PageFormat;"); NSMutableDictionary* printingDictionary = [dst dictionary]; @@ -401,7 +401,7 @@ static void javaPrinterJobToNSPrintInfo(JNIEnv* env, jobject srcPrinterJob, jobj [printingDictionary setObject:[NSNumber numberWithInteger:fromPage] forKey:NSPrintFirstPage]; [printingDictionary setObject:[NSNumber numberWithInteger:toPage] forKey:NSPrintLastPage]; - jobject page = JNFCallObjectMethod(env, srcPrinterJob, jm_getPageFormat, (jint)0); + jobject page = JNFCallObjectMethod(env, srcPrinterJob, jm_getPageFormat); if (page != NULL) { javaPageFormatToNSPrintInfo(env, NULL, page, dst); } diff --git a/src/share/classes/java/awt/Container.java b/src/share/classes/java/awt/Container.java index 47e580bc1ae5f816e1342592cb21fa5a82367109..b9e4f9143b54cb0b818e209f61ae4723bbeb3844 100644 --- a/src/share/classes/java/awt/Container.java +++ b/src/share/classes/java/awt/Container.java @@ -1089,17 +1089,18 @@ public class Container extends Component { } checkAddToSelf(comp); checkNotAWindow(comp); - if (thisGC != null) { - comp.checkGD(thisGC.getDevice().getIDstring()); - } - /* Reparent the component and tidy up the tree's state. */ if (comp.parent != null) { comp.parent.remove(comp); - if (index > component.size()) { - throw new IllegalArgumentException("illegal component position"); - } + if (index > component.size()) { + throw new IllegalArgumentException("illegal component position"); + } } + if (thisGC != null) { + comp.checkGD(thisGC.getDevice().getIDstring()); + } + + //index == -1 means add to the end. if (index == -1) { diff --git a/src/share/classes/sun/print/RasterPrinterJob.java b/src/share/classes/sun/print/RasterPrinterJob.java index eb2b5cf6511d7a4a69a19ad3c0e6a3aa5ece8e50..1bb3dad5f1f5670bcaa088d87a0244fc9187d8dc 100644 --- a/src/share/classes/sun/print/RasterPrinterJob.java +++ b/src/share/classes/sun/print/RasterPrinterJob.java @@ -818,6 +818,14 @@ public abstract class RasterPrinterJob extends PrinterJob { } } + protected PageFormat getPageFormatFromAttributes() { + if (attributes == null || attributes.isEmpty()) { + return null; + } + return attributeToPageFormat(getPrintService(), this.attributes); + } + + /** * Presents the user a dialog for changing properties of the * print job interactively. diff --git a/src/solaris/native/java/net/SocketInputStream.c b/src/solaris/native/java/net/SocketInputStream.c index 864326295ef6362f4546acb6fde3dbc9041685ea..8cff43156c99912ba39199685ad5daec59e8dcbd 100644 --- a/src/solaris/native/java/net/SocketInputStream.c +++ b/src/solaris/native/java/net/SocketInputStream.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -52,6 +52,42 @@ Java_java_net_SocketInputStream_init(JNIEnv *env, jclass cls) { IO_fd_fdID = NET_GetFileDescriptorID(env); } +#if !defined(__solaris__) +static int NET_ReadWithTimeout(JNIEnv *env, int fd, char *bufP, int len, long timeout) { + int result = 0; + long prevtime = NET_GetCurrentTime(), newtime; + while (timeout > 0) { + result = NET_TimeoutWithCurrentTime(fd, timeout, prevtime); + if (result <= 0) { + if (result == 0) { + JNU_ThrowByName(env, "java/net/SocketTimeoutException", "Read timed out"); + } else if (result == -1) { + if (errno == EBADF) { + JNU_ThrowByName(env, "java/net/SocketException", "Socket closed"); + } else if (errno == ENOMEM) { + JNU_ThrowOutOfMemoryError(env, "NET_Timeout native heap allocation failed"); + } else { + JNU_ThrowByNameWithMessageAndLastError + (env, "java/net/SocketException", "select/poll failed"); + } + } + return -1; + } + result = NET_NonBlockingRead(fd, bufP, len); + if (result == -1 && ((errno == EAGAIN) || (errno == EWOULDBLOCK))) { + newtime = NET_GetCurrentTime(); + timeout -= newtime - prevtime; + if (timeout > 0) { + prevtime = newtime; + } + } else { + break; + } + } + return result; +} +#endif + /* * Class: java_net_SocketInputStream * Method: socketRead0 @@ -99,6 +135,7 @@ Java_java_net_SocketInputStream_socketRead0(JNIEnv *env, jobject this, bufP = BUF; } +#if defined(__solaris__) if (timeout) { nread = NET_Timeout(fd, timeout); if (nread <= 0) { @@ -126,7 +163,19 @@ Java_java_net_SocketInputStream_socketRead0(JNIEnv *env, jobject this, } nread = NET_Read(fd, bufP, len); - +#else + if (timeout) { + nread = NET_ReadWithTimeout(env, fd, bufP, len, timeout); + if ((*env)->ExceptionCheck(env)) { + if (bufP != BUF) { + free(bufP); + } + return nread; + } + } else { + nread = NET_Read(fd, bufP, len); + } +#endif if (nread <= 0) { if (nread < 0) { diff --git a/src/solaris/native/java/net/bsd_close.c b/src/solaris/native/java/net/bsd_close.c index 5ec3bea434246a6a4368ed5c36144ca7d9bba7ab..af57cef306cdca5fd50c0546f36a4400658e4f3c 100644 --- a/src/solaris/native/java/net/bsd_close.c +++ b/src/solaris/native/java/net/bsd_close.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2001, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -292,6 +292,10 @@ int NET_Read(int s, void* buf, size_t len) { BLOCKING_IO_RETURN_INT( s, recv(s, buf, len, 0) ); } +int NET_NonBlockingRead(int s, void* buf, size_t len) { + BLOCKING_IO_RETURN_INT( s, recv(s, buf, len, MSG_DONTWAIT)); +} + int NET_ReadV(int s, const struct iovec * vector, int count) { BLOCKING_IO_RETURN_INT( s, readv(s, vector, count) ); } @@ -344,8 +348,8 @@ int NET_Select(int s, fd_set *readfds, fd_set *writefds, * Auto restarts with adjusted timeout if interrupted by * signal other than our wakeup signal. */ -int NET_Timeout(int s, long timeout) { - long prevtime = 0, newtime; +int NET_Timeout0(int s, long timeout, long currentTime) { + long prevtime = currentTime, newtime; struct timeval t, *tp = &t; fd_set fds; fd_set* fdsp = NULL; @@ -366,9 +370,6 @@ int NET_Timeout(int s, long timeout) { */ if (timeout > 0) { /* Timed */ - struct timeval now; - gettimeofday(&now, NULL); - prevtime = now.tv_sec * 1000 + now.tv_usec / 1000; t.tv_sec = timeout / 1000; t.tv_usec = (timeout % 1000) * 1000; } else if (timeout < 0) { diff --git a/src/solaris/native/java/net/linux_close.c b/src/solaris/native/java/net/linux_close.c index 2d3dfe2fb512851e3e6060f73105abe2f5d2dc39..98e1ce0987f43d3e5739711cce7805006930db4f 100644 --- a/src/solaris/native/java/net/linux_close.c +++ b/src/solaris/native/java/net/linux_close.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2001, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -273,6 +273,10 @@ int NET_Read(int s, void* buf, size_t len) { BLOCKING_IO_RETURN_INT( s, recv(s, buf, len, 0) ); } +int NET_NonBlockingRead(int s, void* buf, size_t len) { + BLOCKING_IO_RETURN_INT( s, recv(s, buf, len, MSG_DONTWAIT) ); +} + int NET_ReadV(int s, const struct iovec * vector, int count) { BLOCKING_IO_RETURN_INT( s, readv(s, vector, count) ); } @@ -324,8 +328,8 @@ int NET_Select(int s, fd_set *readfds, fd_set *writefds, * Auto restarts with adjusted timeout if interrupted by * signal other than our wakeup signal. */ -int NET_Timeout(int s, long timeout) { - long prevtime = 0, newtime; +int NET_Timeout0(int s, long timeout, long currentTime) { + long prevtime = currentTime, newtime; struct timeval t; fdEntry_t *fdEntry = getFdEntry(s); @@ -337,14 +341,6 @@ int NET_Timeout(int s, long timeout) { return -1; } - /* - * Pick up current time as may need to adjust timeout - */ - if (timeout > 0) { - gettimeofday(&t, NULL); - prevtime = t.tv_sec * 1000 + t.tv_usec / 1000; - } - for(;;) { struct pollfd pfd; int rv; diff --git a/src/solaris/native/java/net/net_util_md.c b/src/solaris/native/java/net/net_util_md.c index a284fed280f682b55befbc91325e55b2d76ee75a..14aa8ad2d3ac51aa3f9a72373d1616953e2d2438 100644 --- a/src/solaris/native/java/net/net_util_md.c +++ b/src/solaris/native/java/net/net_util_md.c @@ -33,6 +33,7 @@ #include #include #include +#include #ifndef _ALLBSD_SOURCE #include @@ -1661,3 +1662,20 @@ NET_Wait(JNIEnv *env, jint fd, jint flags, jint timeout) return timeout; } + +#if !defined(__solaris__) +long NET_GetCurrentTime() { + struct timeval time; + gettimeofday(&time, NULL); + return (time.tv_sec * 1000 + time.tv_usec / 1000); +} + +int NET_TimeoutWithCurrentTime(int s, long timeout, long currentTime) { + return NET_Timeout0(s, timeout, currentTime); +} + +int NET_Timeout(int s, long timeout) { + long currentTime = (timeout > 0) ? NET_GetCurrentTime() : 0; + return NET_Timeout0(s, timeout, currentTime); +} +#endif diff --git a/src/solaris/native/java/net/net_util_md.h b/src/solaris/native/java/net/net_util_md.h index 58be69078896c1fe2bfd9afb52fada8b031aa4bc..a48446de9ccbf176f5931482063251e9f1b4aecc 100644 --- a/src/solaris/native/java/net/net_util_md.h +++ b/src/solaris/native/java/net/net_util_md.h @@ -47,9 +47,13 @@ close subroutine does not return until the select call returns. ... */ -#if defined(__linux__) || defined(MACOSX) || defined (_AIX) +#if !defined(__solaris__) extern int NET_Timeout(int s, long timeout); +extern int NET_Timeout0(int s, long timeout, long currentTime); extern int NET_Read(int s, void* buf, size_t len); +extern int NET_NonBlockingRead(int s, void* buf, size_t len); +extern int NET_TimeoutWithCurrentTime(int s, long timeout, long currentTime); +extern long NET_GetCurrentTime(); extern int NET_RecvFrom(int s, void *buf, int len, unsigned int flags, struct sockaddr *from, int *fromlen); extern int NET_ReadV(int s, const struct iovec * vector, int count); diff --git a/test/java/awt/Container/MoveToOtherScreenTest/MoveToOtherScreenTest.java b/test/java/awt/Container/MoveToOtherScreenTest/MoveToOtherScreenTest.java new file mode 100644 index 0000000000000000000000000000000000000000..d5cfa4a8446f85bf229a626d5f681215b135ed27 --- /dev/null +++ b/test/java/awt/Container/MoveToOtherScreenTest/MoveToOtherScreenTest.java @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +import javax.swing.JFrame; +import javax.swing.SwingUtilities; +import java.awt.Canvas; +import java.awt.Color; +import java.awt.Dimension; +import java.awt.Frame; +import java.awt.GraphicsConfiguration; +import java.awt.GraphicsDevice; +import java.awt.GraphicsEnvironment; +import java.lang.reflect.InvocationTargetException; + + + +/* @test + @bug 8160696 + @summary IllegalArgumentException: adding a component to a container on a different GraphicsDevice + @author Mikhail Cherkasov + @run main MoveToOtherScreenTest +*/ +public class MoveToOtherScreenTest { + + private static volatile boolean twoDisplays = true; + private static final Canvas canvas = new Canvas(); + private static final Frame[] frms = new JFrame[2]; + + public static void main(String[] args) throws InterruptedException, InvocationTargetException { + SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + GraphicsEnvironment ge = GraphicsEnvironment. + getLocalGraphicsEnvironment(); + GraphicsDevice[] gds = ge.getScreenDevices(); + if (gds.length < 2) { + System.out.println("Test requires at least 2 displays"); + twoDisplays = false; + return; + } + for (int i = 0; i < 2; i++) { + GraphicsConfiguration conf = gds[i].getConfigurations()[0]; + JFrame frm = new JFrame("Frame " + i); + frm.setLocation(conf.getBounds().x, 0); // On first screen + frm.setSize(new Dimension(400, 400)); + frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + frm.setVisible(true); + frms[i] = frm; + } + canvas.setBackground(Color.red); + frms[0].add(canvas); + } + }); + if(!twoDisplays){ + return; + } + Thread.sleep(200); + SwingUtilities.invokeAndWait(new Runnable() { + @Override + public void run() { + frms[1].add(canvas); + } + }); + for (Frame frm : frms) { + frm.dispose(); + } + } +} diff --git a/test/java/awt/print/PageFormat/WrongPaperPrintingTest.java b/test/java/awt/print/PageFormat/WrongPaperPrintingTest.java index 79f07489e3f9eec5985173f8816e81e076ff2803..2299015b25dfac6a3c93f72eba86d7eb9070e1cb 100644 --- a/test/java/awt/print/PageFormat/WrongPaperPrintingTest.java +++ b/test/java/awt/print/PageFormat/WrongPaperPrintingTest.java @@ -24,6 +24,7 @@ /* @test @bug 8167102 @summary PrintRequestAttributeSet breaks page size set using PageFormat + @ignore Exclude the test until 8167102 is resolved by a new reassessed fix @run main/manual WrongPaperPrintingTest */ diff --git a/test/javax/xml/ws/8172297/Main.java b/test/javax/xml/ws/8172297/Main.java new file mode 100644 index 0000000000000000000000000000000000000000..14b376c8c986ccf6d91752e4fafe16966d22420b --- /dev/null +++ b/test/javax/xml/ws/8172297/Main.java @@ -0,0 +1,157 @@ +/* + * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 8172297 + * @summary Test that carriage-return and new-line characters + * are preserved in webservice parameters + * @compile ws/HelloWorld.java ws/HelloWorldImpl.java Main.java + * @run testng/othervm Main + */ + +import java.io.IOException; +import java.net.ServerSocket; +import java.net.URL; +import java.util.concurrent.CountDownLatch; + +import javax.xml.namespace.QName; +import javax.xml.ws.Endpoint; +import javax.xml.ws.Service; + +import org.testng.Assert; +import org.testng.annotations.Test; + +import ws.HelloWorld; +import ws.HelloWorldImpl; + +public class Main { + + @Test + public void runTest() throws Exception { + // + CountDownLatch serverInitSignal = new CountDownLatch(1); + CountDownLatch testDoneSignal = new CountDownLatch(1); + + WebserviceRunner serverThread = new WebserviceRunner(serverInitSignal, testDoneSignal); + (new Thread(serverThread)).start(); + + serverInitSignal.await(); + + boolean paramModified = runClientCode(serverThread.getPort()); + + testDoneSignal.countDown(); + + Assert.assertFalse(paramModified, "WS parameter was modified during round trip."); + } + + /* + * Connects to launched web service endpoint, sends message with CR/NL symbols and + * checks if it was modified during the round trip client/server communication. + */ + private boolean runClientCode(int port) throws Exception { + System.out.println("Launching WS client connection on " + port + " port"); + URL url = new URL("http://localhost:" + port + "/ws/hello?wsdl"); + QName qname = new QName("http://ws/", "HelloWorldImplService"); + Service service = Service.create(url, qname); + + HelloWorld hello = (HelloWorld) service.getPort(HelloWorld.class); + + logStringContent("Client input parameter", WS_PARAM_VALUE); + + String response = hello.getHelloWorldAsString(WS_PARAM_VALUE); + logStringContent("Client response parameter", response); + + return !WS_PARAM_VALUE.equals(response); + } + + /* + * Outputs the parameter value with newline and carriage-return symbols + * replaced with #CR and #NL text abbreviations. + */ + private static void logStringContent(String description, String parameter) { + String readableContent = parameter.replaceAll("\r", "#CR") + .replaceAll("\n", "#NL"); + System.out.println(description + ": '" + readableContent + "'"); + } + + /* Web service parameter value with newline and carriage-return symbols */ + private final static String WS_PARAM_VALUE = "\r\r\n\r\r CarriageReturn and " + +"NewLine \r\n\n Test \r\r\r\r"; + + /* + * Web service server thread that publishes WS on vacant port and waits + * for client to finalize testing + */ + class WebserviceRunner implements Runnable { + // Latch used to signalize when WS endpoint is initialized + private final CountDownLatch initSignal; + // Latch used to signalize when client completed testing + private final CountDownLatch doneSignal; + // Port where WS endpoint is published + private volatile int port = 0; + + // Constructor + WebserviceRunner(CountDownLatch initSignal, CountDownLatch doneSignal) { + this.initSignal = initSignal; + this.doneSignal = doneSignal; + } + + // Returns port of the published endpoint + public int getPort() { + return port; + } + + /* + * Publish web service on vacant port and waits for the client to + * complete testing. + */ + public void run() { + try { + // Find vacant port number + ServerSocket ss = new ServerSocket(0); + port = ss.getLocalPort(); + ss.close(); + + // Publish WebService + System.out.println("Publishing WebService on " + port + " port"); + Endpoint ep = Endpoint.publish("http://localhost:" + port + "/ws/hello", new HelloWorldImpl()); + + // Notify main thread that WS endpoint is published + initSignal.countDown(); + + // Wait for main thread to complete testing + System.out.println("Waiting for done signal from test client."); + doneSignal.await(); + + // Terminate WS endpoint + System.out.println("Got done signal from the client. Stopping WS endpoint."); + ep.stop(); + } catch (IOException ioe) { + System.out.println("Failed to get vacant port number:" + ioe); + } catch (InterruptedException ie) { + System.out.println("Failed to wait for test completion:" + ie); + } + } + } +} diff --git a/test/javax/xml/ws/8172297/ws/HelloWorld.java b/test/javax/xml/ws/8172297/ws/HelloWorld.java new file mode 100644 index 0000000000000000000000000000000000000000..cffce45d851e388a438a5612b509d14e97c0149a --- /dev/null +++ b/test/javax/xml/ws/8172297/ws/HelloWorld.java @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package ws; + +import javax.jws.WebMethod; +import javax.jws.WebService; +import javax.jws.soap.SOAPBinding; +import javax.jws.soap.SOAPBinding.Style; +import javax.jws.soap.SOAPBinding.Use; + +//Web service endpoint interface +@WebService +@SOAPBinding(style = Style.DOCUMENT, use = Use.LITERAL) +public interface HelloWorld { + + @WebMethod + String getHelloWorldAsString(String name); +} diff --git a/test/javax/xml/ws/8172297/ws/HelloWorldImpl.java b/test/javax/xml/ws/8172297/ws/HelloWorldImpl.java new file mode 100644 index 0000000000000000000000000000000000000000..fc7f71d588ba94d752455f7dccb4d936db725f9f --- /dev/null +++ b/test/javax/xml/ws/8172297/ws/HelloWorldImpl.java @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package ws; + +import javax.jws.WebService; + +// Simple web service implementation that echoes its parameter +@WebService(endpointInterface = "ws.HelloWorld") +public class HelloWorldImpl implements HelloWorld { + + @Override + public String getHelloWorldAsString(String name) { + System.out.println("Server-side parameter value: '" + + name.replaceAll("\r", "#CR") + .replaceAll("\n", "#NL") + "'"); + return name; + } +}