wildfly 10.0, jax-ws and stateful session - java

I want to build Jax-ws web service using Wildfly 10.0 and I want this web service with stateful session (read and write on session ),
I have searched for that, and I see the below link:
https://docs.oracle.com/cd/E14571_01/web.1111/e13734/stateful.htm#WSADV234
Unfortunately the session code did'n work
When I call sayHello method that use session, the time finished and returned (Exception: java.lang.NullPointerException Message: java.lang.NullPointerException ).
I'm using Eclipse Mars, Dynamic web service, Wildfly 10.0, and the web service (server: using Wildfly 10.0, web service run-time: Apache Axis, and using ear file for this project)
The code is:
package com.sample;
#WebService(targetNamespace = "http://sample.com/", serviceName = "Test1Service", portName = "Test1Port")
#Stateful
public class Test1 {
#Resource
private WebServiceContext wsContext;
#WebMethod
public String sayHello() {
MessageContext mc = wsContext.getMessageContext();
HttpSession session = ((javax.servlet.http.HttpServletRequest) mc.get(MessageContext.SERVLET_REQUEST))
.getSession();
if (session == null)
throw new WebServiceException("No HTTP Session found");
String item = "";
try {
item = (String) session.getAttribute("name1");
} catch (Exception e) {
e.printStackTrace();
}
if (item == null || item.equals(""))
item = "good";
session.setAttribute("name1", item);
return "Hello " + session.getAttribute("name1");
}
#WebMethod
public int setValue(int x) {
return x;
}
}
Please note the setValue method worked successfully, but the sayHello method did'nt work

Thanks everybody,
The problem: I was using Axis not Axis2 where Axis2 support Http session.

Related

JAX-RS Post requests works fine locally but doesn't on Heroku. What can it be?

I uploaded the server project by WAR file in Heroku, Jersey is okay working locally, just isn't in the server, so annotations seems okay. JSP pages age working both locally and remotely with Spring MVC and Hibernate in a Maven project. URLs seems okay to the request. It returns me 500 Internal Server Error, even when I try by post http request online. What can it be?
Unity Client:
public class Test{
//Simplified version of the code:
public string Testing() {
string url = URL.HEROKUPOST.url;
WWWForm form = new WWWForm();
form.AddField( "JsonRequest", "JsonRequest");
form.AddField( "Action", "Action");
WWW www = new WWW( url, form );
yield return www;
if (string.IsNullOrEmpty(www.error))
{
yield return www.data;
}
else
{
yield return www.error ;
}
}
Java Server:
#Path("/helloworld")
public class JSONController
{
#POST #Produces("application/json")
public String unityRequest(#FormParam("JsonRequest") String requisition, #FormParam("Action")String action)
{
return "Okay";
}
}

Error in Client Server Application : Unable to find converter for java.util.UUID

I am working on a client server application. I was using Restlet 2.0.3. Due to a heavy load task my client was getting timed-out. I searched on the forum and found that switching over to Restlet 2.2 would help. So I did that. I upgraded my Restlet to 2.2.1. But now my code has stopped working at precisely this method.
public synchronized UUID generateUniqueSessionId(String userAtDomain)
{
UUID newSessionId = UUID.randomUUID();
SessionAttributes sessionAttributes = new SessionAttributes();
sessionAttributes.setAlive(true);
sessionAttributes.setFQUserName(userAtDomain);
loggedInUsers.put(newSessionId, sessionAttributes);
return newSessionId;
}
So I am returning the UUID at last.
This code is on the server and invoked during login. Following is the error that I am getting from the logs.
16 Mar 2015 11:23:18 WARN - Unable to find a converter for this object : f3d2edda-443c-454d-856a-fb4e7ed9c535
And this object referred in the log belongs to java.util.UUID
The code on the client side which invokes the server looks like this.
public UUID authenticateUser(String username, String passwd) {
try {
String url = RESTLetWebSvcsFactory.getFactoryInstance().getServer_URL() + "login/" + username + "/" + passwd;
Context context = new Context();
Client client = new Client(context, Protocol.HTTP);
ClientHelper helper = new ClientHelper(client);
helper.getHelpedParameters().set("socketConnectTimeoutMs", "60000");
ClientResource cr = new ClientResource(url);
LoginLogoutResource resource = cr.wrap(LoginLogoutResource.class);
return resource.loginUser();
} catch (ResourceException re) {
if (re.getStatus().isConnectorError()) {
try {
RESTLetWebSvcsFactory.enableFallBackServer();
String url = RESTLetWebSvcsFactory.getFactoryInstance().getServer_URL() + "login/" + username + "/" + passwd;
ClientResource cr = new ClientResource(url);
LoginLogoutResource resource = cr.wrap(LoginLogoutResource.class);
return resource.loginUser();
} catch (ResourceException re1) {
int statusCode = new RESTLetErrorHandler().handleServerError(re);
if (statusCode != -1) {
throw new UserCRUDException(statusCode);
}
}
} else {
throw new UserCRUDException(new RESTLetErrorHandler().handleServerError(re));
}
}
return null;
}
Note: USERCRUDException is my own exception and not one of JAVA
Please help me resolve this problem which probably prevents returning the UUID from the server and thus my application isn't moving ahead.
Thanks in advance
Restlet uses under the hood a generic bean conversion to convert bean to representation (and representation to bean). So your problem depends on the converter you use.
I made a test with the extension org.restlet.ext.jackson (that contains such bean converter) and with version 2.2.1 of Restlet. My test bean is described below:
public class TestBean {
private String name;
private String message;
private UUID uuid;
(...)
public UUID getUuid() {
return uuid;
}
public void setUuid(UUID uuid) {
this.uuid = uuid;
}
}
and the following test server resource:
public class MyServerResource extends ServerResource {
#Get
public TestBean ping() {
TestBean bean = new TestBean();
bean.setMessage("pong");
bean.setUuid(UUID.randomUUID());
return bean;
}
}
I received the following content for a GET method:
{
"name":"my name",
"message":"my message",
"uuid":"be9e5381-d5c9-4e45-b5c8-4af1f8bdca16"
}
Can you provide the converter you use? and the list of the Restlet dependencies you have in your application?
Hope it helps you,
Thierry

Using jax-ws client methods in Weblogic enviroment

I faced with problem using jax ws client with Weblogic 10.3. I generate webservice stubs and test connection with webservice in simple java project. All works fine. But when I pack this project in jar file and add it to my main project which contains other jars and running on weblogic I get:
java.lang.NoSuchMethodError: org.home.client.AddressWS.getAddressByRequestAsync(ILjava/lang/String;)Ljavax/xml/ws/Response;
This exception was thrown when I tried to call webservice stub`s method.
public class MyServiceImpl implements MyService {
private AddressWS service;
private static final String ENDPOINT = "http://endpoint.address.ws.company.org/";
private static final String SERVICE_NAME = "AddressWSImplService";
#Override
public void setSOAPServiceURL(String serviceURL) {
URL url = createURL(serviceURL);
QName qName = new QName(ENDPOINT, SERVICE_NAME);
AddressWSImplService addressWSImplService= new AddressWSImplService(url, qName);
service = addressWSImplService.getAddressWSImplPort();
}
#Override
public String getAddressById(int id, String param) throws TimeoutException {
// NoSuchMethodError was thrown here
final Response<GetAddressById> response = service
.getAddressByIdAsync(id, param);
return (String) getValue(new Future<String>() {...});}
Any pointers will be helpfull.

Reference to own wsdl url

I'm building a web service that's supposed to register on another server by sending its wsdl URL to that server.
I built a very basic web service in Netbeans,
#WebService
public class RegisterTest{
#WebMethod(operationName = "emphasize")
public String emphasize(#WebParam(name = "inputStr") String input){
return input + "!!!";
}
}
and Netbeans automatically directs me to localhost:8080/RegisterTest/RegisterTestService?Tester, and naturally, the wsdl can be found at localhost:8080/RegisterTest/RegisterTestService?wsdl.
How would I programmatically get this URL?
Edit:
I've noticed that the only place that seems to store this URL is the glassfish server itself. The context-root seems to only be found in glassfish/domain//config/domain.xml.
Is there a nice way of accessing the glassfish server APIs? I can easily get the endpoint address through the UI in applications > serviceName > View Endpoint, is there a programmatic way of doing this?
I've tried looking through asadmin commands, but can't seem to find anything there that gets the context-root or the endpoint URL either.
Untested, but should be pretty close to what you're looking for:
#WebService
public class RegisterTest
{
#Resource
private WebServiceContext context;
#WebMethod(operationName = "emphasize")
public String emphasize(#WebParam(name = "inputStr") String input)
{
return input + "!!!";
}
#WebMethod(operationName = "getWsdlUrl")
public String getWsdlUrl()
{
final ServletContext sContext = (ServletContext)
this.context.getMessageContext().get(MessageContext.SERVLET_CONTEXT);
final HttpServletRequest req = (HttpServletRequest)
this.context.getMessageContext().get(MessageContext.SERVLET_REQUEST);
final StringBuilder sb = new StringBuilder();
sb.append(req.isSecure() ? "https" : "http");
sb.append("://");
sb.append(req.getLocalName());
if ((req.isSecure() && req.getLocalPort() != 443) ||
(!req.isSecure() && req.getLocalPort() != 80))
{
sb.append(":");
sb.append(req.getLocalPort());
}
sb.append(sContext.getContextPath());
sb.append(RegisterTest.class.getSimpleName());
sb.append("Service?wsdl");
return sb.toString();
}
}

cannot send parameters from java client

I am developing a java client for a web service.
I have this method in my web service:
#WebMethod(operationName = "test")
public Integer test(#WebParam(name = "number")
int number) {
return number;
}
My client looks like this
public static void main(String[] args) {
try {
String BODY_NAMESPACE_VALUE = /namespace url/;
QName port = new QName(/Service name/);
ServiceFactory factory = ServiceFactory.newInstance();
Service service = factory.createService(new QName(/Service name/));
Call call = service.createCall(port);
call.setTargetEndpointAddress(/WSDL location/);
call.setReturnType(XMLType.XSD_INT);
call.setOperationName(new QName(BODY_NAMESPACE_VALUE, "test"));
call.addParameter("number", XMLType.XSD_INT, ParameterMode.IN);
Integer[] i = new Integer[1];
i[0] = new Integer(20);
System.out.println("test :"+call.invoke(i));
} catch (Exception ex) {
ex.printStackTrace();
}
}
I get return values ok from the web service in my java client since I tried getting a constant from the web service. However, in the case above I am trying to send 20 from the client to the web service and receive it back. However I am receiving 0. Does anyone know why sending parameters from client to web service is not working?
Thanks and regards,
Krt_Malta
I don't know if this is the answer but it appears as though you are sending the webservice an array of Integers
Integer[] i;
when it is only expecting a single int.

Categories

Resources