Win a copy of Spark in Action this week in the Open Source Projects forum!

khan gul

Ranch Hand
+ Follow
since Jan 27, 2011
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by khan gul

I have a Question on JNDI lookup for datasource in websphere. My understanding is that if you have configured a connection pool on server like web sphere then the JDNI binding should occur once to initialize the DataSource object. Then later multiple threads can use this single DataSource object and call the getConnection() to get new connection from the pool. Is it correct?

java code below:


private static OLBDataSource instance = null;
private DataSource dataSource = null;

//make sure there is only one instance of OLBDataSource. aali
static {
try {
instance = new OLBDataSource();
} catch (NamingException e) {
instance = null;
}
}


private OLBDataSource() throws NamingException {
try {
Properties params = new Properties();
params.setProperty(Context.INITIAL_CONTEXT_FACTORY, WSN_INITIAL_CONTEXT_FACTORY);

// Look up the datasource configured on the server.
InitialContext context = new javax.naming.InitialContext(params);
dataSource = (DataSource) context.lookup("jdbc/myDB");

}catch


public static DataSource getMyConnection(){
return dataSource;
}


//Now multiple threads can call the above getMyConnection() method and then call getConnection() to get unique connection from the thread pool.

Is my understanding correct?

7 years ago
Thanks for replying me in details. Can the following has the potential to fail or throw an exception?

Class A{

private static B b;

public void setB(B b1){
b = b1;
}

public A(B b1){
setB(b1);
}

public B getB(){
return b;
}
}

If there is only one thread say T1 and it does this following:

Hi,
I have a question on the following situation

1. Create an instance of A say, A a = new A();
2. Then call another method that create another instance of A in a method say create() method as shown below:

void create(){
Class<?> theClassA = Class.forName("A");
A a = (A)theClassA.newInstance();
Class<?> theClassB = Class.forName("B");
B b = (B) theClassB.newInstance();
a.setB(b);
}

Once the thread return from this create() method it calls a.getB() - where a object was created before the method create was called?. Will this be able to see the B? or there is a possibility it can see null reference of B as B object is set in the method created in an unusual way?

regards,
gul
8 years ago
I checked the code and it has [code:java] tag. Is it fine now?
Hi,
I have a question on the following code. Is it possible that the following code can throw Null Pointer Exception?


can the following code produces Null pointer exception?



Since Test class is being added dynamically to ByValue class and Test is a static field in the ByValue, is it possible that when one Thread RESET this static Test field the other thread sees a NULL value?

From Time line point of view, say Thread T3 run() first and instantiate ByValue first and then set Test object to static Test field. But before calling byValue.getTest(), Thread T4 run() and reset a new Test object in the ByValue. Question I have is it possible that T3 can get Null Pointer Exception when it calls byValue.getTest().getName();

Thanks,
Hi,
I have a question on the following code. Is it possible that the following code can throw Null Pointer Exception?


This Test class is been added to ByValue class as a static variable.




Since Test class is being added dynamically to ByValue class and Test is a static field in the ByValue, is it possible that when one Thread RESET this static Test field the other thread sees a NULL value?

From Time line point of view, say Thread T3 run() first and instantiate ByValue first and then set Test object to static Test field. But before calling byValue.getTest(), Thread T4 run() and reset a new Test object in the ByValue. Question I have is it possible that T3 can get Null Pointer Exception when it calls byValue.getTest().getName();

Thanks,

[Edit - added code tags - MB]
I my opinion there is a strong case for sending one way message with replyTo header. Here is the detail:

Client 1 wants to send a message to Server1 with the intend to get back the response on another URL i.e client2. So the question is how Client 1 can send the message? I can only think of that client1 will send the message as ONEWAY and will recieve an HTTP Response 202. Server 1 will read the replyTo header and send the response to client 2.

Not sure how can we do that if what you are saying is correct. Any idea?
9 years ago
Are you trying to say generate the whole header manually? So if I understand you correctly what you are saying is get the SOAPMessage from the handler and then add new header with all those attribute. Is it correct?
This is very tidous. What I am trying to do is something like this:

//Define your call back class to which the final reply from the server should come

javax.xml.ws.Endpoint e = Endpoint.publish( "http://127.0.0.1:9999/ts", new HelloCallback());

WSEndpointReference replyTo = new WSEndpointReference(e.getEndpointReference());

//Then set this replyTo as a OneWayFeature in the current service request

Hello hello = helloService.getHelloPort(new WebServiceFeature[] { new OneWayFeature(true, replyTo)});

//invoke the service
hello.sayHello("Bob");


The problem with the above is that when I send the request I am getting the following error:

28-Jul-2011 9:22:32 AM com.sun.xml.internal.ws.model.RuntimeModeler getRequestWrapperClass
INFO: Dynamically creating request wrapper Class project1.jaxws.SayHello
28-Jul-2011 9:22:32 AM com.sun.xml.internal.ws.model.RuntimeModeler getResponseWrapperClass
INFO: Dynamically creating response wrapper bean Class project1.jaxws.SayHelloResponse
javax.xml.ws.WebServiceException: java.io.IOException: Stream is closed
at com.sun.xml.internal.ws.streaming.TidyXMLStreamReader.close(TidyXMLStreamReader.java:58)
at com.sun.xml.internal.ws.server.sei.EndpointArgumentsBuilder$DocLit.readRequest(EndpointArgumentsBuilder.java:524)
at com.sun.xml.internal.ws.server.sei.EndpointMethodHandler.invoke(EndpointMethodHandler.java:232)
at com.sun.xml.internal.ws.server.sei.SEIInvokerTube.processRequest(SEIInvokerTube.java:82)
at com.sun.xml.internal.ws.api.pipe.Fiber.__doRun(Fiber.java:587)
at com.sun.xml.internal.ws.api.pipe.Fiber._doRun(Fiber.java:546)
at com.sun.xml.internal.ws.api.pipe.Fiber.doRun(Fiber.java:531)
at com.sun.xml.internal.ws.api.pipe.Fiber.runSync(Fiber.java:428)


I read somewhere that if you use JDK1.6.0.6 then its a known bug. But I am using jdk1.6.0.26 and still see this problem.

Can anyone share his or her code regarding the above
regards,
arslan
9 years ago
Hi,
I am breaking my head to find out how I can set the ReplyTo value programatically. i searched everywhere without any answer. Can any know how to do this?

All I need is to change this the address http://www.w3.org/2005/08/addressing/anonymous as shown below

<ReplyTo xmlns="http://www.w3.org/2005/08/addressing">;
<Address>http://www.w3.org/2005/08/addressing/anonymous</Address>
</ReplyTo>

to something like this:


<ReplyTo xmlns="http://www.w3.org/2005/08/addressing">;
<Address>http://www.myservice.com/invoke</Address>
</ReplyTo>
9 years ago
Hi,
While reading SOAP I came across the concept of understanding role. My question is how a soap Node acquire a specific role? For example if a soap message is send to an end point with a role header set to say "http://myrole.com"; then how the reciever says I am in that specific role? Is it up to the recieving node who inspects the header and decide that I am in this role?
regards,
gul
9 years ago
Hi,
Can anyone share his code on how to create a web service that uses WS-Address capabilities? Also is it possible to create a SOAP message using SAAJ for WS-ADDRESS?
Regards,
gul
Hi,
I am planning to take Enterprise Edition 6 Web Services Developer Certified Expert Exam this or next month. Any one has the discount/coupon for this exam?
regards,
Khan
Thanks Kamal for the quick reply,
Here is what i am confused about. While reading Java Web Services Up and Running I came across example for restful service using @WebServiceProvider annotation. But online when I look at some of the examples they are not using @WebServiceProvider annotation at all. Have a look at the following code, i have taken it from jersey website http://jersey.java.net/nonav/documentation/latest/user-guide.html#d4e107

1 @Path("/myResource")
2 @Produces("text/plain")
3 public class SomeResource {
4 @GET
5 public String doGetAsPlainText() {
6 ...
7 }
8
9 @GET
10 @Produces("text/html")
11 public String doGetAsHtml() {
12 ...
13 }
14 }

as you can see there is no @WebServiceProvider annotation.

So my understaning is @WebServiceProvider annotation is required only for Java SE and cannot be used in a web container?

Kindly help me understanding under what condition should or shouldn't we use @WebServiceProvider annotaiton.

regards,
gul
Hi,
I am bit confused on when to use @WebServiceProvider annotation? Is it specific to Java SE platform? I have seen many examples online that doesn't use @WebServiceProvider annotation deployed on web server like tomcat.
regards,
gul
Hi,
I am not clear how we can use ws-address? I searched on line and gone through number of books but couldn't find a single example that shows how to create a soap message with ws-address and the server response back to the replyTo address.
Can any one give a complete example on this?
Thanks in advance
Hi,
I am playing around with WS-Addressing and what I failed to achieve is, how I can send a soap response to a client or end point that has not initiated the request. For example, I am sending the following SOAP Message to end point http://localhost:9000/SoapContext/SoapPort and would like to recieve the response at http://localhost:18081/myservice/hello


<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"; xmlns:typ="http://apache.org/hello_world_soap_http/types">;
<soapenv:Header xmlns:wsa="http://www.w3.org/2005/08/addressing">;
<wsa:Action>http://apache.org/hello_world_soap_http/Greeter/sayHiRequest</wsa:Action>;
<wsa:ReplyTo>
<wsa:Address>http://localhost:18081/myservice/hello</wsa:Address>;
</wsa:ReplyTo>
<wsa:MessageID>123456</wsa:MessageID>
<wsa:To>http://localhost:9000/SoapContext/SoapPort</wsa:To>;
</soapenv:Header>
<soapenv:Body>
<typ:sayHi/>
</soapenv:Body>
</soapenv:Envelope>


But What i don't know is how to consume the SOAP Message at http://localhost:18081/myservice/hello. Can I consume the soap message using a servlet? or do I have to create a new end point ?
Thanks,
gul
9 years ago