Glassfish does not detect the JAX-WS endpoint - glassfish

Hello am facing a problem in the glassfish server
I have deployed my application with intellij and it has shown me the first page of the Hello World successfully and when I add to the url the name of the service a 404page has been shown
This is the code of the webservice
package test;
import javax.jws.WebMethod;
import javax.jws.WebService;
#WebService(serviceName = "HelloService")
public class Hello {
public Hello() {
}
#WebMethod()
public int calcul (int a , int b){
return a+b;
}
}
the web.xml
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app>
<display-name>Archetype Created Web Application</display-name>
</web-app>
the index.jsp
<html>
<body>
<h1>Test the application the problem is that the glassfish can't access to the webservers</h1>
<h2>Hello World!</h2>
</body>
</html>
This is when I run the application for the first time
This is when I add the webservice name to the url
This is the Glassfish5 GUI showing it doesn't detect the components of the new webservices

After i tried again and again
I found in other WAR files that the web.xml don't exist
so i deleted the web.xml file and

Related

JAX-RS not responding (404)

I have a very basic JAX-WS-RS that I'm trying to get working and am getting frustrated. And would love some help. --thanks.
my environment is Eclipse 2018-09 (fresh "dynamic web-app"), java 8u191, tomcat 8.5
my "basic" code (running in the app named: webservice) won't respond at all to calls to /webservice/steve. only a 404.
I'm including JAR: /WEB-INF/lib/javax.ws.rs-api-2.1.1.jar
code:
import javax.ws.rs.*;
#Path("/")
public class ServletTest {
#GET
#Path("/steve")
#Produces("text/plain")
public String getSteve() {return "Steve";}
}

JSF 2.2.10 file upload not working [duplicate]

This question already has an answer here:
Upgrade JSF / Mojarra in JBoss AS / EAP / WildFly
(1 answer)
Closed 5 years ago.
Issue: Action method and setter for file not getting called on file upload.
I did see the link for JSF 2.2 not working, but it is over 4 years old and I thought the problem should have been resolved. I am posting this since I am facing it today!
I am using JSF 2.2.10, JBoss 6.4; I have mojarra set up in JBoss config as follows: (in \modules\system\layers\base\org\jboss\weld\core\main and \modules\system\layers\base\org\jboss\as\weld\main)
I have set up my xhtml and Controller as follows. Would greatly appreciate if you could point out what I am missing. Been stuck with this for more than a day now!
<h:form id="massUpload" enctype="multipart/form-data">
<div class="col-xs-3 col-md-3">
<h:inputFile id="file" value="#{controller.uploadedFile}" />
<h:commandButton value="Upload"
action="#{controller.massUploadBranchGLInfoViaFile}"/>
</div>
</h:form>
Controller As follows:
#Named("controller")
#ViewScoped
public class MyController
extends AccessController
implements Serializable
{
private Part uploadedFile;
public String massUploadBranchGLInfoViaFile() throws IOException {
InputStream stream = uploadedFile.getInputStream();
addSuccessInfoToFlash("update-gl-success");
return "Success";
}
public void setUploadedFile(Part file){
this.uploadedFile = file;
}
public Part getUploadedFile(){
return this.uploadedFile;
}
}
Thank you very much
Karthik
Found (at least part of) the issue: Had to add the multipart-config to servlet configuration in my web.xml. That resolved calling the action and set methods. Am getting a NULLPointerException now. But one issue at a time I guess :)

Apache cxf jax-rs implementation with xml databind

I configured my rest service to implement content negotiation through Variant.
On jersey all works fine but on apache cxf something goes wrong.
No message body writer has been found for class ContentType: application/xml
It seems thath when I construct the response as xml type it cannnot find the correct body writer.
I configured jax-rs with jacksonJaxbJsonProvider and all works great with json databind.
<jaxrs:providers>
<bean class="com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider" />
</jaxrs:providers>
cxf-rt-frontend-jaxrs version 3.0.3
jackson-databind: 2.4.2
Any idea?
Add a #XmlRootElement(name="order") generated xml cannot be <orderId>data<orderId>, it should have root element. Thus updated code would look like
#XmlRootElement(name="order")
#XmlType(propOrder = { "orderId"})
public class OrderForConfirmationEmail implements Serializable {
#XmlElement
public long getOrderId() {
long orderId = new Random().nextLong();
return orderId;
}
}
Generated xml is
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><order xmlns="http://com.kp.swasthik/so/schema">
<orderId>369317779145370211</orderId>
</order>
and json is
{"orderId":6812414735706519327}

Expression Language with CDI not work

i have a simple ear file that includes a war. I have only one Named- Bean and one xhtml.
On glassfish all works fine. But on websphere it does not works.
I does not works mean all EL- Tag will be ignored. I can reproduce this in glassfish when i delete my beans.xml in /WEB- INF. I tried to put the beans.xml in every single folder.
And i read this (http://www.ibm.com/developerworks/websphere/techjournal/1301_stephen/1301_stephen.html):
The beans.xml file must be placed in one of these locations:
For a library JAR, EJB JAR, application client JAR or RAR archive, it needs to be in the META-INF directory.
The WEB-INF/classes directory of a WAR.
For a directory in the JVM classpath containing classes, the code will be scanned if the beans.xml file is located the META-INF sub-directory.
But nothing works. When i use #ManagedBean and Faces Session Scope instead all works fine.
I don't know what i can do else. Please help.
Here my example code and my structures:
XHTML:
<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui">
<h:head>
</h:head>
<h:body>
<h:form id="tableform">
<h:outputText value="TEST"/>
<h:outputText value="#{personBean.helloWorld}"/>
<p:commandButton value="#{personBean.helloWorld}"/>
</h:form>
</h:body>
</html>
Bean:
#Named
#SessionScoped
public class PersonBean implements Serializable{
private String helloWorld;
#PostConstruct
public void init() {
setHelloWorld("HELLO WORLD");
}
public String getHelloWorld() {
return helloWorld;
}
public void setHelloWorld(String helloWorld) {
this.helloWorld = helloWorld;
}
}
Structure:
Ear
-Meta-Inf
--Application.xml
-WAR
--WEB-INF
---beans.xml
But i tried to put it in WEB-INF/classes, META-INF, META-INF from ear. Nothing works. :(
Result on Glassfish with beans.xml:
Result on Websphere / Glassfish without beans.xml:
I get no exception or error or something else.
WebSphere 8.x bundles JSF implementation (MyFaces) and only that default implementation works with CDI. You need to have beans.xml in WEB-INF folder.
However based on your page fragment, you are using custom one (PrimeFaces).
Check this page for more details : CDI integration with JavaServer Faces

signalR : /signalr/hubs is not generated

I can get this tutorial to work in a new project, but not in my existing project.
My project is an ASP.Net MVC 4 web application with the following attribute in the web.config file:
<appSettings>
<add key="webpages:Enabled" value="true"/>
</appSettings>
This is because my application is a Single-Page-Application, which uses AngularJS on the client side. The only page in my application is index.cshtml, to which I've added the relevant code for signalR:
<!-- signalR chat -->
<script src="~/Scripts/jquery.signalR-1.0.0.js"></script>
<!--Reference the autogenerated SignalR hub script. -->
<script src="/signalr/hubs"></script>
<!--Add script to update the page and send messages.-->
<script type="text/javascript">
$(function () {
// Declare a proxy to reference the hub.
var chat = $.connection.chatHub;
// Create a function that the hub can call to broadcast messages.
chat.client.broadcastMessage = function (name, message) {
// Html encode display name and message.
var encodedName = $('<div />').text(name).html();
var encodedMsg = $('<div />').text(message).html();
// Add the message to the page.
$('#discussion').append('<li><strong>' + encodedName
+ '</strong>: ' + encodedMsg + '</li>');
};
// Get the user name and store it to prepend to messages.
$('#displayname').val(prompt('Enter your name:', ''));
// Set initial focus to message input box.
$('#message').focus();
// Start the connection.
$.connection.hub.start().done(function () {
$('#sendmessage').click(function () {
// Call the Send method on the hub.
chat.server.send($('#displayname').val(), $('#message').val());
// Clear text box and reset focus for next comment.
$('#message').val('').focus();
});
});
});
</script>
Then I've got the ChatHub.cs file:
public class ChatHub : Hub
{
public void Send(string name, string message)
{
// Call the broadcastMessage method to update clients.
Clients.All.broadcastMessage(name, message);
}
}
And finally in the global.asax:
protected void Application_Start()
{
RouteTable.Routes.MapHubs();
BundleConfig.RegisterBundles(BundleTable.Bundles);
}
When I run the application, the /signalr/hubs file is not generated. I get a 404 when requesting the file, and it crashes on the line:
chat.client.broadcastMessage = function (name, message) { ....
because chat is null as the previous line did not find chatHub:
var chat = $.connection.chatHub;
Does anyone know what's wrong with my code ?
UPDATE
I have solved my problem by changing the line::
<script src="/signalr/hubs"></script>
to
<script src="~/signalr/hubs"></script>
I have solved my problem by changing the line::
<script src="/signalr/hubs"></script>
to
<script src="~/signalr/hubs"></script>
Also, the reason why /signalr/hubs are not generated is forget to Map SignalR in OWIN Startup Configuration.
public class Startup
{
public void Configuration(IAppBuilder appBuilder){
...
appBuilder.MapSignalR();
...
}
...
In my case, it was because my ChatHub class was not marked public.
I had a similar problem where the hubs file wasn't being generated. It looks like the OP was following the steps here. The way I fixed the problem had to do with the jquery includes. The tutorial I linked below was written with jquery 1.6.4 and jquery-signalr version 2.1.0. When Visual Studio generated the Scripts folder for me, it used jquery version 1.10.2 and jquery-signalr version 2.0.2.
The way I fixed this was simply to edit the index.html file. Note that you can use Chrome's javascript console window Ctrl+Shift+J to see errors.
For me the solution was to reinstall all the packages and restore all the dependecies.
Open nuget powershell console and use this command.
Update-Package -Reinstall
I'll like to add that the signalR Readme file have some note about this issue.
And also if your signalR page is in a PartialView some script should be place in the master page.
Please see http://go.microsoft.com/fwlink/?LinkId=272764 for more information on using SignalR.
Upgrading from 1.x to 2.0
-------------------------
Please see http://go.microsoft.com/fwlink/?LinkId=320578 for more information on how to
upgrade your SignalR 1.x application to 2.0.
Mapping the Hubs connection
----------------------------
To enable SignalR in your application, create a class called Startup with the following:
using Microsoft.Owin;
using Owin;
using MyWebApplication;
namespace MyWebApplication
{
public class Startup
{
public void Configuration(IAppBuilder app)
{
app.MapSignalR();
}
}
}
Getting Started
---------------
See http://www.asp.net/signalr/overview/getting-started for more information on how to get started.
Why does ~/signalr/hubs return 404 or Why do I get a JavaScript error: 'myhub is undefined'?
--------------------------------------------------------------------------------------------
This issue is generally due to a missing or invalid script reference to the auto-generated Hub JavaScript proxy at '~/signalr/hubs'.
Please make sure that the Hub route is registered before any other routes in your application.
In ASP.NET MVC 4 you can do the following:
<script src="~/signalr/hubs"></script>
If you're writing an ASP.NET MVC 3 application, make sure that you are using Url.Content for your script references:
<script src="#Url.Content("~/signalr/hubs")"></script>
If you're writing a regular ASP.NET application use ResolveClientUrl for your script references or register them via the ScriptManager
using a app root relative path (starting with a '~/'):
<script src='<%: ResolveClientUrl("~/signalr/hubs") %>'></script>
If the above still doesn't work, you may have an issue with routing and extensionless URLs. To fix this, ensure you have the latest
patches installed for IIS and ASP.NET.
In my case i was missing :
app.MapSignalR();
in public void Configuration(IAppBuilder app) function located in startup.cs
Some advice for those that start scaling out from the get go. In my case I was working on getting a remote client to work and never realized that
A. the tutorial example lists the web app(server) startup in a using statement, after which the web app disposes properly and no long exists.
I got rid of the using statement and keep a reference to the web app
for later disposal
B. the client has a different url than the server. the example relies on them having the same url. the "/signalr/hubs" is an endpoint run by the signalr server, called by the signalr client to get a script of all the hubs the server implements.
You need to include "http://myServerURL/signalr/hubs", rather than making it
relative to the client.
No lies. This tripped me up for a solid 2 weeks, because by some magic the solution worked anyways on my coworker's setup. This caused me to keep looking for IIS settings and firewall settings and CORS settings that must have been blocking the connection on my computer. I scavenged every last stack overflow question I could and the ultimate answer was that I should have just implemented a heartbeat monitor on the web app from the start.
Good luck and hopefully this saves other people some time.
See if Microsoft.Owin.Host.Systemweb nuget package is not installed, and therefore not building the dynamic js lib.
OwinStartup not firing