aspose file tools*
The moose likes Web Services and the fly likes Running a DII client through JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Web Services
Bookmark "Running a DII client through JSP" Watch "Running a DII client through JSP" New topic
Author

Running a DII client through JSP

carol roach
Greenhorn

Joined: May 12, 2004
Posts: 1
Hi all, first time post.
I have successfully build and run my web-service in jaxrpc. Build a client using dii ... this works from prompt.
However when i try to copy and use client code in jsp file i donot get a return result.
client code in java
package inventorycheck;
import javax.xml.rpc.Call;
import javax.xml.rpc.Service;
import javax.xml.rpc.JAXRPCException;
import javax.xml.namespace.QName;
import javax.xml.rpc.ServiceFactory;
import javax.xml.rpc.ParameterMode;
public class InventoryCheckClient {
private static String qnameService = "InventoryService";
private static String qnamePort = "InventoryServiceImpl";
private static String BODY_NAMESPACE_VALUE =
"urn:Foo";
private static String ENCODING_STYLE_PROPERTY =
"javax.xml.rpc.encodingstyle.namespace.uri";
private static String NS_XSD =
"http://www.w3.org/2001/XMLSchema";
private static String URI_ENCODING =
"http://schemas.xmlsoap.org/soap/encoding/";
public static void main(String[] args) {
System.out.println("Endpoint address = " + args[0]);
try {
ServiceFactory factory =
ServiceFactory.newInstance();
Service service =
factory.createService(new QName(qnameService));

QName port = new QName(qnamePort);

Call call = service.createCall(port);
call.setTargetEndpointAddress(args[0]);

call.setProperty(Call.SOAPACTION_USE_PROPERTY,
new Boolean(true));
call.setProperty(Call.SOAPACTION_URI_PROPERTY, "");
call.setProperty(ENCODING_STYLE_PROPERTY, URI_ENCODING);
QName QNAME_TYPE_STRING = new QName(NS_XSD, "string");
call.setReturnType(QNAME_TYPE_STRING);

call.setOperationName(new QName(BODY_NAMESPACE_VALUE,
"checkInventory"));
call.addParameter("String_1", QNAME_TYPE_STRING,
ParameterMode.IN);
call.addParameter("String_2", QNAME_TYPE_STRING,
ParameterMode.IN);
String[] params = new String[2];;
params[0] = "bk0001";
params[1] = "150";
System.out.println("params[0] = "+params[0]);
System.out.println("params[0] = "+params[1]);
String result = (String)call.invoke(params);
System.out.println(result);
} catch (Exception ex) {
ex.printStackTrace();
result = "Exception error";
}
}
}
now the jsp
<%
String qnameService = "InventoryService";
String qnamePort = "InventoryServiceImpl";
String result = "look for result here";
String BODY_NAMESPACE_VALUE =
"urn:Foo";
String ENCODING_STYLE_PROPERTY =
"javax.xml.rpc.encodingstyle.namespace.uri";
String NS_XSD =
"http://www.w3.org/2001/XMLSchema";
String URI_ENCODING =
"http://schemas.xmlsoap.org/soap/encoding/";
//System.out.println("Endpoint address = " + args[0]);
try {
ServiceFactory factory =
ServiceFactory.newInstance();
Service service =
factory.createService(new QName(qnameService));

QName port = new QName(qnamePort);

Call call = service.createCall(port);
call.setTargetEndpointAddress("http://localhost:8080/inventory/inventory"); //args[0]);

call.setProperty(Call.SOAPACTION_USE_PROPERTY,
new Boolean(true));
call.setProperty(Call.SOAPACTION_URI_PROPERTY, "");
call.setProperty(ENCODING_STYLE_PROPERTY, URI_ENCODING);
QName QNAME_TYPE_STRING = new QName(NS_XSD, "string");
call.setReturnType(QNAME_TYPE_STRING);

call.setOperationName(new QName(BODY_NAMESPACE_VALUE,
"checkInventory"));
call.addParameter("String_1", QNAME_TYPE_STRING,
ParameterMode.IN);
call.addParameter("String_2", QNAME_TYPE_STRING,
ParameterMode.IN);
String[] params = new String[2];
params[0] = request.getParameter("id");
System.out.println("request parameter id: " + params[0]);
params[1] = request.getParameter("quantity");
System.out.println("request parameter quantity: " + params[1]);
result = (String)call.invoke(params);
System.out.println(result);
} catch (Exception ex) {
ex.printStackTrace();
}

%>

<hr>
<h3>Status: <font color="RED"> <%= result %> </h3>
Result comes out as "Exception Error"
Any ideas?
Balaji Loganathan
author and deputy
Bartender

Joined: Jul 13, 2001
Posts: 3150
Originally posted by carol roach:
Result comes out as "Exception Error"

Carol!. Welcome to Javaranch.
Can you post the complete stact trace or error message..?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Running a DII client through JSP
 
Similar Threads
How do I return simple object via web services
Error while Calling createService in DII Client
Encoding style not supported
dii client problems..help!
Eliminate Namespace preceding WS Call with JAX-RPC