package com.tibco;
/*
* Copyright 2001-2006 TIBCO Software Inc.
* All rights reserved.
* For more information, please contact:
* TIBCO Software Inc., Palo Alto, California, USA
*
* $Id: tibjmsQueueRequestor.java 21731 2006-05-01 21:41:34Z $
*
*/

/*
* This is a simple sample of basic QueueRequestor.
*
* This sample publishes specified message(s) on a specified
* queue and quits.
*
* Notice that specified queue should exist in your configuration
* or your queues configuration file should allow
* creation of the specified queue.
*
* This sample can send into dynamic queues thus it is
* using the QueueSession.createQueue() method
* to obtain the Queue object.
*
* Usage: java tibjmsQueueRequestor [options]
* <message-text1>
* ...
* <message-textN>
*
*
* where options are:
*
* -server Server URL.
* If not specified this sample assumes a
* serverUrl of "tcp://localhost:7222"
*
* -user User name. Default is null.
* -password User password. Default is null.
* -queue Queue name. Default is "queue.sample"
*
*
*/

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;
import java.sql.Timestamp;
import java.util.Calendar;

import org.apache.commons.httpclient.Header;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.UsernamePasswordCred entials;
import org.apache.commons.httpclient.auth.AuthScope;
import org.apache.commons.httpclient.methods.InputStreamR equestEntity;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.codec.DecoderException;
import org.apache.http.client.utils.URIUtils;
import org.apache.http.protocol.HTTP;

import com.sun.corba.se.pept.transport.Connection;


public class TibjmsQueueCompositeTest
{
public static void main(String[] args) throws Exception {
try{

File fisheader = new File(args[1]);
File fisrawxml = new File(args[2]);
InputStream isheader = new FileInputStream(fisheader);
byte[] fileBArrayHeader = new byte[(int)fisheader.length()];
isheader.read(fileBArrayHeader,0,(int)fisheader.le ngth());

InputStream israwxml = new FileInputStream(fisrawxml);
byte[] fileBArrayrawxml = new byte[(int)fisrawxml.length()];
israwxml.read(fileBArrayrawxml,0,(int)fisrawxml.le ngth());



String start="<?xml version=\"1.0\" encoding=\"utf-8\"?><tnsb:ValidateRoadsideSubscriberRequest xmlns:tns=\"http://services.****.com/schemas/AsurionCanonicalModel/2.0.0\" xmlns:tnsa=\"http://services.****.com/schemas/Errors/1.0.0\" xmlns:tnsb=\"http://services.***.com/schemas/PolicyAdministration/ValidateRoadsideSubscriberRequest/1.0\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" ><tnsb:Parameters><tnsb:MDN>";
String mdn="9187588255";
String end ="</tnsb:MDN></tnsb:Parameters></tnsb:ValidateRoadsideSubscriberRequest>";
java.net.URI uri = URIUtils.createURI("http", "****", -1, "/LBSRAServiceDemo/Service.svc/RequestPOST",
"tibcourl="+URLEncoder.encode("<?xml version=\"1.0\" encoding=\"utf-8\"?><ServiceConfigurations xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" ><Connections><MDN>1</MDN><ClientId>1</ClientId><ClientName>ATT</ClientName><TibcoCulture>en-US</TibcoCulture><LineOfBusiness>RoadsideAssistance</LineOfBusiness><Application>IntelliRescue</Application><Channel>CSR</Channel><Culture>en-US</Culture><IsSSL>false</IsSSL><IsAsynchronous>false</IsAsynchronous><ServiceUsername>****</ServiceUsername><ServicePassword>****</ServicePassword><QueueConfiguration Service=\"PolicyAdministration\" QueueName=\"Asurion.Dev.PolicyAdministration.Valid ateRoadsideSubscriber.Request\" Method=\"ValidateRoadsideSubscriber\" Version=\"1.0\" /></Connections></ServiceConfigurations>",HTTP.UTF_8)+"&"
+"rawXML="+URLEncoder.encode(start+mdn+end,HTTP.UT F_8)
, null);

URL url = new URL(uri.toString());
HttpURLConnection connection=( java.net.HttpURLConnection ) url.openConnection();
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");

char[] rawxml= new String(fileBArrayrawxml).toCharArray();
char[] header= new String(fileBArrayHeader).toCharArray();
OutputStreamWriter out = new OutputStreamWriter(connection.getOutputStream());
out.write("rawXML=" + URLEncoder.encode(start+mdn+end,HTTP.UTF_8));
out.close();
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String decodedString;
while ((decodedString = in.readLine()) != null) {
System.out.println(decodedString);
}
in.close();

}catch(Exception e){
e.printStackTrace();
}finally{
}
}

}