Embedded Jetty + 2 Jersey Servlets: unable to load both - jersey

PLEASE HELP!
I'm having an issue regarding configuration of Embedded Jetty to run 2 Jersey Servlets in 2 classes, package entry. It runs from the Eclipse, but once when exported as runnable jar file, I'm getting ERROR: 500, for the one run secondly.
It is Maven project and the tool I'm using for creating runnable jar is <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-shade-plugin</artifactId>,
while the Server point is configured as below:
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.NO_SESSIONS);
context.setContextPath("/");
HttpConfiguration https = new HttpConfiguration();
https.addCustomizer(new SecureRequestCustomizer());
ServerConnector connector = new ServerConnector(jettyServer);
connector.setPort(10001);
jettyServer.setConnectors(new Connector[] { connector });
jettyServer.setHandler(context);
ServletHolder jerseyServletEntry = context.addServlet(org.glassfish.jersey.servlet.ServletContainer.class,
"/entry/*");
jerseyServletEntry.setInitOrder(0);
jerseyServletEntry.setInitParameter("jersey.config.server.provider.classnames",
EntryPoint.class.getCanonicalName());
EntryPoint.logger.info("Server is starting up... ");
ServletHolder jerseyServletNoEntry = context.addServlet(org.glassfish.jersey.servlet.ServletContainer.class,
"/noentry/*");
jerseyServletNoEntry.setInitOrder(1);
jerseyServletNoEntry.setInitParameter("jersey.config.server.provider.classnames",
NoEntryPoint.class.getCanonicalName());
NoEntryPoint.logger.info("Server is starting up... ");
The Postman error I've got :
<head>
<meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1" />
<title>Error 500 </title>
</head>
<body>
<h2>HTTP ERROR: 500</h2>
<p>Problem accessing /entry/input//7858/768434. Reason:
<pre> Request failed.</pre>
</p>
<hr /><i><small>Powered by Jetty://</small></i>
</body>
Reminder: It works fine in Eclipse, and no errors listed when running in console with java -jar command.

I have solved the issue by changing configuration in my ServerPoint as below:
Instead of:
ServletHolder jerseyServletEntry = context.addServlet(org.glassfish.jersey.servlet.ServletContainer.class,
"/entry/*");
jerseyServletEntry.setInitOrder(0);
jerseyServletEntry.setInitParameter("jersey.config.server.provider.classnames",
EntryPoint.class.getCanonicalName());
EntryPoint.logger.info("Server is starting up... ");
ServletHolder jerseyServletNoEntry = context.addServlet(org.glassfish.jersey.servlet.ServletContainer.class,
"/noentry/*");
jerseyServletNoEntry.setInitOrder(1);
jerseyServletNoEntry.setInitParameter("jersey.config.server.provider.classnames",
NoEntryPoint.class.getCanonicalName());
NoEntryPoint.logger.info("Server is starting up... ");
I wrote:
ServletHolder jerseyServletEntry = context.addServlet(org.glassfish.jersey.servlet.ServletContainer.class,
"/api/*");
jerseyServletEntry.setInitOrder(0);
jerseyServletEntry.setInitParameter("jersey.config.server.provider.classnames",
"entry.EntryPoint, entry.NoEntryPoint"); //upload both Jersey servlets
ServerPoint.logger.info("Server is starting up... ");
But now, I'm getting JCE cannot authenticate the provide BC. Tried this solution, but it didn't worked: bouncycastle error "JCE cannot authenticate the provider BC" with "jar-with-dependencies"
Works fine when in Eclipse, but not when exported. Any idea?

Related

CF2021 Getting Started with WebSockets (cfwebsocket)

I am just getting started with cfwebsockets and I am having a bit of trouble. What I found from online, is that since this is public-facing application, it is best to use a websocket proxy.
CF2021, Version: 2021.0.03.329779
Ubuntu 20.04LTS
Steps so far:
I added the websocket package to my server and enabled web-sockets. Restarted Server.
Added this to my application.cfc:
<cfset this.wschannels = [ {name="chat"} ] />
(the application has a this.name= set from a variable as well
3. created a simple page that has this:
<cfwebsocket
name="wSocketObj"
onMessage="wsOnMessage"
onOpen="wsOnOpen"
onClose="wsOnClose"
onError="wsOnError"
subscribeTo="chat"
secure="true"/>
<script type="text/javascript">
wsOnMessage = function(aEvent,aToken) {
console.log('wsOnMessage',aevent);
var message = ColdFusion.JSON.encode(atoken);
var txt=document.getElementById("myDiv");
txt.innerHTML +=message +"<br>";
}
wsOnOpen = function() {
alert("wsOnOpen Connection is open");
}
wsOnClose = function() {
alert("wsOnClose Connection Closed");
}
wsOnError = function() {
alert("wsOnError!");
console.log(arguments);
}
sendMessage = function() {
var text = window.prompt("Enter some text","");
if (text) {
wSocketObj.publish("chat", text);
}
}
</script>
<cfdiv id="myDiv"></cfdiv>
<div id="myChatArea"></div>
<input type="text" id="myMessage" /><input id="myButton" type="button" value="Send Message" onClick="sendMessage()" />
got this in the Chrome Console:
WebSocket connection to 'wss://myhost.mydomain.com:8555/cfusion/cfusion' failed:
CFWebSocketWrapper.open # cfwebsocketCore.js:21
init # cfwebsocketChannel.js:49
_cf_websockets_init_6322652258206397 # client.cfm:35
fire # cfajax.js:1214
$E.windowLoadHandler # cfajax.js:1321
cfwebsocketCore.js:54 Uncaught TypeError: Cannot set properties of undefined (setting 'readyState')
at WebSocket.wsConnection.onerror (cfwebsocketCore.js:54:29)
thinking it was a firewall issue, I disabled it in Ubuntu
It was at this point that it seemed to be that I needed to configure a proxy.
I ran /opt/ColdFusion/cfusion/bin/wsproxyconfig.sh from the command line and verified that both the line in apache2.conf was there and the folder "/opt/ColdFusion/config/wsproxy/1/mod_wsproxy.conf" was created. Restarted apache2 and CF2021
Same Result
Realized I need to change the websocket config in CF Admin,
When I select the Use Proxy in CF Admin, the Save Changes button disappears and I cannot save it.
Obviously I am missing something very fundamental here. Any help that anyone can provide would be appreciated.
thanks in advance

Break in fabric8 kubernetes client mock server

We were using fabric8 kubernetes client 5.3.x for watcher and it worked fine. Recently when we moved to 5.11.2 there were many changes observed and eventually the JUnit Tests started failing.
We use io.fabric8.kubernetes.client.server.mock.KubernetesServer
Earlier we were using ContainerStatus .withNewReady which now seem to be removed.
And then we added the following annotation
#Rule
public KubernetesServer myMockServer = new KubernetesServer(false, true);
After this, we are getting the following logs stating unsupported label requirement while the application code is sending this label.
[2022-02-03T07:30:22.733Z] 07:30:17.812 [pool-1-thread-1] DEBUG io.fabric8.kubernetes.client.dsl.internal.AbstractWatchManager - Watching http://localhost:40033/api/v1/namespaces/test/pods?labelSelector=app.kubernetes.io%2Fname%20in%20%28apps%29&timeoutSeconds=0&allowWatchBookmarks=true&watch=true...
[2022-02-03T07:30:22.733Z] 07:30:17.814 [MockWebServer /127.0.0.1:49882] WARN io.fabric8.kubernetes.client.server.mock.KubernetesAttributesExtractor - Ignoring unsupported label requirement: app.kubernetes.io/name in (apps)
[2022-02-03T07:30:22.733Z] 07:30:17.815 [MockWebServer /127.0.0.1:49882] DEBUG io.fabric8.kubernetes.client.server.mock.KubernetesAttributesExtractor - fromPath /api/v1/namespaces/test/pods?labelSelector=app.kubernetes.io%2Fname%20in%20%28apps%29&timeoutSeconds=0&allowWatchBookmarks=true&watch=true : {attributes: {namespace={key:namespace, value:test}, version={key:version, value:v1}, plural={key:plural, value:pods}}}
[2022-02-03T07:30:22.733Z] 07:30:17.815 [OkHttp http://localhost:40033/...] DEBUG io.fabric8.kubernetes.client.dsl.internal.WatcherWebSocketListener - WebSocket successfully opened
[2022-02-03T07:30:22.733Z] 07:30:20.818 [OkHttp http://localhost:40033/...] DEBUG io.fabric8.kubernetes.client.dsl.internal.AbstractWatchManager - Scheduling reconnect task
Is there something more should be done? Tests are in ERROR state and not Failed.
Sample JUnit program
public void testAddNewPodWatchEvent()
{
//given
doReturn(myClientMock).when(myTestObj).getClient();
doReturn(myWatcherSpy).when(myTestObj).createEventHandler();
String PATH =
"/api/v1/namespaces/test/pods?labelSelector=app.kubernetes.io%2Fname%20in%20%28apps%29&timeoutSeconds=0&watch=true";
Map<String, String> mockLabelMap = new HashMap<>();
mockLabelMap.put("foo", "testlabel");
mockLabelMap.put("app.kubernetes.io/name", "apps");
Pod accPod = createAppsPod(mockLabelMap, true);
myMockServer.expect()
.get()
.withPath(PATH)
.andUpgradeToWebSocket()
.open()
.waitFor(100)
.andEmit(new WatchEvent(accPod, "ADDED"))
.done()
.once();
//when
myTestObj.activate(mockProps);
sleepForWatchToBeInvoked();
//then
verify(myWatcherSpy, atLeastOnce()).eventReceived(Action.ADDED, accPod);
}

jHipster Undertow request failed HttpServerExchange

i'm using jHipster for back-end admin dashboard application and i'm getting this error often that brings my server down every time it appears.
2019-12-26 10:30:29,516 ERROR [XNIO-2 task-10] WebsocketConfiguration$2: Handshake failed due to invalid Upgrade header: null
2019-12-26 10:38:46,039 ERROR [XNIO-2 I/O-1] request: UT005071: Undertow request failed HttpServerExchange{ CONNECT check.best-proxies.ru:80 request {Host=[check.best-proxies.ru:80]} response {}}
java.lang.IllegalArgumentException: UT000068: Servlet path match failed
at io.undertow.servlet.handlers.ServletPathMatchesData.getServletHandlerByPath(ServletPathMatchesData.java:83)
at io.undertow.servlet.handlers.ServletPathMatches.getServletHandlerByPath(ServletPathMatches.java:88)
at io.undertow.servlet.handlers.ServletInitialHandler.handleRequest(ServletInitialHandler.java:151)
at io.undertow.server.handlers.HttpContinueReadHandler.handleRequest(HttpContinueReadHandler.java:65)
at io.undertow.server.handlers.encoding.EncodingHandler.handleRequest(EncodingHandler.java:66)
at io.undertow.server.Connectors.executeRootHandler(Connectors.java:336)
at io.undertow.server.protocol.http.HttpReadListener.handleEventWithNoRunningRequest(HttpReadListener.java:255)
at io.undertow.server.protocol.http.HttpReadListener.handleEvent(HttpReadListener.java:136)
at io.undertow.server.protocol.http.HttpReadListener.handleEvent(HttpReadListener.java:59)
at org.xnio.ChannelListeners.invokeChannelListener(ChannelListeners.java:92)
at org.xnio.conduits.ReadReadyHandler$ChannelListenerHandler.readReady(ReadReadyHandler.java:66)
at org.xnio.nio.NioSocketConduit.handleReady(NioSocketConduit.java:88)
at org.xnio.nio.WorkerThread.run(WorkerThread.java:561)
Since jHipster generates a lot of configuration, the only thing i could find about undertow is this method :
#Override
public void customize(ConfigurableEmbeddedServletContainer container) {
MimeMappings mappings = new MimeMappings(MimeMappings.DEFAULT);
// IE issue, see https://github.com/jhipster/generator-jhipster/pull/711
mappings.add("html", MediaType.TEXT_HTML_VALUE + ";charset=utf-8");
// CloudFoundry issue, see https://github.com/cloudfoundry/gorouter/issues/64
mappings.add("json", MediaType.TEXT_HTML_VALUE + ";charset=utf-8");
container.setMimeMappings(mappings);
// When running in an IDE or with ./mvnw spring-boot:run, set location of the static web assets.
setLocationForStaticAssets(container);
/*
* Enable HTTP/2 for Undertow - https://twitter.com/ankinson/status/829256167700492288
* HTTP/2 requires HTTPS, so HTTP requests will fallback to HTTP/1.1.
* See the JHipsterProperties class and your application-*.yml configuration files
* for more information.
*/
if (jHipsterProperties.getHttp().getVersion().equals(JHipsterProperties.Http.Version.V_2_0) &&
container instanceof UndertowEmbeddedServletContainerFactory) {
((UndertowEmbeddedServletContainerFactory) container)
.addBuilderCustomizers(builder ->
builder.setServerOption(UndertowOptions.ENABLE_HTTP2, true));
}
}
Can anyone tell me where is the problem?
Thanks in advance!
It's the search crawler to get url not found,throw the error,you can write robots.txt to prohibit it on the root directory.

How to include JS in a page HTML with Apache Sling

In Apache Sling i want include a javascript into a HTML page.
Via http://localhost:8080/bin/browser.html/ I created two nodes (then manually): html.html and processing.js.
JSON of html.html is:
{
"jcr:created": "{Date}2018-04-19 20:50:09",
"jcr:createdBy": "admin",
"jcr:primaryType": "{Name}nt:file",
"jcr:content": {
"jcr:data": "/bin/cpm/nodes/property.bin/apps/res/html.html/_jcr_content?name=jcr%3Adata",
"jcr:lastModified": "{Date}2018-04-19 20:50:09",
"jcr:lastModifiedBy": "admin",
"jcr:mimeType": "text/html",
"jcr:primaryType": "{Name}nt:resource",
"jcr:uuid": "ed3121b3-580c-46b2-acc6-7029cdb6f1c3"
}
}
JSON of processing.js is:
{
"jcr:data": "/bin/cpm/nodes/property.bin/apps/res/processing.js?name=jcr%3Adata",
"jcr:lastModified": "{Date}2018-04-19 21:32:40",
"jcr:lastModifiedBy": "admin",
"jcr:mimeType": "text/javascript",
"jcr:primaryType": "{Name}nt:resource",
"jcr:uuid": "74fd137a-3b37-4893-b443-bd086a4fb4d7"
}
In page HTML I include processing.js with <script> tag in the <head> tag look like following:
<head>
<script type="text/javascript" src="processing.js"></script>
</head>
Both nodes is located on the same path, that's "apps".
I get error in console of Mozilla Firefox:
http://i68.tinypic.com/a0cj88.png
In error.log file I get this error:
19.04.2018 22:13:32.813 *INFO* [0:0:0:0:0:0:0:1 [1524168812811] GET /apps/processing.js HTTP/1.1] org.apache.sling.engine.impl.SlingRequestProcessorImpl service: Resource /apps/processing.js not found
Why did I get this error? How can i fix it?
Please help me. Thanks you very much in advance.
Try to add the resource path to the src of your file.
<script type="text/javascript" src="${resource.path}/processing.js"></script>
THat should solve the problem

Building a JMX client in a servlet installed on the Deployment Manager

I'm building a monitoring application as a servlet running on my websphere 7 ND deployment manager. The tool uses JMX to query the deployment manager for various data. Global Security is enabled on the dmgr.
I'm having problems getting this to work however. My first attempt was to use the websphere client code:
String sslProps = "file:" + base +"/properties/ssl.client.props";
System.setProperty("com.ibm.SSL.ConfigURL", sslProps);
String soapProps = "file:" + base +"/properties/soap.client.props";
System.setProperty("com.ibm.SOAP.ConfigURL", pp);
Properties connectProps = new Properties();
connectProps.setProperty(AdminClient.CONNECTOR_TYPE, AdminClient.CONNECTOR_TYPE_SOAP);
connectProps.setProperty(AdminClient.CONNECTOR_HOST, dmgrHost);
connectProps.setProperty(AdminClient.CONNECTOR_PORT, soapPort);
connectProps.setProperty(AdminClient.CONNECTOR_SECURITY_ENABLED, "true");
AdminClient adminClient = AdminClientFactory.createAdminClient(connectProps) ;
This results in the following exception:
Caused by: com.ibm.websphere.management.exception.ConnectorNotAvailableException: ADMC0016E: The system cannot create a SOAP connector to connect to host ssunlab10.apaceng.net at port 13903.
at com.ibm.ws.management.connector.soap.SOAPConnectorClient.getUrl(SOAPConnectorClient.java:1306)
at com.ibm.ws.management.connector.soap.SOAPConnectorClient.access$300(SOAPConnectorClient.java:128)
at com.ibm.ws.management.connector.soap.SOAPConnectorClient$4.run(SOAPConnectorClient.java:370)
at com.ibm.ws.security.util.AccessController.doPrivileged(AccessController.java:118)
at com.ibm.ws.management.connector.soap.SOAPConnectorClient.reconnect(SOAPConnectorClient.java:363)
... 22 more
Caused by: java.net.ConnectException: Connection refused
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
at java.net.Socket.connect(Socket.java:519)
at java.net.Socket.connect(Socket.java:469)
at java.net.Socket.<init>(Socket.java:366)
at java.net.Socket.<init>(Socket.java:209)
at com.ibm.ws.management.connector.soap.SOAPConnectorClient.getUrl(SOAPConnectorClient.java:1286)
... 26 more
So, I then tried to do it via RMI, but adding in the sas.client.properties to the environment, and setting the connectort type in the code to CONNECTOR_TYPE_RMI. Now though I got a NameNotFoundException out of CORBA:
Caused by: javax.naming.NameNotFoundException: Context: , name: JMXConnector: First component in name JMXConnector not found. [Root exception is org.omg.CosNaming.NamingContextPackage.NotFound: IDL:omg.org/CosNaming/NamingContext/NotFound:1.0]
To see if it was an IBM issue, I tried using the standard JMX connector as well with the same result (substitute AdminClient for JMXConnector in the above error)
JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/JMXConnector");
Hashtable h = new Hashtable();
String providerUrl = "corbaloc:iiop:" + dmgrHost + ":" + rmiPort + "/WsnAdminNameService";
h.put(Context.PROVIDER_URL, providerUrl);
// Specify the user ID and password for the server if security is enabled on server.
String[] credentials = new String[] { "***", "***" };
h.put("jmx.remote.credentials", credentials);
// Establish the JMX connection.
JMXConnector jmxc = JMXConnectorFactory.connect(url, h);
// Get the MBean server connection instance.
mbsc = jmxc.getMBeanServerConnection();
At this point, in desperation I wrote a wsadmin sccript to run both the RMI and SOAP methods. To my amazement, this works fine. So my question is, why does the code not work in a servlet installed on the dmgr ?
regards,
Trevor
For the SOAP error, the ConnectException looks like the wrong SOAP host/port was used for the dmgr. I would double-check the server logs for the SOAP port. For the RMI error (NameNotFoundException), it looks like you're trying to use JMXConnectorFactory, which isn't supported by WAS.
If your application is installed on the dmgr, it's probably easiest to just use AdminServiceFactory.getAdminService to get an in-process reference to the AdminService rather than trying to open a new connection to the same process:
http://publib.boulder.ibm.com/infocenter/wasinfo/fep/topic/com.ibm.websphere.javadoc.doc/web/apidocs/com/ibm/websphere/management/AdminServiceFactory.html

Resources