Project

General

Profile

« Previous | Next » 

Revision 5394

Added by berkley almost 14 years ago

tracked down streaming bug. now need to figure out a better way to fix it.

View differences:

ResourceHandler.java
843 843
        out.close();
844 844
    }
845 845
    
846
    private String streamToString(InputStream is)
847
    throws IOException
848
    {
849
        byte b[] = new byte[1024];
850
        int numread = is.read(b, 0, 1024);
851
        String response = new String();
852
        while(numread != -1)
853
        {
854
            response += new String(b, 0, numread);
855
            numread = is.read(b, 0, 1024);
856
        }
857
        return response;
858
    }
859

  
860
    private InputStream stringToStream(String s)
861
    throws IOException
862
    {
863
        ByteArrayInputStream bais = new ByteArrayInputStream(s.getBytes());
864
        return bais;
865
    }
866
    
867
    
846 868
    /**
847 869
     * Earthgrid API > Put Service >Put Function : calls MetacatHandler > handleInsertOrUpdateAction 
848 870
     * 
......
863 885
            logMetacat.debug("Disassembling MIME multipart form");
864 886
            InputStream object = null;
865 887
            InputStream sysmeta = null;
888
            
889
            String s = streamToString(request.getInputStream());
890
            String searchString = "Content-Disposition: attachment; filename=systemmetadata";
891
            String endString = "------=_Part";
892
            int searchStringIndex = s.indexOf(searchString);
893
            sysmeta = new ByteArrayInputStream(
894
                    s.substring(searchStringIndex +
895
                            searchString.length(), 
896
                            s.indexOf(endString, searchStringIndex)).trim().getBytes());
897
            String txt = streamToString(sysmeta);
898
            System.out.println("sysmeta: " + txt);
899
            sysmeta = stringToStream(txt);
900
            
901
            searchString = "Content-Disposition: attachment; filename=object";
902
            searchStringIndex = s.indexOf(searchString);
903
            object = new ByteArrayInputStream(
904
                    s.substring(searchStringIndex +
905
                            searchString.length(), 
906
                            s.indexOf(endString, searchStringIndex)).trim().getBytes());
907
            txt = streamToString(object);
908
            System.out.println("object: " + txt);
909
            sysmeta = stringToStream(txt);
910
            //System.out.println("request stream: " + s);
911
            //Since mmp seems to have a bug where large object parts get truncated,
912
            //parse the stream here.  This has the disavantage of putting the
913
            //stream into memory.
914
            
915
            /*
866 916
            MimeMultipart mmp = new MimeMultipart(new InputStreamDataSource("message", request.getInputStream()));
867 917
            logMetacat.debug("MMP created.");
868
            mmp.writeTo(System.out);
918
            
919
            //mmp.writeTo(System.out);
869 920
            for (int i = 0; i < mmp.getCount(); i++) {
870 921
                BodyPart part = mmp.getBodyPart(i);
871 922
                String name = part.getFileName();
872 923
                logMetacat.debug("Part name is: " + name);
873 924
                logMetacat.debug("Part has class name: " + part.getClass().getName());
925
                
874 926
                if (name.equals("object")) {
875 927
                    object = part.getInputStream();
876
                    logMetacat.debug("Found object part, size is: " + part.getSize());
928
                    try
929
                    {
930
                        String s = streamToString(object);
931
                        System.out.println("doc text: " + s);
932
                        System.out.println("size of doc text is: " + s.getBytes().length);
933
                        object = stringToStream(s);
934
                    }
935
                    catch(Exception e)
936
                    {}
937
                    System.out.println("Found object part, size is: " + part.getSize());
877 938
                } else if (name.equals("systemmetadata")) {
878 939
                    sysmeta = part.getInputStream();
940
                    try
941
                    {
942
                      String s = streamToString(sysmeta);
943
                      System.out.println("system metadata part: " + s);
944
                      sysmeta = stringToStream(s);
945
                    }
946
                    catch(Exception e){}
947
                    System.out.println("system metadata part, size is " + part.getSize());
879 948
                    logMetacat.debug("Found sysmeta part, size is: " + part.getSize());
880 949
                } else {
881 950
                    throw new InvalidRequest("1000", "Request had malformed MIME part with name: " + name);
882 951
                }
883
            }
952
            }*/
884 953
            
885 954
            if ( action.equals(FUNCTION_NAME_INSERT)) { //handle inserts
886 955

  
......
966 1035
            serializeException(e, out);
967 1036
        } catch (InvalidRequest e) {
968 1037
            serializeException(e, out);
969
        } catch (MessagingException e) {
1038
        } /*catch (MessagingException e) {
970 1039
            ServiceFailure sf = new ServiceFailure("1000", e.getMessage());
971 1040
            serializeException(sf, out);
972
        } catch (IOException e) {
1041
        }*/ catch (IOException e) {
973 1042
            ServiceFailure sf = new ServiceFailure("1000", e.getMessage());
974 1043
            serializeException(sf, out);
975 1044
        } catch (JiBXException e) {

Also available in: Unified diff