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

web services doubt

tadi raja
Ranch Hand

Joined: Jul 07, 2008
Posts: 109
Hi i am new to webservices

I have an application,i want to call web services methods to a swing
application,how to call that methods ? i have a frame in that
Drug1,drug2,vehicle1,vehicle2 and solutions are labels and their
corresponding textfields, i can fill the data into textfields and send
submit button,the data will be stored in a Table.from that table i will
provide one hyperlink in one cell and click that link it will go to
another dialog box (the selected row from the Table will be displayed on
next dialog box) and it will call web services methods mentioned
below and that same window i want to show the details of the drug,vehicle and solution like study period,physical compatibility,containers and storage conditions.

Here is the web services code :

package com.quadramed.qcpr.dkv.client;

import java.io.IOException;

import java.util.List;

import javax.xml.bind.JAXBContext;

import javax.xml.bind.JAXBException;

import javax.xml.bind.Marshaller;

import javax.xml.bind.Unmarshaller;

import javax.xml.parsers.DocumentBuilderFactory;

import javax.xml.soap.MessageFactory;

import javax.xml.soap.SOAPBody;

import javax.xml.soap.SOAPConnection;

import javax.xml.soap.SOAPConnectionFactory;

import javax.xml.soap.SOAPEnvelope;

import javax.xml.soap.SOAPException;

import javax.xml.soap.SOAPMessage;

import javax.xml.soap.SOAPPart;
import org.w3c.dom.Document;

import com.quadramed.isdid.DetailedCompatibilityRequest;

import com.quadramed.isdid.DetailedCompatibilityResponse;

import com.quadramed.isdid.DetailedCompatibilityResponseType;

import com.quadramed.isdid.ObjectFactory;

public class QueryDetailedCompatibility {

public static void main(String[] args)

{

QueryDetailedCompatibility obj=new QueryDetailedCompatibility();

List results=obj.setParams("ALL", "01", "809",false, "","", "");

System.out.println("\nUNMARSHALLED RESPONSE\n"+"Results Size"+results.size());



for(int i=0; i<results.size(); i++)

{

DetailedCompatibilityResponseType.ResultType result = (DetailedCompatibilityResponseType.ResultType)results.get(i);

if(result != null)

{



System.out.println("Study Period - \n" + result.getStudyPeriod());

System.out.println("\nContainers -\n"+result.getContainers());

System.out.println("\nPHysical Compatibility\n"+result.getPhysicalCompatibility());

System.out.println("\nStorage Conditions\n"+result.getStorageConditions());

System.out.println("\nMethods\n"+result.getMethods());

System.out.println("\nChemical Stability\n"+result.getChemicalStability());

System.out.println("\nCitation\n"+result.getCitationText());

System.out.println("\nNotes\n"+result.getNotes());



}

else

{

System.out.println("Null result");

}



}

}

public List setParams(String s_administrationMethod,String s_drug1Id,String s_drug2Id,boolean b_IgnoreOptional,String s_solutionId,String s_vehicle1Id,String s_vehicle2Id)

{ List results=null;

try

{

JAXBContext context = JAXBContext.newInstance("com.quadramed.isdid");

ObjectFactory oFactory = new ObjectFactory();



DetailedCompatibilityRequest request = oFactory.createDetailedCompatibilityRequest();



request.setAdministrationMethod(s_administrationMethod);

request.setDrug1Id(s_drug1Id);

if(!s_drug2Id.equals(null))

request.setDrug2Id(s_drug2Id);



request.setIgnoreOptional(b_IgnoreOptional);

if(!s_solutionId.equals(""))

request.setSolutionId(s_solutionId);

if(!s_vehicle1Id.equals(""))

request.setVehicle1Id(s_vehicle1Id);

if(!s_vehicle2Id.equals(""))

request.setVehicle2Id(s_vehicle2Id);



Marshaller m = context.createMarshaller();

m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);



m.marshal(request, System.out);



DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();

dbf.setNamespaceAware(true);

Document marshalledDocument = dbf.newDocumentBuilder().newDocument();



try

{

SOAPConnectionFactory soapConnFactory = SOAPConnectionFactory.newInstance();

SOAPConnection soapConnection = soapConnFactory.createConnection();



MessageFactory messageFactory = MessageFactory.newInstance();

SOAPMessage message = messageFactory.createMessage();



SOAPPart soapPart = message.getSOAPPart();

SOAPEnvelope soapEnv = soapPart.getEnvelope();

SOAPBody body = soapEnv.getBody();

body.addDocument(marshalledDocument);

m.marshal(request, body);



message.saveChanges();



System.out.println("\nSOAP REQUEST\n");

message.writeTo(System.out);



System.out.println("Trying to Send");



String destination = "http://starfighter:7014/isdid/services";

SOAPMessage soapResponse = soapConnection.call(message, destination);



System.out.println("\nSOAP RESPONSE\n");



soapResponse.writeTo(System.out);



Unmarshaller um = context.createUnmarshaller();



Document respDoc = soapResponse.getSOAPBody().getOwnerDocument();



DetailedCompatibilityResponse response = (DetailedCompatibilityResponse) um.unmarshal(soapResponse.getSOAPBody().getFirstChild());





results = response.getResult();



soapConnection.close();



}

catch(SOAPException e)

{

e.printStackTrace();

}

catch(IOException e)

{

e.printStackTrace();

}

}

catch(JAXBException e)

{

e.printStackTrace();

}

catch(Exception e)

{

e.printStackTrace();

}

return (List)results;

}
}
//////////////////
Here is the java code

public StandardPanel firstPanel()
{
StandardPanel firstPanel1 = new StandardPanel();
StandardPanel panel = new StandardPanel();
panel.setLayout(null);
panel.setBounds(0,0,550,470);

StandardPanel secondPnl = new StandardPanel();
secondPnl.setLayout(null);
secondPnl.setBounds(206,50,375,210);
secondPnl.setBorder(BorderFactory.createLineBorder(Color.gray,1));


drug1 = new StandardLabel("* Drug 1: ");
drug1.setBounds(15,40,70,20);
secondPnl.add(drug1);
_drug1 = new StandardTextField(10);
_drug1.setText("");
_drug1.setBounds(95,40,150,20);
secondPnl.add(_drug1);

vehicle1 = new StandardLabel(" Vehicle 1:");
vehicle1.setBounds(15,65,90,20);
secondPnl.add(vehicle1);
_vehicle1 = new StandardTextField(10);
_vehicle1.setText("");
_vehicle1.setBounds(95,65,150,20);
secondPnl.add(_vehicle1);

drug2 = new StandardLabel("** Drug 2:");
drug2.setBounds(15,90,70,20);
secondPnl.add(drug2);
_drug2 = new StandardTextField(10);
_drug2.setText("");
_drug2.setBounds(95,90,150,20);
secondPnl.add(_drug2);

vehicle2 = new StandardLabel(" Vehicle 2: ");
vehicle2.setBounds(15,115,90,20);
secondPnl.add(vehicle2);
_vehicle2 = new StandardTextField(10);
_vehicle2.setText("");
_vehicle2.setBounds(95,115,150,20);
secondPnl.add(_vehicle2);

solution2 = new StandardLabel("** Solution: ");
solution2.setBounds(15,140,100,20);
secondPnl.add(solution2);
_solution = new StandardTextField(10);
_solution.setText("");
_solution.setBounds(95,140,150,20);
secondPnl.add(_solution);

StandardPanel thirdPnl = new StandardPanel();
thirdPnl.setLayout(null);
thirdPnl.setBounds(20,265,520,90);

required = new StandardLabel(" * Required ");
required.setBounds(180,7,90,20);
thirdPnl.add(required);

eitherASolutionOrDrug2IsRequired = new StandardLabel(" ** Either a solution or drug 2 is required ");
eitherASolutionOrDrug2IsRequired.setBounds(255,7,240,20);
thirdPnl.add(eitherASolutionOrDrug2IsRequired);

clearAll = new StandardButton();
clearAll.setText("Clear All");
clearAll.addActionListener(this);
clearAll.setBounds(235,40,100,25);
thirdPnl.add(clearAll);

checkCompatibility = new StandardButton();
checkCompatibility.setText("Check Compatibility");
checkCompatibility.addActionListener(this);
checkCompatibility.setBounds(340,40,150,25);
thirdPnl.add(checkCompatibility);

StandardPanel newPanel = new StandardPanel();

panel.add(firstPnl);
panel.add(secondPnl);
panel.add(thirdPnl);

newPanel.add(panel);

StandardPanel firstPnl1 = new StandardPanel();
firstPnl1.setLayout(null);
firstPnl1.setBounds(0,0,550,470);

solCompatibilitySearch = new StandardLabel("Solution compatibility search");
solCompatibilitySearch.setFont(new Font("Arial",Font.BOLD,12));
solCompatibilitySearch.setForeground(Color.blue);
solCompatibilitySearch.setBounds(5,20,190,20);
firstPnl1.add(solCompatibilitySearch);

print = new StandardButton();
print.setText("Print");
print.setBounds(250,20,80,25);
print.addActionListener(this);
// firstPnl1.add(print);

allCompatibilitySearch = new StandardLabel("All compatibility search");
allCompatibilitySearch.setFont(new Font("Arial",Font.BOLD,12));
allCompatibilitySearch.setForeground(Color.blue);

searched = new StandardLabel("Searched: Norepinephrine bitartrate ");
searched.setFont(new Font("Arial",Font.BOLD,11));
searched.setBounds(5,40,210,20);
firstPnl1.add(searched);

searched1 = new StandardLabel("Searched: Insulin, regular and TPN(2-in-1) Total Parenteral Nutrition Admixture");

StandardPanel searchPnl = new StandardPanel();
searchPnl.setLayout(new BoxLayout(searchPnl,BoxLayout.Y_AXIS));

ysite1 = new StandardRadioButton("Y-Site");
ysite1.setForeground(new Color(143,188,143));

searchPnl.add(ysite1);
searchPnl.add(Box.createHorizontalStrut(10));

admixture1 = new StandardRadioButton("Admixture");
admixture1.setForeground(new Color(143,188,143));

searchPnl.add(admixture1);
searchPnl.add(Box.createHorizontalStrut(10));

solution1 = new StandardRadioButton("Solution");
solution1.setForeground(new Color(143,188,143));

searchPnl.add(solution1);
searchPnl.add(Box.createHorizontalStrut(10));

label2 = new StandardLabel("and 2 Incompatible study result(s). Click on a study to view details ");
label2.setFont(new Font("Arial",Font.BOLD,11));

label1 = new StandardLabel("15 Compatible study result(s) Click on a study to view details.");
label1.setFont(new Font("Arial",Font.BOLD,11));
label1.setBounds(5,65,350,20);
firstPnl1.add(label1);

resultTable = new StandardTable();
resultTable.setModel(model);

resultTable.setRowHeight(40);
resultTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
resultTable.getAutoCreateColumnsFromModel();
resultTable.getTableHeader().setResizingAllowed(false);
resultTable.setPreferredScrollableViewportSize(resultTable.getPreferredSize());
resultTable.getColumnModel().getColumn(0).setCellRenderer(new ColorRenderer(new Color(60,179,113)));
resultTable.getColumnModel().getColumn(6).setCellRenderer(new HyperTextRenderer());
resultTable.getColumnModel().getColumn(6).setPreferredWidth(130);
resultTable.getColumnModel().getColumn(5).setPreferredWidth(100);

///////////// 04-08-2008 add mouse listener to 6 column and 0 row of the table /////////////////

resultTable.addMouseListener(new MouseAdapter()
{
public void mouseClicked(MouseEvent me)
{
JTable table = (JTable)me.getComponent();

int row = table.rowAtPoint(new Point(me.getX(), me.getY()));
int col = table.columnAtPoint(new Point(me.getX(), me.getY()));

String str = Integer.toString(col);
String str1 = Integer.toString(row);

System.out.println("col " + col + ",row "+ row);

study.setVisible(true);

}
});

/* public void mousePressed(MouseEvent me)
{

}
});*/

JScrollPane spane = new JScrollPane(resultTable);
spane.setBounds(5,85,500,250);
firstPnl1.add(spane);

StandardPanel replacePnl = new StandardPanel();

prevScreen = new StandardButton();
prevScreen.setText("previous");
prevScreen.setBounds(375,350,115,25);
prevScreen.addActionListener(this);
firstPnl1.add(prevScreen);

replacePnl.add(firstPnl1);

card = new CardLayout();
mainPanel = new StandardPanel();
mainPanel.setLayout(card);

mainPanel.add(newPanel,"First Panel");
mainPanel.add(replacePnl,"Next Panel");

firstPanel1.add(mainPanel);

return firstPanel1;
}

please help me how to call that web services to a swing application and use that code i want to show the details of the corresponding drugor vehicle or solution with details.

thank you in advance
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: web services doubt