Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Running a DII client through JSP

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
author and deputy
Posts: 3150
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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..?
 
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic