try to create a xml from a external url and will pass that xml to another programme.
Hi
I am trying to create a .xml file from a java code and i culd not able to do this.
please find the code below:-
Code:
import java.io.File;
import javax.xml.soap.MessageFactory;
import javax.xml.soap.Name;
import javax.xml.soap.SOAPBody;
import javax.xml.soap.SOAPConnection;
import javax.xml.soap.SOAPConnectionFactory;
import javax.xml.soap.SOAPFactory;
import javax.xml.soap.SOAPHeader;
import javax.xml.soap.SOAPMessage;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.MultipartPostMethod;
import org.apache.commons.httpclient.methods.multipart.FilePart;
import org.apache.commons.httpclient.protocol.Protocol;
import com.sun.org.apache.bcel.internal.generic.GETFIELD;
public class MYCliass
{
private static String url= "https://http://www.java-forums.org/newthread.php?do=newthread&f=33";
public static void main(String[] args) throws Exception
{
Protocol easyhttps = new Protocol("https", new MySSLFactory(), 443);
Protocol.registerProtocol("https", easyhttps);
HttpClient client = new HttpClient();
File file1 = new File("C:/Swasti/CUMI/CUMI/sender.xml");
String userPassword = "what:ever";
String encoding = new sun.misc.BASE64Encoder().encode (userPassword.getBytes());
SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
SOAPConnection connection = soapConnectionFactory.createConnection();
SOAPFactory soapFactory = SOAPFactory.newInstance();
MessageFactory factory = MessageFactory.newInstance();
SOAPMessage message = factory.createMessage();
SOAPHeader header = message.getSOAPHeader();
SOAPBody body = message.getSOAPBody();
header.detachNode();
System.out.println("..................");
MultipartPostMethod mPost = new MultipartPostMethod(url);
mPost.setRequestHeader ("Authorization", "Basic " + encoding);
System.out.println("..................");
mPost.setRequestHeader("Content-Type","multipart/form-data");
mPost.addPart(new FilePart("ctr", file1, "application/xml","ISO-8859-1"));
client.executeMethod( mPost );
System.out.println("Done");
}
}
if you have any idea then please guide here to do this.
Thanks
-Sw
Re: try to create a xml from a external url and will pass that xml to another program
The URL you used is not a valid one.
Code:
private static String url= "https://http://www.java-forums.org/newthread.php?do=newthread&f=33";