EJB with rest to download service / update blob

Hello

I have successfully uses a rest service to present an image that is stored in my DB as a BLOB, but now I have to do the opposite, upload an image and save it as a blob, replacing the former or the addition of a new.

I thought that I could implement the same way I use to update other data as strings, numbers and dates:

    @POST
    @Consumes("application/xml")
    @Path("/merge/")
    public Response update(Customer customer) {
        
        Customer persistedCustomerRecord = SessionBean.getCustomerFindByRecId(customer.getRecid()).get(0);
        if (persistedCustomerRecord != null) {
        
            persistedCustomerRecord.setFname(customer.getFname());
            persistedCustomerRecord.setMname(customer.getMname());
            persistedCustomerRecord.setName(customer.getName());
            persistedCustomerRecord.setAnniversdate(customer.getAnniversdate());
      
            SessionBean.mergeCustomer(persistedCustomerRecord);
        } else {


            throw new ResourceNotFoundException("The employee resource with the id " + customer.getRecid() + "could not be found");
        }
        return Response.ok().build();
    }

but when I test my service entry for my memo field appears a base64Binary and is not a 'button' as the calendar to select the file.

With this in mind, I guess I have to somehow allow the download, select the file and convert byte [], since this is the data type defined by the EJB, creating the entity from the Table.

Am I wrong?

How can I accomplish this?

I use jdev 12 c and EJB

Thank you

Fixed.

My service now looks like this

    @POST
    @Consumes("application/xml")
    @Path("/merge/")
    public Response updatePhoto(Memos memo) {
        System.out.println("entrei " + memo.getSourceid());
        //find the employee record
        Memos persistedMemosRecord = SessionBean.getMemosUploadRecord(memo.getSourceid()).get(0);
        if (persistedMemosRecord != null) {
            System.out.println("no if, sourceid = " + persistedMemosRecord.getSourceid() + persistedMemosRecord.getRecid());
            //update employee object
            System.out.println("size " + memo.getThememo().length);
            persistedMemosRecord.setThememo(memo.getThememo());
            //persist the change
            SessionBean.mergeMemos(persistedMemosRecord);
        } else {

            throw new ResourceNotFoundException("The employee resource with the id " + memo.getRecid() + "could not be found");
        }
        return Response.ok().build();
    }

The xsd customer



    
        
            
                
            
        
    

And the bean of the jsf page

    public void fileUploaded(ValueChangeEvent event) {
        UploadedFile file = (UploadedFile) event.getNewValue();
        if (file != null) {
            BindingContainer bindings = BindingContext.getCurrent().getCurrentBindingsEntry();
            AttributeBinding attr = (AttributeBinding) bindings.getControlBinding("recid");
            String sourceid = attr.getInputValue().toString();

            FacesContext context = FacesContext.getCurrentInstance();
            FacesMessage message = new FacesMessage("Successfully uploaded file " + file.getFilename() + " (" + file.getLength() + " bytes)");
            context.addMessage(event.getComponent().getClientId(context), message);
            DCBindingContainer bc = (DCBindingContainer) BindingContext.getCurrent().getCurrentBindingsEntry();
            OperationBinding op = bc.getOperationBinding("updatePhoto");

            try {
                System.out.println("################# fileUpload op " + op);
                byte[] buffer = readFully(file.getInputStream());
                String encodedStr = new sun.misc.BASE64Encoder().encode(buffer);
                if (op != null) {
                    Map tempMap = new HashMap();

                    tempMap.put("thememo", encodedStr);
                    tempMap.put("sourceid", sourceid);
                    op.getParamsMap().put("memos", tempMap);
                    System.out.println("################ ja guardei no map str64 " + op.toString());
                    op.execute();
                }
            } catch (IOException e) {
                System.out.println(e);
            }
        }
    }

    /**
     *  Method to convert the InputStream to ByteArray
     */

    public byte[] readFully(InputStream input) throws IOException {
        byte[] buffer = new byte[8192];
        int bytesRead;
        ByteArrayOutputStream output = new ByteArrayOutputStream();
        while ((bytesRead = input.read(buffer)) != -1) {
            output.write(buffer, 0, bytesRead);
        }
        return output.toByteArray();
    }

fileUpload is associated with a componente inputFile


  
  
  

Thanks for your help

Tags: Java

Similar Questions

  • EJB with Rest service to return a blob object

    Hello

    I worked with EJB and Services Rest and now I have this situation.

    I'm trying to present an image saved on my DB as a BLOB, but when I test my service I get no results.

    My entity like the following for the blob, auto generated code

    private byte[] thememo;
    
        public byte[] getThememo() {
            return thememo;
        }
    
        public void setThememo(byte[] thememo) {
            this.thememo = thememo;
        }
    
    
    

    and these are queries, both to return the same, I added

    @NamedQuery(name = "Memos.findPhoto", query = "select o.thememo from Memos o where o.sourceid = :recid and o.memotyp = 101"),
    @NamedQuery(name = "Memos.getPhoto", query = "select 'image/jpeg', o.thememo from Memos o where o.sourceid = :recid and o.memotyp = 101")
    
    
    

    When you are looking for something that might explain to me on how to accomplish what I want, I found a link stating to add this "image/jpeg", before the column that as Creating RESTful Web Service for the recovery of the BLOB blob

    and when I add these requests based on my SessionBean through façade are the results I get

        /** <code>select o.thememo from Memos o where o.sourceid = :recid and o.memotyp = 101</code> */
        @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
        public List<Byte> getMemosFindPhoto(String recid) {
            return em.createNamedQuery("Memos.findPhoto", Memos.class).setParameter("recid", recid).getResultList();
        }
    
        /** <code>select 'image/jpeg', o.thememo from Memos o where o.sourceid = :recid and o.memotyp = 101</code> */
        @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
        public List<Object[]> getMemosGetPhoto(String recid) {
            return em.createNamedQuery("Memos.getPhoto", Memos.class).setParameter("recid", recid).getResultList();
        }
    
    
    

    The first gives me a list of bytes and the other a list of array of objects, and the only thing I want to come back is the blob as an image.

    The two statements in my SessionBean are errors, "Incompatible Types" but this has been generated.

    Without these functions, when I try to add the service to my JAXB schema it will not allow him.

    What am I doing wrong, or that I lack I?

    I use JDev 12.1.3.0

    Thank you

    and when I add "image/jpeg", "image/jpeg","image/jpeg",

    Well, you can create new named queries or change existing, what corresponds to your use case.

    For example, you can change

    @NamedQuery (name = "Memos.findPhoto", query = "" select memos o where o.sourceid = o.thememo: o.memotyp and recid = 101 "").

    TO:

    @NamedQuery (name = "Memos.findPhoto", query = "" select o o memos where o.sourceid =: recid and o.memotyp = 101 "").

    Then use the strongly typed named query (em.createNamedQuery ("Memos.findPhoto", Memos.class)) for map results to your entity of memos.

    Or you can use @NamedQuery which returns only your image (but then you must use createNamedQuery() with a parameter).

    After that, you can add the new method to your interface (or modify existing)

    etc.

    Dario

  • How do I deal with the 'there was an error downloading this update. Quit and try again later. "Helps online says wrong serial number, say its good customer service and I come here for help. CS5 installed today on the new PC.

    Today I installed CS5 on my new PC.  Everything is OK.  Run update help PS and received this message:

    CS5 Adobe Extension Manager 5.0 updated

    There was an error downloading this update. Quit and try again later.

    Adobe Illustrator CS5 15.0.2 updated

    There was an error downloading this update. Quit and try again later.

    Update of Photoshop to Photoshop CS5 12.0.4

    There was an error downloading this update. Quit and try again later.

    Photoshop Camera Raw 6.7 update

    There was an error downloading this update. Quit and try again later.

    My serial number Adobe customer service is good and I come here to help!

    Help.

    I am running CS5 on Windows 10.

    [When a staff member requests the information hover private hover over their name]

    [you can then click the Message option in the pop-up window to send a private email]

    [Accident removed long log... Please only send a log of crash to a technician, when asked]

    Cloud & Win10 https://helpx.adobe.com/creative-cloud/kb/Windows_10_compatibility_FAQ.html

    -In addition, only CURRENT products will be tested and updated for compatibility with Windows 10

    - so if you have an older program, update you to Windows 10 at YOUR risk of problems

    -You can get CS6 and previous programs to install and run, or you can not (some do, some don't)

    An idea that MAY work to install or run some programs in Windows 10 old... works for some, not for others

    -http://www.tenforums.com/tutorials/15523-compatibility-mode-settings-apps-change-windows-1 0 - a.html

    - or run as Administrator http://forums.adobe.com/thread/969395 to assign FULL permissions can help... said yet, but sometimes it is necessary for all Adobe programs (this is same as using an administrator account)

    Try to install your updates manually

    Beginning of the updates here and product selection, read to see if you need to install updates in the order of the numbers, or if updates are cumulative for the product http://www.adobe.com/downloads/updates/

  • repeated download even updated updated security for Microsoft XML Core Services 4.0 Service Pack 2 (KB954430)

    I have auto download from microsoft, and it has downloaded 4 times already. How can I stop it. A security update for Microsoft XML Core Services 4.0 Service Pack 2 (KB954430)

    Visit the Microsoft Solution Center and antivirus security for resources and tools to keep your PC safe and healthy. If you have problems with the installation of the update itself, visit the Microsoft Update Support for resources and tools to keep your PC updated with the latest updates.

    ~ Robear Dyer (PA Bear) ~ MS MVP (that is to say, mail, security, Windows & Update Services) since 2002 ~ WARNING: MS MVPs represent or work for Microsoft

  • This security update is constantly appearing: a security update for Microsoft XML Core Services 4.0 Service Pack 2 (KB954430) I successfully download the update and then it reappears to be downloaded again. ___

    Automatic updates of Windows

    This security update is constantly appearing: a security update for Microsoft XML Core Services 4.0 Service Pack 2 (KB954430) I successfully download the update and then it reappears to be downloaded again.

    See the sections «How to get help...» "and 'known issues' here:
    http://support.Microsoft.com/kb/954430

    Visit the Microsoft Solution Center and antivirus security for resources and tools to keep your PC safe and healthy. If you have problems with the installation of the update itself, visit the Microsoft Update Support for resources and tools to keep your PC updated with the latest updates.

    For enterprise customers, support for security updates is available through your usual support contacts.
    Read also: http://support.microsoft.com/kb/941729/

    Hope this helps, Vincenzo Di Russo
    Microsoft® MVP Windows Internet Explorer, Windows Desktop Experience & security - since 2003.
    My MVP profile: https://mvp.support.microsoft.com/profile/Vincenzo

  • After a fresh install with XP Home EWdition, Service pack 1, 2.0, and 3.0, I can't install Windows Update or IE8.

    After a fresh install with XP Home EWdition, Service pack 1, 2.0, and 3.0, I can't install Windows Update or IE8. Update back me to http://support.microsoft.com/kb/2497281

    Article ID: 2497281 - last review: January 18, 2011 - revision: 1.0

    You may be unable to access the site Web Windows Update in Windows XP, Windows 2000, or Windows Server 2003 if these versions of Windows are not updated with the latest Service Pack

    But I have service Pack 3.  IE8 fails, install a convenience store, but after following the instructions there is no difference.

    I am at a loss for the next steps...

    There was problems with the server for updates for a few weeks now...

    Many people say that download and run the Update Agent stand-alone file solves this problem:

    http://download.windowsupdate.com/WindowsUpdate/redist/standalone/7.4.7600.226/WindowsUpdateAgent30-x86.exe

    For more information:

    http://support.Microsoft.com/kb/943144

    For later use, it is not necessary to use all the steps you mentioned. You can upgrade directly from SP1a to SP3.

  • multiple applications to download the update of security for Microsoft Visual C++ 2005 Service Pack 1 Redistributable Package (KB2538242)

    I keep getting multiple applications to download security: updated for Microsoft Visual C++ 2005 Service Pack 1 Redistributable Package (KB2538242) its been downloaded more than 20 times with success.

    Hi Laura Mallard.

    1. did you of recent changes on the computer?

    2. facing a similar problem with another update?

    3. do you have security software installed on the computer?

    See the Microsoft article below and try the steps mentioned, check if it helps.

    Troubleshooting Windows Update or Microsoft Update when you are repeatedly offered an update

    http://support.Microsoft.com/kb/910339

  • Problems with downloading of updates

    I have Windows 8.1 on my computer HP laptop double heart. Although the automatic update is enabled on my system, I have download all updates manually because Windows seem to think I'm on a meter system. So, how to persuade Windows I'm NOT on a meter system? I have been using the same ISP for the last 6 years, and this problem of meter system has never been a problem when I was with Windows XP Pro on my laptop to be older.
    I would like you help me solve this problem, because the download of updates has become a real pain in the neck, since I started to use Windows 8. In the past, when I was with Windows XP, everything was done automatically, and I had nothing to do. Now, I spend up to 15 HOURS of downloading 100 MB of updates, and it's driving me crazy. I would like to say that this problem of slow performance occurs only when I am downloading of updates on the Microsoft site and does not affect other downloads. For example, the minutes before that I wrote those words, I had spent THAT 5 MINUTES to download a software of 28.5 MB of Cnet downloads Com, but it would take me about 2 hours to download 10 MB of Windows updates... Thank you... Dennis Ekpebu.

    Hi Dennis,

    Thanks for the answer and the update.

    If you use a USB to connect to the internet and if the connection is slow then you must contact the ISP or internet service provider to find out why the download speed is slow. Otherwise, now a days you get a hi speed Wi - Fi to help you can get good download speeds. You get good speeds in public libraries. You can try these options to download updates and check if that helps.

    A 3G modem uses a 3G network to establish an Internet connection. It is ideal for travellers and other people who are always on the road. It is also a popular choice for those whose computers do not have a wireless card installed. A 3G modem usually comes as a USB or a dongle with a SIM card inside which can be easily connected to the computer. The speed of a modem 3G Internet connection is based on the strength of the network signal, the speed of the computer you are using, and many other factors.

    S ' ensure that 3G modem specifications comply with the actual speed of the 3G network that you subscribe to the. For example, your 3 G Internet dongle can have a capacity of 3.6 MB while the 3G network has a speed of 7 MB. If this is the case, you will need to replace the dongle for a faster Internet connection.

    -Close the applications such as games and media players which can slow down the speed of the 3 G connection. If you notice any improvement compared to the speed of 3 G connection, restart the computer.

    -Ensure to that the SIM card is properly connected to the 3G modem. Unplug the modem 3G of the computer and insert the SIM card properly into its housing. Plug the 3G modem and see if it generates significant results.

    -Move the computer near a window or a door to get a stronger signal. If you are in an enclosed area, you can receive a 3G signal low compared to when you are in an open area.

    -Disconnect the 3G modem and reconnect it to the computer. This should refresh the connection and boost the signal of the 3G modem. Restart the computer.

    Let us know if you need assistance with any windows problem. We will be happy to help you.

  • After downloading the update for Yosemite 10.10.5, I got an annoying popup with a beep sound blaring that says that Safari crashed. I've forced to leave Safari, rebooted and popup returned once more. Restarted again and popup went. What was it?

    After downloading the update for Yosemite 10.10.5, I got an annoying popup with a beep sound blaring that says that Safari crashed. I've forced to leave Safari, rebooted and popup returned once more. Restarted again and popup went. What was it?

    Open Safari while holding the SHIFT key

    Try to reset the settings of Safari:

    1. open Safari

    2. click on the Safari menu at the top (to the right of the Apple logo)

    3. Select the Preferences/Privacy tab

    4. click on remove all data from the Web site

    5. close Safari.

    Remove cache Safari files:

    1. click on finder

    2. look for the menu GO to top

    3. click on GO and hold down the option key. This will show a user library folder.

    4. click library and find the Caches folder

    5. in the folder caches com.apple.Safari Ouvrezledossier

    6. move the Cache.db file Trash.

    This should solve the problem. If it does not help, try to disable the Safari extensions

    1. open Safari

    2. click on the Safari menu at the top (to the right of the Apple logo)

    3. Select Preferences

    4. find the Extensions tab

    5 disable all extensions of

    6. relaunch Safari

  • Has anyone with XP, svc pk 3 downloaded new updates to the Java plugin and if so, is FF works fine afterwards?

    No matter who else I wondered about this? Someone else with w/32-bit XP, downloaded the new update Java in plugins and you're running OK?

    I want to update my Java plugin, but wait and see if others with XP, 32 bit have updated and how it works for them.

    Thank you!

    Works fine for me. See this: http://java.com/en/

  • If I download the update for firefox I have problems with my real player as with the last update?

    The last update for firefox I was warned that if I downloaded it that my realplayer wouldn't work. I don't want to download the update to firefox 6, if I'm having a problem with realplayer

    Using the RealPlayer Plugin with Firefox

    Check and tell if its working.

  • I have a question about the time machine. I recently updated my Quicken 2015 and there was something wrong with the update. Can I go back in just the Quicken file and restore it until I downloaded the update do I have to restore the entire

    I have a question about the time machine. I recently updated my Quicken 2015 and there was something wrong with the update. Can I come back in all the Quicken file and restore from time Machine before I downloaded the update to do, I need to restore the entire computer?

    Yes, you can just restore this file or application. Use Time Machine to back up or restore your Mac - Apple Support

  • Asslam o aliakum. I have a problem with itunes 12.3.2 it is not downloaded the 10 windows and when I connect m iphone with itunes and want to update to 9.2 says please download itunes new version for ios 9.2... help me with this... How to solve this probl

    Asslam o aliakum. I have a problem with itunes 12.3.2 it is not downloaded the 10 windows and when I connect m iphone with itunes and want to update to 9.2 says please download itunes new version for ios 9.2... help me with this... How to solve this problem.

    Greetings Dani56777,

    Thank you for using communities Support from Apple!

    I understand that you run Windows 10 and you must update iTunes to the latest version so that your iPhone will be recognized when connected. I do not know if you receive an error when you try to update iTunes or not.

    If you need information on how to update iTunes, please follow the instructions in the following link.

    Download the latest version of iTunes for Windows - Apple Support

    If you receive an error or alert, you can consider removing iTunes and all of its associated components and then reinstalling fresh iTunes on your computer. That would give you the latest version of iTunes. If you need execute this process, please follow the steps described in the following article.

    Remove iTunes Control Panel and its associated components

    Use the control panel to uninstall iTunes and software components in the following order:

    1. iTunes
    2. Apple Software Update
    3. Apple Mobile Device Support
    4. Hello
    5. Apple Application Support 32-bit
    6. Apple Application Support 64-bit

    On some systems, iTunes can install two versions of the Apple Application Support. What is expected. If both are present, do not forget to uninstall both versions.

    Do these elements in a different order, uninstall or uninstall only some of them. This could have unintended effects. After you uninstall a component, you may be asked to restart your computer. Wait to restart your computer until you finish remove all components.

    Remove and reinstall iTunes and software for Windows 7 and later versions - Apple Support components

    Have a great day!

  • I changed my email address, now whenever I need to download the updates it tells me to connect with the old address, even though I changed mt apple ID. Why my old email address come upward instead of my news?

    I changed my email address and now I can't download my updates because my apple ID always happens with my old email address. I changed it to my new address, and it always happens with the former. How can I solve this problem?

    This is because any download/purchase the app store is linked to the Apple ID used to get forever.

  • do phone microsoft to say there is a problem with the download of updates and offer help

    I got a phone call from a woman with an Indian accent, saying: I had a problem downloading of updates and I had to go online and she would help me. It's a real call from microsoft or some sort of a scam

    It's a scam.

    http://www.Microsoft.com/security/online-privacy/msName.aspx

    http://www.Microsoft.com/security/online-privacy/phishing-scams.aspx

    http://www.Microsoft.com/security/online-privacy/avoid-phone-scams.aspx

    http://blogs.msdn.com/b/securitytipstalk/archive/2010/03/09/Don-t-fall-for-phony-phone-tech-support.aspx

Maybe you are looking for