Send a string to a server

Hi,
I am going to write a java application that sends a string so a server. I don�t know what is on the server side(someone else has written the server part) just that my program is going to use sockets and what port number and IP the server has. I first start using datagrampackets but then I have to use byte array that would not work if the server just want a string ?? What should I use?
/Thanks in advance

Hi,
your question is not clear... you can convert the byte array to a string by calling toString method on the byte array.. since the server port and IP is known, try amking a socket and send a string and see what happens by opening a socket inputstream.. read from the stream to understand what the server does..
- Bibin.

Similar Messages

  • HTTPService problems while sending a String Variable to Server

    I have an xml in string form..... I want to send it as an http request to the server, which is written in .NET... server wud make its decession on the basis of this xml and wud return me another xml as http response..
    Problem ---->
    this request reaches server but when i look at the request reached at server it has my client infotmation but does not has my variable anywhere...... i iterate through all the parameters in Request.Params... but I don't find my string at all.... any idea why I can't find my sent variable ???
    Actionscript code to send xmlString to .NET Server using HTTPService:
    public function sendRequest(syncXmlString : String, httpResultHandler : Function) : void {
    try {
       var objectParam : Object = {name:PARAM_NAME, value:syncXmlString };
       var params : Object = [objectParam];
       var httpService : HTTPService = new HTTPService();
       httpService.url = serverUrl;
       httpService.method = HTTPRequestMessage.POST_METHOD;
       httpService.contentType =  HTTPService.CONTENT_TYPE_XML;
       httpService.resultFormat = HTTPService.RESULT_FORMAT_XML;
       httpService.addEventListener(ResultEvent.RESULT, httpResultHandler);
       httpService.addEventListener(FaultEvent.FAULT, httpFaultHandler);
       httpService.send(params);
    } catch (err : Error) {
       Alert.show(err.message);
    Thanks and Regards,
    Ahmed.

    No, that is the problem, the request object should not be an indexed array[], it should be an Object{}.  Remove that imtermediate array and pass objectParams in the send()
    Also, don't mess with the contentType without very good reason.
       httpService.contentType =  HTTPService.CONTENT_TYPE_XML;
    that says you are sending XML, but you are not, you are sending the default name=value pairs.  Remove that assignment and leave it at the default "form"
    One more, you do not want that resultFormat, it is the legacy AS2 class.  You want E4X
       httpService.resultFormat = RESULT_FORMAT_E4X;
    Tracy

  • Sending strings to a server..

    public class sendToServer implements ActionListener {
    public static void main(String args[]) {
    new sendToServer();
    public sendToServer() {
            JFrame mainFrame = new JFrame("Sending to server test..");
            mainFrame.setSize(new Dimension(300, 300);
            Container frameCon = mainFrame.getContentPane();
            JButton send = new JButton("Send");
            frameCon.add(send);
    public void actionPerformed(ActionEvent e) {
    JButton b = (JButton) e.getSource();
    if(b.getText().equals("Send")) {
    Socket socket = new Socket("localhost", 9412);
    OutputStream os = socket.getOutputStream();
    PrintWriter pw = new PrintWriter(os);
    pw.write("Yo");
    }Im trying to send a string to a server..any help?

    Read the "Custom Networking" tutorial:
    http://java.sun.com/docs/books/tutorial/

  • Send string to socket server from applet

    Am trying to send a string to socket server from my applet:
    Server:
    import java.io.*;
    import java.net.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    class Server extends JApplet
    ServerSocket srvr;
    Socket skt;
    PrintWriter out;
    BufferedReader in;
    Server()
    String data = "server";
    try
    srvr = new ServerSocket(5555);
    skt = srvr.accept();
    out = new PrintWriter(skt.getOutputStream(), true);
    in = new BufferedReader(new InputStreamReader(skt.getInputStream()));
    while (in.ready())
    System.out.println(in.readLine());
    out.print(data);
    out.close();
    in.close();
    skt.close();
    srvr.close();
    catch(Exception e)
    System.out.print(e);
    public static void main(String[] aslan)
    new Server();
    My applet where I have my client:
    Socket skt;
    BufferedReader in;
    PrintWriter out;
    try
    skt = new Socket("localhost", 5555);
    out = new PrintWriter(skt.getOutputStream(),true);
    in = new BufferedReader(new InputStreamReader(skt.getInputStream()));
    while (in.ready())
    System.out.println(in.readLine());
    in.close();
    catch(Exception e)
    System.out.print(e);
    public void actionPerformed( ActionEvent e )
    if(e.getSource() == button)
    out.println("test");
    But when the button is pushed the client is supposed to send the string "test" to the server but nothing happens can someone plz help me with this?

    Am trying to send a string to socket server from my
    applet:
    Server:
    import java.io.*;
    import java.net.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    class Server extends JApplet
    ServerSocket srvr;
    Socket skt;
    PrintWriter out;
    BufferedReader in;
    Server()
    String data = "server";
    try
    srvr = new ServerSocket(5555);
    skt = srvr.accept();
    out = new PrintWriter(skt.getOutputStream(), true);
    in = new BufferedReader(new
    InputStreamReader(skt.getInputStream()));
    while (in.ready())
    System.out.println(in.readLine());
    out.print(data);
    out.close();
    in.close();
    skt.close();
    srvr.close();
    catch(Exception e)
    System.out.print(e);
    public static void main(String[] aslan)
    new Server();
    My applet where I have my client:
    Socket skt;
    BufferedReader in;
    PrintWriter out;
    try
    skt = new Socket("localhost", 5555);
    out = new PrintWriter(skt.getOutputStream(),true);
    in = new BufferedReader(new
    InputStreamReader(skt.getInputStream()));
    while (in.ready())
    System.out.println(in.readLine());
    in.close();
    catch(Exception e)
    System.out.print(e);
    public void actionPerformed( ActionEvent e )
    if(e.getSource() == button)
    out.println("test");
    But when the button is pushed the client is supposed
    to send the string "test" to the server but nothing
    happens can someone plz help me with this? Your server code while (in.ready()) is going to block indefinitely.
    Remove the while loop and just write your ouput and close the connection on the server.

  • Sending more than one string from a server to a client in TCP/IP

    hi,
    i have two VIs where one is the server and the other the client in TCP/IP. I need to send more than 2 strings to the client at the same time.i have used the XML method but then by using XML i cant send any thing else to the client because of the byte sizes. so either i need a new way to send the strings or a new way to send more data. i have attached my VIs to this post if you need to take a look.
    thanks,
    Rambaldi.
    Attachments:
    ServerClient.zip ‏83 KB

    Well, after looking at the code it is very difficult to understand what you are trying to do. Not to be nasty or anything but your code is a mess. Did you know that in both VIs you have an infinite loop? The only way to exit your VIs is to use the Abort button. This is bad since it doesn't allow you to actually perform any type of cleanup. Your wiring is very difficult to follow. You should also avoid using local variables to pass data through your application. If you need to pass data between two parallel processes use queues, notifiers or an action engine. You can get rid of all of the sequence frames that you have. They aren't really doing anything for you and are unnecessary.
    As to your particular question I would have to assume that it is simply a result of bad coding that is preventing you from sending more than one string. You have logic in the second loop that appears to be impossible to get to since the conrol used to switch the case statement is placed on a hidden part of the front panel. Take a look at the TCP server example I posted in this thread. The example is on the second page of that thread.
    In order to help you I think you need to provide a good description of exactly what you want your server and client to do. You also need to do some code cleanup to make it readable and easier to follow.
    Mark Yedinak
    "Does anyone know where the love of God goes when the waves turn the minutes to hours?"
    Wreck of the Edmund Fitzgerald - Gordon Lightfoot

  • Once I send 1 string, the rest are cut off, any ideas?

    Hello everyone.
    For some reason when I send my first string through the socket, everything works fine. But after that Its cutting off the first 2 or 3 characters of the string and I have no idea why because I'm flushing the output buffer before and after I send the the string to the output buffer.
    note: complete code can be found here:
    http://cpp.sourceforge.net/?show=38132
    Am I not flushing right?
    Here's the code:
    public class MultiThreadServer implements Runnable {
    //csocket is whatever client is connecting to this server, in this case it will
    //be a telnet client sending strings to the server.
         Socket csocket;
      MultiThreadServer(Socket csocket) {
        this.csocket = csocket;
      public void run() {
           //setting up sockets
           Socket outputServ = null;
           //create a message database to store events
              MessageDB testDB = new MessageDB();
           try {
          //setting up channel to recieve events from the omnibus server
             BufferedReader in= new BufferedReader(
                        new InputStreamReader(
                        csocket.getInputStream()));
             PrintWriter out2
              = new PrintWriter(
              new OutputStreamWriter(
              csocket.getOutputStream()));
             //This socket will be used to communicate with the z/OS reciever
             //we will need a new socket each time because this is a multi-threaded
             //server thus, the  z/OS reciever (outputServ) will need to be
             //multi threaded to handle all the output.
             outputServ = new Socket("localhost",1234);
             if(outputServ.getLocalSocketAddress() == null)
                  System.out.println("OutputServer isn't running...");
             //Setting up channel to send data to outputserv
              PrintWriter out
                   = new PrintWriter(
                   new OutputStreamWriter(
                   outputServ.getOutputStream()));
         String input;
         //accepting events from omnibus server and storing them
         //in a string for later processing.
         while ((input = in.readLine()) != null)  
              //looking to see what telnet gets
              out2.println(input);
              out2.flush();
             //accepting and printing out events from omnibus server
             //also printing out connected client information
              System.out.flush();     
              System.out.println("Event from: " + csocket.getInetAddress().getHostName()
                            +"-> "+ input +"\n");
             System.out.flush();
                  //sending events to output server
              out.flush();
                  out.println(input);
                  out.flush();
                  //close the connection if the client drops
                  if(in.read() == -1)
                       System.out.println("Connection closed by client.");
                       break;
        //cleaning up
          in.close();
          out.close();
          outputServ.close();
          csocket.close();
           catch (SocketException e )
                System.err.println ("Socket error: " + e);
           catch(UnknownHostException e)
                System.out.println("Unknown host: " + e);
              catch (IOException e)
               System.out.println("IOException: " + e);
    }Here's some example output I'm getting from the telnet screen which is (out2) stream:
    This is a test
    This is another test
    his is another test
    This is yet another test
    his is yet another test
    This is a test worked fine, as you can see, it outputed This is a test when I typed it in.
    The next string "This is another test" fails, as you can see its echoing out:
    his is another test
    I'm also printing out the contents to the console, and i'm getting out the same thing:
    Enter port to run server on:
    3333
    Listening on : ServerSocket[addr=0.0.0.0/0.0.0.0,port=0,localport=3333]
    Waiting for client connection...
    Socket[addr=/127.0.0.1,port=2184,localport=3333] connected.
    hostname: localhost
    Ip address: 127.0.0.1:3333
    Event from: localhost-> This is a test
    Event from: localhost-> his is another test
    Event from: localhost-> his is yet another test
    Connection closed by client.
    ANy help would be great!
    Message was edited by:
    lokie

    I posted more compact code so its easier to see and understand: The run() function is where the problem is occurring.
    //SAMPLE OUTPUT FROM CONSOLE
    Enter port to run server on:
    3333
    Listening on : ServerSocket[addr=0.0.0.0/0.0.0.0,port=0,localport=3333]
    Waiting for client connection...
    Socket[addr=/127.0.0.1,port=2750,localport=3333] connected.
    hostname: localhost
    Ip address: 127.0.0.1:3333
    Event from: localhost-> This is a test
    Event from: localhost-> his is a test
    Event from: localhost-> his is a test
    Connection closed by client.
    //------END OF SAMPLE OUTPUT-----//
    //---THis class is called everytime a new thread is created,
    //only 1 thread is created because only 1 client is connecting to the
    //server
    package server;
    //parser server
    import java.io.IOException.*;
    import java.io.*;
    import java.net.*;
    import java.util.Scanner;
    public class MultiThreadServer implements Runnable {
         Socket csocket;
    MultiThreadServer(Socket csocket) {
      this.csocket = csocket;
    public void run() {
           try {
        //setting up channel to recieve events from the omnibus server
           BufferedReader in= new BufferedReader(new InputStreamReader(csocket.getInputStream()));
         String input;
         //accepting events from omnibus server and storing them
         //in a string for later processing.
         while ((input = in.readLine()) != null)  
           //accepting and printing out events from omnibus server
           //also printing out connected client information
              System.out.println("Event from: " + csocket.getInetAddress().getHostName()
                          +"-> "+ input +"\n");
              System.out.flush();     
                //close the connection if the client drops
                if(in.read() == -1)
                     System.out.println("Connection closed by client.");
                     break;
      //cleaning up
        in.close();
        csocket.close();
           catch (SocketException e )
                System.err.println ("Socket error: " + e);
           catch(UnknownHostException e)
                System.out.println("Unknown host: " + e);
              catch (IOException e)
               System.out.println("IOException: " + e);
    //This is the main function, the only thing it does is
    //create a new thread on each connection.
    package server;
    //This is the parser Client that will parse messages and send to the
    //z/Os output Server
    import java.io.*;
    import java.net.*;
    public class MainTest
           public static void main(String args[]) throws Exception
                //get console input
                BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));  
                System.out.println("Enter port to run server on: ");
                String input = stdin.readLine();
                int servPort = Integer.parseInt(input);
                //setting up sockets
                ServerSocket ssock = null;
                Socket sock = null;
                try
                //setting up server to run on servPort
               ssock = new ServerSocket(servPort);
                System.out.println("Listening on : " + ssock);
                System.out.println("Waiting for client connection...");
                  while (true) {
                    //waiting for client to connect to server socket
                    sock = ssock.accept();
                    System.out.println(sock + " connected.");
                    //get host information
                    InetAddress clientIa = sock.getInetAddress( );
                    String clientName = clientIa.getHostName();
                    String clientIp = clientIa.getHostAddress();
                    int localPort = sock.getLocalPort();
                    System.out.println("hostname: "+clientName  +
                              '\n' + "Ip address: " + clientIp
                              +":"+ localPort + "\n\n");
                    new Thread(new MultiThreadServer(sock)).start();
                catch (SocketException e )
                     System.out.println ("Socket error: " + e);
                catch(UnknownHostException e)
                     System.out.println("Unknown host: " + e);
                   catch (IOException e)
                    System.out.println("IOException: " + e);
    }

  • HTTP transport error: javax.xml.soap.SOAPException: java.security.PrivilegedActionException: javax.xml.soap.SOAPException: Message send failed: String index out of range: -7

    All -
    I'm new to consuming web services in JDeveloper. I'm using Oracle JDEV 10.1.3.3/OC4J.  I'm using this version since it is compatible with Oracle EBS 12.1.3.  My intent is to pull data from our third party recruitment app (Success Factors) and load that data into Oracle HRIS.  I'm already doing this through a .NET application.  I'm converting it to be a Java Concurrent Program in EBS.  The code listed below is a stub call to verify I'm on the right track. I created a JDeveloper Web Services proxy project.  I'm testing it locally on my windows desktop.  When I'm able to consume the service successfully, then I'll think about moving it to the EBS server.
    I'm getting the following error when I invoke the following service:
    HTTP transport error: javax.xml.soap.SOAPException: java.security.PrivilegedActionException: javax.xml.soap.SOAPException: Message send failed: String index out of range: -7
    End point is: https://api4.successfactors.com/sfapi/v1/soap?wsdl
    Any help/assistance would be much appreciated. 
    Below is my code and output of my test:
    package emsc.oracle.apps.emscper.sfapi.proxy;
    import HTTPClient.HTTPConnection;
    import emsc.oracle.apps.emscper.sfapi.proxy.types.sfobject_sfapi_successfactors_com.IsValidSession;
    import emsc.oracle.apps.emscper.sfapi.proxy.types.sfobject_sfapi_successfactors_com.IsValidSessionResponse;
    import emsc.oracle.apps.emscper.sfapi.proxy.types.sfobject_sfapi_successfactors_com.Login;
    import emsc.oracle.apps.emscper.sfapi.proxy.types.sfobject_sfapi_successfactors_com.LoginResponse;
    import emsc.oracle.apps.emscper.sfapi.proxy.types.sfobject_sfapi_successfactors_com.LoginResult;
    import emsc.oracle.apps.emscper.sfapi.proxy.types.sfobject_sfapi_successfactors_com.Logout;
    import emsc.oracle.apps.emscper.sfapi.proxy.types.sfobject_sfapi_successfactors_com.LogoutResponse;
    import emsc.oracle.apps.emscper.sfapi.proxy.types.sfobject_sfapi_successfactors_com.SFCredential;
    import emsc.oracle.apps.emscper.sfapi.proxy.types.sfobject_sfapi_successfactors_com.SFParameter;
    import emsc.oracle.apps.emscper.sfapi.proxy.types.sfobject_sfapi_successfactors_com.Error;
    import java.io.File;
    import javax.xml.rpc.ServiceFactory;
    import java.util.ArrayList;
    import java.util.List;
    import java.util.Date;
    import javax.xml.ws.BindingProvider;
    import javax.xml.soap.SOAPException;
    import java.util.Map;
    import oracle.security.ssl.OracleSSLCredential;
    public class SFAPITest {
        // Declare members:      
        private String companyId;
        private String userName;
        private String password;
        private String developerKey;
        private Date   effDt;
        private String greaterThanEffDt;
        private String lessThanEffDt;
        // Declare constants:      
        final static private String breakLine = "+---------------------------------------------------------------------------+";
        final static private String format    = "yyyy-mm-dd";      
        private enum ReqId {
            PrimaryReq(25),
            PrimaryReqCEO(26),
            EmCarePrimary(27),
            RTI(28),
            EmCareClinical(29);
            private int reqId; 
            private ReqId() {
            private ReqId(int value) {
                reqId = value;
            public int getReqId() {
                return reqId;
        // Getters and Setters:  
        protected String getCompanyId() {
           return this.companyId;
        protected void setCompanyId(String value) {
           this.companyId = value;                 
        protected String getUserName() {
           return this.userName;
        protected void setUserName(String value) {
           this.userName = value;                 
        protected String getPassword() {
           return this.password;
        protected void setPassword(String value) {
           this.password = value;                 
        protected String getDeveloperKey() {
           return this.developerKey;
        protected void setDeveloperKey(String value) {
           this.developerKey = value;                 
        protected Date getEffDt() {
            return this.effDt;
        protected void setEffDt(Date value) {
            this.effDt = value;                 
        protected String getGreaterThanEffDt() {
           return this.greaterThanEffDt;
        protected void setGreaterThanEffDt(String value) {
           this.greaterThanEffDt = value;                 
        protected String getLessThanEffDt() {
           return this.lessThanEffDt;
        protected void setLessThanEffDt(String value) {
           this.lessThanEffDt = value;                 
        public void runProgram()
            SFAPIService mySFAPIService;
            String CompletionText = "";
            String effDtStr2 = null;
        /* Code your program logic here.
        * Use getJDBCConnection method to get the connection object for any
        * JDBC operations.
        * Use CpContext provided commit,rollback methods to commit/rollback
        * data base transactions.
        * Don't forget to release the connection before returning from this
        * method.
        /* Call setCompletion method to set the request completion status and
        * completion text.
        * Status values are ReqCompletion.NORMAL,ReqCompletion.WARNING,
        * ReqCompletion.ERROR.
        * Use Completion text message of length 240 characters. If it is more
        * than 240 then full string will appear in log file and truncated 240
        * characters will be used as request completion text.
        try
            ServiceFactory factory = ServiceFactory.newInstance();
            mySFAPIService = (emsc.oracle.apps.emscper.sfapi.proxy.SFAPIService)factory.loadService(emsc.oracle.apps.emscper.sfapi.proxy.SFAPIService.class);      
            SFAPI api = mySFAPIService.getSFAPI();
           /// SFAPI api = new SFAPI();
            //Map<String, Object> requestContext = ((BindingProvider) api).getRequestContext();
            //requestContext.put(BindingProvider.SESSION_MAINTAIN_PROPERTY, true);
            System.out.println("ServiceName => " + mySFAPIService.getServiceName().toString());
            System.out.println("End Point   => " + mySFAPIService.getServiceName().toString());
            System.out.println(breakLine);
            // Authentication: Login to SFAPI:
            SFCredential credential = new SFCredential();
            // Fake credentials being passed in for this post:   
            credential.setCompanyId("XXX");
            credential.setUsername("XXX");
            credential.setPassword("XXX");
            credential.setDeveloperKey("XXX");
            HTTPConnection httpsConnection = null;       
            OracleSSLCredential _credential = new OracleSSLCredential();      
            _credential.setWallet("\\\\\\C:\\Program Files\\Java\\jdk1.6.0_33\\jre\\lib\\security", "ParkEstes3");
            /*System.setProperty("javax.net.ssl.trustStore","C:\\\\\OraHome_1\\jdev\\jdevbin\\jdk\\jre\\lib\\security\\keystore");
            System.setProperty("javax.net.ssl.trustStorePassword","changeit");  
            System.out.println(System.getProperty("javax.net.ssl.trustStore"));*/
            // SFParameter: Define a generic SFParameter List.  This is a necessary parameter
            // to invoking calls in SFAPI:      
             /*System.setProperty("javax.net.ssl.keyStore",
             "file:\\\C:\\jdk1.4.1\\jre\\lib\\security\\client.keystore");
             System.setProperty("javax.net.ssl.keyStorePassword","welcome");         */
            /*  System.setProperty("oracle.net.wallet_location",
                          "(SOURCE=(METHOD=file)(METHOD_DATA=(DIRECTORY=\\\C:\Users\dparrish\Oracle\WALLETS)))");  // (2)                     */
            File kstore = new File("C:\\OraHome_1\\jdev\\jdevbin\\jdk\\jre\\lib\\security\\jssecacerts");
            boolean exists = kstore.exists();
            if (!exists) {
                System.out.println("Keystore does not exist");
            else {
                System.out.println("Keystore does exist");
            System.setProperty("javax.net.ssl.trustStore", kstore.getAbsolutePath());
            System.setProperty("javax.net.ssl.trustStorePassword", "changeit");
            //System.setProperty("proxySet", "false");
            //System.setProperty("http.proxyHost", "127.0.0.1");
            //System.setProperty("http.proxyPort", "8080");
            System.out.println(kstore.getAbsolutePath());
            List<SFParameter> lst = new ArrayList<SFParameter>();
            SFParameter param = new SFParameter();
            param.setName("");
            param.setValue("");
            lst.add(param);      
            SFParameter[] sfParam = lst.toArray(new SFParameter[lst.size()]);
            Login login = new Login();
            try {
                login.setCredential(credential);
                System.out.println("1");
                login.setParam(sfParam);
                System.out.println("2");
                LoginResponse loginResponse = new  LoginResponse();
                LoginResult loginResult = new LoginResult();
                try {
                     loginResponse = api.login(login);               
                catch (Exception e ) {
                    System.out.println(e.getMessage());
                System.out.println("3");
                try {               
                     loginResult = loginResponse.getResult();
                catch (Exception e ) {
                    System.out.println(e.getMessage());
                System.out.println("4");
                IsValidSession vs = new IsValidSession();                  
                IsValidSessionResponse isValidSessionResponse = api.isValidSession(vs);
                System.out.println("5");
                if (isValidSessionResponse.isResult()) {
                     System.out.println("Session is valid");
                     System.out.println("Result => " + loginResult.getSessionId());
                     System.out.println(breakLine);              
                    Logout logout = new Logout();
                    LogoutResponse logoutResponse = api.logout(logout);
                    if (logoutResponse.isResult()) {
                         System.out.println("Logout of SFAPI Successful");
                    else {
                        System.out.println("Logout of SFAPI Unsuccessful");
                else {
                     System.out.println("Session is invalid");
                    List<Error> errors = new ArrayList<Error>();
                    for (int i = 0; i < loginResult.getError().length;  i++) {
                        errors.add(loginResult.getError()[i]);
                    for (int i = 0; i < errors.size(); i++) {
                         System.out.println("Error Indice   => " + i);
                         System.out.println("Error Code:    => " + errors.get(i).getErrorCode());
                         System.out.println("Error Message: => " + errors.get(i).getErrorMessage());
                         System.out.println(breakLine);                                                          
                    } // end for loop of SFObject errors
                } // end InvalidSession
            catch (Exception e)
                 System.out.println("Session Credential Exception");
                 System.out.println("Exception => " + e.getMessage());
                 System.out.println(breakLine);                   
        catch (Exception e)
            System.out.println("Parameter List Exception");
            System.out.println("Exception => " + e.getMessage());
            System.out.println(breakLine);
        }   // end runProgram
        // Constructor:
        public SFAPITest()  {
        } // end constructor
        public static void main (String args[]) {
            try
                SFAPITest test = new SFAPITest();        
                test.runProgram();
            catch (Exception e) {
                System.out.println("main exception => " + e.getMessage());
    } // SFAPITest
    Here is the output with trace:
    WARNING: Unable to connect to URL: https://api4.successfactors.com:443/sfapi/v1/soap due to java.security.PrivilegedActionException: javax.xml.soap.SOAPException: Message send failed: String index out of range: -7
    Session Credential Exception
    Exception => ; nested exception is:
        HTTP transport error: javax.xml.soap.SOAPException: java.security.PrivilegedActionException: javax.xml.soap.SOAPException: Message send failed: String index out of range: -7
    +---------------------------------------------------------------------------+
    Process exited with exit code 0.

    The other end is throwing back a programming error.
    That might be because you are sending incorrect data and the other end fails to validate it.
    You might be able to guess based on your C# code.  But, since you are using soap one generic solution is available to you.
    - Get an http proxy interceptor like wireshark.
    - Run it while your C# app runs, collect the http requests from that.
    - Run it while running your java code, collect the http requests from that.
    Compare the two.

  • When to send JOIN channel to IRC server?urgent..

    i have a problem regarding sending information to IRC server. I want to send the join message to server. But i can only do so after server has finished sending information to me. may i know the correct coding ? i have tried to send it after the while loop but within the try {} it still wouldnt send. when i tried to send it earlier by placing the code above the while loop, the server will display error requesting me to register first.
    Below are the codings... Thanks in advance
    import java.io.*; //---These two are needed for socket support---
    import java.net.*;
    public class IRCConnect
    public static void main(String args[])
    try
    char response;
    Socket s = new Socket("singapore.sg.galaxynet.org", 7000);
    BufferedReader in = new BufferedReader(new InputStreamReader(s.getInputStream()));
    PrintWriter out = new PrintWriter(s.getOutputStream(), true); //---Set up an output stream---
    out.println( "USER" + " " + "Testbot" + " " + "an13810.ath.cx" + " " + "singapore.sg.galaxynet.org" + " " + ":" + "Test bot" );
    out.println( "NICK" + " " + "testWLbot");
    String line;
         do //to join channel...
         out.println( "JOIN" + " " + "#" + "ReXT6ux" );
         out.println ( "PRIVMSG" + " " + "#" + "ReXT6ux" + " " + ":" + "Welcome to #ReXT6ux" );     }
         while((line = in.readLine()) == null); //to wait for server to finish sending data to client.
    while((line = in.readLine()) != null)
         System.out.println(line);      //---Displaying status.---
         if(line.substring(0,4).equalsIgnoreCase("ping"))      //---To prevent from disconnect.---
         String pongmsg = "pong " + line.substring(5);
         //System.out.println(pongmsg);
         out.println(pongmsg);
         System.out.println("ping pong");
         }//---End if---
    } //---End Try---
    catch(IOException e)
    e.printStackTrace();
    } //---End Catch---
    }

    i had a similiar problem, i believe the solution was to wait after sending the "NICK" or "USER" commands to receive some sort of response (could be PING) look at the RFC (www.rfc-editor.org) and if you don't find it there i can post the code i used but its long and messy.
    but i think your problem is you need to respond to a ping (or some other command) after trying to authorize.

  • RE: Sending jpg bytes over a server

    I had another topic but it has not been answered for a couple days so I guess I will clarify my problem more.
    I'm sending my image over a server, Client->Server->Client.
    My sending and receiving works but I get the image and it cannot be displayed.
    Sending
    try{
                  FileInputStream fis = new FileInputStream("picture.jpg");
                  byte[] buffer = new byte[fis.available()];
                  fis.read(buffer);
                  return buffer;
             }catch(Exception e){
                  System.out.println("Loading Image error");
             }Receiving
             try{
                  FileOutputStream fos = new FileOutputStream("received.jpg");
                  fos.write(image);
                  ImageIcon display = new ImageIcon("received.jpg");
                  clientDisplayPicture=new JLabel(display);
             }catch(Exception h){
                  System.out.println("Problem receiving");
             }Am I packaging it wrong? The received image is 0bytes. Thanks in advance!

    Here you are ignoring the result of the read() method.Meaning?
    Here you are not telling us how the incoming data got into 'image'.I put the bytes of the image into an object and passed it over the network.
        public void displayPicture(String from, byte[] image, boolean a, boolean b){
             try{
                  FileOutputStream fos = new FileOutputStream("received.jpg");
                  fos.write(image);
                  fos.close();
             }catch(Exception h){
                  System.out.println("Problem receiving");
        public byte[] getImage(){
             try{
                  FileInputStream fis = new FileInputStream("picture.jpg");
                  File f = new File("picture.jpg");
                  int bsize = 1375;
                  byte[] buffer = new byte[bsize];
                  fis.read(buffer);
                  fis.close();
                  return buffer;
             }catch(Exception e){
                  System.out.println("Loading Image error");
             return null;
        }EDIT: Thanks, got it working, the above worked. THANKS!
    Edited by: Krytical on Aug 10, 2008 12:09 AM

  • How to send data back to the server

    i create a program to send data back to ther server using j2me.
    its work well on emulator but when i install the application on sony ericsssin p910i or k700i or nokia 7710 then its not working and simply hang.
    here is sample code which is run well on emulator but not on mobile.
    what is the problem in that or how can this code run in mobile is there any mobile specific setting or internet setting.
    Pls reply asap.
    import java.io.*;
    import javax.microedition.io.*;
    import javax.microedition.lcdui.*;
    import javax.microedition.midlet.*;
    * An example MIDlet to invoke a CGI script.
    public class ThirdExample extends MIDlet {
    private Display display;
    // String url = "http://www.javacourses.com/cgi-bin/getgrade.cgi?idnum=182016";
    String url = "http://sampler.infopro.stpn.soft.net/midletdata.asp?name=name";
    public ThirdExample() {
    display = Display.getDisplay(this);
    * Initialization. Invoked when we activate the MIDlet.
    public void startApp() {
    try {
    getGrade(url);
    } catch (IOException e) {
    System.out.println("IOException " + e);
    e.printStackTrace();
    * Pause, discontinue ....
    public void pauseApp() {
    * Destroy must cleanup everything.
    public void destroyApp(boolean unconditional) {
    * Retrieve a grade....
    void getGrade(String url) throws IOException {
    HttpConnection c = null;
    InputStream is = null;
    OutputStream os = null;
    StringBuffer b = new StringBuffer();
    TextBox t = null;
    int x = 5, y =7;
    try {
    c = (HttpConnection)Connector.open(url);
    c.setRequestMethod(HttpConnection.GET);
    c.setRequestProperty("IF-Modified-Since", "10 Nov 2000 17:29:12 GMT");
    c.setRequestProperty("User-Agent","Profile/MIDP-1.0 Confirguration/CLDC-1.0");
    c.setRequestProperty("Content-Language", "en-CA");
    os = c.openOutputStream();
    String str = "?idnum=182016";
    byte postmsg[] = str.getBytes();
    for(int i=0;i<postmsg.length;i++) {
    os.writeByte(postmsg);
    os.flush();
    is = c.openDataInputStream();
    int ch;
    while ((ch = is.read()) != -1) {
    b.append((char) ch);
    System.out.println((char)ch);
    t = new TextBox("Final Grades", b.toString(), 1024, 0);
    } finally {
    if(is!= null) {
    is.close();
    if(os != null) {
    os.close();
    if(c != null) {
    c.close();
    display.setCurrent(t);
    }>

    i create a program to send data back to ther server using j2me.
    its work well on emulator but when i install the application on sony ericsssin p910i or k700i or nokia 7710 then its not working and simply hang.
    here is sample code which is run well on emulator but not on mobile.
    what is the problem in that or how can this code run in mobile is there any mobile specific setting or internet setting.
    Pls reply asap.
    import java.io.*;
    import javax.microedition.io.*;
    import javax.microedition.lcdui.*;
    import javax.microedition.midlet.*;
    * An example MIDlet to invoke a CGI script.
    public class ThirdExample extends MIDlet {
    private Display display;
    // String url = "http://www.javacourses.com/cgi-bin/getgrade.cgi?idnum=182016";
    String url = "http://sampler.infopro.stpn.soft.net/midletdata.asp?name=name";
    public ThirdExample() {
    display = Display.getDisplay(this);
    * Initialization. Invoked when we activate the MIDlet.
    public void startApp() {
    try {
    getGrade(url);
    } catch (IOException e) {
    System.out.println("IOException " + e);
    e.printStackTrace();
    * Pause, discontinue ....
    public void pauseApp() {
    * Destroy must cleanup everything.
    public void destroyApp(boolean unconditional) {
    * Retrieve a grade....
    void getGrade(String url) throws IOException {
    HttpConnection c = null;
    InputStream is = null;
    OutputStream os = null;
    StringBuffer b = new StringBuffer();
    TextBox t = null;
    int x = 5, y =7;
    try {
    c = (HttpConnection)Connector.open(url);
    c.setRequestMethod(HttpConnection.GET);
    c.setRequestProperty("IF-Modified-Since", "10 Nov 2000 17:29:12 GMT");
    c.setRequestProperty("User-Agent","Profile/MIDP-1.0 Confirguration/CLDC-1.0");
    c.setRequestProperty("Content-Language", "en-CA");
    os = c.openOutputStream();
    String str = "?idnum=182016";
    byte postmsg[] = str.getBytes();
    for(int i=0;i<postmsg.length;i++) {
    os.writeByte(postmsg);
    os.flush();
    is = c.openDataInputStream();
    int ch;
    while ((ch = is.read()) != -1) {
    b.append((char) ch);
    System.out.println((char)ch);
    t = new TextBox("Final Grades", b.toString(), 1024, 0);
    } finally {
    if(is!= null) {
    is.close();
    if(os != null) {
    os.close();
    if(c != null) {
    c.close();
    display.setCurrent(t);
    }>

  • Send Data back to the Server

    Hi.
    how to send data back to the server using J2ME or how to communicate with server using J2ME

    i am using http its work well on emulator but when i install the application on sony ericsssin p910i or k700i or nokia 7710 then its not working and simply hang.
    here is sample code which is run well on emulator but not on mobile.
    what is the problem in that or how can this code run in mobile is there any mobile specific setting or internet setting.
    Pls reply asap.
    import java.io.*;
    import javax.microedition.io.*;
    import javax.microedition.lcdui.*;
    import javax.microedition.midlet.*;
    * An example MIDlet to invoke a CGI script.
    public class ThirdExample extends MIDlet {
    private Display display;
    // String url = "http://www.javacourses.com/cgi-bin/getgrade.cgi?idnum=182016";
    String url = "http://sampler.infopro.stpn.soft.net/midletdata.asp?name=name";
    public ThirdExample() {
    display = Display.getDisplay(this);
    * Initialization. Invoked when we activate the MIDlet.
    public void startApp() {
         try {
    getGrade(url);
         } catch (IOException e) {
         System.out.println("IOException " + e);
         e.printStackTrace();
    * Pause, discontinue ....
    public void pauseApp() {
    * Destroy must cleanup everything.
    public void destroyApp(boolean unconditional) {
    * Retrieve a grade....
    void getGrade(String url) throws IOException {
    HttpConnection c = null;
    InputStream is = null;
    OutputStream os = null;
    StringBuffer b = new StringBuffer();
    TextBox t = null;
    int x = 5, y =7;
    try {
    c = (HttpConnection)Connector.open(url);
    c.setRequestMethod(HttpConnection.GET);
    c.setRequestProperty("IF-Modified-Since", "10 Nov 2000 17:29:12 GMT");
    c.setRequestProperty("User-Agent","Profile/MIDP-1.0 Confirguration/CLDC-1.0");
    c.setRequestProperty("Content-Language", "en-CA");
    os = c.openOutputStream();
    String str = "?idnum=182016";
    byte postmsg[] = str.getBytes();
    for(int i=0;i<postmsg.length;i++) {
    os.writeByte(postmsg);
    os.flush();
    is = c.openDataInputStream();
    int ch;
    while ((ch = is.read()) != -1) {
    b.append((char) ch);
    System.out.println((char)ch);
    t = new TextBox("Final Grades", b.toString(), 1024, 0);
    } finally {
    if(is!= null) {
    is.close();
    if(os != null) {
    os.close();
    if(c != null) {
    c.close();
    display.setCurrent(t);

  • Send multiple strings over TCP - Like messenger service

    Hello all Java Coders,
    I'm new with TCP programming.
    I'm beggining to learn about TCP and sockets connections in Java. In order to achieve this, I was coding a mini-program so I can learn a little bit about this.
    I'm trying to make a simple TCP program.
    The server sends a string to a client...
    I already searched for a couple of hours in google and so on, about what I'm doing wrong.
    [The server code (Just click)|http://pastebin.com/m39fd1273]
    [The client code (Just click)|http://pastebin.com/m57471803]
    I hope that someone can help me with this and, if you have patience, please tell me the reasons my code doesn't work.
    Many thanks,
    Freiheitpt
    P.S.: I think that the problem is on the server side...

    Sorry jverd.
    I was just trying to put things organized.
    Well, I can't get the String to be sent to the client.
    No error occurs.
    Server:
           try {
                srvr = new ServerSocket(1234);
                System.out.println("Connecting...");
                skt = srvr.accept();
                System.out.println("Connected!\nPreparing data exchange...");
                stream = skt.getOutputStream();
                out = new PrintWriter(stream, true);
                System.out.println("Done!\nReady to Send!");
            } catch (IOException ex) {
                System.out.println("Ups, didn't work!");
                System.exit(1);
            while(!data.equalsIgnoreCase("end")) {
                System.out.print("String to send: ");
                data = input.nextLine();
                System.out.print("Sending string: '" + data + "'\n");
                out.print(data);
            }Client:
            try {
                skt = new Socket("localhost", 1234);
                System.out.println("Connecting...");
                if (skt.isConnected()) {
                    System.out.println("Connected!\nPreparing data exchange...");
                    stream = skt.getInputStream();
                    inputStream = new InputStreamReader(stream);
                    in = new BufferedReader(inputStream);
                    System.out.println("Done!\nReady to Receive!");
                } else {
                    System.out.println("Server not available!\nExiting...");
                    skt.close();
                    System.exit(1);
            } catch (IOException ex) {
                System.out.println("Ups, didn't work!");
                System.exit(1);
            while (!data.equalsIgnoreCase("end")) {
                while(!in.ready()) {}
                data = in.readLine();
                System.out.println("Received String: '" + data + "'");
            }

  • Advisor connector failed to send analysis data to management server

    We are using the online advisory server on the servers we can, we continue to get the following on multiple servers - "Advisor connector failed to send analysis data to management server" 
    Event Description: Failed to upload CAB to management server.
    at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
       at System.IO.File.Delete(String path)
       at Microsoft.SystemCenter.Advisor.Internal.ProbeAction.CabProbeAction.UploadOneCab()
    Seems to be mostly servers with cluster resources
    Does anyone have any information that would lead us to resolve this?
    Thanks in advanced

    I'm also seeing the same problem - as below
    Alert: Advisor connector failed to send analysis data to management server
    Source: servername.domain.com
    Path: servername.domain.com
    Last modified by: System
    Last modified time: 6/29/2014 12:50:00 PM Alert description: Event Description: Failed to upload CAB to management server.
    Reason: System.UnauthorizedAccessException: Access to the path 'C:\Program Files\Microsoft Monitoring Agent\Agent\Advisor\AgentData\AdvisorMonitorV2\Mailbox\Outbox\20140629-114047342.cab' is denied.
       at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
       at System.IO.File.InternalDelete(String path, Boolean checkHost)
       at Microsoft.SystemCenter.Advisor.Internal.ProbeAction.CabProbeAction.UploadOneCab()
    Any ideas...
    Yusuf

  • Urgent!!!! Problem in sending mail through yahoo mail server

    Hi
    I have a yahoo account and I want to send email through yahoo mail server
    using my java program. My program supports SMTP server authentication.
    But when I connect to the yahoo mail server(smtp.mail.yahoo.com) I got this error
    javax.mail.MessagingException: 521 yahoo.com closing transmission channel. You
    must be pop-authenticated before you can use this smtp server, and you must use
    your yahoo mail address for the Sender/From field.
    This is my program
    import javax.mail.*;
    import java.util.*;
    import javax.mail.internet.*;
    import javax.mail.event.*;
    import java.io.*;
    public class JavaMailUserAgent
         Properties properties;
         Session session;
         Message message;
         JavaMailUserAgent(String mailHost,String smtpUsername,String smtpPassword) throws Exception
              properties=new Properties();
              properties.put("mail.smtp.host",mailHost);
              ServerAuthenticate auth=new ServerAuthenticate(smtpUsername,smtpPassword);
              session=Session.getInstance(properties,auth);
              message=new MimeMessage(session);
         } //**********************************************************************end constructor
         void sendMail(String messageFrom,String messageTo,String subject,String messageBody) throws Exception
              properties.put("mail.from",messageFrom);
              InternetAddress[] address={ new InternetAddress(messageTo) };
              message.setFrom(new InternetAddress(messageFrom));
              message.setRecipients(Message.RecipientType.TO,address);
              message.setSubject(subject);
              message.setContent(messageBody,"text/plain");
              Transport transport=session.getTransport(address[0]);
              transport.addConnectionListener(new ConnectionHandler());
              transport.addTransportListener(new TransportHandler());
              transport.connect();
              transport.sendMessage(message,address);
         } //*************************************************************************end function
    } //*************************************************************************************end main
    class ConnectionHandler extends ConnectionAdapter
         public void opened(ConnectionEvent e)
              System.out.println("connection opened");
         public void disconnected(ConnectionEvent e)
              System.out.println("connection disconnected");
         public void closed(ConnectionEvent e)
              System.out.println("connection closed");
    } //*************************************************************************************end main
    class TransportHandler extends TransportAdapter
         public void messageDelivered(TransportAdapter e)
              System.out.println("message delivered");
         public void messageNotDelivered(TransportAdapter e)
              System.out.println("message NOT delivered");
         public void messagePartiallyDelivered(TransportAdapter e)
              System.out.println("message partially delivered");
    } //*************************************************************************************end main
    class ServerAuthenticate extends Authenticator
         String smtpUsername = null;
         String smtpPassword = null;
         public ServerAuthenticate(String username, String password)
              smtpUsername = username;
              smtpPassword = password;
         protected PasswordAuthentication getPasswordAuthentication()
              return new PasswordAuthentication(smtpUsername,smtpPassword);
    } //*************************************************************************************end main
    I use this code to call the program.
    JavaMailUserAgent jmail=new JavaMailUserAgent("smtp.mail.yahoo.com","my_yahoo_username","my_yahoo_password");
    jmail.sendMail("[email protected]","[email protected]","test subject","test message");
    Could you pls tell me why do I get this error eventhough My program has server authentication.
    Is this my program error.Please Helpl me what to do to correct this problem.
    Please include a sample code
    thanks for listening
    sabu

    I have used the code below to send mail from yahoo account,but I got the error message like below,what I should configure in pop3 of yahoo account????
    import javax.mail.*;
    import java.util.*;
    import javax.mail.internet.*;
    import javax.mail.event.*;
    import java.io.*;
    public class JavaMailUserAgent
    Properties properties;
    Session session;
    Message message;
    JavaMailUserAgent(String mailHost,String smtpUsername,String smtpPassword) throws Exception
    properties=new Properties();
    properties.put("mail.smtp.host",mailHost);
    ServerAuthenticate auth=new ServerAuthenticate(smtpUsername,smtpPassword);
    session=Session.getInstance(properties,auth);
    message=new MimeMessage(session);
    //**********************************************************************end constructor
    void sendMail(String messageFrom,String messageTo,String subject,String messageBody) throws Exception
    properties.put("mail.from",messageFrom);
    InternetAddress[] address={ new InternetAddress(messageTo) };
    message.setFrom(new InternetAddress(messageFrom));
    message.setRecipients(Message.RecipientType.TO,address);
    message.setSubject(subject);
    message.setContent(messageBody,"text/plain");
    Transport transport=session.getTransport(address[0]);
    transport.addConnectionListener(new ConnectionHandler());
    transport.addTransportListener(new TransportHandler());
    transport.connect();
    transport.sendMessage(message,address);
    } //*************************************************************************end function
    } //*************************************************************************************end main
    class ConnectionHandler extends ConnectionAdapter
    public void opened(ConnectionEvent e)
    System.out.println("connection opened");
    public void disconnected(ConnectionEvent e)
    System.out.println("connection disconnected");
    public void closed(ConnectionEvent e)
    System.out.println("connection closed");
    } //*************************************************************************************end main
    class TransportHandler extends TransportAdapter
    public void messageDelivered(TransportAdapter e)
    System.out.println("message delivered");
    public void messageNotDelivered(TransportAdapter e)
    System.out.println("message NOT delivered");
    public void messagePartiallyDelivered(TransportAdapter e)
    System.out.println("message partially delivered");
    } //*************************************************************************************end main
    class ServerAuthenticate extends Authenticator
    String smtpUsername = null;
    String smtpPassword = null;
    public ServerAuthenticate(String username, String password)
    smtpUsername = username;
    smtpPassword = password;
    protected PasswordAuthentication getPasswordAuthentication()
    return new PasswordAuthentication(smtpUsername,smtpPassword);
    public static void main(String str[])throws Exception
    JavaMailUserAgent jmail=new
    JavaMailUserAgent("smtp.mail.yahoo.com","[email protected]","passwordd");
    jmail.sendMail("[email protected]","[email protected]","test subject","test message");
    ERROR:
    E:\mail\javamail\servlet>java ServerAuthenticate
    connection opened
    Exception in thread "main" javax.mail.MessagingException: 530 authentication req
    uired - for help go to http://help.yahoo.com/help/us/mail/pop/pop-11.html
    at com.sun.mail.smtp.SMTPTransport.issueCommand(SMTPTransport.java:879)
    at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:599)
    at com.sun.mail.smtp.SMTPTransport.sendMessage(Compiled Code)
    at JavaMailUserAgent.sendMail(JavaMailUserAgent.java:58)
    at ServerAuthenticate.main(JavaMailUserAgent.java:131)
    How Could I rectyfy the above error ?????
    Regards,
    Mahesh.

  • F5 Big IP 4000 Send /Return String for Exchange 2013

    Hi,
    I need to Implement F5 Big IP 4000 and need to set send / return string for Exchange 2013 server for OWA monitoring... Can anyone help me with Exact output String.
    Amit

    Hi,
    In the Send String box enter in GET /owa/healthcheck.htm.  In the
    Receive String box, enter in 200 OK.
    Here is a related article for your reference.
    http://port25guy.com/2013/07/24/how-to-use-managed-availability-in-exchange-2013-with-your-load-balancer/
    Note: Microsoft is providing this information as a convenience to you. The sites are not controlled by Microsoft. Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. Please make
    sure that you completely understand the risk before retrieving any suggestions from the above link.
    Hope this is helpful to you.
    Best regards,
    Belinda Ma
    TechNet Community Support

Maybe you are looking for